1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <QPainter> |
|
20 #include <hbframedrawer.h> |
|
21 #include <hbframeitem.h> |
|
22 #include <hbtextitem.h> |
|
23 #include <QLocale> |
|
24 #ifdef Q_OS_SYMBIAN |
|
25 #include <logsdomaincrkeys.h> |
|
26 #include "qtphonelog.h" |
|
27 #include <xqservicerequest.h> |
|
28 #include <xqcallinfo.h> |
|
29 #include <xqpublishandsubscribeutils.h> |
|
30 #include <ctsydomainpskeys.h> |
|
31 #include <logsservices.h> |
|
32 #endif |
|
33 |
|
34 #include "hsdialerwidget.h" |
|
35 |
|
36 namespace |
|
37 { |
|
38 const char KDialerWidgetIcon[] = ":/icons/resource/qtg_graf_hs_dialer"; |
|
39 const char KMissedCallShortcutBadge[] = ":/icons/resource/qtg_fr_shortcut_badge_bg"; |
|
40 } |
|
41 |
|
42 /*! |
|
43 \class HsDialerWidget |
|
44 |
|
45 \ingroup group_hsdialerwidgetplugin |
|
46 \brief Implementation for the homescreen dialer launcher. |
|
47 |
|
48 */ |
|
49 |
|
50 /*! |
|
51 Constructs dialer widget with given \a parent and given window \a flags. |
|
52 */ |
|
53 HsDialerWidget::HsDialerWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
|
54 : HbWidget(parent, flags), |
|
55 mXQCallInfo(0) |
|
56 { |
|
57 #ifdef Q_OS_SYMBIAN |
|
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 } |
|
89 |
|
90 /*! |
|
91 Destructor. |
|
92 */ |
|
93 HsDialerWidget::~HsDialerWidget() |
|
94 { |
|
95 } |
|
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 } |
|
137 |
|
138 /*! |
|
139 \fn void HsDialerWidget::startDialer() |
|
140 |
|
141 Starts dialer widget via view activation service. |
|
142 */ |
|
143 void HsDialerWidget::startDialer() |
|
144 { |
|
145 #ifdef Q_OS_SYMBIAN |
|
146 PHONE_DEBUG("HsDialerWidget::startDialer"); |
|
147 |
|
148 if (!mXQCallInfo) { |
|
149 mXQCallInfo = XQCallInfo::create(); |
|
150 mXQCallInfo->setParent(this); |
|
151 } |
|
152 |
|
153 QList<CallInfo> calls; |
|
154 mXQCallInfo->getCalls(calls); |
|
155 |
|
156 if( 0 < calls.count() ){ |
|
157 PHONE_DEBUG("call ongoing, bring Telephone to foreground"); |
|
158 |
|
159 // ToDo: should telephone + dialpad be opened when there is a waiting call? |
|
160 int dialer(1); |
|
161 XQServiceRequest snd("com.nokia.services.telephony.uistarter", "start(int)", false); |
|
162 snd << dialer; |
|
163 QVariant retValue; |
|
164 snd.send(retValue); |
|
165 } |
|
166 else { |
|
167 PHONE_DEBUG("no calls, open Dialer"); |
|
168 XQServiceRequest snd("com.nokia.services.logsservices.starter", |
|
169 "start(int,bool)", false); |
|
170 snd << (int)LogsServices::ViewAll; |
|
171 snd << true; |
|
172 int retValue; |
|
173 snd.send(retValue); |
|
174 |
|
175 //LogsServices::start(LogsServices::ViewAll, true); |
|
176 } |
|
177 #endif |
|
178 } |
|
179 |
|
180 void HsDialerWidget::updateMissedCallBadge( |
|
181 const XQSettingsKey &key, const QVariant &value) |
|
182 { |
|
183 #ifdef Q_OS_SYMBIAN |
|
184 if ( key.key() == (quint32)KLogsNewMissedCalls ){ |
|
185 m_missedCalls = value.toInt(); |
|
186 m_shortcutBadge->setVisible(value.toBool()); |
|
187 setItemPositions(); |
|
188 m_backgroud->update(); |
|
189 } |
|
190 #else |
|
191 Q_UNUSED(key); |
|
192 Q_UNUSED(value); |
|
193 #endif |
|
194 } |
|
195 |
|
196 /*! |
|
197 \fn void HsDialerWidget::onShow() |
|
198 |
|
199 Shows the widget |
|
200 */ |
|
201 void HsDialerWidget::onShow() |
|
202 { |
|
203 } |
|
204 |
|
205 /*! |
|
206 \fn void HsDialerWidget::onHide() |
|
207 |
|
208 Hides the widget |
|
209 */ |
|
210 void HsDialerWidget::onHide() |
|
211 { |
|
212 } |
|
213 |
|
214 /*! |
|
215 \fn void HsDialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
|
216 |
|
217 Dialer widget start is triggered from release \a event. |
|
218 \sa startDialer() |
|
219 */ |
|
220 void HsDialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
|
221 { |
|
222 Q_UNUSED(event); |
|
223 startDialer(); |
|
224 } |
|
225 |
|
226 void HsDialerWidget::setItemPositions() |
|
227 { |
|
228 HbIcon icon(KDialerWidgetIcon); |
|
229 setPreferredWidth(icon.width()); |
|
230 int badgeSize = 20; |
|
231 if ( m_shortcutBadge->isVisible()){ |
|
232 m_backgroud->setGeometry(QRectF(QPointF(0,badgeSize / 2 ), |
|
233 QSizeF(icon.width(),icon.height()))); |
|
234 m_shortcutBadge->setGeometry(QRectF( |
|
235 QPointF(m_backgroud->boundingRect().width() - (badgeSize / 2),0 ), |
|
236 QSizeF(badgeSize, badgeSize))); |
|
237 setPreferredHeight(icon.height()+(badgeSize / 2)); |
|
238 } else { |
|
239 m_backgroud->setGeometry(QRectF(QPointF(0,0), |
|
240 QSizeF(icon.width(),icon.height()))); |
|
241 setPreferredHeight(icon.height()); |
|
242 } |
|
243 } |
|