Improve error messages

* Show information about shortcut.
* Make errors translatable.
This commit is contained in:
Shatur95
2020-07-01 23:16:13 +03:00
parent c373d83c36
commit 483e07365e
5 changed files with 18 additions and 16 deletions
+10 -4
View File
@@ -279,9 +279,11 @@ bool QHotkeyPrivate::addShortcutInvoked(QHotkey *hotkey)
QHotkey::NativeShortcut shortcut = hotkey->_nativeShortcut; QHotkey::NativeShortcut shortcut = hotkey->_nativeShortcut;
if(!shortcuts.contains(shortcut)) { if(!shortcuts.contains(shortcut)) {
if(!registerShortcut(shortcut)) if(!registerShortcut(shortcut)) {
qCWarning(logQHotkey) << QHotkey::tr("Failed to register %1. Error: %2").arg(hotkey->shortcut().toString(), error);
return false; return false;
} }
}
shortcuts.insert(shortcut, hotkey); shortcuts.insert(shortcut, hotkey);
hotkey->_registered = true; hotkey->_registered = true;
@@ -296,9 +298,13 @@ bool QHotkeyPrivate::removeShortcutInvoked(QHotkey *hotkey)
return false; return false;
hotkey->_registered = false; hotkey->_registered = false;
emit hotkey->registeredChanged(true); emit hotkey->registeredChanged(true);
if(shortcuts.count(shortcut) == 0) if(shortcuts.count(shortcut) == 0) {
return unregisterShortcut(shortcut); if (!unregisterShortcut(shortcut)) {
else qCWarning(logQHotkey) << QHotkey::tr("Failed to unregister %1. Error: %2").arg(hotkey->shortcut().toString(), error);
return false;
} else
return true;
} else
return true; return true;
} }
+2 -4
View File
@@ -227,8 +227,7 @@ bool QHotkeyPrivateMac::registerShortcut(QHotkey::NativeShortcut shortcut)
0, 0,
&eventRef); &eventRef);
if (status != noErr) { if (status != noErr) {
qCWarning(logQHotkey) << "Failed to register hotkey. Error:" error = QString::number(status);
<< status;
return false; return false;
} else { } else {
this->hotkeyRefs.insert(shortcut, eventRef); this->hotkeyRefs.insert(shortcut, eventRef);
@@ -241,8 +240,7 @@ bool QHotkeyPrivateMac::unregisterShortcut(QHotkey::NativeShortcut shortcut)
EventHotKeyRef eventRef = QHotkeyPrivateMac::hotkeyRefs.value(shortcut); EventHotKeyRef eventRef = QHotkeyPrivateMac::hotkeyRefs.value(shortcut);
OSStatus status = UnregisterEventHotKey(eventRef); OSStatus status = UnregisterEventHotKey(eventRef);
if (status != noErr) { if (status != noErr) {
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:" error = QString::number(status);
<< status;
return false; return false;
} else { } else {
this->hotkeyRefs.remove(shortcut); this->hotkeyRefs.remove(shortcut);
+2
View File
@@ -33,6 +33,8 @@ protected:
virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
QString error;
private: private:
QHash<QPair<Qt::Key, Qt::KeyboardModifiers>, QHotkey::NativeShortcut> mapping; QHash<QPair<Qt::Key, Qt::KeyboardModifiers>, QHotkey::NativeShortcut> mapping;
QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts; QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;
+2 -4
View File
@@ -267,8 +267,7 @@ bool QHotkeyPrivateWin::registerShortcut(QHotkey::NativeShortcut shortcut)
if(ok) if(ok)
return true; return true;
else { else {
qCWarning(logQHotkey) << "Failed to register hotkey. Error:" error = QHotkeyPrivateWin::formatWinError(::GetLastError());
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
return false; return false;
} }
} }
@@ -279,8 +278,7 @@ bool QHotkeyPrivateWin::unregisterShortcut(QHotkey::NativeShortcut shortcut)
if(ok) if(ok)
return true; return true;
else { else {
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:" error = QHotkeyPrivateWin::formatWinError(::GetLastError());
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
return false; return false;
} }
} }
+2 -4
View File
@@ -170,8 +170,7 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
XSync(display, False); XSync(display, False);
if(errorHandler.hasError) { if(errorHandler.hasError) {
qCWarning(logQHotkey) << "Failed to register hotkey. Error:" error = errorHandler.errorString;
<< qPrintable(errorHandler.errorString);
this->unregisterShortcut(shortcut); this->unregisterShortcut(shortcut);
return false; return false;
} else } else
@@ -194,8 +193,7 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
XSync(display, False); XSync(display, False);
if(errorHandler.hasError) { if(errorHandler.hasError) {
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:" error = errorHandler.errorString;
<< qPrintable(errorHandler.errorString);
return false; return false;
} else } else
return true; return true;