File indexing completed on 2024-05-19 05:39:09
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2006 Aaron Seigo <aseigo@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QObject> 0011 #include <QStringList> 0012 0013 class KDesktopFile; 0014 0015 /* 0016 * This class was imported from KService at commit c2cedaaeba0a53939c96a1273ab92ed1d6ca7bcf 0017 */ 0018 class PlasmaAutostart : public QObject 0019 { 0020 Q_OBJECT 0021 0022 public: 0023 /** 0024 * Creates a new KAutostart object that represents the autostart 0025 * service "entryName". If the service already exists in the system 0026 * then the values associated with that service, such as the executable 0027 * command, will be loaded as well. 0028 * 0029 * Note that unless this service is explicitly set to autostart, 0030 * simply creating a KAutostart object will not result in the 0031 * service being autostarted on next log in. 0032 * 0033 * If no such service is already registered and the command to be 0034 * executed on startup is not the same as entryName, then you will want 0035 * to set the associated command with setExec(const QString&) 0036 * @see setExec 0037 * @param entryName the name used to identify the service. If none is 0038 * provided then it uses the name registered with KAboutData. 0039 * @param parent QObject 0040 */ 0041 explicit PlasmaAutostart(const QString &entryName = QString(), QObject *parent = nullptr); 0042 ~PlasmaAutostart(); 0043 0044 /** 0045 * Flags for each of the conditions that may affect whether or not 0046 * a service actually autostarted on login 0047 * @see Conditions 0048 */ 0049 enum Condition { 0050 /** 0051 * no conditions set 0052 */ 0053 NoConditions = 0x0, 0054 /** 0055 * an executable that is checked for existence by name 0056 */ 0057 CheckCommand = 0x1, 0058 /** 0059 * autostart condition will be checked too (KDE-specific) 0060 * @since 4.3 0061 */ 0062 CheckCondition = 0x2, 0063 /** 0064 * all necessary conditions will be checked 0065 * @since 4.3 0066 */ 0067 CheckAll = 0xff, 0068 }; 0069 /** 0070 * Stores a combination of #Condition values. 0071 */ 0072 Q_DECLARE_FLAGS(Conditions, Condition) 0073 0074 /** 0075 * Enumerates the various autostart phases that occur during start-up. 0076 */ 0077 enum StartPhase { 0078 /** 0079 * the essential desktop services such as panels and window managers 0080 */ 0081 BaseDesktop = 0, 0082 /** 0083 * services that should be available before most interactive 0084 * applications start but that aren't part of the base desktop. 0085 * This would include things such as clipboard managers and 0086 * mouse gesture tools. 0087 */ 0088 DesktopServices = 1, 0089 /** 0090 * everything else that doesn't belong in the above two categories, 0091 * including most system tray applications, system monitors and 0092 * interactive applications 0093 */ 0094 Applications = 2, 0095 }; 0096 0097 /** 0098 * Sets the given exec to start automatically at login 0099 * @param autostart will register with the autostart facility when true 0100 * and deregister when false 0101 * @see autostarts() 0102 */ 0103 void setAutostarts(bool autostart); 0104 0105 /** 0106 * Returns whether or not the service represented by entryName in the 0107 * autostart system is set to autostart at login or not 0108 * @param environment if provided the check will be performed as if 0109 * being loaded in that environment 0110 * @param check autostart conditions to check for (see commandToCheck()) 0111 * @see setAutostarts() 0112 */ 0113 bool autostarts(const QString &environment = QString(), Conditions check = NoConditions) const; 0114 0115 /** 0116 * Returns the associated command for this autostart service 0117 * @see setCommand() 0118 */ 0119 QString command() const; 0120 /** 0121 * Set the associated command for this autostart service 0122 * @see command() 0123 */ 0124 void setCommand(const QString &command); 0125 0126 /** 0127 * Checks whether or not a service by the given name @p entryName is registered 0128 * with the autostart system. Does not check whether or not it is 0129 * set to actually autostart or not. 0130 * @param entryName the name of the service to check for 0131 */ 0132 static bool isServiceRegistered(const QString &entryName); 0133 0134 /** 0135 * Returns the autostart phase this service is started in. 0136 * 0137 * Note that this is KDE specific and may not work in other 0138 * environments. 0139 * 0140 * @see StartPhase, setStartPhase() 0141 */ 0142 StartPhase startPhase() const; 0143 0144 /** 0145 * Returns the list of environments (e.g. "KDE") this service is allowed 0146 * to start in. Use checkAllowedEnvironment() or autostarts() for actual 0147 * checks. 0148 * 0149 * This does not take other autostart conditions 0150 * into account. If any environment is added to the allowed environments 0151 * list, then only those environments will be allowed to 0152 * autoload the service. It is not allowed to specify both allowed and excluded 0153 * environments at the same time. 0154 * @see setAllowedEnvironments() 0155 */ 0156 QStringList allowedEnvironments() const; 0157 0158 /** 0159 * Returns the list of environments this service is explicitly not 0160 * allowed to start in. Use checkAllowedEnvironment() or autostarts() for actual 0161 * checks. 0162 * 0163 * This does not take other autostart conditions 0164 * such as into account. It is not allowed to specify both allowed and excluded 0165 * environments at the same time. 0166 * @see setExcludedEnvironments() 0167 */ 0168 QStringList excludedEnvironments() const; 0169 0170 /** 0171 * Returns the name of another service that should be autostarted 0172 * before this one (if that service would be autostarted). 0173 * @internal 0174 */ 0175 QString startAfter() const; 0176 0177 /** 0178 * Checks whether autostart is allowed in the given environment, 0179 * depending on allowedEnvironments() and excludedEnvironments(). 0180 */ 0181 bool checkAllowedEnvironment(const QString &environment) const; 0182 0183 /** 0184 * Checks that a given autostart configuration condition is met. 0185 * @param condition: config in the format "rcfile:group:entry:default" 0186 */ 0187 static bool isStartConditionMet(QStringView condition); 0188 0189 private: 0190 bool checkStartCondition() const; 0191 void copyIfNeeded(); 0192 QString name; 0193 KDesktopFile *df; 0194 bool copyIfNeededChecked; 0195 }; 0196 0197 Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAutostart::Conditions)