[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: FEATURE: Startup sequence reorder
From:       Lubos Lunak <l.lunak () suse ! cz>
Date:       2006-04-25 13:32:27
Message-ID: 200604251532.28213.l.lunak () suse ! cz
[Download RAW message or body]

On Tuesday 25 April 2006 13:58, Lubos Lunak wrote:
> On Sunday 23 April 2006 22:38, David Faure wrote:
> > >  Pros: Startup may be really borken if people try without matching
> > > kdelibs and kdebase (hello Debian), something may potentially start a
> > > bit too late.
> >
> > Yep. Startup was completely broken when I installed kdelibs and didn't
> > install kdebase yet. You had warned about that, but my machine locked up
> > while compiling kdebase and after a reboot I couldn't start kde anymore
> > so I had to finish compiling kdebase in the text tty before being able to
> > start kde again.... I guess there's no chance to make this more robust,
> > i.e. to make kde still start, although still slowly, in case only kdelibs
> > is updated?
>
>  Well, the startup-related code is more or less rewritten (rearranged
> rather), so I guess I'd have to keep separate paths for both cases. On the
> other hand the kdelibs part of the part is quite small, so I could try
> supporting kdelibs-3.5.3+kdebase-3.5.2 (which should be the more sensible
> case anyway).

 Ok, wasn't that difficult, kdeinit, kded and klauncher take --new-startup, 
which makes them execute either the old or new code path (well-visible in the 
nowhitespace version of the patch). I simply ignored i18n() for the added 
KCmdLineArg's as they're internal anyway. New kdebase obviously will require 
new kdelibs. Okay now?

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak@suse.cz , l.lunak@kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/

["kdelibs.patch" (text/x-diff)]

--- kdelibs/kinit/autostart.cpp.sav	2006-04-25 13:58:59.000000000 +0200
+++ kdelibs/kinit/autostart.cpp	2006-04-25 14:32:05.000000000 +0200
@@ -42,8 +42,8 @@ public:
    AutoStartList() { }
 };
 
-AutoStart::AutoStart()
-  : m_phase(0), m_phasedone(false)
+AutoStart::AutoStart( bool new_startup )
+  : m_newStartup( new_startup ), m_phase( new_startup ? -1 : 0), m_phasedone(false)
 {
   m_startList = new AutoStartList;
   m_startList->setAutoDelete(true);
@@ -133,9 +133,18 @@ AutoStart::loadAutoStartList()
        item->name = extractName(*it);
        item->service = *it;
        item->startAfter = config.readEntry("X-KDE-autostart-after");
-       item->phase = config.readNumEntry("X-KDE-autostart-phase", 1);
-       if (item->phase < 1)
-          item->phase = 1;
+       if( m_newStartup )
+       {
+          item->phase = config.readNumEntry("X-KDE-autostart-phase", 2);
+          if (item->phase < 0)
+             item->phase = 0;
+       }
+       else
+       {
+          item->phase = config.readNumEntry("X-KDE-autostart-phase", 1);
+          if (item->phase < 1)
+             item->phase = 1;
+       }
        m_startList->append(item);
    }
 } 
--- kdelibs/kinit/klauncher.cpp.sav	2006-04-25 13:58:59.000000000 +0200
+++ kdelibs/kinit/klauncher.cpp	2006-04-25 14:37:11.000000000 +0200
@@ -162,10 +162,11 @@ IdleSlave::age(time_t now)
    return (int) difftime(now, mBirthDate);
 }
 
-KLauncher::KLauncher(int _kdeinitSocket)
+KLauncher::KLauncher(int _kdeinitSocket, bool new_startup)
   : KApplication( false, false ), // No Styles, No GUI
     DCOPObject("klauncher"),
