]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Allow that Dolphin can also be used with global view properties. Per default Dolphin...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 7 Jan 2007 09:47:05 +0000 (09:47 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 7 Jan 2007 09:47:05 +0000 (09:47 +0000)
svn path=/trunk/playground/utils/dolphin/; revision=620774

16 files changed:
src/applyviewpropsjob.cpp
src/bookmarkssettingspage.cpp
src/bookmarkssettingspage.h
src/detailsviewsettingspage.cpp
src/detailsviewsettingspage.h
src/dolphinsettingsdialog.cpp
src/generalsettingspage.h
src/generalviewsettingspage.cpp
src/generalviewsettingspage.h
src/iconsviewsettingspage.cpp
src/iconsviewsettingspage.h
src/viewproperties.cpp
src/viewproperties.h
src/viewpropsprogressinfo.cpp
src/viewsettingspage.cpp
src/viewsettingspage.h

index 0be8f4d47d32969084f1f3c1af93159c635bf5f4..cddc4d653f8c655f0b93b9dbb60750f5090c00a1 100644 (file)
@@ -23,6 +23,7 @@
 #include "applyviewpropsjob.h"
 #include "viewproperties.h"
 
+#include <assert.h>
 #include <kdebug.h>
 
 ApplyViewPropsJob::ApplyViewPropsJob(const KUrl& dir,
@@ -74,12 +75,10 @@ void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list)
             KUrl url(m_dir);
             url.addPath(name);
 
+            assert(m_viewProps != 0);
+
             ViewProperties props(url);
-            props.setViewMode(m_viewProps->viewMode());
-            props.setShowPreview(m_viewProps->showPreview());
-            props.setShowHiddenFiles(m_viewProps->showHiddenFiles());
-            props.setSorting(m_viewProps->sorting());
-            props.setSortOrder(m_viewProps->sortOrder());
+            props.setDirProperties(*m_viewProps);
         }
     }
 }
index 43aa87c58a1e65b96b826dd4badeed19f57d10c5..89caede0c738b7172660be3c086c4a435925482f 100644 (file)
 #include "dolphinsettings.h"
 #include "editbookmarkdialog.h"
 
-BookmarksSettingsPage::BookmarksSettingsPage(QWidget*parent) :
+BookmarksSettingsPage::BookmarksSettingsPage(DolphinMainWindow* mainWindow,
+                                             QWidget*parent) :
     SettingsPageBase(parent),
+    m_mainWindow(mainWindow),
     m_addButton(0),
     m_removeButton(0),
     m_moveUpButton(0),
index 336c85e17d2cd128d2fe2762722f7d192e3882d8..a76b85d4653befe218d8f79e400926006d5f9b3c 100644 (file)
@@ -24,6 +24,7 @@
 #include <settingspagebase.h>
 #include <q3valuelist.h>
 
+class DolphinMainWindow;
 class K3ListView;
 class KPushButton;
 class Q3ListViewItem;
@@ -37,7 +38,7 @@ class BookmarksSettingsPage : public SettingsPageBase
     Q_OBJECT
 
 public:
-    BookmarksSettingsPage(QWidget* parent);
+    BookmarksSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent);
 
     virtual ~BookmarksSettingsPage();
 
@@ -70,6 +71,7 @@ private:
         IconIdx   = 3
     };
 
+    DolphinMainWindow* m_mainWindow;
     K3ListView* m_listView;
     KPushButton* m_addButton;
     KPushButton* m_editButton;
index 81b9300715f9e8f86a5b7b6f803449fa34acb7c3..8a8d158c9dad2c50472261039a6ffe5e82fde63c 100644 (file)
 #include "detailsmodesettings.h"
 #include "dolphindetailsview.h"
 
-DetailsViewSettingsPage::DetailsViewSettingsPage(QWidget *parent) :
+DetailsViewSettingsPage::DetailsViewSettingsPage(DolphinMainWindow* mainWindow,
+                                                 QWidget* parent) :
     KVBox(parent),
+    m_mainWindow(mainWindow),
     m_dateBox(0),
     m_permissionsBox(0),
     m_ownerBox(0),
