In the case of conflicts, have the socket api propose the config dialog
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 7 Oct 2020 15:51:57 +0000 (17:51 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 22 Oct 2020 14:40:46 +0000 (16:40 +0200)
This should be safe in the case of conflicts in folders on which the
user can write. For other cases we still use the older actions.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/socketapi.cpp
src/gui/socketapi.h

index 3fa216919d08ae66e5d2d7ac261976c15615fa82..717d62f5375b34ce237acd47a420d2f1e9c9e7e3 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "socketapi.h"
 
+#include "conflictdialog.h"
 #include "conflictsolver.h"
 #include "config.h"
 #include "configfile.h"
@@ -690,6 +691,30 @@ void SocketApi::copyUrlToClipboard(const QString &link)
     QApplication::clipboard()->setText(link);
 }
 
+void SocketApi::command_RESOLVE_CONFLICT(const QString &localFile, SocketListener *)
+{
+    const auto fileData = FileData::get(localFile);
+    if (!fileData.folder || !Utility::isConflictFile(fileData.folderRelativePath))
+        return; // should not have shown menu item
+
+    const auto conflictedRelativePath = fileData.folderRelativePath;
+    const auto baseRelativePath = fileData.folder->journalDb()->conflictFileBaseName(fileData.folderRelativePath.toUtf8());
+
+    const auto dir = QDir(fileData.folder->path());
+    const auto conflictedPath = dir.filePath(conflictedRelativePath);
+    const auto basePath = dir.filePath(baseRelativePath);
+
+    const auto baseName = QFileInfo(basePath).fileName();
+
+#ifndef OWNCLOUD_TEST
+    ConflictDialog dialog;
+    dialog.setBaseFilename(baseName);
+    dialog.setLocalVersionFilename(conflictedPath);
+    dialog.setRemoteVersionFilename(basePath);
+    dialog.exec();
+#endif
+}
+
 void SocketApi::command_DELETE_ITEM(const QString &localFile, SocketListener *)
 {
     ConflictSolver solver;
@@ -886,13 +911,7 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
 
             if (isConflict && canChangeFile) {
                 if (canAddToDir) {
-                    if (isOnTheServer) {
-                        // Conflict file that is already uploaded
-                        listener->sendMessage(QLatin1String("MENU_ITEM:MOVE_ITEM::") + tr("Rename..."));
-                    } else {
-                        // Local-only conflict file
-                        listener->sendMessage(QLatin1String("MENU_ITEM:MOVE_ITEM::") + tr("Rename and upload..."));
-                    }
+                    listener->sendMessage(QLatin1String("MENU_ITEM:RESOLVE_CONFLICT::") + tr("Resolve conflict..."));
                 } else {
                     if (isOnTheServer) {
                         // Uploaded conflict file in read-only directory
@@ -901,8 +920,8 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
                         // Local-only conflict file in a read-only dir
                         listener->sendMessage(QLatin1String("MENU_ITEM:MOVE_ITEM::") + tr("Move, rename and upload..."));
                     }
+                    listener->sendMessage(QLatin1String("MENU_ITEM:DELETE_ITEM::") + tr("Delete local changes"));
                 }
-                listener->sendMessage(QLatin1String("MENU_ITEM:DELETE_ITEM::") + tr("Delete local changes"));
             }
 
             // File in a read-only directory?
index e1d11f91906df9945a926103ede4ceb0c9e0098c..25de075eeb7de361eecac07b8dfab104e8dfa04f 100644 (file)
@@ -106,6 +106,7 @@ private:
     Q_INVOKABLE void command_COPY_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
     Q_INVOKABLE void command_EMAIL_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
     Q_INVOKABLE void command_OPEN_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
+    Q_INVOKABLE void command_RESOLVE_CONFLICT(const QString &localFile, SocketListener *listener);
     Q_INVOKABLE void command_DELETE_ITEM(const QString &localFile, SocketListener *listener);
     Q_INVOKABLE void command_MOVE_ITEM(const QString &localFile, SocketListener *listener);