19#include "mauiaccounts.h"
20#include "accountsdb.h"
24MauiAccounts::MauiAccounts()
26 , db(new AccountsDB(nullptr))
31MauiAccounts::~MauiAccounts()
33 qDebug() <<
"DELETING MAUI ACCOUNTS INSTANCE";
34 this->db->deleteLater();
43void MauiAccounts::setAccounts()
47 qDebug() <<
"ACCOUNTS LIST" << this->m_data;
55 auto accounts = this->
get(
"select * from cloud");
57 for (
const auto &account : qAsConst(accounts)) {
58 auto map = account.toMap();
62 {FMH::MODEL_KEY::ICON,
"folder-cloud"},
63 {FMH::MODEL_KEY::LABEL, map[
FMH::MODEL_NAME[FMH::MODEL_KEY::USER]].toString()},
64 {FMH::MODEL_KEY::USER, map[
FMH::MODEL_NAME[FMH::MODEL_KEY::USER]].toString()},
65 {FMH::MODEL_KEY::SERVER, map[
FMH::MODEL_NAME[FMH::MODEL_KEY::SERVER]].toString()},
66 {FMH::MODEL_KEY::PASSWORD, map[
FMH::MODEL_NAME[FMH::MODEL_KEY::PASSWORD]].toString()}};
71bool MauiAccounts::addCloudAccount(
const QString &server,
const QString &user,
const QString &password)
75 if (this->db->insert(
"cloud", account)) {
83bool MauiAccounts::removeCloudAccount(
const QString &server,
const QString &user)
86 {FMH::MODEL_KEY::SERVER, server},
87 {FMH::MODEL_KEY::USER, user},
90 if (this->db->remove(
"cloud", account)) {
100 QVariantList mapList;
102 auto query = this->db->getQuery(queryTxt);
107 while (
query.next()) {
109 for (
auto key : keys)
117 qDebug() <<
query.lastError() <<
query.lastQuery();
124 return this->m_currentAccountIndex;
129 return this->m_currentAccount;
137 if (this->addCloudAccount(model[FMH::MODEL_KEY::SERVER], model[FMH::MODEL_KEY::USER], model[FMH::MODEL_KEY::PASSWORD])) {
144 if (index >= this->m_data.size() || index < 0)
147 if (index == this->m_currentAccountIndex)
151 this->m_currentAccountIndex = index;
152 this->m_currentAccount =
FMH::toMap(this->m_data.at(m_currentAccountIndex));
163 for (
const auto &item : data)
176 if (index >= this->m_data.size() || index < 0)
179 if (this->removeCloudAccount(this->m_data.at(index)[FMH::MODEL_KEY::SERVER], this->m_data.at(index)[FMH::MODEL_KEY::USER])) {
186 if (index >= this->m_data.size() || index < 0)
189 if (this->removeCloudAccount(this->m_data.at(index)[FMH::MODEL_KEY::SERVER], this->m_data.at(index)[FMH::MODEL_KEY::USER])) {
MauiAccounts class provides an interface to access the system registered accounts,...
QVariantList getCloudAccountsList()
getCloudAccountsList
void accountRemoved(QVariantMap account)
accountRemoved
FMH::MODEL_LIST getCloudAccounts()
getCloudAccounts
int getCurrentAccountIndex() const
getCurrentAccountIndex
QVariantMap get(const int &index) const
get
QVariantMap getCurrentAccount() const
getCurrentAccount
void removeAccount(const int &index)
removeAccount
void setCurrentAccountIndex(const int &index)
setCurrentAccountIndex
void accountAdded(QVariantMap account)
accountAdded
void currentAccountIndexChanged(int index)
currentAccountIndexChanged
void registerAccount(const QVariantMap &account)
registerAccount
void removeAccountAndFiles(const int &index)
removeAccountAndFiles
void currentAccountChanged(QVariantMap account)
currentAccountChanged
std::optional< QSqlQuery > query(const QString &queryStatement)
QVector< MODEL > MODEL_LIST
static const QHash< MODEL_KEY, QString > MODEL_NAME
QHash< MODEL_KEY, QString > MODEL
const FMH::MODEL toModel(const QVariantMap &map)
const QVariantMap toMap(const MODEL &model)
QList< Key > keys() const const