Touchgui/plugins/org.apache.cordova.dialogs/src/ubuntu/notification.cpp

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

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

mercurial