1 /* |
|
2 * Copyright (c) 2010 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 #include <hbaction.h> |
|
19 #include <hbtoolbar.h> |
|
20 #include <hbicon.h> |
|
21 #include <hblabel.h> |
|
22 #include <hblistwidgetitem.h> |
|
23 #include <hbabstractviewitem.h> |
|
24 #include <hbinputdialog.h> |
|
25 #include <hbmessagebox.h> |
|
26 #include <hblistwidget.h> |
|
27 #include <hbvalidator.h> |
|
28 #include <hbmenu.h> |
|
29 #include <hbmessagebox.h> |
|
30 |
|
31 #include "cbsuitopiclistview.h" |
|
32 #include "cbsuiviewmanager.h" |
|
33 #include "rcbsui.h" |
|
34 #include "cbslog.h" |
|
35 #include "cbsuiconstants.h" |
|
36 #include "ccbsuitopiclistmonitor.h" |
|
37 |
|
38 // DocML usage |
|
39 const char *T_TOPIC_LIST = "t:ListWidget"; |
|
40 const char *T_TOPICINDEX = "t:topicIndex"; |
|
41 // other items (for decoration) |
|
42 const char *T_LABEL = "t:label"; |
|
43 |
|
44 const char *T_TOGGLE_RECEPTION = "t:toggle_reception"; |
|
45 const char *T_ADD_TOPIC = "t:add_topic"; |
|
46 |
|
47 // Options menu |
|
48 const char *T_EXIT = "t:exit"; |
|
49 |
|
50 const char *T_OPEN = "t:open"; |
|
51 const char *T_SUBSCRIBE = "t:subscribe"; |
|
52 const char *T_UNSUBSCRIBE = "t:unsubscribe"; |
|
53 const char *T_HOTMARK = "t:hotmark"; |
|
54 const char *T_UNHOTMARK = "t:unhotmark"; |
|
55 const char *T_DELETE = "t:delete"; |
|
56 const char *T_EDIT = "t:edit"; |
|
57 |
|
58 // ======== MEMBER FUNCTIONS ================================================== |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // CbsUiTopicListView::CbsUiTopicListView |
|
62 // ---------------------------------------------------------------------------- |
|
63 CbsUiTopicListView::CbsUiTopicListView() |
|
64 : HbView(), |
|
65 mServer(NULL), |
|
66 mViewManager(NULL), |
|
67 mTopicRow(-1), |
|
68 mTopicIndexWidget(NULL), |
|
69 mTopicsWidget(NULL), |
|
70 mReceptionButton(NULL), |
|
71 mOpenAction(NULL), |
|
72 mSubscibeAction(NULL), |
|
73 mUnSubscibeAction(NULL), |
|
74 mHotmarkAction(NULL), |
|
75 mUnHotmarkAction(NULL), |
|
76 mEditAction(NULL), |
|
77 mDeleteAction(NULL), |
|
78 mMonitor(NULL), |
|
79 mTopicQuery(NULL), |
|
80 mTopicNumberList(NULL) |
|
81 { |
|
82 LOG(NORMAL,"CBSUI: CbsUiTopicListView::CbsUiTopicListView IN"); |
|
83 mTopicNumberList = new TCbsUiTopicNumberList(KNumberOfStandardTopics); |
|
84 QT_TRAP_THROWING(mTopicNumberList->AppendL(0)); |
|
85 LOG(NORMAL,"CBSUI: CbsUiTopicListView::CbsUiTopicListView OUT"); |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------------------------------- |
|
89 // CbsUiTopicListView::~CbsUiTopicListView |
|
90 // ---------------------------------------------------------------------------- |
|
91 CbsUiTopicListView::~CbsUiTopicListView() |
|
92 { |
|
93 LOG(NORMAL,"CBSUI: CbsUiTopicListView::~CbsUiTopicListView IN"); |
|
94 delete mTopicNumberList; |
|
95 LOG(NORMAL,"CBSUI: CbsUiTopicListView::~CbsUiTopicListView OUT"); |
|
96 } |
|
97 |
|
98 // ---------------------------------------------------------------------------- |
|
99 // CbsUiTopicListView::init |
|
100 // ---------------------------------------------------------------------------- |
|
101 void CbsUiTopicListView::init(MCbs &server, |
|
102 CbsUiViewManager &viewManager) |
|
103 { |
|
104 LOG(NORMAL,"CBSUI: CbsUiTopicListView::init IN"); |
|
105 mViewManager = &viewManager; |
|
106 LOG(NORMAL,"CBSUI: CbsUiTopicListView::init 1"); |
|
107 mServer = &server; |
|
108 LOG(NORMAL,"CBSUI: CbsUiTopicListView::init 2"); |
|
109 // First get pointers to UI components |
|
110 createComponents(); |
|
111 |
|
112 // Update reception status to UI |
|
113 TBool status; //Symbian variable.. |
|
114 mServer->GetReceptionStatus(status); |
|
115 if (status) { |
|
116 LOG(NORMAL,"CBSUI: CbsUiTopicListView::init reception ON"); |
|
117 mReceptionButton->setText(hbTrId("txt_cbs_deactivate")); |
|
118 } else { |
|
119 LOG(NORMAL,"CBSUI: CbsUiTopicListView::init reception OFF"); |
|
120 mReceptionButton->setText(hbTrId("txt_cbs_activate")); |
|
121 } |
|
122 |
|
123 // Update Topic index and Topics |
|
124 reloadTopicIndex(); |
|
125 reloadTopics(); |
|
126 |
|
127 // Symbian code, leave etc to be handled. |
|
128 // QT_TRAP_THROWING( mMonitor = CCbsUiTopicListMonitor::NewL( *mServer ) ); |
|
129 // mMonitor->AddObserverL( this ); |
|
130 // Longpress in topic list, this is needed always |
|
131 bool ret(false); |
|
132 |
|
133 // conntect topic index list widget operation |
|
134 ret = connect(mTopicIndexWidget, |
|
135 SIGNAL(longPressed(HbListWidgetItem *, QPointF)), |
|
136 this, SLOT(showTopicIndexMenu(HbListWidgetItem *, QPointF))); |
|
137 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init connect \ |
|
138 TopicIndex long press %d", ret); |
|
139 |
|
140 ret = connect(mTopicIndexWidget, SIGNAL(activated(HbListWidgetItem *)), |
|
141 this, SLOT(showTopicSelectionView(HbListWidgetItem *))); |
|
142 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init connect \ |
|
143 TopicIndex short press %d", ret); |
|
144 |
|
145 // conntect topics list widget operation |
|
146 ret = connect(mTopicsWidget, |
|
147 SIGNAL(longPressed(HbListWidgetItem*, QPointF)), |
|
148 this, SLOT(showTopicsMenu(HbListWidgetItem *, QPointF))); |
|
149 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init connect\ |
|
150 Topics long press %d", ret); |
|
151 |
|
152 ret = connect(mTopicsWidget, SIGNAL(activated(HbListWidgetItem *)), |
|
153 this, SLOT(showTopicView(HbListWidgetItem *))); |
|
154 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init connect \ |
|
155 topics short press %d", ret); |
|
156 |
|
157 // connect reception action |
|
158 ret = connect(mReceptionButton, SIGNAL(triggered(bool)), |
|
159 this, SLOT(toggleReception())); |
|
160 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init connect reception %d", ret); |
|
161 |
|
162 // Open |
|
163 mOpenAction = qobject_cast<HbAction *>( |
|
164 mViewManager->xmlLoader()->findObject(T_OPEN)); |
|
165 ret = connect(mOpenAction, SIGNAL(triggered()), |
|
166 this, SLOT(showTopicView())); |
|
167 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init open %d", ret) |
|
168 |
|
169 // Subscribe |
|
170 mSubscibeAction = qobject_cast<HbAction *>( |
|
171 mViewManager->xmlLoader()->findObject(T_SUBSCRIBE)); |
|
172 ret = connect(mSubscibeAction, SIGNAL(triggered()), |
|
173 this, SLOT(toggleSubscription())); |
|
174 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init subscribe %d", ret) |
|
175 |
|
176 // UnSubscribe |
|
177 mUnSubscibeAction = qobject_cast<HbAction *>( |
|
178 mViewManager->xmlLoader()->findObject(T_UNSUBSCRIBE)); |
|
179 ret = connect(mUnSubscibeAction, SIGNAL(triggered()), |
|
180 this, SLOT(toggleSubscription())); |
|
181 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init subscribe %d", ret) |
|
182 |
|
183 // Hotmark |
|
184 mHotmarkAction = qobject_cast<HbAction *>( |
|
185 mViewManager->xmlLoader()->findObject(T_HOTMARK)); |
|
186 ret = connect(mHotmarkAction, SIGNAL(triggered()), |
|
187 this, SLOT(toggleHotmark())); |
|
188 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init hotmark %d", ret) |
|
189 |
|
190 // UnHotmark |
|
191 mUnHotmarkAction = qobject_cast<HbAction *>( |
|
192 mViewManager->xmlLoader()->findObject(T_UNHOTMARK)); |
|
193 ret = connect(mUnHotmarkAction, SIGNAL(triggered()), |
|
194 this, SLOT(toggleHotmark())); |
|
195 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init hotmark %d", ret) |
|
196 |
|
197 // Edit |
|
198 mEditAction = qobject_cast<HbAction *>( |
|
199 mViewManager->xmlLoader()->findObject(T_EDIT)); |
|
200 ret = connect(mEditAction, SIGNAL(triggered()) , |
|
201 this, SLOT(editTopic())); |
|
202 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init edit %d", ret) |
|
203 |
|
204 // Delete |
|
205 mDeleteAction = qobject_cast<HbAction *>( |
|
206 mViewManager->xmlLoader()->findObject(T_DELETE)); |
|
207 ret = connect(mDeleteAction, SIGNAL(triggered()), |
|
208 this, SLOT(deleteTopic())); |
|
209 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::init delete %d", ret) |
|
210 |
|
211 LOG(NORMAL,"CBSUI: CbsUiTopicListView::init OUT"); |
|
212 } |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // CbsUiTopicListView::TopicListChangedL |
|
216 // ---------------------------------------------------------------------------- |
|
217 void CbsUiTopicListView::TopicListChangedL(TCbsTopicListEvent /*aEvent*/, |
|
218 TCbsTopicNumber /*aTopicNumber*/ ) |
|
219 { |
|
220 LOG(NORMAL,"CBSUI: CbsUiTopicListView::TopicListChangedL IN"); |
|
221 reloadTopicIndex(); |
|
222 reloadTopics(); |
|
223 LOG(NORMAL,"CBSUI: CbsUiTopicListView::TopicListChangedL OUT"); |
|
224 } |
|
225 |
|
226 // ---------------------------------------------------------------------------- |
|
227 // CbsUiTopicListView::createComponents |
|
228 // ---------------------------------------------------------------------------- |
|
229 void CbsUiTopicListView::createComponents() |
|
230 { |
|
231 LOG(NORMAL,"CBSUI: CbsUiTopicListView::createComponents IN"); |
|
232 // The topic index widget |
|
233 mTopicIndexWidget = qobject_cast<HbListWidget *>( |
|
234 mViewManager->xmlLoader()->findWidget(T_TOPICINDEX)); |
|
235 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::createComponents\ |
|
236 mTopicIndexWidget=%d", mTopicIndexWidget) |
|
237 |
|
238 // The topic list widget |
|
239 mTopicsWidget = qobject_cast<HbListWidget *>( |
|
240 mViewManager->xmlLoader()->findWidget(T_TOPIC_LIST)); |
|
241 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::createComponents\ |
|
242 mTopicsWidget=%d", mTopicsWidget) |
|
243 |
|
244 // Button for changing reception status |
|
245 mReceptionButton = qobject_cast<HbAction *>( |
|
246 mViewManager->xmlLoader()->findObject(T_TOGGLE_RECEPTION)); |
|
247 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::createComponents\ |
|
248 mReceptionButton=%d", mReceptionButton) |
|
249 |
|
250 // Connect signals of DocML objects |
|
251 HbAction *addTopic = qobject_cast<HbAction *>( |
|
252 mViewManager->xmlLoader()->findObject(T_ADD_TOPIC)); |
|
253 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::createComponents\ |
|
254 addTopic=%d", addTopic) |
|
255 connect(addTopic, SIGNAL(triggered(bool)), this, SLOT(addTopic())); |
|
256 |
|
257 HbAction *exit = qobject_cast<HbAction *>( |
|
258 mViewManager->xmlLoader()->findObject(T_EXIT)); |
|
259 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::createComponents\ |
|
260 exit=%d", exit) |
|
261 connect(exit, SIGNAL(triggered(bool)), mViewManager, SLOT(close())); |
|
262 |
|
263 LOG(NORMAL,"CBSUI: CbsUiTopicListView::createComponents OUT") |
|
264 } |
|
265 |
|
266 // ---------------------------------------------------------------------------- |
|
267 // CbsUiTopicListView::reloadTopicIndex |
|
268 // ---------------------------------------------------------------------------- |
|
269 void CbsUiTopicListView::reloadTopicIndex() |
|
270 { |
|
271 LOG(NORMAL,"CBSUI: CbsUiTopicListView::reloadTopicIndex IN") |
|
272 if (mTopicIndexWidget && mTopicNumberList) { |
|
273 LOG(NORMAL,"CBSUI: CbsUiTopicListView::reloadTopicIndex reload") |
|
274 HbListWidgetItem *item = new HbListWidgetItem(); |
|
275 |
|
276 TCbsTopic topic; |
|
277 mServer->GetTopic(0, topic); |
|
278 mTopicNumberList->At(0) = 0; |
|
279 |
|
280 updateItem(*item, topic); |
|
281 mTopicIndexWidget->clear(); |
|
282 mTopicIndexWidget->addItem(item); |
|
283 |
|
284 // Connect signal to indicate topic selection |
|
285 connect(mTopicIndexWidget, SIGNAL(activated(HbListWidgetItem *)), |
|
286 this, SLOT(showTopicSelectionView(HbListWidgetItem *))); |
|
287 } |
|
288 LOG(NORMAL,"CBSUI: CbsUiTopicListView::reloadTopicIndex OUT") |
|
289 } |
|
290 |
|
291 // ---------------------------------------------------------------------------- |
|
292 // CbsUiTopicListView::reloadTopics |
|
293 // ---------------------------------------------------------------------------- |
|
294 void CbsUiTopicListView::reloadTopics() |
|
295 { |
|
296 LOG(NORMAL,"CBSUI: CbsUiTopicListView::reloadTopics IN"); |
|
297 if (mTopicNumberList && mTopicsWidget) { |
|
298 int count(0); |
|
299 mServer->GetTopicCount(count); |
|
300 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::reloadTopics total count %d", |
|
301 count); |
|
302 // Reset first |
|
303 mTopicNumberList->Reset(); |
|
304 QT_TRAP_THROWING(mTopicNumberList->AppendL(0)); |
|
305 mTopicsWidget->clear(); |
|
306 |
|
307 // Add updated topics one by one |
|
308 for (int i = 1; i < count; i++) { |
|
309 TCbsTopic topic; |
|
310 mServer->GetTopic(i, topic); |
|
311 QT_TRAP_THROWING(mTopicNumberList->AppendL(topic.iNumber)); |
|
312 HbListWidgetItem *item = new HbListWidgetItem(); |
|
313 updateItem(*item, topic); |
|
314 mTopicsWidget->addItem(item); |
|
315 |
|
316 // Connect signal to indicate topic selection |
|
317 connect(mTopicsWidget, SIGNAL(activated(HbListWidgetItem *)), |
|
318 this, SLOT(showTopicView(HbListWidgetItem *))); |
|
319 } |
|
320 } |
|
321 LOG(NORMAL,"CBSUI: CbsUiTopicListView::reloadTopics OUT"); |
|
322 } |
|
323 |
|
324 // ---------------------------------------------------------------------------- |
|
325 // CbsUiTopicListView::showTopicSelectionView |
|
326 // ---------------------------------------------------------------------------- |
|
327 void CbsUiTopicListView::showTopicSelectionView(HbListWidgetItem */*item*/) |
|
328 { |
|
329 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicSelectionView IN"); |
|
330 mTopicRow = 0; |
|
331 if (mTopicNumberList) { |
|
332 TInt messages(0); |
|
333 mServer->GetMessageCount(0, messages); |
|
334 if (messages) { |
|
335 // TODO: show topic selection view |
|
336 } |
|
337 } |
|
338 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicSelectionView OUT"); |
|
339 } |
|
340 |
|
341 // ---------------------------------------------------------------------------- |
|
342 // CbsUiTopicListView::showTopicView |
|
343 // ---------------------------------------------------------------------------- |
|
344 void CbsUiTopicListView::showTopicView(HbListWidgetItem *item) |
|
345 { |
|
346 LOG(NORMAL,"CBSUI: CbsUiTopicListView::topicSelection IN"); |
|
347 mTopicRow = mTopicsWidget->row(item)+1; |
|
348 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::topicSelection index=%d", |
|
349 mTopicRow); |
|
350 if (mTopicNumberList) { |
|
351 TCbsTopicNumber selectTopic(mTopicNumberList->At(mTopicRow)); |
|
352 TInt messages(0); |
|
353 mServer->GetMessageCount(selectTopic, messages); |
|
354 if (messages) { |
|
355 // it will be reopened |
|
356 // mViewManager->activateTopicView(selectTopic); |
|
357 } |
|
358 } |
|
359 LOG(NORMAL,"CBSUI: CbsUiTopicListView::topicSelection OUT"); |
|
360 } |
|
361 |
|
362 // ---------------------------------------------------------------------------- |
|
363 // CbsUiTopicListView::addTopic |
|
364 // ---------------------------------------------------------------------------- |
|
365 void CbsUiTopicListView::addTopic() |
|
366 { |
|
367 LOG(NORMAL,"CBSUI: CbsUiTopicListView::addTopic IN"); |
|
368 // Handle not OK cases, KErrAlreadyExists, KErrArgument, KErrDiskFull |
|
369 // Todo: Add from index if it is available |
|
370 TCbsTopic topic; |
|
371 if (showTopicQuery(topic, true) && |
|
372 KErrNone == mServer->AddTopic(topic)) { |
|
373 reloadTopics(); |
|
374 } |
|
375 LOG(NORMAL,"CBSUI: CbsUiTopicListView::addTopic OUT"); |
|
376 } |
|
377 |
|
378 |
|
379 // ---------------------------------------------------------------------------- |
|
380 // CbsUiTopicListView::editTopic |
|
381 // ---------------------------------------------------------------------------- |
|
382 void CbsUiTopicListView::editTopic() |
|
383 { |
|
384 LOG(NORMAL,"CBSUI: CbsUiTopicListView::editTopic IN"); |
|
385 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::editTopic mTopicRow=%d", mTopicRow) |
|
386 TInt count(0); |
|
387 mServer->GetTopicCount(count); |
|
388 if (mTopicRow > 0 && mTopicRow < count) { |
|
389 // Get topic we need to edit |
|
390 TCbsTopic topic; |
|
391 mServer->GetTopic(mTopicRow, topic); |
|
392 TCbsTopicNumber oldTopicNumber = topic.iNumber; |
|
393 TCbsTopicNumber newTopicNumber(EMaxTopicNumber); |
|
394 TCbsTopicName newTopicName; |
|
395 if (showTopicQuery(topic, false)) { |
|
396 newTopicNumber = topic.iNumber; |
|
397 newTopicName = topic.iName; |
|
398 } |
|
399 TInt err = mServer->ChangeTopicNameAndNumber(oldTopicNumber, |
|
400 newTopicNumber, newTopicName); |
|
401 if (KErrNone == err) { |
|
402 reloadTopics(); |
|
403 } |
|
404 } |
|
405 LOG(NORMAL,"CBSUI: CbsUiTopicListView::editTopic OUT"); |
|
406 } |
|
407 |
|
408 // ---------------------------------------------------------------------------- |
|
409 // CbsUiTopicListView::deleteTopic |
|
410 // ---------------------------------------------------------------------------- |
|
411 void CbsUiTopicListView::deleteTopic() |
|
412 { |
|
413 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::deleteTopic IN row %d", mTopicRow); |
|
414 TInt count(0); |
|
415 mServer->GetTopicCount(count); |
|
416 if (mTopicRow > 0 && mTopicRow < count) { |
|
417 // user confirmation |
|
418 HbMessageBox *box = new HbMessageBox(hbTrId("txt_cbs_delete_topic"), |
|
419 HbMessageBox::MessageTypeQuestion); |
|
420 HbAction *action = box->exec(); |
|
421 if (action == box->primaryAction()) { |
|
422 TCbsTopicNumber selectTopic(mTopicNumberList->At(mTopicRow)); |
|
423 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::deleteTopic topic number %d", |
|
424 selectTopic); |
|
425 if (KErrNone == mServer->DeleteTopic(selectTopic)) { |
|
426 reloadTopics(); |
|
427 } |
|
428 } |
|
429 delete box; |
|
430 box = NULL; |
|
431 } |
|
432 LOG(NORMAL,"CBSUI: CbsUiTopicListView::deleteTopic OUT"); |
|
433 } |
|
434 |
|
435 // ---------------------------------------------------------------------------- |
|
436 // CbsUiTopicListView::toggleReception |
|
437 // ---------------------------------------------------------------------------- |
|
438 void CbsUiTopicListView::toggleReception() |
|
439 { |
|
440 LOG(NORMAL,"CBSUI: CbsUiTopicListView::ToggleReception IN"); |
|
441 TBool status; //Symbian variable.. |
|
442 mServer->GetReceptionStatus(status); |
|
443 |
|
444 if (status) { |
|
445 // Deactivate reception and switch the text on UI |
|
446 LOG(NORMAL,"CBSUI: CbsUiTopicListView::ToggleReception 1->0"); |
|
447 mServer->SetReceptionStatus(EFalse); |
|
448 |
|
449 mReceptionButton->setText( hbTrId("txt_cbs_activate") ); |
|
450 } else { |
|
451 LOG(NORMAL,"CBSUI: CbsUiTopicListView::ToggleReception 0->1"); |
|
452 // Activate reception and switch the text on UI |
|
453 mServer->SetReceptionStatus(ETrue); |
|
454 mReceptionButton->setText(hbTrId("txt_cbs_deactivate")); |
|
455 } |
|
456 LOG(NORMAL,"CBSUI: CbsUiTopicListView::ToggleReception OUT"); |
|
457 } |
|
458 |
|
459 // ---------------------------------------------------------------------------- |
|
460 // CbsUiTopicListView::toggleHotmark |
|
461 // ---------------------------------------------------------------------------- |
|
462 void CbsUiTopicListView::toggleHotmark() |
|
463 { |
|
464 LOG(NORMAL,"CBSUI: CbsUiTopicListView::toggleHotmark IN") |
|
465 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::toggleHotmark\ |
|
466 mTopicRow %d", mTopicRow); |
|
467 TInt count(0); |
|
468 mServer->GetTopicCount(count); |
|
469 if (mTopicRow >= 0 && mTopicRow < count) { |
|
470 // Update data |
|
471 TCbsTopic topic; |
|
472 mServer->GetTopic(mTopicRow, topic); |
|
473 LOG3(NORMAL,"CBSUI: CbsUiTopicListView::toggleHotmark\ |
|
474 before toggle hormark (S,H)=(%d,%d)", |
|
475 topic.iSubscribed, topic.iHotmarked); |
|
476 |
|
477 if (topic.iHotmarked) { |
|
478 mServer->ChangeTopicHotmarkStatus(topic.iNumber, EFalse); |
|
479 mServer->ChangeTopicSubscriptionStatus(topic.iNumber, ETrue); |
|
480 topic.iHotmarked = EFalse; |
|
481 topic.iSubscribed = ETrue; |
|
482 } else { |
|
483 if (topic.iSubscribed){ |
|
484 mServer->ChangeTopicHotmarkStatus(topic.iNumber, ETrue); |
|
485 topic.iHotmarked = ETrue; |
|
486 } else { |
|
487 mServer->ChangeTopicHotmarkStatus(topic.iNumber, ETrue); |
|
488 mServer->ChangeTopicSubscriptionStatus(topic.iNumber, ETrue); |
|
489 topic.iHotmarked = ETrue; |
|
490 topic.iSubscribed = ETrue; |
|
491 } |
|
492 } |
|
493 LOG3(NORMAL,"CBSUI: CbsUiTopicListView::toggleHotmark\ |
|
494 after toggle hotmark (S,H)=(%d,%d)", |
|
495 topic.iSubscribed, topic.iHotmarked); |
|
496 // Update icon |
|
497 updateCurrentItemIcon(topic); |
|
498 } |
|
499 LOG(NORMAL,"CBSUI: CbsUiTopicListView::toggleHotmark OUT") |
|
500 } |
|
501 |
|
502 // ---------------------------------------------------------------------------- |
|
503 // CbsUiTopicListView::toggleSubscription |
|
504 // ---------------------------------------------------------------------------- |
|
505 void CbsUiTopicListView::toggleSubscription() |
|
506 { |
|
507 LOG(NORMAL,"CBSUI: CbsUiTopicListView::toggleSubsciption IN") |
|
508 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::toggleSubsciption mTopicRow=%d", |
|
509 mTopicRow) |
|
510 TInt count(0); |
|
511 mServer->GetTopicCount(count); |
|
512 if (mTopicRow >= 0 && mTopicRow < count) { |
|
513 TCbsTopic topic; |
|
514 mServer->GetTopic(mTopicRow, topic); |
|
515 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::toggleSubsciption\ |
|
516 topic number %d", topic.iNumber); |
|
517 LOG3(NORMAL,"CBSUI: CbsUiTopicListView::toggleSubscription\ |
|
518 before toggle subscibe (S,H)=(%d,%d)", |
|
519 topic.iSubscribed, topic.iHotmarked); |
|
520 |
|
521 if (topic.iSubscribed) { |
|
522 if (topic.iHotmarked) { |
|
523 mServer->ChangeTopicHotmarkStatus(topic.iNumber, EFalse); |
|
524 topic.iHotmarked = EFalse; |
|
525 } |
|
526 mServer->ChangeTopicSubscriptionStatus(topic.iNumber, EFalse); |
|
527 topic.iSubscribed = EFalse; |
|
528 } else { |
|
529 mServer->ChangeTopicSubscriptionStatus(topic.iNumber, ETrue); |
|
530 topic.iSubscribed = ETrue; |
|
531 } |
|
532 LOG3(NORMAL,"CBSUI: CbsUiTopicListView::toggleSubscription\ |
|
533 after toggle subscibe (S,H)=(%d,%d)", |
|
534 topic.iSubscribed, topic.iHotmarked); |
|
535 // Update icon |
|
536 updateCurrentItemIcon(topic); |
|
537 } |
|
538 LOG(NORMAL,"CBSUI: CbsUiTopicListView::toggleSubsciption OUT"); |
|
539 } |
|
540 |
|
541 // ---------------------------------------------------------------------------- |
|
542 // CbsUiTopicListView::showTopicIndexMenu |
|
543 // ---------------------------------------------------------------------------- |
|
544 void CbsUiTopicListView::showTopicIndexMenu(HbListWidgetItem *item, QPointF coords) |
|
545 { |
|
546 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicIndexMenu IN"); |
|
547 Q_UNUSED(item); |
|
548 mTopicRow = 0; |
|
549 TCbsTopic topic; |
|
550 mServer->GetTopic(0, topic); |
|
551 LOG3(NORMAL,"CBSUI: CbsUiTopicListView::showTopicIndexMenu (row %d: %d)", |
|
552 mTopicRow, topic.iNumber); |
|
553 showPopupMenu(topic, coords); |
|
554 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicIndexMenu OUT"); |
|
555 } |
|
556 |
|
557 // ---------------------------------------------------------------------------- |
|
558 // CbsUiTopicListView::showTopicsMenu |
|
559 // ---------------------------------------------------------------------------- |
|
560 void CbsUiTopicListView::showTopicsMenu(HbListWidgetItem *item, QPointF coords) |
|
561 { |
|
562 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicsMenu IN"); |
|
563 mTopicRow = mTopicsWidget->row(item)+1; |
|
564 TCbsTopic topic; |
|
565 mServer->GetTopic(mTopicRow, topic); |
|
566 LOG3(NORMAL,"CBSUI: CbsUiTopicListView::showTopicsMenu (row %d: %d)", |
|
567 mTopicRow, topic.iNumber); |
|
568 showPopupMenu(topic, coords); |
|
569 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicsMenu OUT"); |
|
570 } |
|
571 |
|
572 // ---------------------------------------------------------------------------- |
|
573 // CbsUiTopicListView::showPopupMenu |
|
574 // ---------------------------------------------------------------------------- |
|
575 void CbsUiTopicListView::showPopupMenu(const TCbsTopic &topic, QPointF coords) |
|
576 { |
|
577 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showPopupMenu IN"); |
|
578 HbMenu *contextMenu = new HbMenu(); |
|
579 contextMenu->setTimeout(HbPopup::NoTimeout); |
|
580 contextMenu->setDismissPolicy(HbPopup::TapOutside); |
|
581 |
|
582 TInt messageCount(0); |
|
583 mServer->GetMessageCount(topic.iNumber, messageCount); |
|
584 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::showPopupMenu\ |
|
585 messageCount=%d", messageCount) |
|
586 |
|
587 // Open |
|
588 if (topic.iNumber && messageCount) { |
|
589 contextMenu->addAction(mOpenAction); |
|
590 } |
|
591 // Subscribe / UnSubscribe |
|
592 if (topic.iSubscribed) { |
|
593 contextMenu->addAction(mUnSubscibeAction); |
|
594 } else { |
|
595 contextMenu->addAction(mSubscibeAction); |
|
596 } |
|
597 // Hotmark / UnHotmark |
|
598 if (topic.iHotmarked) { |
|
599 contextMenu->addAction(mUnHotmarkAction); |
|
600 } else { |
|
601 contextMenu->addAction(mHotmarkAction); |
|
602 } |
|
603 // Edit & Delete |
|
604 if (topic.iNumber) { |
|
605 contextMenu->addAction(mEditAction); |
|
606 contextMenu->addAction(mDeleteAction); |
|
607 } |
|
608 |
|
609 // Show context sensitive menu. |
|
610 contextMenu->exec(coords); |
|
611 contextMenu->clearActions(); |
|
612 delete contextMenu; |
|
613 contextMenu = NULL; |
|
614 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showPopupMenu OUT") |
|
615 } |
|
616 |
|
617 // ---------------------------------------------------------------------------- |
|
618 // CbsUiTopicListView::updateQueryAction |
|
619 // ---------------------------------------------------------------------------- |
|
620 // |
|
621 void CbsUiTopicListView::updateQueryAction( QString text ) |
|
622 { |
|
623 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateQueryAction IN" ) |
|
624 LOG2(NORMAL, "SATAPP: CbsUiTopicListView::updateQueryAction text=%s", |
|
625 text.utf16()) |
|
626 if (mTopicQuery && text.length() > 0) { |
|
627 mTopicQuery->primaryAction()->setEnabled(true); |
|
628 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateQueryAction enable OK") |
|
629 } |
|
630 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateQueryAction OUT" ) |
|
631 } |
|
632 |
|
633 // ---------------------------------------------------------------------------- |
|
634 // CbsUiTopicListView::updateItem |
|
635 // ---------------------------------------------------------------------------- |
|
636 void CbsUiTopicListView::updateItem(HbListWidgetItem &item, |
|
637 const TCbsTopic &topic) |
|
638 { |
|
639 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateItem IN" ) |
|
640 updateItemText(item, topic); |
|
641 updateItemIcon(item, topic); |
|
642 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateItem OUT" ) |
|
643 } |
|
644 |
|
645 // ---------------------------------------------------------------------------- |
|
646 // CbsUiTopicListView::updateItemIcon |
|
647 // ---------------------------------------------------------------------------- |
|
648 void CbsUiTopicListView::updateItemIcon(HbListWidgetItem &item, |
|
649 const TCbsTopic &topic) |
|
650 { |
|
651 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemIcon IN"); |
|
652 // TODO: what is the correct way to handle graphics (SVG?) |
|
653 |
|
654 if (topic.iSubscribed) { |
|
655 if (topic.iHotmarked) { |
|
656 item.setDecorationIcon(HbIcon(":/icons/icons/hotmark2.png")); |
|
657 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemIcon Hotmarked"); |
|
658 } else { |
|
659 item.setDecorationIcon(HbIcon(":/icons/icons/sub2.png")); |
|
660 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemIcon Subscribed"); |
|
661 } |
|
662 } else { |
|
663 // No icon if not subscribted: |
|
664 // List item without an icon is alligned on left (looks bad) |
|
665 // temporary solution is to use empty icon |
|
666 item.setDecorationIcon(HbIcon(":/icons/icons/empty.png")); |
|
667 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemIcon Empty"); |
|
668 } |
|
669 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemIcon OUT"); |
|
670 } |
|
671 |
|
672 // ---------------------------------------------------------------------------- |
|
673 // CbsUiTopicListView::updateItemText |
|
674 // ---------------------------------------------------------------------------- |
|
675 void CbsUiTopicListView::updateItemText(HbListWidgetItem &item, |
|
676 const TCbsTopic &topic) |
|
677 { |
|
678 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemText IN"); |
|
679 QString txtL1; |
|
680 QString txtL2; |
|
681 if (0 == topic.iNumber) { |
|
682 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemText topic index"); |
|
683 txtL1 = hbTrId("txt_cbs_000_topic_index"); |
|
684 txtL2 = hbTrId("txt_cbs_not_available"); |
|
685 } else { |
|
686 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemText topics"); |
|
687 txtL1 = QVariant(topic.iNumber).toString(); |
|
688 txtL2 = hbTrId("txt_cbs_no_messages"); |
|
689 // instert zeros to topic number in case 2 or 1 digit topic number. |
|
690 switch (txtL1.length()) { |
|
691 case 1: |
|
692 { |
|
693 txtL1.insert(0, "0"); |
|
694 txtL1.insert(0, "0"); |
|
695 break; |
|
696 } |
|
697 case 2: |
|
698 { |
|
699 txtL1.insert(0, "0"); |
|
700 break; |
|
701 } |
|
702 default: |
|
703 { |
|
704 break; |
|
705 } |
|
706 // do nothing |
|
707 } |
|
708 |
|
709 txtL1.append(' '); // a space |
|
710 QString name = QString::fromUtf16(topic.iName.Ptr(), topic.iName.Length()); |
|
711 txtL1.append(name); |
|
712 if (topic.iUnreadMessages) { |
|
713 txtL1.append(" ("); // space + ( |
|
714 txtL1.append(QVariant(topic.iUnreadMessages).toString()); |
|
715 txtL1.append(')'); // closing ) |
|
716 } |
|
717 // Update the status of topic |
|
718 TInt numberOfMessages(0); |
|
719 mServer->GetMessageCount(topic.iNumber, numberOfMessages); |
|
720 if (numberOfMessages) { |
|
721 TCbsMessage message; |
|
722 TBuf<KMaxMessageTitleLength> buffer; // symbian code |
|
723 // take the last message, not sure is this correct |
|
724 TInt err = mServer->GetMessage(topic.iNumber, |
|
725 numberOfMessages - 1, message); |
|
726 if (KErrNone == err) { |
|
727 err = mServer->GetMessageContents(message.iHandle, buffer); |
|
728 txtL2 = QString::fromUtf16(buffer.Ptr(), buffer.Length()); |
|
729 // TODO: timestamp and second text line |
|
730 } |
|
731 } |
|
732 } |
|
733 item.setText(txtL1); |
|
734 item.setSecondaryText(txtL2); |
|
735 LOG(NORMAL,"CBSUI: CbsUiTopicListView::updateItemText OUT"); |
|
736 } |
|
737 |
|
738 // ---------------------------------------------------------------------------- |
|
739 // CbsUiTopicListView::updateCurrentItem |
|
740 // ---------------------------------------------------------------------------- |
|
741 void CbsUiTopicListView::updateCurrentItem(const TCbsTopic &topic) |
|
742 { |
|
743 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItem IN" ) |
|
744 LOG2(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItem row=%d", |
|
745 mTopicRow) |
|
746 updateCurrentItemIcon(topic); |
|
747 updateCurrentItemText(topic); |
|
748 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItem OUT" ) |
|
749 } |
|
750 |
|
751 // ---------------------------------------------------------------------------- |
|
752 // CbsUiTopicListView::updateCurrentItemIcon |
|
753 // ---------------------------------------------------------------------------- |
|
754 void CbsUiTopicListView::updateCurrentItemIcon(const TCbsTopic &topic) |
|
755 { |
|
756 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItemIcon IN" ) |
|
757 LOG2(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItemIcon row=%d", |
|
758 mTopicRow) |
|
759 HbListWidgetItem *list = NULL; |
|
760 if (0 == mTopicRow) { |
|
761 list = mTopicIndexWidget->item(0); |
|
762 } else { |
|
763 list = mTopicsWidget->item(mTopicRow - 1); |
|
764 } |
|
765 updateItemIcon(*list, topic); |
|
766 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItemIcon OUT" ) |
|
767 } |
|
768 |
|
769 // ---------------------------------------------------------------------------- |
|
770 // CbsUiTopicListView::updateCurrentItemText |
|
771 // ---------------------------------------------------------------------------- |
|
772 void CbsUiTopicListView::updateCurrentItemText(const TCbsTopic &topic) |
|
773 { |
|
774 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItemText IN" ) |
|
775 LOG2(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItemText row=%d", |
|
776 mTopicRow) |
|
777 HbListWidgetItem *list = NULL; |
|
778 if (0 == mTopicRow) { |
|
779 list = mTopicIndexWidget->item(0); |
|
780 } else { |
|
781 list = mTopicsWidget->item(mTopicRow - 1); |
|
782 } |
|
783 updateItemText(*list, topic); |
|
784 LOG(NORMAL, "SATAPP: CbsUiTopicListView::updateCurrentItemText OUT" ) |
|
785 } |
|
786 |
|
787 // ---------------------------------------------------------------------------- |
|
788 // CbsUiTopicListView::showTopicQuery |
|
789 // ---------------------------------------------------------------------------- |
|
790 bool CbsUiTopicListView::showTopicQuery(TCbsTopic &topic, const bool isAddTopic) |
|
791 { |
|
792 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicQuery IN"); |
|
793 bool ret = false; // user didn't click OK |
|
794 // Compose dialog |
|
795 mTopicQuery = new HbInputDialog(); |
|
796 mTopicQuery->setSecondRowVisible(true); |
|
797 // Name |
|
798 mTopicQuery->setInputMode(HbInputDialog::TextInput, 0); |
|
799 mTopicQuery->lineEdit(0)->setMaxLength(KMaxTopicNameLength); |
|
800 QString name = QString::fromUtf16(topic.iName.Ptr(), topic.iName.Length()); |
|
801 if (name.length()) { |
|
802 mTopicQuery->setTextValue(QVariant(name), 0); |
|
803 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::showTopicQuery old name %s", |
|
804 name.utf16()); |
|
805 } |
|
806 |
|
807 // Number |
|
808 mTopicQuery->setInputMode(HbInputDialog::IntInput, 1); |
|
809 mTopicQuery->lineEdit(1)->setMaxLength(3); |
|
810 int number = topic.iNumber; |
|
811 if (number){ |
|
812 mTopicQuery->setTextValue(QVariant(number), 1); |
|
813 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::showTopicQuery old number%d", number); |
|
814 } |
|
815 |
|
816 mTopicQuery->setPromptText(hbTrId("txt_cbs_topic_name"), 0); |
|
817 mTopicQuery->setPromptText(hbTrId("txt_cbs_topic_number"), 1); |
|
818 |
|
819 // Disable OK button if invalid topic number input |
|
820 HbAction *perimaryAction = mTopicQuery->primaryAction(); |
|
821 perimaryAction->setEnabled(false); |
|
822 connect(mTopicQuery->lineEdit(1), SIGNAL(textChanged(QString)), |
|
823 this, SLOT( updateQueryAction(QString))); |
|
824 |
|
825 // Add validation for topic number (1-999) |
|
826 HbValidator *val =new HbValidator; |
|
827 QRegExp r("\\d{1,3}"); // from 1 to 3 digits |
|
828 val->setMasterValidator(new QRegExpValidator(r,0)); |
|
829 val->addField(new QIntValidator(1,999,0),""); |
|
830 mTopicQuery->setValidator(val, 1); |
|
831 |
|
832 // Show the dialog |
|
833 HbAction *action = mTopicQuery->exec(); |
|
834 |
|
835 // Fatch name and number from dialog |
|
836 name = mTopicQuery->value(0).toString(); |
|
837 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::showTopicQuery name=%s ", name.utf16()); |
|
838 number = mTopicQuery->value(1).toString().toInt(); |
|
839 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::showTopicQuery number=%d ", number); |
|
840 bool isNumberExist(false); |
|
841 if (isAddTopic) { |
|
842 int count(0); |
|
843 mServer->GetTopicCount(count); |
|
844 LOG2(NORMAL,"CBSUI: CbsUiTopicListView::showTopicQuery topic total count %d", |
|
845 count); |
|
846 // Check if there is a toipc number same as number which user add |
|
847 for (int i = 1; i < count; i++) { |
|
848 TCbsTopic currentTopic; |
|
849 mServer->GetTopic(i, currentTopic); |
|
850 if (currentTopic.iNumber == number) { |
|
851 isNumberExist = true; |
|
852 break; |
|
853 } |
|
854 } |
|
855 } |
|
856 |
|
857 // check that a topic number was entered and ok pressed |
|
858 // name is optional |
|
859 if (action == mTopicQuery->primaryAction()) { |
|
860 if ( isNumberExist || !number){ |
|
861 // 000 topic and exist number topic can't be edited |
|
862 showNumberInUsePopup(); |
|
863 showTopicQuery( topic, isAddTopic); |
|
864 } else { |
|
865 ret = true; |
|
866 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicQuery OK") |
|
867 topic.iNumber = number; |
|
868 topic.iSubscribed = ETrue; |
|
869 topic.iHotmarked = EFalse; |
|
870 if (name.length()) { |
|
871 topic.iName = name.utf16(); |
|
872 } |
|
873 } |
|
874 } |
|
875 delete mTopicQuery; |
|
876 mTopicQuery = NULL; |
|
877 |
|
878 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showTopicQuery OUT"); |
|
879 return ret; |
|
880 } |
|
881 |
|
882 // ---------------------------------------------------------------------------- |
|
883 // CbsUiTopicListView::showNumberInUsePopup |
|
884 // ---------------------------------------------------------------------------- |
|
885 void CbsUiTopicListView::showNumberInUsePopup() |
|
886 { |
|
887 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showNumberInUsePopup IN"); |
|
888 HbMessageBox *inUsedPopup = new HbMessageBox(HbMessageBox::MessageTypeWarning); |
|
889 inUsedPopup->setText(tr("topic number already in use ")); |
|
890 inUsedPopup->exec(); |
|
891 delete inUsedPopup; |
|
892 inUsedPopup = NULL; |
|
893 LOG(NORMAL,"CBSUI: CbsUiTopicListView::showNumberInUsePopup OUT"); |
|
894 } |
|
895 |
|
896 // End of file |
|