]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/viewproperties.h
DolphinView: Conform to global scroll speed
[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 setSortFoldersFirst(bool foldersFirst);
63 bool sortFoldersFirst() const;
64
65 void setSortHiddenLast(bool hiddenLast);
66 bool sortHiddenLast() const;
67
68 void setDynamicViewPassed(bool dynamicViewPassed);
69 bool dynamicViewPassed() const;
70
71 /**
72 * Sets the additional information for the current set view-mode.
73 * Note that the additional-info property is the only property where
74 * the value is dependent from another property (in this case the view-mode).
75 */
76 void setVisibleRoles(const QList<QByteArray> &info);
77
78 /**
79 * Returns 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 QList<QByteArray> visibleRoles() const;
84
85 void setHeaderColumnWidths(const QList<int> &widths);
86 QList<int> headerColumnWidths() const;
87
88 /**
89 * Sets the directory properties view mode, show preview,
90 * show hidden files, sorting and sort order like
91 * set in \a props.
92 */
93 void setDirProperties(const ViewProperties &props);
94
95 /**
96 * If \a autoSave is true, the properties are automatically
97 * saved when the destructor is called. Per default autosaving
98 * is enabled.
99 */
100 void setAutoSaveEnabled(bool autoSave);
101 bool isAutoSaveEnabled() const;
102
103 void update();
104
105 /**
106 * Saves the view properties for the directory specified
107 * in the constructor. The method is automatically
108 * invoked in the destructor, if
109 * ViewProperties::isAutoSaveEnabled() returns true and
110 * at least one property has been changed.
111 */
112 void save();
113
114 /**
115 * Returns the destination directory path where the view
116 * properties are stored. \a subDir specifies the used sub
117 * directory.
118 */
119 QString destinationDir(const QString &subDir) const;
120
121 private:
122 /**
123 * Returns the view-mode prefix when storing additional properties for
124 * a view-mode.
125 */
126 QString viewModePrefix() const;
127
128 /**
129 * Provides backward compatibility with .directory files created with
130 * Dolphin < 2.0: Converts the old additionalInfo-property into
131 * the visibleRoles-property and clears the additionalInfo-property.
132 */
133 void convertAdditionalInfo();
134
135 /**
136 * Provides backward compatibility with .directory files created with
137 * Dolphin < 2.1: Converts the old name-role "name" to the generic
138 * role "text".
139 */
140 void convertNameRoleToTextRole();
141
142 /**
143 * Provides backward compatibility with .directory files created with
144 * Dolphin < 16.11.70: Converts the old name-role "date" to "modificationtime"
145 */
146
147 void convertDateRoleToModificationTimeRole();
148 /**
149 * Returns true, if \a filePath is part of the home-path (see QDir::homePath()).
150 */
151 static bool isPartOfHome(const QString &filePath);
152
153 /**
154 * @return A hash-value for an URL that can be used as directory name.
155 * Is used to be able to remember view-properties for long baloo-URLs.
156 */
157 static QString directoryHashForUrl(const QUrl &url);
158
159 /** @returns a ViewPropertySettings object with properties loaded for the directory at @param filePath. Ownership is returned to the caller. */
160 ViewPropertySettings *loadProperties(const QString &folderPath) const;
161 /** @returns a ViewPropertySettings object with the globally configured default values. Ownership is returned to the caller. */
162 ViewPropertySettings *defaultProperties() const;
163
164 Q_DISABLE_COPY(ViewProperties)
165
166 private:
167 bool m_changedProps;
168 bool m_autoSave;
169 QString m_filePath;
170 ViewPropertySettings *m_node;
171 };
172
173 #endif