index 89cb7258e6fe8847d9195d471af00802e7bf51d4..95f611b85a898675a3f55fa7a79cb35515d935ac 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <kvbox.h>
 
+class DolphinMainWindow;
 class QCheckBox;
 class QFontComboBox;
 class QSpinBox;
@@ -32,15 +33,13 @@ class QRadioButton;
 /**
  * @brief Represents the page from the Dolphin Settings which allows
  * to modify the settings for the details view.
- *
- *  @author Peter Penz <peter.penz@gmx.at>
  */
 class DetailsViewSettingsPage : public KVBox
 {
     Q_OBJECT
 
 public:
-    DetailsViewSettingsPage(QWidget* parent);
+    DetailsViewSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent);
     virtual ~DetailsViewSettingsPage();
 
     /**
@@ -51,6 +50,7 @@ public:
     void applySettings();
 
 private:
+    DolphinMainWindow* m_mainWindow;
     QCheckBox* m_dateBox;
     QCheckBox* m_permissionsBox;
     QCheckBox* m_ownerBox;
index 7f440fc6c5b5014812db33d99d4d8ebd859acb68..cf66af3b267e800781bad13c6a85e756ee90ea6a 100644 (file)
@@ -42,11 +42,11 @@ DolphinSettingsDialog::DolphinSettingsDialog(DolphinMainWindow* mainWindow) :
     KPageWidgetItem* generalSettingsFrame = addPage(m_generalSettingsPage, i18n("General"));
     generalSettingsFrame->setIcon(KIcon("exec"));
 
-    m_viewSettingsPage = new ViewSettingsPage(this);
+    m_viewSettingsPage = new ViewSettingsPage(mainWindow, this);
     KPageWidgetItem* viewSettingsFrame = addPage(m_viewSettingsPage, i18n("View Modes"));
     viewSettingsFrame->setIcon(KIcon("view_choose"));
 
-    m_bookmarksSettingsPage = new BookmarksSettingsPage(this);
+    m_bookmarksSettingsPage = new BookmarksSettingsPage(mainWindow, this);
     KPageWidgetItem* bookmarksSettingsFrame = addPage(m_bookmarksSettingsPage, i18n("Bookmarks"));
     bookmarksSettingsFrame->setIcon(KIcon("bookmark"));
 }
index 99ec4960040ae3983be5ed6df92afc802f04ef80..0cffc3f6970b1944bd89bdcff225b14f3c4d7b14 100644 (file)
 #define GENERALSETTINGSPAGE_H
 
 #include <settingspagebase.h>
+
+class DolphinMainWindow;
 class QLineEdit;
 class QRadioButton;
 class QCheckBox;
-class DolphinMainWindow;
 
 /**
  * @brief Page for the 'General' settings of the Dolphin settings dialog.
  *
  * The general settings allow to set the home Url, the default view mode
  * and the split view mode.
- *
- *     @author Peter Penz <peter.penz@gmx.at>
  */
 class GeneralSettingsPage : public SettingsPageBase
 {
@@ -40,7 +39,6 @@ class GeneralSettingsPage : public SettingsPageBase
 
 public:
     GeneralSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent);
-
     virtual ~GeneralSettingsPage();
 
     /** @see SettingsPageBase::applySettings */
@@ -52,7 +50,7 @@ private slots:
     void useDefaulLocation();
 
 private:
-    DolphinMainWindow *m_mainWindow;
+    DolphinMainWindowm_mainWindow;
     QLineEdit* m_homeUrl;
     QCheckBox* m_startSplit;
     QCheckBox* m_startEditable;
index 97a8af9052bd40e14238c8858a4936a3331376de..bdaa681a6be33ace438db7ce849488e7b6fe1f67 100644 (file)
  ***************************************************************************/
 
 #include "generalviewsettingspage.h"
+#include "dolphinmainwindow.h"
 #include "dolphinsettings.h"
 #include "generalsettings.h"
+#include "viewproperties.h"
 
 #include <assert.h>
 
 #include <klocale.h>
 #include <kvbox.h>
 
-GeneralViewSettingsPage::GeneralViewSettingsPage(QWidget* parent) :
+GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow* mainWindow,
+                                                 QWidget* parent) :
     KVBox(parent),
