• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KInit

autostart.cpp

Go to the documentation of this file.
00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #define QT_NO_CAST_FROM_ASCII
00021 #include "autostart.h"
00022 
00023 #include <kautostart.h>
00024 #include <kglobal.h>
00025 #include <kstandarddirs.h>
00026 
00027 class AutoStartItem
00028 {
00029 public:
00030    QString name;
00031    QString service;
00032    QString startAfter;
00033    int     phase;
00034 };
00035 
00036 AutoStart::AutoStart()
00037   : m_phase(-1), m_phasedone(false)
00038 {
00039   m_startList = new AutoStartList;
00040   KGlobal::dirs()->addResourceType("xdgconf-autostart", NULL, "autostart/"); // xdg ones
00041   KGlobal::dirs()->addResourceType("autostart", "xdgconf-autostart", "/"); // merge them
00042   KGlobal::dirs()->addResourceType("autostart", 0, "share/autostart"); // KDE ones are higher priority
00043 }
00044 
00045 AutoStart::~AutoStart()
00046 {
00047   qDeleteAll(*m_startList);
00048   m_startList->clear();
00049   delete m_startList;
00050 }
00051 
00052 void
00053 AutoStart::setPhase(int phase)
00054 {
00055    if (phase > m_phase)
00056    {
00057       m_phase = phase;
00058       m_phasedone = false;
00059    }
00060 }
00061 
00062 void AutoStart::setPhaseDone()
00063 {
00064    m_phasedone = true;
00065 }
00066 
00067 static QString extractName(QString path) // krazy:exclude=passbyvalue
00068 {
00069   int i = path.lastIndexOf(QLatin1Char('/'));
00070   if (i >= 0)
00071      path = path.mid(i+1);
00072   i = path.lastIndexOf(QLatin1Char('.'));
00073   if (i >= 0)
00074      path = path.left(i);
00075   return path;
00076 }
00077 
00078 void
00079 AutoStart::loadAutoStartList()
00080 {
00081    const QStringList files = KGlobal::dirs()->findAllResources("autostart",
00082                                                                QString::fromLatin1("*.desktop"),
00083                                                                KStandardDirs::NoDuplicates);
00084 
00085    for(QStringList::ConstIterator it = files.begin();
00086        it != files.end();
00087        ++it)
00088    {
00089        KAutostart config(*it);
00090        if( !config.autostarts(QString::fromLatin1("KDE"), KAutostart::CheckAll))
00091            continue;
00092 
00093        AutoStartItem *item = new AutoStartItem;
00094        item->name = extractName(*it);
00095        item->service = *it;
00096        item->startAfter = config.startAfter();
00097        item->phase = config.startPhase();
00098        if (item->phase < 0)
00099           item->phase = 0;
00100        m_startList->append(item);
00101    }
00102 }
00103 
00104 QString
00105 AutoStart::startService()
00106 {
00107    if (m_startList->isEmpty())
00108       return QString();
00109 
00110    while(!m_started.isEmpty())
00111    {
00112 
00113      // Check for items that depend on previously started items
00114      QString lastItem = m_started[0];
00115      QMutableListIterator<AutoStartItem *> it(*m_startList);
00116      while (it.hasNext())
00117      {
00118         AutoStartItem *item = it.next();
00119         if (item->phase == m_phase
00120         &&  item->startAfter == lastItem)
00121         {
00122            m_started.prepend(item->name);
00123            QString service = item->service;
00124            it.remove();
00125            delete item;
00126            return service;
00127         }
00128      }
00129      m_started.removeFirst();
00130    }
00131 
00132    // Check for items that don't depend on anything
00133    AutoStartItem *item;
00134    QMutableListIterator<AutoStartItem *> it(*m_startList);
00135    while (it.hasNext())
00136    {
00137       item = it.next();
00138       if (item->phase == m_phase
00139       &&  item->startAfter.isEmpty())
00140       {
00141          m_started.prepend(item->name);
00142          QString service = item->service;
00143          it.remove();
00144          delete item;
00145          return service;
00146       }
00147    }
00148 
00149    // Just start something in this phase
00150    it = *m_startList;
00151    while (it.hasNext())
00152    {
00153       item = it.next();
00154       if (item->phase == m_phase)
00155       {
00156          m_started.prepend(item->name);
00157          QString service = item->service;
00158          it.remove();
00159          delete item;
00160          return service;
00161       }
00162    }
00163 
00164    return QString();
00165 }

KInit

Skip menu "KInit"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal