|
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 |
|
28 #include <QString> |
|
29 #include <QDate> |
|
30 #include <QRegExp> |
|
31 |
|
32 #include "notifications.h" |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 |
|
36 void Notifications::showMessageBox(HbMessageBox::MessageBoxType type, const QString &text, const QString &label, int timeout ) |
|
37 { |
|
38 HbMessageBox *messageBox = new HbMessageBox(type); |
|
39 messageBox->setText(text); |
|
40 if(label.length()) |
|
41 { |
|
42 HbLabel *header = new HbLabel(label, messageBox); |
|
43 messageBox->setHeadingWidget(header); |
|
44 } |
|
45 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
46 messageBox->setTimeout(timeout); |
|
47 messageBox->open(); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 |
|
52 void Notifications::about() |
|
53 { |
|
54 showMessageBox(HbMessageBox::MessageTypeInformation, |
|
55 "Version 6.0.0 - April 23rd 2010. Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Licensed under Eclipse Public License v1.0.", |
|
56 "About Creator", |
|
57 HbPopup::NoTimeout |
|
58 ); |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 |
|
63 void Notifications::error(const QString& errorMessage) |
|
64 { |
|
65 showMessageBox(HbMessageBox::MessageTypeWarning, errorMessage, QString("Error"), 3000); |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 |
|
71 HbProgressDialog* Notifications::showProgressBar(const QString& text, int max) |
|
72 { |
|
73 HbProgressDialog *note = new HbProgressDialog(HbProgressDialog::ProgressDialog); |
|
74 note->setText(text); |
|
75 note->setMaximum(max); |
|
76 note->show(); |
|
77 return note; |
|
78 |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 |
|
83 void Notifications::showGlobalNote(const QString& text, HbMessageBox::MessageBoxType type, HbPopup::DefaultTimeout timeout) |
|
84 { |
|
85 showMessageBox(type, text, QString("Creator"), timeout); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 |
|
90 bool Notifications::entriesQueryDialog(int& numberOfEntries, const QString& text, bool acceptsZero) |
|
91 { |
|
92 bool err = false; |
|
93 HbDialog *popup = new HbDialog(); |
|
94 popup->setDismissPolicy(HbPopup::TapOutside); |
|
95 popup->setTimeout(HbPopup::NoTimeout); |
|
96 |
|
97 HbLabel *title = new HbLabel(); |
|
98 HbLineEdit *edit = new HbLineEdit(); |
|
99 HbAction *actionOk = new HbAction("Ok"); |
|
100 HbAction *actionCancel = new HbAction("Cancel"); |
|
101 |
|
102 title->setPlainText(text); |
|
103 popup->setHeadingWidget(title); |
|
104 popup->setContentWidget(edit); |
|
105 |
|
106 HbValidator *validator = new HbValidator(); |
|
107 QString tmp; |
|
108 if (acceptsZero == false) { |
|
109 tmp.append("[1-9]{1}\\d{1,4}"); |
|
110 } |
|
111 else { |
|
112 tmp.append("^[0-9]{5}"); |
|
113 } |
|
114 |
|
115 QRegExp rxBasic(tmp); |
|
116 validator->addField(new QRegExpValidator(rxBasic, 0), ""); |
|
117 edit->setValidator(validator); |
|
118 edit->setText(QString::number(numberOfEntries)); |
|
119 edit->setSelection(0, QString::number(numberOfEntries).length()); |
|
120 |
|
121 popup->setPrimaryAction(actionOk); |
|
122 popup->setSecondaryAction(actionCancel); |
|
123 |
|
124 // Launch popup syncronously |
|
125 popup->setAttribute(Qt::WA_DeleteOnClose); |
|
126 // TODO: handle dialog close & user input |
|
127 popup->open(); |
|
128 |
|
129 // continue if ok selected and valid user input exists in line editor |
|
130 /*if (action && action->text() == "Ok" && edit->text() != "") { |
|
131 numberOfEntries = edit->text().toInt(&err, 10); |
|
132 }*/ |
|
133 return err; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 bool Notifications::timeQueryDialog(QDate& date, const QString& text) |
|
138 { |
|
139 bool err = false; |
|
140 HbDialog *popup = new HbDialog(); |
|
141 popup->setDismissPolicy(HbPopup::TapOutside); |
|
142 popup->setTimeout(HbPopup::NoTimeout); |
|
143 |
|
144 HbLabel *title = new HbLabel(); |
|
145 HbLineEdit *edit = new HbLineEdit(); |
|
146 HbAction *actionOk = new HbAction("Ok"); |
|
147 HbAction *actionCancel = new HbAction("Cancel"); |
|
148 |
|
149 title->setPlainText(text); |
|
150 popup->setHeadingWidget(title); |
|
151 popup->setContentWidget(edit); |
|
152 |
|
153 HbValidator *validator =new HbValidator; |
|
154 QString dateString("(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\\d\\d"); |
|
155 QRegExp rxDate(dateString); |
|
156 validator->addField(new QRegExpValidator(rxDate, 0), ""); |
|
157 edit->setValidator(validator); |
|
158 edit->setText(date.toString()); |
|
159 edit->setSelection(0, date.toString().length()); |
|
160 |
|
161 |
|
162 popup->setPrimaryAction(actionOk); |
|
163 popup->setSecondaryAction(actionCancel); |
|
164 |
|
165 // Launch popup syncronously |
|
166 popup->setAttribute(Qt::WA_DeleteOnClose); |
|
167 // TODO: handle dialog close & user input |
|
168 popup->open(); |
|
169 |
|
170 // continue if ok selected and valid user input exists in line editor |
|
171 /*if (action && action->text() == "Ok" && edit->text() != "") { |
|
172 date = QDate::fromString(edit->text()); |
|
173 err = true; |
|
174 }*/ |
|
175 return err; |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 |
|
180 bool Notifications::yesNoQueryDialog(const QString& text) |
|
181 { |
|
182 HbMessageBox::question(text, 0, 0); |
|
183 return false; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 |
|
188 void Notifications::popupListDialog(const QString& text, QStringList& items, HbAbstractItemView::SelectionMode mode, QObject* receiver, const char* member) |
|
189 { |
|
190 HbSelectionDialog *dlg = new HbSelectionDialog; |
|
191 dlg->setHeadingWidget(new HbLabel(text, dlg)); |
|
192 dlg->setStringItems(items); |
|
193 dlg->setSelectionMode(mode); |
|
194 dlg->setAttribute(Qt::WA_DeleteOnClose); |
|
195 dlg->open(receiver, member); |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 |
|
200 bool Notifications::directoryQueryDialog(const QString& text, QString& directory) |
|
201 { |
|
202 bool err = false; |
|
203 HbDialog *popup = new HbDialog(); |
|
204 popup->setDismissPolicy(HbPopup::TapOutside); |
|
205 popup->setTimeout(HbPopup::NoTimeout); |
|
206 |
|
207 HbLabel *title = new HbLabel(); |
|
208 HbLineEdit *edit = new HbLineEdit(); |
|
209 HbAction *actionOk = new HbAction("Ok"); |
|
210 HbAction *actionCancel = new HbAction("Cancel"); |
|
211 |
|
212 title->setPlainText(text); |
|
213 popup->setHeadingWidget(title); |
|
214 popup->setContentWidget(edit); |
|
215 edit->setMaxLength(256); |
|
216 edit->setText(directory); |
|
217 edit->setSelection(0, directory.length()); |
|
218 |
|
219 popup->setPrimaryAction(actionOk); |
|
220 popup->setSecondaryAction(actionCancel); |
|
221 |
|
222 // Launch popup syncronously |
|
223 popup->setAttribute(Qt::WA_DeleteOnClose); |
|
224 // TODO: handle dialog close & user input |
|
225 popup->open(); |
|
226 |
|
227 // continue if ok selected and valid user input exists in line editor |
|
228 /*if (action && action->text() == "Ok" && edit->text() != "") { |
|
229 directory = edit->text(); |
|
230 err = true; |
|
231 }*/ |
|
232 return err; |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |