41 mApplication(application), |
41 mApplication(application), |
42 mMailboxListWidget(NULL), |
42 mMailboxListWidget(NULL), |
43 mUiEngine(uiEngine), |
43 mUiEngine(uiEngine), |
44 mListModel(mailboxListModel), |
44 mListModel(mailboxListModel), |
45 mItemContextMenu(NULL), |
45 mItemContextMenu(NULL), |
46 mDocumentLoader(documentLoader) |
46 mDocumentLoader(documentLoader), |
47 { |
47 mViewReady(false) |
|
48 { |
|
49 // Load view layout |
48 loadViewLayout(); |
50 loadViewLayout(); |
49 refreshList(); |
51 |
|
52 // Set title |
|
53 setTitle(hbTrId("txt_mail_title_mail")); |
50 } |
54 } |
51 |
55 |
52 /*! |
56 /*! |
53 Destructor |
57 Destructor |
54 */ |
58 */ |
90 // Set item prototype. |
94 // Set item prototype. |
91 mMailboxListWidget->setItemPrototype(new NmMailboxListViewItem(this)); |
95 mMailboxListWidget->setItemPrototype(new NmMailboxListViewItem(this)); |
92 mMailboxListWidget->setItemRecycling(true); |
96 mMailboxListWidget->setItemRecycling(true); |
93 QObject::connect(mMailboxListWidget, |
97 QObject::connect(mMailboxListWidget, |
94 SIGNAL(activated(const QModelIndex &)), |
98 SIGNAL(activated(const QModelIndex &)), |
95 this, SLOT(openSelectedMailBox(const QModelIndex &))); |
99 this, SLOT(itemActivated(const QModelIndex &))); |
96 QObject::connect(mMailboxListWidget, |
100 QObject::connect(mMailboxListWidget, |
97 SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)), |
101 SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)), |
98 this, SLOT(showItemContextMenu(HbAbstractViewItem*,const QPointF&))); |
102 this, SLOT(showItemContextMenu(HbAbstractViewItem*,const QPointF&))); |
99 mMailboxListWidget->setClampingStyle(HbScrollArea::BounceBackClamping); |
103 mMailboxListWidget->setClampingStyle(HbScrollArea::BounceBackClamping); |
100 mMailboxListWidget->setFrictionEnabled(true); |
104 mMailboxListWidget->setFrictionEnabled(true); |
104 } |
108 } |
105 } |
109 } |
106 else { |
110 else { |
107 NMLOG("nmailui: mailboxlistview: Reasource loading failed"); |
111 NMLOG("nmailui: mailboxlistview: Reasource loading failed"); |
108 } |
112 } |
109 |
113 } |
110 // set menubar title |
114 |
111 setTitle(hbTrId("txt_mail_title_mail")); |
115 /*! |
|
116 Lazy loading when view layout has been loaded |
|
117 */ |
|
118 void NmMailboxListView::viewReady() |
|
119 { |
|
120 if (!mViewReady){ |
|
121 // Set title |
|
122 setTitle(hbTrId("txt_mail_title_mail")); |
|
123 // Refresh list |
|
124 QMetaObject::invokeMethod(this, "refreshList", Qt::QueuedConnection); |
|
125 mViewReady=true; |
|
126 } |
112 } |
127 } |
113 |
128 |
114 /*! |
129 /*! |
115 Reload view contents with new start parameters |
130 Reload view contents with new start parameters |
116 Typically when view is already open and external view activation occurs |
131 Typically when view is already open and external view activation occurs |
153 mMailboxListWidget->setModel(&mListModel); |
168 mMailboxListWidget->setModel(&mListModel); |
154 } |
169 } |
155 } |
170 } |
156 |
171 |
157 /*! |
172 /*! |
|
173 Item activated slot |
|
174 */ |
|
175 void NmMailboxListView::itemActivated(const QModelIndex &index) |
|
176 { |
|
177 mActivatedIndex = index; |
|
178 QMetaObject::invokeMethod(this, "openSelectedMailBox", Qt::QueuedConnection); |
|
179 } |
|
180 |
|
181 |
|
182 /*! |
158 Open selected mailbox |
183 Open selected mailbox |
159 */ |
184 */ |
160 void NmMailboxListView::openSelectedMailBox(const QModelIndex &index) |
185 void NmMailboxListView::openSelectedMailBox() |
161 { |
186 { |
162 // Get mailbox meta data |
187 // Get mailbox meta data |
163 NmMailboxMetaData *mailbox = |
188 NmMailboxMetaData *mailbox = |
164 mListModel.data(index, Qt::DisplayRole).value<NmMailboxMetaData*>(); |
189 mListModel.data(mActivatedIndex, Qt::DisplayRole).value<NmMailboxMetaData*>(); |
165 if (mailbox) { |
190 if (mailbox) { |
166 // Get standard folder inbox id |
191 // Get standard folder inbox id |
167 NmId inboxId = mUiEngine.standardFolderId(mailbox->id(), NmFolderInbox); |
192 NmId inboxId = mUiEngine.standardFolderId(mailbox->id(), NmFolderInbox); |
168 // Create start params and launch message list view |
193 // Create start params and launch message list view |
169 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageList,mailbox->id(),inboxId); |
194 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageList,mailbox->id(),inboxId); |
198 } |
223 } |
199 // Display menu |
224 // Display menu |
200 if (mMailboxListWidget){ |
225 if (mMailboxListWidget){ |
201 mMailboxListWidget->setCurrentIndex(item->modelIndex()); |
226 mMailboxListWidget->setCurrentIndex(item->modelIndex()); |
202 mItemContextMenu->setObjectName("MailboxItemContextMenu"); |
227 mItemContextMenu->setObjectName("MailboxItemContextMenu"); |
203 mItemContextMenu->exec(coords); |
228 mItemContextMenu->setPreferredPos(coords); |
204 } |
229 mItemContextMenu->open(this, SLOT(contextButton(NmActionResponse&))); |
205 } |
230 } |
206 } |
231 } |
207 |
232 } |
208 /*! |
233 |
209 handleActionCommand. From NmMenuObserver, extension manager calls this |
234 /*! |
210 call to handle menu command in the UI. |
235 Slot. Signaled when menu option is selected |
211 */ |
236 */ |
212 void NmMailboxListView::handleActionCommand(NmActionResponse &actionResponse) |
237 void NmMailboxListView::contextButton(NmActionResponse &result) |
213 { |
238 { |
214 // Handle context menu commands here |
239 // Handle context menu commands here |
215 if (actionResponse.menuType()==NmActionContextMenu){ |
240 if (result.menuType()==NmActionContextMenu){ |
216 switch (actionResponse.responseCommand()){ |
241 switch (result.responseCommand()){ |
217 case NmActionResponseCommandOpen:{ |
242 case NmActionResponseCommandOpen:{ |
218 // Check that given start response has mailbox and folder id's |
243 // Check that given start response has mailbox and folder id's |
219 if (actionResponse.mailboxId()!=0){ |
244 if (result.mailboxId()!=0){ |
220 // Use standard folder id inbox if folder has not been specified |
245 // Use standard folder id inbox if folder has not been specified |
221 NmId folderId = actionResponse.folderId(); |
246 NmId folderId = result.folderId(); |
222 if (folderId==0){ |
247 if (folderId==0){ |
223 folderId=mUiEngine.standardFolderId(actionResponse.mailboxId(), |
248 folderId=mUiEngine.standardFolderId(result.mailboxId(), |
224 NmFolderInbox); |
249 NmFolderInbox); |
225 } |
250 } |
226 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageList, |
251 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageList, |
227 actionResponse.mailboxId(), |
252 result.mailboxId(), |
228 folderId); |
253 folderId); |
229 mApplication.enterNmUiView(startParam); |
254 mApplication.enterNmUiView(startParam); |
230 } |
255 } |
231 } |
256 } |
232 break; |
257 break; |