+    m_mainWindow(mainWindow),
     m_localProps(0),
     m_globalProps(0)
 {
@@ -77,9 +81,23 @@ GeneralViewSettingsPage::~GeneralViewSettingsPage()
 
 void GeneralViewSettingsPage::applySettings()
 {
+    const KUrl& url = m_mainWindow->activeView()->url();
+    ViewProperties props(url);  // read current view properties
+
+    const bool useGlobalProps = m_globalProps->isChecked();
+
     GeneralSettings* settings = DolphinSettings::instance().generalSettings();
     assert(settings != 0);
-    settings->setGlobalViewProps(m_globalProps->isChecked());
+    settings->setGlobalViewProps(useGlobalProps);
+
+    if (useGlobalProps) {
+        // Remember the global view properties by applying the current view properties.
+        // It is important that GeneralSettings::globalViewProps() is set before
+        // the class ViewProperties is used, as ViewProperties uses this setting
+        // to find the destination folder for storing the view properties.
+        ViewProperties globalProps(url);
+        globalProps.setDirProperties(props);
+    }
 }
 
 #include "generalviewsettingspage.moc"
index 8f6f7ada61787d426f09b8ad2fd506aedec22167..0d065a5726102613f7b6ff63f23b9471d03496b6 100644 (file)
 
 #include <kvbox.h>
 
+class DolphinMainWindow;
 class QRadioButton;
 
 /**
  * @brief Represents the page from the Dolphin Settings which allows
  * to modify general settings for the view modes.
- *
- *  @author Peter Penz <peter.penz@gmx.at>
  */
 class GeneralViewSettingsPage : public KVBox
 {
     Q_OBJECT
 
 public:
-    GeneralViewSettingsPage(QWidget* parent);
+    GeneralViewSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent);
     virtual ~GeneralViewSettingsPage();
 
     /**
@@ -47,6 +46,7 @@ public:
     void applySettings();
 
 private:
+    DolphinMainWindow* m_mainWindow;
     QRadioButton* m_localProps;
     QRadioButton* m_globalProps;
 };
index 7e63cf0f5700ebdfe642d65c49a6e05f13d8250f..8720472463d06335d5e7df4e7d2f4e5293a24721 100644 (file)
 #define GRID_SPACING_BASE 8
 #define GRID_SPACING_INC 12
 
-IconsViewSettingsPage::IconsViewSettingsPage(QWidget* parent) :
+IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow* mainWindow,
+                                             QWidget* parent) :
     KVBox(parent),
+    m_mainWindow(mainWindow),
     m_iconSizeSlider(0),
     m_previewSizeSlider(0),
     m_textWidthBox(0),
index 7d67bc79c244137b15e51f46b6ec2fa8dacbb021..aa106ef27b7df9438f252e0b864621def185a00a 100644 (file)
 #ifndef ICONSVIEWSETTINGSPAGE_H
 #define ICONSVIEWSETTINGSPAGE_H
 
-
 #include <dolphiniconsview.h>
 #include <kvbox.h>
 
+class DolphinMainWindow;
 class QSlider;
 class QComboBox;
 class QCheckBox;
@@ -48,14 +48,13 @@ class PixmapViewer;
  * - arrangement
  *
  * @see DolphinIconsViewSettings
- *  @author Peter Penz <peter.penz@gmx.at>
  */
 class IconsViewSettingsPage : public KVBox
 {
     Q_OBJECT
 
 public:
-    IconsViewSettingsPage(QWidget* parent);
+    IconsViewSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent);
     virtual ~IconsViewSettingsPage();
 
     /**
@@ -70,6 +69,7 @@ private slots:
     void slotPreviewSizeChanged(int value);
 
 private:
+    DolphinMainWindow* m_mainWindow;
     QSlider* m_iconSizeSlider;
     PixmapViewer* m_iconSizeViewer;
     QSlider* m_previewSizeSlider;
index cd66519fd1dde40aa4a620a757f83c2f1a8a294f..9316a6d5aab1c406db30e8d0ceb14c70a3b2ea2f 100644 (file)
@@ -40,7 +40,6 @@ ViewProperties::ViewProperties(const KUrl& url) :
       m_node(0)
 {
     KUrl cleanUrl(url);
-
     cleanUrl.cleanPath();
     m_filepath = cleanUrl.path();
 
@@ -52,22 +51,18 @@ 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.
-    QString rootDir("/"); // TODO: should this be set to the root of the bookmark, if any?
-    if (cleanUrl.isLocalFile()) {
-        QFileInfo info(m_filepath);
-
+    const bool useGlobalViewProps = DolphinSettings::instance().generalSettings()->globalViewProps();
+    if (useGlobalViewProps) {
+        m_filepath = destinationDir("global");
+    }
+    else if (cleanUrl.isLocalFile()) {
+        const QFileInfo info(m_filepath);
         if (!info.isWritable()) {
-            QString basePath = KGlobal::instance()->instanceName();
-            basePath.append("/view_properties/local");
-            rootDir = KStandardDirs::locateLocal("data", basePath);
-            m_filepath = rootDir + m_filepath;
+            m_filepath = destinationDir("local") + m_filepath;
         }
     }
     else {
-        QString basePath = KGlobal::instance()->instanceName();
-        basePath.append("/view_properties/remote/").append(cleanUrl.host());
-        rootDir = KStandardDirs::locateLocal("data", basePath);
-        m_filepath = rootDir + m_filepath;
+        m_filepath = destinationDir("remote") + m_filepath;
     }
 
     m_node = new ViewPropertySettings(KSharedConfig::openConfig(m_filepath + FILE_NAME));
@@ -149,6 +144,15 @@ Qt::SortOrder ViewProperties::sortOrder() const
     return static_cast<Qt::SortOrder>(m_node->sortOrder());
 }
 
+void ViewProperties::setDirProperties(const ViewProperties& props)
+{
+    setViewMode(props.viewMode());
+    setShowPreview(props.showPreview());
+    setShowHiddenFiles(props.showHiddenFiles());
+    setSorting(props.sorting());
+    setSortOrder(props.sortOrder());
+}
+
 void ViewProperties::setAutoSaveEnabled(bool autoSave)
 {
     m_autoSave = autoSave;
@@ -167,12 +171,16 @@ void ViewProperties::updateTimeStamp()
 
 void ViewProperties::save()
 {
-    const bool rememberSettings = !DolphinSettings::instance().generalSettings()->globalViewProps();
-    if (rememberSettings) {
-        KStandardDirs::makeDir(m_filepath);
-        m_node->writeConfig();
-        m_changedProps = false;
-    }
+    KStandardDirs::makeDir(m_filepath);
+    m_node->writeConfig();
+    m_changedProps = false;
+}
+
+QString ViewProperties::destinationDir(const QString& subDir) const
+{
+    QString basePath = KGlobal::instance()->instanceName();
+    basePath.append("/view_properties/").append(subDir);
+    return KStandardDirs::locateLocal("data", basePath);
 }
 
 ViewProperties::ViewProperties(const ViewProperties& props)
index 992429241abeb31d248d7b81c5c049ee6c7216b1..1681b7890c7e917397ee443a2d2244dd85a6bbdb 100644 (file)
@@ -66,6 +66,13 @@ public:
     void setSortOrder(Qt::SortOrder sortOrder);
     Qt::SortOrder sortOrder() const;
 
+    /**
+     * Sets the directory properties view mode, show preview,
+     * show hidden files, sorting and sort order like
+     * set in \a props.
+     */
+    void setDirProperties(const ViewProperties& props);
+
     /**
      * If \a autoSave is true, the properties are automatically
      * saved when the destructor is called. Per default autosaving
@@ -80,23 +87,27 @@ public:
      * Saves the view properties for the directory specified
      * in the constructor. The method is automatically
      * invoked in the destructor, if
-     * ViewProperties::isAutoSaveEnabled() returns true.
-     *
-     * Note that the saving of the properties will be ignored
-     * if GeneralSettings::globalViewProps() returns true: in
-     * this case view properties may not be remembered for
-     * each directory.
+     * ViewProperties::isAutoSaveEnabled() returns true and
+     * at least one property has been changed.
      */
     void save();
 
+private:
+    /**
+     * Returns the destination directory path where the view
+     * properties are stored. \a subDir specifies the used sub
+     * directory.
+     */
+    QString destinationDir(const QString& subDir) const;
+
+    ViewProperties(const ViewProperties& props);
+    ViewProperties& operator= (const ViewProperties& props);
+
 private:
     bool m_changedProps;
     bool m_autoSave;
     QString m_filepath;
     ViewPropertySettings* m_node;
-
-    ViewProperties(const ViewProperties& props);
-    ViewProperties& operator= (const ViewProperties& props);
 };
 
 #endif
