-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnome_keychain.cpp
60 lines (49 loc) · 1.47 KB
/
gnome_keychain.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
#include "config.h"
#include "gnome_keychain.h"
#include <glib.h>
const QString GnomeKeychain::kImplementationName = "Gnome Keyring";
const GnomeKeyringPasswordSchema GnomeKeychain::kOurSchema = {
GNOME_KEYRING_ITEM_GENERIC_SECRET,
{
{ "username", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ "service", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ NULL },
},
};
bool GnomeKeychain::isAvailable() {
return gnome_keyring_is_available();
}
const QString GnomeKeychain::getPassword(const QString& account) {
Q_ASSERT(isAvailable());
char* password;
GnomeKeyringResult result = gnome_keyring_find_password_sync(
&kOurSchema,
&password,
"username", account.toStdString().c_str(),
"service", kServiceName.toStdString().c_str(),
NULL);
if (result == GNOME_KEYRING_RESULT_OK) {
QString pass(password);
gnome_keyring_free_password(password);
return pass;
}
return QString::null;
}
bool GnomeKeychain::setPassword(const QString& account, const QString& password) {
Q_ASSERT(isAvailable());
QString displayName = "%1 Google Reader account for %2";
displayName.arg(TITLE);
displayName.arg(account);
GnomeKeyringResult result = gnome_keyring_store_password_sync(
&kOurSchema,
NULL,
displayName.toStdString().c_str(),
password.toStdString().c_str(),
"username", account.toStdString().c_str(),
"service", kServiceName.toStdString().c_str(),
NULL);
return result == GNOME_KEYRING_RESULT_OK;
}
void GnomeKeychain::init() {
g_set_application_name("PurpleHatstands");
}