Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[transfer-engine] Add TransferPluginInfo metadata and provide access …
…via D-Bus API. Contributes to JB#45043

This allows plugins to provide custom extensible metadata.
  • Loading branch information
Bea Lam committed Nov 18, 2019
1 parent a57767c commit 95c3900
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dbus/org.nemo.transferengine.xml
Expand Up @@ -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" />

Expand Down
1 change: 1 addition & 0 deletions lib/lib.pro
Expand Up @@ -25,6 +25,7 @@ SOURCES += \
mediatransferinterface.cpp \
mediaitem.cpp \
transfermethodinfo.cpp \
transferplugininfo.cpp \
transferengineclient.cpp \
imageoperation.cpp

Expand Down
1 change: 1 addition & 0 deletions lib/transfermethodinfo.cpp
Expand Up @@ -70,6 +70,7 @@
Creates an instance of TransferMethodInfo.
*/
TransferMethodInfo::TransferMethodInfo()
: accountId(0)
{
}

Expand Down
40 changes: 40 additions & 0 deletions lib/transferplugininfo.cpp
@@ -0,0 +1,40 @@
/*
* 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> >();
}
9 changes: 9 additions & 0 deletions lib/transferplugininfo.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2013 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
*
* All rights reserved.
*
Expand All @@ -25,6 +26,7 @@
#ifndef TRANSFERPLUGININFO_H
#define TRANSFERPLUGININFO_H
#include <QObject>
#include <QVariantMap>
#include "transfermethodinfo.h"

class TransferPluginInfo: public QObject
Expand All @@ -35,6 +37,13 @@ class TransferPluginInfo: public QObject
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);
Expand Down
21 changes: 21 additions & 0 deletions src/transferengine.cpp
Expand Up @@ -237,6 +237,7 @@ void TransferEnginePrivate::enabledPluginsCheck()

// First clear old data
m_enabledPlugins.clear();
m_pluginMetaData.clear();
qDeleteAll(m_infoObjects);
m_infoObjects.clear();

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -674,6 +681,7 @@ void TransferEnginePrivate::pluginInfoReady()
if (!infoList.isEmpty()) {
m_enabledPlugins << infoList;
}
m_pluginMetaData << infoObj->metaData();

if (m_infoObjects.removeOne(infoObj)) {
delete infoObj;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/transferengine.h
Expand Up @@ -86,6 +86,8 @@ public Q_SLOTS:
QList <TransferMethodInfoDeprecated> transferMethods();
QList <TransferMethodInfo> transferMethods2();

QList<QVariantMap> pluginMetaData();

void clearTransfers();

void clearTransfer(int transferId);
Expand Down
2 changes: 2 additions & 0 deletions src/transferengine_p.h
Expand Up @@ -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;

Expand All @@ -135,6 +136,7 @@ public Q_SLOTS:
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;
Expand Down

0 comments on commit 95c3900

Please sign in to comment.