Commit 6a410c62 authored by Martin Straka's avatar Martin Straka
Browse files

Isds actions based on asynchronous qml input dialogue

parent 6c3e7848
......@@ -34,21 +34,26 @@ import QtQuick.Controls 2.1
Dialog {
id: root
signal finished(string userName,string accountName, string pwd)
signal finished(string isdsAction, string pwdType, string userName, string pwd)
property int minimumInputSize: parent.width / 2
property int maximumInputSize: parent.width / 2
property string dIsdsAction
property string dPwdType
property string dUserName
property string dAccountName
function openInputDialog(userName, accountName, title, text, hidePwd) {
function openInputDialog(isdsAction, pwdType, userName, title, text, placeholderText, hidePwd) {
dIsdsAction = isdsAction
dPwdType = pwdType
dUserName = userName
dAccountName = accountName
root.title = title
roottext.text = text
rootpwd.clear()
rootpwd.placeholderText = title
rootpwd.placeholderText = placeholderText
rootpwd.echoMode = (hidePwd) ? TextInput.Password : TextInput.Normal
if (pwdType == "totp" || pwdType == "hotp") {
rootpwd.inputMethodHints = Qt.ImhDigitsOnly
}
root.open()
}
......@@ -84,5 +89,5 @@ Dialog {
}
} // ColumnLayout
onAccepted: finished(dUserName, dAccountName, rootpwd.text.toString())
onAccepted: finished(dIsdsAction, dPwdType, dUserName, rootpwd.text.toString())
}
......@@ -115,12 +115,12 @@ ApplicationWindow {
InputDialogue {
id: inputDialog
onFinished: {
isds.returnInputDialogText(userName, accountName, pwd)
isds.returnInputDialogText(isdsAction, pwdType, userName, pwd)
}
Connections {
target: isds
onOpenDialogRequest: {
inputDialog.openInputDialog(userName, accountName, title, text, hidePwd)
inputDialog.openInputDialog(isdsAction, pwdType, userName, title, text, placeholderText, hidePwd)
}
}
}
......
......@@ -66,7 +66,13 @@ Component {
MouseArea {
anchors.fill: parent
onClicked: {
isds.getAccountInfo(userName, false)
isds.doIsdsAction("getAccountInfo", userName)
}
}
Connections {
target: isds
onRunGetAccountInfoSig: {
isds.getAccountInfo(userName)
}
}
}
......
......@@ -110,7 +110,7 @@ Component {
anchors.fill: parent
onClicked: {
statusBarText.text = ""
isds.syncAllAccounts(accountModel)
isds.doIsdsAction("syncAllAccounts", "")
}
}
}
......@@ -260,7 +260,15 @@ Component {
MouseArea {
anchors.fill: parent
onClicked: {
isds.syncOneAccount(accountModel, rUserName)
isds.doIsdsAction("syncOneAccount", rUserName)
}
}
Connections {
target: isds
onRunSyncOneAccountSig: {
if (rUserName == userName) {
isds.syncOneAccount(accountModel, userName)
}
}
}
}
......
......@@ -160,7 +160,7 @@ Component {
anchors.fill: parent
onClicked: {
if (index == 0) {
isds.downloadMessage(messageModel, userName, msgType, msgId)
isds.doIsdsAction("downloadMessage", userName)
} else if (index == 1) {
messages.markMessageAsLocallyRead(messageModel, userName, msgId, true)
} else if (index == 2) {
......@@ -186,5 +186,11 @@ Component {
delegate: messageMenuComponent
}
}
Connections {
target: isds
onRunDownloadMessageSig: {
isds.downloadMessage(messageModel, userName, msgType, msgId)
}
}
}
}
......@@ -151,7 +151,7 @@ Component {
anchors.fill: parent
onClicked: {
if (index == 0) {
isds.downloadMessage(messageModel, userName, msgType, msgId)
isds.doIsdsAction("downloadMessage", userName)
} else if (index == 1) {
files.sendAttachmentsWithEmailFromDb(userName, msgId)
} else if (index == 2) {
......
......@@ -201,7 +201,7 @@ Component {
anchors.fill: parent
onClicked: {
if (fromLocalDb) {
isds.downloadMessage(messageModel, userName, msgType, zfoId)
isds.doIsdsAction("downloadMessage", userName)
}
}
}
......@@ -394,7 +394,7 @@ Component {
if (downloadStart) {
downloadStart = false
if (fromLocalDb) {
isds.downloadMessage(messageModel, userName, msgType, zfoId)
isds.doIsdsAction("downloadMessage", userName)
}
}
}
......@@ -416,7 +416,7 @@ Component {
anchors.fill: parent
onClicked: {
if (fromLocalDb) {
isds.downloadMessage(messageModel, userName, msgType, zfoId)
isds.doIsdsAction("downloadMessage", userName)
}
}
}
......@@ -433,5 +433,13 @@ Component {
wrapMode: Text.WordWrap
text: ""
} // Text
Connections {
target: isds
onRunDownloadMessageSig: {
if (fromLocalDb) {
isds.downloadMessage(messageModel, userName, msgType, zfoId)
}
}
}
}
}
......@@ -215,9 +215,9 @@ Component {
if (downloadStart) {
downloadStart = false
if (msgType == MessageType.TYPE_RECEIVED) {
isds.syncSingleAccountReceived(accountModel, messageModel, userName)
isds.doIsdsAction("syncSingleAccountReceived", userName)
} else if (msgType == MessageType.TYPE_SENT) {
isds.syncSingleAccountSent(accountModel, messageModel, userName)
isds.doIsdsAction("syncSingleAccountSent", userName)
}
}
}
......@@ -234,6 +234,18 @@ Component {
messages.fillMessageList(messageModel, userName, msgType)
}
}
Connections {
target: isds
onRunSyncSingleAccountReceivedSig: {
isds.syncSingleAccountReceived(accountModel, messageModel, userName)
}
}
Connections {
target: isds
onRunSyncSingleAccountSentSig: {
isds.syncSingleAccountSent(accountModel, messageModel, userName)
}
}
}
}
}
......@@ -78,7 +78,8 @@ Item {
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())) {
isds.getAccountInfo(userNameTextField.text.toString(), true)
/* TODO - remove the function or make it asynchronous */
isds.getAccountInfo(userNameTextField.text.toString())
}
} else {
if (accounts.updateAccount(accountModel, sLoginMethod,
......
......@@ -84,6 +84,11 @@
#define OTP_TYPE_HOTP "HOTP"
#define OTP_NO_OTP "noOTP"
/* PASSWORD TYPE */
#define PWD_PWD "pwd"
#define PWD_CERT "cert"
#define PWD_HOTP "hotp"
#define PWD_TOTP "totp"
/*!
* @brief Maximum length of message list to be downloaded.
......
......@@ -78,174 +78,6 @@ IsdsWrapper::~IsdsWrapper(void)
m_workPool.stop();
}
void IsdsWrapper::syncAllAccounts(const QVariant &acntModelVariant)
{
qDebug("%s()", __func__);
QList<QString> userNameList = AccountListModel::globAccounts.keys();
foreach (const QString userName, userNameList) {
syncOneAccount(acntModelVariant, userName);
}
}
void IsdsWrapper::syncOneAccount(const QVariant &acntModelVariant,
const QString &userName)
{
qDebug("%s()", __func__);
syncSingleAccountSent(acntModelVariant, QVariant(), userName);
syncSingleAccountReceived(acntModelVariant, QVariant(), userName);
}
void IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
syncSingleAccount(acntModelVariant, msgModelVariant, userName,
Messages::TYPE_RECEIVED);
}
void IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
syncSingleAccount(acntModelVariant, msgModelVariant, userName,
Messages::TYPE_SENT);
}
void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName,
enum Messages::MessageType msgDirect)
{
qDebug("%s()", __func__);
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("Empty user name"), tr("Internal error"));
return;
}
QString errText;
if (!isLoggedToIsds(userName, errText)) {
showLoginProblemDialog(userName, errText);
return;
}
QString msgType = tr("received");
if (msgDirect == Messages::TYPE_SENT) {
msgType = tr("sent");
}
emit statusBarTextChanged(tr("%1: downloading %2").arg(userName).arg(msgType),
true, true);
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
/* Create download message list task and run it */
TaskDownloadMessageList *task;
task = new (std::nothrow) TaskDownloadMessageList(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
msgDirect, (globSet.downloadOnlyNewMsgs) ? DOWNLOAD_NEW_MESSAGES : DOWNLOAD_ALL_MESSAGES,
1, MESSAGE_LIST_LIMIT, &m_workPool, messageModel, accountModel,
globSet.downloadCompleteMsgs, globSet.dbsLocation);
task->setAutoDelete(true);
m_workPool.assignHi(task);
}
void IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
{
qDebug("%s()", __func__);
QString errTxt = tr("Wrong username");
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return;
}
if (!isLoggedToIsds(userName, errTxt)) {
if (isFirstLogin) {
emit statusBarTextChanged("", false, false);
if (!errTxt.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Problem adding account: %1").arg(userName),
tr("New account could not be created because an error occurred "
"while trying to log in with user name '%1'.").arg(userName),
tr("ISDS returns:") + " " + errTxt + "\n\n" +
tr("Check your login data and try again."));
}
emit downloadAccountInfoFinishedSig(userName, false);
} else {
showLoginProblemDialog(userName, errTxt);
}
return;
}
emit statusBarTextChanged(tr("Getting account info %1").
arg(userName), true, true);
TaskDownloadAccountInfo *task;
task = new (std::nothrow) TaskDownloadAccountInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper);
task->setAutoDelete(true);
m_workPool.assignHi(task);
}
void IsdsWrapper::downloadMessage(const QVariant &msgModelVariant,
const QString &userName, enum Messages::MessageType messageType,
qint64 msgId)
{
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
downloadMessage(messageModel, userName, messageType, msgId);
}
void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
QString errTxt = tr("Wrong username or message ID");
if (userName.isEmpty() || msgId <= 0) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return;
}
if (!isLoggedToIsds(userName, errTxt)) {
showLoginProblemDialog(userName, errTxt);
return;
}
emit statusBarTextChanged(tr("Downloading delivery info %1").
arg(QString::number(msgId)), true, true);
TaskDownloadDeliveryInfo *task;
task = new (std::nothrow) TaskDownloadDeliveryInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper, msgId);
task->setAutoDelete(true);
m_workPool.assignHi(task);
bool success = TaskDownloadDeliveryInfo::DL_SUCCESS == task->m_result;
delete task;
if (!success) {
Dialogues::errorMessage(Dialogues::WARNING,
tr("Delivery info: %1").arg(userName),
tr("Failed to download delivery info for message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false,
true);
}
}
bool IsdsWrapper::changePassword(const QString &userName,
const QString &accountName)
{
......@@ -262,8 +94,7 @@ bool IsdsWrapper::changePassword(const QString &userName,
return false;
}
if (!isLoggedToIsds(userName, errTxt)) {
showLoginProblemDialog(userName, errTxt);
if (!isLoggedToIsds(userName)) {
return false;
}
......@@ -383,11 +214,169 @@ bool IsdsWrapper::changePassword(const QString &userName,
return true;
}
void IsdsWrapper::returnInputDialogText(const QString &userName,
const QString &accountName, const QString &pwd)
void IsdsWrapper::doIsdsAction(const QString &isdsAction,
const QString &userName)
{
qDebug("%s()", __func__);
if (isdsAction == "syncAllAccounts") {
syncAllAccounts();
return;
}
if (isLoggedToIsds(userName)) {
if (isdsAction == "changePassword") {
emit runChangePasswordSig(userName);
} else if (isdsAction == "downloadMessage") {
emit runDownloadMessageSig(userName);
} else if (isdsAction == "getAccountInfo") {
emit runGetAccountInfoSig(userName);
} else if (isdsAction == "syncOneAccount") {
emit runSyncOneAccountSig(userName);
} else if (isdsAction == "syncSingleAccountReceived") {
emit runSyncSingleAccountReceivedSig(userName);
} else if (isdsAction == "syncSingleAccountSent") {
emit runSyncSingleAccountSentSig(userName);
}
return;
}
/* Begin login phase to ISDS */
doLoginAction(isdsAction, userName);
}
void IsdsWrapper::downloadMessage(const QVariant &msgModelVariant,
const QString &userName, enum Messages::MessageType messageType,
qint64 msgId)
{
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
downloadMessage(messageModel, userName, messageType, msgId);
}
void IsdsWrapper::getAccountInfo(const QString &userName)
{
qDebug("%s()", __func__);
QString errTxt = tr("Wrong username");
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return;
}
if (!isLoggedToIsds(userName)) {
return;
}
emit statusBarTextChanged(tr("Getting account info %1").
arg(userName), true, true);
TaskDownloadAccountInfo *task;
task = new (std::nothrow) TaskDownloadAccountInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper);
task->setAutoDelete(true);
m_workPool.assignHi(task);
}
void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
QString errTxt = tr("Wrong username or message ID");
if (userName.isEmpty() || msgId <= 0) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return;
}
if (!isLoggedToIsds(userName)) {
return;
}
emit statusBarTextChanged(tr("Downloading delivery info %1").
arg(QString::number(msgId)), true, true);
TaskDownloadDeliveryInfo *task;
task = new (std::nothrow) TaskDownloadDeliveryInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper, msgId);
task->setAutoDelete(true);
m_workPool.assignHi(task);
bool success = TaskDownloadDeliveryInfo::DL_SUCCESS == task->m_result;
delete task;
if (!success) {
Dialogues::errorMessage(Dialogues::WARNING,
tr("Delivery info: %1").arg(userName),
tr("Failed to download delivery info for message %1.").arg(msgId),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false,
true);
}
}
void IsdsWrapper::returnInputDialogText(const QString &isdsAction,
const QString &pwdType, const QString &userName, const QString &pwd)
{
if (pwdType == PWD_PWD) {
m_isdsSession.isdsCtxMap[userName].password = pwd;
doLoginAction(isdsAction, userName);
} else if (pwdType == PWD_HOTP) {
m_isdsSession.isdsCtxMap[userName].pass_phrase = pwd;
doLoginAction(isdsAction, userName);
} else if (pwdType == PWD_CERT) {
m_isdsSession.isdsCtxMap[userName].pass_phrase = pwd;
doLoginAction(isdsAction, userName);
} else if (pwdType == PWD_TOTP) {
m_isdsSession.isdsCtxMap[userName].pass_phrase = pwd;
runSecondTOTPLoginPhase(m_isdsSession.isdsCtxMap[userName],
isdsAction);
}
}
void IsdsWrapper::syncOneAccount(const QVariant &acntModelVariant,
const QString &userName)
{
qDebug("%s()", __func__);
syncSingleAccountSent(acntModelVariant, QVariant(), userName);
syncSingleAccountReceived(acntModelVariant, QVariant(), userName);
}
void IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
syncSingleAccount(acntModelVariant, msgModelVariant, userName,
Messages::TYPE_RECEIVED);
}
void IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
syncSingleAccount(acntModelVariant, msgModelVariant, userName,
Messages::TYPE_SENT);
}
void IsdsWrapper::closeAllOtpConnections(void)
{
/* TODO - save password to isds context in future */
qDebug() << userName << accountName << pwd;
qDebug("%s()", __func__);
QList<QString> usernames = m_isdsSession.isdsCtxMap.keys();
for (int i = 0; i < usernames.count(); ++i) {
if (m_isdsSession.isdsCtxMap[usernames.at(i)].login_method == USERNAME_PWD_HOTP ||
m_isdsSession.isdsCtxMap[usernames.at(i)].login_method == USERNAME_PWD_TOTP) {
if (isLoggedToIsdsOtp(usernames.at(i))) {
isdsLogoutOTP(usernames.at(i));
}
}
}
}
bool IsdsWrapper::isLoggedToIsdsOtp(const QString &userName)
......@@ -407,8 +396,7 @@ bool IsdsWrapper::isdsLogoutOTP(const QString &userName)
{
qDebug("%s()", __func__);
QString errText;
if (!isLoggedToIsds(userName, errText)) {
if (!isLoggedToIsds(userName)) {
return false;
}
......@@ -427,21 +415,6 @@ bool IsdsWrapper::isdsLogoutOTP(const QString &userName)
return true;
}
void IsdsWrapper::closeAllOtpConnections(void)
{
qDebug("%s()", __func__);
QList<QString> usernames = m_isdsSession.isdsCtxMap.keys();
for (int i = 0; i < usernames.count(); ++i) {
if (m_isdsSession.isdsCtxMap[usernames.at(i)].login_method == USERNAME_PWD_HOTP ||
m_isdsSession.isdsCtxMap[usernames.at(i)].login_method == USERNAME_PWD_TOTP) {
if (isLoggedToIsdsOtp(usernames.at(i))) {
isdsLogoutOTP(usernames.at(i));
}
}
}
}