|
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: Shortcut widget |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QGraphicsLinearLayout> |
|
19 |
|
20 #include <HbStackedLayout> |
|
21 #include <HbIconItem> |
|
22 #include <HbTextItem> |
|
23 |
|
24 #include "hsshortcutwidget.h" |
|
25 #include "hsshortcutservice.h" |
|
26 |
|
27 #include "caservice.h" |
|
28 #include "canotifier.h" |
|
29 |
|
30 /*! |
|
31 \class HsShortcutWidget |
|
32 \ingroup group_hsshortcutwidgetprovider |
|
33 \brief Implementation for the homescreen shortcut widget. |
|
34 |
|
35 Shortcut can be defined to launch different applications or applications |
|
36 with parameters, for example browser with certain url. |
|
37 |
|
38 \section how_to_use_shortcut_plugin How to use HsShortcutWidget |
|
39 |
|
40 At the moment code is compiled with homescreen core implementation. |
|
41 |
|
42 */ |
|
43 |
|
44 /*! |
|
45 |
|
46 Constructs shortcut widget object |
|
47 */ |
|
48 HsShortcutWidget::HsShortcutWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
|
49 : HbWidget(parent, flags), |
|
50 mShortcutBackgroundItem(0), |
|
51 mShortcutIconItem(0), |
|
52 mShortcutTextItem(0), |
|
53 mMcsId(-1) |
|
54 { |
|
55 setPreferredSize(QSizeF(82,82)); |
|
56 resize(82,82); |
|
57 } |
|
58 |
|
59 /*! |
|
60 \fn HsShortcutWidget::~HsShortcutWidget() |
|
61 |
|
62 Destructor |
|
63 */ |
|
64 HsShortcutWidget::~HsShortcutWidget() |
|
65 { |
|
66 } |
|
67 |
|
68 /*! |
|
69 Getter for menu content service id |
|
70 */ |
|
71 int HsShortcutWidget::mcsId() const |
|
72 { |
|
73 return mMcsId; |
|
74 } |
|
75 |
|
76 /*! |
|
77 Sets menu content service id to \a mcsId |
|
78 */ |
|
79 void HsShortcutWidget::setMcsId(int mcsId) |
|
80 { |
|
81 mMcsId = mcsId; |
|
82 } |
|
83 |
|
84 /*! |
|
85 \fn void HsShortcutWidget::onEntryChanged(const CaEntry &entry, ChangeType changeType) |
|
86 |
|
87 Invoked when \a entry has changed with a \a changeType event. |
|
88 */ |
|
89 void HsShortcutWidget::onEntryChanged(const CaEntry &entry, ChangeType changeType) |
|
90 { |
|
91 |
|
92 switch(changeType) { |
|
93 case RemoveChangeType: { |
|
94 emit finished(); |
|
95 break; |
|
96 } |
|
97 case UpdateChangeType: { |
|
98 hideOrShowWidget(entry.flags()); |
|
99 mShortcutIconItem->setIcon(fetchIcon(mMcsId)); |
|
100 |
|
101 QString text = fetchText(mMcsId); |
|
102 mShortcutTextItem->setText(text); |
|
103 break; |
|
104 } |
|
105 default: |
|
106 break; |
|
107 } |
|
108 } |
|
109 |
|
110 /*! |
|
111 \fn void HsShortcutWidget::onInitialize() |
|
112 |
|
113 Initializes shortcut |
|
114 */ |
|
115 void HsShortcutWidget::onInitialize() |
|
116 { |
|
117 constructUI(); |
|
118 |
|
119 if (!HsShortcutService::instance() || mMcsId < 0) { |
|
120 emit finished(); |
|
121 } |
|
122 |
|
123 createCaNotifier(mMcsId); |
|
124 |
|
125 mShortcutIconItem->setIcon(fetchIcon(mMcsId)); |
|
126 |
|
127 QString text = fetchText(mMcsId); |
|
128 mShortcutTextItem->setText(text); |
|
129 |
|
130 setEnabled(true); |
|
131 } |
|
132 |
|
133 /*! |
|
134 \fn void HsClockWidget::show() |
|
135 |
|
136 Shows the widget |
|
137 */ |
|
138 void HsShortcutWidget::onShow() |
|
139 { |
|
140 hideOrShowWidget(fetchEntryFlags(mMcsId)); |
|
141 } |
|
142 |
|
143 /*! |
|
144 \fn void HsClockWidget::show() |
|
145 |
|
146 Hides the widget |
|
147 */ |
|
148 void HsShortcutWidget::onHide() |
|
149 { |
|
150 hide(); |
|
151 } |
|
152 |
|
153 /*! |
|
154 \fn void HsShortcutWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
155 |
|
156 Executes configured action |
|
157 */ |
|
158 void HsShortcutWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
159 { |
|
160 Q_UNUSED(event) |
|
161 |
|
162 CaEntry *entry = CaService::instance()->getEntry(mMcsId); |
|
163 if (!entry) { |
|
164 return; |
|
165 } |
|
166 |
|
167 if (entry->role() == ItemEntryRole) { |
|
168 CaService::instance()->executeCommand(mMcsId); |
|
169 } else { |
|
170 executeCollectionAction(mMcsId, entry->entryTypeName()); |
|
171 } |
|
172 } |
|
173 |
|
174 /*! |
|
175 \fn void HsShortcutWidget::constructUI() |
|
176 |
|
177 Constructs and initializes ui parts |
|
178 */ |
|
179 void HsShortcutWidget::constructUI() |
|
180 { |
|
181 mShortcutBackgroundItem = new HbIconItem("hs_shortcut_bg"); |
|
182 mShortcutBackgroundItem->setAlignment(Qt::AlignCenter); |
|
183 mShortcutIconItem = new HbIconItem; |
|
184 mShortcutIconItem->setAlignment(Qt::AlignCenter); |
|
185 mShortcutTextItem = new HbTextItem; |
|
186 mShortcutTextItem->setAlignment(Qt::AlignCenter); |
|
187 |
|
188 HbStackedLayout *mainLayout = new HbStackedLayout; |
|
189 mainLayout->addItem(mShortcutBackgroundItem); |
|
190 |
|
191 QGraphicsLinearLayout *contentLayout = |
|
192 new QGraphicsLinearLayout(Qt::Vertical); |
|
193 contentLayout->setContentsMargins(4, 4, 4, 4); |
|
194 contentLayout->addItem(mShortcutIconItem); |
|
195 contentLayout->addItem(mShortcutTextItem); |
|
196 mainLayout->addItem(contentLayout); |
|
197 |
|
198 setLayout(mainLayout); |
|
199 } |
|
200 |
|
201 /*! |
|
202 \internal |
|
203 */ |
|
204 HbIcon HsShortcutWidget::fetchIcon(int aShortcutId) |
|
205 { |
|
206 CaEntry *entry = CaService::instance()->getEntry(aShortcutId); |
|
207 if (!entry) { |
|
208 return HbIcon(); |
|
209 } |
|
210 return entry->makeIcon(); |
|
211 } |
|
212 |
|
213 /*! |
|
214 \internal |
|
215 */ |
|
216 QString HsShortcutWidget::fetchText(int aShortcutId) |
|
217 { |
|
218 CaEntry *entry = CaService::instance()->getEntry(aShortcutId); |
|
219 if (!entry) { |
|
220 return QString(); |
|
221 } |
|
222 return entry->text(); |
|
223 } |
|
224 |
|
225 /*! |
|
226 \internal |
|
227 */ |
|
228 void HsShortcutWidget::executeCollectionAction( |
|
229 int shortcutId, const QString& collectionType) |
|
230 { |
|
231 HsShortcutService::instance()->executeCollectionAction( |
|
232 shortcutId, collectionType); |
|
233 } |
|
234 |
|
235 /*! |
|
236 \internal |
|
237 */ |
|
238 void HsShortcutWidget::createCaNotifier(int aShortcutId) |
|
239 { |
|
240 CaNotifierFilter filter; |
|
241 filter.setIds(QList<int>() << aShortcutId); |
|
242 |
|
243 CaNotifier *itemNotifier = CaService::instance()->createNotifier(filter); |
|
244 itemNotifier->setParent(this); |
|
245 |
|
246 connect(itemNotifier, |
|
247 SIGNAL(entryChanged(const CaEntry&, ChangeType)), |
|
248 SLOT(onEntryChanged(const CaEntry&, ChangeType)),Qt::QueuedConnection); |
|
249 } |
|
250 |
|
251 /*! |
|
252 \internal |
|
253 */ |
|
254 void HsShortcutWidget::hideOrShowWidget(EntryFlags aEntryFlags) |
|
255 { |
|
256 if (aEntryFlags.testFlag(MissingEntryFlag)) { |
|
257 hide(); |
|
258 } else { |
|
259 show(); |
|
260 } |
|
261 } |
|
262 |
|
263 /*! |
|
264 \internal |
|
265 */ |
|
266 EntryFlags HsShortcutWidget::fetchEntryFlags(int aShortcutId) |
|
267 { |
|
268 CaEntry *entry = CaService::instance()->getEntry(aShortcutId); |
|
269 EntryFlags entryFlags = 0; |
|
270 if (entry) { |
|
271 entryFlags = entry->flags(); |
|
272 } |
|
273 return entryFlags; |
|
274 } |