]> cloud.milkyroute.net Git - dolphin.git/blob - src/viewproperties.h
Adapt Dolphin Nepomuk support to namespace changes.
[dolphin.git] / src / viewproperties.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (<peter.penz@gmx.at>) *
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 <dolphinview.h>
25 #include <kurl.h>
26 #include <libdolphin_export.h>
27
28 class ViewPropertySettings;
29 /**
30 * @brief Maintains the view properties like 'view mode' or
31 * 'show hidden files' for a directory.
32 *
33 * The view properties are automatically stored as part of the file
34 * .directory inside the corresponding path. To read out the view properties
35 * just construct an instance by passing the path of the directory:
36 *
37 * \code
38 * ViewProperties props(KUrl("/home/peter/Documents"));
39 * const DolphinView::Mode mode = props.viewMode();
40 * const bool showHiddenFiles = props.isShowHiddenFilesEnabled();
41 * \endcode
42 *
43 * When modifying a view property, the '.directory' file is automatically updated
44 * inside the destructor.
45 *
46 * If no .directory file is available or the global view mode is turned on
47 * (see GeneralSettings::globalViewMode()), the values from the global .directory file
48 * are used for initialization.
49 */
50 class LIBDOLPHINPRIVATE_EXPORT ViewProperties
51 {
52 public:
53 explicit ViewProperties(const KUrl& url);
54 virtual ~ViewProperties();
55
56 void setViewMode(DolphinView::Mode mode);
57 DolphinView::Mode viewMode() const;
58
59 void setShowPreview(bool show);
60 bool showPreview() const;
61
62 void setShowHiddenFiles(bool show);
63 bool showHiddenFiles() const;
64
65 void setCategorizedSorting(bool categorized);
66 bool categorizedSorting() const;
67
68 void setSorting(DolphinView::Sorting sorting);
69 DolphinView::Sorting sorting() const;
70
71 void setSortOrder(Qt::SortOrder sortOrder);
72 Qt::SortOrder sortOrder() const;
73
74 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info);
75 KFileItemDelegate::AdditionalInformation additionalInfo() const;
76
77 /**
78 * Sets the directory properties view mode, show preview,
79 * show hidden files, sorting and sort order like
80 * set in \a props.
81 */
82 void setDirProperties(const ViewProperties& props);
83
84 /**
85 * If \a autoSave is true, the properties are automatically
86 * saved when the destructor is called. Per default autosaving
87 * is enabled.
88 */
89 void setAutoSaveEnabled(bool autoSave);
90 bool isAutoSaveEnabled() const;
91
92 void updateTimeStamp();
93
94 /**
95 * Saves the view properties for the directory specified
96 * in the constructor. The method is automatically
97 * invoked in the destructor, if
98 * ViewProperties::isAutoSaveEnabled() returns true and
99 * at least one property has been changed.
100 */
101 void save();
102
103 /**
104 * Returns the URL of the directory, where the mirrored view properties
105 * are stored into. Mirrored view properties are used if:
106 * - there is no write access for storing the view properties into
107 * the original directory
108 * - for non local directories
109 */
110 static KUrl mirroredDirectory();
111
112 private:
113 /**
114 * Returns the destination directory path where the view
115 * properties are stored. \a subDir specifies the used sub
116 * directory.
117 */
118 QString destinationDir(const QString& subDir) const;
119
120 Q_DISABLE_COPY(ViewProperties)
121
122 private:
123 bool m_changedProps;
124 bool m_autoSave;
125 QString m_filepath;
126 ViewPropertySettings* m_node;
127 };
128
129 #endif