13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 #include <HbStyle> |
19 #include <QPainter> |
19 #include <HbStyleLoader> |
20 #include <hbframedrawer.h> |
20 #include <HbFrameItem> |
21 #include <hbframeitem.h> |
21 #include <HbFrameDrawer> |
22 #include <hbtextitem.h> |
22 #include <HbIconItem> |
23 #include <QLocale> |
23 #include <HbTextItem> |
|
24 #include <HbTouchArea> |
|
25 #include "dialerwidgetengine.h" |
|
26 |
24 #ifdef Q_OS_SYMBIAN |
27 #ifdef Q_OS_SYMBIAN |
25 #include <logsdomaincrkeys.h> |
|
26 #include "qtphonelog.h" |
28 #include "qtphonelog.h" |
27 #include <xqservicerequest.h> |
29 #include <xqservicerequest.h> |
28 #include <xqcallinfo.h> |
30 #include <xqcallinfo.h> |
29 #include <xqpublishandsubscribeutils.h> |
31 #include <xqpublishandsubscribeutils.h> |
30 #include <ctsydomainpskeys.h> |
|
31 #include <logsservices.h> |
32 #include <logsservices.h> |
|
33 #include <xqrequestinfo.h> |
|
34 #else |
|
35 #define PHONE_TRACE |
|
36 #define PHONE_TRACE1(A) |
|
37 #define PHONE_TRACE2(A, B) |
|
38 #define PHONE_TRACE3(A, B, C) |
|
39 #define PHONE_TRACE4(A, B, C, D) |
32 #endif |
40 #endif |
33 |
41 |
34 #include "hsdialerwidget.h" |
42 #include "hsdialerwidget.h" |
|
43 |
35 |
44 |
36 namespace |
45 namespace |
37 { |
46 { |
38 const char KDialerWidgetIcon[] = ":/icons/resource/qtg_graf_hs_dialer"; |
47 const char KDialerWidgetIcon[] = ":/icons/resource/qtg_graf_hs_dialer"; |
39 const char KMissedCallShortcutBadge[] = ":/icons/resource/qtg_fr_shortcut_badge_bg"; |
48 const char KMissedCallShortcutBadge[] = ":/icons/resource/qtg_fr_shortcut_badge_bg"; |
|
49 const char KDialerWidgetWidgetml[] = ":/data/resource/dialerwidget.widgetml"; |
|
50 const char KDialerWidgetCss[] = ":/data/resource/dialerwidget.css"; |
40 } |
51 } |
41 |
52 |
42 /*! |
53 /*! |
43 \class HsDialerWidget |
54 \class HsDialerWidget |
44 |
55 |
49 |
60 |
50 /*! |
61 /*! |
51 Constructs dialer widget with given \a parent and given window \a flags. |
62 Constructs dialer widget with given \a parent and given window \a flags. |
52 */ |
63 */ |
53 HsDialerWidget::HsDialerWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
64 HsDialerWidget::HsDialerWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
54 : HbWidget(parent, flags), |
65 : HsWidget(parent, flags), |
55 mXQCallInfo(0) |
66 mXQCallInfo(0), m_background(0), m_badgeBackground(0), m_text(0), m_touchArea(0) |
56 { |
67 { |
57 #ifdef Q_OS_SYMBIAN |
68 PHONE_TRACE |
58 m_setManager = new XQSettingsManager(this); |
|
59 |
|
60 XQSettingsKey settingsKey( XQSettingsKey::TargetCentralRepository, |
|
61 KCRUidLogs.iUid, KLogsNewMissedCalls ); |
|
62 |
|
63 bool ok = connect( m_setManager, |
|
64 SIGNAL( valueChanged(const XQSettingsKey & ,const QVariant &)), |
|
65 this, SLOT(updateMissedCallBadge(XQSettingsKey, |
|
66 QVariant))); |
|
67 ASSERT( ok ); |
|
68 ok = false; |
|
69 ok = m_setManager->startMonitoring( settingsKey ); |
|
70 ASSERT(ok); |
|
71 |
|
72 #endif |
|
73 |
|
74 HbFrameDrawer *drawer = new HbFrameDrawer( |
|
75 KDialerWidgetIcon, HbFrameDrawer::OnePiece); |
|
76 m_backgroud = new HbFrameItem(drawer, this); |
|
77 m_backgroud->setZValue(1); |
|
78 |
|
79 drawer = new HbFrameDrawer(KMissedCallShortcutBadge, |
|
80 HbFrameDrawer::ThreePiecesHorizontal ); |
|
81 |
|
82 m_shortcutBadge = new HbFrameItem(drawer, this); |
|
83 m_shortcutBadge->setZValue(2); |
|
84 m_shortcutBadge->setVisible(false); |
|
85 m_missedCalls=0; |
|
86 setItemPositions(); |
|
87 resize(preferredSize()); |
|
88 } |
69 } |
89 |
70 |
90 /*! |
71 /*! |
91 Destructor. |
72 Destructor. |
92 */ |
73 */ |
93 HsDialerWidget::~HsDialerWidget() |
74 HsDialerWidget::~HsDialerWidget() |
94 { |
75 { |
95 } |
76 PHONE_TRACE |
96 |
|
97 void HsDialerWidget::paint( |
|
98 QPainter *painter, |
|
99 const QStyleOptionGraphicsItem *option, |
|
100 QWidget *widget) |
|
101 { |
|
102 Q_UNUSED(option); |
|
103 Q_UNUSED(widget); |
|
104 painter->setPen(QPen( Qt::transparent ) ); |
|
105 |
|
106 QRectF rect(m_backgroud->boundingRect()); |
|
107 painter->drawRect((int)m_backgroud->pos().x(), |
|
108 (int)m_backgroud->pos().y(), |
|
109 rect.toRect().width(), |
|
110 rect.toRect().height()); |
|
111 |
|
112 if ( m_shortcutBadge->isVisible()) |
|
113 { |
|
114 rect = m_shortcutBadge->boundingRect(); |
|
115 HbTextItem *text = new HbTextItem( m_shortcutBadge->graphicsItem()); |
|
116 |
|
117 QFont badgefont = font(); |
|
118 #ifdef Q_OS_SYMBIAN |
|
119 badgefont.setPointSize( 4 ); |
|
120 #else |
|
121 badgefont.setPointSize( 8 ); |
|
122 #endif |
|
123 text->setFont(badgefont); |
|
124 text->setText(QLocale::system().toString(m_missedCalls)); |
|
125 text->setZValue(3); |
|
126 text->setTextColor(Qt::white); |
|
127 |
|
128 text->setX( ( rect.toRect().width() / 2 ) - 2); |
|
129 text->setY( ( rect.toRect().height() / 5 ) - 1); |
|
130 |
|
131 painter->drawRect( (int)m_shortcutBadge->pos().x(), |
|
132 (int)m_shortcutBadge->pos().y(), |
|
133 rect.toRect().width(), |
|
134 rect.toRect().height() ); |
|
135 } |
|
136 } |
77 } |
137 |
78 |
138 /*! |
79 /*! |
139 \fn void HsDialerWidget::startDialer() |
80 \fn void HsDialerWidget::startDialer() |
140 |
81 |
141 Starts dialer widget via view activation service. |
82 Starts dialer widget via view activation service. |
142 */ |
83 */ |
143 void HsDialerWidget::startDialer() |
84 void HsDialerWidget::startDialer() |
144 { |
85 { |
|
86 PHONE_TRACE |
145 #ifdef Q_OS_SYMBIAN |
87 #ifdef Q_OS_SYMBIAN |
146 PHONE_DEBUG("HsDialerWidget::startDialer"); |
88 PHONE_DEBUG("HsDialerWidget::startDialer"); |
147 |
89 |
148 if (!mXQCallInfo) { |
90 if (!mXQCallInfo) { |
149 mXQCallInfo = XQCallInfo::create(); |
91 mXQCallInfo = XQCallInfo::create(); |
150 mXQCallInfo->setParent(this); |
92 mXQCallInfo->setParent(this); |
151 } |
93 } |
152 |
|
153 QList<CallInfo> calls; |
94 QList<CallInfo> calls; |
154 mXQCallInfo->getCalls(calls); |
95 mXQCallInfo->getCalls(calls); |
155 |
96 |
156 if( 0 < calls.count() ){ |
97 if( 0 < calls.count() ){ |
157 PHONE_DEBUG("call ongoing, bring Telephone to foreground"); |
98 PHONE_DEBUG("call ongoing, bring Telephone to foreground"); |
165 } |
106 } |
166 else { |
107 else { |
167 PHONE_DEBUG("no calls, open Dialer"); |
108 PHONE_DEBUG("no calls, open Dialer"); |
168 XQServiceRequest snd("com.nokia.services.logsservices.starter", |
109 XQServiceRequest snd("com.nokia.services.logsservices.starter", |
169 "start(int,bool)", false); |
110 "start(int,bool)", false); |
|
111 XQRequestInfo info; |
|
112 info.setForeground(true); |
|
113 snd.setInfo(info); |
170 snd << (int)LogsServices::ViewAll; |
114 snd << (int)LogsServices::ViewAll; |
171 snd << true; |
115 snd << true; |
172 int retValue; |
116 int retValue; |
173 snd.send(retValue); |
117 snd.send(retValue); |
174 |
118 |
175 //LogsServices::start(LogsServices::ViewAll, true); |
119 //LogsServices::start(LogsServices::ViewAll, true); |
176 } |
120 } |
177 #endif |
121 #endif |
178 } |
122 |
179 |
123 } |
180 void HsDialerWidget::updateMissedCallBadge( |
124 |
181 const XQSettingsKey &key, const QVariant &value) |
125 void HsDialerWidget::onInitialize() |
182 { |
126 { |
183 #ifdef Q_OS_SYMBIAN |
127 PHONE_TRACE |
184 if ( key.key() == (quint32)KLogsNewMissedCalls ){ |
128 QT_TRY{ |
185 m_missedCalls = value.toInt(); |
129 // basic ui |
186 m_shortcutBadge->setVisible(value.toBool()); |
130 createPrimitives(); |
187 setItemPositions(); |
131 Q_ASSERT(HbStyleLoader::registerFilePath(KDialerWidgetWidgetml)); |
188 m_backgroud->update(); |
132 Q_ASSERT(HbStyleLoader::registerFilePath(KDialerWidgetCss)); |
189 } |
133 // Engine construction is 2 phased |
190 #else |
134 m_engine = new DialerWidgetEngine(); |
191 Q_UNUSED(key); |
135 connect(m_engine, SIGNAL( exceptionOccured(const int&) ) |
192 Q_UNUSED(value); |
136 ,this, SLOT( onEngineException(const int&) ) ); |
193 #endif |
137 |
|
138 if(!m_engine->initialize()){ |
|
139 //engine construction failed. Give up. |
|
140 emit error(); |
|
141 return; |
|
142 } |
|
143 connect( m_engine, SIGNAL(missedCallsCountChanged(const int&)), |
|
144 this, SLOT(onMissedCallsCountChange(const int&))); |
|
145 |
|
146 } |
|
147 QT_CATCH(...){ |
|
148 emit error(); |
|
149 } |
194 } |
150 } |
195 |
151 |
196 /*! |
152 /*! |
197 \fn void HsDialerWidget::onShow() |
153 \fn void HsDialerWidget::onShow() |
198 |
154 |
199 Shows the widget |
155 Shows the widget |
200 */ |
156 */ |
201 void HsDialerWidget::onShow() |
157 void HsDialerWidget::onShow() |
202 { |
158 { |
|
159 PHONE_TRACE |
|
160 updatePrimitives(); |
203 } |
161 } |
204 |
162 |
205 /*! |
163 /*! |
206 \fn void HsDialerWidget::onHide() |
164 \fn void HsDialerWidget::onHide() |
207 |
165 |
208 Hides the widget |
166 Hides the widget |
209 */ |
167 */ |
210 void HsDialerWidget::onHide() |
168 void HsDialerWidget::onHide() |
211 { |
169 { |
|
170 PHONE_TRACE |
|
171 } |
|
172 |
|
173 void HsDialerWidget::onUninitialize() |
|
174 { |
|
175 PHONE_TRACE |
|
176 HbStyleLoader::unregisterFilePath(KDialerWidgetWidgetml); |
|
177 HbStyleLoader::unregisterFilePath(KDialerWidgetCss); |
|
178 } |
|
179 |
|
180 void HsDialerWidget::onEngineException(const int& exc) |
|
181 { |
|
182 Q_UNUSED(exc); |
|
183 emit error(); |
|
184 } |
|
185 |
|
186 void HsDialerWidget::onMissedCallsCountChange(const int& count) |
|
187 { |
|
188 m_text->setText( QLocale::system().toString(count)); |
|
189 if ( count ){ |
|
190 m_text->setVisible(true); |
|
191 m_badgeBackground->setVisible(true); |
|
192 } else { |
|
193 m_text->setVisible(false); |
|
194 m_badgeBackground->setVisible(false); |
|
195 } |
212 } |
196 } |
213 |
197 |
214 /*! |
198 /*! |
215 \fn void HsDialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
199 \fn void HsDialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
216 |
200 |
217 Dialer widget start is triggered from release \a event. |
201 Dialer widget start is triggered from release \a event. |
218 \sa startDialer() |
202 \sa startDialer() |
219 */ |
203 */ |
220 void HsDialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
204 void HsDialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
221 { |
205 { |
222 Q_UNUSED(event); |
206 Q_UNUSED(event); |
223 startDialer(); |
207 startDialer(); |
224 } |
208 } |
225 |
209 |
226 void HsDialerWidget::setItemPositions() |
210 HsWidget::StartResult HsDialerWidget::onStart() |
227 { |
211 { |
228 HbIcon icon(KDialerWidgetIcon); |
212 return StartResultRunning; |
229 setPreferredWidth(icon.width()); |
213 } |
230 int badgeSize = 20; |
214 HsWidget::StopResult HsDialerWidget::onStop() |
231 if ( m_shortcutBadge->isVisible()){ |
215 { |
232 m_backgroud->setGeometry(QRectF(QPointF(0,badgeSize / 2 ), |
216 return StopResultFinished; |
233 QSizeF(icon.width(),icon.height()))); |
217 } |
234 m_shortcutBadge->setGeometry(QRectF( |
218 HsWidget::SuspendResult HsDialerWidget::onSuspend() |
235 QPointF(m_backgroud->boundingRect().width() - (badgeSize / 2),0 ), |
219 { |
236 QSizeF(badgeSize, badgeSize))); |
220 return SuspendResultSuspended; |
237 setPreferredHeight(icon.height()+(badgeSize / 2)); |
221 } |
238 } else { |
222 HsWidget::ResumeResult HsDialerWidget::onResume() |
239 m_backgroud->setGeometry(QRectF(QPointF(0,0), |
223 { |
240 QSizeF(icon.width(),icon.height()))); |
224 return ResumeResultRunning; |
241 setPreferredHeight(icon.height()); |
225 } |
242 } |
226 |
243 } |
227 void HsDialerWidget::createPrimitives() |
|
228 { |
|
229 setPreferredSize(100,100); |
|
230 // Background |
|
231 if (!m_background) { |
|
232 HbFrameDrawer *drawer = new HbFrameDrawer( |
|
233 KDialerWidgetIcon, HbFrameDrawer::OnePiece); |
|
234 m_background = new HbFrameItem(drawer, this); |
|
235 style()->setItemName(m_background, /*QLatin1String(*/"background"/*)*/); |
|
236 m_background->moveBy(0,10); |
|
237 m_background->resize(81,81); |
|
238 } |
|
239 |
|
240 // Badge background |
|
241 if (!m_badgeBackground) { |
|
242 HbFrameDrawer *badgedrawer = new HbFrameDrawer( |
|
243 KMissedCallShortcutBadge, HbFrameDrawer::ThreePiecesHorizontal); |
|
244 m_badgeBackground = new HbFrameItem(badgedrawer, this); |
|
245 style()->setItemName(m_background, QLatin1String("badgeBackground")); |
|
246 m_badgeBackground->resize(20,20); |
|
247 m_badgeBackground->moveBy(70,0); |
|
248 m_badgeBackground->setVisible(true); |
|
249 m_badgeBackground->setVisible( false ); |
|
250 } |
|
251 |
|
252 // Text |
|
253 if (!m_text) { |
|
254 m_text = new HbTextItem(this); |
|
255 style()->setItemName(m_text, QLatin1String("text")); |
|
256 m_text->resize(20,20); |
|
257 m_text->moveBy(76,0); |
|
258 m_text->setVisible(true); |
|
259 HbFontSpec *textFont = new HbFontSpec(HbFontSpec::Primary); |
|
260 textFont->setTextHeight(3*HbDeviceProfile::current().unitValue()); |
|
261 m_text->setFontSpec(*textFont); |
|
262 m_text->setText("0"); |
|
263 m_text->setVisible( false); |
|
264 } |
|
265 |
|
266 // Touch Area |
|
267 if (!m_touchArea) { |
|
268 m_touchArea = new HbTouchArea(this); |
|
269 m_touchArea->installEventFilter(this); |
|
270 style()->setItemName(m_touchArea, QLatin1String("touch_area")); |
|
271 m_touchArea->moveBy(0,10); |
|
272 m_touchArea->resize(81,81); |
|
273 } |
|
274 } |