Skip to content

Commit

Permalink
Allow to create private transfers
Browse files Browse the repository at this point in the history
Private transfers are still kept in the database, but don't appear in the Transfers list
  • Loading branch information
ilpianista committed Mar 28, 2024
1 parent 25a9d2d commit c7bc98b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions dbus/org.nemo.transferengine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<arg direction="in" type="as" name="callback"/>
<arg direction="in" type="s" name="cancelMethod"/>
<arg direction="in" type="s" name="restartMethod"/>
<arg direction="in" type="b" name="privateTransfer"/>
<arg direction="out" type="i" name="transferId"/>
</method>

Expand Down
2 changes: 1 addition & 1 deletion declarative/declarativetransfermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ bool TransferModel::executeQuery(QVector<TransferDBRecord> *rows, int *activeTra
QSqlQuery query(db);
query.setForwardOnly(true);

if (!query.exec(QString(QStringLiteral("SELECT * FROM transfers ORDER BY transfer_id DESC")))) {
if (!query.exec(QString(QStringLiteral("SELECT * FROM transfers WHERE private=0 ORDER BY transfer_id DESC")))) {
qWarning() << Q_FUNC_INFO;
qWarning() << "Failed to create tmp table";
qWarning() << query.lastQuery();
Expand Down
3 changes: 2 additions & 1 deletion lib/mediaitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class MediaItemPrivate
\value Description Description for the media item to be transfered
\value ServiceIcon Service icon URL e.g. email service
\value ApplicationIcon Application icon url
\value AccountId, Account Id
\value AccountId Account Id
\value UserData User specific data that is passed from the UI
\value Private Do not save transfer data
\value Callback Callback service, path, interface packed to QStringList
\value CancelCBMethod Cancel callback method name
\value RestartCBMethod Restart callback method name
Expand Down
1 change: 1 addition & 0 deletions lib/mediaitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class MediaItem: public QObject
ThumbnailIcon,
AccountId,
UserData,
Private,

// Callback methods comes from the API, not from the plugins
Callback,
Expand Down
4 changes: 3 additions & 1 deletion lib/transferengineclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ int TransferEngineClient::createDownloadEvent(const QString &displayName,
const QUrl &url,
const QString &mimeType,
qlonglong expectedFileSize,
const bool privateTransfer,
const CallbackInterface &callback)
{
Q_D(const TransferEngineClient);
Expand All @@ -241,7 +242,8 @@ int TransferEngineClient::createDownloadEvent(const QString &displayName,
expectedFileSize,
callback.d_func()->callback,
callback.d_func()->m_cancelMethod,
callback.d_func()->m_restartMethod);
callback.d_func()->m_restartMethod,
privateTransfer);
reply.waitForFinished();

if (reply.isError()) {
Expand Down
1 change: 1 addition & 0 deletions lib/transferengineclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class TransferEngineClient : public QObject
const QUrl &url,
const QString &mimeType,
qlonglong expectedFileSize,
const bool privateTransfer,
const CallbackInterface &callback = CallbackInterface());


Expand Down
29 changes: 24 additions & 5 deletions src/dbmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"cancel_supported INTEGER,\n" \
"restart_supported INTEGER,\n" \
"notification_id INTEGER\n" \
"private INTEGER\n" \
");\n"

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

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

class DbManagerPrivate {
Expand Down Expand Up @@ -263,6 +264,23 @@ DbManager::DbManager():
}
}

if (d->userVersion() == 2) {
// For this we get away with DeclarativeTransferModel directly reading database without
// update because private is the last column
QSqlQuery query;
if (query.exec("ALTER TABLE transfers ADD COLUMN private INTEGER")) {
qWarning() << "Extended transfers table for private column";

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 for private column!"
<< query.lastError().text() << ":" << query.lastError().databaseText();
}
}

if (d->userVersion() != USER_VERSION) {
d->deleteOldTables();
d->createDatabaseSchema();
Expand Down Expand Up @@ -425,10 +443,10 @@ int DbManager::createTransferEntry(const MediaItem *mediaItem)
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, notification_id)"
" cancel_supported, restart_supported, notification_id, private)"
"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)");
" :cancel_supported, :restart_supported, :notification_id, :private)");
query.bindValue(":transfer_type", mediaItem->value(MediaItem::TransferType));
query.bindValue(":status", TransferEngineData::NotStarted);
query.bindValue(":timestamp", d->currentDateTime());
Expand All @@ -448,6 +466,7 @@ int DbManager::createTransferEntry(const MediaItem *mediaItem)
query.bindValue(":cancel_supported", mediaItem->value(MediaItem::CancelSupported));
query.bindValue(":restart_supported", mediaItem->value(MediaItem::RestartSupported));
query.bindValue(":notification_id", 0);
query.bindValue(":private", mediaItem->value(MediaItem::Private).toBool() ? 1 : 0);

if (!query.exec()) {
qWarning() << "DbManager::createTransferEntry: Failed to execute SQL query. Couldn't create an entry!"
Expand Down Expand Up @@ -702,8 +721,8 @@ QList<TransferDBRecord> DbManager::transfers(TransferEngineData::TransferStatus
// 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);
QString("SELECT * FROM transfers WHERE private=0 ORDER BY transfer_id DESC") :
QString("SELECT * FROM transfers WHERE private=0 AND status='%1' ORDER BY transfer_id DESC").arg(status);
QSqlQuery query;
if (!query.exec(queryStr)) {
qWarning() << "DbManager::transfers: Failed to execute SQL query. Couldn't get list of transfers!";
Expand Down
5 changes: 4 additions & 1 deletion src/transferengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ int TransferEngine::uploadMediaItemContent(const QVariantMap &content,
\li \a callback QStringList containing DBus callback information such as: service, path and interface
\li \a cancelMethod The name of the cancel callback method, which DBus callback provides
\li \a restartMethod The name of the restart callback method, which DBus callback provides
\li \a privateTransfer If true, hide transfer from history
\endlist
This method returns the transfer id of the created Download transfer. Note that this method only
Expand All @@ -862,7 +863,8 @@ int TransferEngine::createDownload(const QString &displayName,
qlonglong expectedFileSize,
const QStringList &callback,
const QString &cancelMethod,
const QString &restartMethod)
const QString &restartMethod,
const bool privateTransfer)
{
Q_D(TransferEngine);
QUrl url = QUrl::fromLocalFile(filePath);
Expand All @@ -877,6 +879,7 @@ int TransferEngine::createDownload(const QString &displayName,
mediaItem->setValue(MediaItem::DisplayName, displayName);
mediaItem->setValue(MediaItem::ApplicationIcon, applicationIcon);
mediaItem->setValue(MediaItem::ServiceIcon, serviceIcon);
mediaItem->setValue(MediaItem::Private, privateTransfer);
mediaItem->setValue(MediaItem::Callback, callback);
mediaItem->setValue(MediaItem::CancelCBMethod, cancelMethod);
mediaItem->setValue(MediaItem::RestartCBMethod, restartMethod);
Expand Down
3 changes: 2 additions & 1 deletion src/transferengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public Q_SLOTS:
qlonglong expectedFileSize,
const QStringList &callback,
const QString &cancelMethod,
const QString &restartMethod);
const QString &restartMethod,
const bool privateTransfer);

int createSync(const QString &displayName,
const QString &applicationIcon,
Expand Down

0 comments on commit c7bc98b

Please sign in to comment.