]> cloud.milkyroute.net Git - dolphin.git/commitdiff
- Performance optimization in DolphinView::loadDirectory() (don't store the view...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 20 Dec 2006 20:50:32 +0000 (20:50 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 20 Dec 2006 20:50:32 +0000 (20:50 +0000)
- Get rid of methods which are not used anymore due to moving to KDirModel.
- Respect GeneralSettings::globalViewProps() setting when storing view properties.

svn path=/trunk/playground/utils/dolphin/; revision=615255

src/dolphinmainwindow.cpp
src/dolphinview.cpp
src/dolphinview.h
src/viewproperties.cpp
src/viewproperties.h
src/viewpropertiesdialog.cpp

index c1b99d9a85ea99cdca67f326005f1362cb99a46f..f3e2e293c8b6236ac701d01d9b9b77df3e460373 100644 (file)
@@ -837,6 +837,12 @@ void DolphinMainWindow::stopLoading()
 
 void DolphinMainWindow::togglePreview()
 {
+    clearStatusBar();
+
+    const KToggleAction* showPreviewAction =
+        static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
+    const bool show = showPreviewAction->isChecked();
+    m_activeView->setShowPreview(show);
 }
 
 void DolphinMainWindow::toggleShowHiddenFiles()
index 35737e41b71cef4a879aa38a5c049ec2df59c665..d66cfd9246a9be523ceee5d39d18a14ef21b97f1 100644 (file)
@@ -188,6 +188,22 @@ DolphinView::Mode DolphinView::mode() const
     return m_mode;
 }
 
