|
|
@@ -17,8 +17,8 @@
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
|
|
******************************************************************************/
|
|
|
|
|
|
-#include <KPluginFactory>
|
|
|
-#include <KPluginLoader>
|
|
|
+#include <KCoreAddons/KPluginFactory>
|
|
|
+#include <KCoreAddons/KPluginLoader>
|
|
|
#include <KIOWidgets/kabstractfileitemactionplugin.h>
|
|
|
#include <QtNetwork/QLocalSocket>
|
|
|
#include <KIOCore/kfileitem.h>
|
|
|
@@ -27,6 +27,7 @@
|
|
|
#include <QtWidgets/QMenu>
|
|
|
#include <QtCore/QDir>
|
|
|
#include <QtCore/QTimer>
|
|
|
+#include <QtCore/QEventLoop>
|
|
|
#include "ownclouddolphinpluginhelper.h"
|
|
|
|
|
|
class OwncloudDolphinPluginAction : public KAbstractFileItemActionPlugin
|
|
|
@@ -39,22 +40,70 @@ public:
|
|
|
QList<QAction*> actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) Q_DECL_OVERRIDE
|
|
|
{
|
|
|
auto helper = OwncloudDolphinPluginHelper::instance();
|
|
|
- QList<QUrl> urls = fileItemInfos.urlList();
|
|
|
- if (urls.count() != 1 || !helper->isConnected())
|
|
|
+ if (!helper->isConnected() || !fileItemInfos.isLocal())
|
|
|
return {};
|
|
|
|
|
|
- auto url = urls.first();
|
|
|
- if (!url.isLocalFile())
|
|
|
+ // If any of the url is outside of a sync folder, return an empty menu.
|
|
|
+ const QList<QUrl> urls = fileItemInfos.urlList();
|
|
|
+ const auto paths = helper->paths();
|
|
|
+ QByteArray files;
|
|
|
+ for (const auto &url : urls) {
|
|
|
+ QDir localPath(url.toLocalFile());
|
|
|
+ auto localFile = localPath.canonicalPath();
|
|
|
+ if (!std::any_of(paths.begin(), paths.end(), [&](const QString &s) {
|
|
|
+ return localFile.startsWith(s);
|
|
|
+ }))
|
|
|
+ return {};
|
|
|
+
|
|
|
+ if (!files.isEmpty())
|
|
|
+ files += '\x1e'; // Record separator
|
|
|
+ files += localFile.toUtf8();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (helper->version() < "1.1") { // in this case, lexicographic order works
|
|
|
+ return legacyActions(fileItemInfos, parentWidget);
|
|
|
+ }
|
|
|
+
|
|
|
+ auto menu = new QMenu(parentWidget);
|
|
|
+ QEventLoop loop;
|
|
|
+ auto con = connect(helper, &OwncloudDolphinPluginHelper::commandRecieved, this, [&](const QByteArray &cmd) {
|
|
|
+ if (cmd.startsWith("GET_MENU_ITEMS:END")) {
|
|
|
+ loop.quit();
|
|
|
+ } else if (cmd.startsWith("MENU_ITEM:")) {
|
|
|
+ auto args = QString::fromUtf8(cmd).split(QLatin1Char(':'));
|
|
|
+ if (args.size() < 3)
|
|
|
+ return;
|
|
|
+ auto action = menu->addAction(args.mid(2).join(QLatin1Char(':')));
|
|
|
+ auto call = args.value(1).toLatin1();
|
|
|
+ connect(action, &QAction::triggered, [helper, call, files] {
|
|
|
+ helper->sendCommand(QByteArray(call + ":" + files + "\n"));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ QTimer::singleShot(100, &loop, SLOT(quit())); // add a timeout to be sure we don't freeze dolphin
|
|
|
+ helper->sendCommand(QByteArray("GET_MENU_ITEMS:" + files + "\n"));
|
|
|
+ loop.exec(QEventLoop::ExcludeUserInputEvents);
|
|
|
+ disconnect(con);
|
|
|
+ if (menu->actions().isEmpty()) {
|
|
|
+ delete menu;
|
|
|
return {};
|
|
|
- QDir localPath(url.toLocalFile());
|
|
|
- auto localFile = localPath.canonicalPath();
|
|
|
+ }
|
|
|
+
|
|
|
+ auto menuaction = new QAction(parentWidget);
|
|
|
+ menuaction->setText(helper->contextMenuTitle());
|
|
|
+ menuaction->setMenu(menu);
|
|
|
+ return { menuaction };
|
|
|
+ }
|
|
|
|
|
|
- const auto paths = helper->paths();
|
|
|
- if (!std::any_of(paths.begin(), paths.end(), [&](const QString &s) {
|
|
|
- return localFile.startsWith(s);
|
|
|
- } ))
|
|
|
- return {};
|
|
|
|
|
|
+ QList<QAction *> legacyActions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget)
|
|
|
+ {
|
|
|
+ QList<QUrl> urls = fileItemInfos.urlList();
|
|
|
+ if (urls.count() != 1)
|
|
|
+ return {};
|
|
|
+ QDir localPath(urls.first().toLocalFile());
|
|
|
+ auto localFile = localPath.canonicalPath();
|
|
|
+ auto helper = OwncloudDolphinPluginHelper::instance();
|
|
|
auto menuaction = new QAction(parentWidget);
|
|
|
menuaction->setText(helper->contextMenuTitle());
|
|
|
auto menu = new QMenu(parentWidget);
|
|
|
@@ -62,8 +111,8 @@ public:
|
|
|
|
|
|
auto shareAction = menu->addAction(helper->shareActionTitle());
|
|
|
connect(shareAction, &QAction::triggered, this, [localFile, helper] {
|
|
|
- helper->sendCommand(QByteArray("SHARE:"+localFile.toUtf8()+"\n"));
|
|
|
- } );
|
|
|
+ helper->sendCommand(QByteArray("SHARE:" + localFile.toUtf8() + "\n"));
|
|
|
+ });
|
|
|
|
|
|
if (!helper->copyPrivateLinkTitle().isEmpty()) {
|
|
|
auto copyPrivateLinkAction = menu->addAction(helper->copyPrivateLinkTitle());
|
|
|
@@ -78,7 +127,6 @@ public:
|
|
|
helper->sendCommand(QByteArray("EMAIL_PRIVATE_LINK:" + localFile.toUtf8() + "\n"));
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
return { menuaction };
|
|
|
}
|
|
|
|