|
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, application, parent), |
|
41 mApplication(application), |
|
42 mMailboxListWidget(NULL), |
|
43 mUiEngine(uiEngine), |
|
44 mListModel(mailboxListModel), |
|
45 mItemContextMenu(NULL), |
|
46 mDocumentLoader(documentLoader), |
|
47 mViewReady(false) |
|
48 { |
|
49 NM_FUNCTION; |
|
50 |
|
51 // Load view layout |
|
52 loadViewLayout(); |
|
53 |
|
54 // Set title |
|
55 setTitle(hbTrId("txt_mail_title_mail")); |
|
56 } |
|
57 |
|
58 /*! |
|
59 Destructor |
|
60 */ |
|
61 NmMailboxListView::~NmMailboxListView() |
|
62 { |
|
63 NM_FUNCTION; |
|
64 |
|
65 delete mDocumentLoader; |
|
66 mWidgetList.clear(); |
|
67 if (mItemContextMenu){ |
|
68 mItemContextMenu->clearActions(); |
|
69 } |
|
70 delete mItemContextMenu; |
|
71 } |
|
72 |
|
73 /*! |
|
74 View layout loading from XML |
|
75 */ |
|
76 void NmMailboxListView::loadViewLayout() |
|
77 { |
|
78 NM_FUNCTION; |
|
79 |
|
80 |
|
81 // Use document loader to load the view |
|
82 bool ok(false); |
|
83 setObjectName(QString(NMUI_MAILBOX_LIST_VIEW)); |
|
84 QObjectList objectList; |
|
85 objectList.append(this); |
|
86 // Pass the view to documentloader. Document loader uses this view |
|
87 // when docml is parsed, instead of creating new view. |
|
88 if (mDocumentLoader) { |
|
89 mDocumentLoader->setObjectTree(objectList); |
|
90 mWidgetList = mDocumentLoader->load(NMUI_MAILBOX_LIST_VIEW_XML, &ok); |
|
91 } |
|
92 |
|
93 if (ok) { |
|
94 // Create item context menu |
|
95 mItemContextMenu = new HbMenu(); |
|
96 // Get mailbox widget pointer and set parameters |
|
97 mMailboxListWidget = qobject_cast<HbListView *> |
|
98 (mDocumentLoader->findWidget(NMUI_MAILBOX_LIST_WIDGET)); |
|
99 if (mMailboxListWidget) { |
|
100 NM_COMMENT("nmailui: mailboxlistview: list object loaded"); |
|
101 // Set item prototype. |
|
102 mMailboxListWidget->setItemPrototype(new NmMailboxListViewItem(this)); |
|
103 mMailboxListWidget->setItemRecycling(true); |
|
104 QObject::connect(mMailboxListWidget, |
|
105 SIGNAL(activated(const QModelIndex &)), |
|
106 this, SLOT(itemActivated(const QModelIndex &))); |
|
107 mMailboxListWidget->setClampingStyle(HbScrollArea::BounceBackClamping); |
|
108 mMailboxListWidget->setFrictionEnabled(true); |
|
109 } |
|
110 else { |
|
111 NM_ERROR(1,"nmailui: mailboxlistview: list object loading failed"); |
|
112 } |
|
113 } |
|
114 else { |
|
115 NM_ERROR(1,"nmailui: mailboxlistview: resource loading failed"); |
|
116 } |
|
117 } |
|
118 |
|
119 /*! |
|
120 Lazy loading when view layout has been loaded |
|
121 */ |
|
122 void NmMailboxListView::viewReady() |
|
123 { |
|
124 NM_FUNCTION; |
|
125 |
|
126 if (!mViewReady){ |
|
127 // Set title |
|
128 setTitle(hbTrId("txt_mail_title_mail")); |
|
129 // Refresh list |
|
130 QMetaObject::invokeMethod(this, "refreshList", Qt::QueuedConnection); |
|
131 mViewReady=true; |
|
132 } |
|
133 } |
|
134 |
|
135 /*! |
|
136 Reload view contents with new start parameters |
|
137 Typically when view is already open and external view activation occurs |
|
138 for this same view |
|
139 */ |
|
140 void NmMailboxListView::reloadViewContents(NmUiStartParam* startParam) |
|
141 { |
|
142 NM_FUNCTION; |
|
143 |
|
144 // Check start parameter validity. |
|
145 if (startParam&&startParam->viewId()==NmUiViewMailboxList) { |
|
146 // Delete existing start parameter data |
|
147 delete mStartParam; |
|
148 mStartParam=NULL; |
|
149 // Store new start parameter data |
|
150 mStartParam=startParam; |
|
151 // Refresh model |
|
152 refreshList(); |
|
153 } |
|
154 else { |
|
155 NM_ERROR(1,"nmailui: mailboxlistview: invalid start parameter"); |
|
156 // Unused start parameter needs to be deleted |
|
157 delete startParam; |
|
158 startParam = NULL; |
|
159 } |
|
160 } |
|
161 |
|
162 /*! |
|
163 View id |
|
164 */ |
|
165 NmUiViewId NmMailboxListView::nmailViewId() const |
|
166 { |
|
167 NM_FUNCTION; |
|
168 |
|
169 return NmUiViewMailboxList; |
|
170 } |
|
171 |
|
172 /*! |
|
173 Refresh list |
|
174 */ |
|
175 void NmMailboxListView::refreshList() |
|
176 { |
|
177 NM_FUNCTION; |
|
178 |
|
179 if (mMailboxListWidget) { |
|
180 mMailboxListWidget->setModel(&mListModel); |
|
181 } |
|
182 } |
|
183 |
|
184 /*! |
|
185 Item activated slot |
|
186 */ |
|
187 void NmMailboxListView::itemActivated(const QModelIndex &index) |
|
188 { |
|
189 NM_FUNCTION; |
|
190 |
|
191 mActivatedIndex = index; |
|
192 QMetaObject::invokeMethod(this, "openSelectedMailBox", Qt::QueuedConnection); |
|
193 } |
|
194 |
|
195 |
|
196 /*! |
|
197 Open selected mailbox |
|
198 */ |
|
199 void NmMailboxListView::openSelectedMailBox() |
|
200 { |
|
201 NM_FUNCTION; |
|
202 |
|
203 // Get mailbox meta data |
|
204 NmMailboxMetaData *mailbox = |
|
205 mListModel.data(mActivatedIndex, Qt::DisplayRole).value<NmMailboxMetaData*>(); |
|
206 if (mailbox) { |
|
207 // Get standard folder inbox id |
|
208 NmId inboxId = mUiEngine.standardFolderId(mailbox->id(), NmFolderInbox); |
|
209 // Create start params and launch message list view |
|
210 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMessageList,mailbox->id(),inboxId); |
|
211 mApplication.enterNmUiView(startParam); |
|
212 } |
|
213 } |
|
214 |
|
215 |