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