|
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 "xqservicelog.h" |
|
23 |
|
24 #include <hbapplication.h> |
|
25 #include <hbtoolbar.h> |
|
26 #include <hbaction.h> |
|
27 #include <HbLineEdit.h> |
|
28 #include <hblabel.h> |
|
29 #include <QTimer> |
|
30 #include <QGraphicsLinearLayout> |
|
31 |
|
32 #include <hbserviceproviderview.h> |
|
33 #include <xqserviceprovider.h> |
|
34 #include <xqservicerequest.h> |
|
35 #include <xqserviceutil.h> |
|
36 |
|
37 HbDialerView::HbDialerView(DialerService* service,QGraphicsItem *parent) |
|
38 : mService(service), |
|
39 HbView(parent), |
|
40 doomsdayTimer(), |
|
41 doomsdayCounter(5) |
|
42 { |
|
43 XQSERVICE_DEBUG_PRINT("HbDialerView::HbDialerView"); |
|
44 sndEmbedded = NULL; |
|
45 if (XQServiceUtil::isService()) |
|
46 { |
|
47 setTitle(tr("HB Dialer As Service")); |
|
48 } |
|
49 else |
|
50 { |
|
51 setTitle(tr("HB Dialer As Non-Service")); |
|
52 } |
|
53 |
|
54 HbToolBar* toolBar = this->toolBar(); |
|
55 |
|
56 HbAction* endAction = new HbAction("End Call"); |
|
57 connect(endAction, SIGNAL(triggered()), this, SLOT(quit())); |
|
58 |
|
59 toolBar->addAction(endAction); |
|
60 |
|
61 if (XQServiceUtil::isEmbedded()) { |
|
62 HbAction* embeddedAction = new HbAction("Embed"); |
|
63 connect(embeddedAction, SIGNAL(triggered()), this, SLOT(embed())); |
|
64 toolBar->addAction(embeddedAction); |
|
65 } |
|
66 |
|
67 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical,this); |
|
68 |
|
69 mTextEdit = new HbLineEdit(this); |
|
70 mRetValue = new HbLineEdit(this); |
|
71 timerLabel = new HbLabel("..."); |
|
72 layout->addItem(mTextEdit); |
|
73 layout->addItem(mRetValue); |
|
74 layout->addItem(timerLabel); |
|
75 setLayout(layout); |
|
76 bool con = connect(&doomsdayTimer, SIGNAL(timeout()), this, SLOT(tick())); |
|
77 //doomsdayTimer.start(1000); |
|
78 } |
|
79 |
|
80 HbDialerView::~HbDialerView() |
|
81 { |
|
82 XQSERVICE_DEBUG_PRINT("HbDialerView::~HbDialerView"); |
|
83 } |
|
84 |
|
85 void HbDialerView::quit() |
|
86 { |
|
87 XQSERVICE_DEBUG_PRINT("HbDialerView::quit"); |
|
88 connect(mService, SIGNAL(returnValueDelivered()), qApp, SLOT(quit())); |
|
89 mService->complete(); |
|
90 } |
|
91 |
|
92 void HbDialerView::tick() |
|
93 { |
|
94 if (doomsdayCounter>1) { |
|
95 doomsdayCounter--; |
|
96 timerLabel->setPlainText(QString("%1").arg(doomsdayCounter)); |
|
97 } else if (doomsdayCounter == 1) { |
|
98 quit(); |
|
99 } else { |
|
100 doomsdayTimer.stop(); |
|
101 qApp->quit(); |
|
102 } |
|
103 } |
|
104 |
|
105 void HbDialerView::embed() |
|
106 { |
|
107 XQSERVICE_DEBUG_PRINT("HbDialerView::embed"); |
|
108 if (sndEmbedded) |
|
109 delete sndEmbedded; |
|
110 |
|
111 //XQServiceRequest snd("com.nokia.services.hbserviceprovider.Dialer","dial(QString)",true); |
|
112 sndEmbedded = new XQServiceRequest("serviceapp.Dialer","dial(QString,bool)",true); |
|
113 connect(sndEmbedded, SIGNAL(requestCompleted(QVariant)), this, SLOT(requestCompleted(QVariant))); |
|
114 *sndEmbedded << mTextEdit->text(); |
|
115 *sndEmbedded << true; |
|
116 QVariant retValue; |
|
117 bool res=sndEmbedded->send(); |
|
118 if (!res) { |
|
119 mRetValue->setText("send fail!"); |
|
120 } |
|
121 } |
|
122 |
|
123 void HbDialerView::requestCompleted(const QVariant& value) |
|
124 { |
|
125 XQSERVICE_DEBUG_PRINT("HbDialerView::requestCompleted"); |
|
126 mRetValue->setText(value.toString()); |
|
127 } |
|
128 |
|
129 void HbDialerView::setNumber(const QString& number) |
|
130 { |
|
131 XQSERVICE_DEBUG_PRINT("HbDialerView::setNumber"); |
|
132 mTextEdit->setText("Call from " + number); |
|
133 } |
|
134 |
|
135 DialerService::DialerService(QObject* parent) |
|
136 : XQServiceProvider("com.nokia.services.hbserviceprovider.Dialer",parent) |
|
137 { |
|
138 XQSERVICE_DEBUG_PRINT("DialerService::DialerService"); |
|
139 publishAll(); |
|
140 } |
|
141 |
|
142 DialerService::~DialerService() |
|
143 { |
|
144 XQSERVICE_DEBUG_PRINT("DialerService::~DialerService"); |
|
145 } |
|
146 |
|
147 void DialerService::complete() |
|
148 { |
|
149 XQSERVICE_DEBUG_PRINT("DialerService::complete"); |
|
150 QString retvalue = "retValue="+mNumber; |
|
151 completeRequest(1,retvalue); |
|
152 } |
|
153 |
|
154 QString DialerService::dial(const QString& number) |
|
155 { |
|
156 XQSERVICE_DEBUG_PRINT("DialerService::dial"); |
|
157 mNumber = number ; |
|
158 emit showView("dialer"); |
|
159 emit setNumber(number); |
|
160 setCurrentRequestAsync(); |
|
161 return "retValue="+number; |
|
162 } |
|
163 |
|
164 QString DialerService::dial(const QString& number, bool async) |
|
165 { |
|
166 XQSERVICE_DEBUG_PRINT("DialerService::dial (2)"); |
|
167 return dial(number); |
|
168 } |
|
169 |
|
170 Q_IMPLEMENT_USER_METATYPE(HbContact) |
|
171 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(HbContactList) |
|
172 |