Skip to content

Commit

Permalink
[sociald] Use central data location for sync databases. Contributes t…
Browse files Browse the repository at this point in the history
…o JB#7975

Previously, the ~/.config/sociald directory was used.  This commit
ensures that the central data location is used instead.  In particular,
the images metadata database (which is used by jolla-gallery-facebook)
is now located under PRIVILEGED_DATA_DIR/Images/facebook.db, and the
contacts metadata database (and avatar images associated with contacts)
is now located under PRIVILEGED_DATA_DIR/Contacts/facebook.db

Contributes to JB#7975
  • Loading branch information
Chris Adams committed Aug 8, 2013
1 parent 00de0e9 commit ab457c7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
15 changes: 8 additions & 7 deletions src/facebook/facebookcontactsyncadaptor.cpp
Expand Up @@ -68,12 +68,13 @@ FacebookContactSyncAdaptor::FacebookContactSyncAdaptor(SyncService *syncService,
return;
}

// we create a database at SOCIALD_DATABASE_DIR/Contacts/facebook.db
if (!QFile::exists(QString("%1/%2/%3")
.arg(QLatin1String(SOCIALD_DATABASE_DIR))
// we create a database at PRIVILEGED_DATA_DIR/Contacts/facebook.db
QString contactSyncDb = QString("%1/%2/%3")
.arg(QLatin1String(PRIVILEGED_DATA_DIR))
.arg(SyncService::dataType(m_dataType))
.arg(QLatin1String("facebook.db")))) {
QDir dir(QString("%1/%2").arg(QLatin1String(SOCIALD_DATABASE_DIR)).arg(SyncService::dataType(m_dataType)));
.arg(QLatin1String("facebook.db"));
if (!QFile::exists(contactSyncDb)) {
QDir dir(QString("%1/%2").arg(QLatin1String(PRIVILEGED_DATA_DIR)).arg(SyncService::dataType(m_dataType)));
if (!dir.exists()) {
dir.mkpath(".");
}
Expand All @@ -90,7 +91,7 @@ FacebookContactSyncAdaptor::FacebookContactSyncAdaptor(SyncService *syncService,

// open the database in which we store our synced friend information
QString connectionName = QString(QLatin1String("sociald/facebook/%1")).arg(SyncService::dataType(m_dataType));
QString databaseName = QString("%1/%2/%3").arg(QLatin1String(SOCIALD_DATABASE_DIR)).arg(SyncService::dataType(m_dataType)).arg(QLatin1String("facebook.db"));
QString databaseName = contactSyncDb;
m_contactSyncDb = QSqlDatabase::addDatabase("QSQLITE", connectionName);
m_contactSyncDb.setDatabaseName(databaseName);
if (!m_contactSyncDb.open()) {
Expand Down Expand Up @@ -792,7 +793,7 @@ void FacebookContactSyncAdaptor::saveImageAndUpdateDatabase(int accountId, const

// save the new image (eg fbfriendid-accid-picture.jpg or fbfriendid-accid-cover.jpg)
QString newName = QString("%1/%2/%3-%4-%5.jpg")
.arg(QLatin1String(SOCIALD_DATABASE_DIR))
.arg(QLatin1String(PRIVILEGED_DATA_DIR))
.arg(SyncService::dataType(m_dataType))
.arg(fbFriendId)
.arg(accountId)
Expand Down
15 changes: 8 additions & 7 deletions src/facebook/facebookimagesyncadaptor.cpp
Expand Up @@ -39,13 +39,14 @@ FacebookImageSyncAdaptor::FacebookImageSyncAdaptor(SyncService *syncService, QOb
{
m_enabled = false;

// we create a database at SOCIALD_DATABASE_DIR/Images/facebook.db
// we create a database at PRIVILEGED_DATA_DIR/Images/facebook.db
// the Jolla Gallery application will open this database for fb album support.
if (!QFile::exists(QString("%1/%2/%3")
.arg(QLatin1String(SOCIALD_DATABASE_DIR))
QString imageSyncDatabaseFile = QString("%1/%2/%3")
.arg(QLatin1String(PRIVILEGED_DATA_DIR))
.arg(SyncService::dataType(m_dataType))
.arg(QLatin1String("facebook.db")))) {
QDir dir(QString("%1/%2").arg(QLatin1String(SOCIALD_DATABASE_DIR)).arg(SyncService::dataType(m_dataType)));
.arg(QLatin1String("facebook.db"));
if (!QFile::exists(imageSyncDatabaseFile)) {
QDir dir(QString("%1/%2").arg(QLatin1String(PRIVILEGED_DATA_DIR)).arg(SyncService::dataType(m_dataType)));
if (!dir.exists()) {
dir.mkpath(".");
}
Expand All @@ -62,11 +63,11 @@ FacebookImageSyncAdaptor::FacebookImageSyncAdaptor(SyncService *syncService, QOb

// open the database in which we store our synced image information
m_imgdb = QSqlDatabase::addDatabase("QSQLITE", QString(QLatin1String("sociald/facebook/%1")).arg(SyncService::dataType(m_dataType)));
m_imgdb.setDatabaseName(QString("%1/%2/%3").arg(QLatin1String(SOCIALD_DATABASE_DIR)).arg(SyncService::dataType(m_dataType)).arg(QLatin1String("facebook.db")));
m_imgdb.setDatabaseName(imageSyncDatabaseFile);
if (!m_imgdb.open()) {
TRACE(SOCIALD_ERROR,
QString(QLatin1String("error: unable to open Facebook image database %1 - Facebook image sync will be inactive"))
.arg(QLatin1String(SOCIALD_DATABASE_NAME)));
.arg(imageSyncDatabaseFile));
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/src.pro
Expand Up @@ -35,9 +35,9 @@ QT += \
include(facebook/facebook.pri)
include(twitter/twitter.pri)

# if you change this, you need to modify jolla-gallery-facebook too!
DEFINES += 'SOCIALD_DATABASE_DIR=\'\"/home/nemo/.config/sociald\"\''
DEFINES += 'SOCIALD_DATABASE_NAME=\'\"sociald.db\"\''
DEFINES += 'PRIVILEGED_DATA_DIR=\'\"/home/nemo/.local/share/data/.privileged/\"\''
DEFINES += 'SYNC_DATABASE_DIR=\'\"Sync\"\''
DEFINES += 'SOCIALD_SYNC_DATABASE_NAME=\'\"sociald.db\"\''

HEADERS += \
$$PWD/buteosocialsync.h \
Expand Down
13 changes: 8 additions & 5 deletions src/syncservice.cpp
Expand Up @@ -26,12 +26,15 @@
SyncServicePrivate::SyncServicePrivate(const QString &connectionName, SyncService *parent)
: QObject(parent), q(parent)
{
if (!QFile::exists(QString("%1/%2").arg(QLatin1String(SOCIALD_DATABASE_DIR)).arg(QLatin1String(SOCIALD_DATABASE_NAME)))) {
QDir dir(SOCIALD_DATABASE_DIR);
QString socialdDatabaseDir = QString("%1/%2")
.arg(QLatin1String(PRIVILEGED_DATA_DIR))
.arg(QLatin1String(SYNC_DATABASE_DIR));
if (!QFile::exists(QString("%1/%2").arg(socialdDatabaseDir).arg(QLatin1String(SOCIALD_SYNC_DATABASE_NAME)))) {
QDir dir(socialdDatabaseDir);
if (!dir.exists()) {
dir.mkpath(".");
}
QString absolutePath = dir.absoluteFilePath(SOCIALD_DATABASE_NAME);
QString absolutePath = dir.absoluteFilePath(SOCIALD_SYNC_DATABASE_NAME);
QFile dbfile(absolutePath);
if (!dbfile.open(QIODevice::ReadWrite)) {
TRACE(SOCIALD_ERROR,
Expand All @@ -44,11 +47,11 @@ SyncServicePrivate::SyncServicePrivate(const QString &connectionName, SyncServic

// open the database in which we store our sync event information
m_db = QSqlDatabase::addDatabase("QSQLITE", connectionName);
m_db.setDatabaseName(QString("%1/%2").arg(QLatin1String(SOCIALD_DATABASE_DIR)).arg(QLatin1String(SOCIALD_DATABASE_NAME)));
m_db.setDatabaseName(QString("%1/%2").arg(socialdDatabaseDir).arg(QLatin1String(SOCIALD_SYNC_DATABASE_NAME)));
if (!m_db.open()) {
TRACE(SOCIALD_ERROR,
QString(QLatin1String("error: unable to open sociald database %1 - sociald will be inactive"))
.arg(QLatin1String(SOCIALD_DATABASE_NAME)));
.arg(QLatin1String(SOCIALD_SYNC_DATABASE_NAME)));
return;
}

Expand Down

0 comments on commit ab457c7

Please sign in to comment.