Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into 'master'
Progress support on notifications

See merge request !4
  • Loading branch information
pvuorela committed Jan 17, 2018
2 parents ec3b91c + 2cf8a6d commit ff6c5eb
Show file tree
Hide file tree
Showing 17 changed files with 264 additions and 151 deletions.
6 changes: 0 additions & 6 deletions data/data.pro

This file was deleted.

3 changes: 0 additions & 3 deletions data/notificationcategories/x-nemo.transfer.complete.conf

This file was deleted.

4 changes: 0 additions & 4 deletions data/notificationcategories/x-nemo.transfer.conf

This file was deleted.

2 changes: 0 additions & 2 deletions data/notificationcategories/x-nemo.transfer.error.conf

This file was deleted.

Whitespace-only changes.
14 changes: 7 additions & 7 deletions doc/src/index.qdoc
Expand Up @@ -63,10 +63,10 @@ share functionality implementation depends on the client e.g. if it's HW specifi
such as Facebook. Each plugin must implement or use the following interface:

\list
\o \l {TransferPluginInterface} Share plugin must implement this interface
\o \l {MediaTransferInterface} Share plugin must implement this interface
\o \l {TransferPluginInfo} Share plugin must provide information about plugin using this class
\o \l {TransferMethodInfo} Share plugin must provide information about e.g. accounts using this class
\li \l {TransferPluginInterface} Share plugin must implement this interface
\li \l {MediaTransferInterface} Share plugin must implement this interface
\li \l {TransferPluginInfo} Share plugin must provide information about plugin using this class
\li \l {TransferMethodInfo} Share plugin must provide information about e.g. accounts using this class
\endlist

\section3 Client API
Expand All @@ -77,14 +77,14 @@ example Transfer UI and client side sharing interface on top of it. The Transfer
be used by clients who want to inform Nemo Transfer Engine of ongoing Sync or Downloads.

\list
\o DBus API - see org.nemomobile.transferengine.xml. For the client side it will generate TransferEngineInterface
\li DBus API - see org.nemomobile.transferengine.xml. For the client side it will generate TransferEngineInterface
class which can be used directly.
\o TransferEngineClient - The convenience API to create Sync and Download events.
\li TransferEngineClient - The convenience API to create Sync and Download events.
\endlist

\section3 Reference
\list
\o \l {Nemo Transfer Engine Reference}
\li \l {Nemo Transfer Engine Reference}
\endlist

*/
6 changes: 3 additions & 3 deletions doc/src/mediaplugininterface.qdoc
Expand Up @@ -41,9 +41,9 @@
TransferEngine supports C++ share plugins. Each share plugin must implement couple of well defined interfaces:

\list
\o \l TransferPluginInterface Provides interfaces to access required objects to start sharing.
\o \l MediaTransferInterface Implements the actual sharing functionality
\o \l TransferPluginInfo Provides information about plugin status such as is it ready.
\li \l TransferPluginInterface Provides interfaces to access required objects to start sharing.
\li \l MediaTransferInterface Implements the actual sharing functionality
\li \l TransferPluginInfo Provides information about plugin status such as is it ready.
\endlist

TransferPluginInterface provides information to the TransferEngine via this interface.
Expand Down
6 changes: 3 additions & 3 deletions lib/imageoperation.cpp
Expand Up @@ -38,9 +38,9 @@
This class is meant to be used by share plugins. It can be used for:
\list
\o Removing image metadata
\o Scaling image
\o Create a temp files from the image paths
\li Removing image metadata
\li Scaling image
\li Create a temp files from the image paths
\endlist
*/

Expand Down
8 changes: 4 additions & 4 deletions lib/mediatransferinterface.cpp
Expand Up @@ -60,10 +60,10 @@ class MediaTransferInterfacePrivate
each share plugin. The subclass of this class is resposible of providing:
\list
\o Status information of the sharing
\o Progress of the sharing
\o Information, if cancel and restart actions are supported
\o Starting and/or canceling the sharing
\li Status information of the sharing
\li Progress of the sharing
\li Information, if cancel and restart actions are supported
\li Starting and/or canceling the sharing
\endlist
Expand Down
1 change: 0 additions & 1 deletion lib/mediatransferinterface.h
Expand Up @@ -53,7 +53,6 @@ class MediaTransferInterface: public QObject

MediaItem *mediaItem();