-    kdeinitSocket(_kdeinitSocket), dontBlockReading(false)
+    kdeinitSocket(_kdeinitSocket), mAutoStart( new_startup ),
+    dontBlockReading(false), newStartup( new_startup )
 {
 #ifdef Q_WS_X11
    mCached_dpy = NULL;
@@ -674,8 +675,16 @@ KLauncher::autoStart(int phase)
    if( mAutoStart.phase() >= phase )
        return;
    mAutoStart.setPhase(phase);
-   if (phase == 1)
-      mAutoStart.loadAutoStartList();
+   if( newStartup )
+   {
+      if (phase == 0)
+         mAutoStart.loadAutoStartList();
+   }
+   else
+   {
+      if (phase == 1)
+         mAutoStart.loadAutoStartList();
+   }
    mAutoTimer.start(0, true);
 }
 
@@ -693,11 +702,20 @@ KLauncher::slotAutoStart()
 	 {
 	    mAutoStart.setPhaseDone();
 	    // Emit signal
-	    QCString autoStartSignal( "autoStartDone()" );
-	    int phase = mAutoStart.phase();
-	    if ( phase > 1 )
-	        autoStartSignal.sprintf( "autoStart%dDone()", phase );
-            emitDCOPSignal(autoStartSignal, QByteArray());
+            if( newStartup )
+            {
+	       QCString autoStartSignal;
+               autoStartSignal.sprintf( "autoStart%dDone()", mAutoStart.phase());
+               emitDCOPSignal(autoStartSignal, QByteArray());
+            }
+            else
+            {
+	       QCString autoStartSignal( "autoStartDone()" );
+	       int phase = mAutoStart.phase();
+	       if ( phase > 1 )
+	           autoStartSignal.sprintf( "autoStart%dDone()", phase );
+               emitDCOPSignal(autoStartSignal, QByteArray());
+            }
 	 }
          return;
       }
