23 #include "autostart.h"
25 #include <tdeconfig.h>
26 #include <kdesktopfile.h>
27 #include <tdeglobal.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 TDEGlobal::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 TDEGlobal::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 TDEConfig 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 = TDEGlobal::dirs()->findAllResources(
"xdgconf-autostart",
"*.desktop",
false,
true);
118 TQStringList kdefiles = TDEGlobal::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-TDE-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(TDEGlobal::dirs()->localxdgconfdir()) ==
true) || ((*localit).startsWith(TDEGlobal::dirs()->localtdedir()) ==
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 #ifdef WITH_OLD_XDG_STD
182 if ((!config.readListEntry(
"OnlyShowIn",
';').contains(
"TDE")) && (!config.readListEntry(
"OnlyShowIn",
';').contains(
"KDE")))
185 if (!config.readListEntry(
"OnlyShowIn",
';').contains(
"TDE"))
189 if (config.hasKey(
"NotShowIn"))
191 #ifdef WITH_OLD_XDG_STD
192 if ((config.readListEntry(
"NotShowIn",
';').contains(
"TDE")) || (config.readListEntry(
"NotShowIn",
';').contains(
"KDE")))
195 if (config.readListEntry(
"NotShowIn",
';').contains(
"TDE"))
200 AutoStartItem *item =
new AutoStartItem;
201 item->name = extractName(*it);
203 if (config.hasKey(
"X-TDE-autostart-after"))
204 item->startAfter = config.readEntry(
"X-TDE-autostart-after");
206 item->startAfter = config.readEntry(
"X-TDE-autostart-after");
209 if (config.hasKey(
"X-TDE-autostart-phase"))
210 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 2);
212 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 2);
218 if (config.hasKey(
"X-TDE-autostart-phase"))
219 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 1);
221 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 1);
225 m_startList->append(item);
229 TQPtrListIterator<AutoStartItem> it1(*m_startList);
230 TQPtrListIterator<AutoStartItem> it2(*m_startList);
231 AutoStartItem *item1;
232 AutoStartItem *item2;
233 while ((item1 = it1.current()) != 0) {
234 bool dupfound1 =
false;
236 while ((item2 = it2.current()) != 0) {
237 bool dupfound2 =
false;
238 if (item2 != item1) {
239 if (item1->service == item2->service) {
240 m_startList->removeRef(item2);
256 AutoStart::startService()
258 if (m_startList->isEmpty())
261 while(!m_started.isEmpty())
265 TQString lastItem = m_started[0];
266 for(AutoStartItem *item = m_startList->first();
267 item; item = m_startList->next())
269 if (item->phase == m_phase
270 && item->startAfter == lastItem)
272 m_started.prepend(item->name);
273 TQString service = item->service;
274 m_startList->remove();
278 m_started.remove(m_started.begin());
283 for(item = m_startList->first();
284 item; item = m_startList->next())
286 if (item->phase == m_phase
287 && item->startAfter.isEmpty())
289 m_started.prepend(item->name);
290 TQString service = item->service;
291 m_startList->remove();
297 for(item = m_startList->first();
298 item; item = m_startList->next())
300 if (item->phase == m_phase)
302 m_started.prepend(item->name);
303 TQString service = item->service;
304 m_startList->remove();