summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-08-26 14:51:21 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-09-05 13:52:11 (GMT)
commitdbb1f8b0216db246039bedbe11009b9d2637bc85 (patch)
treed7d6f6421a1b7258e38712379ed3b0d9c96c95f7
parentdd39faa6f4c5b4d534c03546cc7a60e1d68c7dcd (diff)
Do heavy init work only after uniqueservice call
Moving the heavy init stuff like keycache init below the uniqueservice creation saves resources and fixes ghosting systray icons when multiple calls are done and forwarded to the unique instance of the application. The speed up on Windows is noticable (> 200ms).
-rw-r--r--src/kleopatraapplication.cpp32
-rw-r--r--src/kleopatraapplication.h10
-rw-r--r--src/main.cpp6
3 files changed, 37 insertions, 11 deletions
diff --git a/src/kleopatraapplication.cpp b/src/kleopatraapplication.cpp
index f3e8ec5..203a4c8 100644
--- a/src/kleopatraapplication.cpp
+++ b/src/kleopatraapplication.cpp
@@ -106,17 +106,22 @@ public:
: q(qq),
ignoreNewInstance(true)
{
+ }
+ ~Private() {
+ delete sysTray;
+ }
+ void init()
+ {
KDAB_SET_OBJECT_NAME(readerStatus);
#ifndef QT_NO_SYSTEMTRAYICON
- KDAB_SET_OBJECT_NAME(sysTray);
-
- sysTray.setAnyCardHasNullPin(readerStatus.anyCardHasNullPin());
- sysTray.setAnyCardCanLearnKeys(readerStatus.anyCardCanLearnKeys());
+ sysTray = new SysTrayIcon();
+ sysTray->setAnyCardHasNullPin(readerStatus.anyCardHasNullPin());
+ sysTray->setAnyCardCanLearnKeys(readerStatus.anyCardCanLearnKeys());
connect(&readerStatus, &SmartCard::ReaderStatus::anyCardHasNullPinChanged,
- &sysTray, &SysTrayIcon::setAnyCardHasNullPin);
+ sysTray, &SysTrayIcon::setAnyCardHasNullPin);
connect(&readerStatus, &SmartCard::ReaderStatus::anyCardCanLearnKeysChanged,
- &sysTray, &SysTrayIcon::setAnyCardCanLearnKeys);
+ sysTray, &SysTrayIcon::setAnyCardCanLearnKeys);
#endif
}
@@ -140,7 +145,7 @@ public:
QPointer<MainWindow> mainWindow;
SmartCard::ReaderStatus readerStatus;
#ifndef QT_NO_SYSTEMTRAYICON
- SysTrayIcon sysTray;
+ SysTrayIcon *sysTray;
#endif
shared_ptr<KeyCache> keyCache;
shared_ptr<Log> log;
@@ -197,11 +202,16 @@ public:
KleopatraApplication::KleopatraApplication(int &argc, char *argv[])
: QApplication(argc, argv), d(new Private(this))
{
+}
+
+void KleopatraApplication::init()
+{
+ d->init();
add_resources();
d->setupKeyCache();
d->setupLogging();
#ifndef QT_NO_SYSTEMTRAYICON
- d->sysTray.show();
+ d->sysTray->show();
#endif
setQuitOnLastWindowClosed(false);
KWindowSystem::allowExternalProcessWindowActivation();
@@ -386,12 +396,12 @@ QString KleopatraApplication::newInstance(const QCommandLineParser &parser,
#ifndef QT_NO_SYSTEMTRAYICON
const SysTrayIcon *KleopatraApplication::sysTrayIcon() const
{
- return &d->sysTray;
+ return d->sysTray;
}
SysTrayIcon *KleopatraApplication::sysTrayIcon()
{
- return &d->sysTray;
+ return d->sysTray;
}
#endif
@@ -415,7 +425,7 @@ void KleopatraApplication::setMainWindow(MainWindow *mainWindow)
d->mainWindow = mainWindow;
#ifndef QT_NO_SYSTEMTRAYICON
- d->sysTray.setMainWindow(mainWindow);
+ d->sysTray->setMainWindow(mainWindow);
#endif
d->connectConfigureDialog();
diff --git a/src/kleopatraapplication.h b/src/kleopatraapplication.h
index f4022db..dc1fa8f 100644
--- a/src/kleopatraapplication.h
+++ b/src/kleopatraapplication.h
@@ -47,9 +47,19 @@ class KleopatraApplication : public QApplication
{
Q_OBJECT
public:
+ /** Create a new Application obejct. You have to
+ * make sure to call init afterwards to get a valid object.
+ * This is to delay initialisation after the UniqueService
+ * call is done and our init / call might be forwarded to
+ * another instance. */
KleopatraApplication(int &argc, char *argv[]);
~KleopatraApplication();
+ /** Initialize the application. Without calling init any
+ * other call to KleopatraApplication will result in undefined behavior
+ * and likely crash. */
+ void init();
+
static KleopatraApplication *instance()
{
return qobject_cast<KleopatraApplication *>(qApp);
diff --git a/src/main.cpp b/src/main.cpp
index 9d83e89..2fd02fb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -139,6 +139,12 @@ int main(int argc, char **argv)
&service, [&service](int i) {
service.setExitValue(i);
});
+ // Delay init after KUniqueservice call as this might already
+ // have terminated us and so we can avoid overhead (e.g. keycache
+ // setup / systray icon).
+ qCDebug(KLEOPATRA_LOG) << "Startup timing:" << timer.elapsed() << "ms elapsed: Service created";
+ app.init();
+ qCDebug(KLEOPATRA_LOG) << "Startup timing:" << timer.elapsed() << "ms elapsed: Application initialized";
AboutData aboutData;