Commit b23c7826 authored by blam's avatar blam

Merge branch 'jb47080-backuprestore-options' into 'master'

[buteo-sync-plugins-social] Fetch backup configuration from...

See merge request !48
parents c513113a 74ce619a
......@@ -6,6 +6,7 @@ PKGCONFIG += \
accounts-qt5 \
buteosyncfw5 \
socialcache
LIBS += -lssu
QT += \
network \
......@@ -30,12 +31,14 @@ DEFINES += 'SOCIALD_SYNC_DATABASE_NAME=\'\"sociald.db\"\''
INCLUDEPATH += . $$PWD/common/
HEADERS += \
$$PWD/common/backuprestoreoptions_p.h \
$$PWD/common/buteosyncfw_p.h \
$$PWD/common/socialdbuteoplugin.h \
$$PWD/common/socialnetworksyncadaptor.h \
$$PWD/common/trace.h
SOURCES += \
$$PWD/common/backuprestoreoptions.cpp \
$$PWD/common/socialdbuteoplugin.cpp \
$$PWD/common/socialnetworksyncadaptor.cpp
......
/****************************************************************************
**
** Copyright (C) 2019 Open Mobile Platform LLC
**
** This program/library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public License
** version 2.1 as published by the Free Software Foundation.
**
** This program/library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this program/library; if not, write to the Free
** Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
** 02110-1301 USA
**
****************************************************************************/
#include "backuprestoreoptions_p.h"
#include "trace.h"
#include <QtCore/QCryptographicHash>
// nemo
#include <ssudeviceinfo.h>
// buteo-syncfw
#include <SyncProfile.h>
bool BackupRestoreOptions::copyToProfile(Buteo::SyncProfile *syncProfile)
{
if (!syncProfile) {
qWarning() << "Invalid profile!";
return false;
}
Buteo::Profile *clientProfile = syncProfile->clientProfile();
if (!clientProfile) {
qWarning() << "Cannot find client profile in sync profile:" << syncProfile->name();
return false;
}
QString operationValue;
switch (operation) {
case DirectoryListing:
operationValue = "dir-listing";
break;
case Upload:
operationValue = "upload";
break;
case Download:
operationValue = "download";
break;
};
clientProfile->setKey("sfos-operation", operationValue);
clientProfile->setKey("sfos-dir-local", localDirPath);
clientProfile->setKey("sfos-dir-remote", remoteDirPath);
clientProfile->setKey("sfos-filename", fileName);
return true;
}
BackupRestoreOptions BackupRestoreOptions::fromProfile(Buteo::SyncProfile *syncProfile, bool *ok)
{
if (!syncProfile) {
qWarning() << "Invalid sync profile!";
return BackupRestoreOptions();
}
Buteo::Profile *clientProfile = syncProfile->clientProfile();
if (!clientProfile) {
qWarning() << "Cannot find client profile in sync profile:" << syncProfile->name();
return BackupRestoreOptions();
}
BackupRestoreOptions options;
QString operation = clientProfile->key("sfos-operation");
options.localDirPath = clientProfile->key("sfos-dir-local");
options.remoteDirPath = clientProfile->key("sfos-dir-remote");
options.fileName = clientProfile->key("sfos-filename");
if (operation == "dir-listing") {
options.operation = BackupRestoreOptions::DirectoryListing;
} else if (operation == "upload") {
options.operation = BackupRestoreOptions::Upload;
} else if (operation == "download") {
options.operation = BackupRestoreOptions::Download;
} else {
qWarning() << "Backup/restore options for sync profile" << syncProfile->name()
<< "has invalid operation type:" << operation;
return BackupRestoreOptions();
}
if (options.localDirPath.isEmpty()) {
qWarning() << "Backup/restore options for sync profile" << syncProfile->name()
<< "do not specify a local directory!";
return BackupRestoreOptions();
}
if (options.operation == BackupRestoreOptions::DirectoryListing && options.fileName.isEmpty()) {
qWarning() << "Backup/restore options for sync profile" << syncProfile->name()
<< "do not specify a file name for directory listing!";
return BackupRestoreOptions();
}
if (ok) {
*ok = true;
}
return options;
}
QString BackupRestoreOptions::backupDeviceName()
{
SsuDeviceInfo deviceInfo;
const QString deviceId = deviceInfo.deviceUid();
const QByteArray hashedDeviceId = QCryptographicHash::hash(deviceId.toUtf8(), QCryptographicHash::Sha256);
const QString encodedDeviceId = QString::fromUtf8(hashedDeviceId.toBase64(QByteArray::Base64UrlEncoding)).mid(0,12);
if (deviceId.isEmpty()) {
qWarning() << "Could not determine device identifier for backup directory name!";
return QString();
}
QString deviceDisplayNamePrefix = deviceInfo.displayName(Ssu::DeviceModel);
if (!deviceDisplayNamePrefix.isEmpty()) {
deviceDisplayNamePrefix = deviceDisplayNamePrefix.replace(' ', '-') + '_';
}
return deviceDisplayNamePrefix + encodedDeviceId;
}
/****************************************************************************
**
** Copyright (C) 2019 Open Mobile Platform LLC
**
** This program/library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public License
** version 2.1 as published by the Free Software Foundation.
**
** This program/library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this program/library; if not, write to the Free
** Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
** 02110-1301 USA
**
****************************************************************************/
#ifndef BACKUPRESTOREOPTIONS_H
#define BACKUPRESTOREOPTIONS_H
#include <QtCore/QString>
namespace Buteo {
class SyncProfile;
}
// Basically a mirror of AccountSyncManager::BackupRestoreOptions.
class BackupRestoreOptions
{
public:
enum Operation {
DirectoryListing,
Upload,
Download
};
Operation operation = DirectoryListing;
QString localDirPath;
QString remoteDirPath;
QString fileName;
bool copyToProfile(Buteo::SyncProfile *syncProfile);
static BackupRestoreOptions fromProfile(Buteo::SyncProfile *syncProfile, bool *ok);
static QString backupDeviceName();
};
#endif // BACKUPRESTOREOPTIONS_H
CONFIG += link_pkgconfig
PKGCONFIG += mlite5
LIBS += -lssu
SOURCES += $$PWD/dropboxbackupsyncadaptor.cpp
HEADERS += $$PWD/dropboxbackupsyncadaptor.h
INCLUDEPATH += $$PWD
......
/****************************************************************************
**
** Copyright (C) 2015 Jolla Ltd.
** Copyright (C) 2015-2019 Jolla Ltd.
** Copyright (C) 2019 Open Mobile Platform LLC
** Contact: Chris Adams <chris.adams@jolla.com>
**
** This program/library is free software; you can redistribute it and/or
......@@ -50,5 +51,5 @@ DropboxBackupPlugin::~DropboxBackupPlugin()
SocialNetworkSyncAdaptor *DropboxBackupPlugin::createSocialNetworkSyncAdaptor()
{
return new DropboxBackupSyncAdaptor(this);
return new DropboxBackupSyncAdaptor(profile().name(), this);
}
/****************************************************************************
**
** Copyright (C) 2015 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jollamobile.com>
** Copyright (C) 2015-2019 Jolla Ltd.
** Copyright (C) 2019 Open Mobile Platform LLC
**
** This program/library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public License
......@@ -23,6 +23,7 @@
#define DROPBOXBACKUPSYNCADAPTOR_H
#include "dropboxdatatypesyncadaptor.h"
#include "backuprestoreoptions_p.h"
#include <QtCore/QObject>
#include <QtCore/QString>
......@@ -35,12 +36,16 @@
#include <QtNetwork/QSslError>
#include <QtSql/QSqlDatabase>
namespace Buteo {
class ProfileManager;
}
class DropboxBackupSyncAdaptor : public DropboxDataTypeSyncAdaptor
{
Q_OBJECT
public:
DropboxBackupSyncAdaptor(QObject *parent);
DropboxBackupSyncAdaptor(const QString &profileName, QObject *parent);
~DropboxBackupSyncAdaptor();
QString syncServiceName() const;
......@@ -55,7 +60,7 @@ protected: // implementing DropboxDataTypeSyncAdaptor interface
private:
void requestList(int accountId,
const QString &accessToken,
const QString &operationType,
int operationType,
const QString &remotePath,
const QString &continuationCursor,
const QVariantMap &extraProperties);
......@@ -67,8 +72,8 @@ private:
const QString &localFile = QString());
void purgeAccount(int accountId);
void beginListOperation(int accountId, const QString &accessToken, const QString &remotePath);
void beginSyncOperation(int accountId, const QString &accessToken, const QString &remotePath);
void beginListOperation(int accountId, const QString &accessToken, const BackupRestoreOptions &options);
void beginSyncOperation(int accountId, const QString &accessToken, const BackupRestoreOptions &options);
private Q_SLOTS:
void remotePathFinishedHandler();
......@@ -79,7 +84,10 @@ private Q_SLOTS:
void uploadProgressHandler(qint64 bytesSent, qint64 bytesTotal);
private:
Buteo::ProfileManager *m_profileManager;
QSet<QString> m_backupFiles;
QString m_profileName;
};
#endif // DROPBOXBACKUPSYNCADAPTOR_H
CONFIG += link_pkgconfig
PKGCONFIG += mlite5
LIBS += -lssu
SOURCES += $$PWD/onedrivebackupsyncadaptor.cpp
HEADERS += $$PWD/onedrivebackupsyncadaptor.h
INCLUDEPATH += $$PWD
......
/****************************************************************************
**
** Copyright (C) 2015 Jolla Ltd.
** Copyright (C) 2015-2019 Jolla Ltd.
** Copyright (C) 2019 Open Mobile Platform LLC
** Contact: Chris Adams <chris.adams@jolla.com>
**
** This program/library is free software; you can redistribute it and/or
......@@ -50,5 +51,5 @@ OneDriveBackupPlugin::~OneDriveBackupPlugin()
SocialNetworkSyncAdaptor *OneDriveBackupPlugin::createSocialNetworkSyncAdaptor()
{
return new OneDriveBackupSyncAdaptor(this);
return new OneDriveBackupSyncAdaptor(profile().name(), this);
}
/****************************************************************************
**
** Copyright (C) 2015 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jollamobile.com>
** Copyright (C) 2015-2019 Jolla Ltd.
** Copyright (C) 2019 Open Mobile Platform LLC
**
** This program/library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public License
......@@ -23,6 +23,7 @@
#define ONEDRIVEBACKUPSYNCADAPTOR_H
#include "onedrivedatatypesyncadaptor.h"
#include "backuprestoreoptions_p.h"
#include <QtCore/QObject>
#include <QtCore/QString>
......@@ -35,12 +36,16 @@
#include <QtNetwork/QSslError>
#include <QtSql/QSqlDatabase>
namespace Buteo {
class ProfileManager;
}
class OneDriveBackupSyncAdaptor : public OneDriveDataTypeSyncAdaptor
{
Q_OBJECT
public:
OneDriveBackupSyncAdaptor(QObject *parent);
OneDriveBackupSyncAdaptor(const QString &profileName, QObject *parent);
~OneDriveBackupSyncAdaptor();
QString syncServiceName() const;
......@@ -79,10 +84,13 @@ private Q_SLOTS:
void uploadProgressHandler(qint64 bytesSent, qint64 bytesTotal);
private:
void beginListOperation(int accountId, const QString &accessToken, const QString &remotePath);
void beginSyncOperation(int accountId, const QString &accessToken, const QString &remotePath);
void beginListOperation(int accountId, const QString &accessToken, const BackupRestoreOptions &options);
void beginSyncOperation(int accountId, const QString &accessToken, const BackupRestoreOptions &options);
void listOperationFinished();
Buteo::ProfileManager *m_profileManager;
QString m_profileName;
QString m_remoteAppDir;
struct RemoteDirectory {
......
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