2 * SPDX-FileCopyrightText: 2006-2010 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Aaron J. Seigo <aseigo@kde.org>
5 * SPDX-License-Identifier: GPL-2.0-or-later
8 #ifndef VIEWPROPERTIES_H
9 #define VIEWPROPERTIES_H
11 #include "dolphin_export.h"
12 #include "views/dolphinview.h"
16 class ViewPropertySettings
;
18 * @brief Maintains the view properties like 'view mode' or
19 * 'show hidden files' for a directory.
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:
26 * ViewProperties props(QUrl::fromLocalFile("/home/peter/Documents"));
27 * const DolphinView::Mode mode = props.viewMode();
28 * const bool hiddenFilesShown = props.hiddenFilesShown();
31 * When modifying a view property, the '.directory' file is automatically updated
32 * inside the destructor.
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.
38 class DOLPHIN_EXPORT ViewProperties
41 explicit ViewProperties(const QUrl
&url
);
42 virtual ~ViewProperties();
44 void setViewMode(DolphinView::Mode mode
);
45 DolphinView::Mode
viewMode() const;
47 void setPreviewsShown(bool show
);
48 bool previewsShown() const;
50 void setHiddenFilesShown(bool show
);
51 bool hiddenFilesShown() const;
53 void setGroupedSorting(bool grouped
);
54 bool groupedSorting() const;
56 void setSortRole(const QByteArray
&role
);
57 QByteArray
sortRole() const;
59 void setSortOrder(Qt::SortOrder sortOrder
);
60 Qt::SortOrder
sortOrder() const;
62 void setSortFoldersFirst(bool foldersFirst
);
63 bool sortFoldersFirst() const;
65 void setSortHiddenLast(bool hiddenLast
);
66 bool sortHiddenLast() const;
69 * Sets the additional information for the current set view-mode.
70 * Note that the additional-info property is the only property where
71 * the value is dependent from another property (in this case the view-mode).
73 void setVisibleRoles(const QList
<QByteArray
> &info
);
76 * Returns the additional information for the current set view-mode.
77 * Note that the additional-info property is the only property where
78 * the value is dependent from another property (in this case the view-mode).
80 QList
<QByteArray
> visibleRoles() const;
82 void setHeaderColumnWidths(const QList
<int> &widths
);
83 QList
<int> headerColumnWidths() const;
86 * Sets the directory properties view mode, show preview,
87 * show hidden files, sorting and sort order like
90 void setDirProperties(const ViewProperties
&props
);
93 * If \a autoSave is true, the properties are automatically
94 * saved when the destructor is called. Per default autosaving
97 void setAutoSaveEnabled(bool autoSave
);
98 bool isAutoSaveEnabled() const;
103 * Saves the view properties for the directory specified
104 * in the constructor. The method is automatically
105 * invoked in the destructor, if
106 * ViewProperties::isAutoSaveEnabled() returns true and
107 * at least one property has been changed.
112 * @return True if properties for the given URL exist:
113 * As soon as the properties for an URL have been saved with
114 * ViewProperties::save(), true will be returned. If false is
115 * returned, the default view-properties are used.
121 * Returns the destination directory path where the view
122 * properties are stored. \a subDir specifies the used sub
125 QString
destinationDir(const QString
&subDir
) const;
128 * Returns the view-mode prefix when storing additional properties for
131 QString
viewModePrefix() const;
134 * Provides backward compatibility with .directory files created with
135 * Dolphin < 2.0: Converts the old additionalInfo-property into
136 * the visibleRoles-property and clears the additionalInfo-property.
138 void convertAdditionalInfo();
141 * Provides backward compatibility with .directory files created with
142 * Dolphin < 2.1: Converts the old name-role "name" to the generic
145 void convertNameRoleToTextRole();
148 * Provides backward compatibility with .directory files created with
149 * Dolphin < 16.11.70: Converts the old name-role "date" to "modificationtime"
152 void convertDateRoleToModificationTimeRole();
154 * Returns true, if \a filePath is part of the home-path (see QDir::homePath()).
156 static bool isPartOfHome(const QString
&filePath
);
159 * @return A hash-value for an URL that can be used as directory name.
160 * Is used to be able to remember view-properties for long baloo-URLs.
162 static QString
directoryHashForUrl(const QUrl
&url
);
164 Q_DISABLE_COPY(ViewProperties
)
170 ViewPropertySettings
*m_node
;