diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index 5601503b18403..f27612ca9aa39 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -54,6 +54,8 @@ #include +#include + // This is the version that is returned when the client asks for the VERSION. // The first number should be changed if there is an incompatible change that breaks old clients. @@ -457,6 +459,11 @@ void SocketApi::command_SHARE_MENU_TITLE(const QString &, SocketListener *listen listener->sendMessage(QLatin1String("SHARE_MENU_TITLE:") + tr("Share with %1", "parameter is Nextcloud").arg(Theme::instance()->appNameGUI())); } +void SocketApi::command_EDIT(const QString &localFile, SocketListener *listener) +{ + fetchPrivateLinkUrlHelper(localFile, &SocketApi::openPrivateLink); +} + // don't pull the share manager into socketapi unittests #ifndef OWNCLOUD_TEST @@ -717,9 +724,18 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe FileData fileData = hasSeveralFiles ? FileData{} : FileData::get(argument); bool isOnTheServer = fileData.journalRecord().isValid(); auto flagString = isOnTheServer ? QLatin1String("::") : QLatin1String(":d:"); + auto capabilities = fileData.folder->accountState()->account()->capabilities(); + if (fileData.folder && fileData.folder->accountState()->isConnected()) { sendSharingContextMenuOptions(fileData, listener); listener->sendMessage(QLatin1String("MENU_ITEM:OPEN_PRIVATE_LINK") + flagString + tr("Open in browser")); + + QMimeDatabase db; + QMimeType type = db.mimeTypeForFile(fileData.localPath); + if (capabilities.hasRichDocuments() && capabilities.supportedRichDocumentsMimetypes().contains(type.name().toLatin1())){ + listener->sendMessage(QLatin1String("MENU_ITEM:EDIT") + flagString + tr("Edit via ") + capabilities.richDocumentsProductName()); + } + } listener->sendMessage(QString("GET_MENU_ITEMS:END")); } diff --git a/src/gui/socketapi.h b/src/gui/socketapi.h index e94ed5116b5da..0314b92df3f88 100644 --- a/src/gui/socketapi.h +++ b/src/gui/socketapi.h @@ -123,6 +123,8 @@ private slots: */ Q_INVOKABLE void command_GET_MENU_ITEMS(const QString &argument, SocketListener *listener); + Q_INVOKABLE void command_EDIT(const QString &localFile, SocketListener *listener); + QString buildRegisterPathMessage(const QString &path); QSet _registeredAliases; diff --git a/src/libsync/capabilities.cpp b/src/libsync/capabilities.cpp index 39df7d1677f87..e92e521c5169a 100644 --- a/src/libsync/capabilities.cpp +++ b/src/libsync/capabilities.cpp @@ -107,6 +107,10 @@ bool Capabilities::hasActivities() const { return _capabilities.contains("activity"); } +bool Capabilities::hasRichDocuments() const { + return _capabilities.contains("richdocuments"); +} + QList Capabilities::supportedChecksumTypes() const { QList list; @@ -175,4 +179,18 @@ bool Capabilities::uploadConflictFiles() const return _capabilities["uploadConflictFiles"].toBool(); } + +QList Capabilities::supportedRichDocumentsMimetypes() const +{ + QList list; + foreach (const auto &t, _capabilities["richdocuments"].toMap()["mimetypes"].toList()) { + list.push_back(t.toByteArray()); + } + return list; +} + +QString Capabilities::richDocumentsProductName() const +{ + return _capabilities["richdocuments"].toMap()["productName"].toString(); +} } diff --git a/src/libsync/capabilities.h b/src/libsync/capabilities.h index 8f8fd826a8ec7..712c2343fb128 100644 --- a/src/libsync/capabilities.h +++ b/src/libsync/capabilities.h @@ -62,6 +62,9 @@ class OWNCLOUDSYNC_EXPORT Capabilities /// return true if the activity app is enabled bool hasActivities() const; + /// return true if Collabora/OnlyOffice is enabled + bool hasRichDocuments() const; + /** * Returns the checksum types the server understands. * @@ -127,6 +130,18 @@ class OWNCLOUDSYNC_EXPORT Capabilities */ bool uploadConflictFiles() const; + /** + * Returns the richdocuments supported mimetypes + * + */ + QList supportedRichDocumentsMimetypes() const; + + /** + * Returns the richdocuments productName + * + */ + QString richDocumentsProductName() const; + private: QVariantMap _capabilities; };