[Pkg-owncloud-commits] [owncloud-client] 29/484: Dolphin shell integration: Add a Share with owncloud action
Sandro Knauß
hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:07 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit cac219aca894b48ff78f963c7238b2a5e9cd1181
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Thu Sep 10 11:45:19 2015 +0200
Dolphin shell integration: Add a Share with owncloud action
---
shell_integration/dolphin_kf5/CMakeLists.txt | 8 +-
.../dolphin_kf5/ownclouddolphinplugin.cpp | 1 +
...nplugin.cpp => ownclouddolphinpluginaction.cpp} | 135 +++++++++++----------
.../ownclouddolphinpluginaction.desktop | 6 +
4 files changed, 83 insertions(+), 67 deletions(-)
diff --git a/shell_integration/dolphin_kf5/CMakeLists.txt b/shell_integration/dolphin_kf5/CMakeLists.txt
index 1dfe9be..b896d4d 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 116858d..c542e7b 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/ownclouddolphinplugin.cpp b/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.cpp
similarity index 54%
copy from shell_integration/dolphin_kf5/ownclouddolphinplugin.cpp
copy to shell_integration/dolphin_kf5/ownclouddolphinpluginaction.cpp
index 116858d..81d04c4 100644
--- a/shell_integration/dolphin_kf5/ownclouddolphinplugin.cpp
+++ b/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.cpp
@@ -17,78 +17,43 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
-#include <Dolphin/KOverlayIconPlugin>
#include <KPluginFactory>
#include <KPluginLoader>
+#include <KIOWidgets/kabstractfileitemactionplugin.h>
#include <QtNetwork/QLocalSocket>
#include <KIOCore/kfileitem.h>
+#include <KIOCore/KFileItemListProperties>
+#include <QtWidgets/QAction>
-class OwncloudDolphinPlugin : public KOverlayIconPlugin
-{
+class Connector : QObject {
Q_OBJECT
+public:
QLocalSocket m_socket;
- typedef QHash<QByteArray, QByteArray> StatusMap;
- StatusMap m_status;
QByteArray m_line;
+ QVector<QString> m_paths;
+ QString m_shareActionString;
-public:
- explicit OwncloudDolphinPlugin(QObject* parent, const QList<QVariant>&) : KOverlayIconPlugin(parent) {
+ Connector() {
connect(&m_socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
tryConnect();
}
- virtual QStringList getOverlays(const KFileItem& item) {
- auto url = item.url();
- if (!url.isLocalFile())
- return QStringList();
- const QByteArray localFile = url.toLocalFile().toUtf8();
-// kDebug() << localFile;
-
- tryConnect();
- if (m_socket.state() == QLocalSocket::ConnectingState) {
- if (!m_socket.waitForConnected(100)) {
-// kWarning() << "not connected" << m_socket.errorString();
- }
- }
- if (m_socket.state() == QLocalSocket::ConnectedState) {
- m_socket.write("RETRIEVE_FILE_STATUS:");
- m_socket.write(localFile);
- m_socket.write("\n");
- }
-
- StatusMap::iterator it = m_status.find(localFile);
- if (it != m_status.constEnd()) {
- return overlaysForString(*it);
- }
- return QStringList();
- }
-
-
-private:
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);
- }
-
- QStringList overlaysForString(const QByteArray status) {
- QStringList r;
- if (status.startsWith("NOP"))
- return r;
-
- if (status.startsWith("OK"))
- r << "dialog-ok";
- if (status.startsWith("SYNC") || status.startsWith("NEW"))
- r << "view-refresh";
-
- if (status.contains("+SWM"))
- r << "document-share";
-
- return r;
+ 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:
@@ -102,26 +67,64 @@ private slots:
line.chop(1);
if (line.isEmpty())
continue;
- QList<QByteArray> tokens = line.split(':');
- if (tokens.count() != 3)
- continue;
- if (tokens[0] != "STATUS" && tokens[0] != "BROADCAST")
+ if (line.startsWith("REGISTER_PATH:")) {
+ QString file = QString::fromUtf8(line.mid(line.indexOf(':') + 1));
+ m_paths.append(file);
continue;
- if (tokens[2].isEmpty())
+ } else if (line.startsWith("SHARE_MENU_TITLE:")) {
+ m_shareActionString = QString::fromUtf8(line.mid(line.indexOf(':') + 1));
continue;
+ }
+ }
+ }
+};
- const QByteArray name = tokens[2];
- QByteArray &status = m_status[name]; // reference to the item in the hash
- if (status == tokens[1])
- continue;
- status = tokens[1];
- emit this->overlaysChanged(QUrl::fromLocalFile(QString::fromUtf8(name)), overlaysForString(status));
- }
+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(OwncloudDolphinPluginFactory, registerPlugin<OwncloudDolphinPlugin>();)
-K_EXPORT_PLUGIN(OwncloudDolphinPluginFactory("ownclouddolhpinplugin"))
+K_PLUGIN_FACTORY(OwncloudDolphinPluginActionFactory, registerPlugin<OwncloudDolphinPluginAction>();)
+K_EXPORT_PLUGIN(OwncloudDolphinPluginActionFactory("ownclouddolhpinpluginaction"))
-#include "ownclouddolphinplugin.moc"
+#include "ownclouddolphinpluginaction.moc"
diff --git a/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.desktop b/shell_integration/dolphin_kf5/ownclouddolphinpluginaction.desktop
new file mode 100644
index 0000000..0fdc00c
--- /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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list