Skip to content

Commit

Permalink
Dolphin integration: Copy local link action owncloud#5023
Browse files Browse the repository at this point in the history
  • Loading branch information
ckamm committed Jun 23, 2017
1 parent c478ca7 commit 5909405
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
22 changes: 18 additions & 4 deletions shell_integration/dolphin/ownclouddolphinactionplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <KIOCore/kfileitem.h>
#include <KIOCore/KFileItemListProperties>
#include <QtWidgets/QAction>
#include <QtWidgets/QMenu>
#include <QtCore/QDir>
#include <QtCore/QTimer>
#include "ownclouddolphinpluginhelper.h"
Expand Down Expand Up @@ -53,12 +54,25 @@ class OwncloudDolphinPluginAction : public KAbstractFileItemActionPlugin
} ))
return {};

auto act = new QAction(parentWidget);
act->setText(helper->shareActionString());
connect(act, &QAction::triggered, this, [localFile, helper] {
auto menuaction = new QAction(parentWidget);
menuaction->setText(helper->contextMenuTitle());
auto menu = new QMenu(parentWidget);
menuaction->setMenu(menu);

auto shareAction = new QAction(menu);
shareAction->setText(helper->shareActionTitle());
connect(shareAction, &QAction::triggered, this, [localFile, helper] {
helper->sendCommand(QByteArray("SHARE:"+localFile.toUtf8()+"\n"));
} );
return { act };
menu->addAction(shareAction);

auto localLinkAction = new QAction(menu);
localLinkAction->setText(helper->copyLocalLinkTitle());
connect(localLinkAction, &QAction::triggered, this, [localFile, helper] {
helper->sendCommand(QByteArray("COPY_LOCAL_LINK:"+localFile.toUtf8()+"\n"));
});
menu->addAction(localLinkAction);
return { menuaction };
}

};
Expand Down
19 changes: 15 additions & 4 deletions shell_integration/dolphin/ownclouddolphinpluginhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void OwncloudDolphinPluginHelper::sendCommand(const char* data)

void OwncloudDolphinPluginHelper::slotConnected()
{
sendCommand("SHARE_MENU_TITLE:\n");
sendCommand("GET_STRINGS:\n");
}

void OwncloudDolphinPluginHelper::tryConnect()
Expand All @@ -75,6 +75,12 @@ void OwncloudDolphinPluginHelper::tryConnect()
_socket.connectToServer(socketPath);
}

static QString getString(const QByteArray& line)
{
auto col = line.lastIndexOf(':');
return QString::fromUtf8(line.constData() + col + 1, line.size() - col - 1);
}

void OwncloudDolphinPluginHelper::slotReadyRead()
{
while (_socket.bytesAvailable()) {
Expand All @@ -92,9 +98,14 @@ void OwncloudDolphinPluginHelper::slotReadyRead()
QString file = QString::fromUtf8(line.constData() + col + 1, line.size() - col - 1);
_paths.append(file);
continue;
} else if (line.startsWith("SHARE_MENU_TITLE:")) {
auto col = line.indexOf(':');
_shareActionString = QString::fromUtf8(line.constData() + col + 1, line.size() - col - 1);
} else if (line.startsWith("STRING:CONTEXT_MENU_TITLE:")) {
_contextMenuTitle = getString(line);
continue;
} else if (line.startsWith("STRING:SHARE_MENU_TITLE:")) {
_shareActionTitle = getString(line);
continue;
} else if (line.startsWith("STRING:COPY_LOCAL_LINK_TITLE:")) {
_copyLocalLinkTitle = getString(line);
continue;
}
emit commandRecieved(line);
Expand Down
10 changes: 8 additions & 2 deletions shell_integration/dolphin/ownclouddolphinpluginhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ class OWNCLOUDDOLPHINPLUGINHELPER_EXPORT OwncloudDolphinPluginHelper : public QO
public:
static OwncloudDolphinPluginHelper *instance();

QString shareActionString() const { return _shareActionString; }
bool isConnected() const;
void sendCommand(const char *data);
QVector<QString> paths() const { return _paths; }

QString contextMenuTitle() const { return _contextMenuTitle; }
QString shareActionTitle() const { return _shareActionTitle; }
QString copyLocalLinkTitle() const { return _copyLocalLinkTitle; }

signals:
void commandRecieved(const QByteArray &cmd);

Expand All @@ -47,6 +50,9 @@ class OWNCLOUDDOLPHINPLUGINHELPER_EXPORT OwncloudDolphinPluginHelper : public QO
QLocalSocket _socket;
QByteArray _line;
QVector<QString> _paths;
QString _shareActionString;
QBasicTimer _connectTimer;

QString _contextMenuTitle;
QString _shareActionTitle;
QString _copyLocalLinkTitle;
};

0 comments on commit 5909405

Please sign in to comment.