26#include <kdesktopfile.h>
28#include <kstandarddirs.h>
41class AutoStartList:
public TQPtrList<AutoStartItem>
47AutoStart::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");
63AutoStart::~AutoStart()
69AutoStart::setPhase(
int phase)
78void AutoStart::setPhaseDone()
83static TQString extractName(TQString path)
85 int i = path.findRev(
'/');
88 i = path.findRev(
'.');
94static 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);
115AutoStart::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"))
193 AutoStartItem *item =
new AutoStartItem;
194 item->name = extractName(*it);
196 if (config.hasKey(
"X-TDE-autostart-after"))
197 item->startAfter = config.readEntry(
"X-TDE-autostart-after");
199 item->startAfter = config.readEntry(
"X-KDE-autostart-after");
202 if (config.hasKey(
"X-TDE-autostart-phase"))
203 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 2);
205 item->phase = config.readNumEntry(
"X-KDE-autostart-phase", 2);
211 if (config.hasKey(
"X-TDE-autostart-phase"))
212 item->phase = config.readNumEntry(
"X-TDE-autostart-phase", 1);
214 item->phase = config.readNumEntry(
"X-KDE-autostart-phase", 1);
218 m_startList->append(item);
222 TQPtrListIterator<AutoStartItem> it1(*m_startList);
223 TQPtrListIterator<AutoStartItem> it2(*m_startList);
224 AutoStartItem *item1;
225 AutoStartItem *item2;
226 while ((item1 = it1.current()) != 0) {
227 bool dupfound1 =
false;
229 while ((item2 = it2.current()) != 0) {
230 bool dupfound2 =
false;
231 if (item2 != item1) {
232 if (item1->service == item2->service) {
233 m_startList->removeRef(item2);
249AutoStart::startService()
251 if (m_startList->isEmpty())
254 while(!m_started.isEmpty())
258 TQString lastItem = m_started[0];
259 for(AutoStartItem *item = m_startList->first();
260 item; item = m_startList->next())
262 if (item->phase == m_phase
263 && item->startAfter == lastItem)
265 m_started.prepend(item->name);
266 TQString service = item->service;
267 m_startList->remove();
271 m_started.remove(m_started.begin());
276 for(item = m_startList->first();
277 item; item = m_startList->next())
279 if (item->phase == m_phase
280 && item->startAfter.isEmpty())
282 m_started.prepend(item->name);
283 TQString service = item->service;
284 m_startList->remove();
290 for(item = m_startList->first();
291 item; item = m_startList->next())
293 if (item->phase == m_phase)
295 m_started.prepend(item->name);
296 TQString service = item->service;
297 m_startList->remove();