]> cloud.milkyroute.net Git - dolphin.git/commitdiff
allow to enable the categorization feature for sorting
authorPeter Penz <peter.penz19@gmail.com>
Tue, 10 Apr 2007 11:22:56 +0000 (11:22 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 10 Apr 2007 11:22:56 +0000 (11:22 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=652200

12 files changed:
src/dolphin_directoryviewpropertysettings.kcfg
src/dolphiniconsview.cpp
src/dolphiniconsview.h
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinui.rc
src/dolphinview.cpp
src/dolphinview.h
src/viewproperties.cpp
src/viewproperties.h
src/viewpropertiesdialog.cpp
src/viewpropertiesdialog.h

index 64a859173af4922a505a55835e2706bf1bdad015..7b192f54950cb07820237b2d6daa67ef58610f1d 100644 (file)
             <default>false</default>
         </entry>
 
+        <entry name="CategorizedSorting" type="Bool" >
+            <label>Categorized Sorting</label>
+            <whatsthis>When this option is enabled, the sorted items get summarized by their category.</whatsthis>
+            <default>false</default>
+        </entry>
+
         <entry name="Sorting" type="Int" >
             <label>Sort files by</label>
             <whatsthis>This option defines which attribute (name, size, date, etc) sorting is performed on.</whatsthis>
index de66613bec9894afdf8c4fca99dbd89eb7a2d94d..85a40952015546e4fc1fbdecbc53d56f60dbcb04 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "dolphiniconsview.h"
 
-#include "dolphinitemcategorizer.h"
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
 #include "dolphinitemcategorizer.h"
@@ -35,8 +34,7 @@
 
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
         KListView(parent),
-        m_controller(controller),
-        m_itemCategorizer(0)
+        m_controller(controller)
 {
     Q_ASSERT(controller != 0);
     setViewMode(QListView::IconMode);
@@ -75,17 +73,10 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
         setFlow(QListView::TopToBottom);
         m_viewOptions.decorationPosition = QStyleOptionViewItem::Left;
     }
-
-    m_itemCategorizer = new DolphinItemCategorizer();
-    // setItemCategorizer(m_itemCategorizer);
 }
 
 DolphinIconsView::~DolphinIconsView()
-{
-    setItemCategorizer(0);
-    delete m_itemCategorizer;
-    m_itemCategorizer = 0;
-}
+{}
 
 QStyleOptionViewItem DolphinIconsView::viewOptions() const
 {
index f0d0abc1a6acac47a2d6350032ad098fd8e64bbb..36df119d7159be2f545394c63183d13cbcec111c 100644 (file)
@@ -73,7 +73,6 @@ private:
 private:
     DolphinController* m_controller;
     QStyleOptionViewItem m_viewOptions;
-    DolphinItemCategorizer* m_itemCategorizer;
 };
 
 #endif
index 3a375ebb93365830980a80fff837a77f96d61261..eed6da4ea74b26a8011ce6b3b7d1828ec4653cac 100644 (file)
@@ -275,6 +275,14 @@ void DolphinMainWindow::slotShowHiddenFilesChanged()
     showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
 }
 
+void DolphinMainWindow::slotCategorizedSortingChanged()
+{
+    KToggleAction* categorizedSortingAction =
+        static_cast<KToggleAction*>(actionCollection()->action("categorized"));
+    categorizedSortingAction->setChecked(m_activeView->categorizedSorting());
+    categorizedSortingAction->setEnabled(m_activeView->supportsCategorizedSorting());
+}
+
 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
 {
     QAction* action = 0;
@@ -714,6 +722,12 @@ void DolphinMainWindow::toggleSortOrder()
     m_activeView->setSortOrder(order);
 }
 
