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
Calendar sync for Facebook, initial work
This commit includes some initial work for importing Facebook events to the calendar. Right now, it uses a database to track the list of events from Facebook and associate them to local mkcal events. Events are currently imported into the default notebook. It should be imported into a specific notebook in future implementations. Even if events cleaning is implemented, calendar do not support running this cleanup, so it is untested.
- Loading branch information
1 parent
914e5a5
commit 7bee99d
Showing
9 changed files
with
601 additions
and
6 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,116 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2013 Jolla Ltd. | ||
** Contact: Chris Adams <chris.adams@jollamobile.com> | ||
** | ||
****************************************************************************/ | ||
|
||
#include "databasemanipulationinterface.h" | ||
#include <QtCore/QDir> | ||
#include <QtCore/QFile> | ||
#include <QtSql/QSqlQuery> | ||
#include <QtSql/QSqlError> | ||
#include <QtSql/QSqlRecord> | ||
#include "trace.h" | ||
#include "syncservice.h" | ||
|
||
DatabaseManipulationInterface::~DatabaseManipulationInterface() | ||
{ | ||
} | ||
|
||
bool DatabaseManipulationInterface::initDatabase(const QString &serviceName, | ||
const QString &dataType, const QString &baseDir, | ||
const QString &dbFile, int userVersion) | ||
{ | ||
if (!QFile::exists(QString(QLatin1String("%1/%2/%3")).arg(baseDir, dataType, dbFile))) { | ||
QDir dir(QString(QLatin1String("%1/%2")).arg(baseDir, dataType)); | ||
if (!dir.exists()) { | ||
dir.mkpath("."); | ||
} | ||
QString absolutePath = dir.absoluteFilePath(dbFile); | ||
QFile dbfile(absolutePath); | ||
if (!dbfile.open(QIODevice::ReadWrite)) { | ||
TRACE(SOCIALD_ERROR, | ||
QString(QLatin1String("error: unable to create database %1 - "\ | ||
"%2 %3 sync will be inactive")).arg(dbFile, serviceName, | ||
dataType)); | ||
return false; | ||
} | ||
dbfile.close(); | ||
} | ||
|
||
QString connectionName | ||
= QString(QLatin1String("sociald/%1/%2")).arg(serviceName, dataType); | ||
|
||
// open the database in which we store our synced image information | ||
db = QSqlDatabase::addDatabase("QSQLITE", connectionName); | ||
db.setDatabaseName(QString("%1/%2/%3").arg(baseDir, dataType, dbFile)); | ||
if (!db.open()) { | ||
TRACE(SOCIALD_ERROR, | ||
QString(QLatin1String("error: unable to open database %1 - "\ | ||
"%2 %3 sync will be inactive")).arg(dbFile, serviceName, | ||
dataType)); | ||
return false; | ||
} | ||
|
||
if (dbUserVersion(serviceName, dataType) < userVersion) { | ||
// DB needs to be recreated | ||
if (!dbDropTables()) { | ||
TRACE(SOCIALD_ERROR, | ||
QString(QLatin1String("error: failed to update database %1 ! "\ | ||
"Remove it manually and restart sociald")).arg(dbFile)); | ||
db.close(); | ||
return false; | ||
} | ||
} | ||
|
||
if (!dbCreateTables()) { | ||
TRACE(SOCIALD_ERROR, | ||
QString(QLatin1String("error: failed to create tables for database %1 ! "\ | ||
"Remove it manually and restart sociald")).arg(dbFile)); | ||
db.close(); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool DatabaseManipulationInterface::createPragmaVersion(const QString &serviceName, | ||
const QString &dataType, int version) | ||
{ | ||
QSqlQuery query (db); | ||
query.prepare(QString(QLatin1String("PRAGMA user_version=%1")).arg(version)); | ||
if (!query.exec()) { | ||
TRACE(SOCIALD_ERROR, | ||
QString(QLatin1String("error: unable to create pragma user_version: - "\ | ||
"%1 %2 sync will be inactive. Error: %3")) | ||
.arg(serviceName, dataType, query.lastError().text())); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
int DatabaseManipulationInterface::dbUserVersion(const QString &serviceName, | ||
const QString &dataType) const | ||
{ | ||
const QString queryStr = QString("PRAGMA user_version"); | ||
|
||
QSqlQuery query(db); | ||
if (!query.exec(queryStr)) { | ||
TRACE(SOCIALD_ERROR, | ||
QString(QLatin1String("error: unable to query db version - "\ | ||
"%1 %2 sync will be inactive. Error: %3")) | ||
.arg(serviceName, dataType, query.lastError().text())); | ||
return -1; | ||
} | ||
QSqlRecord record = query.record(); | ||
if (query.isActive() && query.isSelect()) { | ||
query.first(); | ||
QString value = query.value(record.indexOf("user_version")).toString(); | ||
if (value.isEmpty()) { | ||
return -1; | ||
} | ||
return value.toInt(); | ||
} | ||
return -1; | ||
} |
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,28 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2013 Jolla Ltd. | ||
** Contact: Chris Adams <chris.adams@jollamobile.com> | ||
** | ||
****************************************************************************/ | ||
|
||
#ifndef DATABASEMANIPULATIONINTERFACE_H | ||
#define DATABASEMANIPULATIONINTERFACE_H | ||
|
||
#include <QtSql/QSqlDatabase> | ||
|
||
class DatabaseManipulationInterface | ||
{ | ||
public: | ||
virtual ~DatabaseManipulationInterface(); | ||
protected: | ||
bool initDatabase(const QString &serviceName, const QString &dataType, const QString &baseDir, | ||
const QString &dbFile, int userVersion); | ||
virtual bool dbCreateTables() = 0; | ||
virtual bool dbDropTables() = 0; | ||
bool createPragmaVersion(const QString &serviceName, const QString &dataType, int version); | ||
QSqlDatabase db; | ||
private: | ||
int dbUserVersion(const QString &serviceName, const QString &dataType) const; | ||
}; | ||
|
||
#endif // DATABASEMANIPULATIONINTERFACE_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
Oops, something went wrong.