]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add SortOrderForUrl method to DBus interface
authorMarco Martin <notmart@gmail.com>
Fri, 4 Jun 2021 12:04:14 +0000 (12:04 +0000)
committerNate Graham <nate@kde.org>
Fri, 4 Jun 2021 12:04:14 +0000 (12:04 +0000)
adds a method to ask what's the sorting strategy (column and order) for a particular Url, as Dolphin can have directory-specific sorting strategies

This makes possible for other apps that have lists of files, like Gwenview to use the same sorting when invoked from dolphin, ie opening an image

CCBUG:236059

src/dbusinterface.cpp
src/dbusinterface.h
src/global.cpp
src/global.h

index cf1ad53ad0c56b0e8f9ecee25bbb46604f0f427e..7e453f72ac785ffddcba23582c6b2129cc10444a 100644 (file)
@@ -59,6 +59,18 @@ void DBusInterface::ShowItemProperties(const QStringList& uriList, const QString
     }
 }
 
+void DBusInterface::SortOrderForUrl(const QString &url, QString &role, QString &order)
+{
+    QUrl qurl(url);
+    auto sort = Dolphin::sortOrderForUrl(qurl);
+    role = sort.first;
+    if (sort.second == Qt::AscendingOrder) {
+        order = QStringLiteral("ascending");
+    } else {
+        order = QStringLiteral("descending");
+    }
+}
+
 void DBusInterface::setAsDaemon()
 {
     m_isDaemon = true;
index 9b183384d903f987ac2b8c22a2272edb348e9eae..66659e97620cc1d09aa1daaa7d73a6fd170c5834 100644 (file)
@@ -20,6 +20,8 @@ public:
     Q_SCRIPTABLE void ShowItems(const QStringList& uriList, const QString& startUpId);
     Q_SCRIPTABLE void ShowItemProperties(const QStringList& uriList, const QString& startUpId);
 
+    Q_SCRIPTABLE void SortOrderForUrl(const QString &url, QString &role, QString &order);
+
     /**
      * Set whether this interface has been created by dolphin --daemon.
      */
index 3d17a733bca243110621a75069adbd2c5c5ec146..197d6ec288f5e1b88ca0a9b3d129154293d4fbb3 100644 (file)
@@ -9,6 +9,7 @@
 #include "dolphin_generalsettings.h"
 #include "dolphindebug.h"
 #include "dolphinmainwindowinterface.h"
+#include "views/viewproperties.h"
 
 #include <KConfigWatcher>
 #include <KDialogJobUiDelegate>
@@ -140,6 +141,12 @@ QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> Do
     return dolphinInterfaces;
 }
 
+QPair<QString, Qt::SortOrder> Dolphin::sortOrderForUrl(QUrl &url)
+{
+    ViewProperties globalProps(url);
+    return QPair<QString, Qt::SortOrder>(globalProps.sortRole(), globalProps.sortOrder());
+}
+
 double GlobalConfig::animationDurationFactor()
 {
     if (s_animationDurationFactor >= 0.0) {
index 088e9c5b66b20f58e2dc686f801ea3e899493171..4f4eb890cd79e954f72d6da81f8fa94140e1cc62 100644 (file)
@@ -46,6 +46,8 @@ namespace Dolphin {
      */
     QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinGuiInstances(const QString& preferredService);
 
+    QPair<QString, Qt::SortOrder> sortOrderForUrl(QUrl &url);
+
     /**
      * TODO: Move this somewhere global to all KDE apps, not just Dolphin
      */