|
1 /* |
|
2 * |
|
3 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 * you may not use this file except in compliance with the License. |
|
5 * You may obtain a copy of the License at |
|
6 * |
|
7 * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 * |
|
9 * Unless required by applicable law or agreed to in writing, software |
|
10 * distributed under the License is distributed on an "AS IS" BASIS, |
|
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 * See the License for the specific language governing permissions and |
|
13 * limitations under the License. |
|
14 */ |
|
15 |
|
16 #include "notification.h" |
|
17 |
|
18 #include <QApplication> |
|
19 |
|
20 void Dialogs::beep(int scId, int ecId, int times) { |
|
21 Q_UNUSED(scId) |
|
22 Q_UNUSED(ecId) |
|
23 Q_UNUSED(times) |
|
24 |
|
25 _player.setVolume(100); |
|
26 _player.setMedia(QUrl::fromLocalFile("/usr/share/sounds/ubuntu/stereo/bell.ogg")); |
|
27 _player.play(); |
|
28 } |
|
29 |
|
30 void Dialogs::alert(int scId, int ecId, const QString &message, const QString &title, const QString &buttonLabel) { |
|
31 QStringList list; |
|
32 list.append(buttonLabel); |
|
33 |
|
34 confirm(scId, ecId, message, title, list); |
|
35 } |
|
36 |
|
37 void Dialogs::confirm(int scId, int ecId, const QString &message, const QString &title, const QStringList &buttonLabels) { |
|
38 Q_UNUSED(ecId); |
|
39 |
|
40 if (_alertCallback) { |
|
41 qCritical() << "can't open second dialog"; |
|
42 return; |
|
43 } |
|
44 _alertCallback = scId; |
|
45 |
|
46 QString s1, s2, s3; |
|
47 if (buttonLabels.size() > 0) |
|
48 s1 = buttonLabels[0]; |
|
49 if (buttonLabels.size() > 1) |
|
50 s2 = buttonLabels[1]; |
|
51 if (buttonLabels.size() > 2) |
|
52 s3 = buttonLabels[2]; |
|
53 |
|
54 QString path = m_cordova->get_app_dir() + "/../qml/notification.qml"; |
|
55 QString qml = QString("PopupUtils.open(%1, root, { root: root, cordova: cordova, title: %2, text: %3, promptVisible: false, button1Text: %4, button2Text: %5, button3Text: %6 })") |
|
56 .arg(CordovaInternal::format(path)).arg(CordovaInternal::format(title)).arg(CordovaInternal::format(message)) |
|
57 .arg(CordovaInternal::format(s1)).arg(CordovaInternal::format(s2)).arg(CordovaInternal::format(s3)); |
|
58 |
|
59 m_cordova->execQML(qml); |
|
60 } |
|
61 |
|
62 void Dialogs::prompt(int scId, int ecId, const QString &message, const QString &title, const QStringList &buttonLabels, const QString &defaultText) { |
|
63 Q_UNUSED(ecId); |
|
64 |
|
65 if (_alertCallback) { |
|
66 qCritical() << "can't open second dialog"; |
|
67 return; |
|
68 } |
|
69 _alertCallback = scId; |
|
70 |
|
71 QString s1, s2, s3; |
|
72 if (buttonLabels.size() > 0) |
|
73 s1 = buttonLabels[0]; |
|
74 if (buttonLabels.size() > 1) |
|
75 s2 = buttonLabels[1]; |
|
76 if (buttonLabels.size() > 2) |
|
77 s3 = buttonLabels[2]; |
|
78 QString path = m_cordova->get_app_dir() + "/../qml/notification.qml"; |
|
79 QString qml = QString("PopupUtils.open(%1, root, { root: root, cordova: cordova, title: %2, text: %3, promptVisible: true, defaultPromptText: %7, button1Text: %4, button2Text: %5, button3Text: %6 })") |
|
80 .arg(CordovaInternal::format(path)).arg(CordovaInternal::format(title)).arg(CordovaInternal::format(message)) |
|
81 .arg(CordovaInternal::format(s1)).arg(CordovaInternal::format(s2)) |
|
82 .arg(CordovaInternal::format(s3)).arg(CordovaInternal::format(defaultText)); |
|
83 |
|
84 m_cordova->execQML(qml); |
|
85 } |