diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2015-09-10 12:45:19 +0300 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2015-09-10 14:41:45 +0300 |
commit | cac219aca894b48ff78f963c7238b2a5e9cd1181 (patch) | |
tree | 4ec44f79744e1e04b0ea02840db58c6b7622e81b /shell_integration | |
parent | a159dfc7ec812dd7268fca8106deb1a9202ce47c (diff) |
Dolphin shell integration: Add a Share with owncloud action
Diffstat (limited to 'shell_integration')
4 files changed, 144 insertions, 1 deletions
diff --git a/shell_integration/dolphin_kf5/CMakeLists.txt b/shell_integration/dolphin_kf5/CMakeLists.txt index 1dfe9bed7..b896d4d0c 100644 --- a/shell_integration/dolphin_kf5/CMakeLists.txt +++ b/shell_integration/dolphin_kf5/CMakeLists.txt @@ -11,7 +11,7 @@ find_package(ECM 1.2.0 REQUIRED CONFIG) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS CoreAddons) +find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS CoreAddons KIO) find_package(DolphinVcs REQUIRED) set_package_properties(DolphinVcs PROPERTIES @@ -35,3 +35,9 @@ add_library(ownclouddolphinplugin MODULE ownclouddolphinplugin.cpp) target_link_libraries(ownclouddolphinplugin DolphinVcs Qt5::Network KF5::CoreAddons KF5::KIOCore) install(FILES ownclouddolphinplugin.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) install(TARGETS ownclouddolphinplugin DESTINATION ${KDE_INSTALL_PLUGINDIR}) + + +add_library(ownclouddolphinpluginaction MODULE ownclouddolphinpluginaction.cpp) +target_link_libraries(ownclouddolphinpluginaction Qt5::Network KF5::CoreAddons KF5::KIOCore KF5::KIOWidgets) +install(FILES ownclouddolphinpluginaction.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) +install(TARGETS ownclouddolphinpluginaction DESTINATION ${KDE_INSTALL_PLUGINDIR}) diff --git a/shell_integration/dolphin_kf5/ownclouddolphinplugin.cpp b/shell_integration/dolphin_kf5/ownclouddolphinplugin.cpp index 116858d1a..c542e7b45 100644 --- a/shell_integration/dolphin_kf5/ownclouddolphinplugin.cpp +++ b/shell_integration/dolphin_kf5/ownclouddolphinplugin.cpp @@ -24,6 +24,7 @@ #include <KIOCore/kfileitem.h> + class OwncloudDolphinPlugin : public KOverlayIconPlugin { Q_OBJECT diff --git a/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.cpp b/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.cpp new file mode 100644 index 000000000..81d04c45a --- /dev/null +++ b/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.cpp @@ -0,0 +1,130 @@ +/****************************************************************************** + * Copyright (C) 2014 by Olivier Goffart <ogoffart@woboq.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ******************************************************************************/ + +#include <KPluginFactory> +#include <KPluginLoader> +#include <KIOWidgets/kabstractfileitemactionplugin.h> +#include <QtNetwork/QLocalSocket> +#include <KIOCore/kfileitem.h> +#include <KIOCore/KFileItemListProperties> +#include <QtWidgets/QAction> + + +class Connector : QObject { + Q_OBJECT +public: + QLocalSocket m_socket; + QByteArray m_line; + QVector<QString> m_paths; + QString m_shareActionString; + + Connector() { + connect(&m_socket, SIGNAL(readyRead()), this, SLOT(readyRead())); + tryConnect(); + } + + + void tryConnect() { + + if (m_socket.state() != QLocalSocket::UnconnectedState) + return; + QString runtimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR")); + QString socketPath = runtimeDir + "/" + "ownCloud" + "/socket"; + m_socket.connectToServer(socketPath); + if (m_socket.state() == QLocalSocket::ConnectingState) { + m_socket.waitForConnected(100); + } + if (m_socket.state() == QLocalSocket::ConnectedState) { + m_socket.write("SHARE_MENU_TITLE:\n"); + m_socket.flush(); + } + } + +private slots: + void readyRead() { + while (m_socket.bytesAvailable()) { + m_line += m_socket.readLine(); + if (!m_line.endsWith("\n")) + continue; + QByteArray line; + qSwap(line, m_line); + line.chop(1); + if (line.isEmpty()) + continue; + if (line.startsWith("REGISTER_PATH:")) { + QString file = QString::fromUtf8(line.mid(line.indexOf(':') + 1)); + m_paths.append(file); + continue; + } else if (line.startsWith("SHARE_MENU_TITLE:")) { + m_shareActionString = QString::fromUtf8(line.mid(line.indexOf(':') + 1)); + continue; + } + } + } +}; + + +class OwncloudDolphinPluginAction : public KAbstractFileItemActionPlugin +{ +public: + explicit OwncloudDolphinPluginAction(QObject* parent, const QList<QVariant>&) : KAbstractFileItemActionPlugin(parent) { + } + + QList<QAction*> actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) Q_DECL_OVERRIDE + { + static Connector connector; + connector.tryConnect(); + + QList<QUrl> urls = fileItemInfos.urlList(); + if (urls.count() != 1 || connector.m_socket.state() != QLocalSocket::ConnectedState) + return {}; + + auto url = urls.first(); + + + if (!url.isLocalFile()) + return {}; + auto localFile = url.toLocalFile(); + + + if (!std::any_of(connector.m_paths.begin(), connector.m_paths.end(), [&](const QString &s) { + return localFile.startsWith(s); + } )) + return {}; + + auto act = new QAction(parentWidget); + act->setText(connector.m_shareActionString); + auto socket = &connector.m_socket; + connect(act, &QAction::triggered, this, [localFile, socket] { + socket->write("SHARE:"); + socket->write(localFile.toUtf8()); + socket->write("\n"); + socket->flush(); + } ); + + return { act }; + + } + +}; + +K_PLUGIN_FACTORY(OwncloudDolphinPluginActionFactory, registerPlugin<OwncloudDolphinPluginAction>();) +K_EXPORT_PLUGIN(OwncloudDolphinPluginActionFactory("ownclouddolhpinpluginaction")) + +#include "ownclouddolphinpluginaction.moc" diff --git a/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.desktop b/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.desktop new file mode 100644 index 000000000..0fdc00c05 --- /dev/null +++ b/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Type=Service +Name=OwncloudAction +ServiceTypes=KFileItemAction/Plugin +MimeType=text/plain; +X-KDE-Library=ownclouddolphinpluginaction |