┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-02-18 11:20:32 +0000
committerPeter Penz <[email protected]>2007-02-18 11:20:32 +0000
commit3316903fe8a9a3c95dad18d19d795cdb55208473 (patch)
tree19a2c7522a426e10b5638673a15d9322b41c923e
parent0368591365d3a4ddd7c7cd189087eeed96acd1fa (diff)
View properties dialog: Allow to reset all view properties (the timestamp is used for this). Additionally it is possible for the user to specify whether the current view properties should be the default for new directories.
svn path=/trunk/KDE/kdebase/apps/; revision=634789
-rw-r--r--src/dolphinmainwindow.cpp3
-rw-r--r--src/generalsettings.kcfg5
-rw-r--r--src/viewproperties.cpp32
-rw-r--r--src/viewproperties.h14
-rw-r--r--src/viewpropertiesdialog.cpp45
-rw-r--r--src/viewpropertiesdialog.h1
6 files changed, 87 insertions, 13 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index dda1bdd47..bd91de09a 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -883,6 +883,9 @@ void DolphinMainWindow::init()
// a proper default window size is given at the end of DolphinMainWindow::init().
GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
const bool firstRun = generalSettings->firstRun();
+ if (firstRun) {
+ generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
+ }
setAcceptDrops(true);
diff --git a/src/generalsettings.kcfg b/src/generalsettings.kcfg
index 5fc190a29..37fe8d18e 100644
--- a/src/generalsettings.kcfg
+++ b/src/generalsettings.kcfg
@@ -19,9 +19,12 @@
<label>Split the view into two panes</label>
<default>false</default>
</entry>
- <entry name="globalViewProps" type="Bool">
+ <entry name="GlobalViewProps" type="Bool">
<label>Should the view properties used for all directories</label>
<default>false</default>
</entry>
+ <entry name="ViewPropsTimestamp" type="DateTime" >
+ <label>Timestamp since when the view properties are valid</label>
+ </entry>
</group>
</kcfg> \ No newline at end of file
diff --git a/src/viewproperties.cpp b/src/viewproperties.cpp
index 24573c1c9..fd4dfd8dd 100644
--- a/src/viewproperties.cpp
+++ b/src/viewproperties.cpp
@@ -1,6 +1,6 @@
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
+ * Copyright (C) 2006 by Peter Penz (<[email protected]>) *
+ * Copyright (C) 2006 by Aaron J. Seigo (<[email protected]>) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -52,7 +52,8 @@ ViewProperties::ViewProperties(const KUrl& url) :
// We try and save it to a file in the directory being viewed.
// If the directory is not writable by the user or the directory is not local,
// we store the properties information in a local file.
- const bool useGlobalViewProps = DolphinSettings::instance().generalSettings()->globalViewProps();
+ GeneralSettings* settings = DolphinSettings::instance().generalSettings();
+ const bool useGlobalViewProps = settings->globalViewProps();
if (useGlobalViewProps) {
m_filepath = destinationDir("global");
}
@@ -66,7 +67,26 @@ ViewProperties::ViewProperties(const KUrl& url) :
m_filepath = destinationDir("remote") + m_filepath;
}
- m_node = new ViewPropertySettings(KSharedConfig::openConfig(m_filepath + FILE_NAME));
+ const QString file(m_filepath + FILE_NAME);
+ m_node = new ViewPropertySettings(KSharedConfig::openConfig(file));
+
+ kDebug() << "------------------ global timestamp: " << settings->viewPropsTimestamp() << endl;
+
+ const bool useDefaultProps = !useGlobalViewProps &&
+ (!QFileInfo(file).exists() ||
+ (m_node->timestamp() < settings->viewPropsTimestamp()));
+ if (useDefaultProps) {
+ // If the .directory file does not exist or the timestamp is too old,
+ // use the values from the global .directory file instead, which acts
+ // as default view for new folders in this case.
+ settings->setGlobalViewProps(true);
+
+ ViewProperties defaultProps(url);
+ setDirProperties(defaultProps);
+
+ settings->setGlobalViewProps(false);
+ m_changedProps = false;
+ }
}
ViewProperties::~ViewProperties()
@@ -184,12 +204,12 @@ QString ViewProperties::destinationDir(const QString& subDir) const
return KStandardDirs::locateLocal("data", basePath);
}
-ViewProperties::ViewProperties(const ViewProperties& props)
+ViewProperties::ViewProperties(const ViewProperties& /*props*/)
{
assert(false);
}
-ViewProperties& ViewProperties::operator = (const ViewProperties& props)
+ViewProperties& ViewProperties::operator = (const ViewProperties& /*props*/)
{
assert(false);
}
diff --git a/src/viewproperties.h b/src/viewproperties.h
index 771144e12..b4d9500bc 100644
--- a/src/viewproperties.h
+++ b/src/viewproperties.h
@@ -1,6 +1,6 @@
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
+ * Copyright (C) 2006 by Peter Penz (<[email protected]>) *
+ * Copyright (C) 2006 by Aaron J. Seigo (<[email protected]>) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -33,9 +33,9 @@ class QFile;
* @brief Maintains the view properties like 'view mode' or
* 'show hidden files' for a directory.
*
- * The view properties are automatically stored inside the directory inside
- * the hidden file '.directory'. To read out the view properties
- * just construct an instance by passing the URL of the directory:
+ * The view properties are automatically stored as part of the file
+ * .directory inside the corresponding path. To read out the view properties
+ * just construct an instance by passing the path of the directory:
*
* \code
* ViewProperties props(KUrl("/home/peter/Documents"));
@@ -45,6 +45,10 @@ class QFile;
*
* When modifying a view property, the '.directory' file is automatically updated
* inside the destructor.
+ *
+ * If no .directory file is available or the global view mode is turned on
+ * (see GeneralSettings::globalViewMode()), the values from the global .directory file
+ * are used for initialization.
*/
class ViewProperties
{
diff --git a/src/viewpropertiesdialog.cpp b/src/viewpropertiesdialog.cpp
index 8cedb73cb..eceaf8048 100644
--- a/src/viewpropertiesdialog.cpp
+++ b/src/viewpropertiesdialog.cpp
@@ -28,9 +28,13 @@
#include <assert.h>
+#include <kcomponentdata.h>
#include <klocale.h>
#include <kiconloader.h>
+#include <kio/netaccess.h>
#include <kmessagebox.h>
+#include <kstandarddirs.h>
+#include <kurl.h>
#include <QButtonGroup>
#include <QCheckBox>
@@ -136,14 +140,17 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
m_applyToCurrentFolder = new QRadioButton(i18n("Current folder"), applyBox);
m_applyToCurrentFolder->setChecked(true);
m_applyToSubFolders = new QRadioButton(i18n("Current folder including all sub folders"), applyBox);
+ m_applyToAllFolders = new QRadioButton(i18n("All folders"),applyBox);
QButtonGroup* applyGroup = new QButtonGroup(this);
applyGroup->addButton(m_applyToCurrentFolder);
applyGroup->addButton(m_applyToSubFolders);
+ applyGroup->addButton(m_applyToAllFolders);
QVBoxLayout* applyBoxLayout = new QVBoxLayout(applyBox);
applyBoxLayout->addWidget(m_applyToCurrentFolder);
applyBoxLayout->addWidget(m_applyToSubFolders);
+ applyBoxLayout->addWidget(m_applyToAllFolders);
m_useAsDefault = new QCheckBox(i18n("Use as default for new folders"), main);
@@ -154,6 +161,8 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
this, SLOT(markAsDirty()));
connect(m_applyToSubFolders, SIGNAL(clicked()),
this, SLOT(markAsDirty()));
+ connect(m_applyToAllFolders, SIGNAL(clicked()),
+ this, SLOT(markAsDirty()));
connect(m_useAsDefault, SIGNAL(clicked()),
this, SLOT(markAsDirty()));
}
@@ -238,6 +247,27 @@ void ViewPropertiesDialog::applyViewProperties()
info->show();
}
+ const bool applyToAllFolders = m_isDirty &&
+ (m_applyToAllFolders != 0) &&
+ m_applyToAllFolders->isChecked();
+ if (applyToAllFolders) {
+ const QString text(i18n("The view properties of all folders will be changed. Do you want to continue?"));
+ if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
+ return;
+ }
+
+ // Updating the global view properties time stamp in the general settings makes
+ // all existing viewproperties invalid, as they have a smaller time stamp.
+ GeneralSettings* settings = DolphinSettings::instance().generalSettings();
+ settings->setViewPropsTimestamp(QDateTime::currentDateTime());
+
+ // This is also a good chance to make a cleanup of all mirrored view properties:
+ QString basePath = KGlobal::mainComponent().componentName();
+ basePath.append("/view_properties/");
+ const QString mirroredViewProps = KStandardDirs::locateLocal("data", basePath);
+ KIO::NetAccess::del(mirroredViewProps, this);
+ }
+
m_viewProps->save();
m_dolphinView->setMode(m_viewProps->viewMode());
@@ -248,7 +278,20 @@ void ViewPropertiesDialog::applyViewProperties()
m_isDirty = false;
- // TODO: handle m_useAsDefault setting
+ if (m_useAsDefault->isChecked()) {
+ // For directories where no .directory file is available, the .directory
+ // file stored for the global view properties is used as fallback. To update
+ // this file we temporary turn on the global view properties mode.
+ GeneralSettings* settings = DolphinSettings::instance().generalSettings();
+ assert(!settings->globalViewProps());
+
+ settings->setGlobalViewProps(true);
+ ViewProperties defaultProps(m_dolphinView->url());
+ defaultProps.setDirProperties(*m_viewProps);
+ kDebug() << "saving global viewprops" << endl;
+ defaultProps.save();
+ settings->setGlobalViewProps(false);
+ }
}
#include "viewpropertiesdialog.moc"
diff --git a/src/viewpropertiesdialog.h b/src/viewpropertiesdialog.h
index 827371935..9c5dd4cc7 100644
--- a/src/viewpropertiesdialog.h
+++ b/src/viewpropertiesdialog.h
@@ -66,6 +66,7 @@ private:
QCheckBox* m_showHiddenFiles;
QRadioButton* m_applyToCurrentFolder;
QRadioButton* m_applyToSubFolders;
+ QRadioButton* m_applyToAllFolders;
QCheckBox* m_useAsDefault;
void applyViewProperties();