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