diff --git a/src/main.cpp b/src/main.cpp index c0d020de..a191f2dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -178,25 +178,30 @@ int main(int argc, char *argv[]) // install the translations built-into Qt itself QTranslator qtTranslator; if (qtTranslator.load(QStringLiteral("qt_") + QLocale::system().name(), QLibraryInfo::path(QLibraryInfo::TranslationsPath))) + { app->installTranslator(&qtTranslator); + } QTranslator translator; + bool installTr = false; QString fname = QString::fromLatin1("qterminal_%1.qm").arg(QLocale::system().name().left(5)); #ifdef TRANSLATIONS_DIR //qDebug() << "TRANSLATIONS_DIR: Loading translation file" << fname << "from dir" << TRANSLATIONS_DIR; - /*qDebug() << "load success:" <<*/ translator.load(fname, QString::fromUtf8(TRANSLATIONS_DIR), QStringLiteral("_")); + installTr = translator.load(fname, QString::fromUtf8(TRANSLATIONS_DIR), QStringLiteral("_")); #endif #ifdef APPLE_BUNDLE QDir translations_dir = QDir(QApplication::applicationDirPath()); translations_dir.cdUp(); if (translations_dir.cd(QStringLiteral("Resources/translations"))) { - //qDebug() << "APPLE_BUNDLE: Loading translator file" << fname << "from dir" << translations_dir.path(); - /*qDebug() << "load success:" <<*/ translator.load(fname, translations_dir.path(), QStringLiteral("_")); + installTr = translator.load(fname, translations_dir.path(), QStringLiteral("_")); } /*else { qWarning() << "Unable to find \"Resources/translations\" dir in" << translations_dir.path(); }*/ #endif - app->installTranslator(&translator); + if (installTr) + { + app->installTranslator(&translator); + } TerminalConfig initConfig = TerminalConfig(workdir, shell_command); app->newWindow(dropMode, initConfig); diff --git a/src/terminalconfig.cpp b/src/terminalconfig.cpp index 552a4158..2c105fb7 100644 --- a/src/terminalconfig.cpp +++ b/src/terminalconfig.cpp @@ -80,14 +80,14 @@ TerminalConfig TerminalConfig::fromDbus(const QHash &termArgsC static QString variantToString(const QVariant& variant, QString &defaultVal) { - if (variant.typeId() == QMetaType::type("QString")) + if (variant.typeId() == QMetaType::QString) return qvariant_cast(variant); return defaultVal; } static QStringList variantToStringList(const QVariant& variant, QStringList &defaultVal) { - if (variant.typeId() == QMetaType::type("QStringList")) + if (variant.typeId() == QMetaType::QStringList) return qvariant_cast(variant); return defaultVal; } diff --git a/src/third-party/qxtglobalshortcut.cpp b/src/third-party/qxtglobalshortcut.cpp index 435b81dc..bb3037bc 100644 --- a/src/third-party/qxtglobalshortcut.cpp +++ b/src/third-party/qxtglobalshortcut.cpp @@ -1,212 +1,212 @@ -#include "qxtglobalshortcut.h" -/**************************************************************************** -** Copyright (c) 2006 - 2011, the LibQxt project. -** See the Qxt AUTHORS file for a list of authors and copyright holders. -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in the -** documentation and/or other materials provided with the distribution. -** * Neither the name of the LibQxt project nor the -** names of its contributors may be used to endorse or promote products -** derived from this software without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY -** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -** -** -*****************************************************************************/ - -#include "qxtglobalshortcut_p.h" -#include -#include - -#ifndef Q_OS_MAC -int QxtGlobalShortcutPrivate::ref = 0; -#endif -QHash, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts; - -QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier) -{ -#ifndef Q_OS_MAC - if (ref == 0) { - QAbstractEventDispatcher::instance()->installNativeEventFilter(this); - } - ++ref; -#endif -} - -QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate() -{ -#ifndef Q_OS_MAC - --ref; - if (ref == 0) { - QAbstractEventDispatcher *ed = QAbstractEventDispatcher::instance(); - if (ed != nullptr) { - ed->removeNativeEventFilter(this); - } - } -#endif -} - -bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) -{ - Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; - key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]); - mods = shortcut.isEmpty() ? Qt::KeyboardModifiers() : Qt::KeyboardModifiers(shortcut[0] & allMods); - const quint32 nativeKey = nativeKeycode(key); - const quint32 nativeMods = nativeModifiers(mods); - const bool res = registerShortcut(nativeKey, nativeMods); - if (res) - shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p()); - else - qWarning() << "QxtGlobalShortcut failed to register:" << QKeySequence(key + mods).toString(); - return res; -} - -bool QxtGlobalShortcutPrivate::unsetShortcut() -{ - bool res = false; - const quint32 nativeKey = nativeKeycode(key); - const quint32 nativeMods = nativeModifiers(mods); - if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p()) - res = unregisterShortcut(nativeKey, nativeMods); - if (res) - shortcuts.remove(qMakePair(nativeKey, nativeMods)); - else - qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); - key = Qt::Key(0); - mods = Qt::KeyboardModifiers(); - return res; -} - -void QxtGlobalShortcutPrivate::activateShortcut(quint32 nativeKey, quint32 nativeMods) -{ - QxtGlobalShortcut* shortcut = shortcuts.value(qMakePair(nativeKey, nativeMods)); - if (shortcut && shortcut->isEnabled()) - emit shortcut->activated(); -} - -/*! - \class QxtGlobalShortcut - \inmodule QxtWidgets - \brief The QxtGlobalShortcut class provides a global shortcut aka "hotkey". - - A global shortcut triggers even if the application is not active. This - makes it easy to implement applications that react to certain shortcuts - still if some other application is active or if the application is for - example minimized to the system tray. - - Example usage: - \code - QxtGlobalShortcut* shortcut = new QxtGlobalShortcut(window); - connect(shortcut, SIGNAL(activated()), window, SLOT(toggleVisibility())); - shortcut->setShortcut(QKeySequence("Ctrl+Shift+F12")); - \endcode - - \bold {Note:} Since Qxt 0.6 QxtGlobalShortcut no more requires QxtApplication. - */ - -/*! - \fn QxtGlobalShortcut::activated() - - This signal is emitted when the user types the shortcut's key sequence. - - \sa shortcut - */ - -/*! - Constructs a new QxtGlobalShortcut with \a parent. - */ -QxtGlobalShortcut::QxtGlobalShortcut(QObject* parent) - : QObject(parent) -{ - QXT_INIT_PRIVATE(QxtGlobalShortcut); -} - -/*! - Constructs a new QxtGlobalShortcut with \a shortcut and \a parent. - */ -QxtGlobalShortcut::QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent) - : QObject(parent) -{ - QXT_INIT_PRIVATE(QxtGlobalShortcut); - setShortcut(shortcut); -} - -/*! - Destructs the QxtGlobalShortcut. - */ -QxtGlobalShortcut::~QxtGlobalShortcut() -{ - if (qxt_d().key != 0) - qxt_d().unsetShortcut(); -} - -/*! - \property QxtGlobalShortcut::shortcut - \brief the shortcut key sequence - - \bold {Note:} Notice that corresponding key press and release events are not - delivered for registered global shortcuts even if they are disabled. - Also, comma separated key sequences are not supported. - Only the first part is used: - - \code - qxtShortcut->setShortcut(QKeySequence("Ctrl+Alt+A,Ctrl+Alt+B")); - Q_ASSERT(qxtShortcut->shortcut() == QKeySequence("Ctrl+Alt+A")); - \endcode - */ -QKeySequence QxtGlobalShortcut::shortcut() const -{ - return QKeySequence(qxt_d().key | qxt_d().mods); -} - -bool QxtGlobalShortcut::setShortcut(const QKeySequence& shortcut) -{ - if (qxt_d().key != 0) - qxt_d().unsetShortcut(); - return qxt_d().setShortcut(shortcut); -} - -/*! - \property QxtGlobalShortcut::enabled - \brief whether the shortcut is enabled - - A disabled shortcut does not get activated. - - The default value is \c true. - - \sa setDisabled() - */ -bool QxtGlobalShortcut::isEnabled() const -{ - return qxt_d().enabled; -} - -void QxtGlobalShortcut::setEnabled(bool enabled) -{ - qxt_d().enabled = enabled; -} - -/*! - Sets the shortcut \a disabled. - - \sa enabled - */ -void QxtGlobalShortcut::setDisabled(bool disabled) -{ - qxt_d().enabled = !disabled; -} +#include "qxtglobalshortcut.h" +/**************************************************************************** +** Copyright (c) 2006 - 2011, the LibQxt project. +** See the Qxt AUTHORS file for a list of authors and copyright holders. +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the LibQxt project nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +** +** +*****************************************************************************/ + +#include "qxtglobalshortcut_p.h" +#include +#include + +#ifndef Q_OS_MAC +int QxtGlobalShortcutPrivate::ref = 0; +#endif +QHash, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts; + +QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier) +{ +#ifndef Q_OS_MAC + if (ref == 0) { + QAbstractEventDispatcher::instance()->installNativeEventFilter(this); + } + ++ref; +#endif +} + +QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate() +{ +#ifndef Q_OS_MAC + --ref; + if (ref == 0) { + QAbstractEventDispatcher *ed = QAbstractEventDispatcher::instance(); + if (ed != nullptr) { + ed->removeNativeEventFilter(this); + } + } +#endif +} + +bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) +{ + Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; + key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0].key() ^ allMods) & shortcut[0].key()); + mods = shortcut.isEmpty() ? Qt::KeyboardModifiers() : Qt::KeyboardModifiers(shortcut[0].key() & allMods); + const quint32 nativeKey = nativeKeycode(key); + const quint32 nativeMods = nativeModifiers(mods); + const bool res = registerShortcut(nativeKey, nativeMods); + if (res) + shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p()); + else + qWarning() << "QxtGlobalShortcut failed to register:" << QKeySequence(key | mods).toString(); + return res; +} + +bool QxtGlobalShortcutPrivate::unsetShortcut() +{ + bool res = false; + const quint32 nativeKey = nativeKeycode(key); + const quint32 nativeMods = nativeModifiers(mods); + if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p()) + res = unregisterShortcut(nativeKey, nativeMods); + if (res) + shortcuts.remove(qMakePair(nativeKey, nativeMods)); + else + qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key | mods).toString(); + key = Qt::Key(0); + mods = Qt::KeyboardModifiers(); + return res; +} + +void QxtGlobalShortcutPrivate::activateShortcut(quint32 nativeKey, quint32 nativeMods) +{ + QxtGlobalShortcut* shortcut = shortcuts.value(qMakePair(nativeKey, nativeMods)); + if (shortcut && shortcut->isEnabled()) + emit shortcut->activated(); +} + +/*! + \class QxtGlobalShortcut + \inmodule QxtWidgets + \brief The QxtGlobalShortcut class provides a global shortcut aka "hotkey". + + A global shortcut triggers even if the application is not active. This + makes it easy to implement applications that react to certain shortcuts + still if some other application is active or if the application is for + example minimized to the system tray. + + Example usage: + \code + QxtGlobalShortcut* shortcut = new QxtGlobalShortcut(window); + connect(shortcut, SIGNAL(activated()), window, SLOT(toggleVisibility())); + shortcut->setShortcut(QKeySequence("Ctrl+Shift+F12")); + \endcode + + \bold {Note:} Since Qxt 0.6 QxtGlobalShortcut no more requires QxtApplication. + */ + +/*! + \fn QxtGlobalShortcut::activated() + + This signal is emitted when the user types the shortcut's key sequence. + + \sa shortcut + */ + +/*! + Constructs a new QxtGlobalShortcut with \a parent. + */ +QxtGlobalShortcut::QxtGlobalShortcut(QObject* parent) + : QObject(parent) +{ + QXT_INIT_PRIVATE(QxtGlobalShortcut); +} + +/*! + Constructs a new QxtGlobalShortcut with \a shortcut and \a parent. + */ +QxtGlobalShortcut::QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent) + : QObject(parent) +{ + QXT_INIT_PRIVATE(QxtGlobalShortcut); + setShortcut(shortcut); +} + +/*! + Destructs the QxtGlobalShortcut. + */ +QxtGlobalShortcut::~QxtGlobalShortcut() +{ + if (qxt_d().key != 0) + qxt_d().unsetShortcut(); +} + +/*! + \property QxtGlobalShortcut::shortcut + \brief the shortcut key sequence + + \bold {Note:} Notice that corresponding key press and release events are not + delivered for registered global shortcuts even if they are disabled. + Also, comma separated key sequences are not supported. + Only the first part is used: + + \code + qxtShortcut->setShortcut(QKeySequence("Ctrl+Alt+A,Ctrl+Alt+B")); + Q_ASSERT(qxtShortcut->shortcut() == QKeySequence("Ctrl+Alt+A")); + \endcode + */ +QKeySequence QxtGlobalShortcut::shortcut() const +{ + return QKeySequence(qxt_d().key | qxt_d().mods); +} + +bool QxtGlobalShortcut::setShortcut(const QKeySequence& shortcut) +{ + if (qxt_d().key != 0) + qxt_d().unsetShortcut(); + return qxt_d().setShortcut(shortcut); +} + +/*! + \property QxtGlobalShortcut::enabled + \brief whether the shortcut is enabled + + A disabled shortcut does not get activated. + + The default value is \c true. + + \sa setDisabled() + */ +bool QxtGlobalShortcut::isEnabled() const +{ + return qxt_d().enabled; +} + +void QxtGlobalShortcut::setEnabled(bool enabled) +{ + qxt_d().enabled = enabled; +} + +/*! + Sets the shortcut \a disabled. + + \sa enabled + */ +void QxtGlobalShortcut::setDisabled(bool disabled) +{ + qxt_d().enabled = !disabled; +}