ts-files removal (#90)
[lxde/liblxqt.git] / lxqtautostartentry.h
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * LXQt - a lightweight, Qt based, desktop toolset
5 * http://razor-qt.org
6 *
7 * Copyright (C) 2012 Alec Moskvin <alecm@gmx.com>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 * END_COMMON_COPYRIGHT_HEADER */
24
25 #ifndef LXQTAUTOSTARTENTRY_H
26 #define LXQTAUTOSTARTENTRY_H
27
28 #include "lxqtglobals.h"
29 #include <XdgDesktopFile>
30
31 namespace LXQt
32 {
33
34 /*! \brief The AutostartEntry class provides an interface for staging configuration of individual
35 autostart items. All changes are made in memory until commit() is called.
36
37 - "system" file refers to a read-only file in /etc/xdg/autostart (or a directory in $XDG_CONFIG_DIRS)
38 - "local" file refers to the file in user's ~/.config/autostart (or in $XDG_CONFIG_HOME/autostart)
39
40 When a "local" file has the same name as the "system" file, the local one overrides it. This class
41 tries to ensure that the "local" file is deleted if it's identical to the "system" file.
42 */
43 class LXQT_API AutostartEntry
44 {
45 public:
46 /*! Constructs an AutostartEntry object for a specific entry.
47 * \param name The name of the autostart desktop file (e.g. "lxqt-panel.desktop")
48 */
49 AutostartEntry(const QString& name);
50
51 //! \brief Default constructor
52 AutostartEntry();
53
54 //! Destructor
55 virtual ~AutostartEntry() { }
56
57 //! Returns the "active" desktop file
58 const XdgDesktopFile& file() const;
59
60 //! Returns the name of the autostart entry (e.g. "lxqt-panel.desktop")
61 QString name() const;
62
63 /*! Sets to the specified desktop file. Use this to make modifications.
64 * \param file The desktop file
65 */
66 void setFile(const XdgDesktopFile& file);
67
68 /*! Sets whether the item auto-starts
69 * \param enable When false, sets the "Hidden" key which will prevent the item from starting
70 */
71 void setEnabled(bool enable);
72
73 //! Returns true if the item will auto-start
74 bool isEnabled() const;
75
76 /*! Returns true if the entry does not exist, and the object carries no useful information
77 * and can be ignored/deleted.
78 */
79 bool isEmpty() const { return !mSystem && mLocalState == StateNone; }
80
81 /*! Write any changes to disk
82 * \return true on success
83 */
84 bool commit();
85
86 protected:
87 //! Returns true if the user's "local" version exists
88 bool isLocal() const { return mLocalState != StateNone && mLocalState != StateDeleted; }
89
90 /*! Removes the user's "local" version of the file, reverting to system defaults
91 * \return true if there is no "system" version left (i.e. the entry was entirely deleted)
92 */
93 bool removeLocal();
94
95 //! \brief a read-only file in /etc/xdg/autostart (or a directory in $XDG_CONFIG_DIRS)
96 XdgDesktopFile mSystemFile;
97
98 //! \brief the file in user's ~/.config/autostart (or in $XDG_CONFIG_HOME/autostart)
99 XdgDesktopFile mLocalFile;
100
101 //! State of the "local" file
102 enum ItemState
103 {
104 StateNone, //! does not exist at all
105 StateDeleted, //! needs to be deleted from disk
106 StateTransient, //! does not yet exist on disk
107 StateModified, //! exists on disk and is modified
108 StateExists //! exists on disk and unmodified
109 } mLocalState;
110 bool mSystem; //! true if the "system" file exists
111 };
112
113 } // namespace LXQt
114 #endif // LXQTAUTOSTARTENTRY_H