• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KInit

  • sources
  • kde-4.14
  • kdelibs
  • kinit
autostart.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #define QT_NO_CAST_FROM_ASCII
21 #include "autostart.h"
22 
23 #include <kautostart.h>
24 #include <kglobal.h>
25 #include <kstandarddirs.h>
26 
27 class AutoStartItem
28 {
29 public:
30  QString name;
31  QString service;
32  QString startAfter;
33  int phase;
34 };
35 
36 AutoStart::AutoStart()
37  : m_phase(-1), m_phasedone(false)
38 {
39  m_startList = new AutoStartList;
40  KGlobal::dirs()->addResourceType("xdgconf-autostart", NULL, "autostart/"); // xdg ones
41  KGlobal::dirs()->addResourceType("autostart", "xdgconf-autostart", "/"); // merge them
42  KGlobal::dirs()->addResourceType("autostart", 0, "share/autostart"); // KDE ones are higher priority
43 }
44 
45 AutoStart::~AutoStart()
46 {
47  qDeleteAll(*m_startList);
48  m_startList->clear();
49  delete m_startList;
50 }
51 
52 void
53 AutoStart::setPhase(int phase)
54 {
55  if (phase > m_phase)
56  {
57  m_phase = phase;
58  m_phasedone = false;
59  }
60 }
61 
62 void AutoStart::setPhaseDone()
63 {
64  m_phasedone = true;
65 }
66 
67 static QString extractName(QString path) // krazy:exclude=passbyvalue
68 {
69  int i = path.lastIndexOf(QLatin1Char('/'));
70  if (i >= 0)
71  path = path.mid(i+1);
72  i = path.lastIndexOf(QLatin1Char('.'));
73  if (i >= 0)
74  path = path.left(i);
75  return path;
76 }
77 
78 void
79 AutoStart::loadAutoStartList()
80 {
81  const QStringList files = KGlobal::dirs()->findAllResources("autostart",
82  QString::fromLatin1("*.desktop"),
83  KStandardDirs::NoDuplicates);
84 
85  for(QStringList::ConstIterator it = files.begin();
86  it != files.end();
87  ++it)
88  {
89  KAutostart config(*it);
90  if( !config.autostarts(QString::fromLatin1("KDE"), KAutostart::CheckAll))
91  continue;
92 
93  AutoStartItem *item = new AutoStartItem;
94  item->name = extractName(*it);
95  item->service = *it;
96  item->startAfter = config.startAfter();
97  item->phase = config.startPhase();
98  if (item->phase < 0)
99  item->phase = 0;
100  m_startList->append(item);
101  }
102 }
103 
104 QString
105 AutoStart::startService()
106 {
107  if (m_startList->isEmpty())
108  return QString();
109 
110  while(!m_started.isEmpty())
111  {
112 
113  // Check for items that depend on previously started items
114  QString lastItem = m_started[0];
115  QMutableListIterator<AutoStartItem *> it(*m_startList);
116  while (it.hasNext())
117  {
118  AutoStartItem *item = it.next();
119  if (item->phase == m_phase
120  && item->startAfter == lastItem)
121  {
122  m_started.prepend(item->name);
123  QString service = item->service;
124  it.remove();
125  delete item;
126  return service;
127  }
128  }
129  m_started.removeFirst();
130  }
131 
132  // Check for items that don't depend on anything
133  AutoStartItem *item;
134  QMutableListIterator<AutoStartItem *> it(*m_startList);
135  while (it.hasNext())
136  {
137  item = it.next();
138  if (item->phase == m_phase
139  && item->startAfter.isEmpty())
140  {
141  m_started.prepend(item->name);
142  QString service = item->service;
143  it.remove();
144  delete item;
145  return service;
146  }
147  }
148 
149  // Just start something in this phase
150  it = *m_startList;
151  while (it.hasNext())
152  {
153  item = it.next();
154  if (item->phase == m_phase)
155  {
156  m_started.prepend(item->name);
157  QString service = item->service;
158  it.remove();
159  delete item;
160  return service;
161  }
162  }
163 
164  return QString();
165 }
QList::clear
void clear()
KStandardDirs::addResourceType
bool addResourceType(const char *type, const QString &relativename, bool priority=true)
AutoStart::setPhaseDone
void setPhaseDone()
Definition: autostart.cpp:62
AutoStart::setPhase
void setPhase(int phase)
Definition: autostart.cpp:53
QList::removeFirst
void removeFirst()
KGlobal::dirs
KStandardDirs * dirs()
kautostart.h
AutoStart::phase
int phase() const
Definition: autostart.h:38
AutoStartList
QList< AutoStartItem * > AutoStartList
Definition: autostart.h:25
AutoStart::~AutoStart
~AutoStart()
Definition: autostart.cpp:45
config
KSharedConfigPtr config()
QString::lastIndexOf
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
kglobal.h
QList::append
void append(const T &value)
AutoStart::AutoStart
AutoStart()
Definition: autostart.cpp:36
QList::isEmpty
bool isEmpty() const
KAutostart
QMutableListIterator::remove
void remove()
QString
QStringList
QList::end
iterator end()
QLatin1Char
KStandardDirs::NoDuplicates
QMutableListIterator::hasNext
bool hasNext() const
KAutostart::startAfter
QString startAfter() const
KAutostart::CheckAll
QString::mid
QString mid(int position, int n) const
extractName
static QString extractName(QString path)
Definition: autostart.cpp:67
KAutostart::autostarts
bool autostarts(const QString &environment=QString(), Conditions check=NoConditions) const
QMutableListIterator::next
T & next()
QMutableListIterator
kstandarddirs.h
AutoStart::startService
QString startService()
Definition: autostart.cpp:105
QList::ConstIterator
typedef ConstIterator
QString::left
QString left(int n) const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QList::prepend
void prepend(const T &value)
KStandardDirs::findAllResources
QStringList findAllResources(const char *type, const QString &filter=QString(), SearchOptions options=NoSearchOptions) const
autostart.h
AutoStart::loadAutoStartList
void loadAutoStartList()
Definition: autostart.cpp:79
QList::begin
iterator begin()
KAutostart::startPhase
StartPhase startPhase() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KInit

Skip menu "KInit"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal