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