+void DolphinView::setShowPreview(bool show)
+{
+    ViewProperties props(m_urlNavigator->url());
+    props.setShowPreview(show);
+
+    // TODO: wait until previews are possible with KFileItemDelegate
+
+    emit showPreviewChanged();
+}
+
+bool DolphinView::showPreview() const
+{
+    // TODO: wait until previews are possible with KFileItemDelegate
+    return true;
+}
+
 void DolphinView::setShowHiddenFiles(bool show)
 {
     if (m_dirLister->showingDotFiles() == show) {
@@ -210,14 +226,6 @@ bool DolphinView::showHiddenFiles() const
     return m_dirLister->showingDotFiles();
 }
 
-void DolphinView::setViewProperties(const ViewProperties& props)
-{
-    setMode(props.viewMode());
-    setSorting(props.sorting());
-    setSortOrder(props.sortOrder());
-    setShowHiddenFiles(props.showHiddenFiles());
-}
-
 void DolphinView::renameSelectedItems()
 {
     const KUrl::List urls = selectedUrls();
@@ -618,34 +626,38 @@ DolphinMainWindow* DolphinView::mainWindow() const
 void DolphinView::loadDirectory(const KUrl& url)
 {
     const ViewProperties props(url);
-    setMode(props.viewMode());
+
+    const Mode mode = props.viewMode();
+    if (m_mode != mode) {
+        m_mode = mode;
+        applyModeToView();
+        emit modeChanged();
+    }
 
     const bool showHiddenFiles = props.showHiddenFiles();
-    setShowHiddenFiles(showHiddenFiles);
-    m_dirLister->setShowingDotFiles(showHiddenFiles);
+    if (showHiddenFiles != m_dirLister->showingDotFiles()) {
+        m_dirLister->setShowingDotFiles(showHiddenFiles);
+        emit showHiddenFilesChanged();
+    }
 
-    setSorting(props.sorting());
-    setSortOrder(props.sortOrder());
+    const DolphinView::Sorting sorting = props.sorting();
+    if (sorting != m_proxyModel->sorting()) {
+        m_proxyModel->setSorting(sorting);
+        emit sortingChanged(sorting);
+    }
+
+    const Qt::SortOrder sortOrder = props.sortOrder();
+    if (sortOrder != m_proxyModel->sortOrder()) {
+        m_proxyModel->setSortOrder(sortOrder);
+        emit sortOrderChanged(sortOrder);
+    }
+
+    // TODO: handle previews (props.showPreview())
 
     startDirLister(url);
     emit urlChanged(url);
 }
 
-void DolphinView::triggerIconsViewItem(Q3IconViewItem* item)
-{
-    /* KDE4-TODO:
-    const Qt::ButtonState keyboardState = KApplication::keyboardMouseState();
-    const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) ||
-                                   ((keyboardState & Qt::ControlModifier) > 0);*/
-    const bool isSelectionActive = false;
-    if ((item != 0) && !isSelectionActive) {
-        // Updating the Url must be done outside the scope of this slot,
-        // as iconview items will get deleted.
-        QTimer::singleShot(0, this, SLOT(updateUrl()));
-        mainWindow()->setActiveView(this);
-    }
-}
-
 void DolphinView::triggerItem(const QModelIndex& index)
 {
     KFileItem* item = m_dirModel->itemForIndex(index);
@@ -676,35 +688,6 @@ void DolphinView::triggerItem(const QModelIndex& index)
     }
 }
 
-void DolphinView::updateUrl()
-{
-    //KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
-    //                                           static_cast<KFileView*>(m_iconsView);
-
-    KFileItem* fileItem = 0; // TODO: fileView->currentFileItem();
-    if (fileItem == 0) {
-        return;
-    }
-
-    if (fileItem->isDir()) {
-        // Prefer the local path over the Url. This assures that the
-        // volume space information is correct. Assuming that the Url is media:/sda1,
-        // and the local path is /windows/C: For the Url the space info is related
-        // to the root partition (and hence wrong) and for the local path the space
-        // info is related to the windows partition (-> correct).
-        const QString localPath(fileItem->localPath());
-        if (localPath.isEmpty()) {
-            setUrl(fileItem->url());
-        }
-        else {
-            setUrl(KUrl(localPath));
-        }
-    }
-    else {
-        fileItem->run();
-    }
-}
-
 void DolphinView::slotPercent(int percent)
 {
     if (m_showProgress) {
index 297dd3bd82d3ac0daef58ad309c4818e4e7eecd8..cd3df38b35b1a10742ac26dd8b9b0dfc7d2abe1e 100644 (file)
@@ -129,13 +129,35 @@ public:
     void requestActivation();
     bool isActive() const;
 
+    /**
+     * Changes the view mode for the current directory to \a mode.
+     * If the view properties should be remembered for each directory
+     * (GeneralSettings::globalViewProps() returns false), then the
+     * changed view mode will be be stored automatically.
+     */
     void setMode(Mode mode);
     Mode mode() const;
+
+    /**
+     * Turns on the file preview for the all files of the current directory,
+     * if \a show is true.
+     * If the view properties should be remembered for each directory
+     * (GeneralSettings::globalViewProps() returns false), then the
+     * preview setting will be be stored automatically.
+     */
+    void setShowPreview(bool show);
+    bool showPreview() const;
+
+    /**
+     * Shows all hidden files of the current directory,
+     * if \a show is true.
+     * If the view properties should be remembered for each directory
+     * (GeneralSettings::globalViewProps() returns false), then the
+     * show hidden file setting will be be stored automatically.
+     */
     void setShowHiddenFiles(bool show);
     bool showHiddenFiles() const;
 
-    void setViewProperties(const ViewProperties& props);
-
     /**
      * Triggers the renaming of the currently selected items, where
      * the user must input a new name for the items.
@@ -347,6 +369,9 @@ signals:
      */
     void modeChanged();
 
+    /** Is emitted if the 'show preview' property has been changed. */
+    void showPreviewChanged();
+
     /** Is emitted if the 'show hidden files' property has been changed. */
     void showHiddenFilesChanged();
 
@@ -383,9 +408,7 @@ protected:
 
 private slots:
     void loadDirectory(const KUrl& kurl);
-    void triggerIconsViewItem(Q3IconViewItem *item);
     void triggerItem(const QModelIndex& index);
-    void updateUrl();
 
     void slotPercent(int percent);
     void slotClear();
index 60e91cabf354c2bb75ea982addb2f6d34aae0cce..cd66519fd1dde40aa4a620a757f83c2f1a8a294f 100644 (file)
@@ -20,9 +20,8 @@
 
 #include <assert.h>
 
-#include <qdatetime.h>
-#include <qdir.h>
-#include <qfile.h>
+#include <QDateTime>
+#include <QFile>
 
 #include <klocale.h>
 #include <kstandarddirs.h>
@@ -30,8 +29,8 @@
 #include <kinstance.h>
 
 #include "viewproperties.h"
-
 #include "dolphinsettings.h"
+#include "generalsettings.h"
 
 #define FILE_NAME "/.directory"
 
@@ -168,9 +167,12 @@ void ViewProperties::updateTimeStamp()
 
 void ViewProperties::save()
 {
-    KStandardDirs::makeDir(m_filepath);
-    m_node->writeConfig();
-    m_changedProps = false;
+    const bool rememberSettings = !DolphinSettings::instance().generalSettings()->globalViewProps();
+    if (rememberSettings) {
+        KStandardDirs::makeDir(m_filepath);
+        m_node->writeConfig();
+        m_changedProps = false;
+    }
 }
 
 ViewProperties::ViewProperties(const ViewProperties& props)
index a988004078a5c74e9d4ea1ea45e046b585313281..992429241abeb31d248d7b81c5c049ee6c7216b1 100644 (file)
@@ -66,10 +66,27 @@ public:
     void setSortOrder(Qt::SortOrder sortOrder);
     Qt::SortOrder sortOrder() const;
 
+    /**
+     * If \a autoSave is true, the properties are automatically
+     * saved when the destructor is called. Per default autosaving
+     * is enabled.
+     */
     void setAutoSaveEnabled(bool autoSave);
     bool isAutoSaveEnabled() const;
 
     void updateTimeStamp();
+
+    /**
+     * 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.
+     */
     void save();
 
 private:
index 3f440633f17b1dd30a9a1d3cdb2e80157fef97e7..a187ef89a9a960c6f42a9121157eb910bbe2a179 100644 (file)
 
 #include "viewpropertiesdialog.h"
 #include "viewpropsprogressinfo.h"
+#include "dolphinview.h"
+#include "dolphinsettings.h"
+#include "generalsettings.h"
+#include "viewproperties.h"
 
 #include <klocale.h>
 #include <kiconloader.h>
@@ -34,9 +38,6 @@
 #include <QRadioButton>
 #include <QVBoxLayout>
 
-#include "viewproperties.h"
-#include "dolphinview.h"
-
 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     KDialog(dolphinView),
     m_isDirty(false),
@@ -110,12 +111,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     propsBoxLayout->addWidget(m_showPreview, 3, 0);
     propsBoxLayout->addWidget(m_showHiddenFiles, 4, 0);
 
-    m_applyToSubFolders = new QCheckBox(i18n("Apply changes to all sub folders"), main);
-    m_useAsDefault = new QCheckBox(i18n("Use as default"), main);
-
     topLayout->addWidget(propsBox);
-    topLayout->addWidget(m_applyToSubFolders);
-    topLayout->addWidget(m_useAsDefault);
 
     connect(m_viewMode, SIGNAL(activated(int)),
             this, SLOT(slotViewModeChanged(int)));
@@ -128,14 +124,23 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     connect(m_showHiddenFiles, SIGNAL(clicked()),
             this, SLOT(slotShowHiddenFilesChanged()));
 
-    connect(m_applyToSubFolders, SIGNAL(clicked()),
-            this, SLOT(markAsDirty()));
-    connect(m_applyToSubFolders, SIGNAL(clicked()),
-            this, SLOT(markAsDirty()));
-
     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
     connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
 
+    // Only show the following settings if the view properties are remembered
+    // for each directory:
+    if (!DolphinSettings::instance().generalSettings()->globalViewProps()) {
+        m_applyToSubFolders = new QCheckBox(i18n("Apply changes to all sub folders"), main);
+        m_useAsDefault = new QCheckBox(i18n("Use as default"), main);
+        topLayout->addWidget(m_applyToSubFolders);
+        topLayout->addWidget(m_useAsDefault);
+
+        connect(m_applyToSubFolders, SIGNAL(clicked()),
+                this, SLOT(markAsDirty()));
+        connect(m_useAsDefault, SIGNAL(clicked()),
+                this, SLOT(markAsDirty()));
+    }
+
     main->setLayout(topLayout);
     setMainWidget(main);
 }
@@ -205,7 +210,10 @@ void ViewPropertiesDialog::markAsDirty()
 
 void ViewPropertiesDialog::applyViewProperties()
 {
-    if (m_applyToSubFolders->isChecked() && m_isDirty) {
+    const bool applyToSubFolders = m_isDirty &&
+                                   (m_applyToSubFolders != 0) &&
+                                   m_applyToSubFolders->isChecked();
+    if (applyToSubFolders) {
         const QString text(i18n("The view properties of all sub folders will be changed. Do you want to continue?"));
         if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
             return;
@@ -219,7 +227,13 @@ void ViewPropertiesDialog::applyViewProperties()
     }
 
     m_viewProps->save();
-    m_dolphinView->setViewProperties(*m_viewProps);
+
+    m_dolphinView->setMode(m_viewProps->viewMode());
+    m_dolphinView->setSorting(m_viewProps->sorting());
+    m_dolphinView->setSortOrder(m_viewProps->sortOrder());
+    m_dolphinView->setShowPreview(m_viewProps->showPreview());
+    m_dolphinView->setShowHiddenFiles(m_viewProps->showHiddenFiles());
+
     m_isDirty = false;
 
     // TODO: handle m_useAsDefault setting