File kdepim-trinity-speed-up-kalarm.patch of Package kdepim3
From c2ad4a056c3fecc0643b92755bc851b2fa299c49 Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Sun, 23 Aug 2015 11:19:11 +0000
Subject: Sped up KAlarm startup mechanism. This resolves bug 1610.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
diff --git a/kalarm/daemon.cpp b/kalarm/daemon.cpp
index c5769f9..842514d 100644
--- a/kalarm/daemon.cpp
+++ b/kalarm/daemon.cpp
@@ -64,21 +64,21 @@ class NotificationHandler : public QObject, virtual public AlarmGuiIface
};
-Daemon* Daemon::mInstance = 0;
-NotificationHandler* Daemon::mDcopHandler = 0;
-QValueList<QString> Daemon::mQueuedEvents;
-QValueList<QString> Daemon::mSavingEvents;
+Daemon* Daemon::mInstance = 0;
+NotificationHandler* Daemon::mDcopHandler = 0;
+QValueList<QString> Daemon::mQueuedEvents;
+QValueList<QString> Daemon::mSavingEvents;
QTimer* Daemon::mStartTimer = 0;
QTimer* Daemon::mRegisterTimer = 0;
QTimer* Daemon::mStatusTimer = 0;
-int Daemon::mStatusTimerCount = 0;
-int Daemon::mStatusTimerInterval;
-int Daemon::mStartTimeout = 0;
-Daemon::Status Daemon::mStatus = Daemon::STOPPED;
-bool Daemon::mRunning = false;
-bool Daemon::mCalendarDisabled = false;
-bool Daemon::mEnableCalPending = false;
-bool Daemon::mRegisterFailMsg = false;
+int Daemon::mStatusTimerCount = 0;
+int Daemon::mStatusTimerInterval;
+int Daemon::mStartTimeout = 0;
+Daemon::Status Daemon::mStatus = Daemon::STOPPED;
+bool Daemon::mRunning = false;
+bool Daemon::mCalendarDisabled = false;
+bool Daemon::mEnableCalPending = false;
+bool Daemon::mRegisterFailMsg = false;
// How frequently to check the daemon's status after starting it.
// This is equal to the length of time we wait after the daemon is registered with DCOP
@@ -655,7 +655,7 @@ int Daemon::maxTimeSinceCheck()
=============================================================================*/
NotificationHandler::NotificationHandler()
- : DCOPObject(NOTIFY_DCOP_OBJECT),
+ : DCOPObject(NOTIFY_DCOP_OBJECT),
QObject()
{
kdDebug(5950) << "NotificationHandler::NotificationHandler()\n";
diff --git a/kalarm/kalarmd/alarmdaemon.cpp b/kalarm/kalarmd/alarmdaemon.cpp
index 3b7f745..573cac0 100644
--- a/kalarm/kalarmd/alarmdaemon.cpp
+++ b/kalarm/kalarmd/alarmdaemon.cpp
@@ -73,23 +73,54 @@ AlarmDaemon::AlarmDaemon(bool autostart, QObject *parent, const char *name)
#ifdef AUTOSTART_KALARM
if (autostart)
{
- /* The alarm daemon is being autostarted.
- * Check if KAlarm needs to be autostarted in the system tray.
+ /* The alarm daemon has been autostarted.
+ * Check if also KAlarm needs to be autostarted (by the daemon) in the system tray.
* This should ideally be handled internally by KAlarm, but is done by kalarmd
- * for the following reason:
- * KAlarm needs to be both session restored and autostarted, but KDE doesn't
- * currently cater properly for this - there is no guarantee that the session
- * restoration activation will come before the autostart activation. If they
- * come in the wrong order, KAlarm won't know that it is supposed to restore
- * itself and instead will simply open a new window.
+ * to correctly handle the cases when KAlarm is restored and when it is autostarted.
+ * If the autostart request comes before the restoring one, KAlarm would not know
+ * that it is supposed to restore itself and instead would simply open a new window.
+ * So we first check if the session has been fully restored by the session manager
+ * and if so we can continue safely. If the session hasn't yet been fully restored
+ * or created, we wait for up to 30 seconds and then continue as normal.
*/
KConfig kaconfig(locate("config", "kalarmrc"));
kaconfig.setGroup(QString::fromLatin1("General"));
autostart = kaconfig.readBoolEntry(AUTOSTART_TRAY, false);
if (autostart)
{
- kdDebug(5900) << "AlarmDaemon::AlarmDaemon(): wait to autostart KAlarm\n";
- QTimer::singleShot(KALARM_AUTOSTART_TIMEOUT * 1000, this, SLOT(autostartKAlarm()));
+ bool done = false;
+ DCOPClient* client = kapp->dcopClient();
+ if (client->isApplicationRegistered("ksmserver"))
+ {
+ QByteArray callData;
+ QCString replyType;
+ QByteArray replyData;
+ for (int i=0; !done && i<KALARM_AUTOSTART_TIMEOUT; ++i)
+ {
+ // Check if the session has been fully created/restored. If not, wait a little and try again
+ if (!kapp->dcopClient()->call("ksmserver", "ksmserver", "startupCompleted()", callData, replyType, replyData) ||
+ replyType != "bool")
+ {
+ done = true; // In case of DCOP call error, just continue normally
+ }
+ else
+ {
+ bool result;
+ QDataStream replyStream(replyData, IO_ReadOnly);
+ replyStream >> result;
+ if (result)
+ {
+ done = true; // Session created/restored ==> continue
+ }
+ else
+ {
+ sleep(1); // Session not yet fully created/restored ==> wait and retry
+ }
+ }
+ }
+ // Give some extra time to KAlarm to be fully restored, then proceed as usual
+ QTimer::singleShot(3000, this, SLOT(autostartKAlarm()));
+ }
}
}
if (!autostart)
--
cgit v0.9.0.2-52-g1de3