]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Provide the "sort by" actions in dolphinpart (konqueror); share and simplify the...
authorDavid Faure <faure@kde.org>
Wed, 13 Feb 2008 20:52:21 +0000 (20:52 +0000)
committerDavid Faure <faure@kde.org>
Wed, 13 Feb 2008 20:52:21 +0000 (20:52 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=774699

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinpart.cpp
src/dolphinviewactionhandler.cpp
src/dolphinviewactionhandler.h

index 55647347104734a7b854521632738699230cfd51..668f92b7c6cea56b403fe3e7376cf09e9b4f84bc 100644 (file)
@@ -177,48 +177,6 @@ void DolphinMainWindow::changeSelection(const KFileItemList& selection)
     activeViewContainer()->view()->changeSelection(selection);
 }
 
-void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
-{
-    QAction* action = 0;
-    switch (sorting) {
-    case DolphinView::SortByName:
-        action = actionCollection()->action("sort_by_name");
-        break;
-    case DolphinView::SortBySize:
-        action = actionCollection()->action("sort_by_size");
-        break;
-    case DolphinView::SortByDate:
-        action = actionCollection()->action("sort_by_date");
-        break;
-    case DolphinView::SortByPermissions:
-        action = actionCollection()->action("sort_by_permissions");
-        break;
-    case DolphinView::SortByOwner:
-        action = actionCollection()->action("sort_by_owner");
-        break;
-    case DolphinView::SortByGroup:
-        action = actionCollection()->action("sort_by_group");
-        break;
-    case DolphinView::SortByType:
-        action = actionCollection()->action("sort_by_type");
-        break;
-#ifdef HAVE_NEPOMUK
-    case DolphinView::SortByRating:
-        action = actionCollection()->action("sort_by_rating");
-        break;
-    case DolphinView::SortByTags:
-        action = actionCollection()->action("sort_by_tags");
-        break;
-#endif
-    default:
-        break;
-    }
-
-    if (action != 0) {
-        action->setChecked(true);
-    }
-}
-
 void DolphinMainWindow::slotEditableStateChanged(bool editable)
 {
     KToggleAction* editableLocationAction =
@@ -477,55 +435,6 @@ void DolphinMainWindow::invertSelection()
     m_activeViewContainer->view()->invertSelection();
 }
 
