|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QProcess> |
|
19 #include <QTranslator> |
|
20 #include <QCoreApplication> |
|
21 #include <HbInstance> |
|
22 #include <HbAction> |
|
23 #include <HbMessagebox> |
|
24 |
|
25 #include "nmsettingsviewfactory.h" |
|
26 #include "nmmailboxsettingsmanager.h" |
|
27 #include "nmmailboxsettingview.h" |
|
28 #include "nmmailboxselectionview.h" |
|
29 #include "nmmailbox.h" |
|
30 #include "nmcommon.h" |
|
31 #include "nmsettingsviewlauncher.h" |
|
32 #include "nmsettingscommon.h" |
|
33 |
|
34 static const QString mailWizardStartExe = "mailwizard.exe"; |
|
35 static const QString mailWizardStartArgs = "from:controlpanel"; |
|
36 |
|
37 |
|
38 /*! |
|
39 \class NmSettingsViewFactory |
|
40 \brief Constructs and displays settings views. |
|
41 |
|
42 */ |
|
43 |
|
44 |
|
45 // ======== MEMBER FUNCTIONS ======== |
|
46 |
|
47 /*! |
|
48 Constructor of NmSettingsViewFactory. |
|
49 |
|
50 \param itemDataHelper |
|
51 \param text |
|
52 \param description |
|
53 \param icon |
|
54 \param parent |
|
55 \return A newly constructed settings view factory instance. |
|
56 */ |
|
57 NmSettingsViewFactory::NmSettingsViewFactory( |
|
58 CpItemDataHelper &itemDataHelper, |
|
59 const QString &text, |
|
60 const QString &description, |
|
61 const HbIcon &icon, |
|
62 const HbDataFormModelItem *parent) |
|
63 : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent), |
|
64 mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(0),mPrevView(0) |
|
65 { |
|
66 } |
|
67 |
|
68 |
|
69 /*! |
|
70 Constructor of NmSettingsViewFactory. |
|
71 |
|
72 \param viewLauncher |
|
73 \param itemDataHelper |
|
74 \param text |
|
75 \param description |
|
76 \param icon |
|
77 \param parent |
|
78 \return A newly constructed settings view factory instance. |
|
79 */ |
|
80 NmSettingsViewFactory::NmSettingsViewFactory( |
|
81 const NmSettingsViewLauncher *viewLauncher, |
|
82 CpItemDataHelper &itemDataHelper, |
|
83 const QString &text, |
|
84 const QString &description, |
|
85 const HbIcon &icon, |
|
86 const HbDataFormModelItem *parent) |
|
87 : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent), |
|
88 mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(viewLauncher), mPrevView(0) |
|
89 { |
|
90 } |
|
91 |
|
92 |
|
93 /*! |
|
94 Destructor of NmSettingsViewFactory. |
|
95 */ |
|
96 NmSettingsViewFactory::~NmSettingsViewFactory() |
|
97 { |
|
98 delete mSettingsManager; |
|
99 } |
|
100 |
|
101 |
|
102 /*! |
|
103 Constructs a setting view. The type of the view depends on the number of |
|
104 mailboxes present. If there are no mailboxes defined, displays a query |
|
105 asking whether to user wants to define a new mailbox or not. |
|
106 |
|
107 \return A newly constructed setting view instance. |
|
108 */ |
|
109 CpBaseSettingView *NmSettingsViewFactory::createSettingView() const |
|
110 { |
|
111 NMLOG(QString("NmSettingsViewFactory::createSettingView(): Begin.")); |
|
112 |
|
113 CpBaseSettingView *view = 0; |
|
114 QList<NmMailbox *> mailboxList; |
|
115 mSettingsManager->listMailboxes(mailboxList); |
|
116 const int mailboxCount(mailboxList.count()); |
|
117 |
|
118 // Log the number of mailboxes. |
|
119 NMLOG(QString("NmSettingsViewFactory::createSettingView(): Mailbox count is ") + |
|
120 QString::number(mailboxCount)); |
|
121 |
|
122 if (mailboxCount == 0) { |
|
123 // Query the user whether to launch the wizard or not. |
|
124 HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
|
125 messageBox->setText(hbTrId("txt_mail_dialog_no_mailboxes_create_new")); |
|
126 messageBox->setTimeout(HbMessageBox::NoTimeout); |
|
127 |
|
128 // Read the user selection. |
|
129 HbAction *action = messageBox->exec(); |
|
130 |
|
131 if (action == messageBox->primaryAction()) { |
|
132 // Launch mail wizard. |
|
133 NMLOG(QString("NmSettingsViewFactory::createSettingView(): Launching the mail wizard.")); |
|
134 QStringList args; |
|
135 args << mailWizardStartArgs; |
|
136 QProcess::startDetached(mailWizardStartExe, args); |
|
137 } |
|
138 } |
|
139 else if (mailboxCount == 1) { |
|
140 // Construct setting view for the only available mailbox |
|
141 NmMailbox *mailbox = mailboxList.at(0); |
|
142 view = new NmMailboxSettingView(mailbox->id(), |
|
143 mailbox->name(), |
|
144 *mSettingsManager); |
|
145 } |
|
146 else if (mailboxCount > 1) { |
|
147 // Construct mailbox selection view |
|
148 view = new NmMailboxSelectionView(*this, *mSettingsManager, mailboxList); |
|
149 } |
|
150 |
|
151 if (view) { |
|
152 connect(mSettingsManager, |
|
153 SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)), |
|
154 view, SLOT(mailboxListChanged(const NmId &, NmSettings::MailboxEventType))); |
|
155 |
|
156 connect(mSettingsManager, |
|
157 SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)), |
|
158 view, SLOT(mailboxPropertyChanged(const NmId &, QVariant, QVariant))); |
|
159 } |
|
160 |
|
161 NMLOG(QString("NmSettingsViewFactory::createSettingView(): End.")); |
|
162 return view; |
|
163 } |
|
164 |
|
165 |
|
166 /*! |
|
167 Constructs and launches, i.e. displays a setting view for the given mailbox. |
|
168 |
|
169 \param mailboxId The id of the mailbox. |
|
170 \param mailboxName The name of the mailbox. |
|
171 */ |
|
172 void NmSettingsViewFactory::launchSettingView(const NmId &mailboxId, |
|
173 const QString &mailboxName) const |
|
174 { |
|
175 NMLOG(QString("NmSettingsViewFactory::launchSettingView")); |
|
176 |
|
177 // There's always at least one valid main window available. |
|
178 HbMainWindow *mainWindow = hbInstance->allMainWindows().takeFirst(); |
|
179 |
|
180 CpBaseSettingView *view = |
|
181 new NmMailboxSettingView(mailboxId, mailboxName, *mSettingsManager); |
|
182 |
|
183 connect(mSettingsManager, |
|
184 SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)), |
|
185 view, SLOT(mailboxListChanged(const NmId &, NmSettings::MailboxEventType))); |
|
186 |
|
187 connect(mSettingsManager, |
|
188 SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)), |
|
189 view, SLOT(mailboxPropertyChanged(const NmId &, QVariant, QVariant))); |
|
190 |
|
191 // Disconnect mSettingsViewLauncher's previous connections to be sure that signals which are |
|
192 // offered out will be sent last. |
|
193 mSettingsManager->disconnect( |
|
194 SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)), |
|
195 mSettingsViewLauncher, |
|
196 SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType))); |
|
197 |
|
198 mSettingsManager->disconnect( |
|
199 SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)), |
|
200 mSettingsViewLauncher, |
|
201 SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant))); |
|
202 |
|
203 |
|
204 // Reconnect mSettingsViewLauncher. |
|
205 connect(mSettingsManager, |
|
206 SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)), |
|
207 mSettingsViewLauncher, |
|
208 SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType))); |
|
209 |
|
210 connect(mSettingsManager, |
|
211 SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)), |
|
212 mSettingsViewLauncher, |
|
213 SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant))); |
|
214 |
|
215 // Create back navigation action for a view. |
|
216 HbAction *action = new HbAction(Hb::BackNaviAction, view); |
|
217 connect(action, SIGNAL(triggered()), this, SLOT(backPress())); |
|
218 view->setNavigationAction(action); |
|
219 mPrevView = mainWindow->currentView(); |
|
220 mainWindow->addView(view); |
|
221 mainWindow->setCurrentView(view); |
|
222 |
|
223 NMLOG(QString("NmSettingsViewFactory::launchSettingView - OK")); |
|
224 } |
|
225 |
|
226 |
|
227 /*! |
|
228 Handles back button press. |
|
229 Removes the current view from the main window and activates the previous view. |
|
230 Destroys removed view. |
|
231 */ |
|
232 void NmSettingsViewFactory::backPress() |
|
233 { |
|
234 NMLOG(QString("NmSettingsViewFactory::backPress")); |
|
235 |
|
236 HbMainWindow *mainWindow = hbInstance->allMainWindows().takeFirst(); |
|
237 QList<HbView *> views = mainWindow->views(); |
|
238 if (views.count() > 1) { |
|
239 HbView *currentView = mainWindow->currentView(); |
|
240 int indexOfView(views.indexOf(mPrevView)); |
|
241 if (indexOfView > -1) { |
|
242 mainWindow->setCurrentView(views.at(indexOfView)); |
|
243 mainWindow->removeView(currentView); |
|
244 currentView->deleteLater(); |
|
245 } |
|
246 mPrevView = 0; |
|
247 } |
|
248 |
|
249 NMLOG(QString("NmSettingsViewFactory::backPress - OK")); |
|
250 } |
|
251 |
|
252 // End of file. |