Commit 5be7a416 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Allow uploading files to gdrive via Purpose

This adds a plugin for Purpose that allows uploading files from apps that use Purpose like Dolphin, Okular, Gwenview, or Spectacle to GDrive.
parent 81207c73
......@@ -35,6 +35,10 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
find_package(KPimGAPI ${KGAPI_MIN_VERSION} REQUIRED)
find_package(KF5Purpose ${KF5_MIN_VERSION}) # Optional since it depends on KAccounts
set_package_properties(KF5Purpose PROPERTIES TYPE RECOMMENDED PURPOSE "Enables the Share menu plugin.")
find_package(KAccounts ${KACCOUNTS_MIN_VERSION})
set_package_properties(KAccounts PROPERTIES
TYPE RECOMMENDED
......@@ -73,6 +77,10 @@ add_subdirectory(desktop)
add_subdirectory(doc)
add_subdirectory(src)
if (KF5Purpose_FOUND)
add_subdirectory(purpose)
endif()
if (KAccounts_FOUND)
message(STATUS "Building the KAccounts backend.")
add_subdirectory(kaccounts)
......
kcoreaddons_add_plugin(purpose_gdrive SOURCES purpose_gdrive.cpp gdrivejob.cpp JSON "purpose_gdrive.json" INSTALL_NAMESPACE "kf5/purpose")
target_link_libraries(purpose_gdrive Qt5::Core KF5::Purpose)
set_target_properties(purpose_gdrive PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/purpose")
install(FILES "purpose_gdrive_config.qml" DESTINATION ${KDE_INSTALL_DATADIR}/purpose)
target_link_libraries(purpose_gdrive KF5::KIOCore KF5::I18n KF5::Purpose)
#!/bin/sh
$XGETTEXT `find . -not -path \*/tests/\* -name \*.cpp -o -name \*.qml -o -name \*.cc -o -name \*.h` -o $podir/kio5_gdrive.pot
/*
SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "gdrivejob.h"
#include <KIO/CopyJob>
QList<QUrl> arrayToList(const QJsonArray& array)
{
QList<QUrl> ret;
for (const QJsonValue& val : array) {
ret += val.toVariant().toUrl();
}
return ret;
}
void GDriveJob::start()
{
const QString accountName = data().value(QStringLiteral("accountName")).toString();
QString folder = data().value(QStringLiteral("folder")).toString();
if (!folder.startsWith(QLatin1Char('/'))) {
folder.prepend(QLatin1Char('/'));
}
QUrl destUrl;
destUrl.setScheme(QStringLiteral("gdrive"));
destUrl.setPath(accountName + folder);
const QList<QUrl> sourceUrls = arrayToList(data().value(QStringLiteral("urls")).toArray());
KIO::CopyJob *copyJob = KIO::copy(sourceUrls, destUrl);
connect(copyJob, &KIO::CopyJob::finished, this, [this, copyJob] {
if (copyJob->error()) {
setError(copyJob->error());
setErrorText(copyJob->errorText());
}
emitResult();
});
copyJob->start();
}
/*
SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef GDRIVEJOB_H
#define GDRIVEJOB_H
#include <purpose/pluginbase.h>
#include <QString>
#include <QUrl>
class GDriveJob : public Purpose::Job
{
Q_OBJECT
public:
GDriveJob(QObject* parent)
: Purpose::Job(parent)
{}
void start() override;
};
#endif /* GDRIVEJOB_H */
/*
SPDX-FileCopyrightText: 2017 Lim Yuen Hoe <yuenhoe86@gmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <purpose/pluginbase.h>
#include "gdrivejob.h"
#include <KPluginFactory>
#include <QUrl>
class GDrivePlugin : public Purpose::PluginBase
{
Q_OBJECT
public:
GDrivePlugin(QObject* parent, const QVariantList& args)
: Purpose::PluginBase(parent)
{
Q_UNUSED(args);
}
Purpose::Job* createJob() const override
{
return new GDriveJob(nullptr);
}
};
K_PLUGIN_CLASS_WITH_JSON(GDrivePlugin, "purpose_gdrive.json")
EXPORT_SHARE_VERSION
#include "purpose_gdrive.moc"
{
"KPlugin": {
"Authors": [
{
"Name": "Nicolas Fella"
}
],
"Category": "Utilities",
"Description": "Upload files to Google Drive",
"Icon": "folder-gdrive",
"License": "GPL",
"Name": "Google Drive",
"X-Purpose-ActionDisplay": "Google Drive..."
},
"X-Purpose-Configuration": [
"folder",
"accountName"
],
"X-Purpose-PluginTypes": [
"Export"
]
}
/*
SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
import QtQuick 2.2
import QtQuick.Controls 2.10
import QtQuick.Layouts 1.1
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kquickcontrolsaddons 2.0 as KQCA
import Ubuntu.OnlineAccounts 0.1 as OA
ColumnLayout
{
id: root
property var folder: folderField.text
property var accountName
property var urls
property var mimeType
Kirigami.Heading {
text: i18nd("kio5_gdrive", "Select an account:")
visible: list.count !== 0
}
ScrollView {
id: scroll
Layout.fillWidth: true
Layout.fillHeight: true
Component.onCompleted: scroll.background.visible = true
ListView {
id: list
clip: true
model: OA.AccountServiceModel {
id: serviceModel
serviceType: "google-drive"
}
delegate: Kirigami.BasicListItem {
text: model.displayName
}
onCurrentIndexChanged: {
if (currentIndex === -1) {
root.accountName = undefined
return
}
root.accountName = serviceModel.get(list.currentIndex, "displayName")
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: parent.width - (Kirigami.Units.largeSpacing * 4)
visible: list.count === 0
text: i18nd("kio5_gdrive", "No account configured")
}
}
}
Button {
Layout.alignment: Qt.AlignRight
text: i18nd("kio5_gdrive", "Configure Accounts")
icon.name: "applications-internet"
onClicked: KQCA.KCMShell.openSystemSettings("kcm_kaccounts")
}
Label {
Layout.fillWidth: true
text: i18nd("kio5_gdrive", "Upload to folder:")
}
TextField {
id: folderField
Layout.fillWidth: true
text: "/"
onTextChanged: {
// Setting folder to undefined disables the Run button
root.folder = text !== "" ? text : undefined
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment