|
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 |
|
19 #include <hbmessagebox.h> |
|
20 #include <hblabel.h> |
|
21 #include <hbaction.h> |
|
22 #include <hbpopup.h> |
|
23 #include <hblineedit.h> |
|
24 #include <hbvalidator.h> |
|
25 #include <hbabstractitemview.h> |
|
26 #include <hbprogressdialog.h> |
|
27 #include <hbdatetimepicker.h> |
|
28 |
|
29 #include <QString> |
|
30 #include <QDate> |
|
31 #include <QRegExp> |
|
32 #include <QList> |
|
33 |
|
34 #include "notifications.h" |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 |
|
38 void Notifications::showMessageBox(HbMessageBox::MessageBoxType type, const QString &text, const QString &label, int timeout ) |
|
39 { |
|
40 HbMessageBox *messageBox = new HbMessageBox(type); |
|
41 messageBox->setText(text); |
|
42 messageBox->setStandardButtons( HbMessageBox::Ok ); |
|
43 if(label.length()) |
|
44 { |
|
45 HbLabel *header = new HbLabel(label, messageBox); |
|
46 messageBox->setHeadingWidget(header); |
|
47 } |
|
48 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
49 messageBox->setTimeout(timeout); |
|
50 messageBox->open(); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 |
|
55 void Notifications::about() |
|
56 { |
|
57 showMessageBox(HbMessageBox::MessageTypeInformation, |
|
58 "Version 6.1.2 - September 9th 2010. Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Licensed under Eclipse Public License v1.0.", |
|
59 "About Creator", |
|
60 HbPopup::NoTimeout |
|
61 ); |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 |
|
66 void Notifications::error(const QString& errorMessage) |
|
67 { |
|
68 showMessageBox(HbMessageBox::MessageTypeWarning, errorMessage, QString("Error"), 3000); |
|
69 } |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 |
|
74 HbProgressDialog* Notifications::showProgressBar(const QString& text, int max) |
|
75 { |
|
76 HbProgressDialog *note = new HbProgressDialog(HbProgressDialog::ProgressDialog); |
|
77 note->setText(text); |
|
78 note->setMaximum(max); |
|
79 note->setAutoClose(false); |
|
80 note->show(); |
|
81 return note; |
|
82 |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 |
|
87 void Notifications::showGlobalNote(const QString& text, HbMessageBox::MessageBoxType type, int timeout) |
|
88 { |
|
89 showMessageBox(type, text, QString("Creator"), timeout); |
|
90 } |
|
91 |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 |
|
95 CreatorYesNoDialog::CreatorYesNoDialog(MUIObserver* observer, int userData) : |
|
96 HbMessageBox(HbMessageBox::MessageTypeQuestion, NULL), |
|
97 CreatorDialog(observer, userData) |
|
98 { |
|
99 } |
|
100 |
|
101 void CreatorYesNoDialog::launch(const QString& text, const QString& label, MUIObserver* observer, int userData) throw(std::exception) |
|
102 { |
|
103 CreatorYesNoDialog* dlg = new CreatorYesNoDialog(observer, userData); |
|
104 dlg->setStandardButtons( HbMessageBox::Yes | HbMessageBox::No ); |
|
105 dlg->setText(text); |
|
106 if(label.length()) |
|
107 dlg->setHeadingWidget(new HbLabel(label, dlg)); |
|
108 dlg->setAttribute(Qt::WA_DeleteOnClose); |
|
109 dlg->setTimeout(HbPopup::NoTimeout); |
|
110 dlg->open(dlg, SLOT(DialogClosed(HbAction*))); |
|
111 } |
|
112 |
|
113 void CreatorYesNoDialog::DialogClosed(HbAction *action) |
|
114 { |
|
115 TBool PositiveAction(EFalse); |
|
116 if(action && (action->softKeyRole()==QAction::PositiveSoftKey || !action->text().compare("yes", Qt::CaseInsensitive))){ |
|
117 PositiveAction = ETrue; |
|
118 } |
|
119 NotifyObserver(PositiveAction); |
|
120 } |
|
121 |
|
122 CreatorInputDialog::CreatorInputDialog(int* value, MUIObserver* module, int userData) : |
|
123 HbInputDialog(NULL), |
|
124 CreatorDialog(module, userData), |
|
125 mIntValue(value), |
|
126 mStrValue(mDummy)// will not be used |
|
127 { |
|
128 if(!value) |
|
129 throw std::invalid_argument("value cannot be the null!"); |
|
130 } |
|
131 |
|
132 CreatorInputDialog::CreatorInputDialog(TDes& value, MUIObserver* module, int userData) : |
|
133 HbInputDialog(NULL), |
|
134 CreatorDialog(module, userData), |
|
135 mIntValue(NULL), |
|
136 mStrValue(value) |
|
137 { |
|
138 } |
|
139 |
|
140 void CreatorInputDialog::launch(const QString& label, int* value, bool acceptsZero, MUIObserver* observer, int userData) throw( std::exception ) |
|
141 { |
|
142 CreatorInputDialog* dlg = new CreatorInputDialog(value, observer, userData); |
|
143 dlg->setPromptText(label); |
|
144 dlg->setInputMode(IntInput); |
|
145 HbValidator *validator = new HbValidator(dlg); |
|
146 QString tmp; |
|
147 if (acceptsZero == false) { |
|
148 tmp.append("^[1-9]{1}\\d{0,4}"); |
|
149 } |
|
150 else { |
|
151 tmp.append("^[0-9]{1,5}"); |
|
152 } |
|
153 |
|
154 QRegExp rxBasic(tmp); |
|
155 validator->addField(new QRegExpValidator(rxBasic, 0), ""); |
|
156 dlg->setValidator(validator); |
|
157 dlg->setValue(QVariant(*value)); |
|
158 dlg->lineEdit()->setSelection(0, dlg->value().toString().length()); |
|
159 dlg->setAttribute(Qt::WA_DeleteOnClose); |
|
160 dlg->open(dlg, SLOT(DialogClosed(HbAction*))); |
|
161 } |
|
162 |
|
163 void CreatorInputDialog::launch(const QString& label, TDes& value, MUIObserver* observer, int userData) throw( std::exception ) |
|
164 { |
|
165 CreatorInputDialog* dlg = new CreatorInputDialog(value, observer, userData); |
|
166 dlg->setPromptText(label); |
|
167 dlg->lineEdit()->setMaxLength(value.MaxLength()); |
|
168 dlg->setValue(QString::fromUtf16(value.Ptr(), value.Length())); |
|
169 dlg->lineEdit()->setSelection(0, dlg->value().toString().length()); |
|
170 dlg->setInputMode(TextInput); |
|
171 dlg->setAttribute(Qt::WA_DeleteOnClose); |
|
172 dlg->open(dlg, SLOT(DialogClosed(HbAction*))); |
|
173 } |
|
174 |
|
175 void CreatorInputDialog::DialogClosed(HbAction *action) |
|
176 { |
|
177 TBool PositiveAction(EFalse); |
|
178 if(action && (action->softKeyRole()==QAction::PositiveSoftKey || !action->text().compare("ok", Qt::CaseInsensitive))){ |
|
179 bool ok = true; |
|
180 if( inputMode() == IntInput ) |
|
181 *mIntValue = value().toInt(&ok); |
|
182 else if( inputMode() == TextInput && mStrValue.MaxLength() >= value().toString().length() ) |
|
183 mStrValue.Copy(value().toString().utf16()); |
|
184 else |
|
185 ok = false; |
|
186 PositiveAction = ok ? ETrue : EFalse; |
|
187 } |
|
188 NotifyObserver(PositiveAction); |
|
189 } |
|
190 |
|
191 CreatorSelectionDialog::CreatorSelectionDialog(int* selectedItem, MUIObserver* observer, int userData) throw(std::exception) : |
|
192 HbSelectionDialog(NULL), |
|
193 CreatorDialog(observer, userData), |
|
194 mSelectedItem(selectedItem), |
|
195 mSelectedItems(NULL) |
|
196 { |
|
197 if(!mSelectedItem) |
|
198 throw std::invalid_argument("selectedItem cannot be null!"); |
|
199 } |
|
200 |
|
201 CreatorSelectionDialog::CreatorSelectionDialog(CArrayFixFlat<TInt>* selectedItems, MUIObserver* observer, int userData) throw(std::exception) : |
|
202 HbSelectionDialog(NULL), |
|
203 CreatorDialog(observer, userData), |
|
204 mSelectedItem(NULL), |
|
205 mSelectedItems(selectedItems) |
|
206 { |
|
207 if(!mSelectedItems) |
|
208 throw std::invalid_argument("selectedItems cannot be null!"); |
|
209 } |
|
210 |
|
211 void CreatorSelectionDialog::launch(const QString& label, const QStringList& items, int* selectedItem, MUIObserver* observer, int userData) throw(std::exception) |
|
212 { |
|
213 CreatorSelectionDialog* dlg = new CreatorSelectionDialog(selectedItem, observer, userData); |
|
214 if(label.length()) |
|
215 dlg->setHeadingWidget(new HbLabel(label, dlg)); |
|
216 dlg->setStringItems(items); |
|
217 dlg->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
218 dlg->setSelectedItems(QList<QVariant>()); |
|
219 dlg->setAttribute(Qt::WA_DeleteOnClose); |
|
220 dlg->open(dlg, SLOT(DialogClosed(HbAction*))); |
|
221 } |
|
222 |
|
223 void CreatorSelectionDialog::launch(const QString& label, const QStringList& items, CArrayFixFlat<TInt>* selectedItems, MUIObserver* observer, int userData) throw(std::exception) |
|
224 { |
|
225 CreatorSelectionDialog* dlg = new CreatorSelectionDialog(selectedItems, observer, userData); |
|
226 if(label.length()) |
|
227 dlg->setHeadingWidget(new HbLabel(label, dlg)); |
|
228 dlg->setStringItems(items); |
|
229 dlg->setSelectionMode(HbAbstractItemView::MultiSelection); |
|
230 dlg->setAttribute(Qt::WA_DeleteOnClose); |
|
231 dlg->open(dlg, SLOT(DialogClosed(HbAction*))); |
|
232 } |
|
233 |
|
234 void CreatorSelectionDialog::DialogClosed(HbAction *action) |
|
235 { |
|
236 TBool PositiveAction(EFalse); |
|
237 //CreatorSelectionDialog* dlg = qobject_cast<CreatorSelectionDialog*>(sender()); |
|
238 if(!action || (action && action->softKeyRole()==QAction::SelectSoftKey) || (action && !action->text().compare("ok", Qt::CaseInsensitive))){ |
|
239 if(selectedItems().count()){ |
|
240 try{ |
|
241 if( selectionMode() == HbAbstractItemView::SingleSelection && mSelectedItem){ |
|
242 bool ok(false); |
|
243 *mSelectedItem = selectedItems().at(0).toInt(&ok); |
|
244 if(!ok) |
|
245 throw std::invalid_argument("cannot obtain selected item!"); |
|
246 } |
|
247 if( selectionMode() == HbAbstractItemView::MultiSelection && mSelectedItems){ |
|
248 QList<QVariant> items = selectedItems(); |
|
249 foreach( QVariant item, items){ |
|
250 QT_TRAP_THROWING( mSelectedItems->AppendL( item.toInt() ) ); |
|
251 } |
|
252 } |
|
253 PositiveAction = ETrue; |
|
254 } |
|
255 catch (std::exception& e){ |
|
256 Notifications::error( QString("exception: ")+e.what() ); |
|
257 } |
|
258 } |
|
259 } |
|
260 NotifyObserver(PositiveAction); |
|
261 } |
|
262 |
|
263 CreatorDateTimeDialog::CreatorDateTimeDialog(TTime* value, MUIObserver* observer, int userData) : |
|
264 HbDialog(NULL), |
|
265 CreatorDialog(observer, userData), |
|
266 mValue(value) |
|
267 { |
|
268 } |
|
269 |
|
270 void CreatorDateTimeDialog::launch(const QString& label, TTime* value, MUIObserver* observer, int userData) throw( std::exception ) |
|
271 { |
|
272 CreatorDateTimeDialog* dlg = new CreatorDateTimeDialog(value, observer, userData); |
|
273 if(!value) |
|
274 throw std::invalid_argument("value cannot be the null!"); |
|
275 if(label.length()) |
|
276 dlg->setHeadingWidget( new HbLabel(label, dlg) ); |
|
277 |
|
278 // TTime to QDate |
|
279 TBuf<20> timeString; |
|
280 _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3"); |
|
281 TRAP_IGNORE( value->FormatL(timeString, KDateString) ); |
|
282 QString temp = QString::fromUtf16(timeString.Ptr(), timeString.Length()); |
|
283 temp.replace(QChar('/'), QChar('-')); |
|
284 QDate date = QDate::fromString(temp, "dd-MM-yyyy"); |
|
285 HbDateTimePicker* widget = new HbDateTimePicker( date, dlg ); |
|
286 dlg->setContentWidget( widget ); |
|
287 dlg->addAction(new HbAction("Ok", dlg)); |
|
288 dlg->addAction(new HbAction("Cancel", dlg)); |
|
289 dlg->setModal(true); // Dialog is modal |
|
290 dlg->setAttribute(Qt::WA_DeleteOnClose); |
|
291 dlg->setTimeout(HbPopup::NoTimeout); |
|
292 dlg->open(dlg, SLOT(DialogClosed(HbAction*))); |
|
293 } |
|
294 |
|
295 void CreatorDateTimeDialog::DialogClosed(HbAction *action) |
|
296 { |
|
297 TBool PositiveAction(EFalse); |
|
298 if(action && (action->softKeyRole()==QAction::PositiveSoftKey || !action->text().compare("ok", Qt::CaseInsensitive))){ |
|
299 QString str = qobject_cast<HbDateTimePicker*>(contentWidget())->date().toString(Qt::ISODate); |
|
300 str.remove('-'); |
|
301 str += ":000000";// 0h 0m 0s |
|
302 TBuf<30> dateTimeString(str.utf16()); |
|
303 mValue->Set(dateTimeString); |
|
304 PositiveAction = ETrue; |
|
305 } |
|
306 NotifyObserver(PositiveAction); |
|
307 } |
|
308 //End of File |