-void DolphinMainWindow::sortByName()
-{
-    m_activeViewContainer->view()->setSorting(DolphinView::SortByName);
-}
-
-void DolphinMainWindow::sortBySize()
-{
-    m_activeViewContainer->view()->setSorting(DolphinView::SortBySize);
-}
-
-void DolphinMainWindow::sortByDate()
-{
-    m_activeViewContainer->view()->setSorting(DolphinView::SortByDate);
-}
-
-void DolphinMainWindow::sortByPermissions()
-{
-    m_activeViewContainer->view()->setSorting(DolphinView::SortByPermissions);
-}
-
-void DolphinMainWindow::sortByOwner()
-{
-    m_activeViewContainer->view()->setSorting(DolphinView::SortByOwner);
-}
-
-void DolphinMainWindow::sortByGroup()
-{
-    m_activeViewContainer->view()->setSorting(DolphinView::SortByGroup);
-}
-
-void DolphinMainWindow::sortByType()
-{
-    m_activeViewContainer->view()->setSorting(DolphinView::SortByType);
-}
-
-void DolphinMainWindow::sortByRating()
-{
-#ifdef HAVE_NEPOMUK
-    m_activeViewContainer->view()->setSorting(DolphinView::SortByRating);
-#endif
-}
-
-void DolphinMainWindow::sortByTags()
-{
-#ifdef HAVE_NEPOMUK
-    m_activeViewContainer->view()->setSorting(DolphinView::SortByTags);
-#endif
-}
-
 void DolphinMainWindow::toggleSplitView()
 {
     if (m_viewContainer[SecondaryView] == 0) {
@@ -831,75 +740,7 @@ void DolphinMainWindow::setupActions()
     connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
 
     // setup 'View' menu
-
-    //TODO
-    //QActionGroup* sortActionGroup = DolphinView::createSortActionGroup(actionCollection());
-    //connect(sortActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(sortActionGroupTriggered(QAction*)));
-
-    KToggleAction* sortByName = actionCollection()->add<KToggleAction>("sort_by_name");
-    sortByName->setText(i18nc("@action:inmenu Sort By", "Name"));
-    connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName()));
-
-    KToggleAction* sortBySize = actionCollection()->add<KToggleAction>("sort_by_size");
-    sortBySize->setText(i18nc("@action:inmenu Sort By", "Size"));
-    connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize()));
-
-    KToggleAction* sortByDate = actionCollection()->add<KToggleAction>("sort_by_date");
-    sortByDate->setText(i18nc("@action:inmenu Sort By", "Date"));
-    connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate()));
-
-    KToggleAction* sortByPermissions = actionCollection()->add<KToggleAction>("sort_by_permissions");
-    sortByPermissions->setText(i18nc("@action:inmenu Sort By", "Permissions"));
-    connect(sortByPermissions, SIGNAL(triggered()), this, SLOT(sortByPermissions()));
-
-    KToggleAction* sortByOwner = actionCollection()->add<KToggleAction>("sort_by_owner");
-    sortByOwner->setText(i18nc("@action:inmenu Sort By", "Owner"));
-    connect(sortByOwner, SIGNAL(triggered()), this, SLOT(sortByOwner()));
-
-    KToggleAction* sortByGroup = actionCollection()->add<KToggleAction>("sort_by_group");
-    sortByGroup->setText(i18nc("@action:inmenu Sort By", "Group"));
-    connect(sortByGroup, SIGNAL(triggered()), this, SLOT(sortByGroup()));
-
-    KToggleAction* sortByType = actionCollection()->add<KToggleAction>("sort_by_type");
-    sortByType->setText(i18nc("@action:inmenu Sort By", "Type"));
-    connect(sortByType, SIGNAL(triggered()), this, SLOT(sortByType()));
-
-    // TODO: Hided "sort by rating" and "sort by tags" as without caching the performance
-    // is too slow currently (Nepomuk will support caching in future releases).
-    //
-    // KToggleAction* sortByRating = actionCollection()->add<KToggleAction>("sort_by_rating");
-    // sortByRating->setText(i18nc("@action:inmenu Sort By", "Rating"));
-    //
-    // KToggleAction* sortByTags = actionCollection()->add<KToggleAction>("sort_by_tags");
-    // sortByTags->setText(i18nc("@action:inmenu Sort By", "Tags"));
-    //
-#ifdef HAVE_NEPOMUK
-    // if (MetaDataWidget::metaDataAvailable()) {
-    //     connect(sortByRating, SIGNAL(triggered()), this, SLOT(sortByRating()));
-    //     connect(sortByTags, SIGNAL(triggered()), this, SLOT(sortByTags()));
-    // }
-    // else {
-    //     sortByRating->setEnabled(false);
-    //     sortByTags->setEnabled(false);
-    // }
-#else
-    // sortByRating->setEnabled(false);
-    // sortByTags->setEnabled(false);
-#endif
-
-    QActionGroup* sortGroup = new QActionGroup(this);
-    sortGroup->addAction(sortByName);
-    sortGroup->addAction(sortBySize);
-    sortGroup->addAction(sortByDate);
-    sortGroup->addAction(sortByPermissions);
-    sortGroup->addAction(sortByOwner);
-    sortGroup->addAction(sortByGroup);
-    sortGroup->addAction(sortByType);
-
-    // TODO: Hided "sort by rating" and "sort by tags" as without caching the performance
-    // is too slow currently (Nepomuk will support caching in future releases).
-    //sortGroup->addAction(sortByRating);
-    //sortGroup->addAction(sortByTags);
+    // (note that most of it is set up in DolphinViewActionHandler)
 
     KAction* split = actionCollection()->addAction("split_view");
     split->setShortcut(Qt::Key_F3);
