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