From 6422ae393ed378f8dcde0bf35e1f8d67a5df2295 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Tue, 10 Apr 2007 11:22:56 +0000 Subject: [PATCH] allow to enable the categorization feature for sorting svn path=/trunk/KDE/kdebase/apps/; revision=652200 --- ...dolphin_directoryviewpropertysettings.kcfg | 6 ++ src/dolphiniconsview.cpp | 13 +--- src/dolphiniconsview.h | 1 - src/dolphinmainwindow.cpp | 21 +++++++ src/dolphinmainwindow.h | 6 ++ src/dolphinui.rc | 1 + src/dolphinview.cpp | 60 +++++++++++++++++++ src/dolphinview.h | 21 +++++++ src/viewproperties.cpp | 15 +++++ src/viewproperties.h | 3 + src/viewpropertiesdialog.cpp | 20 ++++++- src/viewpropertiesdialog.h | 2 + 12 files changed, 156 insertions(+), 13 deletions(-) diff --git a/src/dolphin_directoryviewpropertysettings.kcfg b/src/dolphin_directoryviewpropertysettings.kcfg index 64a859173..7b192f549 100644 --- a/src/dolphin_directoryviewpropertysettings.kcfg +++ b/src/dolphin_directoryviewpropertysettings.kcfg @@ -29,6 +29,12 @@ false + + + When this option is enabled, the sorted items get summarized by their category. + false + + This option defines which attribute (name, size, date, etc) sorting is performed on. diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index de66613be..85a409520 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -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 { diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index f0d0abc1a..36df119d7 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -73,7 +73,6 @@ private: private: DolphinController* m_controller; QStyleOptionViewItem m_viewOptions; - DolphinItemCategorizer* m_itemCategorizer; }; #endif diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 3a375ebb9..eed6da4ea 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -275,6 +275,14 @@ void DolphinMainWindow::slotShowHiddenFilesChanged() showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles()); } +void DolphinMainWindow::slotCategorizedSortingChanged() +{ + KToggleAction* categorizedSortingAction = + static_cast(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("categorized"); + sortCategorized->setText(i18n("Categorized")); + connect(sortCategorized, SIGNAL(triggered()), this, SLOT(toggleSortCategorization())); + KToggleAction* clearInfo = actionCollection()->add("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)), diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 4212a0987..bdb7ec59a 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -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); diff --git a/src/dolphinui.rc b/src/dolphinui.rc index bb3e2d729..17edc1aa7 100644 --- a/src/dolphinui.rc +++ b/src/dolphinui.rc @@ -32,6 +32,7 @@ + Additional Information diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 45717afc1..48f0214bc 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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; diff --git a/src/dolphinview.h b/src/dolphinview.h index 4f78f050b..d60556663 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -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); diff --git a/src/viewproperties.cpp b/src/viewproperties.cpp index 485ed4384..ab5e0634e 100644 --- a/src/viewproperties.cpp +++ b/src/viewproperties.cpp @@ -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()); diff --git a/src/viewproperties.h b/src/viewproperties.h index 7050073d7..74ff72cb1 100644 --- a/src/viewproperties.h +++ b/src/viewproperties.h @@ -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; diff --git a/src/viewpropertiesdialog.cpp b/src/viewpropertiesdialog.cpp index 9a721e2bc..61fd38476 100644 --- a/src/viewpropertiesdialog.cpp +++ b/src/viewpropertiesdialog.cpp @@ -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(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()); diff --git a/src/viewpropertiesdialog.h b/src/viewpropertiesdialog.h index 2454137bb..3843fd558 100644 --- a/src/viewpropertiesdialog.h +++ b/src/viewpropertiesdialog.h @@ -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; -- 2.47.3