author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 13:35:48 +0300 | |
changeset 34 | 84197e66a4bd |
parent 31 | ebfee66fde93 |
child 44 | 36f374c67aa8 |
permissions | -rw-r--r-- |
31 | 1 |
/* |
2 |
* Copyright (c) 2009 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: Drafts List View for displaying drafts messages. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include "draftslistview.h" |
|
19 |
||
20 |
// SYSTEM INCLUDES |
|
21 |
#include <HbMenu> |
|
22 |
#include <HbAction> |
|
23 |
#include <HbToolBar> |
|
24 |
#include <HbToolBarExtension> |
|
25 |
#include <HbListView> |
|
26 |
#include <HbListViewItem> |
|
27 |
#include <HbListWidget> |
|
28 |
#include <HbListWidgetItem> |
|
29 |
#include <HbStyleLoader> |
|
30 |
#include <HbGroupBox> |
|
31 |
#include <HbFrameBackground> |
|
32 |
#include <HbMessageBox> |
|
33 |
#include <HbMainWindow> |
|
34 |
||
35 |
#include <QAbstractItemModel> |
|
36 |
#include <QSortFilterProxyModel> |
|
37 |
#include <QGraphicsLinearLayout> |
|
38 |
||
39 |
// USER INCLUDES |
|
40 |
#include "conversationsengine.h" |
|
41 |
#include "conversationsenginedefines.h" |
|
42 |
#include "convergedmessage.h" |
|
43 |
#include "convergedmessageid.h" |
|
44 |
||
45 |
// LOCAL CONSTANTS |
|
46 |
const QString POPUP_LIST_FRAME("qtg_fr_popup_list_normal"); |
|
47 |
const QString NEW_MESSAGE_ICON("qtg_mono_create_message"); |
|
48 |
const QString SORT_ICON("qtg_mono_sort"); |
|
49 |
||
50 |
// LOCALIZATION CONSTANTS |
|
51 |
||
52 |
// Long Tap |
|
53 |
#define LOC_COMMON_OPEN hbTrId("txt_common_menu_open") |
|
54 |
#define LOC_COMMON_DELETE hbTrId("txt_common_menu_delete") |
|
55 |
||
56 |
// View heading |
|
57 |
#define LOC_DLV_HEADING hbTrId("txt_messaging_title_drafts") |
|
58 |
||
59 |
// Menu items |
|
60 |
#define LOC_MENU_DELETE_ALL hbTrId("txt_messaging_opt_delete_all") |
|
61 |
||
62 |
// Toolbar & toolbar exension |
|
63 |
#define LOC_TB_EXTN_DRAFTS hbTrId("txt_messaging_button_drafts") |
|
64 |
#define LOC_TB_EXTN_CONVERSATIONS hbTrId("txt_messaging_button_conversations") |
|
65 |
||
66 |
// Confirmation note |
|
67 |
#define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message") |
|
68 |
#define LOC_DELETE_ALL_DRAFTS hbTrId("txt_messaging_dialog_delate_all_drafts") |
|
69 |
#define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete") |
|
70 |
#define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel") |
|
71 |
||
72 |
//--------------------------------------------------------------- |
|
73 |
// DraftsListView::DraftsListView |
|
74 |
// @see header |
|
75 |
//--------------------------------------------------------------- |
|
76 |
DraftsListView::DraftsListView(QGraphicsItem *parent) : |
|
77 |
MsgBaseView(parent), |
|
78 |
mListView(0), |
|
79 |
mViewExtnList(0), |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
80 |
mToolBar(0) |
31 | 81 |
{ |
82 |
// Delayed loading. |
|
83 |
connect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(doDelayedLoading())); |
|
84 |
} |
|
85 |
||
86 |
//--------------------------------------------------------------- |
|
87 |
// DraftsListView::~DraftsListView |
|
88 |
// @see header |
|
89 |
//--------------------------------------------------------------- |
|
90 |
DraftsListView::~DraftsListView() |
|
91 |
{ |
|
92 |
} |
|
93 |
||
94 |
//--------------------------------------------------------------- |
|
95 |
// DraftsListView::setupMenu |
|
96 |
// @see header |
|
97 |
//--------------------------------------------------------------- |
|
98 |
void DraftsListView::setupMenu() |
|
99 |
{ |
|
100 |
QAbstractItemModel *model = mListView->model(); |
|
101 |
||
102 |
// Menu items are added/removed based on the item count. |
|
103 |
connect(mListView->model(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, |
|
104 |
SLOT(handleModelChanged()), Qt::UniqueConnection); |
|
105 |
connect(mListView->model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), this, |
|
106 |
SLOT(handleModelChanged()), Qt::UniqueConnection); |
|
107 |
} |
|
108 |
||
109 |
//--------------------------------------------------------------- |
|
110 |
// DraftsListView::setupToolbar |
|
111 |
// @see header |
|
112 |
//--------------------------------------------------------------- |
|
113 |
void DraftsListView::setupToolbar() |
|
114 |
{ |
|
115 |
if (!mToolBar) { |
|
116 |
mToolBar = this->toolBar(); |
|
117 |
mToolBar->setOrientation(Qt::Horizontal); |
|
118 |
||
119 |
// Create & setup ToolBar Extension |
|
120 |
HbToolBarExtension *viewExtn = new HbToolBarExtension(); |
|
121 |
HbAction *viewAction = mToolBar->addExtension(viewExtn); |
|
122 |
viewAction->setIcon(HbIcon(SORT_ICON)); |
|
123 |
||
124 |
mViewExtnList = new HbListWidget(); |
|
125 |
mViewExtnList->addItem(LOC_TB_EXTN_DRAFTS); |
|
126 |
mViewExtnList->addItem(LOC_TB_EXTN_CONVERSATIONS); |
|
127 |
||
128 |
HbListViewItem *prototype = mViewExtnList->listItemPrototype(); |
|
129 |
HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces); |
|
130 |
prototype->setDefaultFrame(frame); |
|
131 |
||
132 |
connect(mViewExtnList, SIGNAL(activated(HbListWidgetItem*)), this, |
|
133 |
SLOT(handleViewExtnActivated(HbListWidgetItem*))); |
|
134 |
connect(mViewExtnList, SIGNAL(released(HbListWidgetItem*)), viewExtn, SLOT(close())); |
|
135 |
||
136 |
viewExtn->setContentWidget(mViewExtnList); |
|
137 |
||
138 |
// Create & setup 2nd ToolBar button. |
|
139 |
mToolBar->addAction(HbIcon(NEW_MESSAGE_ICON), "", this, SLOT(createNewMessage())); |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
//--------------------------------------------------------------- |
|
144 |
// DraftsListView::setupListView |
|
145 |
// @see header |
|
146 |
//--------------------------------------------------------------- |
|
147 |
void DraftsListView::setupListView() |
|
148 |
{ |
|
149 |
if (!mListView) { |
|
150 |
// Create parent layout. |
|
151 |
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
152 |
mainLayout->setContentsMargins(0, 0, 0, 0); |
|
153 |
mainLayout->setSpacing(0); |
|
154 |
||
155 |
// Create view heading. |
|
156 |
HbGroupBox *viewHeading = new HbGroupBox(); |
|
157 |
viewHeading->setHeading(LOC_DLV_HEADING); |
|
158 |
||
159 |
// Create List View. |
|
160 |
mListView = new HbListView(this); |
|
161 |
||
162 |
mListView->setScrollingStyle(HbScrollArea::PanOrFlick); |
|
163 |
mListView->setItemRecycling(true); |
|
164 |
mListView->setUniformItemSizes(true); |
|
165 |
mListView->setClampingStyle(HbScrollArea::BounceBackClamping); |
|
166 |
||
167 |
// Register the custorm css path. |
|
168 |
HbStyleLoader::registerFilePath(":/dlv"); |
|
169 |
// mListView->setLayoutName("custom"); |
|
170 |
||
171 |
// Set list item properties. |
|
172 |
HbListViewItem *prototype = mListView->listItemPrototype(); |
|
173 |
prototype->setGraphicsSize(HbListViewItem::SmallIcon); |
|
174 |
prototype->setStretchingStyle(HbListViewItem::StretchLandscape); |
|
175 |
prototype->setSecondaryTextRowCount(1, 1); |
|
176 |
||
177 |
// Create and set model |
|
178 |
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); |
|
179 |
proxyModel->setDynamicSortFilter(true); |
|
180 |
proxyModel->setSourceModel(ConversationsEngine::instance()->getDraftsModel()); |
|
181 |
proxyModel->setSortRole(TimeStamp); |
|
182 |
proxyModel->sort(0, Qt::DescendingOrder); |
|
183 |
mListView->setModel(proxyModel); |
|
184 |
||
185 |
// Short & Long Taps |
|
186 |
connect(mListView, SIGNAL(activated(QModelIndex)), this, |
|
187 |
SLOT(openDraftMessage(QModelIndex))); |
|
188 |
connect(mListView, SIGNAL(longPressed(HbAbstractViewItem*,QPointF)), this, |
|
189 |
SLOT(handleLongPressed(HbAbstractViewItem*,QPointF))); |
|
190 |
||
191 |
// Add all widgets to main layout. |
|
192 |
mainLayout->addItem(viewHeading); |
|
193 |
mainLayout->addItem(mListView); |
|
194 |
||
195 |
this->setLayout(mainLayout); |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
//------------------------------------------------------------------------------ |
|
200 |
// DraftsListView::doDelayedLoading |
|
201 |
// @see header |
|
202 |
//------------------------------------------------------------------------------ |
|
203 |
void DraftsListView::doDelayedLoading() |
|
204 |
{ |
|
205 |
setupToolbar(); |
|
206 |
setupListView(); |
|
207 |
setupMenu(); |
|
208 |
disconnect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(doDelayedLoading())); |
|
209 |
} |
|
210 |
||
211 |
//------------------------------------------------------------------------------ |
|
212 |
// DraftsListView::openDraftMessage |
|
213 |
// @see header |
|
214 |
//------------------------------------------------------------------------------ |
|
215 |
void DraftsListView::openDraftMessage() |
|
216 |
{ |
|
217 |
openDraftMessage(mListView->currentIndex()); |
|
218 |
} |
|
219 |
||
220 |
//------------------------------------------------------------------------------ |
|
221 |
// DraftsListView::deleteDraftMessage |
|
222 |
// @see header |
|
223 |
//------------------------------------------------------------------------------ |
|
224 |
void DraftsListView::deleteDraftMessage() |
|
225 |
{ |
|
226 |
QModelIndex index = mListView->currentIndex(); |
|
227 |
||
228 |
if (!index.isValid()) { |
|
229 |
return; |
|
230 |
} |
|
231 |
||
232 |
HbMessageBox::question(LOC_DELETE_MESSAGE, |
|
233 |
this,SLOT(onDialogDeleteMsg(HbAction*)), |
|
234 |
LOC_BUTTON_DELETE, LOC_BUTTON_CANCEL); |
|
235 |
||
236 |
} |
|
237 |
||
238 |
//------------------------------------------------------------------------------ |
|
239 |
// DraftsListView::deleteAllDraftMessage |
|
240 |
// @see header |
|
241 |
//------------------------------------------------------------------------------ |
|
242 |
void DraftsListView::deleteAllDraftMessage() |
|
243 |
{ |
|
244 |
HbMessageBox::question(LOC_DELETE_ALL_DRAFTS, |
|
245 |
this,SLOT(onDialogDeleteAllMessages(HbAction*)), |
|
246 |
LOC_BUTTON_DELETE, |
|
247 |
LOC_BUTTON_CANCEL); |
|
248 |
} |
|
249 |
||
250 |
//------------------------------------------------------------------------------ |
|
251 |
// DraftsListView::createNewMessage |
|
252 |
// @see header |
|
253 |
//------------------------------------------------------------------------------ |
|
254 |
void DraftsListView::createNewMessage() |
|
255 |
{ |
|
256 |
QVariantList param; |
|
257 |
param << MsgBaseView::UNIEDITOR; // target view |
|
258 |
param << MsgBaseView::DLV; // source view |
|
259 |
||
260 |
emit switchView(param); |
|
261 |
} |
|
262 |
||
263 |
//------------------------------------------------------------------------------ |
|
264 |
// DraftsListView::openDraftMessage |
|
265 |
// @see header |
|
266 |
//------------------------------------------------------------------------------ |
|
267 |
void DraftsListView::openDraftMessage(const QModelIndex &index) |
|
268 |
{ |
|
269 |
QVariant msgId = index.data(ConvergedMsgId); |
|
270 |
QVariant msgType = index.data(MessageType); |
|
271 |
ConvergedMessageId convergedMsgId = ConvergedMessageId(msgId.toInt()); |
|
272 |
ConvergedMessage message; |
|
273 |
message.setMessageType((ConvergedMessage::MessageType) msgType.toInt()); |
|
274 |
message.setMessageId(convergedMsgId); |
|
275 |
||
276 |
// Launch uni-editor view |
|
277 |
QByteArray dataArray; |
|
278 |
QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append); |
|
279 |
message.serialize(messageStream); |
|
280 |
||
281 |
QVariantList params; |
|
282 |
params << MsgBaseView::UNIEDITOR; // target view |
|
283 |
params << MsgBaseView::DLV; // source view |
|
284 |
||
285 |
params << dataArray; |
|
286 |
emit switchView(params); |
|
287 |
} |
|
288 |
||
289 |
//------------------------------------------------------------------------------ |
|
290 |
// DraftsListView::handleLongPressed |
|
291 |
// @see header |
|
292 |
//------------------------------------------------------------------------------ |
|
293 |
void DraftsListView::handleLongPressed(HbAbstractViewItem *item, const QPointF &coords) |
|
294 |
{ |
|
295 |
if (this->isVisible()) { |
|
296 |
||
297 |
// Set the current index as tapped items index. |
|
298 |
mListView->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Select); |
|
299 |
||
300 |
HbMenu *contextMenu = new HbMenu(); |
|
301 |
contextMenu->setAttribute(Qt::WA_DeleteOnClose); |
|
302 |
// Open |
|
303 |
HbAction* openAction = contextMenu->addAction(LOC_COMMON_OPEN); |
|
304 |
connect(openAction, SIGNAL(triggered()), this, SLOT(openDraftMessage())); |
|
305 |
||
306 |
// Delete |
|
307 |
HbAction *deletAction = contextMenu->addAction(LOC_COMMON_DELETE); |
|
308 |
connect(deletAction, SIGNAL(triggered()), this, SLOT(deleteDraftMessage())); |
|
309 |
||
310 |
contextMenu->setPreferredPos(coords); |
|
311 |
contextMenu->show(); |
|
312 |
} |
|
313 |
} |
|
314 |
||
315 |
//------------------------------------------------------------------------------ |
|
316 |
// DraftsListView::handleViewExtnActivated |
|
317 |
// @see header |
|
318 |
//------------------------------------------------------------------------------ |
|
319 |
void DraftsListView::handleViewExtnActivated(HbListWidgetItem *item) |
|
320 |
{ |
|
321 |
int row = mViewExtnList->row(item); |
|
322 |
if (CONVERSATIONS_EXTN == row) { |
|
323 |
QVariantList param; |
|
324 |
param << MsgBaseView::CLV; // target view |
|
325 |
param << MsgBaseView::DLV; // source view |
|
326 |
||
327 |
emit switchView(param); |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
//------------------------------------------------------------------------------ |
|
332 |
// DraftsListView::handleModelChanged |
|
333 |
// @see header |
|
334 |
//------------------------------------------------------------------------------ |
|
335 |
void DraftsListView::handleModelChanged() |
|
336 |
{ |
|
337 |
// If there are no items in list view, delete the menu item. |
|
338 |
HbMenu *mainMenu = this->menu(); |
|
339 |
if (!mListView->model()->rowCount()) { |
|
340 |
mainMenu->clearActions(); |
|
341 |
} |
|
342 |
else { |
|
343 |
if (this->menu()->isEmpty()) { |
|
344 |
mainMenu->addAction(LOC_MENU_DELETE_ALL, this, SLOT(deleteAllDraftMessage())); |
|
345 |
} |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
//------------------------------------------------------------------------------ |
|
350 |
// DraftsListView::onDialogDeleteMsg |
|
351 |
// @see header |
|
352 |
//------------------------------------------------------------------------------ |
|
353 |
void DraftsListView::onDialogDeleteMsg(HbAction* action) |
|
354 |
{ |
|
355 |
HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
|
356 |
if (action == dlg->actions().at(0)) { |
|
357 |
QModelIndex index = mListView->currentIndex(); |
|
358 |
if (index.isValid()) { |
|
359 |
int msgId = index.data(ConvergedMsgId).toInt(); |
|
360 |
QList<int> msgIdList; |
|
361 |
msgIdList.append(msgId); |
|
362 |
ConversationsEngine::instance()->deleteMessages(msgIdList); |
|
363 |
} |
|
364 |
||
365 |
} |
|
366 |
} |
|
367 |
||
368 |
//------------------------------------------------------------------------------ |
|
369 |
// DraftsListView::onDialogDeleteMsg |
|
370 |
// @see header |
|
371 |
//------------------------------------------------------------------------------ |
|
372 |
void DraftsListView::onDialogDeleteAllMessages(HbAction* action) |
|
373 |
{ |
|
374 |
HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
|
375 |
if (action == dlg->actions().at(0)) { |
|
376 |
ConversationsEngine::instance()->deleteAllDraftMessages(); |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
// EOF |