Skip to content

Commit

Permalink
Add to the file manager extension the option to edit a file.
Browse files Browse the repository at this point in the history
The file can be edited in the browser via one of our apps Text,
Collabora or OnlyOffice.

Signed-off-by: Camila San <hello@camila.codes>
  • Loading branch information
Camila San committed Sep 25, 2019
1 parent 7a03339 commit fcd1a3f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/gui/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@

#include <QStandardPaths>

#include <QMimeDatabase>


// 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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"));
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/socketapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString> _registeredAliases;
Expand Down
18 changes: 18 additions & 0 deletions src/libsync/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ bool Capabilities::hasActivities() const {
return _capabilities.contains("activity");
}

bool Capabilities::hasRichDocuments() const {
return _capabilities.contains("richdocuments");
}

QList<QByteArray> Capabilities::supportedChecksumTypes() const
{
QList<QByteArray> list;
Expand Down Expand Up @@ -175,4 +179,18 @@ bool Capabilities::uploadConflictFiles() const

return _capabilities["uploadConflictFiles"].toBool();
}

QList<QByteArray> Capabilities::supportedRichDocumentsMimetypes() const
{
QList<QByteArray> 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();
}
}
15 changes: 15 additions & 0 deletions src/libsync/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -127,6 +130,18 @@ class OWNCLOUDSYNC_EXPORT Capabilities
*/
bool uploadConflictFiles() const;

/**
* Returns the richdocuments supported mimetypes
*
*/
QList<QByteArray> supportedRichDocumentsMimetypes() const;

/**
* Returns the richdocuments productName
*
*/
QString richDocumentsProductName() const;

private:
QVariantMap _capabilities;
};
Expand Down

0 comments on commit fcd1a3f

Please sign in to comment.