23 #include "autostart.h"
26 #include <kdesktopfile.h>
28 #include <kstandarddirs.h>
41 class AutoStartList:
public TQPtrList<AutoStartItem>
47 AutoStart::AutoStart(
bool new_startup )
48 : m_newStartup( new_startup ), m_phase( new_startup ? -1 : 0), m_phasedone(false)
50 m_startList =
new AutoStartList;
51 m_startList->setAutoDelete(
true);
52 KGlobal::dirs()->addResourceType(
"autostart",
"share/autostart");
53 TQString xdgdirs = getenv(
"XDG_CONFIG_DIRS");
54 if (xdgdirs.isEmpty())
57 TQStringList xdgdirslist = TQStringList::split(
':', xdgdirs );
58 for ( TQStringList::Iterator itr = xdgdirslist.begin(); itr != xdgdirslist.end(); ++itr ) {
59 KGlobal::dirs()->addResourceDir(
"autostart", (*itr) +
"/autostart");
63 AutoStart::~AutoStart()
69 AutoStart::setPhase(
int phase)
78 void AutoStart::setPhaseDone()
83 static TQString extractName(TQString path)
85 int i = path.findRev(
'/');
88 i = path.findRev(
'.');
94 static bool startCondition(
const TQString &condition)
96 if (condition.isEmpty())
99 TQStringList list = TQStringList::split(
':', condition,
true);
100 if (list.count() < 4)
102 if (list[0].isEmpty() || list[2].isEmpty())
105 KConfig config(list[0],
true,
false);
106 if (!list[1].isEmpty())
107 config.setGroup(list[1]);
109 bool defaultValue = (list[3].lower() ==
"true");
111 return config.readBoolEntry(list[2], defaultValue);
115 AutoStart::loadAutoStartList()
117 TQStringList files = KGlobal::dirs()->findAllResources(
"xdgconf-autostart",
"*.desktop",
false,
true);
118 TQStringList kdefiles = KGlobal::dirs()->findAllResources(
"autostart",
"*.desktop",
false,
true);
121 for(TQStringList::ConstIterator it = files.begin();
125 KDesktopFile config(*it,
true);
126 if (config.hasKey(
"X-TDE-autostart-condition")) {
127 if (!startCondition(config.readEntry(
"X-TDE-autostart-condition")))
131 if (!startCondition(config.readEntry(
"X-KDE-autostart-condition")))
134 if (!config.tryExec())
136 if (config.readBoolEntry(
"Hidden",
false))
141 bool autostartOverriddenAndDisabled =
false;
142 for(TQStringList::ConstIterator localit = files.begin();
143 localit != files.end();
146 if (((*localit).startsWith(KGlobal::dirs()->localxdgconfdir()) ==
true) || ((*localit).startsWith(KGlobal::dirs()->localkdedir()) ==
true)) {
150 int slashPos = (*it).findRev(
'/', -1, TRUE );
151 if (slashPos == -1) {
155 localOuter = (*it).mid(slashPos+1);
157 slashPos = (*localit).findRev(
'/', -1, TRUE );
158 if (slashPos == -1) {
159 localInner = (*localit);
162 localInner = (*localit).mid(slashPos+1);
164 if (localOuter == localInner) {
167 KDesktopFile innerConfig(*localit,
true);
168 if (innerConfig.readBoolEntry(
"Hidden",
false)) {
170 autostartOverriddenAndDisabled =
true;
176 if (autostartOverriddenAndDisabled ==
true)
179 if (config.hasKey(
"OnlyShowIn"))
181 if ((!config.readListEntry(
"OnlyShowIn",
';').contains(
"TDE")) && (!config.readListEntry(
"OnlyShowIn",
';').contains(
"KDE")))
184 if (config.hasKey(
"NotShowIn"))
186 if ((config.readListEntry(
"NotShowIn",
';').contains(
"TDE")) || (config.readListEntry(
"NotShowIn",
';').contains(
"KDE")))
190 AutoStartItem *item =
new AutoStartItem;
191 item->name = extractName(*it);
193 if (config.hasKey(
"X-TDE-autostart-after"))
194 item->startAfter = config.readEntry(
"X-TDE-autostart-after");
196 item->startAfter = config.readEntry(
"X-KDE-autostart-after");
199 if (config.hasKey(
"X-TDE-autostart-phase"))
200 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 2);
202 item->phase = config.readNumEntry(
"X-KDE-autostart-phase", 2);
208 if (config.hasKey(
"X-TDE-autostart-phase"))
209 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 1);
211 item->phase = config.readNumEntry(
"X-KDE-autostart-phase", 1);
215 m_startList->append(item);
219 TQPtrListIterator<AutoStartItem> it1(*m_startList);
220 TQPtrListIterator<AutoStartItem> it2(*m_startList);
221 AutoStartItem *item1;
222 AutoStartItem *item2;
223 while ((item1 = it1.current()) != 0) {
224 bool dupfound1 =
false;
226 while ((item2 = it2.current()) != 0) {
227 bool dupfound2 =
false;
228 if (item2 != item1) {
229 if (item1->service == item2->service) {
230 m_startList->removeRef(item2);
246 AutoStart::startService()
248 if (m_startList->isEmpty())
251 while(!m_started.isEmpty())
255 TQString lastItem = m_started[0];
256 for(AutoStartItem *item = m_startList->first();
257 item; item = m_startList->next())
259 if (item->phase == m_phase
260 && item->startAfter == lastItem)
262 m_started.prepend(item->name);
263 TQString service = item->service;
264 m_startList->remove();
268 m_started.remove(m_started.begin());
273 for(item = m_startList->first();
274 item; item = m_startList->next())
276 if (item->phase == m_phase
277 && item->startAfter.isEmpty())
279 m_started.prepend(item->name);
280 TQString service = item->service;
281 m_startList->remove();
287 for(item = m_startList->first();
288 item; item = m_startList->next())
290 if (item->phase == m_phase)
292 m_started.prepend(item->name);
293 TQString service = item->service;
294 m_startList->remove();