]>
cloud.milkyroute.net Git - dolphin.git/blob - src/viewproperties.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
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. *
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. *
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 ***************************************************************************/
23 #include <qdatetime.h>
28 #include <kstandarddirs.h>
31 #include "viewproperties.h"
33 #include "dolphinsettings.h"
35 #define FILE_NAME "/.directory"
37 ViewProperties::ViewProperties(KUrl url
) :
38 m_changedProps(false),
40 m_subDirValidityHidden(false),
44 m_filepath
= url
.path();
46 if ((m_filepath
.length() < 1) || (m_filepath
.at(0) != QChar('/'))) {
47 m_node
= new ViewPropertySettings();
51 // we try and save it to a file in the directory being viewed
52 // if the directory is not writable by the user or the directory is not local
53 // we store the properties information in a local file
54 QString
rootDir("/"); // TODO: should this be set to the root of the bookmark, if any?
55 if (url
.isLocalFile()) {
56 QFileInfo
info(m_filepath
);
58 if (!info
.isWritable()) {
59 QString basePath
= KGlobal::instance()->instanceName();
60 basePath
.append("/view_properties/local");
61 rootDir
= locateLocal("data", basePath
);
62 m_filepath
= rootDir
+ m_filepath
;
66 QString basePath
= KGlobal::instance()->instanceName();
67 basePath
.append("/view_properties/remote/").append(url
.host());
68 rootDir
= locateLocal("data", basePath
);
69 m_filepath
= rootDir
+ m_filepath
;
72 m_node
= new ViewPropertySettings(KSharedConfig::openConfig(m_filepath
+ FILE_NAME
));
75 const bool isValidForSubDirs
= m_node
->validForSubDirs();
76 while ((dir
.path() != rootDir
) && dir
.cdUp()) {
77 QString
parentPath(dir
.path() + FILE_NAME
);
79 if (!QFile::exists(parentPath
))
84 ViewPropertySettings
parentNode(KSharedConfig::openConfig(dir
.path() + FILE_NAME
));
85 const bool inheritProps
= parentNode
.validForSubDirs() &&
86 (parentNode
.timestamp() > m_node
->timestamp());
94 if (isValidForSubDirs
) {
95 m_subDirValidityHidden
= true;
99 ViewProperties::~ViewProperties()
101 if (m_changedProps
&& m_autoSave
) {
108 void ViewProperties::setViewMode(DolphinView::Mode mode
)
110 if (m_node
->viewMode() != mode
) {
111 m_node
->setViewMode(mode
);
116 DolphinView::Mode
ViewProperties::viewMode() const
118 return static_cast<DolphinView::Mode
>(m_node
->viewMode());
121 void ViewProperties::setShowHiddenFilesEnabled(bool show
)
123 if (m_node
->showHiddenFiles() != show
) {
124 m_node
->setShowHiddenFiles(show
);
129 bool ViewProperties::isShowHiddenFilesEnabled() const
131 return m_node
->showHiddenFiles();
134 void ViewProperties::setSorting(DolphinView::Sorting sorting
)
136 if (m_node
->sorting() != sorting
) {
137 m_node
->setSorting(sorting
);
142 DolphinView::Sorting
ViewProperties::sorting() const
144 return static_cast<DolphinView::Sorting
>(m_node
->sorting());
147 void ViewProperties::setSortOrder(Qt::SortOrder sortOrder
)
149 if (m_node
->sortOrder() != sortOrder
) {
150 m_node
->setSortOrder(sortOrder
);
155 Qt::SortOrder
ViewProperties::sortOrder() const
157 return static_cast<Qt::SortOrder
>(m_node
->sortOrder());
160 void ViewProperties::setValidForSubDirs(bool valid
)
162 if (m_node
->validForSubDirs() != valid
) {
163 m_node
->setValidForSubDirs(valid
);
168 bool ViewProperties::isValidForSubDirs() const
170 return m_node
->validForSubDirs();
173 void ViewProperties::setAutoSaveEnabled(bool autoSave
)
175 m_autoSave
= autoSave
;
178 bool ViewProperties::isAutoSaveEnabled() const
183 void ViewProperties::updateTimeStamp()
185 m_changedProps
= true;
186 m_node
->setTimestamp(QDateTime::currentDateTime());
189 void ViewProperties::save()
191 KStandardDirs::makeDir(m_filepath
);
192 m_node
->writeConfig();
193 m_changedProps
= false;
196 ViewProperties
& ViewProperties::operator = (const ViewProperties
& props
)
198 if (&props
!= this) {
199 m_changedProps
= props
.m_changedProps
;
200 m_autoSave
= props
.m_autoSave
;
201 m_subDirValidityHidden
= props
.m_subDirValidityHidden
;
202 m_filepath
= props
.m_filepath
;
203 m_node
= new ViewPropertySettings();
204 //*m_node = *(props.m_node);