@@ -1103,9 +944,6 @@ void DolphinMainWindow::updateViewActions()
 {
     m_actionHandler->updateViewActions();
 
-    const DolphinView* view = m_activeViewContainer->view();
-    slotSortingChanged(view->sorting());
-
     QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
     showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
 
@@ -1135,8 +973,6 @@ void DolphinMainWindow::connectViewSignals(int viewIndex)
             this, SLOT(updateFilterBarAction(bool)));
 
     DolphinView* view = container->view();
-    connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
-            this, SLOT(slotSortingChanged(DolphinView::Sorting)));
     connect(view, SIGNAL(selectionChanged(KFileItemList)),
             this, SLOT(slotSelectionChanged(KFileItemList)));
     connect(view, SIGNAL(requestItemInfo(KFileItem)),
index 4f4e765a8b67adc4de60f26a8dab4b423d564f74..a7204703997619f3870a1d7f3f09942a9a3ac036 100644 (file)
@@ -223,33 +223,6 @@ private slots:
      */
     void invertSelection();
 
-    /** The sorting of the current view should be done by the name. */
-    void sortByName();
-
-    /** The sorting of the current view should be done by the size. */
-    void sortBySize();
-
-    /** The sorting of the current view should be done by the date. */
-    void sortByDate();
-
-    /** The sorting of the current view should be done by the permissions. */
-    void sortByPermissions();
-
-    /** The sorting of the current view should be done by the owner. */
-    void sortByOwner();
-
-    /** The sorting of the current view should be done by the group. */
-    void sortByGroup();
-
-    /** The sorting of the current view should be done by the type. */
-    void sortByType();
-
-    /** The sorting of the current view should be done by the rating. */
-    void sortByRating();
-
-    /** The sorting of the current view should be done by tags. */
-    void sortByTags();
-
     /**
      * Switches between one and two views:
      * If one view is visible, it will get split into two views.
@@ -312,9 +285,6 @@ private slots:
     /** Opens the settings dialog for Dolphin. */
     void editSettings();
 
-    /** Updates the state of the 'Sort by' actions. */
-    void slotSortingChanged(DolphinView::Sorting sorting);
-
     /** Updates the state of the 'Show Full Location' action. */
     void slotEditableStateChanged(bool editable);
 
index 1cd336c8cc30cb02605921171c26890183b04eaf..16caae9d69e85339bfc06ef3bdfe3f625320e73a 100644 (file)
@@ -94,7 +94,6 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi
             this, SLOT(slotUrlChanged(KUrl)));
     connect(m_view, SIGNAL(modeChanged()),
             this, SIGNAL(viewModeChanged())); // relay signal
-    // TODO slotSortingChanged
 
     m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
     m_actionHandler->setCurrentView(m_view);
index ef3c042929c9e9696de10cb48f3d56f2a181a564..87facace1a80822f43ca44bd32a4f508ac988d49 100644 (file)
@@ -59,6 +59,8 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
             this, SLOT(slotCategorizedSortingChanged()));
     connect(view, SIGNAL(showHiddenFilesChanged()),
             this, SLOT(slotShowHiddenFilesChanged()));
+    connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
+            this, SLOT(slotSortingChanged(DolphinView::Sorting)));
 }
 
 void DolphinViewActionHandler::createActions()
@@ -115,6 +117,9 @@ void DolphinViewActionHandler::createActions()
     sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
     connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
 
+    QActionGroup* sortByActionGroup = createSortByActionGroup();
+    connect(sortByActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSortTriggered(QAction*)));
+
     QActionGroup* showInformationActionGroup = createAdditionalInformationActionGroup();
     connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*)));
 
@@ -167,6 +172,76 @@ QActionGroup* DolphinViewActionHandler::createAdditionalInformationActionGroup()
     return showInformationGroup;
 }
 
+Q_DECLARE_METATYPE(DolphinView::Sorting)
+
+QActionGroup* DolphinViewActionHandler::createSortByActionGroup()
+{
+    QActionGroup* sortByActionGroup = new QActionGroup(m_actionCollection);
+    sortByActionGroup->setExclusive(true);
+
+    KToggleAction* sortByName = m_actionCollection->add<KToggleAction>("sort_by_name");
+    sortByName->setText(i18nc("@action:inmenu Sort By", "Name"));
+    sortByName->setData(QVariant::fromValue(DolphinView::SortByName));
+    sortByActionGroup->addAction(sortByName);
+
+    KToggleAction* sortBySize = m_actionCollection->add<KToggleAction>("sort_by_size");
+    sortBySize->setText(i18nc("@action:inmenu Sort By", "Size"));
+    sortBySize->setData(QVariant::fromValue(DolphinView::SortBySize));
+    sortByActionGroup->addAction(sortBySize);
+
+    KToggleAction* sortByDate = m_actionCollection->add<KToggleAction>("sort_by_date");
+    sortByDate->setText(i18nc("@action:inmenu Sort By", "Date"));
+    sortByDate->setData(QVariant::fromValue(DolphinView::SortByDate));
+    sortByActionGroup->addAction(sortByDate);
+
+    KToggleAction* sortByPermissions = m_actionCollection->add<KToggleAction>("sort_by_permissions");
+    sortByPermissions->setText(i18nc("@action:inmenu Sort By", "Permissions"));
+    sortByPermissions->setData(QVariant::fromValue(DolphinView::SortByPermissions));
+    sortByActionGroup->addAction(sortByPermissions);
+
+    KToggleAction* sortByOwner = m_actionCollection->add<KToggleAction>("sort_by_owner");
+    sortByOwner->setText(i18nc("@action:inmenu Sort By", "Owner"));
+    sortByOwner->setData(QVariant::fromValue(DolphinView::SortByOwner));
+    sortByActionGroup->addAction(sortByOwner);
+
+    KToggleAction* sortByGroup = m_actionCollection->add<KToggleAction>("sort_by_group");
+    sortByGroup->setText(i18nc("@action:inmenu Sort By", "Group"));
+    sortByGroup->setData(QVariant::fromValue(DolphinView::SortByGroup));
+    sortByActionGroup->addAction(sortByGroup);
+
+    KToggleAction* sortByType = m_actionCollection->add<KToggleAction>("sort_by_type");
+    sortByType->setText(i18nc("@action:inmenu Sort By", "Type"));
+    sortByType->setData(QVariant::fromValue(DolphinView::SortByType));
+    sortByActionGroup->addAction(sortByType);
+
+    // TODO: Hid "sort by rating" and "sort by tags" as without caching the performance
+    // is too slow currently (Nepomuk will support caching in future releases).
+    //
+    // KToggleAction* sortByRating = m_actionCollection->add<KToggleAction>("sort_by_rating");
+    // sortByRating->setData(QVariant::fromValue(DolphinView::SortByRating));
+    // sortByRating->setText(i18nc("@action:inmenu Sort By", "Rating"));
+    // sortByActionGroup->addAction(sortByRating);
+    //
+    // KToggleAction* sortByTags = m_actionCollection->add<KToggleAction>("sort_by_tags");
+    // sortByTags->setData(QVariant::fromValue(DolphinView::SortByTags));
+    // sortByTags->setText(i18nc("@action:inmenu Sort By", "Tags"));
+    // sortByActionGroup->addAction(sortByTags);
+    //
+#ifdef HAVE_NEPOMUK
+    // if (!MetaDataWidget::metaDataAvailable()) {
+    //     sortByRating->setEnabled(false);
+    //     sortByTags->setEnabled(false);
+    // }
+#else
+    // sortByRating->setEnabled(false);
+    // sortByTags->setEnabled(false);
+#endif
+
+
+
+    return sortByActionGroup;
+}
+
 void DolphinViewActionHandler::slotCreateDir()
 {
     Q_ASSERT(m_currentView);
@@ -252,6 +327,7 @@ void DolphinViewActionHandler::updateViewActions()
     slotSortOrderChanged(m_currentView->sortOrder());
     slotAdditionalInfoChanged();
     slotCategorizedSortingChanged();
+    slotSortingChanged(m_currentView->sorting());
 
     QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
     showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles());
@@ -347,3 +423,51 @@ KToggleAction* DolphinViewActionHandler::columnsModeAction()
     columnView->setData(QVariant::fromValue(DolphinView::ColumnView));
     return columnView;
 }
+
+void DolphinViewActionHandler::slotSortingChanged(DolphinView::Sorting sorting)
+{
+    QAction* action = 0;
+    switch (sorting) {
+    case DolphinView::SortByName:
+        action = m_actionCollection->action("sort_by_name");
+        break;
+    case DolphinView::SortBySize:
+        action = m_actionCollection->action("sort_by_size");
+        break;
+    case DolphinView::SortByDate:
+        action = m_actionCollection->action("sort_by_date");
+        break;
+    case DolphinView::SortByPermissions:
+        action = m_actionCollection->action("sort_by_permissions");
+        break;
+    case DolphinView::SortByOwner:
+        action = m_actionCollection->action("sort_by_owner");
+        break;
+    case DolphinView::SortByGroup:
+        action = m_actionCollection->action("sort_by_group");
+        break;
+    case DolphinView::SortByType:
+        action = m_actionCollection->action("sort_by_type");
+        break;
+#ifdef HAVE_NEPOMUK
+    case DolphinView::SortByRating:
+        action = m_actionCollection->action("sort_by_rating");
+        break;
+    case DolphinView::SortByTags:
+        action = m_actionCollection->action("sort_by_tags");
+        break;
+#endif
+    default:
+        break;
+    }
+
+    if (action != 0) {
+        action->setChecked(true);
+    }
+}
+
+void DolphinViewActionHandler::slotSortTriggered(QAction* action)
+{
+    const DolphinView::Sorting sorting = action->data().value<DolphinView::Sorting>();
+    m_currentView->setSorting(sorting);
+}
index d4790a38da76d9e15aef247dedcc30eaffe2de28..4eb856387b28d2d4312ca359c78072bc5b8affb8 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef DOLPHINVIEWACTIONHANDLER_H
 #define DOLPHINVIEWACTIONHANDLER_H
 
+#include "dolphinview.h"
 #include "libdolphin_export.h"
 #include <QtCore/QObject>
 class KToggleAction;
@@ -125,12 +126,22 @@ private Q_SLOTS:
      */
     void slotSortOrderChanged(Qt::SortOrder order);
 
+    /**
+     * Updates the state of the 'Sort by' actions.
+     */
+    void slotSortingChanged(DolphinView::Sorting sorting);
+
     /**
      * Switches on or off the displaying of additional information
      * as specified by \a action.
      */
     void toggleAdditionalInfo(QAction* action);
 
+    /**
+     * Changes the sorting of the current view.
+     */
+    void slotSortTriggered(QAction*);
+
     /**
      * Updates the state of the 'Additional Information' actions.
      */
@@ -168,6 +179,12 @@ private:
      */
     QActionGroup* createAdditionalInformationActionGroup();
 
+    /**
+     * Creates an action group with all the "sort by" actions in it.
+     * Helper method for createActions();
+     */
+    QActionGroup* createSortByActionGroup();
+
     /**
      * Returns the "switch to icons mode" action.
      * Helper method for createActions();