-
Notifications
You must be signed in to change notification settings - Fork 0
/
accountsmodel.cpp
73 lines (63 loc) · 2.4 KB
/
accountsmodel.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
64
65
66
67
68
69
70
71
72
73
#include "accountsmodel.h"
#include <QDebug>
AccountsModel::AccountsModel(QObject *parent) :
QAbstractListModel(parent),
m_accountsManager(new Accounts::Manager())
{
foreach(Accounts::AccountId id, m_accountsManager.accountListEnabled("e-mail")) {
Accounts::Account *account = m_accountsManager.account(id);
if (account->providerName() == "google") {
m_accountsList.append(account);
}
}
}
QVariant AccountsModel::data(const QModelIndex &index, int role) const
{
if (index.row() >= rowCount())
return QVariant();
switch (role) {
case Qt::DisplayRole:
return m_accountsList.at(index.row())->displayName();
}
}
int AccountsModel::rowCount(const QModelIndex &parent) const
{
return m_accountsList.count();
}
void AccountsModel::gotInfo (const SignOn::IdentityInfo &info)
{
foreach(SignOn::MethodName name, info.methods()) {
qDebug() << info.mechanisms(name);
}
}
void AccountsModel::response (const SignOn::SessionData &sessionData)
{
emit loggedIn(sessionData.getProperty("Auth").toByteArray());
}
void AccountsModel::performLogin(int accountIndex)
{
if (accountIndex >= rowCount())
return;
Accounts::Account *account = m_accountsList.at(accountIndex);
SignOn::Identity *identity = SignOn::Identity::existingIdentity(account->valueAsInt("CredentialsId"));
SignOn::AuthSessionP session = identity->createSession("google");
connect(session, SIGNAL(response(SignOn::SessionData)), SLOT(response (SignOn::SessionData)));
QVariantMap parameters;
parameters["service"] = "writely";
parameters["source"] = "Calligrav2";
qDebug() << "Logging in " << parameters;
m_lastUsedIndex = accountIndex;
session->request(SignOn::SessionData(parameters), "ClientLogin");
}
void AccountsModel::performLoginAgain(const QString &service)
{
Accounts::Account *account = m_accountsList.at(m_lastUsedIndex);
SignOn::Identity *identity = SignOn::Identity::existingIdentity(account->valueAsInt("CredentialsId"));
SignOn::AuthSessionP session = identity->createSession("google");
connect(session, SIGNAL(response(SignOn::SessionData)), SLOT(response (SignOn::SessionData)));
QVariantMap parameters;
parameters["service"] = service;
parameters["source"] = "Calligrav2";
qDebug() << "Logging in " << parameters;
session->request(SignOn::SessionData(parameters), "ClientLogin");
}