+void DolphinMainWindow::toggleSortCategorization()
+{
+    const bool categorizedSorting = m_activeView->categorizedSorting();
+    m_activeView->setCategorizedSorting(!categorizedSorting);
+}
+
 void DolphinMainWindow::clearInfo()
 {
     m_activeView->setAdditionalInfo(KFileItemDelegate::NoInformation);
@@ -1157,6 +1171,10 @@ void DolphinMainWindow::setupActions()
     sortDescending->setText(i18n("Descending"));
     connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
 
+    KToggleAction* sortCategorized = actionCollection()->add<KToggleAction>("categorized");
+    sortCategorized->setText(i18n("Categorized"));
+    connect(sortCategorized, SIGNAL(triggered()), this, SLOT(toggleSortCategorization()));
+
     KToggleAction* clearInfo = actionCollection()->add<KToggleAction>("clear_info");
     clearInfo->setText(i18n("No Information"));
     connect(clearInfo, SIGNAL(triggered()), this, SLOT(clearInfo()));
@@ -1391,6 +1409,7 @@ void DolphinMainWindow::updateViewActions()
 
     slotSortingChanged(m_activeView->sorting());
     slotSortOrderChanged(m_activeView->sortOrder());
+    slotCategorizedSortingChanged();
     slotAdditionalInfoChanged(m_activeView->additionalInfo());
 
     KToggleAction* showFilterBarAction =
@@ -1452,6 +1471,8 @@ void DolphinMainWindow::connectViewSignals(int viewIndex)
             this, SLOT(slotShowPreviewChanged()));
     connect(view, SIGNAL(showHiddenFilesChanged()),
             this, SLOT(slotShowHiddenFilesChanged()));
+    connect(view, SIGNAL(categorizedSortingChanged()),
+            this, SLOT(slotCategorizedSortingChanged()));
     connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
             this, SLOT(slotSortingChanged(DolphinView::Sorting)));
     connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
index 4212a0987564c99b6c806c125146ce7d076d8e89..bdb7ec59aeb6827a08386cda03ffae158bf90560 100644 (file)
@@ -265,6 +265,9 @@ private slots:
     /** Switches between an ascending and descending sorting order. */
     void toggleSortOrder();
 
+    /** Switches between sorting by categories or not. */
+    void toggleSortCategorization();
+
     /**
      * Clears any additional information for an item except for the
      * name and the icon.
@@ -364,6 +367,9 @@ private slots:
     /** Updates the state of the 'Show hidden files' menu action. */
     void slotShowHiddenFilesChanged();
 
+    /** Updates the state of the 'Categorized sorting' menu action. */
+    void slotCategorizedSortingChanged();
+
     /** Updates the state of the 'Sort by' actions. */
     void slotSortingChanged(DolphinView::Sorting sorting);
 
index bb3e2d7291be6443f6eb30e4e0343e501907ec89..17edc1aa79478969cf259e1f290569dd87ab6df7 100644 (file)
@@ -32,6 +32,7 @@
     <Action name="by_group" />
     <Separator/>
     <Action name="descending" />
+    <Action name="categorized" />
    </Menu>
    <Menu name="additional_info">
     <text>Additional Information</text>
index 45717afc1b9a439aed9a78c611f40f556702e656..48f0214bcbaaa06556d5e87de623ccd253d05902 100644 (file)
@@ -51,6 +51,7 @@
 #include "dolphindetailsview.h"
 #include "dolphiniconsview.h"
 #include "dolphincontextmenu.h"
+#include "dolphinitemcategorizer.h"
 #include "filterbar.h"
 #include "renamedialog.h"
 #include "kurlnavigator.h"
@@ -255,6 +256,44 @@ bool DolphinView::showHiddenFiles() const
     return m_dirLister->showingDotFiles();
 }
 
+void DolphinView::setCategorizedSorting(bool categorized)
+{
+    if (!supportsCategorizedSorting() || (categorized == categorizedSorting())) {
+        return;
+    }
+
+    Q_ASSERT(m_iconsView != 0);
+    if (categorized) {
+        Q_ASSERT(m_iconsView->itemCategorizer() == 0);
+        m_iconsView->setItemCategorizer(new DolphinItemCategorizer());
+    } else {
+        KItemCategorizer* categorizer = m_iconsView->itemCategorizer();
+        m_iconsView->setItemCategorizer(0);
+        delete categorizer;
+    }
+
+    ViewProperties props(m_urlNavigator->url());
+    props.setCategorizedSorting(categorized);
+    props.save();
+
+    emit categorizedSortingChanged();
+}
+
+bool DolphinView::categorizedSorting() const
+{
+    if (!supportsCategorizedSorting()) {
+        return false;
+    }
+
+    Q_ASSERT(m_iconsView != 0);
+    return m_iconsView->itemCategorizer() != 0;
+}
+
+bool DolphinView::supportsCategorizedSorting() const
+{
+    return m_iconsView != 0;
+}
+
 void DolphinView::renameSelectedItems()
 {
     DolphinView* view = mainWindow()->activeView();
@@ -612,6 +651,22 @@ void DolphinView::loadDirectory(const KUrl& url)
         emit showHiddenFilesChanged();
     }
 
