// a proper default window size is given at the end of DolphinMainWindow::init().\r
GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();\r
const bool firstRun = generalSettings->firstRun();\r
+ if (firstRun) {\r
+ generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());\r
+ }\r
\r
setAcceptDrops(true);\r
\r
<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
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
- * peter.penz@gmx.at *
+ * Copyright (C) 2006 by Peter Penz (<peter.penz@gmx.at>) *
+ * Copyright (C) 2006 by Aaron J. Seigo (<aseigo@kde.org>) *
* *
* 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 *
// 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");
}
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()
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);
}
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
- * peter.penz@gmx.at *
+ * Copyright (C) 2006 by Peter Penz (<peter.penz@gmx.at>) *
+ * Copyright (C) 2006 by Aaron J. Seigo (<aseigo@kde.org>) *
* *
* 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 *
* @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"));
*
* 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
{
#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>
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);
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()));
}
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());
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"
QCheckBox* m_showHiddenFiles;
QRadioButton* m_applyToCurrentFolder;
QRadioButton* m_applyToSubFolders;
+ QRadioButton* m_applyToAllFolders;
QCheckBox* m_useAsDefault;
void applyViewProperties();