]> cloud.milkyroute.net Git - dolphin.git/commitdiff
View properties dialog: Allow to reset all view properties (the timestamp is used...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 18 Feb 2007 11:20:32 +0000 (11:20 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 18 Feb 2007 11:20:32 +0000 (11:20 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=634789

src/dolphinmainwindow.cpp
src/generalsettings.kcfg
src/viewproperties.cpp
src/viewproperties.h
src/viewpropertiesdialog.cpp
src/viewpropertiesdialog.h

index dda1bdd47efafd13d252057f5d3141cf21db7277..bd91de09a340e264dbb6e0939ff61f3d3300b4bf 100644 (file)
@@ -883,6 +883,9 @@ void DolphinMainWindow::init()
     // 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
index 5fc190a297cb075ac3006bdca3b2d578cdfaa3dc..37fe8d18eec01f5343e6deafc759f0f0f8c0cd6d 100644 (file)
             <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
index 24573c1c994c7c66d3aaf297382068ab010c2d61..fd4dfd8dd5ba1204513dabe132fece8062723149 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   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  *
@@ -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);
 }
index 771144e1256bd713b293eec9c3e09d13b42fa0e1..b4d9500bc66e57c1e905c59b2bcc4c564de745b7 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   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  *
@@ -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
 {
index 8cedb73cbb7e78e8f659664380c514b6be400fa6..eceaf8048a594c4d28c3b84231e643a65c7d2850 100644 (file)
 
 #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"
index 827371935e38bdbcb513740c65c12cc4f8584ce7..9c5dd4cc70e5f45b7ae934e03081d8b4dadf50fd 100644 (file)
@@ -66,6 +66,7 @@ private:
     QCheckBox* m_showHiddenFiles;
     QRadioButton* m_applyToCurrentFolder;
     QRadioButton* m_applyToSubFolders;
+    QRadioButton* m_applyToAllFolders;
     QCheckBox* m_useAsDefault;
 
     void applyViewProperties();