Commit e80af074 authored by Anupam Basak's avatar Anupam Basak

Implement add/remove account

parent a0ecbc9d
......@@ -20,13 +20,21 @@ Maui.Dialog
id: _syncDialog
onAccepted:
{
control.addAccount(serverField.text, userField.text, passwordField.text);
control.addAccount(serverField.text, userField.text, passwordField.text);
close();
}
}
rejectButton.visible: false
acceptButton.text: qsTr("Add account")
onAccepted: _syncDialog.open()
onAccepted: {
console.log(Maui.App.accounts.requiresAddAccountDialog())
if (Maui.App.accounts.requiresAddAccountDialog()) {
_syncDialog.open()
} else {
control.addAccount("", "", "");
}
}
Maui.BaseModel
{
......@@ -48,8 +56,8 @@ Maui.Dialog
onRejected:
{
var account = Maui.App.accounts.get(_listView.currentIndex)
console.log(account.label)
control.removeAccount(account.server, account.user)
console.log(account)
control.removeAccount(account)
close()
}
......@@ -60,7 +68,7 @@ Maui.Dialog
onClicked:
{
var account = Maui.App.accounts.get(_listView.currentIndex)
control.removeAccountAndFiles(account.server, account.user)
control.removeAccountAndFiles(account)
close()
}
}
......@@ -127,19 +135,21 @@ Maui.Dialog
function addAccount(server, user, password)
{
if(user.length)
if(!Maui.App.accounts.requiresAddAccountDialog()
|| (Maui.App.accounts.requiresAddAccountDialog() && user.length)) {
Maui.App.accounts.registerAccount({server: server, user: user, password: password})
}
}
function removeAccount(server, user)
function removeAccount(account)
{
if(server.length && user.length)
Maui.App.accounts.removeAccount(server, user)
if(account)
Maui.App.accounts.removeAccount(account)
}
function removeAccountAndFiles(server, user)
function removeAccountAndFiles(account)
{
if(server.length && user.length)
Maui.App.accounts.removeAccountAndFiles(server, user)
if(account)
Maui.App.accounts.removeAccountAndFiles(account)
}
}
......@@ -25,6 +25,7 @@
KAccountsProvider::KAccountsProvider(QObject *parent) : AccountsProvider(parent)
{
accountsModel = new OnlineAccounts::AccountServiceModel();
accountHandlesMap = new QMap<QString, QObject *>();
}
FMH::MODEL_LIST KAccountsProvider::getAccounts(QString service, bool includeDisabled)
......@@ -40,8 +41,13 @@ FMH::MODEL_LIST KAccountsProvider::getAccounts(QString service, bool includeDisa
res << FMH::MODEL {
{FMH::MODEL_KEY::ICON, "folder-cloud"},
{FMH::MODEL_KEY::LABEL, accountsModel->get(row, accountsModel->roleNames()[OnlineAccounts::AccountServiceModel::Roles::DisplayNameRole]).toString()},
{FMH::MODEL_KEY::ACCOUNT, accountsModel->get(row, accountsModel->roleNames()[OnlineAccounts::AccountServiceModel::Roles::AccountHandleRole]).toString()}
{FMH::MODEL_KEY::ID, accountsModel->get(row, accountsModel->roleNames()[OnlineAccounts::AccountServiceModel::Roles::AccountIdRole]).toString()}
};
accountHandlesMap->insert(
accountsModel->get(row, accountsModel->roleNames()[OnlineAccounts::AccountServiceModel::Roles::AccountIdRole]).toString(),
qvariant_cast<QObject*>(accountsModel->get(row, accountsModel->roleNames()[OnlineAccounts::AccountServiceModel::Roles::AccountHandleRole]))
);
}
return res;
......@@ -49,20 +55,26 @@ FMH::MODEL_LIST KAccountsProvider::getAccounts(QString service, bool includeDisa
bool KAccountsProvider::addAccount(const QString& server, const QString& user, const QString& password)
{
return false;
Q_UNUSED(server)
Q_UNUSED(user)
Q_UNUSED(password)
// NOTE : The system() call is not made in another thread and is intentionally blocking UI
// because the running application should wait until the account is added to system.
system("kcmshell5 kcm_kaccounts");
return true;
}
bool KAccountsProvider::removeAccount(FMH::MODEL account)
{
OnlineAccounts::Account _account;
// FIXME : This setObjectHandle requires the objectHandle which is of type QObject*
// Since FMH::MODEL doesn't support QObject *, accounts cannot be removed yet
// See line 43, the data needs to be stored as an QObject.
//_account.setObjectHandle(account[FMH::MODEL_KEY::ACCOUNT]);
_account.setObjectHandle(accountHandlesMap->value(account[FMH::MODEL_KEY::ID]));
_account.remove();
return false;
emit this->accountRemoved(FMH::toMap(account));
return true;
}
......@@ -42,6 +42,7 @@ public:
private:
OnlineAccounts::AccountServiceModel *accountsModel;
QMap<QString, QObject*> *accountHandlesMap;
};
#endif
......
......@@ -116,7 +116,16 @@ uint MauiAccounts::getCount() const
void MauiAccounts::refresh()
{
this->setAccounts();
this->setAccounts();
}
bool MauiAccounts::requiresAddAccountDialog()
{
if (dynamic_cast<KAccountsProvider*>(this->provider)) {
return false;
} else {
return true;
}
}
void MauiAccounts::removeAccount(const int& index)
......
......@@ -67,6 +67,8 @@ public slots:
void removeAccount(const int &index);
void removeAccountAndFiles(const int &index);
void refresh();
bool requiresAddAccountDialog();
private:
static MauiAccounts *m_instance;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment