]> cloud.milkyroute.net Git - dolphin.git/blob - src/viewproperties.cpp
fixed compile issues resulted by kdelibs cleanup
[dolphin.git] / src / viewproperties.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include <assert.h>
22
23 #include <QDateTime>
24 #include <QFile>
25
26 #include <klocale.h>
27 #include <kstandarddirs.h>
28 #include <kurl.h>
29 #include <kinstance.h>
30
31 #include "viewproperties.h"
32 #include "dolphinsettings.h"
33 #include "generalsettings.h"
34
35 #define FILE_NAME "/.directory"
36
37 ViewProperties::ViewProperties(const KUrl& url) :
38 m_changedProps(false),
39 m_autoSave(true),
40 m_node(0)
41 {
42 KUrl cleanUrl(url);
43
44 cleanUrl.cleanPath();
45 m_filepath = cleanUrl.path();
46
47 if ((m_filepath.length() < 1) || (m_filepath.at(0) != QChar('/'))) {
48 m_node = new ViewPropertySettings();
49 return;
50 }
51
52 // We try and save it to a file in the directory being viewed.
53 // If the directory is not writable by the user or the directory is not local,
54 // we store the properties information in a local file.
55 QString rootDir("/"); // TODO: should this be set to the root of the bookmark, if any?
56 if (cleanUrl.isLocalFile()) {
57 QFileInfo info(m_filepath);
58
59 if (!info.isWritable()) {
60 QString basePath = KGlobal::instance()->instanceName();
61 basePath.append("/view_properties/local");
62 rootDir = KStandardDirs::locateLocal("data", basePath);
63 m_filepath = rootDir + m_filepath;
64 }
65 }
66 else {
67 QString basePath = KGlobal::instance()->instanceName();
68 basePath.append("/view_properties/remote/").append(cleanUrl.host());
69 rootDir = KStandardDirs::locateLocal("data", basePath);
70 m_filepath = rootDir + m_filepath;
71 }
72
73 m_node = new ViewPropertySettings(KSharedConfig::openConfig(m_filepath + FILE_NAME));
74 }
75
76 ViewProperties::~ViewProperties()
77 {
78 if (m_changedProps && m_autoSave) {
79 save();
80 }
81
82 delete m_node;
83 m_node = 0;
84 }
85
86 void ViewProperties::setViewMode(DolphinView::Mode mode)
87 {
88 if (m_node->viewMode() != mode) {
89 m_node->setViewMode(mode);
90 updateTimeStamp();
91 }
92 }
93
94 DolphinView::Mode ViewProperties::viewMode() const
95 {
96 return static_cast<DolphinView::Mode>(m_node->viewMode());
97 }
98
99 void ViewProperties::setShowPreview(bool show)
100 {
101 if (m_node->showPreview() != show) {
102 m_node->setShowPreview(show);
103 updateTimeStamp();
104 }
105 }
106
107 bool ViewProperties::showPreview() const
108 {
109 return m_node->showPreview();
110 }
111
112
113 void ViewProperties::setShowHiddenFiles(bool show)
114 {
115 if (m_node->showHiddenFiles() != show) {
116 m_node->setShowHiddenFiles(show);
117 updateTimeStamp();
118 }
119 }
120
121 bool ViewProperties::showHiddenFiles() const
122 {
123 return m_node->showHiddenFiles();
124 }
125
126 void ViewProperties::setSorting(DolphinView::Sorting sorting)
127 {
128 if (m_node->sorting() != sorting) {
129 m_node->setSorting(sorting);
130 updateTimeStamp();
131 }
132 }
133
134 DolphinView::Sorting ViewProperties::sorting() const
135 {
136 return static_cast<DolphinView::Sorting>(m_node->sorting());
137 }
138
139 void ViewProperties::setSortOrder(Qt::SortOrder sortOrder)
140 {
141 if (m_node->sortOrder() != sortOrder) {
142 m_node->setSortOrder(sortOrder);
143 updateTimeStamp();
144 }
145 }
146
147 Qt::SortOrder ViewProperties::sortOrder() const
148 {
149 return static_cast<Qt::SortOrder>(m_node->sortOrder());
150 }
151
152 void ViewProperties::setAutoSaveEnabled(bool autoSave)
153 {
154 m_autoSave = autoSave;
155 }
156
157 bool ViewProperties::isAutoSaveEnabled() const
158 {
159 return m_autoSave;
160 }
161
162 void ViewProperties::updateTimeStamp()
163 {
164 m_changedProps = true;
165 m_node->setTimestamp(QDateTime::currentDateTime());
166 }
167
168 void ViewProperties::save()
169 {
170 const bool rememberSettings = !DolphinSettings::instance().generalSettings()->globalViewProps();
171 if (rememberSettings) {
172 KStandardDirs::makeDir(m_filepath);
173 m_node->writeConfig();
174 m_changedProps = false;
175 }
176 }
177
178 ViewProperties::ViewProperties(const ViewProperties& props)
179 {
180 assert(false);
181 }
182
183 ViewProperties& ViewProperties::operator = (const ViewProperties& props)
184 {
185 assert(false);
186 }