From: Frank Reininghaus Date: Mon, 20 Apr 2009 17:52:21 +0000 (+0000) Subject: Let the user choose if folders are always shown first in the views of X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/29c5ab3b74d26657c60b40770676be082caa953d Let the user choose if folders are always shown first in the views of Dolphin and Konqueror (the default) or not. This setting can be changed in the View menu: "View->Sort By->Folders First". FEATURE: 62007 svn path=/trunk/KDE/kdebase/apps/; revision=956820 --- diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 3a7f03e47..f34be92e9 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -65,6 +65,8 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control this, SLOT(slotSortingChanged(DolphinView::Sorting))); connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(slotSortOrderChanged(Qt::SortOrder))); + connect(view, SIGNAL(sortFoldersFirstChanged(bool)), + this, SLOT(slotSortFoldersFirstChanged(bool))); connect(view, SIGNAL(showHiddenFilesChanged()), this, SLOT(slotShowHiddenFilesChanged())); connect(view, SIGNAL(showPreviewChanged()), @@ -448,6 +450,13 @@ void DolphinColumnView::slotSortOrderChanged(Qt::SortOrder order) } } +void DolphinColumnView::slotSortFoldersFirstChanged(bool foldersFirst) +{ + foreach (DolphinColumnWidget* column, m_columns) { + column->setSortFoldersFirst(foldersFirst); + } +} + void DolphinColumnView::slotShowHiddenFilesChanged() { const bool show = m_controller->dolphinView()->showHiddenFiles(); diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 65e4ff3e9..360148672 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -167,6 +167,7 @@ private slots: void slotSortingChanged(DolphinView::Sorting sorting); void slotSortOrderChanged(Qt::SortOrder order); + void slotSortFoldersFirstChanged(bool foldersFirst); void slotShowHiddenFilesChanged(); void slotShowPreviewChanged(); diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index b0d40f5b6..e85c9491b 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -126,6 +126,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, const DolphinView* dolphinView = m_view->m_controller->dolphinView(); m_proxyModel->setSorting(dolphinView->sorting()); m_proxyModel->setSortOrder(dolphinView->sortOrder()); + m_proxyModel->setSortFoldersFirst(dolphinView->sortFoldersFirst()); setModel(m_proxyModel); @@ -210,6 +211,11 @@ void DolphinColumnWidget::setSortOrder(Qt::SortOrder order) m_proxyModel->setSortOrder(order); } +void DolphinColumnWidget::setSortFoldersFirst(bool foldersFirst) +{ + m_proxyModel->setSortFoldersFirst(foldersFirst); +} + void DolphinColumnWidget::setShowHiddenFiles(bool show) { if (show != m_dirLister->showingDotFiles()) { diff --git a/src/dolphincolumnwidget.h b/src/dolphincolumnwidget.h index 916bfac2e..02c9aea81 100644 --- a/src/dolphincolumnwidget.h +++ b/src/dolphincolumnwidget.h @@ -86,6 +86,7 @@ public: void setSorting(DolphinView::Sorting sorting); void setSortOrder(Qt::SortOrder order); + void setSortFoldersFirst(bool foldersFirst); void setShowHiddenFiles(bool show); void setShowPreview(bool show); diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index b128c9033..85ff5039f 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -104,6 +104,11 @@ void DolphinController::indicateSortOrderChange(Qt::SortOrder order) emit sortOrderChanged(order); } +void DolphinController::indicateSortFoldersFirstChange(bool foldersFirst) +{ + emit sortFoldersFirstChanged(foldersFirst); +} + void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info) { emit additionalInfoChanged(info); diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index 29dd7dfb1..f6abbb148 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -59,6 +59,7 @@ class QWidget; * - indicateDroppedUrls() * - indicateSortingChange() * - indicateSortOrderChanged() + * - indicateSortFoldersFirstChanged() * - triggerItem() * - requestTab() * - handleKeyPressEvent() @@ -164,6 +165,15 @@ public: */ void indicateSortOrderChange(Qt::SortOrder order); + /** + * Informs the abstract Dolphin view about a change between separate sorting + * (with folders first) and mixed sorting of files and folders done inside + * the view implementation. This method should be invoked by the view + * implementation (e. g. the details view uses this method in combination + * with the details header). + */ + void indicateSortFoldersFirstChange(bool foldersFirst); + /** * Informs the abstract Dolphin view about an additional information change * done inside the view implementation. This method should be invoked by the @@ -316,6 +326,14 @@ signals: */ void sortOrderChanged(Qt::SortOrder order); + /** + * Is emitted if 'sort folders first' has been changed to \a foldersFirst + * by the view implementation (see indicateSortOrderChanged(). + * The abstract Dolphin view connects + * to this signal to update its menu actions. + */ + void sortFoldersFirstChanged(bool foldersFirst); + /** * Is emitted if the additional info has been changed to \a info * by the view implementation. The abstract Dolphin view connects diff --git a/src/dolphinpart.rc b/src/dolphinpart.rc index 2ed6ea764..d0b2cc634 100644 --- a/src/dolphinpart.rc +++ b/src/dolphinpart.rc @@ -27,6 +27,7 @@ + Additional Information diff --git a/src/dolphinsortfilterproxymodel.cpp b/src/dolphinsortfilterproxymodel.cpp index 6b0a454a7..2622f9034 100644 --- a/src/dolphinsortfilterproxymodel.cpp +++ b/src/dolphinsortfilterproxymodel.cpp @@ -73,6 +73,23 @@ void DolphinSortFilterProxyModel::setSortOrder(Qt::SortOrder sortOrder) KDirSortFilterProxyModel::sort((int) m_sorting, m_sortOrder); } +void DolphinSortFilterProxyModel::setSortFoldersFirst(bool foldersFirst) +{ + if (foldersFirst != sortFoldersFirst()) { + KDirSortFilterProxyModel::setSortFoldersFirst(foldersFirst); + + // We need to make sure that the files and folders are really resorted. + // Without the following two lines, QSortFilterProxyModel::sort(int column, Qt::SortOrder order) + // would do nothing because neither the column nor the sort order have changed. + // TODO: remove this hack if we find a better way to force the ProxyModel to re-sort the data. + Qt::SortOrder tmpSortOrder = (m_sortOrder == Qt::AscendingOrder ? Qt::DescendingOrder : Qt::AscendingOrder); + KDirSortFilterProxyModel::sort((int) m_sorting, tmpSortOrder); + + // Now comes the real sorting with the old column and sort order + KDirSortFilterProxyModel::sort((int) m_sorting, m_sortOrder); + } +} + void DolphinSortFilterProxyModel::sort(int column, Qt::SortOrder sortOrder) { m_sorting = sortingForColumn(column); diff --git a/src/dolphinsortfilterproxymodel.h b/src/dolphinsortfilterproxymodel.h index b9e6b74e8..fa7bded92 100644 --- a/src/dolphinsortfilterproxymodel.h +++ b/src/dolphinsortfilterproxymodel.h @@ -56,6 +56,8 @@ public: void setSortOrder(Qt::SortOrder sortOrder); Qt::SortOrder sortOrder() const; + void setSortFoldersFirst(bool foldersFirst); + /** * @reimplemented, @internal * diff --git a/src/dolphinui.rc b/src/dolphinui.rc index 05dfd3abb..a70285fb3 100644 --- a/src/dolphinui.rc +++ b/src/dolphinui.rc @@ -37,6 +37,7 @@ + Additional Information diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index ed17c94ab..f2f23d273 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -129,6 +129,8 @@ DolphinView::DolphinView(QWidget* parent, this, SLOT(updateSorting(DolphinView::Sorting))); connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(updateSortOrder(Qt::SortOrder))); + connect(m_controller, SIGNAL(sortFoldersFirstChanged(bool)), + this, SLOT(updateSortFoldersFirst(bool))); connect(m_controller, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)), this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList&))); connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)), @@ -443,6 +445,18 @@ Qt::SortOrder DolphinView::sortOrder() const return m_proxyModel->sortOrder(); } +void DolphinView::setSortFoldersFirst(bool foldersFirst) +{ + if (sortFoldersFirst() != foldersFirst) { + updateSortFoldersFirst(foldersFirst); + } +} + +bool DolphinView::sortFoldersFirst() const +{ + return m_proxyModel->sortFoldersFirst(); +} + void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info) { const KUrl viewPropsUrl = viewPropertiesUrl(); @@ -818,6 +832,11 @@ void DolphinView::toggleSortOrder() setSortOrder(order); } +void DolphinView::toggleSortFoldersFirst() +{ + setSortFoldersFirst(!sortFoldersFirst()); +} + void DolphinView::toggleAdditionalInfo(QAction* action) { const KFileItemDelegate::Information info = @@ -987,6 +1006,16 @@ void DolphinView::updateSortOrder(Qt::SortOrder order) emit sortOrderChanged(order); } +void DolphinView::updateSortFoldersFirst(bool foldersFirst) +{ + ViewProperties props(viewPropertiesUrl()); + props.setSortFoldersFirst(foldersFirst); + + m_proxyModel->setSortFoldersFirst(foldersFirst); + + emit sortFoldersFirstChanged(foldersFirst); +} + void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& info) { ViewProperties props(viewPropertiesUrl()); @@ -1277,6 +1306,12 @@ void DolphinView::applyViewProperties(const KUrl& url) emit sortOrderChanged(sortOrder); } + const bool sortFoldersFirst = props.sortFoldersFirst(); + if (sortFoldersFirst != m_proxyModel->sortFoldersFirst()) { + m_proxyModel->setSortFoldersFirst(sortFoldersFirst); + emit sortFoldersFirstChanged(sortFoldersFirst); + } + KFileItemDelegate::InformationList info = props.additionalInfo(); if (info != m_fileItemDelegate->showInformation()) { m_fileItemDelegate->setShowInformation(info); diff --git a/src/dolphinview.h b/src/dolphinview.h index 385bcd50f..1df268ad7 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -267,6 +267,12 @@ public: /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */ Qt::SortOrder sortOrder() const; + /** Sets a separate sorting with folders first (true) or a mixed sorting of files and folders (false). */ + void setSortFoldersFirst(bool foldersFirst); + + /** Returns if files and folders are sorted separately or not. */ + bool sortFoldersFirst() const; + /** Sets the additional information which should be shown for the items. */ void setAdditionalInfo(KFileItemDelegate::InformationList info); @@ -422,6 +428,9 @@ public slots: /** Switches between an ascending and descending sorting order. */ void toggleSortOrder(); + /** Switches between a separate sorting (with folders first) and a mixed sorting of files and folders. */ + void toggleSortFoldersFirst(); + /** * Switches on or off the displaying of additional information * as specified by \a action. @@ -474,6 +483,9 @@ signals: /** Is emitted if the sort order (ascending or descending) has been changed. */ void sortOrderChanged(Qt::SortOrder order); + /** Is emitted if the sorting of files and folders (separate with folders first or mixed) has been changed. */ + void sortFoldersFirstChanged(bool foldersFirst); + /** Is emitted if the additional information shown for this view has been changed. */ void additionalInfoChanged(); @@ -586,6 +598,12 @@ private slots: */ void updateSortOrder(Qt::SortOrder order); + /** + * Updates the view properties of the current URL to the + * sorting of files and folders (separate with folders first or mixed) given by \a foldersFirst. + */ + void updateSortFoldersFirst(bool foldersFirst); + /** * Updates the view properties of the current URL to the * additional information given by \a info. diff --git a/src/dolphinviewactionhandler.cpp b/src/dolphinviewactionhandler.cpp index 88530febf..71e9fd398 100644 --- a/src/dolphinviewactionhandler.cpp +++ b/src/dolphinviewactionhandler.cpp @@ -57,6 +57,8 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view) this, SLOT(slotShowPreviewChanged())); connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(slotSortOrderChanged(Qt::SortOrder))); + connect(view, SIGNAL(sortFoldersFirstChanged(bool)), + this, SLOT(slotSortFoldersFirstChanged(bool))); connect(view, SIGNAL(additionalInfoChanged()), this, SLOT(slotAdditionalInfoChanged())); connect(view, SIGNAL(categorizedSortingChanged()), @@ -148,6 +150,10 @@ void DolphinViewActionHandler::createActions() sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); + KToggleAction* sortFoldersFirst = m_actionCollection->add("folders_first"); + sortFoldersFirst->setText(i18nc("@action:inmenu Sort", "Folders First")); + connect(sortFoldersFirst, SIGNAL(triggered()), this, SLOT(toggleSortFoldersFirst())); + QActionGroup* sortByActionGroup = createSortByActionGroup(); connect(sortByActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSortTriggered(QAction*))); @@ -356,6 +362,7 @@ void DolphinViewActionHandler::updateViewActions() showPreviewAction->setChecked(m_currentView->showPreview()); slotSortOrderChanged(m_currentView->sortOrder()); + slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst()); slotAdditionalInfoChanged(); slotCategorizedSortingChanged(); slotSortingChanged(m_currentView->sorting()); @@ -385,6 +392,11 @@ void DolphinViewActionHandler::toggleSortOrder() m_currentView->toggleSortOrder(); } +void DolphinViewActionHandler::toggleSortFoldersFirst() +{ + m_currentView->toggleSortFoldersFirst(); +} + void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order) { QAction* descending = m_actionCollection->action("descending"); @@ -392,6 +404,11 @@ void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order) descending->setChecked(sortDescending); } +void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst) +{ + m_actionCollection->action("folders_first")->setChecked(foldersFirst); +} + void DolphinViewActionHandler::toggleAdditionalInfo(QAction* action) { emit actionBeingHandled(); diff --git a/src/dolphinviewactionhandler.h b/src/dolphinviewactionhandler.h index 40062de04..91875ec0c 100644 --- a/src/dolphinviewactionhandler.h +++ b/src/dolphinviewactionhandler.h @@ -132,11 +132,19 @@ private Q_SLOTS: /** Switches between an ascending and descending sorting order. */ void toggleSortOrder(); + /** Switches between a separate sorting and a mixed sorting of files and folders. */ + void toggleSortFoldersFirst(); + /** * Updates the state of the 'Sort Ascending/Descending' action. */ void slotSortOrderChanged(Qt::SortOrder order); + /** + * Updates the state of the 'Sort Folders First' action. + */ + void slotSortFoldersFirstChanged(bool foldersFirst); + /** * Updates the state of the 'Sort by' actions. */ diff --git a/src/settings/dolphin_directoryviewpropertysettings.kcfg b/src/settings/dolphin_directoryviewpropertysettings.kcfg index ead1325de..415b872b3 100644 --- a/src/settings/dolphin_directoryviewpropertysettings.kcfg +++ b/src/settings/dolphin_directoryviewpropertysettings.kcfg @@ -50,6 +50,11 @@ Qt::DescendingOrder + + + true + + 0 diff --git a/src/settings/viewpropertiesdialog.cpp b/src/settings/viewpropertiesdialog.cpp index f407f7c90..7bd992ef1 100644 --- a/src/settings/viewpropertiesdialog.cpp +++ b/src/settings/viewpropertiesdialog.cpp @@ -62,6 +62,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : m_viewMode(0), m_sortOrder(0), m_sorting(0), + m_sortFoldersFirst(0), m_showPreview(0), m_showInGroups(0), m_showHiddenFiles(0), @@ -122,6 +123,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Tags")); // } #endif + m_sortFoldersFirst = new QCheckBox(i18nc("@option:check", "Show folders first")); m_showPreview = new QCheckBox(i18nc("@option:check", "Show preview")); m_showInGroups = new QCheckBox(i18nc("@option:check", "Show in groups")); m_showHiddenFiles = new QCheckBox(i18nc("@option:check", "Show hidden files")); @@ -142,6 +144,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox); propsBoxLayout->addWidget(propsGrid); + propsBoxLayout->addWidget(m_sortFoldersFirst); propsBoxLayout->addWidget(m_showPreview); propsBoxLayout->addWidget(m_showInGroups); propsBoxLayout->addWidget(m_showHiddenFiles); @@ -157,6 +160,8 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : this, SLOT(slotSortOrderChanged(int))); connect(m_additionalInfo, SIGNAL(clicked()), this, SLOT(configureAdditionalInfo())); + connect(m_sortFoldersFirst, SIGNAL(clicked()), + this, SLOT(slotSortFoldersFirstChanged())); connect(m_showPreview, SIGNAL(clicked()), this, SLOT(slotShowPreviewChanged())); connect(m_showInGroups, SIGNAL(clicked()), @@ -269,6 +274,13 @@ void ViewPropertiesDialog::slotCategorizedSortingChanged() markAsDirty(true); } +void ViewPropertiesDialog::slotSortFoldersFirstChanged() +{ + const bool foldersFirst = m_sortFoldersFirst->isChecked(); + m_viewProps->setSortFoldersFirst(foldersFirst); + markAsDirty(true); +} + void ViewPropertiesDialog::slotShowPreviewChanged() { const bool show = m_showPreview->isChecked(); @@ -370,6 +382,7 @@ void ViewPropertiesDialog::applyViewProperties() m_dolphinView->setMode(m_viewProps->viewMode()); m_dolphinView->setSorting(m_viewProps->sorting()); m_dolphinView->setSortOrder(m_viewProps->sortOrder()); + m_dolphinView->setSortFoldersFirst(m_viewProps->sortFoldersFirst()); m_dolphinView->setCategorizedSorting(m_viewProps->categorizedSorting()); m_dolphinView->setAdditionalInfo(m_viewProps->additionalInfo()); m_dolphinView->setShowPreview(m_viewProps->showPreview()); @@ -395,6 +408,7 @@ void ViewPropertiesDialog::loadSettings() (index == DolphinView::IconsView); m_additionalInfo->setEnabled(enabled); + m_sortFoldersFirst->setChecked(m_viewProps->sortFoldersFirst()); // load show preview, show in groups and show hidden files settings m_showPreview->setChecked(m_viewProps->showPreview()); diff --git a/src/settings/viewpropertiesdialog.h b/src/settings/viewpropertiesdialog.h index fbfae3020..ce0c3e5b8 100644 --- a/src/settings/viewpropertiesdialog.h +++ b/src/settings/viewpropertiesdialog.h @@ -54,6 +54,7 @@ private slots: void slotSortingChanged(int index); void slotSortOrderChanged(int index); void slotCategorizedSortingChanged(); + void slotSortFoldersFirstChanged(); void slotShowPreviewChanged(); void slotShowHiddenFilesChanged(); void markAsDirty(bool isDirty); @@ -71,6 +72,7 @@ private: KComboBox* m_viewMode; KComboBox* m_sortOrder; KComboBox* m_sorting; + QCheckBox* m_sortFoldersFirst; QCheckBox* m_showPreview; QCheckBox* m_showInGroups; QCheckBox* m_showHiddenFiles; diff --git a/src/viewproperties.cpp b/src/viewproperties.cpp index 510e4195b..3fc102d6c 100644 --- a/src/viewproperties.cpp +++ b/src/viewproperties.cpp @@ -198,6 +198,19 @@ Qt::SortOrder ViewProperties::sortOrder() const return static_cast(m_node->sortOrder()); } +void ViewProperties::setSortFoldersFirst(bool foldersFirst) +{ + if (m_node->sortFoldersFirst() != foldersFirst) { + m_node->setSortFoldersFirst(foldersFirst); + updateTimeStamp(); + } +} + +bool ViewProperties::sortFoldersFirst() const +{ + return m_node->sortFoldersFirst(); +} + void ViewProperties::setAdditionalInfo(KFileItemDelegate::InformationList list) { int info = NoInfo; diff --git a/src/viewproperties.h b/src/viewproperties.h index 3237686c7..a0279004e 100644 --- a/src/viewproperties.h +++ b/src/viewproperties.h @@ -71,6 +71,9 @@ public: void setSortOrder(Qt::SortOrder sortOrder); Qt::SortOrder sortOrder() const; + void setSortFoldersFirst(bool foldersFirst); + bool sortFoldersFirst() const; + /** * Sets the additional information for the current set view-mode. * Note that the additional-info property is the only property where