• 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 
32 class AutoStartItem
33 {
34 public:
35  TQString name;
36  TQString service;
37  TQString startAfter;
38  int phase;
39 };
40 
41 class AutoStartList: public TQPtrList<AutoStartItem>
42 {
43 public:
44  AutoStartList() { }
45 };
46 
47 AutoStart::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 
63 AutoStart::~AutoStart()
64 {
65  delete m_startList;
66 }
67 
68 void
69 AutoStart::setPhase(int phase)
70 {
71  if (phase > m_phase)
72  {
73  m_phase = phase;
74  m_phasedone = false;
75  }
76 }
77 
78 void AutoStart::setPhaseDone()
79 {
80  m_phasedone = true;
81 }
82 
83 static 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 
94 static 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 
114 void
115 AutoStart::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(); it != files.end(); ++it)
122  {
123  // Explicitly skip autostart files from KDE
124  if ((*it).contains("org.kde") || (*it).startsWith("/etc/kde/xdg/autostart"))
125  {
126  continue;
127  }
128  KDesktopFile config(*it, true);
129  if (config.hasKey("X-TDE-autostart-condition")) {
130  if (!startCondition(config.readEntry("X-TDE-autostart-condition")))
131  continue;
132  }
133  else if (config.hasKey("X-KDE-autostart-condition")) {
134  if (!startCondition(config.readEntry("X-KDE-autostart-condition")))
135  continue;
136  }
137  if (!config.tryExec())
138  continue;
139  if (config.readBoolEntry("Hidden", false))
140  continue;
141 
142  // Check to see if the most important ( usually ~/.config/autostart or ~/.trinity/Autostart) XDG directory
143  // has overridden the Hidden directive and honor it if set to True
144  bool autostartOverriddenAndDisabled = false;
145  for(TQStringList::ConstIterator localit = files.begin();
146  localit != files.end();
147  ++localit)
148  {
149  if (((*localit).startsWith(TDEGlobal::dirs()->localxdgconfdir()) == true) || ((*localit).startsWith(TDEGlobal::dirs()->localtdedir()) == true)) {
150  // Same local file name?
151  TQString localOuter;
152  TQString localInner;
153  int slashPos = (*it).findRev( '/', -1, TRUE );
154  if (slashPos == -1) {
155  localOuter = (*it);
156  }
157  else {
158  localOuter = (*it).mid(slashPos+1);
159  }
160  slashPos = (*localit).findRev( '/', -1, TRUE );
161  if (slashPos == -1) {
162  localInner = (*localit);
163  }
164  else {
165  localInner = (*localit).mid(slashPos+1);
166  }
167  if (localOuter == localInner) {
168  // Overridden!
169  // But is Hidden == True?
170  KDesktopFile innerConfig(*localit, true);
171  if (innerConfig.readBoolEntry("Hidden", false)) {
172  // Override confirmed; exit speedily without autostarting
173  autostartOverriddenAndDisabled = true;
174  }
175  }
176  }
177  }
178 
179  if (autostartOverriddenAndDisabled == true)
180  continue;
181 
182  if (config.hasKey("OnlyShowIn"))
183  {
184  if (!config.readListEntry("OnlyShowIn", ';').contains("TDE"))
185  continue;
186  }
187  if (config.hasKey("NotShowIn"))
188  {
189  if (config.readListEntry("NotShowIn", ';').contains("TDE") ||
190  config.readListEntry("NotShowIn", ';').contains("KDE"))
191  continue;
192  }
193 
194  AutoStartItem *item = new AutoStartItem;
195  item->name = extractName(*it);
196  item->service = *it;
197  if (config.hasKey("X-TDE-autostart-after"))
198  item->startAfter = config.readEntry("X-TDE-autostart-after");
199  else
200  item->startAfter = config.readEntry("X-KDE-autostart-after");
201  if( m_newStartup )
202  {
203  if (config.hasKey("X-TDE-autostart-phase"))
204  item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
205  else
206  item->phase = config.readNumEntry("X-KDE-autostart-phase", 2);
207  if (item->phase < 0)
208  item->phase = 0;
209  }
210  else
211  {
212  if (config.hasKey("X-TDE-autostart-phase"))
213  item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
214  else
215  item->phase = config.readNumEntry("X-KDE-autostart-phase", 1);
216  if (item->phase < 1)
217  item->phase = 1;
218  }
219  m_startList->append(item);
220  }
221 
222  // Check for duplicate entries and remove if found
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;
229  it2.toFirst();
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);
235  dupfound1 = true;
236  dupfound2 = true;
237  }
238  }
239  if (!dupfound2) {
240  ++it2;
241  }
242  }
243  if (!dupfound1) {
244  ++it1;
245  }
246  }
247 }
248 
249 TQString
250 AutoStart::startService()
251 {
252  if (m_startList->isEmpty())
253  return 0;
254 
255  while(!m_started.isEmpty())
256  {
257 
258  // Check for items that depend on previously started items
259  TQString lastItem = m_started[0];
260  for(AutoStartItem *item = m_startList->first();
261  item; item = m_startList->next())
262  {
263  if (item->phase == m_phase
264  && item->startAfter == lastItem)
265  {
266  m_started.prepend(item->name);
267  TQString service = item->service;
268  m_startList->remove();
269  return service;
270  }
271  }
272  m_started.remove(m_started.begin());
273  }
274 
275  // Check for items that don't depend on anything
276  AutoStartItem *item;
277  for(item = m_startList->first();
278  item; item = m_startList->next())
279  {
280  if (item->phase == m_phase
281  && item->startAfter.isEmpty())
282  {
283  m_started.prepend(item->name);
284  TQString service = item->service;
285  m_startList->remove();
286  return service;
287  }
288  }
289 
290  // Just start something in this phase
291  for(item = m_startList->first();
292  item; item = m_startList->next())
293  {
294  if (item->phase == m_phase)
295  {
296  m_started.prepend(item->name);
297  TQString service = item->service;
298  m_startList->remove();
299  return service;
300  }
301  }
302 
303  return 0;
304 }

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.1
This website is maintained by Timothy Pearson.