• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeinit
 

tdeinit

  • tdeinit
autostart.cpp
1/*
2 *
3 * This file is part of the KDE libraries
4 * Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
5 *
6 * $Id$
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License version 2 as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 **/
22
23#include "autostart.h"
24
25#include <tdeconfig.h>
26#include <kdesktopfile.h>
27#include <tdeglobal.h>
28#include <kstandarddirs.h>
29
30#include <stdlib.h>
31
32class AutoStartItem
33{
34public:
35 TQString name;
36 TQString service;
37 TQString startAfter;
38 int phase;
39};
40
41class AutoStartList: public TQPtrList<AutoStartItem>
42{
43public:
44 AutoStartList() { }
45};
46
47AutoStart::AutoStart( bool new_startup )
48 : m_newStartup( new_startup ), m_phase( new_startup ? -1 : 0), m_phasedone(false)
49{
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())
55 xdgdirs = "/etc/xdg";
56
57 TQStringList xdgdirslist = TQStringList::split( ':', xdgdirs );
58 for ( TQStringList::Iterator itr = xdgdirslist.begin(); itr != xdgdirslist.end(); ++itr ) {
59 TDEGlobal::dirs()->addResourceDir("autostart", (*itr) +"/autostart");
60 }
61}
62
63AutoStart::~AutoStart()
64{
65 delete m_startList;
66}
67
68void
69AutoStart::setPhase(int phase)
70{
71 if (phase > m_phase)
72 {
73 m_phase = phase;
74 m_phasedone = false;
75 }
76}
77
78void AutoStart::setPhaseDone()
79{
80 m_phasedone = true;
81}
82
83static TQString extractName(TQString path)
84{
85 int i = path.findRev('/');
86 if (i >= 0)
87 path = path.mid(i+1);
88 i = path.findRev('.');
89 if (i >= 0)
90 path = path.left(i);
91 return path;
92}
93
94static bool startCondition(const TQString &condition)
95{
96 if (condition.isEmpty())
97 return true;
98
99 TQStringList list = TQStringList::split(':', condition, true);
100 if (list.count() < 4)
101 return true;
102 if (list[0].isEmpty() || list[2].isEmpty())
103 return true;
104
105 TDEConfig config(list[0], true, false);
106 if (!list[1].isEmpty())
107 config.setGroup(list[1]);
108
109 bool defaultValue = (list[3].lower() == "true");
110
111 return config.readBoolEntry(list[2], defaultValue);
112}
113
114void
115AutoStart::loadAutoStartList()
116{
117 TQStringList files = TDEGlobal::dirs()->findAllResources("xdgconf-autostart", "*.desktop", false, true);
118 TQStringList kdefiles = TDEGlobal::dirs()->findAllResources("autostart", "*.desktop", false, true);
119 files += kdefiles;
120
121 for(TQStringList::ConstIterator it = files.begin();
122 it != files.end();
123 ++it)
124 {
125 KDesktopFile config(*it, true);
126 if (config.hasKey("X-TDE-autostart-condition")) {
127 if (!startCondition(config.readEntry("X-TDE-autostart-condition")))
128 continue;
129 }
130 else {
131 if (!startCondition(config.readEntry("X-TDE-autostart-condition")))
132 continue;
133 }
134 if (!config.tryExec())
135 continue;
136 if (config.readBoolEntry("Hidden", false))
137 continue;
138
139 // Check to see if the most important ( usually ~/.config/autostart or ~/.trinity/Autostart) XDG directory
140 // has overridden the Hidden directive and honor it if set to True
141 bool autostartOverriddenAndDisabled = false;
142 for(TQStringList::ConstIterator localit = files.begin();
143 localit != files.end();
144 ++localit)
145 {
146 if (((*localit).startsWith(TDEGlobal::dirs()->localxdgconfdir()) == true) || ((*localit).startsWith(TDEGlobal::dirs()->localtdedir()) == true)) {
147 // Same local file name?
148 TQString localOuter;
149 TQString localInner;
150 int slashPos = (*it).findRev( '/', -1, TRUE );
151 if (slashPos == -1) {
152 localOuter = (*it);
153 }
154 else {
155 localOuter = (*it).mid(slashPos+1);
156 }
157 slashPos = (*localit).findRev( '/', -1, TRUE );
158 if (slashPos == -1) {
159 localInner = (*localit);
160 }
161 else {
162 localInner = (*localit).mid(slashPos+1);
163 }
164 if (localOuter == localInner) {
165 // Overridden!
166 // But is Hidden == True?
167 KDesktopFile innerConfig(*localit, true);
168 if (innerConfig.readBoolEntry("Hidden", false)) {
169 // Override confirmed; exit speedily without autostarting
170 autostartOverriddenAndDisabled = true;
171 }
172 }
173 }
174 }
175
176 if (autostartOverriddenAndDisabled == true)
177 continue;
178
179 if (config.hasKey("OnlyShowIn"))
180 {
181#ifdef WITH_OLD_XDG_STD
182 if ((!config.readListEntry("OnlyShowIn", ';').contains("TDE")) && (!config.readListEntry("OnlyShowIn", ';').contains("KDE")))
183 continue;
184#else
185 if (!config.readListEntry("OnlyShowIn", ';').contains("TDE"))
186 continue;
187#endif
188 }
189 if (config.hasKey("NotShowIn"))
190 {
191#ifdef WITH_OLD_XDG_STD
192 if ((config.readListEntry("NotShowIn", ';').contains("TDE")) || (config.readListEntry("NotShowIn", ';').contains("KDE")))
193 continue;
194#else
195 if (config.readListEntry("NotShowIn", ';').contains("TDE"))
196 continue;
197#endif
198 }
199
200 AutoStartItem *item = new AutoStartItem;
201 item->name = extractName(*it);
202 item->service = *it;
203 if (config.hasKey("X-TDE-autostart-after"))
204 item->startAfter = config.readEntry("X-TDE-autostart-after");
205 else
206 item->startAfter = config.readEntry("X-TDE-autostart-after");
207 if( m_newStartup )
208 {
209 if (config.hasKey("X-TDE-autostart-phase"))
210 item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
211 else
212 item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
213 if (item->phase < 0)
214 item->phase = 0;
215 }
216 else
217 {
218 if (config.hasKey("X-TDE-autostart-phase"))
219 item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
220 else
221 item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
222 if (item->phase < 1)
223 item->phase = 1;
224 }
225 m_startList->append(item);
226 }
227
228 // Check for duplicate entries and remove if found
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;
235 it2.toFirst();
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);
241 dupfound1 = true;
242 dupfound2 = true;
243 }
244 }
245 if (!dupfound2) {
246 ++it2;
247 }
248 }
249 if (!dupfound1) {
250 ++it1;
251 }
252 }
253}
254
255TQString
256AutoStart::startService()
257{
258 if (m_startList->isEmpty())
259 return 0;
260
261 while(!m_started.isEmpty())
262 {
263
264 // Check for items that depend on previously started items
265 TQString lastItem = m_started[0];
266 for(AutoStartItem *item = m_startList->first();
267 item; item = m_startList->next())
268 {
269 if (item->phase == m_phase
270 && item->startAfter == lastItem)
271 {
272 m_started.prepend(item->name);
273 TQString service = item->service;
274 m_startList->remove();
275 return service;
276 }
277 }
278 m_started.remove(m_started.begin());
279 }
280
281 // Check for items that don't depend on anything
282 AutoStartItem *item;
283 for(item = m_startList->first();
284 item; item = m_startList->next())
285 {
286 if (item->phase == m_phase
287 && item->startAfter.isEmpty())
288 {
289 m_started.prepend(item->name);
290 TQString service = item->service;
291 m_startList->remove();
292 return service;
293 }
294 }
295
296 // Just start something in this phase
297 for(item = m_startList->first();
298 item; item = m_startList->next())
299 {
300 if (item->phase == m_phase)
301 {
302 m_started.prepend(item->name);
303 TQString service = item->service;
304 m_startList->remove();
305 return service;
306 }
307 }
308
309 return 0;
310}

tdeinit

Skip menu "tdeinit"
  • Main Page
  • File List
  • Related Pages

tdeinit

Skip menu "tdeinit"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeinit by doxygen 1.9.8
This website is maintained by Timothy Pearson.