2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "autostart.h"
23 #include <kconfiggroup.h>
24 #include <kdesktopfile.h>
26 #include <kstandarddirs.h>
37 AutoStart::AutoStart()
38 : m_phase(-1), m_phasedone(false)
40 m_startList
= new AutoStartList
;
41 KGlobal::dirs()->addResourceType("xdgconf-autostart", NULL
, "autostart/"); // xdg ones
42 KGlobal::dirs()->addResourceType("autostart", "xdgconf-autostart", "/"); // merge them
43 KGlobal::dirs()->addResourceType("autostart", 0, "share/autostart"); // KDE ones are higher priority
46 AutoStart::~AutoStart()
48 qDeleteAll(*m_startList
);
54 AutoStart::setPhase(int phase
)
63 void AutoStart::setPhaseDone()
68 static QString
extractName(QString path
) // krazy:exclude=passbyvalue
70 int i
= path
.lastIndexOf('/');
73 i
= path
.lastIndexOf('.');
79 static bool startCondition(const QString
&condition
)
81 if (condition
.isEmpty())
84 QStringList list
= condition
.split(':');
87 if (list
[0].isEmpty() || list
[2].isEmpty())
90 KConfig
config(list
[0], KConfig::NoGlobals
);
91 KConfigGroup
cg(&config
, list
[1]);
93 bool defaultValue
= (list
[3].toLower() == "true");
95 return cg
.readEntry(list
[2], defaultValue
);
99 AutoStart::loadAutoStartList()
101 const QStringList files
= KGlobal::dirs()->findAllResources("autostart", "*.desktop", KStandardDirs::NoDuplicates
);
103 for(QStringList::ConstIterator it
= files
.begin();
107 KDesktopFile
config(*it
);
108 const KConfigGroup grp
= config
.desktopGroup();
109 if (!startCondition(grp
.readEntry("X-KDE-autostart-condition")))
111 if (!config
.tryExec())
113 if (grp
.readEntry("Hidden", false))
115 if (config
.noDisplay()) // handles OnlyShowIn, NotShowIn (and NoDisplay, but that's not used here)
118 AutoStartItem
*item
= new AutoStartItem
;
119 item
->name
= extractName(*it
);
121 item
->startAfter
= grp
.readEntry("X-KDE-autostart-after");
122 item
->phase
= grp
.readEntry("X-KDE-autostart-phase", 2);
125 m_startList
->append(item
);
130 AutoStart::startService()
132 if (m_startList
->isEmpty())
135 while(!m_started
.isEmpty())
138 // Check for items that depend on previously started items
139 QString lastItem
= m_started
[0];
140 QMutableListIterator
<AutoStartItem
*> it(*m_startList
);
143 AutoStartItem
*item
= it
.next();
144 if (item
->phase
== m_phase
145 && item
->startAfter
== lastItem
)
147 m_started
.prepend(item
->name
);
148 QString service
= item
->service
;
154 m_started
.removeFirst();
157 // Check for items that don't depend on anything
159 QMutableListIterator
<AutoStartItem
*> it(*m_startList
);
163 if (item
->phase
== m_phase
164 && item
->startAfter
.isEmpty())
166 m_started
.prepend(item
->name
);
167 QString service
= item
->service
;
174 // Just start something in this phase
179 if (item
->phase
== m_phase
)
181 m_started
.prepend(item
->name
);
182 QString service
= item
->service
;