Skip to content

Improve error messages #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve error messages
* Show information about shortcut.
* Make errors translatable.
  • Loading branch information
Shatur committed Jul 1, 2020
commit 483e07365ee943b19f8078a4951090b6a9b87a65
14 changes: 10 additions & 4 deletions QHotkey/qhotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,10 @@ bool QHotkeyPrivate::addShortcutInvoked(QHotkey *hotkey)
QHotkey::NativeShortcut shortcut = hotkey->_nativeShortcut;

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;
}
}

shortcuts.insert(shortcut, hotkey);
Expand All @@ -296,9 +298,13 @@ bool QHotkeyPrivate::removeShortcutInvoked(QHotkey *hotkey)
return false;
hotkey->_registered = false;
emit hotkey->registeredChanged(true);
if(shortcuts.count(shortcut) == 0)
return unregisterShortcut(shortcut);
else
if(shortcuts.count(shortcut) == 0) {
if (!unregisterShortcut(shortcut)) {
qCWarning(logQHotkey) << QHotkey::tr("Failed to unregister %1. Error: %2").arg(hotkey->shortcut().toString(), error);
return false;
} else
return true;
} else
return true;
}

Expand Down
6 changes: 2 additions & 4 deletions QHotkey/qhotkey_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ bool QHotkeyPrivateMac::registerShortcut(QHotkey::NativeShortcut shortcut)
0,
&eventRef);
if (status != noErr) {
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
<< status;
error = QString::number(status);
return false;
} else {
this->hotkeyRefs.insert(shortcut, eventRef);
Expand All @@ -241,8 +240,7 @@ bool QHotkeyPrivateMac::unregisterShortcut(QHotkey::NativeShortcut shortcut)
EventHotKeyRef eventRef = QHotkeyPrivateMac::hotkeyRefs.value(shortcut);
OSStatus status = UnregisterEventHotKey(eventRef);
if (status != noErr) {
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
<< status;
error = QString::number(status);
return false;
} else {
this->hotkeyRefs.remove(shortcut);
Expand Down
2 changes: 2 additions & 0 deletions QHotkey/qhotkey_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class QHOTKEY_SHARED_EXPORT QHotkeyPrivate : public QObject, public QAbstractNat
virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement

QString error;

private:
QHash<QPair<Qt::Key, Qt::KeyboardModifiers>, QHotkey::NativeShortcut> mapping;
QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;
Expand Down
6 changes: 2 additions & 4 deletions QHotkey/qhotkey_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ bool QHotkeyPrivateWin::registerShortcut(QHotkey::NativeShortcut shortcut)
if(ok)
return true;
else {
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
error = QHotkeyPrivateWin::formatWinError(::GetLastError());
return false;
}
}
Expand All @@ -279,8 +278,7 @@ bool QHotkeyPrivateWin::unregisterShortcut(QHotkey::NativeShortcut shortcut)
if(ok)
return true;
else {
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
<< qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError()));
error = QHotkeyPrivateWin::formatWinError(::GetLastError());
return false;
}
}
Expand Down
6 changes: 2 additions & 4 deletions QHotkey/qhotkey_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
XSync(display, False);

if(errorHandler.hasError) {
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
<< qPrintable(errorHandler.errorString);
error = errorHandler.errorString;
this->unregisterShortcut(shortcut);
return false;
} else
Expand All @@ -194,8 +193,7 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
XSync(display, False);

if(errorHandler.hasError) {
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
<< qPrintable(errorHandler.errorString);
error = errorHandler.errorString;
return false;
} else
return true;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy