Commit 95c3900c authored by blam's avatar blam

[transfer-engine] Add TransferPluginInfo metadata and provide access via D-Bus...

[transfer-engine] Add TransferPluginInfo metadata and provide access via D-Bus API. Contributes to JB#45043

This allows plugins to provide custom extensible metadata.
parent a57767c8
......@@ -97,6 +97,12 @@
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList &lt; TransferMethodInfo&gt; "/>
</method>
# Get a list of plugin metadata
<method name="pluginMetaData">
<arg name="methods" type="a(a{sv})" direction="out" />
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList &lt; QVariantMap &gt; "/>
</method>
# clear all unfinished transfers
<method name="clearTransfers" />
......
......@@ -25,6 +25,7 @@ SOURCES += \
mediatransferinterface.cpp \
mediaitem.cpp \
transfermethodinfo.cpp \
transferplugininfo.cpp \
transferengineclient.cpp \
imageoperation.cpp
......
......@@ -70,6 +70,7 @@
Creates an instance of TransferMethodInfo.
*/
TransferMethodInfo::TransferMethodInfo()
: accountId(0)
{
}
......
/*
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* All rights reserved.
*
* This file is part of Sailfish Transfer Engine package.
*
* You may use this file under the terms of the GNU Lesser General
* Public License version 2.1 as published by the Free Software Foundation
* and appearing in the file license.lgpl included in the packaging
* of this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* and appearing in the file license.lgpl included in the packaging
* of this file.
*
* This library 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
* Lesser General Public License for more details.
*/
#include "transferplugininfo.h"
QVariantMap TransferPluginInfo::metaData() const
{
return property("_nemo_transferplugininfo_capabilities").toMap();
}
void TransferPluginInfo::setMetaData(const QVariantMap &metaData)
{
setProperty("_nemo_transferplugininfo_capabilities", metaData);
}
void TransferPluginInfo::registerType()
{
qDBusRegisterMetaType<QList<QVariantMap> >();
}
/*
* Copyright (c) 2013 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* All rights reserved.
*
......@@ -25,6 +26,7 @@
#ifndef TRANSFERPLUGININFO_H
#define TRANSFERPLUGININFO_H
#include <QObject>
#include <QVariantMap>
#include "transfermethodinfo.h"
class TransferPluginInfo: public QObject
......@@ -35,6 +37,13 @@ public:
virtual void query() = 0;
virtual bool ready() const = 0;
QVariantMap metaData() const;
static void registerType();
protected:
void setMetaData(const QVariantMap &metaData);
Q_SIGNALS:
void infoReady();
void infoError(const QString &msg);
......
......@@ -237,6 +237,7 @@ void TransferEnginePrivate::enabledPluginsCheck()
// First clear old data
m_enabledPlugins.clear();
m_pluginMetaData.clear();
qDeleteAll(m_infoObjects);
m_infoObjects.clear();
......@@ -268,6 +269,7 @@ void TransferEnginePrivate::enabledPluginsCheck()
if (info->info().count() > 0) {
m_enabledPlugins << info->info();
}
m_pluginMetaData << info->metaData();
delete info;
} else {
// These object will be cleaned in pluginInfoReady() slot.
......@@ -564,6 +566,11 @@ QList <TransferMethodInfo> TransferEnginePrivate::enabledPlugins() const
return m_enabledPlugins;
}
QList<QVariantMap> TransferEnginePrivate::pluginMetaData() const
{
return m_pluginMetaData;
}
MediaTransferInterface *TransferEnginePrivate::loadPlugin(const QString &pluginId) const
{
QPluginLoader loader;
......@@ -674,6 +681,7 @@ void TransferEnginePrivate::pluginInfoReady()
if (!infoList.isEmpty()) {
m_enabledPlugins << infoList;
}
m_pluginMetaData << infoObj->metaData();
if (m_infoObjects.removeOne(infoObj)) {
delete infoObj;
......@@ -815,6 +823,7 @@ TransferEngine::TransferEngine(QObject *parent) :
TransferMethodInfoDeprecated::registerType();
TransferMethodInfo::registerType();
TransferDBRecord::registerType();
TransferPluginInfo::registerType();
QDBusConnection connection = QDBusConnection::sessionBus();
if (!connection.registerObject("/org/nemo/transferengine", this)) {
......@@ -1298,6 +1307,18 @@ QList <TransferMethodInfo> TransferEngine::transferMethods2()
return d->enabledPlugins();
}
/*!
DBus adaptor calls this method to fetch a list of the share plugin metadata.
This method returns QList<QVariantMap>.
*/
QList<QVariantMap> TransferEngine::pluginMetaData()
{
Q_D(TransferEngine);
d->exitSafely();
return d->pluginMetaData();
}
/*!
DBus adaptor calls this method to clear all the finished, canceled or interrupted transfers in the database.
*/
......
......@@ -86,6 +86,8 @@ public Q_SLOTS:
QList <TransferMethodInfoDeprecated> transferMethods();
QList <TransferMethodInfo> transferMethods2();
QList<QVariantMap> pluginMetaData();
void clearTransfers();
void clearTransfer(int transferId);
......
......@@ -126,6 +126,7 @@ public Q_SLOTS:
public:
QStringList pluginList() const;
QList <TransferMethodInfo> enabledPlugins() const;
QList<QVariantMap> pluginMetaData() const;
MediaTransferInterface *loadPlugin(const QString &pluginId) const;
QString mediaFileOrResourceName(MediaItem *mediaItem) const;
......@@ -135,6 +136,7 @@ private:
bool m_notificationsEnabled;
QList <TransferPluginInfo*> m_infoObjects;
QList <TransferMethodInfo> m_enabledPlugins;
QList<QVariantMap> m_pluginMetaData;
Accounts::Manager *m_accountManager;
QFileSystemWatcher *m_fileWatcher;
QTimer *m_fileWatcherTimer;
......
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