virtual QString displayName() const = 0;
virtual QUrl serviceIcon() const = 0;
virtual bool cancelEnabled() const = 0;
Expand Down
2 changes: 0 additions & 2 deletions lib/transferdbrecord.h
Expand Up @@ -32,9 +32,7 @@

class TransferDBRecord
{

public:

enum TransferDBRecordField {
TransferID = 0,
TransferType,
Expand Down
24 changes: 12 additions & 12 deletions lib/transferengineclient.cpp
Expand Up @@ -78,11 +78,11 @@ CallbackInterface::CallbackInterface()
Construct CallbackInterface instance to provide callback information to the TransferEngineClient. Setup
arguments as:
\list
\o \a server e.g. "com.jolla.myapp"
\o \a path e.g. "/com/jolla/myapp"
\o \a interface e.g. "com.jolla.myapp"
\o \a cancelMethod Cancel method name e.g. "cancelSync"
\o \a restartMethod Restart method name e.g. "restartSync"
\li \a server e.g. "com.jolla.myapp"
\li \a path e.g. "/com/jolla/myapp"
\li \a interface e.g. "com.jolla.myapp"
\li \a cancelMethod Cancel method name e.g. "cancelSync"
\li \a restartMethod Restart method name e.g. "restartSync"
\endlist
*/
CallbackInterface::CallbackInterface(const QString &server, const QString &path, const QString &interface,
Expand Down Expand Up @@ -222,9 +222,9 @@ TransferEngineClient::~TransferEngineClient()
Create a download event to the TransferEngine. This only creates and entry, and client
needs still call:
\list
\o \l TransferEngineClient::startTransfer()
\o \l TransferEngineClient::updateTransferProgress()
\o \l TransferEngineClient::finishTransfer()
\li \l TransferEngineClient::startTransfer()
\li \l TransferEngineClient::updateTransferProgress()
\li \l TransferEngineClient::finishTransfer()
\endlist
\sa createSyncEvent(), startTransfer(), updateTransferProgress(), finishTransfer()
Expand Down Expand Up @@ -325,9 +325,9 @@ void TransferEngineClient::updateTransferProgress(int transferId, qreal progress
Finalize the transfer with \a transferId. There are three options for finalizing the transfer by setting
the \a status parameter value:
\list
\o \l TransferEngineClient::TransferFinished - success
\o \l TransferEngineClient::TransferCanceled - user cancelation
\o \l TransferEngineClient::TransferInterrupted - an error
\li \l TransferEngineClient::TransferFinished - success
\li \l TransferEngineClient::TransferCanceled - user cancelation
\li \l TransferEngineClient::TransferInterrupted - an error
\endlist
If the client wants to provide reason for finishing the transfer, it's possible to provide \a reason
Expand Down Expand Up @@ -388,7 +388,7 @@ void TransferEngineClient::enableNotifications(bool enable)
/*!
Private method for QML interface.
\returns true if notifications are enabled, otherwise false is returned.
Returns true if notifications are enabled, otherwise false is returned.
*/
bool TransferEngineClient::notificationsEnabled() const
{
Expand Down
Empty file modified lib/transfermethodinfo.cpp
Whitespace-only changes.
1 change: 0 additions & 1 deletion rpm/transfer-engine-qt5.spec
Expand Up @@ -36,7 +36,6 @@ Obsoletes: nemo-transferengine <= 0.0.19
%{_bindir}/nemo-transfer-engine
%{_datadir}/dbus-1/services/org.nemo.transferengine.service
%{_datadir}/translations/nemo-transfer-engine_eng_en.qm
%{_datadir}/lipstick/notificationcategories/*

%package -n libnemotransferengine-qt5
Summary: Transfer engine library.
Expand Down
121 changes: 101 additions & 20 deletions src/dbmanager.cpp
Expand Up @@ -81,7 +81,8 @@
"strip_metadata INTEGER,\n" \
"scale_percent REAL,\n" \
"cancel_supported INTEGER,\n" \
"restart_supported INTEGER\n" \
"restart_supported INTEGER,\n" \
"notification_id INTEGER\n" \
");\n"

// Cascade trigger i.e. when transfer is removed and it has metadata or callbacks, this
Expand All @@ -95,7 +96,7 @@
"END;\n"

// Update the following version if database schema changes.
#define USER_VERSION 1
#define USER_VERSION 2
#define PRAGMA_USER_VERSION QString("PRAGMA user_version=%1").arg(USER_VERSION)

class DbManagerPrivate {
Expand Down Expand Up @@ -175,7 +176,7 @@ class DbManagerPrivate {

QSqlQuery query;
if (!query.exec(queryStr)) {
qWarning() << "DbManager::callback: Failed to execute SQL query. Couldn't update the progress!"
qWarning() << "DbManager::callback: Failed to execute SQL query for user_version."
<< query.lastError().text() << ": "
<< query.lastError().databaseText();
return -1;
Expand Down Expand Up @@ -247,6 +248,23 @@ DbManager::DbManager():
}
} else {
// Database exists, check the schema version
if (d->userVersion() == 1) {
// For this we get away with DeclarativeTransferModel directly reading database without
// update because notification_id is the last column
QSqlQuery query;
if (query.exec("ALTER TABLE transfers ADD COLUMN notification_id INTEGER")) {
qWarning() << "Extended transfers table";

if (!query.exec(PRAGMA_USER_VERSION)) {
qWarning() << "DbManager pragma user_version update:"
<< query.lastError().text() << ":" << query.lastError().databaseText();
}
} else {
qWarning() << "Failed to extend transfers table!"
<< query.lastError().text() << ":" << query.lastError().databaseText();
}
}

if (d->userVersion() != USER_VERSION) {
d->deleteOldTables();
d->createDatabaseSchema();
Expand Down Expand Up @@ -277,11 +295,11 @@ DbManager::~DbManager()
In a case there is a DBus callback, then QStringList contains the following items:
\list
\o service
\o path
\o interface
\o cancel method name
\o restart method name
\li service
\li path
\li interface
\li cancel method name
\li restart method name
\endlist
*/
QStringList DbManager::callback(int key) const
Expand All @@ -292,7 +310,7 @@ QStringList DbManager::callback(int key) const
QStringList result;
QSqlQuery query;
if (!query.exec(queryStr)) {
qWarning() << "DbManager::callback: Failed to execute SQL query. Couldn't update the progress!"
qWarning() << "DbManager::callback: Failed to execute SQL query. Couldn't get callback!"
<< query.lastError().text() << ": "
<< query.lastError().databaseText();
return result;
Expand Down Expand Up @@ -349,11 +367,11 @@ int DbManager::createMetadataEntry(int key, const QString &title, const QString
The callback is a dbus interface so it must contain the following attributes:
\list
\o \a service e.g. com.jolla.myapp
\o \a path e.g. /com/jolla/myapp
\o \a interface e.g. com.jolla.myapp
\o \a cancelMethod The name of the cancel method
\o \a restartMethod The name of the restart method
\li \a service e.g. com.jolla.myapp
\li \a path e.g. /com/jolla/myapp
\li \a interface e.g. com.jolla.myapp
\li \a cancelMethod The name of the cancel method
\li \a restartMethod The name of the restart method
\endlist
This method returns a key of the created callback record in a callback table or -1 on
Expand Down Expand Up @@ -408,9 +426,11 @@ int DbManager::createTransferEntry(const MediaItem *mediaItem)
Q_D(DbManager);
QSqlQuery query;
query.prepare("INSERT INTO transfers (transfer_type, timestamp, status, progress, display_name, application_icon, thumbnail_icon, "
"service_icon, url, resource_name, mime_type, file_size, plugin_id, account_id, strip_metadata, scale_percent, cancel_supported, restart_supported)"
"VALUES (:transfer_type, :timestamp, :status, :progress, :display_name, :application_icon, :thumbnail_icon, :service_icon, "
":url, :resource_name, :mime_type, :file_size, :plugin_id, :account_id, :strip_metadata, :scale_percent, :cancel_supported, :restart_supported)");
" service_icon, url, resource_name, mime_type, file_size, plugin_id, account_id, strip_metadata, scale_percent, "
" cancel_supported, restart_supported, notification_id)"
"VALUES (:transfer_type, :timestamp, :status, :progress, :display_name, :application_icon, :thumbnail_icon, "
" :service_icon, :url, :resource_name, :mime_type, :file_size, :plugin_id, :account_id, :strip_metadata, :scale_percent, "
" :cancel_supported, :restart_supported, :notification_id)");
query.bindValue(":transfer_type", mediaItem->value(MediaItem::TransferType));
query.bindValue(":status", TransferEngineData::NotStarted);
query.bindValue(":timestamp", d->currentDateTime());
Expand All @@ -429,9 +449,10 @@ int DbManager::createTransferEntry(const MediaItem *mediaItem)
query.bindValue(":scale_percent", mediaItem->value(MediaItem::ScalePercent));
query.bindValue(":cancel_supported", mediaItem->value(MediaItem::CancelSupported));
query.bindValue(":restart_supported", mediaItem->value(MediaItem::RestartSupported));
query.bindValue(":notification_id", 0);

if (!query.exec()) {
qWarning() << "DbManager::createTransfereEntry: Failed to execute SQL query. Couldn't create an entry!"
qWarning() << "DbManager::createTransferEntry: Failed to execute SQL query. Couldn't create an entry!"
<< query.lastError().text() << ": "
<< query.lastError().databaseText();
return -1;
Expand Down Expand Up @@ -730,7 +751,7 @@ TransferEngineData::TransferType DbManager::transferType(int key) const

QSqlQuery query;
if (!query.exec(queryStr)) {
qWarning() << "DbManager::transferType: Failed to execute SQL query. Couldn't update the progress!"
qWarning() << "DbManager::transferType: Failed to execute SQL query. Couldn't get transfer type!"
<< query.lastError().text() << ": "
<< query.lastError().databaseText();
return TransferEngineData::Undefined;
Expand All @@ -757,7 +778,7 @@ TransferEngineData::TransferStatus DbManager::transferStatus(int key) const

QSqlQuery query;
if (!query.exec(queryStr)) {
qWarning() << "DbManager::transferStatus: Failed to execute SQL query. Couldn't update the progress!"
qWarning() << "DbManager::transferStatus: Failed to execute SQL query. Couldn't get transfer status!"
<< query.lastError().text() << ": "
<< query.lastError().databaseText();
return TransferEngineData::Unknown;
Expand All @@ -771,6 +792,66 @@ TransferEngineData::TransferStatus DbManager::transferStatus(int key) const
return TransferEngineData::Unknown;
}
}

/*!
Returns the transfer progress or -1 if unavailable
*/
qreal DbManager::transferProgress(int key) const
{
QString queryStr = QString("SELECT progress FROM transfers WHERE transfer_id='%1';").arg(QString::number(key));

QSqlQuery query;
if (!query.exec(queryStr)) {
qWarning() << "DbManager::transferStatus: Failed to execute SQL query. Couldn't get the progress!"
<< query.lastError().text() << ": "
<< query.lastError().databaseText();
return -1;
}

if (query.isActive() && query.isSelect()) {
query.first();
return static_cast<qreal>(query.value(0).toReal());
} else {
return -1;
}
}

int DbManager::notificationId(int key)
{
QString queryStr = QString("SELECT notification_id FROM transfers WHERE transfer_id='%1';").arg(QString::number(key));

QSqlQuery query;
if (!query.exec(queryStr)) {
qWarning() << "DbManager::transferStatus: Failed to execute SQL query. Couldn't get the notification id!"
<< query.lastError().text() << ": "
<< query.lastError().databaseText();
return 0;
}

if (query.isActive() && query.isSelect()) {
query.first();
return static_cast<qreal>(query.value(0).toReal());
} else {
return 0;
}
}

bool DbManager::setNotificationId(int key, int notificationId)
{
QString queryStr = QString("UPDATE transfers SET notification_id='%1' WHERE transfer_id='%2';")
.arg(QString::number(notificationId)).arg(QString::number(key));

QSqlQuery query;
if (!query.exec(queryStr)) {
qWarning() << "Failed to execute SQL query. Couldn't update the notification id!"
<< query.lastError().text() << ": "
<< query.lastError().databaseText();
return false;
}
query.finish();
return true;
}

/*!
Reads the callback method names from the database for the transfer with \a key. The method names are set to the
output arguments \a cancelMethod and \a restartMethod.
Expand Down
5 changes: 5 additions & 0 deletions src/dbmanager.h
Expand Up @@ -77,6 +77,11 @@ class DbManager

TransferEngineData::TransferStatus transferStatus(int key) const;

qreal transferProgress(int key) const;

int notificationId(int key);
bool setNotificationId(int key, int notificationId);

bool callbackMethods(int key, QString &cancelMethod, QString &restartMethod) const;

MediaItem * mediaItem(int key) const;
Expand Down

0 comments on commit ff6c5eb

Please sign in to comment.