index 2d0b1a8f8c79f682820dfbda444a18a7fe72eb78..887dfa2c750898bbade6e1fb70b3ec54d4fbfb3d 100644 (file)
@@ -48,10 +48,7 @@ ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent,
     setButtons(KDialog::Cancel);
 
     m_viewProps = new ViewProperties(dir);
-    m_viewProps->setViewMode(viewProps.viewMode());
-    m_viewProps->setShowHiddenFiles(viewProps.showHiddenFiles());
-    m_viewProps->setSorting(viewProps.sorting());
-    m_viewProps->setSortOrder(viewProps.sortOrder());
+    m_viewProps->setDirProperties(viewProps);
 
     // the view properties are stored by the ViewPropsApplierJob, so prevent
     // that the view properties are saved twice:
index 837aed835f8727dedce03d9be23f3a278b5d6e75..859f479a8a8daf16bcb8055e7c2d9cebb17067e6 100644 (file)
@@ -32,7 +32,8 @@
 #include <klocale.h>
 #include <kiconloader.h>
 
-ViewSettingsPage::ViewSettingsPage(QWidget *parent) :
+ViewSettingsPage::ViewSettingsPage(DolphinMainWindow* mainWindow,
+                                   QWidget* parent) :
     SettingsPageBase(parent),
     m_generalPage(0),
     m_iconsPage(0),
