mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Done settings class
This commit is contained in:
parent
9786786e7f
commit
b1415056cb
@ -20,7 +20,8 @@ Application::Application(int &argc, char **argv) :
|
||||
|
||||
{
|
||||
|
||||
jop::db().initialize("D:/Web/www/joplin/QtClient/data/notes.sqlite");
|
||||
QString dbPath = "D:/Web/www/joplin/QtClient/data/notes.sqlite";
|
||||
jop::db().initialize(dbPath);
|
||||
|
||||
// This is linked to where the QSettings will be saved. In other words,
|
||||
// if these values are changed, the settings will be reset and saved
|
||||
@ -60,16 +61,24 @@ Application::Application(int &argc, char **argv) :
|
||||
|
||||
connect(&api_, SIGNAL(requestDone(const QJsonObject&, const QString&)), this, SLOT(api_requestDone(const QJsonObject&, const QString&)));
|
||||
|
||||
QString sessionId = settings.value("sessionId").toString();
|
||||
|
||||
// Don't store password, store session ID
|
||||
QString clientId = "B6E12222B6E12222";
|
||||
if (!settings.contains("user.email")) {
|
||||
settings.setValue("user.email", "laurent@cozic.net");
|
||||
settings.setValue("user.password", "12345678");
|
||||
}
|
||||
|
||||
QUrlQuery postData;
|
||||
postData.addQueryItem("email", "laurent@cozic.net");
|
||||
postData.addQueryItem("password", "12345678");
|
||||
postData.addQueryItem("client_id", "B6E12222B6E12222");
|
||||
postData.addQueryItem("email", settings.value("user.email").toString());
|
||||
postData.addQueryItem("password", settings.value("user.password").toString());
|
||||
postData.addQueryItem("client_id", clientId);
|
||||
api_.post("sessions", QUrlQuery(), postData, "getSession");
|
||||
}
|
||||
|
||||
void Application::api_requestDone(const QJsonObject& response, const QString& tag) {
|
||||
// TODO: handle errors
|
||||
// Handle expired sessions
|
||||
|
||||
if (tag == "getSession") {
|
||||
QString sessionId = response.value("id").toString();
|
||||
|
@ -23,8 +23,15 @@ QSettings::SettingsMap Setting::settings() {
|
||||
jop::db().execQuery(query);
|
||||
while (query.next()) {
|
||||
QString key = query.value(0).toString();
|
||||
QVariant val = query.value(1);
|
||||
QMetaType::Type type = (QMetaType::Type)query.value(2).toInt();
|
||||
qDebug() << key << type;
|
||||
if (type == QMetaType::Int) {
|
||||
output[key] = QVariant(val.toInt());
|
||||
} else if (type == QMetaType::QString) {
|
||||
output[key] = QVariant(val.toString());
|
||||
} else {
|
||||
qCritical() << "Unsupported setting type" << key << val << type;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@ -3,32 +3,25 @@
|
||||
|
||||
using namespace jop;
|
||||
|
||||
Settings::Settings() : QSettings() {
|
||||
|
||||
}
|
||||
Settings::Settings() : QSettings() {}
|
||||
|
||||
bool readSqlite(QIODevice &device, QSettings::SettingsMap &map) {
|
||||
//qDebug() << "XXXXXXXXXXXX";
|
||||
// map = Setting::settings();
|
||||
qDebug() << "Calling readSqlite";
|
||||
map = Setting::settings();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool writeSqlite(QIODevice &device, const QSettings::SettingsMap &map) {
|
||||
//Setting::setSettings(map);
|
||||
qDebug() << "Calling writeSqlite";
|
||||
// HACK: QSettings requires a readable/writable file to be present
|
||||
// for the custom handler to work. However, we don't need such a
|
||||
// file since we write to the db. So to simulate it, we write once
|
||||
// to that file. Without this, readSqlite in particular will never
|
||||
// get called.
|
||||
device.write("X", 1);
|
||||
Setting::setSettings(map);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Settings::initialize() {
|
||||
// const QSettings::Format SqliteFormat = QSettings::registerFormat("sqlite", &readSqlite, &writeSqlite);
|
||||
// QSettings::setDefaultFormat(SqliteFormat);
|
||||
|
||||
// QSettings settings;
|
||||
// //qDebug() << settings.value("test");
|
||||
// settings.setValue("test", 123456);
|
||||
|
||||
// QSettings s(SqliteFormat, QSettings::UserScope, "MySoft",
|
||||
// "Star Runner");
|
||||
// qDebug() << "IN" << s.value("test") << "test";
|
||||
const QSettings::Format SqliteFormat = QSettings::registerFormat("sqlite", &readSqlite, &writeSqlite);
|
||||
QSettings::setDefaultFormat(SqliteFormat);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user