15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "cntfavoritesmemberview.h" |
18 #include "cntfavoritesmemberview.h" |
19 #include "cntgroupselectionpopup.h" |
19 #include "cntgroupselectionpopup.h" |
|
20 #include "qtpbkglobal.h" |
20 |
21 |
21 #include <hblistview.h> |
22 #include <hblistview.h> |
22 #include <hbtoolbar.h> |
|
23 #include <hbmenu.h> |
23 #include <hbmenu.h> |
24 #include <hbaction.h> |
24 #include <hbaction.h> |
|
25 #include <hblistview.h> |
|
26 #include <hblistviewitem.h> |
|
27 #include <hbview.h> |
|
28 #include <hbaction.h> |
|
29 #include <hblabel.h> |
|
30 #include <mobcntmodel.h> |
|
31 #include <hbframebackground.h> |
25 |
32 |
26 const char *CNT_FAVORITESMEMBERVIEW_XML = ":/xml/contacts_favmember.docml"; |
33 const char *CNT_FAVORITESMEMBERVIEW_XML = ":/xml/contacts_favmember.docml"; |
27 |
34 |
28 /*! |
35 CntFavoritesMemberView::CntFavoritesMemberView() : |
29 Constructor, initialize member variables. |
36 mContact(NULL), |
30 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0) |
37 mModel(NULL), |
31 */ |
38 mFavoriteListView(NULL), |
32 CntFavoritesMemberView::CntFavoritesMemberView(CntViewManager *viewManager, QGraphicsItem *parent) |
39 mViewManager(NULL) |
33 :CntBaseView(viewManager, parent), |
|
34 mManageFavoritesAction(0), |
|
35 mFavoritesMenu(0), |
|
36 mFavoriteListView(0) |
|
37 { |
40 { |
38 bool ok = false; |
41 bool ok = false; |
39 ok = loadDocument(CNT_FAVORITESMEMBERVIEW_XML); |
42 mDocumentLoader.load(CNT_FAVORITESMEMBERVIEW_XML, &ok); |
40 |
43 |
41 if (ok) |
44 if (ok) |
42 { |
45 { |
43 QGraphicsWidget *content = findWidget(QString("content")); |
46 mView = static_cast<HbView*>(mDocumentLoader.findWidget(QString("view"))); |
44 setWidget(content); |
|
45 } |
47 } |
46 else |
48 else |
47 { |
49 { |
48 qFatal("Unable to read :/xml/contacts_favmember.docml"); |
50 qFatal("Unable to read :/xml/contacts_favmember.docml"); |
49 } |
51 } |
|
52 |
|
53 //back button |
|
54 mSoftkey = new HbAction(Hb::BackNaviAction, mView); |
|
55 connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView())); |
|
56 |
|
57 // menu actions |
|
58 mManageFavoritesAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:manageFavorite")); |
|
59 connect(mManageFavoritesAction, SIGNAL(triggered()), this, SLOT(manageFavorites())); |
50 } |
60 } |
51 |
61 |
52 /*! |
62 /*! |
53 Destructor |
63 Destructor |
54 */ |
64 */ |
55 CntFavoritesMemberView::~CntFavoritesMemberView() |
65 CntFavoritesMemberView::~CntFavoritesMemberView() |
56 { |
66 { |
57 delete mManageFavoritesAction; |
67 mView->deleteLater(); |
58 delete mFavoritesMenu; |
68 |
59 delete mContact; |
69 delete mManageFavoritesAction; |
60 } |
70 mManageFavoritesAction = 0; |
61 |
71 |
62 /*! |
72 delete mContact; |
63 Save selections |
73 mContact = 0; |
64 */ |
74 |
65 void CntFavoritesMemberView::aboutToCloseView() |
75 delete mModel; |
|
76 mModel = 0; |
|
77 } |
|
78 |
|
79 void CntFavoritesMemberView::showPreviousView() |
66 { |
80 { |
67 CntViewParameters viewParameters; |
81 CntViewParameters viewParameters; |
68 viewManager()->back(viewParameters); |
82 mViewManager->back(viewParameters); |
69 } |
83 } |
70 |
84 |
71 void CntFavoritesMemberView::activateView(const CntViewParameters &viewParameters) |
85 void CntFavoritesMemberView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs ) |
72 { |
86 { |
73 //group box |
87 if (mView->navigationAction() != mSoftkey) |
74 HbGroupBox* groupBox = static_cast<HbGroupBox *>(findWidget(QString("groupBox"))); |
88 mView->setNavigationAction(mSoftkey); |
75 mContact = new QContact(viewParameters.selectedContact()); |
89 |
76 |
90 mContact = new QContact(aArgs.value(ESelectedContact).value<QContact>()); |
77 mFavoriteListView = static_cast<HbListView*>(findWidget(QString("cnt_listview_favorites"))); |
91 mViewManager = aMgr; |
|
92 |
|
93 mFavoriteListView = static_cast<HbListView*> (mDocumentLoader.findWidget("listView")); |
|
94 mFavoriteListView->setUniformItemSizes(true); |
78 connect(mFavoriteListView, SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)), |
95 connect(mFavoriteListView, SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)), |
79 this, SLOT(onLongPressed(HbAbstractViewItem *, const QPointF &))); |
96 this, SLOT(onLongPressed(HbAbstractViewItem *, const QPointF &))); |
80 |
97 |
81 QContactRelationshipFilter rFilter; |
98 HbFrameBackground frame; |
82 rFilter.setRelationshipType(QContactRelationship::HasMember); |
99 frame.setFrameGraphicsName("qtg_fr_list_normal"); |
83 rFilter.setRelatedContactRole(QContactRelationshipFilter::First); |
100 frame.setFrameType(HbFrameDrawer::NinePieces); |
84 rFilter.setRelatedContactId(mContact->id()); |
101 mFavoriteListView->itemPrototypes().first()->setDefaultFrame(frame); |
85 |
102 |
86 contactModel()->setFilterAndSortOrder(rFilter); |
103 mFavoriteListView->listItemPrototype()->setGraphicsSize(HbListViewItem::Thumbnail); |
87 contactModel()->showMyCard(false); |
104 |
88 mFavoriteListView->setModel(contactModel()); |
105 if (!mModel) |
89 } |
106 { |
|
107 QContactRelationshipFilter rFilter; |
|
108 rFilter.setRelationshipType(QContactRelationship::HasMember); |
|
109 rFilter.setRelatedContactRole(QContactRelationship::First); |
|
110 rFilter.setRelatedContactId(mContact->id()); |
|
111 |
|
112 QContactSortOrder sortOrderFirstName; |
|
113 sortOrderFirstName.setDetailDefinitionName(QContactName::DefinitionName, |
|
114 QContactName::FieldFirst); |
|
115 sortOrderFirstName.setCaseSensitivity(Qt::CaseInsensitive); |
|
116 |
|
117 QContactSortOrder sortOrderLastName; |
|
118 sortOrderLastName.setDetailDefinitionName(QContactName::DefinitionName, |
|
119 QContactName::FieldLast); |
|
120 sortOrderLastName.setCaseSensitivity(Qt::CaseInsensitive); |
|
121 |
|
122 QList<QContactSortOrder> sortOrders; |
|
123 sortOrders.append(sortOrderFirstName); |
|
124 sortOrders.append(sortOrderLastName); |
|
125 |
|
126 mModel = new MobCntModel(mViewManager->contactManager(SYMBIAN_BACKEND), rFilter, sortOrders, false); |
|
127 } |
|
128 |
|
129 mFavoriteListView->setModel(mModel); |
|
130 |
|
131 connect(mFavoriteListView, SIGNAL(activated (const QModelIndex&)), this, |
|
132 SLOT(openContact(const QModelIndex&))); |
|
133 } |
|
134 |
|
135 void CntFavoritesMemberView::deactivate() |
|
136 { |
|
137 |
|
138 } |
90 |
139 |
91 void CntFavoritesMemberView::manageFavorites() |
140 void CntFavoritesMemberView::manageFavorites() |
92 { |
141 { |
93 // call a dialog to display the contacts |
142 // call a dialog to display the contacts |
94 CntGroupSelectionPopup *groupSelectionPopup = new CntGroupSelectionPopup(contactManager(), mContact); |
143 CntGroupSelectionPopup *groupSelectionPopup = new CntGroupSelectionPopup(mViewManager->contactManager(SYMBIAN_BACKEND), mContact); |
95 mFavoriteListView->setModel(0); |
144 mFavoriteListView->setModel(0); |
96 groupSelectionPopup->populateListOfContact(); |
145 groupSelectionPopup->populateListOfContact(); |
97 |
146 |
98 HbAction* action = groupSelectionPopup->exec(); |
147 HbAction* action = groupSelectionPopup->exec(); |
99 if (action == groupSelectionPopup->primaryAction()) |
148 if (action == groupSelectionPopup->primaryAction()) |
100 { |
149 { |
101 groupSelectionPopup->saveOldGroup(); |
150 groupSelectionPopup->saveOldGroup(); |
102 } |
151 } |
103 delete groupSelectionPopup; |
152 delete groupSelectionPopup; |
104 |
153 |
105 mFavoriteListView->setModel(contactModel()); |
154 mFavoriteListView->setModel(mModel); |
106 } |
155 } |
107 |
156 |
108 /*! |
|
109 Add actions also to toolbar |
|
110 */ |
|
111 void CntFavoritesMemberView::addMenuItems() |
|
112 { |
|
113 mManageFavoritesAction = new HbAction(hbTrId("Manage favorites")); |
|
114 mFavoritesMenu = new HbMenu(); |
|
115 mFavoritesMenu->addAction(mManageFavoritesAction); |
|
116 |
|
117 connect(mManageFavoritesAction, SIGNAL(triggered()), |
|
118 this, SLOT (manageFavorites())); |
|
119 |
|
120 setMenu(mFavoritesMenu); |
|
121 } |
|
122 |
157 |
123 /*! |
158 /*! |
124 Called when a list item is longpressed |
159 Called when a list item is longpressed |
125 */ |
160 */ |
126 void CntFavoritesMemberView::onLongPressed (HbAbstractViewItem *aItem, const QPointF &aCoords) |
161 void CntFavoritesMemberView::onLongPressed (HbAbstractViewItem *aItem, const QPointF &aCoords) |
127 { |
162 { |
128 QModelIndex index = aItem->modelIndex(); |
163 QModelIndex index = aItem->modelIndex(); |
129 QVariant variant = index.data(Qt::UserRole+1); |
164 QVariant variant = index.data(Qt::UserRole+1); |
130 const QMap<QString, QVariant> map = variant.toMap(); |
165 const QMap<QString, QVariant> map = variant.toMap(); |
131 |
166 |
132 HbMenu *menu = new HbMenu(); |
167 HbMenu *menu = new HbMenu(); |
133 |
168 |
134 HbAction *openContactAction = 0; |
169 HbAction *openContactAction = 0; |
167 menu->deleteLater(); |
202 menu->deleteLater(); |
168 } |
203 } |
169 |
204 |
170 void CntFavoritesMemberView::openContact(const QModelIndex &index) |
205 void CntFavoritesMemberView::openContact(const QModelIndex &index) |
171 { |
206 { |
172 QContact selectedContact = contactModel()->contact(index); |
207 QContact selectedContact = mModel->contact(index); |
173 CntViewParameters viewParameters(CntViewParameters::commLauncherView); |
208 |
174 viewParameters.setSelectedContact(selectedContact); |
209 CntViewParameters viewParameters; |
175 viewManager()->changeView(viewParameters); |
210 viewParameters.insert(EViewId, commLauncherView); |
|
211 QVariant var; |
|
212 var.setValue(selectedContact); |
|
213 viewParameters.insert(ESelectedContact, var); |
|
214 QVariant varGroup; |
|
215 varGroup.setValue(*mContact); |
|
216 viewParameters.insert(ESelectedGroupContact, varGroup); |
|
217 viewParameters.insert(ESelectedAction, "FromGroupMemberView"); |
|
218 mViewManager->changeView(viewParameters); |
176 } |
219 } |
177 |
220 |
178 void CntFavoritesMemberView::editContact(const QModelIndex &index) |
221 void CntFavoritesMemberView::editContact(const QModelIndex &index) |
179 { |
222 { |
180 QContact selectedContact = contactModel()->contact(index); |
223 QContact selectedContact = mModel->contact(index); |
181 CntViewParameters viewParameters(CntViewParameters::editView); |
224 |
182 viewParameters.setSelectedContact(selectedContact); |
225 CntViewParameters viewParameters; |
183 viewManager()->changeView(viewParameters); |
226 viewParameters.insert(EViewId, editView); |
|
227 QVariant var; |
|
228 var.setValue(selectedContact); |
|
229 viewParameters.insert(ESelectedContact, var); |
|
230 mViewManager->changeView(viewParameters); |
184 } |
231 } |
185 |
232 |
186 /*! |
233 /*! |
187 Called after user clicked on the listview. |
234 Called after user clicked on the listview. |
188 */ |
235 */ |
189 void CntFavoritesMemberView::removeFromFavorites(const QModelIndex &index) |
236 void CntFavoritesMemberView::removeFromFavorites(const QModelIndex &index) |
190 { |
237 { |
191 // get contact id using index |
238 // get contact id using index |
192 QContact selectedContact = contactModel()->contact(index); |
239 QContact selectedContact = mModel->contact(index); |
193 QContactRelationship relationship; |
240 QContactRelationship relationship; |
194 relationship.setRelationshipType(QContactRelationship::HasMember); |
241 relationship.setRelationshipType(QContactRelationship::HasMember); |
195 relationship.setFirst(mContact->id()); |
242 relationship.setFirst(mContact->id()); |
196 relationship.setSecond(selectedContact.id()); |
243 relationship.setSecond(selectedContact.id()); |
197 contactManager()->removeRelationship(relationship); |
244 mViewManager->contactManager(SYMBIAN_BACKEND)->removeRelationship(relationship); |
198 } |
245 } |
199 |
246 |