Dekko
Loading...
Searching...
No Matches
SetupWizard.qml
1/* Copyright (C) 2016 - 2017 Dan Chapman <dpniel@ubuntu.com>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18import QtQuick 2.4
19import QtQml.StateMachine 1.0 as DSM
20import Dekko.Controls 1.0
21import Dekko.Mail 1.0
22import Dekko.Mail.API 1.0
23import Dekko.Mail.Stores.Accounts 1.0
24import Dekko.Mail.Workers 1.0
25import Dekko.Lomiri.Dialogs 1.0
26import QuickFlux 1.0
27import "./states"
28
29/*For the setup wizard we use the state machine framework. http://doc.qt.io/qt-5/qmlstatemachine.html
30
31 Each step of the setup wizard should be it's own state in the FSM and each state should be responsible
32 for loading/activating the UI for that state.
33
34 All states go into the setupwizard/states/ directory and UI views or components go into the setupwizard/components directory
35
36 See http://code.dekkoproject.org/dekko-dev/dekko/uploads/626fa76f365226af0b3fa84d39c7e589/SetupWizardStateMachine.pdf
37 for a diagram of the intended state transitions.
38*/
39Item {
40 id: wizard
41
42 width: parent.width
43 height: parent.height
44 // Use stack view so we get the nice page transitions
45 StackView {
46 id: stack
47 anchors.fill: parent
48 }
49
50 AppListener {
51 filter: WizardKeys.wizardNavigateTo
52 onDispatched: {
53 stack.push({item: message.view, properties: message.properties});
54 }
55 }
56
57 AppListener {
58 filter: WizardKeys.wizardStepBack
59 onDispatched: {
60 // The navigate back action
61 // will trigger the "quit" state when only 1 page left on the stack so no need
62 // to pop anything here.
63 if (stack.depth > 1) {
64 Log.logInfo("SetupWizard::wizardStepBack", "Going back to previous step")
65 stack.pop()
66 }
67 AccountSetup.goBack()
68 }
69 }
70
71 AppListener {
72 filter: WizardKeys.addAnotherAccount
73 onDispatched: {
74 WizardActions.wizardResetAccount()
75 stack.clear()
76 WizardActions.wizardStepForward()
77 }
78 }
79
80 // Popups created from PopupKeys.popupSetupWizard (e.g. account validation
81 // errors, the "password empty?" and "use IMAP instead?" confirmations) need
82 // to render inside this wizard Window rather than the main app Window, which
83 // is hidden behind this one while the wizard is open.
84 DialogWorker {
85 name: PopupKeys.popupSetupWizard
86 dlgTarget: wizard
87 noticePopup: Component {
89 }
90 confirmationPopup: Component {
92 }
93 }
94
95 // Here we define our statemachine and there next/previous states
96 DSM.StateMachine {
97 // TODO: Use the AccountsStore to query configured accounts. views/ shouldn't talk to Client directly
98 initialState: Client.hasConfiguredAccounts ? newAccountState : noAccountsState
99 running: true
100
102 id: noAccountsState
103 backTargetState: quit
104 createTargetState: newAccountState
105 }
106
108 id: newAccountState
109 // If we already have accounts configured then the user accessed this
110 // from the "Manage accounts" UI so move to the quit state
111 // TODO: same as initialState todo
112 backTargetState: Client.hasConfiguredAccounts ? quit : noAccountsState
113 // All account types have to go through the UserInputUI/State
114 nextTargetState: userInputState
115 }
116
118 id: userInputState
119 backTargetState: newAccountState
120 // TODO: Move to validation state if this is a preset account
121 nextTargetState: AccountSetup.isPreset ? validate : autoConfig
122 }
123
125 id: yukItsGoogle
126 }
127
129 id: autoConfig
130 nextTargetState: AccountSetup.needsValidation ? validate : manualInput
131 }
132
134 id: manualInput
135 nextTargetState: validate
136 backTartgetState: userInputState
137 }
138
140 id: validate
141 backTartgetState: manualInput
142 nextTargetState: sync
143 }
144
145 SyncState {
146 id: sync
147 nextTargetState: addAnother
148 }
149
151 id: addAnother
152 nextTargetState: newAccountState
153 quitTargetState: finished
154 }
155
156 // This state deletes the NewAccount object
157 // and removes it form the accounts store if it exists
158 // i.e we tried validating the account which requires
159 // we save it first so it has a valid entry in the db
160 // that needs clenaing up
161 DSM.State {
162 id: quit
163 onEntered: {
164 WizardActions.removeNewAccount()
165 WizardActions.wizardResetAccount()
166 rootPageStack.pop()
167 }
168 }
169
170 DSM.FinalState {
171 id: finished
172 }
173 onFinished: {
174 WizardActions.wizardResetAccount()
175 // FIXME: Use dispatcher API!!!
176 rootPageStack.pop()
177 }
178 }
179}
180