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