Commit 3e54d6c5 authored by Dan Chapman's avatar Dan Chapman
Browse files

Ubuntu: Implements PasswordWatcher for imap access

Now uses the passwordWatcher. When authRequest signal is
received it either auto connects or if no password saved ask
user to enter password.

REVIEW: 118130
BUG: 333965
BUG: 332987

Removed using an anonymous function to call a reloadPassword slot
parent 8f5ba68a
......@@ -722,7 +722,7 @@ if(WITH_UBUNTU)
set_property(TARGET trojita-ubu APPEND PROPERTY INCLUDE_DIRECTORIES
${QT_MKSPECS_DIR}/default ${CMAKE_CURRENT_SOURCE_DIR}/src/Ubuntu)
target_link_libraries(trojita-ubu AppVersion Imap MSA Streams qwwsmtpclient Common Composer Plugins )
target_link_libraries(trojita-ubu AppVersion Imap MSA Streams qwwsmtpclient Common Composer Plugins ${STATIC_PLUGINS})
endif()
if(WITH_QT5)
......
......@@ -34,6 +34,7 @@
#include "Imap/Model/ThreadingMsgListModel.h"
#include "MSA/Account.h"
#include "Plugins/PluginManager.h"
#include "static_plugins.h"
int main(int argc, char *argv[])
{
......@@ -121,6 +122,8 @@ int main(int argc, char *argv[])
qmlRegisterSingletonType<UiUtils::Formatting>("trojita.UiFormatting", 0, 1, "UiFormatting", UiUtils::Formatting::factory);
qmlRegisterUncreatableType<MSA::Account>("trojita.MSA.Account", 0, 1, "MSAAccount",
QLatin1String("MSA::Account can be only created from the C++ code."));
qmlRegisterUncreatableType<UiUtils::PasswordWatcher>("trojita.PasswordWatcher", 0, 1, "PasswordWatcher",
QLatin1String("PasswordWatcher can only be created from the C++ code. Use ImapAccess if you need access to an instance."));
viewer.setTitle(QObject::trUtf8("Trojitá"));
viewer.setSource(QUrl::fromLocalFile(qmlFile));
......
......@@ -68,9 +68,6 @@ Page {
if (connectionSelector.model.get(connectionSelector.selectedIndex).name !== imapAccess.sslMode) {
imapAccess.sslMode = connectionSelector.model.get(connectionSelector.selectedIndex).name
}
if (imapPasswordInput.text.length > 0) {
imapAccess.password = imapPasswordInput.text
}
}
states: [
......@@ -94,7 +91,10 @@ Page {
// Load user details
PropertyChanges { target: imapSettings; imapServer: imapAccess.server }
PropertyChanges { target: imapSettings; imapUserName: imapAccess.username }
PropertyChanges { target: imapSettings; imapPassword: "" }
PropertyChanges {
target: imapSettings;
imapPassword: imapAccess.passwordWatcher.password ? imapAccess.passwordWatcher.password : ""
}
PropertyChanges {
target: imapSettings
imapSslModelIndex: {
......@@ -180,6 +180,23 @@ Page {
KeyNavigation.backtab: imapUserNameInput
}
Label {
id: passwordWarning
color: imapAccess.passwordWatcher.isStorageEncrypted ? "#888888" : "red"
anchors {
left: parent.left
right: parent.right
}
visible: imapPasswordInput.text.length > 0
wrapMode: TextEdit.Wrap
text: imapAccess.passwordWatcher.isStorageEncrypted ?
qsTr("This password will be saved in encrypted storage. " +
"If you do not enter password here, Trojitá will prompt for one when needed.")
:
qsTr("This password will be saved in clear text. " +
"If you do not enter password here, Trojitá will prompt for one when needed.");
}
Label {
id: hostLabel
property bool valid: !!imapServerInput.text
......
......@@ -26,9 +26,17 @@ import Ubuntu.Components.Popups 1.0
Dialog {
id: showInfoDialog
property string buttonText
property Action buttonAction
Button {
text: qsTr("Close")
id: dialogButton
text: buttonText ? qsTr(buttonText) : qsTr("Close")
color: UbuntuColors.orange
onClicked: PopupUtils.close(showInfoDialog)
onClicked: {
if (buttonAction) {
showInfoDialog.buttonAction.triggered(dialogButton)
}
PopupUtils.close(showInfoDialog)
}
}
}
......@@ -21,7 +21,7 @@
*/
import QtQuick 2.0
import Ubuntu.Components 1.1
import trojita.models.ThreadingMsgListModel 0.1
import Ubuntu.Components.Popups 1.0
import trojita.MSA.Account 0.1
// We should try and keep the same settings tabs as desktop
......@@ -30,13 +30,55 @@ import trojita.MSA.Account 0.1
Tabs {
id: settingsTabs
visible: false
// We should try and keep the same settings tabs as desktop
// so we should have profiles, SMTP, offline etc in the future
// during the password saving there is a short period where password is an empty string and trying to
// either using the binding to determine if password exists or reloadPassword cause undesired events.
// This helps to determine if we need to show error dialog on saving failed signals
property bool passwordGiven
Component.onCompleted: {
// use the passwordWatcher savingDone signal to trigger saving the rest and ensure we
// have any given password available when connecting.
imapAccess.passwordWatcher.savingDone.connect(continueSavingAction.trigger)
imapAccess.passwordWatcher.savingFailed.connect(showSavingPasswordFailed)
}
function showSavingPasswordFailed(message) {
// if no passwordGiven then we can safely just continue and ignore
// the error message
if (!passwordGiven) {
continueSavingAction.trigger()
} else {
PopupUtils.open(Qt.resolvedUrl("InfoDialog.qml"), appWindow, {
title: qsTr("Failed saving password"),
text: message,
buttonText: qsTr("Continue"),
buttonAction: continueSavingAction
})
}
}
Action {
id: continueSavingAction
onTriggered: {
imapSettings.saveImapSettings()
if (!imapSettings.settingsModified) {
pageStack.pop()
} else {
imapSettings.imapSettingsChanged()
imapAccess.doConnect()
appWindow.connectModels()
}
// update state
imapSettings.state = "HAS_ACCOUNT"
imapSettings.settingsModified = false
}
}
Action {
id: cancelAction
onTriggered: {
smtpSettings.restoreSettings()
smtpAccountSettings.restoreSettings()
pageStack.pop()
}
}
......@@ -49,19 +91,9 @@ Tabs {
} else if (!smtpSettings.settingsValid) {
settingsTabs.selectedTabIndex = 1
} else {
imapSettings.saveImapSettings()
smtpAccountSettings.saveSettings()
if (!imapSettings.settingsModified) {
pageStack.pop()
} else {
imapSettings.imapSettingsChanged()
imapAccess.doConnect()
appWindow.connectModels()
}
// update state
imapSettings.state = "HAS_ACCOUNT"
imapSettings.settingsModified = false
passwordGiven = imapSettings.imapPassword
imapAccess.passwordWatcher.setPassword(imapSettings.imapPassword)
}
}
}
......
......@@ -67,7 +67,16 @@ MainView{
})
}
function requestingPassword() {
function continueAuthentication() {
if (imapAccess.passwordWatcher.didReadOk && imapAccess.passwordWatcher.password) {
imapAccess.imapModel.imapPassword = imapAccess.passwordWatcher.password
} else {
PopupUtils.open(passwordDialogComponent)
}
}
function passwordReadingFailed(message) {
authAttemptFailed(message)
PopupUtils.open(passwordDialogComponent)
}
......@@ -81,7 +90,7 @@ MainView{
imapAccess.imapModel.imapError.connect(showImapError)
imapAccess.imapModel.networkError.connect(showNetworkError)
imapAccess.imapModel.alertReceived.connect(showImapAlert)
imapAccess.imapModel.authRequested.connect(requestingPassword)
imapAccess.imapModel.authRequested.connect(imapAccess.passwordWatcher.reloadPassword())
imapAccess.imapModel.authAttemptFailed.connect(authAttemptFailed)
imapAccess.imapModel.networkPolicyOffline.connect(function() {networkOffline = true})
imapAccess.imapModel.networkPolicyOnline.connect(function() {networkOffline = false})
......@@ -92,6 +101,8 @@ MainView{
// connect these before calling imapAccess.doConnect()
imapAccess.checkSslPolicy.connect(function() {PopupUtils.open(sslSheetPage)})
imapAccess.modelsChanged.connect(modelsChanged)
imapAccess.passwordWatcher.readingDone.connect(continueAuthentication)
imapAccess.passwordWatcher.readingFailed.connect(passwordReadingFailed)
}
function settingsChanged() {
......@@ -101,6 +112,7 @@ MainView{
function modelsChanged() {
mailboxList.model = imapAccess.mailboxModel
pageStack.clear()
// Initially set the sort order to descending, if the sort order
// then gets changed from message list page toolbar, we respect that
// change and use the specified sort order from then onwards
......
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