1 /* This file is part of the KDE libraries
2 Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
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.
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.
20 #ifndef KDELIBS_KAUTOSTART_H
21 #define KDELIBS_KAUTOSTART_H
23 #include <kdecore_export.h>
25 #include <QtCore/QObject>
30 * KAutostart provides a programmatic means to control the state of
31 * autostart services on a per-user basis. This is useful for applications
32 * that wish to offer a configurable means to allow the application to be
35 * By using this class you future-proof your applications against potential
36 * future or platform-specific changes to the autostart mechanism(s).
38 * Typical usage might look like:
41 * KAutostart autostart; // without an entryName arg, gets name from KAboutData
42 * autostart.setAutostarts(true); // will now start up when the user logs in
44 * // set the value in our configuration settings to reflect whether or not
45 * // we will actually start up on log in
46 * config.setAutoStart(autostart.autoStarts());
49 class KDECORE_EXPORT KAutostart
: public QObject
55 * Creates a new KAutostart object that represents the autostart
56 * service "entryName". If the service already exists in the system
57 * then the values associated with that service, such as the executable
58 * command, will be loaded as well.
60 * Note that unless this service is explicitly set to autostart,
61 * simply creating a KAutostart object will not result in the
62 * service being autostarted on next log in.
64 * If no such service is already registered and the command to be
65 * executed on startup is not the same as entryName, then you will want
66 * to set the associated command with setExec(const QString&)
68 * @param entryName the name used to identify the service. If none is
69 * provided then it uses the name registered with KAboutData.
70 * @param parent QObject
72 explicit KAutostart(const QString
& entryName
= QString(),
77 * Flags for each of the conditions that may affect whether or not
78 * a service actually autostarted on login
84 * an executable that is checked for existence by name
88 Q_DECLARE_FLAGS(Conditions
, Condition
)
91 * Enumerates the various autostart phases that occur during start-up.
96 * the essential desktop services such as panels and window managers
100 * services that should be available before most interactive
101 * applications start but that aren't part of the base desktop.
102 * This would include things such as clipboard managers and
103 * mouse gesture tools.
107 * everything else that doesn't belong in the above two categories,
108 * including most system tray applications, system monitors and
109 * interactive applications
115 * Sets the given exec to start automatically at login
116 * @param autostart will register with the autostart facility when true
117 * and deregister when false
120 void setAutostarts(bool autostart
);
123 * Returns whether or not the service represented by entryName in the
124 * autostart system is set to autostart at login or not
125 * @param environment if provided the check will be performed as if
126 * being loaded in that environment
127 * @param check autostart conditions to check for (see commandToCheck())
128 * @see setAutostarts()
130 bool autostarts(const QString
& environment
= QString(),
131 Conditions check
= NoConditions
) const;
134 * Returns the associated command for this autostart service
137 QString
command() const;
139 * Set the associated command for this autostart service
142 void setCommand(const QString
& command
);
145 * Returns the user-visible name this autostart service is registered as
146 * @see setVisibleName(), setEntryName()
148 QString
visibleName() const;
150 * Sets the user-visible name for this autostart service.
153 void setVisibleName(const QString
& entryName
);
156 * Checks whether or not a service by the given name @p entryName is registered
157 * with the autostart system. Does not check whether or not it is
158 * set to actually autostart or not.
159 * @param entryName the name of the service to check for
161 static bool isServiceRegistered(const QString
& entryName
);
164 * Returns the executable to check for when attempting to autostart
165 * this service. If the executable is not found in the user's
166 * environment, it will not autostart.
167 * @see setCommandToCheck()
169 QString
commandToCheck() const;
171 * Sets the executable to check for the existence of when
172 * autostarting this service
173 * @see commandToCheck()
175 void setCommandToCheck(const QString
& exec
);
178 * Returns the autostart phase this service is started in.
180 * Note that this is KDE specific and may not work in other
183 * @see StartPhase, setStartPhase()
185 StartPhase
startPhase() const;
187 * Sets the service (by name) this service should be started after.
189 * Note that this is KDE specific and may not work in other
192 * @see StartPhase, startPhase()
194 void setStartPhase(StartPhase phase
);
197 * Returns the list of environments (e.g. "KDE") this service is allowed
200 * This does not take other autostart conditions
201 * into account. If any environment is added to the allowed environments
202 * list, then only those environments will be allowed to
203 * autoload the service. If an environment is marked as both allowed
204 * and excluded, it will be excluded.
205 * @see setAllowedEnvironments()
207 QStringList
allowedEnvironments() const;
209 * Sets the environments this service is allowed to start in
210 * @see allowedEnvironments(), addToAllowedEnvironments()
212 void setAllowedEnvironments(const QStringList
& environments
);
214 * Adds an environment to the list of environments this service may
216 * @see setAllowedEnvironments(), removeFromAllowedEnvironments()
218 void addToAllowedEnvironments(const QString
& environment
);
220 * Removes an environment to the list of environments this service may
222 * @see addToAllowedEnvironments()
224 void removeFromAllowedEnvironments(const QString
& environment
);
227 * Returns the list of environments this service is explicitly not
228 * allowed to start in.
230 * This does not take other autostart conditions
231 * such as into account. If the same environment is also marked as
232 * allowed, it will still be excluded.
233 * @see setExcludedEnvironments()
235 QStringList
excludedEnvironments() const;
237 * Sets the environments this service is not allowed to start in
238 * @see excludedEnvironments(), addToExcludedEnvironments()
240 void setExcludedEnvironments(const QStringList
& environments
);
242 * Adds an environment to the list of environments this service may
243 * not be autostarted in
244 * @see removeFromExcludedEnvironments()
246 void addToExcludedEnvironments(const QString
& environment
);
248 * Removes an environment to the list of environments this service may
249 * not be autostarted in
250 * @see addToExcludedEnvironments()
252 void removeFromExcludedEnvironments(const QString
& environment
);
259 Q_DECLARE_OPERATORS_FOR_FLAGS(KAutostart::Conditions
)