From bd90ba9326593d9b800a6c0a58fee2780b6726dd Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Fri, 2 Nov 2012 15:33:39 +0100 Subject: [PATCH] Move initial auto-type timeout to plugins. --- src/autotype/AutoType.cpp | 5 +---- src/autotype/AutoType.h | 1 - src/autotype/AutoTypePlatformPlugin.h | 1 + src/autotype/test/AutoTypeTest.cpp | 4 ++++ src/autotype/test/AutoTypeTest.h | 1 + src/autotype/x11/AutoTypeX11.cpp | 5 +++++ src/autotype/x11/AutoTypeX11.h | 1 + src/core/Tools.cpp | 6 +++++- 8 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 67cb17cf7..7cfba262e 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -34,7 +34,6 @@ AutoType* AutoType::m_instance = Q_NULLPTR; AutoType::AutoType(QObject* parent, bool test) : QObject(parent) - , m_test(test) , m_inAutoType(false) , m_pluginLoader(new QPluginLoader(this)) , m_plugin(Q_NULLPTR) @@ -133,9 +132,7 @@ void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow, const QS hideWindow->showMinimized(); } - if (!m_test) { - Tools::wait(500); - } + Tools::wait(m_plugin->initialTimeout()); if (!window) { window = m_plugin->activeWindow(); diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h index 26e8c8abc..51b6a540a 100644 --- a/src/autotype/AutoType.h +++ b/src/autotype/AutoType.h @@ -69,7 +69,6 @@ private: QString autoTypeSequence(const Entry* entry, const QString& windowTitle = QString()); bool windowMatches(const QString& windowTitle, const QString& windowPattern); - bool m_test; bool m_inAutoType; Qt::Key m_currentGlobalKey; Qt::KeyboardModifiers m_currentGlobalModifiers; diff --git a/src/autotype/AutoTypePlatformPlugin.h b/src/autotype/AutoTypePlatformPlugin.h index bf8b5c47a..28115393b 100644 --- a/src/autotype/AutoTypePlatformPlugin.h +++ b/src/autotype/AutoTypePlatformPlugin.h @@ -32,6 +32,7 @@ public: virtual bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) = 0; virtual void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) = 0; virtual int platformEventFilter(void* event) = 0; + virtual int initialTimeout() = 0; virtual AutoTypeExecutor* createExecutor() = 0; diff --git a/src/autotype/test/AutoTypeTest.cpp b/src/autotype/test/AutoTypeTest.cpp index a6ff22dbf..d48d17fe0 100644 --- a/src/autotype/test/AutoTypeTest.cpp +++ b/src/autotype/test/AutoTypeTest.cpp @@ -98,6 +98,10 @@ void AutoTypePlatformTest::addActionKey(AutoTypeKey* action) m_actionChars.append(keyToString(action->key)); } +int AutoTypePlatformTest::initialTimeout() +{ + return 0; +} AutoTypeExecturorTest::AutoTypeExecturorTest(AutoTypePlatformTest* platform) : m_platform(platform) diff --git a/src/autotype/test/AutoTypeTest.h b/src/autotype/test/AutoTypeTest.h index 4bcd1e705..cda9397c9 100644 --- a/src/autotype/test/AutoTypeTest.h +++ b/src/autotype/test/AutoTypeTest.h @@ -41,6 +41,7 @@ public: bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); int platformEventFilter(void* event); + int initialTimeout(); AutoTypeExecutor* createExecutor(); void setActiveWindowTitle(const QString& title); diff --git a/src/autotype/x11/AutoTypeX11.cpp b/src/autotype/x11/AutoTypeX11.cpp index a39f73085..9a0755275 100644 --- a/src/autotype/x11/AutoTypeX11.cpp +++ b/src/autotype/x11/AutoTypeX11.cpp @@ -798,4 +798,9 @@ void AutoTypeExecturorX11::execKey(AutoTypeKey* action) m_platform->SendKeyPressedEvent(m_platform->keyToKeySym(action->key)); } +int AutoTypePlatformX11::initialTimeout() +{ + return 500; +} + Q_EXPORT_PLUGIN2(keepassx-autotype-x11, AutoTypePlatformX11) diff --git a/src/autotype/x11/AutoTypeX11.h b/src/autotype/x11/AutoTypeX11.h index 744a553a4..ab8e9cfb3 100644 --- a/src/autotype/x11/AutoTypeX11.h +++ b/src/autotype/x11/AutoTypeX11.h @@ -45,6 +45,7 @@ public: bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); int platformEventFilter(void* event); + int initialTimeout(); AutoTypeExecutor* createExecutor(); KeySym charToKeySym(const QChar& ch); diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index fb48e0fe8..c0525e7b1 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -178,7 +178,11 @@ void sleep(int ms) void wait(int ms) { - Q_ASSERT(ms > 0); + Q_ASSERT(ms >= 0); + + if (ms == 0) { + return; + } #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) QElapsedTimer timer;