Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add to the file manager extension the option to edit a file. #1442

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Member

@jancborchardt jancborchardt Dec 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clear this up, we only want it to say "Edit", right? No product name, no "… collaboratively". Can you confirm @karlitschek?

cc @camilasan fyi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also, "Edit" should be the first in the list, before the Sharing entries – because you can also do that when the document is not shared.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jancborchardt Yes. I would only say 'Edit'. The app that is used depends on the mime type and is not really important for the user.

Copy link
Member

@jancborchardt jancborchardt Dec 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karlitschek thanks, agreed!

Suggested change
listener->sendMessage(QLatin1String("MENU_ITEM:EDIT") + flagString + tr("Edit via ") + capabilities.richDocumentsProductName());
listener->sendMessage(QLatin1String("MENU_ITEM:EDIT") + flagString + tr("Edit"));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While implementing this feature with OO, we found a small "problem": you can open also pdf files, which are not editable.
So we thought about "open (remotely)" instead of "edit" as this is more generic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobiasKaminsky can’t we just exclude PDF from it instead? Then the entry will simply say "Open in browser" as specified at #1442 (comment)

That’s much better than complicating the wording for the regular case.

}

}
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