]>
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>
30 #include <kinstance.h>
32 #include "viewproperties.h"
34 #include "dolphinsettings.h"
36 #define FILE_NAME "/.directory"
38 ViewProperties::ViewProperties(const KUrl
& url
) :
39 m_changedProps(false),
46 m_filepath
= cleanUrl
.path();
48 if ((m_filepath
.length() < 1) || (m_filepath
.at(0) != QChar('/'))) {
49 m_node
= new ViewPropertySettings();
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
);
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
;
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
;
74 m_node
= new ViewPropertySettings(KSharedConfig::openConfig(m_filepath
+ FILE_NAME
));
77 ViewProperties::~ViewProperties()
79 if (m_changedProps
&& m_autoSave
) {
87 void ViewProperties::setViewMode(DolphinView::Mode mode
)
89 if (m_node
->viewMode() != mode
) {
90 m_node
->setViewMode(mode
);
95 DolphinView::Mode
ViewProperties::viewMode() const
97 return static_cast<DolphinView::Mode
>(m_node
->viewMode());
100 void ViewProperties::setShowPreview(bool show
)
102 if (m_node
->showPreview() != show
) {
103 m_node
->setShowPreview(show
);
108 bool ViewProperties::showPreview() const
110 return m_node
->showPreview();
114 void ViewProperties::setShowHiddenFiles(bool show
)
116 if (m_node
->showHiddenFiles() != show
) {
117 m_node
->setShowHiddenFiles(show
);
122 bool ViewProperties::showHiddenFiles() const
124 return m_node
->showHiddenFiles();
127 void ViewProperties::setSorting(DolphinView::Sorting sorting
)
129 if (m_node
->sorting() != sorting
) {
130 m_node
->setSorting(sorting
);
135 DolphinView::Sorting
ViewProperties::sorting() const
137 return static_cast<DolphinView::Sorting
>(m_node
->sorting());
140 void ViewProperties::setSortOrder(Qt::SortOrder sortOrder
)
142 if (m_node
->sortOrder() != sortOrder
) {
143 m_node
->setSortOrder(sortOrder
);
148 Qt::SortOrder
ViewProperties::sortOrder() const
150 return static_cast<Qt::SortOrder
>(m_node
->sortOrder());
153 void ViewProperties::setAutoSaveEnabled(bool autoSave
)
155 m_autoSave
= autoSave
;
158 bool ViewProperties::isAutoSaveEnabled() const
163 void ViewProperties::updateTimeStamp()
165 m_changedProps
= true;
166 m_node
->setTimestamp(QDateTime::currentDateTime());
169 void ViewProperties::save()
171 KStandardDirs::makeDir(m_filepath
);
172 m_node
->writeConfig();
173 m_changedProps
= false;
176 ViewProperties::ViewProperties(const ViewProperties
& props
)
181 ViewProperties
& ViewProperties::operator = (const ViewProperties
& props
)