]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/viewproperties.h
Remove unused #include
[dolphin.git] / src / views / viewproperties.h
1 /***************************************************************************
2 * Copyright (C) 2006-2010 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Aaron J. Seigo <aseigo@kde.org> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #ifndef VIEWPROPERTIES_H
22 #define VIEWPROPERTIES_H
23
24 #include "dolphin_export.h"
25 #include "views/dolphinview.h"
26
27 #include <QUrl>
28
29 class ViewPropertySettings;
30 /**
31 * @brief Maintains the view properties like 'view mode' or
32 * 'show hidden files' for a directory.
33 *
34 * The view properties are automatically stored as part of the file
35 * .directory inside the corresponding path. To read out the view properties
36 * just construct an instance by passing the path of the directory:
37 *
38 * \code
39 * ViewProperties props(QUrl::fromLocalFile("/home/peter/Documents"));
40 * const DolphinView::Mode mode = props.viewMode();
41 * const bool hiddenFilesShown = props.hiddenFilesShown();
42 * \endcode
43 *
44 * When modifying a view property, the '.directory' file is automatically updated
45 * inside the destructor.
46 *
47 * If no .directory file is available or the global view mode is turned on
48 * (see GeneralSettings::globalViewMode()), the values from the global .directory file
49 * are used for initialization.
50 */
51 class DOLPHIN_EXPORT ViewProperties
52 {
53 public:
54 explicit ViewProperties(const QUrl& url);
55 virtual ~ViewProperties();
56
57 void setViewMode(DolphinView::Mode mode);
58 DolphinView::Mode viewMode() const;
59
60 void setPreviewsShown(bool show);
61 bool previewsShown() const;
62
63 void setHiddenFilesShown(bool show);
64 bool hiddenFilesShown() const;
65
66 void setGroupedSorting(bool grouped);
67 bool groupedSorting() const;
68
69 void setSortRole(const QByteArray& role);
70 QByteArray sortRole() const;
71
72 void setSortOrder(Qt::SortOrder sortOrder);
73 Qt::SortOrder sortOrder() const;
74
75 void setSortFoldersFirst(bool foldersFirst);
76 bool sortFoldersFirst() const;
77
78 /**
79 * Sets the additional information for the current set view-mode.
80 * Note that the additional-info property is the only property where
81 * the value is dependent from another property (in this case the view-mode).
82 */
83 void setVisibleRoles(const QList<QByteArray>& info);
84
85 /**
86 * Returns the additional information for the current set view-mode.
87 * Note that the additional-info property is the only property where
88 * the value is dependent from another property (in this case the view-mode).
89 */
90 QList<QByteArray> visibleRoles() const;
91
92 void setHeaderColumnWidths(const QList<int>& widths);
93 QList<int> headerColumnWidths() const;
94
95 /**
96 * Sets the directory properties view mode, show preview,
97 * show hidden files, sorting and sort order like
98 * set in \a props.
99 */
100 void setDirProperties(const ViewProperties& props);
101
102 /**
103 * If \a autoSave is true, the properties are automatically
104 * saved when the destructor is called. Per default autosaving
105 * is enabled.
106 */
107 void setAutoSaveEnabled(bool autoSave);
108 bool isAutoSaveEnabled() const;
109
110 void update();
111
112 /**
113 * Saves the view properties for the directory specified
114 * in the constructor. The method is automatically
115 * invoked in the destructor, if
116 * ViewProperties::isAutoSaveEnabled() returns true and
117 * at least one property has been changed.
118 */
119 void save();
120
121 /**
122 * @return True if properties for the given URL exist:
123 * As soon as the properties for an URL have been saved with
124 * ViewProperties::save(), true will be returned. If false is
125 * returned, the default view-properties are used.
126 */
127 bool exist() const;
128
129 private:
130 /**
131 * Returns the destination directory path where the view
132 * properties are stored. \a subDir specifies the used sub
133 * directory.
134 */
135 QString destinationDir(const QString& subDir) const;
136
137 /**
138 * Returns the view-mode prefix when storing additional properties for
139 * a view-mode.
140 */
141 QString viewModePrefix() const;
142
143 /**
144 * Provides backward compatibility with .directory files created with
145 * Dolphin < 2.0: Converts the old additionalInfo-property into
146 * the visibleRoles-property and clears the additionalInfo-property.
147 */
148 void convertAdditionalInfo();
149
150 /**
151 * Provides backward compatibility with .directory files created with
152 * Dolphin < 2.1: Converts the old name-role "name" to the generic
153 * role "text".
154 */
155 void convertNameRoleToTextRole();
156
157 /**
158 * Provides backward compatibility with .directory files created with
159 * Dolphin < 16.11.70: Converts the old name-role "date" to "modificationtime"
160 */
161
162 void convertDateRoleToModificationTimeRole();
163 /**
164 * Returns true, if \a filePath is part of the home-path (see QDir::homePath()).
165 */
166 static bool isPartOfHome(const QString& filePath);
167
168 /**
169 * @return A hash-value for an URL that can be used as directory name.
170 * Is used to be able to remember view-properties for long baloo-URLs.
171 */
172 static QString directoryHashForUrl(const QUrl &url);
173
174 Q_DISABLE_COPY(ViewProperties)
175
176 private:
177 bool m_changedProps;
178 bool m_autoSave;
179 QString m_filePath;
180 ViewPropertySettings* m_node;
181 };
182
183 #endif