@@ -43,15 +44,15 @@ ViewSettingsPage::ViewSettingsPage(QWidget *parent) :
     QTabWidget* tabWidget = new QTabWidget(this);
 
     // initialize 'General' tab
-    m_generalPage = new GeneralViewSettingsPage(tabWidget);
+    m_generalPage = new GeneralViewSettingsPage(mainWindow, tabWidget);
     tabWidget->addTab(m_generalPage, SmallIcon("view_choose"), i18n("General"));
 
     // initialize 'Icons' tab
-    m_iconsPage = new IconsViewSettingsPage(tabWidget);
+    m_iconsPage = new IconsViewSettingsPage(mainWindow, tabWidget);
     tabWidget->addTab(m_iconsPage, SmallIcon("view_icon"), i18n("Icons"));
 
     // initialize 'Details' tab
-    m_detailsPage = new DetailsViewSettingsPage(tabWidget);
+    m_detailsPage = new DetailsViewSettingsPage(mainWindow, tabWidget);
     tabWidget->addTab(m_detailsPage, SmallIcon("view_text"), i18n("Details"));
 
     topLayout->addWidget(tabWidget, 0, 0 );
index f41238733a689853afc1e04c28330dc2c24e42cc..f2949bbc3626147ca9c06eaf549772f9ae9a5b6a 100644 (file)
@@ -23,6 +23,7 @@
 #include <qwidget.h>
 #include <settingspagebase.h>
 
+class DolphinMainWindow;
 class GeneralViewSettingsPage;
 class IconsViewSettingsPage;
 class DetailsViewSettingsPage;
@@ -32,16 +33,13 @@ class DetailsViewSettingsPage;
  *
  * The views settings allow to set the properties for the icons mode and
  * the details mode.
- *
- *  @author Peter Penz <peter.penz@gmx.at>
  */
 class ViewSettingsPage : public SettingsPageBase
 {
     Q_OBJECT
 
 public:
-    ViewSettingsPage(QWidget* parent);
-
+    ViewSettingsPage(DolphinMainWindow* mainWindow, QWidget* parent);
     virtual ~ViewSettingsPage();
 
     /** @see SettingsPageBase::applySettings */