+    const bool categorized = props.categorizedSorting();
+    if (categorized != categorizedSorting()) {
+        if (supportsCategorizedSorting()) {
+            Q_ASSERT(m_iconsView != 0);
+            if (categorized) {
+                Q_ASSERT(m_iconsView->itemCategorizer() == 0);
+                m_iconsView->setItemCategorizer(new DolphinItemCategorizer());
+            } else {
+                KItemCategorizer* categorizer = m_iconsView->itemCategorizer();
+                m_iconsView->setItemCategorizer(0);
+                delete categorizer;
+            }
+        }
+        emit categorizedSortingChanged();
+    }
+
     const DolphinView::Sorting sorting = props.sorting();
     if (sorting != m_proxyModel->sorting()) {
         m_proxyModel->setSorting(sorting);
@@ -1096,6 +1151,11 @@ void DolphinView::createView()
     if (view != 0) {
         m_topLayout->removeWidget(view);
         view->close();
+        if (view == m_iconsView) {
+            KItemCategorizer* categorizer = m_iconsView->itemCategorizer();
+            m_iconsView->setItemCategorizer(0);
+            delete categorizer;
+        }
         view->deleteLater();
         view = 0;
         m_iconsView = 0;
index 4f78f050be8bfbc1de98e79346f203251454fbce..d6055666343ed4e98de3f7692d56ea99e79316ec 100644 (file)
@@ -164,6 +164,24 @@ public:
     void setShowHiddenFiles(bool show);
     bool showHiddenFiles() const;
 
+    /**
+     * Summarizes all sorted items by their category \a categorized
+     * is true.
+     * If the view properties should be remembered for each directory
+     * (GeneralSettings::globalViewProps() returns false), then the
+     * categorized sorting setting will be be stored automatically.
+     */
+    void setCategorizedSorting(bool categorized);
+    bool categorizedSorting() const;
+
+    /**
+     * Returns true, if the categorized sorting is supported by the current
+     * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
+     * supports categorizations. To check whether the categorized
+     * sorting is set, use DolphinView::categorizedSorting().
+     */
+    bool supportsCategorizedSorting() const;
+
     /**
      * Triggers the renaming of the currently selected items, where
      * the user must input a new name for the items.
@@ -375,6 +393,9 @@ signals:
     /** Is emitted if the 'show hidden files' property has been changed. */
     void showHiddenFilesChanged();
 
+    /** Is emitted if the 'categorized sorting' property has been changed. */
+    void categorizedSortingChanged();
+
     /** Is emitted if the sorting by name, size or date has been changed. */
     void sortingChanged(DolphinView::Sorting sorting);
 
index 485ed438498f6a8146bfe40e72c89d9721318ab8..ab5e0634e2083087a8ced4b263ad7b01452d4e26 100644 (file)
@@ -131,6 +131,20 @@ void ViewProperties::setShowHiddenFiles(bool show)
     }
 }
 
+void ViewProperties::setCategorizedSorting(bool categorized)
+{
+    if (m_node->categorizedSorting() != categorized) {
+        m_node->setCategorizedSorting(categorized);
+        updateTimeStamp();
+    }
+}
+
+bool ViewProperties::categorizedSorting() const
+{
+    return m_node->categorizedSorting();
+}
+
+
 bool ViewProperties::showHiddenFiles() const
 {
     return m_node->showHiddenFiles();
@@ -181,6 +195,7 @@ void ViewProperties::setDirProperties(const ViewProperties& props)
     setViewMode(props.viewMode());
     setShowPreview(props.showPreview());
     setShowHiddenFiles(props.showHiddenFiles());
+    setCategorizedSorting(props.categorizedSorting());
     setSorting(props.sorting());
     setSortOrder(props.sortOrder());
     setAdditionalInfo(props.additionalInfo());
index 7050073d7d05db1fa743da7e129f70841ff4776e..74ff72cb17df567ee19acb1b172e84a825b6635f 100644 (file)
@@ -66,6 +66,9 @@ public:
     void setShowHiddenFiles(bool show);
     bool showHiddenFiles() const;
 
+    void setCategorizedSorting(bool categorized);
+    bool categorizedSorting() const;
+
     void setSorting(DolphinView::Sorting sorting);
     DolphinView::Sorting sorting() const;
 
index 9a721e2bc2c15dabea5deec0b495594d87fb89a6..61fd38476967b2c084e9330fd21a4fd5c4bca60a 100644 (file)
@@ -51,6 +51,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
         m_viewMode(0),
         m_sorting(0),
         m_sortOrder(0),
+        m_categorizedSorting(0),
         m_additionalInfo(0),
         m_showPreview(0),
         m_showHiddenFiles(0),
@@ -94,6 +95,11 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     const int sortOrderIdx = (m_viewProps->sortOrder() == Qt::AscendingOrder) ? 0 : 1;
     m_sortOrder->setCurrentIndex(sortOrderIdx);
 
+    m_categorizedSorting = new QComboBox(sortingBox);
+    m_categorizedSorting->addItem(i18n("Uncategorized"));
+    m_categorizedSorting->addItem(i18n("Categorized"));
+    m_categorizedSorting->setCurrentIndex(m_viewProps->categorizedSorting() ? 1 : 0);
+
     m_sorting = new QComboBox(sortingBox);
     m_sorting->addItem("By Name");
     m_sorting->addItem("By Size");
@@ -107,6 +113,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
     sortingLayout->setMargin(0);
     sortingLayout->addWidget(m_sortOrder);
     sortingLayout->addWidget(m_sorting);
+    sortingLayout->addWidget(m_categorizedSorting);
     sortingBox->setLayout(sortingLayout);
 
     QLabel* additionalInfoLabel = new QLabel(i18n("Additional information:"), propsBox);
@@ -143,6 +150,8 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
             this, SLOT(slotSortingChanged(int)));
     connect(m_sortOrder, SIGNAL(activated(int)),
             this, SLOT(slotSortOrderChanged(int)));
