|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include <QtGlobal> |
|
23 #include <QApplication> |
|
24 #include <QKeyEvent> |
|
25 #include <QLabel> |
|
26 #include <QStackedWidget> |
|
27 #include <QImageReader> |
|
28 #include <QDebug> |
|
29 #include <QTimer> |
|
30 #include <QPushButton> |
|
31 #include <QList> |
|
32 #include <QLineEdit> |
|
33 #include <QString> |
|
34 #include <QCheckBox> |
|
35 #include <QAction> |
|
36 #include <QListView> |
|
37 #include <QUrl> |
|
38 #include <QFileInfo> |
|
39 #include <math.h> |
|
40 #include <QCompleter> |
|
41 #include <xqserviceglobal.h> |
|
42 #include <QDir> |
|
43 #include <QTranslator> |
|
44 #include <cntservicescontact.h> |
|
45 |
|
46 #include <XQSharableFile.h> |
|
47 |
|
48 // Include declarations to see if any compilation issues |
|
49 #include <xqaiwdecl.h> |
|
50 #include <xqaiwdeclplat.h> |
|
51 |
|
52 #include "notreceiver.h" |
|
53 |
|
54 #define CONNECT_ASSERT(a, b, c, d) if (!QObject::connect((a), (b), (c), (d))) { \ |
|
55 qWarning("connection failed!"); \ |
|
56 qApp->exit(0); \ |
|
57 exit(0); \ |
|
58 } |
|
59 |
|
60 |
|
61 QString NotificationsReceiver::POOLING_TEMPLATE("pooling: %1"); |
|
62 QString NotificationsReceiver::NOTIFY_TEMPLATE("notification: %1"); |
|
63 |
|
64 NotificationsReceiver::NotificationsReceiver(QWidget *parent, Qt::WFlags f) |
|
65 : QWidget(parent, f), |
|
66 poolingTimer(), |
|
67 pooledDescr(0) |
|
68 { |
|
69 mgr = new XQApplicationManager(); |
|
70 |
|
71 CONNECT_ASSERT(&poolingTimer, SIGNAL(timeout()), this, SLOT(poolForService())); |
|
72 |
|
73 bool ok; |
|
74 |
|
75 ok = QObject::connect(mgr, SIGNAL(serviceStarted(XQAiwInterfaceDescriptor)), this, SLOT(serviceStarted(XQAiwInterfaceDescriptor))); |
|
76 ok = QObject::connect(mgr, SIGNAL(serviceStopped(XQAiwInterfaceDescriptor)), this, SLOT(serviceStopped(XQAiwInterfaceDescriptor))); |
|
77 |
|
78 initUi(); |
|
79 |
|
80 XQAiwInterfaceDescriptor descr(); |
|
81 |
|
82 QString serviceName = QString("com.nokia.services.hbserviceprovider"); |
|
83 QString interfaceName = QString("Dialer"); |
|
84 QString opName = "dial(QString,bool)"; |
|
85 |
|
86 QList<XQAiwInterfaceDescriptor> dscrList = mgr->list(serviceName, interfaceName, opName); |
|
87 |
|
88 if (dscrList.size() == 1) { |
|
89 XQAiwInterfaceDescriptor dscr = dscrList.at(0); |
|
90 mgr->notifyRunning(dscr); |
|
91 qDebug() << "Start notifications for: " << dscr.serviceName() << " " << dscr.interfaceName(); |
|
92 if (mgr->isRunning(dscr)) { |
|
93 serviceStarted(dscr); |
|
94 } else { |
|
95 serviceStopped(dscr); |
|
96 } |
|
97 labelServiceName->setText(serviceName + "." + interfaceName + "." + opName); |
|
98 pooledDescr = new XQAiwInterfaceDescriptor(dscr); |
|
99 } else { |
|
100 qWarning("Whoops, requested service not found."); |
|
101 labelServiceName->setText("service not found"); |
|
102 } |
|
103 |
|
104 poolingTimer.start(1000); |
|
105 } |
|
106 |
|
107 void NotificationsReceiver::initUi() |
|
108 { |
|
109 /* Adjust the palette */ |
|
110 #if defined(Q_WS_S60) |
|
111 QPalette p = qApp->palette(); |
|
112 QColor color(192,192,192); |
|
113 QColor bg(208, 242, 209); |
|
114 p.setColor(QPalette::Highlight, color.lighter(200)); |
|
115 p.setColor(QPalette::Text, Qt::black); |
|
116 p.setColor(QPalette::Base, bg); |
|
117 p.setColor(QPalette::WindowText, Qt::black); |
|
118 p.setColor(QPalette::Window, bg); |
|
119 p.setColor(QPalette::ButtonText, Qt::black); |
|
120 p.setColor(QPalette::Button, color.lighter(150)); |
|
121 p.setColor(QPalette::Link, QColor(240,40,40)); |
|
122 qApp->setPalette(p); |
|
123 #endif |
|
124 QPushButton *quitButton = new QPushButton(tr("quit")); |
|
125 connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); |
|
126 |
|
127 labelServiceName = new QLabel("...service name..."); |
|
128 labelPoolingResult = new QLabel(POOLING_TEMPLATE); |
|
129 labelNotifyResult = new QLabel(NOTIFY_TEMPLATE); |
|
130 |
|
131 vl = new QVBoxLayout; |
|
132 vl->setMargin(10); |
|
133 vl->setSpacing(5); |
|
134 |
|
135 vl->addWidget(labelServiceName); |
|
136 vl->addWidget(labelPoolingResult); |
|
137 vl->addWidget(labelNotifyResult); |
|
138 |
|
139 vl->insertStretch(-1); |
|
140 vl->addWidget(quitButton); |
|
141 |
|
142 setLayout(vl); |
|
143 |
|
144 #if defined(Q_WS_X11) || defined(Q_WS_WIN) |
|
145 setFixedSize(QSize(360,640)); // nHD |
|
146 #elif defined(Q_WS_S60) |
|
147 // showMaximized(); |
|
148 showFullScreen(); |
|
149 #endif |
|
150 } |
|
151 |
|
152 NotificationsReceiver::~NotificationsReceiver() |
|
153 { |
|
154 delete mgr; |
|
155 delete pooledDescr; |
|
156 } |
|
157 |
|
158 void NotificationsReceiver::serviceStarted(XQAiwInterfaceDescriptor dscr) |
|
159 { |
|
160 qDebug("service started"); |
|
161 labelNotifyResult->setText("[N] service started"); |
|
162 } |
|
163 |
|
164 void NotificationsReceiver::serviceStopped(XQAiwInterfaceDescriptor dscr) |
|
165 { |
|
166 qDebug("service started"); |
|
167 labelNotifyResult->setText("[N] service stopped"); |
|
168 } |
|
169 |
|
170 void NotificationsReceiver::poolForService() |
|
171 { |
|
172 qDebug(__PRETTY_FUNCTION__); |
|
173 XQAiwInterfaceDescriptor d(*pooledDescr); |
|
174 labelPoolingResult->setText(QString("[P] service %1").arg(mgr->isRunning(*pooledDescr) ? "running" : "stopped")); |
|
175 } |
|
176 |