-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings.cpp
64 lines (56 loc) · 1.76 KB
/
settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "settings.h"
Settings* Settings::m_instance = NULL;
Settings::Settings(QObject *parent) :
QObject(parent)
{
QDir notesdir("/home/user/MyDocs/.evernote/notes");
if (!notesdir.exists()) {
notesdir.mkpath(notesdir.absolutePath());
}
}
Settings* Settings::instance(){
if(!m_instance){
m_instance = new Settings();
}
return m_instance;
}
void Settings::drop(){
if(m_instance){
delete m_instance;
m_instance = 0;
}
}
Settings::~Settings() {
}
void Settings::setPassword(const QString &password){
DatabaseManager::instance()->makeSetting(SettingsKeys::PASSWORD, password);
}
QString Settings::getPassword(){
return DatabaseManager::instance()->getSetting(SettingsKeys::PASSWORD);
}
void Settings::setUsername(const QString &username){
DatabaseManager::instance()->makeSetting(SettingsKeys::USERNAME, username);
}
QString Settings::getUsername(){
return DatabaseManager::instance()->getSetting(SettingsKeys::USERNAME);
}
bool Settings::areCredentialsSaved(){
QString username = getUsername();
QString password = getPassword();
qDebug() << "Creds saved: " << (!username.isEmpty() && !password.isEmpty());
return !username.isEmpty() && !password.isEmpty();
}
void Settings::setAuthToken(const QString &token){
DatabaseManager::instance()->makeSetting(SettingsKeys::AUTH_TOKEN, token);
}
QString Settings::getAuthToken(){
return DatabaseManager::instance()->getSetting(SettingsKeys::AUTH_TOKEN);
}
void Settings::setUser(User user){
DatabaseManager::instance()->makeSetting(SettingsKeys::USER_SHARDID, user.shardId.c_str());
}
User Settings::getUser(){
User user;
user.shardId = DatabaseManager::instance()->getSetting(SettingsKeys::USER_SHARDID).toStdString();
return user;
}