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:Message List View for the messaging application.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "msglistview.h"
|
|
19 |
|
|
20 |
// SYSTEM INCLUDES
|
|
21 |
#include <hbmenu.h>
|
|
22 |
#include <hbaction.h>
|
|
23 |
#include <hbtoolbar.h>
|
|
24 |
#include <hbtoolbarextension.h>
|
|
25 |
#include <hblistview.h>
|
|
26 |
#include <hblistwidget.h>
|
|
27 |
#include <hblistwidgetitem.h>
|
|
28 |
#include <hbgroupbox.h>
|
|
29 |
#include <hbmessagebox.h>
|
|
30 |
#include <hbframebackground.h>
|
|
31 |
#include <QSortFilterProxyModel>
|
|
32 |
#include <QGraphicsLinearLayout>
|
|
33 |
#include <hblistviewitem.h>
|
|
34 |
#include <HbStyleLoader>
|
|
35 |
#include <HbMainWindow>
|
|
36 |
#include <xqaiwrequest.h>
|
|
37 |
#include <xqappmgr.h>
|
|
38 |
#include <qtcontacts.h>
|
|
39 |
|
|
40 |
// USER INCLUDES
|
|
41 |
#include "msgconversationviewinterface.h"
|
|
42 |
#include "debugtraces.h"
|
|
43 |
#include "conversationsengine.h"
|
|
44 |
#include "conversationsenginedefines.h"
|
|
45 |
#include "convergedmessage.h"
|
|
46 |
#include "msglistviewitem.h"
|
|
47 |
|
|
48 |
QTM_USE_NAMESPACE
|
|
49 |
|
|
50 |
//Icons
|
|
51 |
const QString POPUP_LIST_FRAME("qtg_fr_popup_list_normal");
|
|
52 |
const QString NEW_MESSAGE_ICON("qtg_mono_create_message");
|
|
53 |
const QString SORT_ICON("qtg_mono_sort");
|
|
54 |
|
|
55 |
//Localized constants
|
|
56 |
|
|
57 |
#define LOC_DIALOG_DELETE_CONVERSATION hbTrId("txt_messaging_dialog_delete_conversation")
|
|
58 |
|
|
59 |
//itemspecific menu
|
|
60 |
#define LOC_OPEN hbTrId("txt_common_menu_open")
|
|
61 |
#define LOC_SAVETO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
|
|
62 |
#define LOC_DELETE_CONVERSATION hbTrId("txt_messaging_menu_delete_conversation")
|
|
63 |
#define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info")
|
|
64 |
|
|
65 |
#define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
|
|
66 |
#define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
|
|
67 |
|
|
68 |
//main menu
|
|
69 |
#define LOC_SETTINGS hbTrId("txt_messaging_opt_settings")
|
|
70 |
|
|
71 |
#define LOC_TB_VIEW_EXTN hbTrId("txt_messaging_button_view")
|
|
72 |
#define LOC_TB_NEW_MESSAGE hbTrId("txt_messaging_button_new_message")
|
|
73 |
#define LOC_TB_EXTN_DRAFTS hbTrId("txt_messaging_button_drafts")
|
|
74 |
#define LOC_TB_EXTN_CONVERSATIONS hbTrId("txt_messaging_button_conversations")
|
|
75 |
|
|
76 |
#define LOC_VIEW_HEADING hbTrId("txt_messaging_title_conversations")
|
|
77 |
|
|
78 |
//---------------------------------------------------------------
|
|
79 |
// MsgListView::MsgListView
|
|
80 |
// @see header
|
|
81 |
//---------------------------------------------------------------
|
|
82 |
MsgListView::MsgListView(QGraphicsItem *parent) :
|
|
83 |
MsgBaseView(parent),
|
|
84 |
mItemLongPressed(false)
|
|
85 |
{
|
|
86 |
connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
|
|
87 |
}
|
|
88 |
|
|
89 |
//---------------------------------------------------------------
|
|
90 |
// MsgListView::~MsgListView
|
|
91 |
// @see header
|
|
92 |
//---------------------------------------------------------------
|
|
93 |
MsgListView::~MsgListView()
|
|
94 |
{
|
|
95 |
|
|
96 |
}
|
|
97 |
|
|
98 |
//---------------------------------------------------------------
|
|
99 |
// MsgListView::longPressed
|
|
100 |
// @see header
|
|
101 |
//---------------------------------------------------------------
|
|
102 |
void MsgListView::longPressed(HbAbstractViewItem* viewItem, const QPointF& point)
|
|
103 |
{
|
|
104 |
mItemLongPressed = true;
|
|
105 |
if (this->isVisible()) {
|
|
106 |
// Set the current index as the present Item's index.
|
|
107 |
// By default it will not be set.
|
|
108 |
mMsgList->setCurrentIndex(viewItem->modelIndex(), QItemSelectionModel::Select);
|
|
109 |
|
|
110 |
// Create new menu
|
|
111 |
HbMenu *contextMenu = new HbMenu();
|
|
112 |
contextMenu->setAttribute(Qt::WA_DeleteOnClose);
|
|
113 |
//open menu option
|
|
114 |
contextMenu->addAction(LOC_OPEN,this,SLOT(openConversation()));
|
|
115 |
|
|
116 |
//save to contacts for unresolved.
|
|
117 |
int msgType = viewItem->modelIndex().data(MessageType).toInt();
|
|
118 |
if(msgType == ConvergedMessage::Sms ||
|
|
119 |
msgType == ConvergedMessage::Mms ||
|
|
120 |
msgType == ConvergedMessage::BioMsg)
|
|
121 |
{
|
|
122 |
qint64 contactId = mMsgList->currentIndex().data(ContactId).toLongLong();
|
|
123 |
if(contactId < 0)
|
|
124 |
{
|
|
125 |
contextMenu->addAction(LOC_SAVETO_CONTACTS,this,SLOT(saveToContacts()));
|
|
126 |
}
|
|
127 |
else
|
|
128 |
{
|
|
129 |
contextMenu->addAction(LOC_OPEN_CONTACT_INFO,this,SLOT(contactInfo()));
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
//delete conversation
|
|
134 |
contextMenu->addAction(LOC_DELETE_CONVERSATION,this,SLOT(deleteItem()));
|
|
135 |
|
|
136 |
contextMenu->setPreferredPos(point);
|
|
137 |
contextMenu->show();
|
|
138 |
}
|
|
139 |
}
|
|
140 |
|
|
141 |
//---------------------------------------------------------------
|
|
142 |
// MsgListView::openConversation
|
|
143 |
// @see header
|
|
144 |
//---------------------------------------------------------------
|
|
145 |
void MsgListView::openConversation(const QModelIndex& index)
|
|
146 |
{
|
|
147 |
if(mItemLongPressed)
|
|
148 |
{
|
|
149 |
mItemLongPressed = false;
|
|
150 |
return;
|
|
151 |
}
|
|
152 |
//TODO: model populating possibilities.
|
|
153 |
if (index.isValid()) {
|
|
154 |
QVariant conversationId = index.data(ConversationId);
|
|
155 |
|
|
156 |
// Launch conversation view
|
|
157 |
QVariantList param;
|
|
158 |
param << MsgBaseView::CV; // target view
|
|
159 |
param << MsgBaseView::CLV; // source view
|
|
160 |
|
|
161 |
param << conversationId;
|
|
162 |
|
|
163 |
emit switchView(param);
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
//---------------------------------------------------------------
|
|
168 |
// MsgListView::sendNewMessage
|
|
169 |
// @see header
|
|
170 |
//---------------------------------------------------------------
|
|
171 |
void MsgListView::sendNewMessage()
|
|
172 |
{
|
|
173 |
QVariantList param;
|
|
174 |
param << MsgBaseView::UNIEDITOR; // target view
|
|
175 |
param << MsgBaseView::CLV; // source view
|
|
176 |
|
|
177 |
emit switchView(param);
|
|
178 |
}
|
|
179 |
|
|
180 |
//---------------------------------------------------------------
|
|
181 |
// MsgListView::settings
|
|
182 |
// @see header
|
|
183 |
//---------------------------------------------------------------
|
|
184 |
void MsgListView::settings()
|
|
185 |
{
|
|
186 |
// Launch message settings
|
|
187 |
QVariantList param;
|
|
188 |
param << MsgBaseView::MSGSETTINGS;
|
|
189 |
param << MsgBaseView::CLV;
|
|
190 |
emit switchView(param);
|
|
191 |
}
|
|
192 |
|
|
193 |
//---------------------------------------------------------------
|
|
194 |
// MsgListView::openConversation
|
|
195 |
// @see header
|
|
196 |
//---------------------------------------------------------------
|
|
197 |
void MsgListView::openConversation()
|
|
198 |
{
|
|
199 |
QModelIndex modelIndex = mMsgList->currentIndex();
|
|
200 |
openConversation(modelIndex);
|
|
201 |
}
|
|
202 |
|
|
203 |
//---------------------------------------------------------------
|
|
204 |
// MsgListView::showContact
|
|
205 |
// @see header
|
|
206 |
//---------------------------------------------------------------
|
|
207 |
void MsgListView::showContact()
|
|
208 |
{
|
|
209 |
}
|
|
210 |
|
|
211 |
//---------------------------------------------------------------
|
|
212 |
// MsgListView::deleteItem
|
|
213 |
// @see header
|
|
214 |
//---------------------------------------------------------------
|
|
215 |
void MsgListView::deleteItem()
|
|
216 |
{
|
|
217 |
#ifdef _DEBUG_TRACES_
|
|
218 |
qDebug() << "Inside MsgListView::deleteItem";
|
|
219 |
#endif
|
|
220 |
//confirmation dialog.
|
|
221 |
HbMessageBox::question(LOC_DIALOG_DELETE_CONVERSATION,
|
|
222 |
this,SLOT(onDialogDeleteMsg(HbAction*)),
|
|
223 |
LOC_BUTTON_DELETE, LOC_BUTTON_CANCEL);
|
|
224 |
#ifdef _DEBUG_TRACES_
|
|
225 |
qDebug() << " Leaving MsgConversationView::deleteItem";
|
|
226 |
#endif
|
|
227 |
}
|
|
228 |
|
|
229 |
//---------------------------------------------------------------
|
|
230 |
// MsgListView::setupView
|
|
231 |
// @see header
|
|
232 |
//---------------------------------------------------------------
|
|
233 |
void MsgListView::setupListView()
|
|
234 |
{
|
|
235 |
// Create parent layout.
|
|
236 |
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
237 |
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
238 |
mainLayout->setSpacing(0);
|
|
239 |
|
|
240 |
// Create view heading.
|
|
241 |
HbGroupBox *viewHeading = new HbGroupBox();
|
|
242 |
viewHeading->setHeading(LOC_VIEW_HEADING);
|
|
243 |
|
|
244 |
// Register the custorm css path.
|
|
245 |
HbStyleLoader::registerFilePath(":/clv");
|
|
246 |
|
|
247 |
mMsgList = new HbListView(this);
|
|
248 |
mMsgList->setScrollingStyle(HbScrollArea::PanOrFlick);
|
|
249 |
mMsgList->setClampingStyle(HbScrollArea::BounceBackClamping);
|
|
250 |
|
|
251 |
mMsgList->setLayoutName("custom");
|
|
252 |
mMsgList->setItemRecycling(true);
|
|
253 |
mMsgList->setUniformItemSizes(true);
|
|
254 |
|
|
255 |
MsgListViewItem *prototype = new MsgListViewItem(this);
|
|
256 |
mMsgList->setItemPrototype(prototype);
|
|
257 |
|
|
258 |
// Set proxy model
|
|
259 |
QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this);
|
|
260 |
proxyModel->setDynamicSortFilter(true);
|
|
261 |
proxyModel->setSourceModel(ConversationsEngine::instance()->getConversationsSummaryModel());
|
|
262 |
proxyModel->setSortRole(TimeStamp);
|
|
263 |
proxyModel->sort(0, Qt::DescendingOrder);
|
|
264 |
|
|
265 |
mMsgList->setModel(proxyModel);
|
|
266 |
|
|
267 |
connect(ConversationsEngine::instance(), SIGNAL(conversationListModelPopulated()),
|
|
268 |
this, SLOT(populateListView()));
|
|
269 |
|
|
270 |
// Single tap list item
|
|
271 |
connect(mMsgList, SIGNAL(activated(const QModelIndex&)),
|
|
272 |
this, SLOT(openConversation(const QModelIndex&)));
|
|
273 |
|
|
274 |
// Long tap list item
|
|
275 |
connect(mMsgList, SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)),
|
|
276 |
this, SLOT(longPressed(HbAbstractViewItem*, const QPointF&)));
|
|
277 |
|
|
278 |
// Add all widgets to main layout.
|
|
279 |
mainLayout->addItem(viewHeading);
|
|
280 |
mainLayout->addItem(mMsgList);
|
|
281 |
|
|
282 |
this->setLayout(mainLayout);
|
|
283 |
}
|
|
284 |
|
|
285 |
//---------------------------------------------------------------
|
|
286 |
// MsgListView::addMenu
|
|
287 |
// @see header
|
|
288 |
//---------------------------------------------------------------
|
|
289 |
void MsgListView::setupMenu()
|
|
290 |
{
|
|
291 |
// Main menu
|
|
292 |
HbMenu* mainMenu = this->menu();
|
|
293 |
mainMenu->addAction(LOC_SETTINGS,this,SLOT(settings()));
|
|
294 |
}
|
|
295 |
|
|
296 |
//---------------------------------------------------------------
|
|
297 |
// MsgListView::setupToolBar
|
|
298 |
// @see header
|
|
299 |
//---------------------------------------------------------------
|
|
300 |
void MsgListView::setupToolBar()
|
|
301 |
{
|
|
302 |
// ToolBar
|
|
303 |
HbToolBar *toolBar = this->toolBar();
|
|
304 |
toolBar->setOrientation(Qt::Horizontal);
|
|
305 |
|
|
306 |
// Create & setup ToolBar Extension
|
|
307 |
HbToolBarExtension *viewExtn = new HbToolBarExtension();
|
|
308 |
HbAction *viewAction = toolBar->addExtension(viewExtn);
|
|
309 |
viewAction->setIcon(HbIcon(SORT_ICON));
|
|
310 |
|
|
311 |
mViewExtnList = new HbListWidget();
|
|
312 |
mViewExtnList->addItem(LOC_TB_EXTN_DRAFTS);
|
|
313 |
mViewExtnList->addItem(LOC_TB_EXTN_CONVERSATIONS);
|
|
314 |
|
|
315 |
HbListViewItem *prototype = mViewExtnList->listItemPrototype();
|
|
316 |
HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
|
|
317 |
prototype->setDefaultFrame(frame);
|
|
318 |
|
|
319 |
connect(mViewExtnList, SIGNAL(activated(HbListWidgetItem*)),
|
|
320 |
this,SLOT(handleViewExtnActivated(HbListWidgetItem*)));
|
|
321 |
connect(mViewExtnList, SIGNAL(released(HbListWidgetItem*)), viewExtn, SLOT(close()));
|
|
322 |
|
|
323 |
viewExtn->setContentWidget(mViewExtnList);
|
|
324 |
|
|
325 |
// Create & setup 2nd ToolBar button.
|
|
326 |
toolBar->addAction(HbIcon(NEW_MESSAGE_ICON),"",this,SLOT(sendNewMessage()));
|
|
327 |
}
|
|
328 |
|
|
329 |
//---------------------------------------------------------------
|
|
330 |
// MsgListView::handleViewExtnActivated
|
|
331 |
// @see header
|
|
332 |
//---------------------------------------------------------------
|
|
333 |
void MsgListView::handleViewExtnActivated(HbListWidgetItem *item)
|
|
334 |
{
|
|
335 |
int row = mViewExtnList->row(item);
|
|
336 |
if (DRAFTS_EXTN == row) {
|
|
337 |
QVariantList param;
|
|
338 |
param << MsgBaseView::DLV; // target view
|
|
339 |
param << MsgBaseView::CLV; // source view
|
|
340 |
|
|
341 |
emit switchView(param);
|
|
342 |
}
|
|
343 |
}
|
|
344 |
|
|
345 |
//---------------------------------------------------------------
|
|
346 |
// MsgListView::doDelayedConstruction
|
|
347 |
// @see header
|
|
348 |
//---------------------------------------------------------------
|
|
349 |
void MsgListView::doDelayedConstruction()
|
|
350 |
{
|
|
351 |
setupToolBar();
|
|
352 |
setupListView();
|
|
353 |
setupMenu();
|
|
354 |
|
|
355 |
disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
|
|
356 |
}
|
|
357 |
|
|
358 |
//---------------------------------------------------------------
|
|
359 |
// MsgListView::saveToContacts
|
|
360 |
// @see header
|
|
361 |
//---------------------------------------------------------------
|
|
362 |
void MsgListView::saveToContacts()
|
|
363 |
{
|
|
364 |
//save to contacts with phone number field prefilled.
|
|
365 |
QList<QVariant> args;
|
|
366 |
|
|
367 |
QString data = mMsgList->currentIndex().data(DisplayName).toString();
|
|
368 |
|
|
369 |
QString type = QContactPhoneNumber::DefinitionName;
|
|
370 |
|
|
371 |
args << type;
|
|
372 |
args << data;
|
|
373 |
|
|
374 |
//service stuff.
|
|
375 |
QString serviceName("com.nokia.services.phonebookservices");
|
|
376 |
QString operation("editCreateNew(QString,QString)");
|
|
377 |
|
|
378 |
XQAiwRequest* request;
|
|
379 |
XQApplicationManager appManager;
|
|
380 |
request = appManager.create(serviceName, "Fetch", operation, true); // embedded
|
|
381 |
if ( request == NULL )
|
|
382 |
{
|
|
383 |
return;
|
|
384 |
}
|
|
385 |
|
|
386 |
request->setArguments(args);
|
|
387 |
request->send();
|
|
388 |
|
|
389 |
delete request;
|
|
390 |
}
|
|
391 |
|
|
392 |
//---------------------------------------------------------------
|
|
393 |
// MsgListView::contactInfo
|
|
394 |
// @see header
|
|
395 |
//---------------------------------------------------------------
|
|
396 |
void MsgListView::contactInfo()
|
|
397 |
{
|
|
398 |
//open contact info.
|
|
399 |
QList<QVariant> args;
|
|
400 |
|
|
401 |
int contactId = mMsgList->currentIndex().data(ContactId).toInt();
|
|
402 |
|
|
403 |
args << contactId;
|
|
404 |
|
|
405 |
//service stuff.
|
|
406 |
QString serviceName("com.nokia.services.phonebookservices");
|
|
407 |
QString operation("open(int)");
|
|
408 |
|
|
409 |
XQAiwRequest* request;
|
|
410 |
XQApplicationManager appManager;
|
|
411 |
request = appManager.create(serviceName, "Fetch", operation, true); // embedded
|
|
412 |
if ( request == NULL )
|
|
413 |
{
|
|
414 |
return;
|
|
415 |
}
|
|
416 |
|
|
417 |
request->setArguments(args);
|
|
418 |
request->send();
|
|
419 |
|
|
420 |
delete request;
|
|
421 |
}
|
|
422 |
|
|
423 |
//---------------------------------------------------------------
|
|
424 |
// MsgListView::onDialogDeleteMsg
|
|
425 |
// @see header
|
|
426 |
//---------------------------------------------------------------
|
|
427 |
void MsgListView::onDialogDeleteMsg(HbAction* action)
|
|
428 |
{
|
|
429 |
HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
|
|
430 |
if (action == dlg->actions().at(0)) {
|
|
431 |
QModelIndex index = mMsgList->currentIndex();
|
|
432 |
if(index.isValid())
|
|
433 |
{
|
|
434 |
qint64 conversationId = index.data(ConversationId).toLongLong();
|
|
435 |
ConversationsEngine::instance()->deleteConversations(conversationId);
|
|
436 |
}
|
|
437 |
|
|
438 |
}
|
|
439 |
}
|
|
440 |
|
|
441 |
//EOF
|