|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // Layout file and view |
|
19 static const char *NMUI_MAILBOX_LIST_VIEW_XML = ":/docml/nmmailboxlistview.docml"; |
|
20 static const char *NMUI_MAILBOX_LIST_VIEW = "NmMailboxListView"; |
|
21 static const char *NMUI_MAILBOX_LIST_WIDGET = "MailboxListWidget"; |
|
22 |
|
23 #include "nmuiheaders.h" |
|
24 |
|
25 /*! |
|
26 \class NmMailboxListView |
|
27 \brief Mailbox list view |
|
28 */ |
|
29 |
|
30 /*! |
|
31 Constructor |
|
32 */ |
|
33 NmMailboxListView::NmMailboxListView( |
|
34 NmApplication &application, |
|
35 NmUiStartParam* startParam, |
|
36 NmUiEngine &uiEngine, |
|
37 NmMailboxListModel &mailboxListModel, |
|
38 HbDocumentLoader *documentLoader, |
|
39 QGraphicsItem *parent) |
|
40 : NmBaseView(startParam,parent), |
|
41 mApplication(application), |
|
42 mMailboxListWidget(NULL), |
|
43 mUiEngine(uiEngine), |
|
44 mListModel(mailboxListModel), |
|
45 mItemContextMenu(NULL), |
|
46 mDocumentLoader(documentLoader) |
|
47 { |
|
48 loadViewLayout(); |
|
49 refreshList(); |
|
50 } |
|
51 |
|
52 /*! |
|
53 Destructor |
|
54 */ |
|
55 NmMailboxListView::~NmMailboxListView() |
|
56 { |
|
57 delete mDocumentLoader; |
|
58 mWidgetList.clear(); |
|
59 if (mItemContextMenu){ |
|
60 mItemContextMenu->clearActions(); |
|
61 } |
|
62 delete mItemContextMenu; |
|
63 } |
|
64 |
|
65 /*! |
|
66 View layout loading from XML |
|
67 */ |
|
68 void NmMailboxListView::loadViewLayout() |
|
69 { |
|
70 // Use document loader to load the view |
|
71 bool ok = false; |
|
72 setObjectName(QString(NMUI_MAILBOX_LIST_VIEW)); |
|
73 QObjectList objectList; |
|
74 objectList.append(this); |
|
75 // Pass the view to documentloader. Document loader uses this view |
|
76 // when docml is parsed, instead of creating new view. |
|
77 if (mDocumentLoader) { |
|
78 mDocumentLoader->setObjectTree(objectList); |
|
79 mWidgetList = mDocumentLoader->load(NMUI_MAILBOX_LIST_VIEW_XML, &ok); |
|
80 } |
|
81 |
|
82 if (ok == true && mWidgetList.count()) { |
|
83 // Create item context menu |
|
84 mItemContextMenu = new HbMenu(); |
|
85 // Get mailbox widget pointer and set parameters |
|
86 mMailboxListWidget = qobject_cast<HbListView *> |
|
87 (mDocumentLoader->findWidget(NMUI_MAILBOX_LIST_WIDGET)); |
|
88 if (mMailboxListWidget) { |
|
89 NMLOG("nmailui: mailboxlistview: List object loaded"); |
|
90 // Set item prototype. |
|
91 mMailboxListWidget->setItemPrototype(new NmMailboxListViewItem(mDocumentLoader)); |
|
92 mMailboxListWidget->setItemRecycling(true); |
|
93 QObject::connect(mMailboxListWidget, |
|
94 SIGNAL(activated(const QModelIndex &)), |
|
95 this, SLOT(openSelectedMailBox(const QModelIndex &))); |
|
96 QObject::connect(mMailboxListWidget, |
|
97 SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)), |
|
98 this, SLOT(showItemContextMenu(HbAbstractViewItem*,const QPointF&))); |
|
99 mMailboxListWidget->setClampingStyle(HbScrollArea::BounceBackClamping); |
|
100 mMailboxListWidget->setFrictionEnabled(true); |
|
101 } |
|
102 else { |
|
103 NMLOG("nmailui: mailboxlistview: List object loading failed"); |
|
104 } |
|
105 } |
|
106 else { |
|
107 NMLOG("nmailui: mailboxlistview: Reasource loading failed"); |
|
108 } |
|
109 |
|
110 // set menubar title |
|
111 setTitle(hbTrId("txt_mail_title_mail")); |
|
112 } |
|
113 |
|
114 /*! |
|
115 Reload view contents with new start parameters |
|
116 Typically when view is already open and external view activation occurs |
|
117 for this same view |
|
118 */ |
|
119 void NmMailboxListView::reloadViewContents(NmUiStartParam* startParam) |
|
120 { |
|
121 // Check start parameter validity. |
|
122 if (startParam&&startParam->viewId()==NmUiViewMailboxList) { |
|
123 // Delete existing start parameter data |
|
124 delete mStartParam; |
|
125 mStartParam=NULL; |
|
126 // Store new start parameter data |
|
127 mStartParam=startParam; |
|
128 // Refresh model |
|
129 refreshList(); |
|
130 } |
|
131 else { |
|
132 NMLOG("nmailui: mailboxlistview: Invalid start parameter"); |
|
133 // Unused start parameter needs to be deleted |
|
134 delete startParam; |
|
135 startParam = NULL; |
|
136 } |
|
137 } |
|
138 |
|
139 /*! |
|
140 View id |
|
141 */ |
|
142 NmUiViewId NmMailboxListView::nmailViewId() const |
|
143 { |
|
144 return NmUiViewMailboxList; |
|
145 } |
|
146 |
|
147 /*! |
|
148 Refresh list |
|
149 */ |
|
150 void NmMailboxListView::refreshList() |
|
151 { |
|
152 if (mMailboxListWidget) { |
|
153 mMailboxListWidget->setModel(&mListModel); |
|
154 } |
|
155 } |
|
156 |
|
157 /*! |
|
158 Open selected mailbox |
|
159 */ |
|
160 void NmMailboxListView::openSelectedMailBox(const QModelIndex &index) |
|
161 { |
|
162 // Get mailbox meta data |
|
163 NmMailboxMetaData *mailbox = |
|
164 mListModel.data(index, Qt::DisplayRole).value<NmMailboxMetaData*>(); |
|
165 if (mailbox) { |
|
166 // Get standard folder inbox id |
|
167 NmId inboxId = mUiEngine.standardFolderId(mailbox->id(), NmFolderInbox); |
|
168 // Create start params and launch message list view |
|
169 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageList,mailbox->id(),inboxId); |
|
170 mApplication.enterNmUiView(startParam); |
|
171 } |
|
172 } |
|
173 |
|
174 /*! |
|
175 showItemContextMenu. Functions starts fetching item context menu objects |
|
176 from extension. Menu is displayed in view callback funtion. |
|
177 */ |
|
178 void NmMailboxListView::showItemContextMenu(HbAbstractViewItem *item, const QPointF &coords) |
|
179 { |
|
180 if (mItemContextMenu&&item){ |
|
181 // Clear previous items from context menu |
|
182 mItemContextMenu->clearActions(); |
|
183 // Get mailbox meta data |
|
184 NmMailboxMetaData *mailbox = |
|
185 mListModel.data(item->modelIndex(), Qt::DisplayRole).value<NmMailboxMetaData*>(); |
|
186 NmId mailboxId(0); |
|
187 if (mailbox) { |
|
188 mailboxId = mailbox->id(); |
|
189 } |
|
190 // Fetch items from extension based on item |
|
191 NmActionRequest request(this, NmActionContextMenu, NmActionContextViewNone, |
|
192 NmActionContextDataMailbox, mailboxId); |
|
193 NmUiExtensionManager &extMngr = mApplication.extManager(); |
|
194 QList<NmAction*> list; |
|
195 extMngr.getActions(request, list); |
|
196 for (int i=0;i<list.count();i++) { |
|
197 mItemContextMenu->addAction(list[i]); |
|
198 } |
|
199 // Display menu |
|
200 if (mMailboxListWidget){ |
|
201 mMailboxListWidget->setCurrentIndex(item->modelIndex()); |
|
202 mItemContextMenu->setObjectName("MailboxItemContextMenu"); |
|
203 mItemContextMenu->exec(coords); |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 /*! |
|
209 handleActionCommand. From NmMenuObserver, extension manager calls this |
|
210 call to handle menu command in the UI. |
|
211 */ |
|
212 void NmMailboxListView::handleActionCommand(NmActionResponse &actionResponse) |
|
213 { |
|
214 // Handle context menu commands here |
|
215 if (actionResponse.menuType()==NmActionContextMenu){ |
|
216 switch (actionResponse.responseCommand()){ |
|
217 case NmActionResponseCommandOpen:{ |
|
218 // Check that given start response has mailbox and folder id's |
|
219 if (actionResponse.mailboxId()!=0){ |
|
220 // Use standard folder id inbox if folder has not been specified |
|
221 NmId folderId = actionResponse.folderId(); |
|
222 if (folderId==0){ |
|
223 folderId=mUiEngine.standardFolderId(actionResponse.mailboxId(), |
|
224 NmFolderInbox); |
|
225 } |
|
226 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageList, |
|
227 actionResponse.mailboxId(), |
|
228 folderId); |
|
229 mApplication.enterNmUiView(startParam); |
|
230 } |
|
231 } |
|
232 break; |
|
233 default: |
|
234 break; |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 |