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(); it != files.end(); ++it)
124 if ((*it).contains(
"org.kde") || (*it).startsWith(
"/etc/kde/xdg/autostart"))
128 KDesktopFile config(*it,
true);
129 if (config.hasKey(
"X-TDE-autostart-condition")) {
130 if (!startCondition(config.readEntry(
"X-TDE-autostart-condition")))
133 else if (config.hasKey(
"X-KDE-autostart-condition")) {
134 if (!startCondition(config.readEntry(
"X-KDE-autostart-condition")))
137 if (!config.tryExec())
139 if (config.readBoolEntry(
"Hidden",
false))
144 bool autostartOverriddenAndDisabled =
false;
145 for(TQStringList::ConstIterator localit = files.begin();
146 localit != files.end();
149 if (((*localit).startsWith(TDEGlobal::dirs()->localxdgconfdir()) ==
true) || ((*localit).startsWith(TDEGlobal::dirs()->localtdedir()) ==
true)) {
153 int slashPos = (*it).findRev(
'/', -1, TRUE );
154 if (slashPos == -1) {
158 localOuter = (*it).mid(slashPos+1);
160 slashPos = (*localit).findRev(
'/', -1, TRUE );
161 if (slashPos == -1) {
162 localInner = (*localit);
165 localInner = (*localit).mid(slashPos+1);
167 if (localOuter == localInner) {
170 KDesktopFile innerConfig(*localit,
true);
171 if (innerConfig.readBoolEntry(
"Hidden",
false)) {
173 autostartOverriddenAndDisabled =
true;
179 if (autostartOverriddenAndDisabled ==
true)
182 if (config.hasKey(
"OnlyShowIn"))
184 if (!config.readListEntry(
"OnlyShowIn",
';').contains(
"TDE"))
187 if (config.hasKey(
"NotShowIn"))
189 if (config.readListEntry(
"NotShowIn",
';').contains(
"TDE") ||
190 config.readListEntry(
"NotShowIn",
';').contains(
"KDE"))
194 AutoStartItem *item =
new AutoStartItem;
195 item->name = extractName(*it);
197 if (config.hasKey(
"X-TDE-autostart-after"))
198 item->startAfter = config.readEntry(
"X-TDE-autostart-after");
200 item->startAfter = config.readEntry(
"X-KDE-autostart-after");
203 if (config.hasKey(
"X-TDE-autostart-phase"))
204 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 2);
206 item->phase = config.readNumEntry(
"X-KDE-autostart-phase", 2);
212 if (config.hasKey(
"X-TDE-autostart-phase"))
213 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 1);
215 item->phase = config.readNumEntry(
"X-KDE-autostart-phase", 1);
219 m_startList->append(item);
223 TQPtrListIterator<AutoStartItem> it1(*m_startList);
224 TQPtrListIterator<AutoStartItem> it2(*m_startList);
225 AutoStartItem *item1;
226 AutoStartItem *item2;
227 while ((item1 = it1.current()) != 0) {
228 bool dupfound1 =
false;
230 while ((item2 = it2.current()) != 0) {
231 bool dupfound2 =
false;
232 if (item2 != item1) {
233 if (item1->service == item2->service) {
234 m_startList->removeRef(item2);
250 AutoStart::startService()
252 if (m_startList->isEmpty())
255 while(!m_started.isEmpty())
259 TQString lastItem = m_started[0];
260 for(AutoStartItem *item = m_startList->first();
261 item; item = m_startList->next())
263 if (item->phase == m_phase
264 && item->startAfter == lastItem)
266 m_started.prepend(item->name);
267 TQString service = item->service;
268 m_startList->remove();
272 m_started.remove(m_started.begin());
277 for(item = m_startList->first();
278 item; item = m_startList->next())
280 if (item->phase == m_phase
281 && item->startAfter.isEmpty())
283 m_started.prepend(item->name);
284 TQString service = item->service;
285 m_startList->remove();
291 for(item = m_startList->first();
292 item; item = m_startList->next())
294 if (item->phase == m_phase)
296 m_started.prepend(item->name);
297 TQString service = item->service;
298 m_startList->remove();