• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kinit
 

kinit

autostart.cpp
00001 /*
00002  *
00003  *  This file is part of the KDE libraries
00004  *  Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
00005  *
00006  * $Id$
00007  *
00008  *  This library is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU Library General Public
00010  *  License version 2 as published by the Free Software Foundation.
00011  *
00012  *  This library is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *  Library General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU Library General Public License
00018  *  along with this library; see the file COPYING.LIB.  If not, write to
00019  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  *  Boston, MA 02110-1301, USA.
00021  **/
00022 
00023 #include "autostart.h"
00024 
00025 #include <kconfig.h>
00026 #include <kdesktopfile.h>
00027 #include <kglobal.h>
00028 #include <kstandarddirs.h>
00029 
00030 #include <stdlib.h>
00031 
00032 class AutoStartItem
00033 {
00034 public:
00035    TQString name;
00036    TQString service;
00037    TQString startAfter;
00038    int     phase;
00039 };
00040 
00041 class AutoStartList: public TQPtrList<AutoStartItem>
00042 {
00043 public:
00044    AutoStartList() { }
00045 };
00046 
00047 AutoStart::AutoStart( bool new_startup )
00048   : m_newStartup( new_startup ), m_phase( new_startup ? -1 : 0), m_phasedone(false)
00049 {
00050   m_startList = new AutoStartList;
00051   m_startList->setAutoDelete(true);
00052   KGlobal::dirs()->addResourceType("autostart", "share/autostart");
00053   TQString xdgdirs = getenv("XDG_CONFIG_DIRS");
00054   if (xdgdirs.isEmpty())
00055         xdgdirs = "/etc/xdg";
00056 
00057   TQStringList xdgdirslist = TQStringList::split( ':', xdgdirs );
00058   for ( TQStringList::Iterator itr = xdgdirslist.begin(); itr != xdgdirslist.end(); ++itr ) {
00059     KGlobal::dirs()->addResourceDir("autostart", (*itr) +"/autostart");
00060   }
00061 }
00062 
00063 AutoStart::~AutoStart()
00064 {
00065     delete m_startList;
00066 }
00067 
00068 void
00069 AutoStart::setPhase(int phase)
00070 {
00071    if (phase > m_phase)
00072    {
00073       m_phase = phase;
00074       m_phasedone = false;
00075    }
00076 }
00077 
00078 void AutoStart::setPhaseDone()
00079 {
00080    m_phasedone = true;
00081 }
00082 
00083 static TQString extractName(TQString path)
00084 {
00085   int i = path.findRev('/');
00086   if (i >= 0)
00087      path = path.mid(i+1);
00088   i = path.findRev('.');
00089   if (i >= 0)
00090      path = path.left(i);
00091   return path;
00092 }
00093 
00094 static bool startCondition(const TQString &condition)
00095 {
00096   if (condition.isEmpty())
00097      return true;
00098 
00099   TQStringList list = TQStringList::split(':', condition, true);
00100   if (list.count() < 4) 
00101      return true;
00102   if (list[0].isEmpty() || list[2].isEmpty()) 
00103      return true;
00104 
00105   KConfig config(list[0], true, false);
00106   if (!list[1].isEmpty())
00107      config.setGroup(list[1]);
00108 
00109   bool defaultValue = (list[3].lower() == "true");
00110 
00111   return config.readBoolEntry(list[2], defaultValue);
00112 }
00113 
00114 void
00115 AutoStart::loadAutoStartList()
00116 {
00117    TQStringList files = KGlobal::dirs()->findAllResources("xdgconf-autostart", "*.desktop", false, true);
00118    TQStringList kdefiles = KGlobal::dirs()->findAllResources("autostart", "*.desktop", false, true);
00119    files += kdefiles;
00120    
00121    for(TQStringList::ConstIterator it = files.begin();
00122        it != files.end();
00123        ++it)
00124    {
00125        KDesktopFile config(*it, true);
00126        if (config.hasKey("X-TDE-autostart-condition")) {
00127            if (!startCondition(config.readEntry("X-TDE-autostart-condition")))
00128               continue;
00129        }
00130        else {
00131            if (!startCondition(config.readEntry("X-KDE-autostart-condition")))
00132               continue;
00133        }
00134        if (!config.tryExec())
00135           continue;
00136        if (config.readBoolEntry("Hidden", false))
00137           continue;
00138 
00139        // Check to see if the most important ( usually ~/.config/autostart or ~/.trinity/Autostart) XDG directory
00140        // has overridden the Hidden directive and honor it if set to True
00141        bool autostartOverriddenAndDisabled = false;
00142        for(TQStringList::ConstIterator localit = files.begin();
00143            localit != files.end();
00144            ++localit)
00145        {
00146            if (((*localit).startsWith(KGlobal::dirs()->localxdgconfdir()) == true) || ((*localit).startsWith(KGlobal::dirs()->localkdedir()) == true)) {
00147                // Same local file name?
00148                TQString localOuter;
00149                TQString localInner;
00150                int slashPos = (*it).findRev( '/', -1, TRUE );
00151                if (slashPos == -1) {
00152                    localOuter = (*it);
00153                }
00154                else {
00155                    localOuter = (*it).mid(slashPos+1);
00156                }
00157                slashPos = (*localit).findRev( '/', -1, TRUE );
00158                if (slashPos == -1) {
00159                    localInner = (*localit);
00160                }
00161                else {
00162                    localInner = (*localit).mid(slashPos+1);
00163                }
00164                if (localOuter == localInner) {
00165                    // Overridden!
00166                    // But is Hidden == True?
00167                    KDesktopFile innerConfig(*localit, true);
00168                    if (innerConfig.readBoolEntry("Hidden", false)) {
00169                        // Override confirmed; exit speedily without autostarting
00170                        autostartOverriddenAndDisabled = true;
00171                    }
00172                }
00173            }
00174        }
00175 
00176        if (autostartOverriddenAndDisabled == true)
00177            continue;
00178 
00179        if (config.hasKey("OnlyShowIn"))
00180        {
00181           if ((!config.readListEntry("OnlyShowIn", ';').contains("TDE")) && (!config.readListEntry("OnlyShowIn", ';').contains("KDE")))
00182               continue;
00183        }
00184        if (config.hasKey("NotShowIn"))
00185        {
00186            if ((config.readListEntry("NotShowIn", ';').contains("TDE")) || (config.readListEntry("NotShowIn", ';').contains("KDE")))
00187                continue;
00188        }
00189 
00190        AutoStartItem *item = new AutoStartItem;
00191        item->name = extractName(*it);
00192        item->service = *it;
00193        if (config.hasKey("X-TDE-autostart-after"))
00194            item->startAfter = config.readEntry("X-TDE-autostart-after");
00195        else
00196            item->startAfter = config.readEntry("X-KDE-autostart-after");
00197        if( m_newStartup )
00198        {
00199           if (config.hasKey("X-TDE-autostart-phase"))
00200               item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
00201           else
00202               item->phase = config.readNumEntry("X-KDE-autostart-phase", 2);
00203           if (item->phase < 0)
00204              item->phase = 0;
00205        }
00206        else
00207        {
00208           if (config.hasKey("X-TDE-autostart-phase"))
00209               item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
00210           else
00211               item->phase = config.readNumEntry("X-KDE-autostart-phase", 1);
00212           if (item->phase < 1)
00213              item->phase = 1;
00214        }
00215        m_startList->append(item);
00216    }
00217 
00218    // Check for duplicate entries and remove if found
00219    TQPtrListIterator<AutoStartItem> it1(*m_startList);
00220    TQPtrListIterator<AutoStartItem> it2(*m_startList);
00221    AutoStartItem *item1;
00222    AutoStartItem *item2;
00223    while ((item1 = it1.current()) != 0) {
00224        bool dupfound1 = false;
00225        it2.toFirst();
00226        while ((item2 = it2.current()) != 0) {
00227            bool dupfound2 = false;
00228            if (item2 != item1) {
00229                if (item1->service == item2->service) {
00230                    m_startList->removeRef(item2);
00231                    dupfound1 = true;
00232                    dupfound2 = true;
00233                }
00234            }
00235            if (!dupfound2) {
00236                ++it2;
00237            }
00238        }
00239        if (!dupfound1) {
00240            ++it1;
00241        }
00242    }
00243 }
00244 
00245 TQString
00246 AutoStart::startService()
00247 {
00248    if (m_startList->isEmpty())
00249       return 0;
00250 
00251    while(!m_started.isEmpty())
00252    {
00253 
00254      // Check for items that depend on previously started items
00255      TQString lastItem = m_started[0];
00256      for(AutoStartItem *item = m_startList->first(); 
00257          item; item = m_startList->next())
00258      {
00259         if (item->phase == m_phase
00260         &&  item->startAfter == lastItem)
00261         {
00262            m_started.prepend(item->name);
00263            TQString service = item->service;
00264            m_startList->remove();
00265            return service;
00266         }
00267      }
00268      m_started.remove(m_started.begin());
00269    }
00270 
00271    // Check for items that don't depend on anything
00272    AutoStartItem *item;
00273    for(item = m_startList->first();
00274        item; item = m_startList->next())
00275    {
00276       if (item->phase == m_phase
00277       &&  item->startAfter.isEmpty())
00278       {
00279          m_started.prepend(item->name);
00280          TQString service = item->service;
00281          m_startList->remove();
00282          return service;
00283       }
00284    }
00285 
00286    // Just start something in this phase
00287    for(item = m_startList->first();
00288        item; item = m_startList->next())
00289    {
00290       if (item->phase == m_phase)
00291       {
00292          m_started.prepend(item->name);
00293          TQString service = item->service;
00294          m_startList->remove();
00295          return service;
00296       }
00297    }
00298 
00299    return 0;
00300 }

kinit

Skip menu "kinit"
  • Main Page
  • File List
  • Related Pages

kinit

Skip menu "kinit"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kinit by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |