1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Touchgui/plugins/org.apache.cordova.dialogs/src/ubuntu/notification.cpp Thu Jun 04 14:50:33 2015 +0200 1.3 @@ -0,0 +1,85 @@ 1.4 +/* 1.5 + * 1.6 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.7 + * you may not use this file except in compliance with the License. 1.8 + * You may obtain a copy of the License at 1.9 + * 1.10 + * http://www.apache.org/licenses/LICENSE-2.0 1.11 + * 1.12 + * Unless required by applicable law or agreed to in writing, software 1.13 + * distributed under the License is distributed on an "AS IS" BASIS, 1.14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.15 + * See the License for the specific language governing permissions and 1.16 + * limitations under the License. 1.17 + */ 1.18 + 1.19 +#include "notification.h" 1.20 + 1.21 +#include <QApplication> 1.22 + 1.23 +void Dialogs::beep(int scId, int ecId, int times) { 1.24 + Q_UNUSED(scId) 1.25 + Q_UNUSED(ecId) 1.26 + Q_UNUSED(times) 1.27 + 1.28 + _player.setVolume(100); 1.29 + _player.setMedia(QUrl::fromLocalFile("/usr/share/sounds/ubuntu/stereo/bell.ogg")); 1.30 + _player.play(); 1.31 +} 1.32 + 1.33 +void Dialogs::alert(int scId, int ecId, const QString &message, const QString &title, const QString &buttonLabel) { 1.34 + QStringList list; 1.35 + list.append(buttonLabel); 1.36 + 1.37 + confirm(scId, ecId, message, title, list); 1.38 +} 1.39 + 1.40 +void Dialogs::confirm(int scId, int ecId, const QString &message, const QString &title, const QStringList &buttonLabels) { 1.41 + Q_UNUSED(ecId); 1.42 + 1.43 + if (_alertCallback) { 1.44 + qCritical() << "can't open second dialog"; 1.45 + return; 1.46 + } 1.47 + _alertCallback = scId; 1.48 + 1.49 + QString s1, s2, s3; 1.50 + if (buttonLabels.size() > 0) 1.51 + s1 = buttonLabels[0]; 1.52 + if (buttonLabels.size() > 1) 1.53 + s2 = buttonLabels[1]; 1.54 + if (buttonLabels.size() > 2) 1.55 + s3 = buttonLabels[2]; 1.56 + 1.57 + QString path = m_cordova->get_app_dir() + "/../qml/notification.qml"; 1.58 + QString qml = QString("PopupUtils.open(%1, root, { root: root, cordova: cordova, title: %2, text: %3, promptVisible: false, button1Text: %4, button2Text: %5, button3Text: %6 })") 1.59 + .arg(CordovaInternal::format(path)).arg(CordovaInternal::format(title)).arg(CordovaInternal::format(message)) 1.60 + .arg(CordovaInternal::format(s1)).arg(CordovaInternal::format(s2)).arg(CordovaInternal::format(s3)); 1.61 + 1.62 + m_cordova->execQML(qml); 1.63 +} 1.64 + 1.65 +void Dialogs::prompt(int scId, int ecId, const QString &message, const QString &title, const QStringList &buttonLabels, const QString &defaultText) { 1.66 + Q_UNUSED(ecId); 1.67 + 1.68 + if (_alertCallback) { 1.69 + qCritical() << "can't open second dialog"; 1.70 + return; 1.71 + } 1.72 + _alertCallback = scId; 1.73 + 1.74 + QString s1, s2, s3; 1.75 + if (buttonLabels.size() > 0) 1.76 + s1 = buttonLabels[0]; 1.77 + if (buttonLabels.size() > 1) 1.78 + s2 = buttonLabels[1]; 1.79 + if (buttonLabels.size() > 2) 1.80 + s3 = buttonLabels[2]; 1.81 + QString path = m_cordova->get_app_dir() + "/../qml/notification.qml"; 1.82 + 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 })") 1.83 + .arg(CordovaInternal::format(path)).arg(CordovaInternal::format(title)).arg(CordovaInternal::format(message)) 1.84 + .arg(CordovaInternal::format(s1)).arg(CordovaInternal::format(s2)) 1.85 + .arg(CordovaInternal::format(s3)).arg(CordovaInternal::format(defaultText)); 1.86 + 1.87 + m_cordova->execQML(qml); 1.88 +}