--- kdelibs/kinit/kinit.cpp.sav	2006-04-13 14:00:40.000000000 +0200
+++ kdelibs/kinit/kinit.cpp	2006-04-25 14:08:21.000000000 +0200
@@ -1651,6 +1651,7 @@ int main(int argc, char **argv, char **e
    int launch_klauncher = 1;
    int launch_kded = 1;
    int keep_running = 1;
+   int new_startup = 0;
    d.suicide = false;
 
    /** Save arguments first... **/
@@ -1668,6 +1669,8 @@ int main(int argc, char **argv, char **e
          d.suicide = true;
       if (strcmp(safe_argv[i], "--exit") == 0)
          keep_running = 0;
+      if (strcmp(safe_argv[i], "--new-startup") == 0)
+         new_startup = 1;
       if (strcmp(safe_argv[i], "--help") == 0)
       {
         printf("Usage: kdeinit [options]\n");
@@ -1768,7 +1771,10 @@ int main(int argc, char **argv, char **e
 #endif 
    if (launch_klauncher)
    {
-      pid = launch( 1, "klauncher", 0 );
+      if( new_startup )
+         pid = launch( 2, "klauncher", "--new-startup" );
+      else
+         pid = launch( 1, "klauncher", 0 );
 #ifndef NDEBUG
       fprintf(stderr, "kdeinit: Launched KLauncher, pid = %ld result = %d\n", (long) pid, d.result);
 #endif
@@ -1803,7 +1809,10 @@ int main(int argc, char **argv, char **e
 
    if (launch_kded)
    {
-      pid = launch( 1, "kded", 0 );
+      if( new_startup )
+         pid = launch( 2, "kded", "--new-startup" );
+      else
+         pid = launch( 1, "kded", 0 );
 #ifndef NDEBUG
       fprintf(stderr, "kdeinit: Launched KDED, pid = %ld result = %d\n", (long) pid, d.result);
 #endif
--- kdelibs/kinit/klauncher_main.cpp.sav	2005-09-29 21:31:28.000000000 +0200
+++ kdelibs/kinit/klauncher_main.cpp	2006-04-25 14:26:48.000000000 +0200
@@ -44,6 +44,12 @@ fprintf(stderr, "klauncher: Exiting on s
    KLauncher::destruct(255);
 }
 
+static KCmdLineOptions options[] =
+{
+  { "new-startup", "Internal", 0 },
+  KCmdLineLastOption
+};
+
 extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
 {
    // Started via kdeinit.
@@ -60,6 +66,7 @@ extern "C" KDE_EXPORT int kdemain( int a
                        "v1.0");
 
    KLauncher::addCmdLineOptions();
+   KCmdLineArgs::addCmdLineOptions( options );
 
    // WABA: Make sure not to enable session management.
    putenv(strdup("SESSION_MANAGER="));
@@ -67,6 +74,8 @@ extern "C" KDE_EXPORT int kdemain( int a
    // Allow the locale to initialize properly
    KLocale::setMainCatalogue("kdelibs");
 
+   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
    int maxTry = 3;
    while(true)
    {
@@ -92,7 +101,7 @@ extern "C" KDE_EXPORT int kdemain( int a
       // Try again...
    }
    
-   KLauncher *launcher = new KLauncher(LAUNCHER_FD);
+   KLauncher *launcher = new KLauncher(LAUNCHER_FD, args->isSet("new-startup"));
    launcher->dcopClient()->setDefaultObject( name );
    launcher->dcopClient()->setDaemonMode( true );
 
--- kdelibs/kinit/klauncher.h.sav	2005-09-29 21:31:28.000000000 +0200
+++ kdelibs/kinit/klauncher.h	2006-04-25 14:27:09.000000000 +0200
@@ -110,7 +110,7 @@ class KLauncher : public KApplication, p
    Q_OBJECT
 
 public:
-   KLauncher(int _kdeinitSocket);
+   KLauncher(int _kdeinitSocket, bool new_startup);
 
    ~KLauncher();
 
@@ -192,6 +192,7 @@ protected:
    QCString mSlaveValgrind;
    QCString mSlaveValgrindSkin;
    bool dontBlockReading;
+   bool newStartup;
 #ifdef Q_WS_X11
    Display *mCached_dpy;
 #endif
--- kdelibs/kinit/autostart.h.sav	2005-09-29 21:31:28.000000000 +0200
+++ kdelibs/kinit/autostart.h	2006-04-25 14:30:43.000000000 +0200
@@ -27,7 +27,7 @@ class AutoStartList;
 class AutoStart
 {
 public:
-  AutoStart();
+  AutoStart( bool new_startup );
   ~AutoStart();
     
   void loadAutoStartList();
@@ -38,6 +38,7 @@ public:
   bool    phaseDone() const { return m_phasedone; }
 
 private:
+  bool m_newStartup;
   AutoStartList *m_startList;  
   QStringList m_started;
   int m_phase;
--- kdelibs/kded/kded.cpp.sav	2006-04-25 13:58:59.000000000 +0200
+++ kdelibs/kded/kded.cpp	2006-04-25 14:36:38.000000000 +0200
@@ -96,10 +96,11 @@ static void runDontChangeHostname(const 
    KApplication::kdeinitExecWait( "kdontchangethehostname", args );
 }
 
-Kded::Kded(bool checkUpdates)
+Kded::Kded(bool checkUpdates, bool new_startup)
   : DCOPObject("kbuildsycoca"), DCOPObjectProxy(),
     b_checkUpdates(checkUpdates),
-    m_needDelayedCheck(false)
+    m_needDelayedCheck(false),
+    m_newStartup( new_startup )
 {
   _self = this;
   QCString cPath;
@@ -162,9 +163,33 @@ void Kded::initModules()
          bool autoload = service->property("X-KDE-Kded-autoload", QVariant::Bool).toBool();
          config->setGroup(QString("Module-%1").arg(service->desktopEntryName()));
          autoload = config->readBoolEntry("autoload", autoload);
-         if (autoload && kde_running)
-            loadModule(service, false);
-
+         if( m_newStartup )
+         {
+            // see ksmserver's README for description of the phases
+            QVariant phasev = service->property("X-KDE-Kded-phase", QVariant::Int );
+            int phase = phasev.isValid() ? phasev.toInt() : 2;
+            bool prevent_autoload = false;
+            switch( phase )
+            {
+                case 0: // always autoload
+                    break;
+                case 1: // autoload only in KDE
+                    if( !kde_running )
+                        prevent_autoload = true;
+                    break;
+                case 2: // autoload delayed, only in KDE
+                default:
+                    prevent_autoload = true;
+                    break;   
+            }
+            if (autoload && !prevent_autoload)
+               loadModule(service, false);
+         }
+         else
+         {
+            if (autoload && kde_running)
+               loadModule(service, false);
+         }
          bool dontLoad = false;
          QVariant p = service->property("X-KDE-Kded-load-on-demand", QVariant::Bool);
          if (p.isValid() && (p.toBool() == false))
@@ -177,6 +202,23 @@ void Kded::initModules()
      }
 }
 
+void Kded::loadSecondPhase()
+{
+     kdDebug(7020) << "Loading second phase autoload" << endl;
+     KConfig *config = kapp->config();
+     KService::List kdedModules = KServiceType::offers("KDEDModule");
+     for(KService::List::ConstIterator it = kdedModules.begin(); it != kdedModules.end(); ++it)
+     {
+         KService::Ptr service = *it;
+         bool autoload = service->property("X-KDE-Kded-autoload", QVariant::Bool).toBool();
+         config->setGroup(QString("Module-%1").arg(service->desktopEntryName()));
+         autoload = config->readBoolEntry("autoload", autoload);
+         QVariant phasev = service->property("X-KDE-Kded-phase", QVariant::Int );
+         int phase = phasev.isValid() ? phasev.toInt() : 2;
+         if( phase == 2 && autoload )
+            loadModule(service, false);
+     }
+}
 
 void Kded::noDemandLoad(const QString &obj)
 {
@@ -671,6 +713,7 @@ void KHostnameD::checkHostname()
 static KCmdLineOptions options[] =
 {
   { "check", I18N_NOOP("Check Sycoca database only once"), 0 },
+  { "new-startup", "Internal", 0 },
   KCmdLineLastOption
 };
 
@@ -713,7 +756,10 @@ public:
     {
        if (startup) {
           startup = false;
-	  QTimer::singleShot(500, Kded::self(), SLOT(initModules()));
+          if( Kded::self()->newStartup())
+             Kded::self()->initModules();
+          else
+	     QTimer::singleShot(500, Kded::self(), SLOT(initModules()));
        } else 
           runBuildSycoca();
 
@@ -729,6 +775,7 @@ public:
        res += "void unregisterWindowId(long int)";
        res += "QCStringList loadedModules()";
        res += "void reconfigure()";
+       res += "void loadSecondPhase()";
        res += "void quit()";
        return res;
     }
@@ -786,6 +833,11 @@ public:
       replyType = "void";
       return true;
     }
+    else if (fun == "loadSecondPhase()") {
+      Kded::self()->loadSecondPhase();
+      replyType = "void";
+      return true;
+    }
     else if (fun == "quit()") {
       quit();
       replyType = "void";
@@ -860,7 +912,7 @@ extern "C" KDE_EXPORT int kdemain(int ar
      checkStamps = config->readBoolEntry("CheckFileStamps", true);
      delayedCheck = config->readBoolEntry("DelayedCheck", false);
 
-     Kded *kded = new Kded(bCheckSycoca); // Build data base
+     Kded *kded = new Kded(bCheckSycoca, args->isSet("new-startup")); // Build data base
 
      signal(SIGTERM, sighandler);
      signal(SIGHUP, sighandler);
--- kdelibs/kded/kded.h.sav	2006-04-25 13:58:59.000000000 +0200
+++ kdelibs/kded/kded.h	2006-04-25 14:36:31.000000000 +0200
@@ -42,7 +42,7 @@ class Kded : public QObject, public DCOP
 {
   Q_OBJECT
 public:
-   Kded(bool checkUpdates);
+   Kded(bool checkUpdates, bool new_startup);
    virtual ~Kded();
 
    static Kded *self() { return _self;}
@@ -72,6 +72,7 @@ public:
    void registerWindowId(long windowId);
    void unregisterWindowId(long windowId);
    void recreate(bool initial);
+   void loadSecondPhase();
 
 public slots:
    /**
@@ -164,6 +165,10 @@ protected:
    QIntDict<long> m_globalWindowIdList;
    QStringList m_allResourceDirs;
    bool m_needDelayedCheck;
+   bool m_newStartup;
+public:
+   bool newStartup() const { return m_newStartup; }
+private:
      
    static Kded *_self;
 };

["kdelibs_nows.patch" (text/x-diff)]

--- kdelibs/kinit/autostart.cpp.sav	2006-04-25 13:58:59.000000000 +0200
+++ kdelibs/kinit/autostart.cpp	2006-04-25 14:32:05.000000000 +0200
@@ -42,8 +42,8 @@ public:
    AutoStartList() { }
 };
 
-AutoStart::AutoStart()
-  : m_phase(0), m_phasedone(false)
+AutoStart::AutoStart( bool new_startup )
+  : m_newStartup( new_startup ), m_phase( new_startup ? -1 : 0), m_phasedone(false)
 {
   m_startList = new AutoStartList;
   m_startList->setAutoDelete(true);
@@ -133,9 +133,18 @@ AutoStart::loadAutoStartList()
        item->name = extractName(*it);
        item->service = *it;
        item->startAfter = config.readEntry("X-KDE-autostart-after");
+       if( m_newStartup )
+       {
+          item->phase = config.readNumEntry("X-KDE-autostart-phase", 2);
+          if (item->phase < 0)
+             item->phase = 0;
+       }
+       else
+       {
        item->phase = config.readNumEntry("X-KDE-autostart-phase", 1);
        if (item->phase < 1)
           item->phase = 1;
+       }
        m_startList->append(item);
    }
 } 
--- kdelibs/kinit/klauncher.cpp.sav	2006-04-25 13:58:59.000000000 +0200
+++ kdelibs/kinit/klauncher.cpp	2006-04-25 14:37:11.000000000 +0200
@@ -162,10 +162,11 @@ IdleSlave::age(time_t now)
    return (int) difftime(now, mBirthDate);
 }
 
-KLauncher::KLauncher(int _kdeinitSocket)
+KLauncher::KLauncher(int _kdeinitSocket, bool new_startup)
   : KApplication( false, false ), // No Styles, No GUI
     DCOPObject("klauncher"),
-    kdeinitSocket(_kdeinitSocket), dontBlockReading(false)
+    kdeinitSocket(_kdeinitSocket), mAutoStart( new_startup ),
+    dontBlockReading(false), newStartup( new_startup )
 {
 #ifdef Q_WS_X11
    mCached_dpy = NULL;
@@ -674,8 +675,16 @@ KLauncher::autoStart(int phase)
    if( mAutoStart.phase() >= phase )
        return;
    mAutoStart.setPhase(phase);
+   if( newStartup )
+   {
+      if (phase == 0)
+         mAutoStart.loadAutoStartList();
+   }
+   else
+   {
    if (phase == 1)
       mAutoStart.loadAutoStartList();
+   }
    mAutoTimer.start(0, true);
 }
 
@@ -693,12 +702,21 @@ KLauncher::slotAutoStart()
 	 {
 	    mAutoStart.setPhaseDone();
 	    // Emit signal
+            if( newStartup )
+            {
+	       QCString autoStartSignal;
+               autoStartSignal.sprintf( "autoStart%dDone()", mAutoStart.phase());
+               emitDCOPSignal(autoStartSignal, QByteArray());
+            }
+            else
+            {
 	    QCString autoStartSignal( "autoStartDone()" );
 	    int phase = mAutoStart.phase();
 	    if ( phase > 1 )
 	        autoStartSignal.sprintf( "autoStart%dDone()", phase );
             emitDCOPSignal(autoStartSignal, QByteArray());
 	 }
+	 }
          return;
       }
       s = new KService(service);
--- kdelibs/kinit/kinit.cpp.sav	2006-04-13 14:00:40.000000000 +0200
+++ kdelibs/kinit/kinit.cpp	2006-04-25 14:08:21.000000000 +0200
@@ -1651,6 +1651,7 @@ int main(int argc, char **argv, char **e
    int launch_klauncher = 1;
    int launch_kded = 1;
    int keep_running = 1;
+   int new_startup = 0;
    d.suicide = false;
 
    /** Save arguments first... **/
@@ -1668,6 +1669,8 @@ int main(int argc, char **argv, char **e
          d.suicide = true;
       if (strcmp(safe_argv[i], "--exit") == 0)
          keep_running = 0;
+      if (strcmp(safe_argv[i], "--new-startup") == 0)
+         new_startup = 1;
       if (strcmp(safe_argv[i], "--help") == 0)
       {
         printf("Usage: kdeinit [options]\n");
@@ -1768,6 +1771,9 @@ int main(int argc, char **argv, char **e
 #endif 
    if (launch_klauncher)
    {
+      if( new_startup )
+         pid = launch( 2, "klauncher", "--new-startup" );
+      else
       pid = launch( 1, "klauncher", 0 );
 #ifndef NDEBUG
       fprintf(stderr, "kdeinit: Launched KLauncher, pid = %ld result = %d\n", (long) pid, d.result);
@@ -1803,6 +1809,9 @@ int main(int argc, char **argv, char **e
 
    if (launch_kded)
    {
+      if( new_startup )
+         pid = launch( 2, "kded", "--new-startup" );
+      else
       pid = launch( 1, "kded", 0 );
 #ifndef NDEBUG
       fprintf(stderr, "kdeinit: Launched KDED, pid = %ld result = %d\n", (long) pid, d.result);
--- kdelibs/kinit/klauncher_main.cpp.sav	2005-09-29 21:31:28.000000000 +0200
+++ kdelibs/kinit/klauncher_main.cpp	2006-04-25 14:26:48.000000000 +0200
@@ -44,6 +44,12 @@ fprintf(stderr, "klauncher: Exiting on s
    KLauncher::destruct(255);
 }
 
+static KCmdLineOptions options[] =
+{
+  { "new-startup", "Internal", 0 },
+  KCmdLineLastOption
+};
+
 extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
 {
    // Started via kdeinit.
@@ -60,6 +66,7 @@ extern "C" KDE_EXPORT int kdemain( int a
                        "v1.0");
 
    KLauncher::addCmdLineOptions();
+   KCmdLineArgs::addCmdLineOptions( options );
 
    // WABA: Make sure not to enable session management.
    putenv(strdup("SESSION_MANAGER="));
@@ -67,6 +74,8 @@ extern "C" KDE_EXPORT int kdemain( int a
    // Allow the locale to initialize properly
    KLocale::setMainCatalogue("kdelibs");
 
+   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
    int maxTry = 3;
    while(true)
    {
@@ -92,7 +101,7 @@ extern "C" KDE_EXPORT int kdemain( int a
       // Try again...
    }
    
-   KLauncher *launcher = new KLauncher(LAUNCHER_FD);
+   KLauncher *launcher = new KLauncher(LAUNCHER_FD, args->isSet("new-startup"));
    launcher->dcopClient()->setDefaultObject( name );
    launcher->dcopClient()->setDaemonMode( true );
 
--- kdelibs/kinit/klauncher.h.sav	2005-09-29 21:31:28.000000000 +0200
+++ kdelibs/kinit/klauncher.h	2006-04-25 14:27:09.000000000 +0200
@@ -110,7 +110,7 @@ class KLauncher : public KApplication, p
    Q_OBJECT
 
 public:
-   KLauncher(int _kdeinitSocket);
+   KLauncher(int _kdeinitSocket, bool new_startup);
 
    ~KLauncher();
 
@@ -192,6 +192,7 @@ protected:
    QCString mSlaveValgrind;
    QCString mSlaveValgrindSkin;
    bool dontBlockReading;
+   bool newStartup;
 #ifdef Q_WS_X11
    Display *mCached_dpy;
 #endif
--- kdelibs/kinit/autostart.h.sav	2005-09-29 21:31:28.000000000 +0200
+++ kdelibs/kinit/autostart.h	2006-04-25 14:30:43.000000000 +0200
@@ -27,7 +27,7 @@ class AutoStartList;
 class AutoStart
 {
 public:
-  AutoStart();
+  AutoStart( bool new_startup );
   ~AutoStart();
     
   void loadAutoStartList();
@@ -38,6 +38,7 @@ public:
   bool    phaseDone() const { return m_phasedone; }
 
 private:
+  bool m_newStartup;
   AutoStartList *m_startList;  
   QStringList m_started;
   int m_phase;
--- kdelibs/kded/kded.cpp.sav	2006-04-25 13:58:59.000000000 +0200
+++ kdelibs/kded/kded.cpp	2006-04-25 14:36:38.000000000 +0200
@@ -96,10 +96,11 @@ static void runDontChangeHostname(const 
    KApplication::kdeinitExecWait( "kdontchangethehostname", args );
 }
 
-Kded::Kded(bool checkUpdates)
+Kded::Kded(bool checkUpdates, bool new_startup)
   : DCOPObject("kbuildsycoca"), DCOPObjectProxy(),
     b_checkUpdates(checkUpdates),
-    m_needDelayedCheck(false)
+    m_needDelayedCheck(false),
+    m_newStartup( new_startup )
 {
   _self = this;
   QCString cPath;
@@ -162,9 +163,33 @@ void Kded::initModules()
          bool autoload = service->property("X-KDE-Kded-autoload", QVariant::Bool).toBool();
          config->setGroup(QString("Module-%1").arg(service->desktopEntryName()));
          autoload = config->readBoolEntry("autoload", autoload);
+         if( m_newStartup )
+         {
+            // see ksmserver's README for description of the phases
+            QVariant phasev = service->property("X-KDE-Kded-phase", QVariant::Int );
+            int phase = phasev.isValid() ? phasev.toInt() : 2;
+            bool prevent_autoload = false;
+            switch( phase )
+            {
+                case 0: // always autoload
+                    break;
+                case 1: // autoload only in KDE
+                    if( !kde_running )
+                        prevent_autoload = true;
+                    break;
+                case 2: // autoload delayed, only in KDE
+                default:
+                    prevent_autoload = true;
+                    break;   
+            }
+            if (autoload && !prevent_autoload)
+               loadModule(service, false);
+         }
+         else
+         {
          if (autoload && kde_running)
             loadModule(service, false);
-
+         }
          bool dontLoad = false;
          QVariant p = service->property("X-KDE-Kded-load-on-demand", QVariant::Bool);
          if (p.isValid() && (p.toBool() == false))
@@ -177,6 +202,23 @@ void Kded::initModules()
      }
 }
 
+void Kded::loadSecondPhase()
+{
+     kdDebug(7020) << "Loading second phase autoload" << endl;
+     KConfig *config = kapp->config();
+     KService::List kdedModules = KServiceType::offers("KDEDModule");
+     for(KService::List::ConstIterator it = kdedModules.begin(); it != kdedModules.end(); ++it)
+     {
+         KService::Ptr service = *it;
+         bool autoload = service->property("X-KDE-Kded-autoload", QVariant::Bool).toBool();
+         config->setGroup(QString("Module-%1").arg(service->desktopEntryName()));
+         autoload = config->readBoolEntry("autoload", autoload);
+         QVariant phasev = service->property("X-KDE-Kded-phase", QVariant::Int );
+         int phase = phasev.isValid() ? phasev.toInt() : 2;
+         if( phase == 2 && autoload )
+            loadModule(service, false);
+     }
+}
 
 void Kded::noDemandLoad(const QString &obj)
 {
@@ -671,6 +713,7 @@ void KHostnameD::checkHostname()
 static KCmdLineOptions options[] =
 {
   { "check", I18N_NOOP("Check Sycoca database only once"), 0 },
+  { "new-startup", "Internal", 0 },
   KCmdLineLastOption
 };
 
@@ -713,6 +756,9 @@ public:
     {
        if (startup) {
           startup = false;
+          if( Kded::self()->newStartup())
+             Kded::self()->initModules();
+          else
 	  QTimer::singleShot(500, Kded::self(), SLOT(initModules()));
        } else 
           runBuildSycoca();
@@ -729,6 +775,7 @@ public:
        res += "void unregisterWindowId(long int)";
        res += "QCStringList loadedModules()";
        res += "void reconfigure()";
+       res += "void loadSecondPhase()";
        res += "void quit()";
        return res;
     }
@@ -786,6 +833,11 @@ public:
       replyType = "void";
       return true;
     }
+    else if (fun == "loadSecondPhase()") {
+      Kded::self()->loadSecondPhase();
+      replyType = "void";
+      return true;
+    }
     else if (fun == "quit()") {
       quit();
       replyType = "void";
@@ -860,7 +912,7 @@ extern "C" KDE_EXPORT int kdemain(int ar
      checkStamps = config->readBoolEntry("CheckFileStamps", true);
      delayedCheck = config->readBoolEntry("DelayedCheck", false);
 
-     Kded *kded = new Kded(bCheckSycoca); // Build data base
+     Kded *kded = new Kded(bCheckSycoca, args->isSet("new-startup")); // Build data base
 
      signal(SIGTERM, sighandler);
      signal(SIGHUP, sighandler);
--- kdelibs/kded/kded.h.sav	2006-04-25 13:58:59.000000000 +0200
+++ kdelibs/kded/kded.h	2006-04-25 14:36:31.000000000 +0200
@@ -42,7 +42,7 @@ class Kded : public QObject, public DCOP
 {
   Q_OBJECT
 public:
-   Kded(bool checkUpdates);
+   Kded(bool checkUpdates, bool new_startup);
    virtual ~Kded();
 
    static Kded *self() { return _self;}
@@ -72,6 +72,7 @@ public:
    void registerWindowId(long windowId);
    void unregisterWindowId(long windowId);
    void recreate(bool initial);
+   void loadSecondPhase();
 
 public slots:
    /**
@@ -164,6 +165,10 @@ protected:
    QIntDict<long> m_globalWindowIdList;
    QStringList m_allResourceDirs;
    bool m_needDelayedCheck;
+   bool m_newStartup;
+public:
+   bool newStartup() const { return m_newStartup; }
+private:
      
    static Kded *_self;
 };

["startkde.patch" (text/x-diff)]

--- startkde.sav	2006-04-13 14:46:00.000000000 +0200
+++ startkde	2006-04-25 14:53:38.000000000 +0200
@@ -287,7 +287,7 @@ export KDE_FULL_SESSION
 
 # We set LD_BIND_NOW to increase the efficiency of kdeinit.
 # kdeinit unsets this variable before loading applications.
-LD_BIND_NOW=true kdeinit +kcminit_startup
+LD_BIND_NOW=true kdeinit --new-startup +kcminit_startup
 if test $? -ne 0; then
   # Startup error
   echo 'startkde: Could not start kdeinit. Check your installation.'  1>&2


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic