]> 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 51474db8f0b3641eb36b38d6904ce6eda5b8027e..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 <qlabel.h>
-#include <qlayout.h>
-#include <q3vbox.h>
-#include <q3buttongroup.h>
-#include <qcheckbox.h>
-#include <qradiobutton.h>
-#include <qpushbutton.h>
-#include <qsizepolicy.h>
-#include <q3groupbox.h>
-#include <qcombobox.h>
-//Added by qt3to4:
-#include <Q3VBoxLayout>
 #include <kiconloader.h>
 #include <kmessagebox.h>
 #include <assert.h>
 
-#include "viewproperties.h"
-#include "dolphinview.h"
+#include <QCheckBox>
+#include <QComboBox>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QLabel>
+#include <QRadioButton>
+#include <QVBoxLayout>
 
 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
-    KDialog(dolphinView, static_cast<Qt::WFlags>(Ok /* KDE4-TODO: Apply | Cancel*/)),
+    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);
 
-    const int margin = KDialog::marginHint();
-    const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+    setCaption(i18n("View Properties"));
+    setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
 
     const KUrl& url = dolphinView->url();
     m_viewProps = new ViewProperties(url);
     m_viewProps->setAutoSaveEnabled(false);
 
-    Q3VBoxLayout* topLayout = new Q3VBoxLayout(mainWidget(), 0, spacingHint());
+    QWidget* main = new QWidget();
+    QVBoxLayout* topLayout = new QVBoxLayout();
 
     // create 'Properties' group containing view mode, sorting, sort order and show hidden files
-    Q3GroupBox* propsGroup = new Q3GroupBox(2, Qt::Horizontal, i18n("Properties"), mainWidget());
-    propsGroup->setSizePolicy(sizePolicy);
-    propsGroup->setMargin(margin);
-
-    new QLabel(i18n("View mode:"), propsGroup);
-    m_viewMode = new QComboBox(propsGroup);
-    m_viewMode->insertItem(SmallIcon("view_icon"), i18n("Icons"));
-    m_viewMode->insertItem(SmallIcon("view_text"), i18n("Details"));
-    m_viewMode->insertItem(SmallIcon("gvdirpart"), i18n("Previews"));
+    QGroupBox* propsBox = new QGroupBox(i18n("Properties"), main);
+
+    QLabel* viewModeLabel = new QLabel(i18n("View mode:"), propsBox);
+    m_viewMode = new QComboBox(propsBox);
+    m_viewMode->addItem(SmallIcon("view_icon"), i18n("Icons"));
+    m_viewMode->addItem(SmallIcon("view_text"), i18n("Details"));
     const int index = static_cast<int>(m_viewProps->viewMode());
-    m_viewMode->setCurrentItem(index);
+    m_viewMode->setCurrentIndex(index);
 
-    new QLabel(i18n("Sorting:"), propsGroup);
-    m_sorting = new QComboBox(propsGroup);
-    m_sorting->insertItem("By Name");
-    m_sorting->insertItem("By Size");
-    m_sorting->insertItem("By Date");
+    QLabel* sortingLabel = new QLabel(i18n("Sorting:"), propsBox);
+    m_sorting = new QComboBox(propsBox);
+    m_sorting->addItem("By Name");
+    m_sorting->addItem("By Size");
+    m_sorting->addItem("By Date");
     int sortingIdx = 0;
     switch (m_viewProps->sorting()) {
         case DolphinView::SortByName: sortingIdx = 0; break;
@@ -80,44 +85,33 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
         case DolphinView::SortByDate: sortingIdx = 2; break;
         default: break;
     }
-    m_sorting->setCurrentItem(sortingIdx);
+    m_sorting->setCurrentIndex(sortingIdx);
 
-    new QLabel(i18n("Sort order:"), propsGroup);
-    m_sortOrder = new QComboBox(propsGroup);
-    m_sortOrder->insertItem(i18n("Ascending"));
-    m_sortOrder->insertItem(i18n("Descending"));
+    QLabel* sortOrderLabel = new QLabel(i18n("Sort order:"), propsBox);
+    m_sortOrder = new QComboBox(propsBox);
+    m_sortOrder->addItem(i18n("Ascending"));
+    m_sortOrder->addItem(i18n("Descending"));
     const int sortOrderIdx = (m_viewProps->sortOrder() == Qt::Ascending) ? 0 : 1;
-    m_sortOrder->setCurrentItem(sortOrderIdx);
+    m_sortOrder->setCurrentIndex(sortOrderIdx);
 
-    m_showHiddenFiles = new QCheckBox(i18n("Show hidden files"), propsGroup);
-    m_showHiddenFiles->setChecked(m_viewProps->isShowHiddenFilesEnabled());
+    m_showPreview = new QCheckBox(i18n("Show preview"), propsBox);
+    m_showPreview->setChecked(m_viewProps->showPreview());
 
-    // create 'Apply view properties to:' group
-    Q3ButtonGroup* buttonGroup = new Q3ButtonGroup(3,
-                                                 Qt::Vertical,
-                                                 i18n("Apply view properties to:"),
-                                                 mainWidget());
-    buttonGroup->setSizePolicy(sizePolicy);
-    buttonGroup->setMargin(margin);
+    m_showHiddenFiles = new QCheckBox(i18n("Show hidden files"), propsBox);
+    m_showHiddenFiles->setChecked(m_viewProps->showHiddenFiles());
 