+    connect(m_categorizedSorting, SIGNAL(activated(int)),
+            this, SLOT(slotCategorizedSortingChanged(int)));
     connect(m_additionalInfo, SIGNAL(activated(int)),
             this, SLOT(slotAdditionalInfoChanged(int)));
     connect(m_showPreview, SIGNAL(clicked()),
@@ -216,7 +225,9 @@ void ViewPropertiesDialog::slotViewModeChanged(int index)
     m_viewProps->setViewMode(static_cast<DolphinView::Mode>(index));
     m_isDirty = true;
 
-    m_additionalInfo->setEnabled(m_viewProps->viewMode() == DolphinView::IconsView);
+    const bool iconsViewEnabled = (m_viewProps->viewMode() == DolphinView::IconsView);
+    m_categorizedSorting->setEnabled(iconsViewEnabled);
+    m_additionalInfo->setEnabled(iconsViewEnabled);
 }
 
 void ViewPropertiesDialog::slotSortingChanged(int index)
@@ -233,6 +244,12 @@ void ViewPropertiesDialog::slotSortOrderChanged(int index)
     m_isDirty = true;
 }
 
+void ViewPropertiesDialog::slotCategorizedSortingChanged(int index)
+{
+    m_viewProps->setCategorizedSorting(index == 1);
+    m_isDirty = true;
+}
+
 void ViewPropertiesDialog::slotAdditionalInfoChanged(int index)
 {
     KFileItemDelegate::AdditionalInformation info = KFileItemDelegate::NoInformation;
@@ -307,6 +324,7 @@ void ViewPropertiesDialog::applyViewProperties()
     m_dolphinView->setMode(m_viewProps->viewMode());
     m_dolphinView->setSorting(m_viewProps->sorting());
     m_dolphinView->setSortOrder(m_viewProps->sortOrder());
+    m_dolphinView->setCategorizedSorting(m_viewProps->categorizedSorting());
     m_dolphinView->setAdditionalInfo(m_viewProps->additionalInfo());
     m_dolphinView->setShowPreview(m_viewProps->showPreview());
     m_dolphinView->setShowHiddenFiles(m_viewProps->showHiddenFiles());
index 2454137bbeae346fa1fac221fe86eee5bb2c7fc6..3843fd5587fe3b6edbb7739f4152c9e0bdfe9eca 100644 (file)
@@ -50,6 +50,7 @@ private slots:
     void slotViewModeChanged(int index);
     void slotSortingChanged(int index);
     void slotSortOrderChanged(int index);
+    void slotCategorizedSortingChanged(int index);
     void slotAdditionalInfoChanged(int index);
     void slotShowPreviewChanged();
     void slotShowHiddenFilesChanged();
@@ -63,6 +64,7 @@ private:
     QComboBox* m_viewMode;
     QComboBox* m_sorting;
     QComboBox* m_sortOrder;
+    QComboBox* m_categorizedSorting;
     QComboBox* m_additionalInfo;
     QCheckBox* m_showPreview;
     QCheckBox* m_showHiddenFiles;