Commit c7405a4c authored by Slava Monich's avatar Slava Monich

[transfer-engine] Added activeTransfers method to the D-Bus interface. Contributes to JB#34083

activeTransfersChanged signal is emitted when a transfer is added to
or removed from the activeTransfers list.

This allows to avoid the overhead of fetching the full list of transfers
just to check if any of them is active.
parent dc528c6e
......@@ -79,6 +79,12 @@
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList &lt; TransferDBRecord &gt; "/>
</method>
# Get a list of active transfers
<method name="activeTransfers">
<arg name="records" type="a(iidss)" direction="out" />
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList &lt; TransferDBRecord &gt; "/>
</method>
# Get a list of transfer methods such as FB, Twitter, BT, NFC, etc
<method name="transferMethods">
<arg name="methods" type="a(ssssasi)" direction="out" />
......@@ -116,6 +122,8 @@
<signal name="transfersChanged" />
<signal name="activeTransfersChanged" />
<signal name="transferMethodListChanged" />
</interface>
</node>
......
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jollamobile.com>
** All rights reserved.
**
......@@ -613,16 +613,61 @@ bool DbManager::clearTransfers()
return true;
}
int DbManager::transferCount() const
{
QSqlQuery query;
if (query.exec(QString("SELECT COUNT(transfer_id) FROM transfers"))) {
query.next();
return query.value(0).toInt();
} else {
qWarning() << "DbManager::transferCount: Failed to execute SQL query!";
return -1;
}
}
int DbManager::activeTransferCount() const
{
QSqlQuery query;
if (query.exec(QString("SELECT COUNT(transfer_id) FROM transfers WHERE status='%1'").arg(TransferEngineData::TransferStarted))) {
query.next();
return query.value(0).toInt();
} else {
qWarning() << "DbManager::activeTransferCount: Failed to execute SQL query!";
return -1;
}
}
/*!
Returns all the transfers from the database. This method doesn't fetch all the fields from all the
tables, instead it returns what is required to fill fields in TransferDBRecord class.
*/
QList<TransferDBRecord> DbManager::transfers() const
{
return transfers(TransferEngineData::Unknown);
}
/*!
Returns all the active transfers from the database. This method doesn't fetch all the fields from all the
tables, instead it returns what is required to fill fields in TransferDBRecord class.
*/
QList<TransferDBRecord> DbManager::activeTransfers() const
{
return transfers(TransferEngineData::TransferStarted);
}
/*!
Returns all the transfers from the database which have the specified status. This method doesn't fetch all the fields from all the
tables, instead it returns what is required to fill fields in TransferDBRecord class.
*/
QList<TransferDBRecord> DbManager::transfers(TransferEngineData::TransferStatus status) const
{
// TODO: This should order the result based on timestamp
QList<TransferDBRecord> records;
QString queryStr = (status == TransferEngineData::Unknown) ?
QString("SELECT * FROM transfers ORDER BY transfer_id DESC") :
QString("SELECT * FROM transfers WHERE status='%1' ORDER BY transfer_id DESC").arg(status);
QSqlQuery query;
if (!query.exec("SELECT * FROM transfers ORDER BY transfer_id DESC")) {
if (!query.exec(queryStr)) {
qWarning() << "DbManager::transfers: Failed to execute SQL query. Couldn't get list of transfers!";
return records;
}
......
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jollamobile.com>
** All rights reserved.
**
......@@ -63,8 +63,14 @@ public:
bool clearTransfers();
int transferCount() const;
int activeTransferCount() const;
QList<TransferDBRecord> transfers() const;
QList<TransferDBRecord> activeTransfers() const;
TransferEngineData::TransferType transferType(int key) const;
TransferEngineData::TransferStatus transferStatus(int key) const;
......@@ -75,6 +81,7 @@ public:
private:
DbManager();
QList<TransferDBRecord> transfers(TransferEngineData::TransferStatus status) const;
DbManagerPrivate *d_ptr;
Q_DECLARE_PRIVATE(DbManager)
};
......
......@@ -14,7 +14,10 @@ packagesExist(qt5-boostable) {
LIBS += -L../lib -lnemotransferengine-qt5
# generate adaptor code
system(qdbusxml2cpp -c TransferEngineAdaptor -a transferengineadaptor.h:transferengineadaptor.cpp -i metatypedeclarations.h ../dbus/org.nemo.transferengine.xml)
DBUS_ADAPTORS += transferengine
transferengine.files = ../dbus/org.nemo.transferengine.xml
transferengine.header_flags = -i metatypedeclarations.h -i transferengine.h -l TransferEngine -c TransferEngineAdaptor
transferengine.source_flags = -l TransferEngine -c TransferEngineAdaptor
CONFIG += link_pkgconfig
PKGCONFIG += accounts-qt5 nemonotifications-qt5
......@@ -49,12 +52,10 @@ PRE_TARGETDEPS += ts engineering_english
# Input
SOURCES += main.cpp \
transferengineadaptor.cpp \
dbmanager.cpp \
transferengine.cpp
HEADERS += \
transferengineadaptor.h \
dbmanager.h \
transferengine.h \
transferengine_p.h
......
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jollamobile.com>
** All rights reserved.
**
......@@ -29,7 +29,7 @@
#include "transferplugininterface.h"
#include "mediaitem.h"
#include "dbmanager.h"
#include "transferengineadaptor.h"
#include "transferengine_adaptor.h"
#include "transfertypes.h"
#include "transferplugininfo.h"
......@@ -195,8 +195,12 @@ void TransferEnginePrivate::exitSafely()
void TransferEnginePrivate::delayedExitSafely()
{
qDebug() << "Stopping transfer engine";
qApp->exit();
if (getenv("TRANSFER_ENGINE_KEEP_RUNNING")) {
qDebug() << "Keeping transfer engine running";
} else {
qDebug() << "Stopping transfer engine";
qApp->exit();
}
}
void TransferEnginePrivate::enabledPluginsCheck()
......@@ -285,6 +289,9 @@ void TransferEnginePrivate::recoveryCheck()
record.status == TransferEngineData::NotStarted) {
if (DbManager::instance()->updateTransferStatus(record.transfer_id, TransferEngineData::TransferInterrupted)) {
emit q->statusChanged(record.transfer_id, TransferEngineData::TransferInterrupted);
if (record.status == TransferEngineData::TransferStarted) {
emit q_ptr->activeTransfersChanged(); // It's not active anymore
}
}
}
}
......@@ -1041,6 +1048,7 @@ void TransferEngine::startTransfer(int transferId)
d->m_activityMonitor->newActivity(transferId);
DbManager::instance()->updateTransferStatus(transferId, TransferEngineData::TransferStarted);
emit statusChanged(transferId, TransferEngineData::TransferStarted);
emit activeTransfersChanged();
} else {
qWarning() << "TransferEngine::startTransfer: could not start transfer";
}
......@@ -1159,6 +1167,8 @@ void TransferEngine::finishTransfer(int transferId, int status, const QString &r
}
}
emit activeTransfersChanged(); // Assume that the transfer was active
if (notify) {
emit transfersChanged();
}
......@@ -1197,6 +1207,16 @@ QList<TransferDBRecord> TransferEngine::transfers()
return DbManager::instance()->transfers();
}
/*!
DBus adaptor calls this method to fetch a list of active transfers. This method returns QList<TransferDBRecord>.
*/
QList<TransferDBRecord> TransferEngine::activeTransfers()
{
Q_D(TransferEngine);
d->exitSafely();
return DbManager::instance()->activeTransfers();
}
/*!
DBus adaptor calls this method to fetch a list of transfer methods. This method returns QList<TransferMethodInfo>.
......@@ -1216,10 +1236,15 @@ void TransferEngine::clearTransfers()
{
Q_D(TransferEngine);
d->exitSafely();
if (DbManager::instance()->clearTransfers()) {
emit transfersChanged();
} else {
qWarning() << "TransferEngine::clearTransfers: Failed to clear finished transfers!";
const int count = DbManager::instance()->transferCount();
if (count > 0) {
const int active = DbManager::instance()->activeTransferCount();
if (DbManager::instance()->clearTransfers()) {
if (active > 0) {
emit activeTransfersChanged();
}
emit transfersChanged();
}
}
}
......
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jollamobile.com>
** All rights reserved.
**
......@@ -83,6 +83,8 @@ public Q_SLOTS:
QList<TransferDBRecord> transfers();
QList<TransferDBRecord> activeTransfers();
QList <TransferMethodInfo> transferMethods();
void clearTransfers();
......@@ -102,6 +104,7 @@ Q_SIGNALS:
void transfersChanged();
void activeTransfersChanged();
private:
TransferEnginePrivate *d_ptr;
......
......@@ -13,6 +13,7 @@ systemd.path = /usr/lib/systemd/user/
OTHER_FILES += \
rpm/*.spec \
nemo-transfer-engine.conf \
dbus/* \
doc/src/* \
doc/config/*
......
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