]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/viewpropertiesdialog.cpp
- Performance optimization in DolphinView::loadDirectory() (don't store the view...
[dolphin.git] / src / viewpropertiesdialog.cpp
index b13b3d4a6cb2bbcf9b235ed6bac4a60af92dc736..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>
 #include <QRadioButton>
 #include <QVBoxLayout>
 
-#include "viewproperties.h"
-#include "dolphinview.h"
-
 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     KDialog(dolphinView),
     m_isDirty(false),
-    m_dolphinView(dolphinView)
+    m_dolphinView(dolphinView),
+    m_viewProps(0),
+    m_viewMode(0),
+    m_sorting(0),
+    m_sortOrder(0),
+    m_showPreview(0),
+    m_showHiddenFiles(0),
+    m_applyToSubFolders(0),
+    m_useAsDefault(0)
 {
     assert(dolphinView != 0);
 
@@ -61,7 +70,6 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     m_viewMode = new QComboBox(propsBox);
     m_viewMode->addItem(SmallIcon("view_icon"), i18n("Icons"));
     m_viewMode->addItem(SmallIcon("view_text"), i18n("Details"));
-    m_viewMode->addItem(SmallIcon("gvdirpart"), i18n("Previews"));
     const int index = static_cast<int>(m_viewProps->viewMode());
     m_viewMode->setCurrentIndex(index);
 
@@ -86,8 +94,11 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     const int sortOrderIdx = (m_viewProps->sortOrder() == Qt::Ascending) ? 0 : 1;
     m_sortOrder->setCurrentIndex(sortOrderIdx);
 
+    m_showPreview = new QCheckBox(i18n("Show preview"), propsBox);
+    m_showPreview->setChecked(m_viewProps->showPreview());
+
     m_showHiddenFiles = new QCheckBox(i18n("Show hidden files"), propsBox);
-    m_showHiddenFiles->setChecked(m_viewProps->isShowHiddenFilesEnabled());
+    m_showHiddenFiles->setChecked(m_viewProps->showHiddenFiles());
 
     QGridLayout* propsBoxLayout = new QGridLayout(propsBox);
     propsBoxLayout->addWidget(viewModeLabel, 0, 0);
@@ -97,11 +108,10 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     propsBoxLayout->addWidget(m_sorting, 1, 1);
     propsBoxLayout->addWidget(sortOrderLabel, 2, 0);
     propsBoxLayout->addWidget(m_sortOrder, 2, 1);
-    propsBoxLayout->addWidget(m_showHiddenFiles, 3, 0);
+    propsBoxLayout->addWidget(m_showPreview, 3, 0);
+    propsBoxLayout->addWidget(m_showHiddenFiles, 4, 0);
 
-    m_applyToSubFolders = new QCheckBox(i18n("Apply changes to all sub folders"), main);
     topLayout->addWidget(propsBox);
-    topLayout->addWidget(m_applyToSubFolders);
 
     connect(m_viewMode, SIGNAL(activated(int)),
             this, SLOT(slotViewModeChanged(int)));
@@ -109,15 +119,28 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
             this, SLOT(slotSortingChanged(int)));
     connect(m_sortOrder, SIGNAL(activated(int)),
             this, SLOT(slotSortOrderChanged(int)));
+    connect(m_showPreview, SIGNAL(clicked()),
+            this, SLOT(slotShowPreviewChanged()));
     connect(m_showHiddenFiles, SIGNAL(clicked()),
             this, SLOT(slotShowHiddenFilesChanged()));
 
-    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);
 }
@@ -166,10 +189,17 @@ void ViewPropertiesDialog::slotSortOrderChanged(int index)
     m_isDirty = true;
 }
 
+void ViewPropertiesDialog::slotShowPreviewChanged()
+{
+    const bool show = m_showPreview->isChecked();
+    m_viewProps->setShowPreview(show);
+    m_isDirty = true;
+}
+
 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
 {
     const bool show = m_showHiddenFiles->isChecked();
-    m_viewProps->setShowHiddenFilesEnabled(show);
+    m_viewProps->setShowHiddenFiles(show);
     m_isDirty = true;
 }
 
@@ -180,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;
@@ -194,8 +227,16 @@ 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
 }
 
 #include "viewpropertiesdialog.moc"