Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[transfer-engine] Added clearTransfer method to the D-Bus interface. …
…Contributes to JB#15452
  • Loading branch information
monich committed Aug 10, 2016
1 parent 53895a4 commit b0132eb
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 4 deletions.
4 changes: 4 additions & 0 deletions dbus/org.nemo.transferengine.xml
Expand Up @@ -99,6 +99,10 @@
<arg name="transferId" type="i" direction="in"/>
</method>

<method name="clearTransfer">
<arg name="transferId" type="i" direction="in"/>
</method>

# enable or disable notifications
<method name="enableNotifications">
<arg name="enable" type="b" direction="in"/>
Expand Down
9 changes: 8 additions & 1 deletion declarative/declarativetransfermodel.cpp
@@ -1,6 +1,6 @@
/****************************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Copyright (C) 2014-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jolla.com>
** All rights reserved.
**
Expand Down Expand Up @@ -134,6 +134,13 @@ void TransferModel::clearTransfers()
}
}

void TransferModel::clearTransfer(int transferId)
{
if (m_client) {
m_client->clearTransfer(transferId);
}
}

QHash<int, QByteArray> TransferModel::roleNames() const
{
return m_roles;
Expand Down
3 changes: 2 additions & 1 deletion declarative/declarativetransfermodel.h
@@ -1,6 +1,6 @@
/****************************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Copyright (C) 2014-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jolla.com>
** All rights reserved.
**
Expand Down Expand Up @@ -83,6 +83,7 @@ class TransferModel

Q_INVOKABLE QJSValue get(int index) const;
Q_INVOKABLE void clearTransfers();
Q_INVOKABLE void clearTransfer(int transferId);

QHash<int, QByteArray> roleNames() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
Expand Down
11 changes: 10 additions & 1 deletion lib/transferengineclient.cpp
@@ -1,6 +1,6 @@
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jollamobile.com>
** All rights reserved.
**
Expand Down Expand Up @@ -366,6 +366,15 @@ void TransferEngineClient::clearTransfers()
d->m_client->clearTransfers();
}

/*!
Private method for QML interface to clear a finished, canceled or interrupted event.
*/
void TransferEngineClient::clearTransfer(int transferId)
{
Q_D(TransferEngineClient);
d->m_client->clearTransfer(transferId);
}

/*!
Private method for QML interface to enable notifications.
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/transferengineclient.h
@@ -1,6 +1,6 @@
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jollamobile.com>
** All rights reserved.
**
Expand Down Expand Up @@ -84,6 +84,7 @@ class TransferEngineClient : public QObject
private:
void cbCancelTransfer(int transferId);
void cbRestartTransfer(int transferId);
void clearTransfer(int transferId);
void clearTransfers();
void enableNotifications(bool enable);
bool notificationsEnabled() const;
Expand Down
19 changes: 19 additions & 0 deletions src/dbmanager.cpp
Expand Up @@ -613,6 +613,25 @@ bool DbManager::clearTransfers()
return true;
}

bool DbManager::clearTransfer(int key)
{
QSqlQuery query;
TransferEngineData::TransferStatus status = transferStatus(key);
switch (status) {
case TransferEngineData::TransferFinished:
case TransferEngineData::TransferCanceled:
case TransferEngineData::TransferInterrupted:
if (query.exec(QString("DELETE FROM transfers WHERE transfer_id='%1';").arg(QString::number(key)))) {
return true;
}
qWarning() << "Failed to execute SQL query. Couldn't delete transfer" << key;
return false;
default:
qWarning() << "Not clearing transfer" << key << "because its status is" << status;
return false;
}
}

int DbManager::transferCount() const
{
QSqlQuery query;
Expand Down
2 changes: 2 additions & 0 deletions src/dbmanager.h
Expand Up @@ -61,6 +61,8 @@ class DbManager

bool clearFailedTransfers(int excludeKey, TransferEngineData::TransferType type);

bool clearTransfer(int key);

bool clearTransfers();

int transferCount() const;
Expand Down
12 changes: 12 additions & 0 deletions src/transferengine.cpp
Expand Up @@ -1248,6 +1248,18 @@ void TransferEngine::clearTransfers()
}
}

/*!
DBus adaptor calls this method to remove a finished, canceled or interrupted transfer from the database.
*/
void TransferEngine::clearTransfer(int transferId)
{
Q_D(TransferEngine);
d->exitSafely();
if (DbManager::instance()->clearTransfer(transferId)) {
emit transfersChanged();
}
}

/*!
DBus adaptor calls this method to cancel an existing transfer with a \a transferId.
Expand Down
2 changes: 2 additions & 0 deletions src/transferengine.h
Expand Up @@ -89,6 +89,8 @@ public Q_SLOTS:

void clearTransfers();

void clearTransfer(int transferId);

void cancelTransfer(int transferId);

void enableNotifications(bool enable);
Expand Down

0 comments on commit b0132eb

Please sign in to comment.