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