-    m_applyToCurrentFolder = new QRadioButton(i18n("Current folder"), buttonGroup);
-    buttonGroup->insert(m_applyToCurrentFolder);
+    QGridLayout* propsBoxLayout = new QGridLayout(propsBox);
+    propsBoxLayout->addWidget(viewModeLabel, 0, 0);
+    propsBoxLayout->addWidget(m_viewMode, 0, 1);
+    propsBoxLayout->addWidget(m_sorting, 1, 1);
+    propsBoxLayout->addWidget(sortingLabel, 1, 0);
+    propsBoxLayout->addWidget(m_sorting, 1, 1);
+    propsBoxLayout->addWidget(sortOrderLabel, 2, 0);
+    propsBoxLayout->addWidget(m_sortOrder, 2, 1);
+    propsBoxLayout->addWidget(m_showPreview, 3, 0);
+    propsBoxLayout->addWidget(m_showHiddenFiles, 4, 0);
 
-    m_applyToSubFolders = new QRadioButton(i18n("Current folder including all sub folders"), buttonGroup);
-    buttonGroup->insert(m_applyToSubFolders);
-
-    m_applyToAllFolders = new QRadioButton(i18n("All folders"), buttonGroup);
-    buttonGroup->insert(m_applyToAllFolders);
-
-    if (m_viewProps->isValidForSubDirs()) {
-        m_applyToSubFolders->setChecked(true);
-    }
-    else {
-        m_applyToCurrentFolder->setChecked(true);
-    }
-
-    topLayout->addWidget(propsGroup);
-    topLayout->addWidget(buttonGroup);
+    topLayout->addWidget(propsBox);
 
     connect(m_viewMode, SIGNAL(activated(int)),
             this, SLOT(slotViewModeChanged(int)));
@@ -125,14 +119,30 @@ 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_applyToCurrentFolder, SIGNAL(clicked()),
-            this, SLOT(slotApplyToCurrentFolder()));
-    connect(m_applyToSubFolders, SIGNAL(clicked()),
-            this, SLOT(slotApplyToSubFolders()));
-    connect(m_applyToAllFolders, SIGNAL(clicked()),
-            this, SLOT(slotApplyToAllFolders()));
+
+    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);
 }
 
 ViewPropertiesDialog::~ViewPropertiesDialog()
@@ -145,13 +155,12 @@ ViewPropertiesDialog::~ViewPropertiesDialog()
 void ViewPropertiesDialog::slotOk()
 {
     applyViewProperties();
-    // KDE4-TODO: KDialog::slotOk();
+    accept();
 }
 
 void ViewPropertiesDialog::slotApply()
 {
     applyViewProperties();
-    // KDE4-TODO: KDialog::slotApply();
 }
 
 void ViewPropertiesDialog::slotViewModeChanged(int index)
@@ -180,57 +189,54 @@ void ViewPropertiesDialog::slotSortOrderChanged(int index)
     m_isDirty = true;
 }
 
-void ViewPropertiesDialog::slotShowHiddenFilesChanged()
+void ViewPropertiesDialog::slotShowPreviewChanged()
 {
-    const bool show = m_showHiddenFiles->isChecked();
-    m_viewProps->setShowHiddenFilesEnabled(show);
+    const bool show = m_showPreview->isChecked();
+    m_viewProps->setShowPreview(show);
     m_isDirty = true;
 }
 
-void ViewPropertiesDialog::slotApplyToCurrentFolder()
-{
-    m_viewProps->setValidForSubDirs(false);
-    m_isDirty = true;
-}
-
-void ViewPropertiesDialog::slotApplyToSubFolders()
+void ViewPropertiesDialog::slotShowHiddenFilesChanged()
 {
-    m_viewProps->setValidForSubDirs(true);
+    const bool show = m_showHiddenFiles->isChecked();
+    m_viewProps->setShowHiddenFiles(show);
     m_isDirty = true;
 }
 
-void ViewPropertiesDialog::slotApplyToAllFolders()
+void ViewPropertiesDialog::markAsDirty()
 {
     m_isDirty = true;
 }
 
 void ViewPropertiesDialog::applyViewProperties()
 {
-    if (m_applyToAllFolders->isChecked()) {
-        if (m_isDirty) {
-            const QString text(i18n("The view properties of all folders will be replaced. Do you want to continue?"));
-            if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
-                return;
-            }
-        }
-
-        ViewProperties props(QDir::homePath());
-        props.setViewMode(m_viewProps->viewMode());
-        props.setSorting(m_viewProps->sorting());
-        props.setSortOrder(m_viewProps->sortOrder());
-        props.setShowHiddenFilesEnabled(m_viewProps->isShowHiddenFilesEnabled());
-        props.setValidForSubDirs(true);
-    }
-    else if (m_applyToSubFolders->isChecked() && m_isDirty) {
-        const QString text(i18n("The view properties of all sub folders will be replaced. Do you want to continue?"));
+    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;
         }
+
+        ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView,
+                                                                m_dolphinView->url(),
+                                                                *m_viewProps);
+        info->setWindowModality(Qt::NonModal);
+        info->show();
     }
 
     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"