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

kinit

  • kinit
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 <kconfig.h>
26 #include <kdesktopfile.h>
27 #include <kglobal.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  KGlobal::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  KGlobal::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  KConfig 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 = KGlobal::dirs()->findAllResources("xdgconf-autostart", "*.desktop", false, true);
118  TQStringList kdefiles = KGlobal::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-KDE-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(KGlobal::dirs()->localxdgconfdir()) == true) || ((*localit).startsWith(KGlobal::dirs()->localkdedir()) == 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  if ((!config.readListEntry("OnlyShowIn", ';').contains("TDE")) && (!config.readListEntry("OnlyShowIn", ';').contains("KDE")))
182  continue;
183  }
184  if (config.hasKey("NotShowIn"))
185  {
186  if ((config.readListEntry("NotShowIn", ';').contains("TDE")) || (config.readListEntry("NotShowIn", ';').contains("KDE")))
187  continue;
188  }
189 
190  AutoStartItem *item = new AutoStartItem;
191  item->name = extractName(*it);
192  item->service = *it;
193  if (config.hasKey("X-TDE-autostart-after"))
194  item->startAfter = config.readEntry("X-TDE-autostart-after");
195  else
196  item->startAfter = config.readEntry("X-KDE-autostart-after");
197  if( m_newStartup )
198  {
199  if (config.hasKey("X-TDE-autostart-phase"))
200  item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
201  else
202  item->phase = config.readNumEntry("X-KDE-autostart-phase", 2);
203  if (item->phase < 0)
204  item->phase = 0;
205  }
206  else
207  {
208  if (config.hasKey("X-TDE-autostart-phase"))
209  item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
210  else
211  item->phase = config.readNumEntry("X-KDE-autostart-phase", 1);
212  if (item->phase < 1)
213  item->phase = 1;
214  }
215  m_startList->append(item);
216  }
217 
218  // Check for duplicate entries and remove if found
219  TQPtrListIterator<AutoStartItem> it1(*m_startList);
220  TQPtrListIterator<AutoStartItem> it2(*m_startList);
221  AutoStartItem *item1;
222  AutoStartItem *item2;
223  while ((item1 = it1.current()) != 0) {
224  bool dupfound1 = false;
225  it2.toFirst();
226  while ((item2 = it2.current()) != 0) {
227  bool dupfound2 = false;
228  if (item2 != item1) {
229  if (item1->service == item2->service) {
230  m_startList->removeRef(item2);
231  dupfound1 = true;
232  dupfound2 = true;
233  }
234  }
235  if (!dupfound2) {
236  ++it2;
237  }
238  }
239  if (!dupfound1) {
240  ++it1;
241  }
242  }
243 }
244 
245 TQString
246 AutoStart::startService()
247 {
248  if (m_startList->isEmpty())
249  return 0;
250 
251  while(!m_started.isEmpty())
252  {
253 
254  // Check for items that depend on previously started items
255  TQString lastItem = m_started[0];
256  for(AutoStartItem *item = m_startList->first();
257  item; item = m_startList->next())
258  {
259  if (item->phase == m_phase
260  && item->startAfter == lastItem)
261  {
262  m_started.prepend(item->name);
263  TQString service = item->service;
264  m_startList->remove();
265  return service;
266  }
267  }
268  m_started.remove(m_started.begin());
269  }
270 
271  // Check for items that don't depend on anything
272  AutoStartItem *item;
273  for(item = m_startList->first();
274  item; item = m_startList->next())
275  {
276  if (item->phase == m_phase
277  && item->startAfter.isEmpty())
278  {
279  m_started.prepend(item->name);
280  TQString service = item->service;
281  m_startList->remove();
282  return service;
283  }
284  }
285 
286  // Just start something in this phase
287  for(item = m_startList->first();
288  item; item = m_startList->next())
289  {
290  if (item->phase == m_phase)
291  {
292  m_started.prepend(item->name);
293  TQString service = item->service;
294  m_startList->remove();
295  return service;
296  }
297  }
298 
299  return 0;
300 }

kinit

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

kinit

Skip menu "kinit"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kinit by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |