]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make sort/descending available in dolphinpart
authorDavid Faure <faure@kde.org>
Mon, 21 Jan 2008 19:42:16 +0000 (19:42 +0000)
committerDavid Faure <faure@kde.org>
Mon, 21 Jan 2008 19:42:16 +0000 (19:42 +0000)
svn path=/branches/KDE/4.0/kdebase/apps/; revision=764444

src/dolphinmainwindow.cpp
src/dolphinpart.cpp
src/dolphinpart.h
src/dolphinview.cpp
src/dolphinview.h

index 1da9377c7d6c29ace603fe37c7a6787e1312a1c2..407ec16b4b498b89a70f721718b60cc3c6f3b728 100644 (file)
@@ -650,11 +650,7 @@ void DolphinMainWindow::sortByTags()
 
 void DolphinMainWindow::toggleSortOrder()
 {
-    DolphinView* view = m_activeViewContainer->view();
-    const Qt::SortOrder order = (view->sortOrder() == Qt::AscendingOrder) ?
-                                Qt::DescendingOrder :
-                                Qt::AscendingOrder;
-    view->setSortOrder(order);
+    m_activeViewContainer->view()->toggleSortOrder();
 }
 
 void DolphinMainWindow::toggleSortCategorization()
@@ -1126,8 +1122,7 @@ void DolphinMainWindow::setupActions()
     //sortGroup->addAction(sortByRating);
     //sortGroup->addAction(sortByTags);
 
-    KToggleAction* sortDescending = actionCollection()->add<KToggleAction>("descending");
-    sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
+    KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection());
     connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
 
     KToggleAction* showInGroups = actionCollection()->add<KToggleAction>("show_in_groups");
index 2c4c1eaa36473233c8ad3bfda6e60de2b942791d..e7c919ad8457bd128ca1a9099635a7b75a0e402a 100644 (file)
@@ -93,6 +93,8 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi
             this, SLOT(slotUrlChanged(KUrl)));
     connect(m_view, SIGNAL(modeChanged()),
             this, SLOT(updateViewActions()));
+    connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
+            this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
 
     QClipboard* clipboard = QApplication::clipboard();
     connect(clipboard, SIGNAL(dataChanged()),
@@ -144,6 +146,13 @@ void DolphinPart::createActions()
     propertiesAction->setShortcut(Qt::ALT+Qt::Key_Return);
     connect(propertiesAction, SIGNAL(triggered()), SLOT(slotProperties()));
 
+    // View menu
+
+    // TODO sort_by_*
+
+    KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection());
+    connect(sortDescending, SIGNAL(triggered()), m_view, SLOT(toggleSortOrder()));
+
     // Go menu
 
     KAction* newDirAction = DolphinView::createNewDirAction(actionCollection());
@@ -431,4 +440,11 @@ void DolphinPart::createDir()
     KonqOperations::newDir(m_view, url());
 }
 
+void DolphinPart::slotSortOrderChanged(Qt::SortOrder order)
+{
+    KToggleAction* descending = static_cast<KToggleAction*>(actionCollection()->action("descending"));
+    const bool sortDescending = (order == Qt::DescendingOrder);
+    descending->setChecked(sortDescending);
+}
+
 #include "dolphinpart.moc"
index 04161b6be6053bb34dd156d2887604eb57bc1f41..883cf945631f3d57225d2bc8b2e6cf24e3cca771 100644 (file)
@@ -136,6 +136,9 @@ private Q_SLOTS:
      */
     void createDir();
 
+    /** Updates the state of the 'Sort Ascending/Descending' action. */
+    void slotSortOrderChanged(Qt::SortOrder);
+
 private:
     void createActions();
     void createGoAction(const char* name, const char* iconName,
index 138971360c1a357bea566ee85ecc09ac7f579cdb..cccbd36b9fbd7ba9bc5b88ba0f6f41f2b7ff1d7d 100644 (file)
@@ -794,6 +794,14 @@ void DolphinView::updateSortOrder(Qt::SortOrder order)
     emit sortOrderChanged(order);
 }
 
+void DolphinView::toggleSortOrder()
+{
+    const Qt::SortOrder order = (sortOrder() == Qt::AscendingOrder) ?
+                                Qt::DescendingOrder :
+                                Qt::AscendingOrder;
+    setSortOrder(order);
+}
+
 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& info)
 {
     ViewProperties props(viewPropertiesUrl());
@@ -1257,4 +1265,11 @@ KAction* DolphinView::createNewDirAction(KActionCollection* collection)
     return newDirAction;
 }
 
+KAction* DolphinView::createSortDescendingAction(KActionCollection* collection)
+{
+    KToggleAction* sortDescending = collection->add<KToggleAction>("descending");
+    sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
+    return sortDescending;
+}
+
 #include "dolphinview.moc"
index 8076a62f0bb3a88d2b4fc9846a8b365ed4f0bfc5..80430ca77940f1fa64c24ef838e4de2cf9e06d51 100644 (file)
@@ -368,6 +368,12 @@ public:
      */
     static KAction* createNewDirAction(KActionCollection* collection);
 
+    /**
+     * Creates the "sort descending" action.
+     * This code is here to share it between the mainwindow and the part
+     */
+    static KAction* createSortDescendingAction(KActionCollection* collection);
+
     /**
      * Returns the action name corresponding to the current view mode
      */
@@ -423,6 +429,9 @@ public slots:
     /** Pastes the clipboard data to this view. */
     void paste();
 
+    /** Switches between an ascending and descending sorting order. */
+    void toggleSortOrder();
+
 signals:
     /**
      * Is emitted if the view has been activated by e. g. a mouse click.