]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Support changing the sorting type and sort order (TODO: does not work yet as the...
authorPeter Penz <peter.penz19@gmail.com>
Thu, 14 Dec 2006 19:12:05 +0000 (19:12 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 14 Dec 2006 19:12:05 +0000 (19:12 +0000)
svn path=/trunk/playground/utils/dolphin/; revision=613696

src/dolphinview.cpp
src/dolphinview.h

index 7f0481eec4cc4d2f2f683d0dbe2d006be9d7bd73..2f287f353359b4c524c9c38c0effd94c372e9f6b 100644 (file)
@@ -392,61 +392,43 @@ bool DolphinView::isZoomOutPossible() const
 void DolphinView::setSorting(Sorting sorting)
 {
     if (sorting != this->sorting()) {
-        /*KFileView* view = fileView();
-        int spec = view->sorting() & ~QDir::Name & ~QDir::Size & ~QDir::Time & ~QDir::Unsorted;
-
-        switch (sorting) {
-            case SortByName: spec = spec | QDir::Name; break;
-            case SortBySize: spec = spec | QDir::Size; break;
-            case SortByDate: spec = spec | QDir::Time; break;
-            default: break;
-        }
-
         ViewProperties props(url());
         props.setSorting(sorting);
 
-        view->setSorting(static_cast<QDir::SortFlags>(spec));
+        KDirModel* dirModel = static_cast<KDirModel*>(m_iconsView->model());
+        dirModel->sort(columnIndex(sorting), props.sortOrder());
 
-        emit signalSortingChanged(sorting);*/
+        emit sortingChanged(sorting);
     }
 }
 
 DolphinView::Sorting DolphinView::sorting() const
 {
-    /*const QDir::SortFlags spec = fileView()->sorting();
-
-    if (spec & QDir::Time) {
-        return SortByDate;
-    }
-
-    if (spec & QDir::Size) {
-        return SortBySize;
-    }*/
-
-    return SortByName;
+    // TODO: instead of getting the sorting from the properties just fetch
+    // them from KDirModel, if such an interface will be offered (David?)
+    ViewProperties props(url());
+    return props.sorting();
 }
 
 void DolphinView::setSortOrder(Qt::SortOrder order)
 {
     if (sortOrder() != order) {
-        /*KFileView* view = fileView();
-        int sorting = view->sorting();
-        sorting = (order == Qt::Ascending) ? (sorting & ~QDir::Reversed) :
-                                             (sorting | QDir::Reversed);
-
         ViewProperties props(url());
         props.setSortOrder(order);
 
-        view->setSorting(static_cast<QDir::SortFlags>(sorting));
+        KDirModel* dirModel = static_cast<KDirModel*>(m_iconsView->model());
+        dirModel->sort(columnIndex(props.sorting()), order);
 
-        emit signalSortOrderChanged(order);*/
+        emit sortOrderChanged(order);
     }
 }
 
 Qt::SortOrder DolphinView::sortOrder() const
 {
-    //return fileView()->isReversed() ? Qt::Descending : Qt::Ascending;
-    return Qt::Descending;
+    // TODO: instead of getting the order from the properties just fetch
+    // them from KDirModel, if such an interface will be offered (David?)
+    ViewProperties props(url());
+    return props.sortOrder();
 }
 
 void DolphinView::goBack()
@@ -1054,4 +1036,16 @@ void DolphinView::applyModeToView()
     }
 }
 
+int DolphinView::columnIndex(Sorting sorting) const
+{
+    int index = 0;
+    switch (sorting) {
+        case SortByName: index = KDirModel::Name; break;
+        case SortBySize: index = KDirModel::Size; break;
+        case SortByDate: index = KDirModel::ModifiedTime; break;
+        default: assert(false);
+    }
+    return index;
+}
+
 #include "dolphinview.moc"
index 2f1d7c60557e342dac92a2252cd7cbf14005e09f..e5af61f3f96874db569f5c36df7173b0bfdecf9a 100644 (file)
@@ -442,6 +442,12 @@ private:
      */
     void applyModeToView();
 
+    /**
+     * Returns the column index used in the KDirModel depending on \a sorting.
+     */
+    int columnIndex(Sorting sorting) const;
+
+private:
     bool m_refreshing;
     bool m_showProgress;
     Mode m_mode;