Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[buteo-sync-plugins-social] Fetch backup configuration from sync prof…
…ile. Contributes to JB#47080 Do this instead of fetching config values from dconf.
- Loading branch information
Bea Lam
committed
Oct 8, 2019
1 parent
ef91cc8
commit 74ce619
Showing
11 changed files
with
347 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/**************************************************************************** | ||
** | ||
** 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/**************************************************************************** | ||
** | ||
** 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.