mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
logging update
use QLoggingCategory now to provides improved logging
This commit is contained in:
+7
-8
@@ -6,6 +6,8 @@
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
|
||||
Q_LOGGING_CATEGORY(logQHotkey, "[QHotkey]")
|
||||
|
||||
QHotkey::QHotkey(QObject *parent) :
|
||||
QObject(parent),
|
||||
key(Qt::Key_unknown),
|
||||
@@ -65,8 +67,8 @@ bool QHotkey::setShortcut(const QKeySequence &shortcut, bool autoRegister)
|
||||
if(shortcut.isEmpty()) {
|
||||
return this->resetShortcut();
|
||||
} else if(shortcut.count() > 1) {
|
||||
qWarning("QHotkey: Keysequences with multiple shortcuts are not allowed! "
|
||||
"Only the first shortcut will be used!");
|
||||
qCWarning(logQHotkey, "Keysequences with multiple shortcuts are not allowed! "
|
||||
"Only the first shortcut will be used!");
|
||||
}
|
||||
|
||||
return this->setShortcut(Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask),
|
||||
@@ -80,10 +82,8 @@ bool QHotkey::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool aut
|
||||
if(autoRegister) {
|
||||
if(!QHotkeyPrivate::instance()->removeShortcut(this))
|
||||
return false;
|
||||
} else {
|
||||
qWarning("QHotkey: Can't change the shortcut while the hotkey is registered");
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this->key = key;
|
||||
@@ -95,7 +95,7 @@ bool QHotkey::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool aut
|
||||
else
|
||||
return true;
|
||||
} else {
|
||||
qWarning() << "QHotkey: Unable to map shortcut to native keys. Key:" << key << "Modifiers:" << modifiers;
|
||||
qCWarning(logQHotkey) << "Unable to map shortcut to native keys. Key:" << key << "Modifiers:" << modifiers;
|
||||
this->key = Qt::Key_unknown;
|
||||
this->mods = Qt::NoModifier;
|
||||
this->nativeShortcut = NativeShortcut();
|
||||
@@ -107,7 +107,6 @@ bool QHotkey::resetShortcut()
|
||||
{
|
||||
if(this->registered &&
|
||||
!QHotkeyPrivate::instance()->removeShortcut(this)) {
|
||||
qWarning("QHotkey: Failed to unregister shortcut");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -144,7 +143,7 @@ QHotkeyPrivate::QHotkeyPrivate() :
|
||||
QHotkeyPrivate::~QHotkeyPrivate()
|
||||
{
|
||||
if(!this->shortcuts.isEmpty())
|
||||
qWarning("QHotkey: QHotkeyPrivate destroyed with registered shortcuts!");
|
||||
qCWarning(logQHotkey, "QHotkeyPrivate destroyed with registered shortcuts!");
|
||||
if(qApp && qApp->eventDispatcher())
|
||||
qApp->eventDispatcher()->removeNativeEventFilter(this);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QKeySequence>
|
||||
#include <QPair>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
class QHotkey : public QObject
|
||||
{
|
||||
@@ -48,4 +49,6 @@ private:
|
||||
bool registered;
|
||||
};
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(logQHotkey)
|
||||
|
||||
#endif // QHOTKEY_H
|
||||
|
||||
@@ -206,8 +206,9 @@ bool QHotkeyPrivateMac::registerShortcut(QHotkey::NativeShortcut shortcut)
|
||||
GetApplicationEventTarget(),
|
||||
0,
|
||||
&eventRef);
|
||||
if (status != noErr) {
|
||||
qWarning() << "QHotkey: Failed to register hotkey. Error:" << status;
|
||||
if (status != noErr) {
|
||||
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
|
||||
<< status;
|
||||
return false;
|
||||
} else {
|
||||
this->hotkeyRefs.insert(shortcut, eventRef);
|
||||
@@ -219,8 +220,9 @@ bool QHotkeyPrivateMac::unregisterShortcut(QHotkey::NativeShortcut shortcut)
|
||||
{
|
||||
EventHotKeyRef eventRef = QHotkeyPrivateMac::hotkeyRefs.value(shortcut);
|
||||
OSStatus status = UnregisterEventHotKey(eventRef);
|
||||
if (status != noErr) {
|
||||
qWarning() << "QHotkey: Failed to unregister hotkey. Error:" << status;
|
||||
if (status != noErr) {
|
||||
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
|
||||
<< status;
|
||||
return false;
|
||||
} else {
|
||||
this->hotkeyRefs.remove(shortcut);
|
||||
|
||||
@@ -228,7 +228,8 @@ bool QHotkeyPrivateWin::registerShortcut(QHotkey::NativeShortcut shortcut)
|
||||
if(ok)
|
||||
return true;
|
||||
else {
|
||||
qWarning() << "QHotkey: Failed to register hotkey. Error:" << qPrintable(formatWinError(::GetLastError()));
|
||||
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
|
||||
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -239,7 +240,8 @@ bool QHotkeyPrivateWin::unregisterShortcut(QHotkey::NativeShortcut shortcut)
|
||||
if(ok)
|
||||
return true;
|
||||
else {
|
||||
qWarning() << "QHotkey: Failed to unregister hotkey. Error:" << qPrintable(formatWinError(::GetLastError()));
|
||||
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
|
||||
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ private:
|
||||
HotkeyErrorHandler();
|
||||
~HotkeyErrorHandler();
|
||||
|
||||
static bool hasError;//TODO threading
|
||||
static QString errorString;//TODO threading
|
||||
static bool hasError;
|
||||
static QString errorString;
|
||||
|
||||
private:
|
||||
XErrorHandler prevHandler;
|
||||
@@ -108,7 +108,8 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
|
||||
}
|
||||
|
||||
if(errorHandler.hasError) {
|
||||
qWarning() << "QHotkey: Failed to register hotkey. Error:" << qPrintable(errorHandler.errorString);
|
||||
qCWarning(logQHotkey) << "[QHotkey] Failed to register hotkey. Error:"
|
||||
<< qPrintable(errorHandler.errorString);
|
||||
this->unregisterShortcut(shortcut);
|
||||
return false;
|
||||
} else
|
||||
@@ -129,8 +130,9 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
|
||||
DefaultRootWindow(display));
|
||||
}
|
||||
|
||||
if(errorHandler.hasError) {
|
||||
qWarning() << "QHotkey: Failed to unregister hotkey. Error:" << qPrintable(errorHandler.errorString);
|
||||
if(errorHandler.hasError) {
|
||||
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
|
||||
<< qPrintable(errorHandler.errorString);
|
||||
this->unregisterShortcut(shortcut);
|
||||
return false;
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user