Debian Codegraph @

src/playlist/layouts/LayoutManager.h

raw
1 /****************************************************************************************
2 * Copyright (c) 2008-2009 Nikolaj Hald Nielsen <[email protected]> *
3 * Copyright (c) 2009 Seb Ruiz <[email protected]> *
4 * *
5 * This program is free software; you can redistribute it and/or modify it under *
6 * the terms of the GNU General Public License as published by the Free Software *
7 * Foundation; either version 2 of the License, or (at your option) any later *
8 * version. *
9 * *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
12 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License along with *
15 * this program. If not, see <http://www.gnu.org/licenses/>. *
16 ****************************************************************************************/
17
18 #ifndef PLAYLISTLAYOUTMANAGER_H
19 #define PLAYLISTLAYOUTMANAGER_H
20
21 #include "LayoutItemConfig.h"
22
23 #include <QStringList>
24 #include <QString>
25 #include <QMap>
26
27 class QDomElement;
28 class QDomDocument;
29
30 namespace Playlist {
31
32 /**
33 * Class for keeping track of playlist layouts and loading/saving them to xml files. Also keeps track
34 * Of the order in which these layouts are shown to the user and makes this persistent between sessions.
35 * @author Nikolaj Hald Nielsen <[email protected]>
36 */
37 class LayoutManager : public QObject
38 {
39 Q_OBJECT
40
41 public:
42 /**
43 * Get the class instance (Singleton Pattern).
44 * @return The class instance.
45 */
46 static LayoutManager* instance();
47
48 /**
49 * Get the ordered list of layout names.
50 * @return The list of layout names.
51 */
52 QStringList layouts() const;
53
54 /**
55 * Set the layout that is to be made active and used in the playlist.
56 * @param layout The name of the layout.
57 */
58 void setActiveLayout( const QString &layout );
59
60 /**
61 * Preview a layout in the playlist. This layout does not need to be stored or have a name yet.
62 * @param layout The layout to preview.
63 */
64 void setPreviewLayout( const PlaylistLayout &layout );
65
66 /**
67 * Replace the current layout with a new one and also store changes to disk.
68 * Also use the new layout as current.
69 * @param layout The updated layout.
70 */
71 void updateCurrentLayout( const PlaylistLayout &layout );
72
73 /**
74 * Get the layout with a specific name. Returns an empty layout if there is no layout matching the name.
75 * @param layout The name of the layout.
76 * @return The layout matching the name.
77 */
78 PlaylistLayout layout( const QString &layout ) const;
79
80 /**
81 * Get the currently active layout.
82 * @return the layout that is currently active.
83 */
84 PlaylistLayout activeLayout() const;
85
86 /**
87 * Get the name o the currently active layout.
88 * @return The name of the layout that is currently active.
89 */
90 QString activeLayoutName() const;
91
92 /**
93 * Check if a named layout if one of Amarok's defaults or is one added by a user, This is important
94 * as default layouts cannot be changed or deleted.
95 * @param layout The name of the layout.
96 * @return Is layout one of the defaults.
97 */
98 bool isDefaultLayout( const QString &layout ) const;
99
100 /**
101 * Add and store a new user defined layout.
102 * @param name The name of the new layout.
103 * @param layout The new layout.
104 */
105 void addUserLayout( const QString &name, PlaylistLayout layout );
106
107 /**
108 * Delete a layout. Checks if the layout is editable (is not one of the defaults) and deletes it if possible
109 * @param layout The name of the layout to delete.
110 */
111 void deleteLayout( const QString &layout );
112
113 /**
114 * Check if a layout can be deleted (is not a default layout).
115 * @param layout The name of the layout.
116 * @return Can this layout be delete.
117 */
118 bool isDeleteable( const QString &layout ) const;
119
120 /**
121 * Move the named layout up one place if possible
122 * @param layout The name of he layout to move
123 * @return The new row of the layout
124 */
125 int moveUp( const QString &layout );
126
127 /**
128 * Move the named layout down one place if possible
129 * @param layout The name of he layout to move
130 * @return The new row of the layout
131 */
132 int moveDown( const QString &layout );
133
134 Q_SIGNALS:
135
136 /**
137 * Signal emitted when the active layout changes.
138 */
139 void activeLayoutChanged();
140
141 /**
142 * Signal emitted when the list of layouts has changed. Either because a layout has been added or
143 * removed or because the order of the layouts has changed.
144 */
145 void layoutListChanged();
146
147 protected:
148 /**
149 * Private constructor (Singleton Pattern).
150 */
151 LayoutManager();
152
153 /**
154 * Load the default layouts shipped with Amarok.
155 */
156 void loadDefaultLayouts();
157
158 /**
159 * Load user generated layouts.
160 */
161 void loadUserLayouts();
162
163 /**
164 * Order the layouts according to what is stored in the config. If any layouts are present that are not mentioned in the config
165 * these are added to the bottom of the list, and of any layouts are mentioned in the config that is not found, these are ignored.
166 */
167 void orderLayouts();
168
169 /**
170 * Save the current ordering of the layouts to config.
171 */
172 void storeLayoutOrdering();
173
174 /**
175 * Load all layouts from an XML file.
176 * @param fileName The file to load the layouts from.
177 * @param user Are these to be treated as user generated layouts or Amarok default layouts.
178 */
179 void loadLayouts( const QString &fileName, bool user );
180
181 /**
182 * Create a DOM element corresponding to a LayoutItemConfig. Used when storing a layout to a file.
183 * @param doc The QDomDocument that is the parent of the current tree.
184 * @param name The name of the layoutItem
185 * @param item The layout item.
186 * @return A DOM element containing the XML encoded layout item.
187 */
188 QDomElement createItemElement( QDomDocument doc, const QString &name, const LayoutItemConfig &item ) const;
189
190 /**
191 * Create a LayoutItemConfig based on a QDomElement. Use when reading a layout from an XML file.
192 * @param elem The DOM element containing the encoded layout item.
193 * @return The layout item generated.
194 */
195 LayoutItemConfig parseItemConfig( const QDomElement &elem ) const;
196
197 static LayoutManager *s_instance;
198
199 QMap<QString, PlaylistLayout> m_layouts;
200 QStringList m_layoutNames; //used to make a custom ordering of items
201 QString m_activeLayout;
202 PlaylistLayout m_previewLayout;
203 };
204
205 }
206
207 #endif