Commit adbc3db2 authored by Slava Monich's avatar Slava Monich

Merge branch 'jb15452' into 'master'

Add clearTransfer method to the D-Bus interface

Enabler for adding UI to delete individual entries from the transfer list.

See merge request !3
parents 53895a46 b0132ebc
......@@ -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"/>
......
/****************************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Copyright (C) 2014-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jolla.com>
** All rights reserved.
**
......@@ -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;
......
/****************************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Copyright (C) 2014-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jolla.com>
** All rights reserved.
**
......@@ -83,6 +83,7 @@ public:
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;
......
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jollamobile.com>
** All rights reserved.
**
......@@ -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.
*/
......
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2016 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jollamobile.com>
** All rights reserved.
**
......@@ -84,6 +84,7 @@ public:
private:
void cbCancelTransfer(int transferId);
void cbRestartTransfer(int transferId);
void clearTransfer(int transferId);
void clearTransfers();
void enableNotifications(bool enable);
bool notificationsEnabled() const;
......
......@@ -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;
......
......@@ -61,6 +61,8 @@ public:
bool clearFailedTransfers(int excludeKey, TransferEngineData::TransferType type);
bool clearTransfer(int key);
bool clearTransfers();
int transferCount() const;
......
......@@ -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.
......
......@@ -89,6 +89,8 @@ public Q_SLOTS:
void clearTransfers();
void clearTransfer(int transferId);
void cancelTransfer(int transferId);
void enableNotifications(bool enable);
......
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