19 |
19 |
20 #include <hblabel.h> |
20 #include <hblabel.h> |
21 #include <hbgroupbox.h> |
21 #include <hbgroupbox.h> |
22 #include <hbaction.h> |
22 #include <hbaction.h> |
23 #include <hbsearchpanel.h> |
23 #include <hbsearchpanel.h> |
|
24 #include <hblistviewitem.h> |
24 #include <hbtextitem.h> |
25 #include <hbtextitem.h> |
25 #include <qtcontacts.h> |
26 #include <qtcontacts.h> |
26 #include <QStringListModel> |
27 #include <QStringListModel> |
27 #include <QGraphicsWidget> |
28 #include <QGraphicsWidget> |
28 #include <mobcntmodel.h> |
29 #include <mobcntmodel.h> |
|
30 #include <hbmainwindow.h> |
29 |
31 |
30 |
32 |
31 CntGroupSelectionPopup::CntGroupSelectionPopup(QContactManager *manager, QContact *contact, QGraphicsItem *parent): |
33 CntGroupSelectionPopup::CntGroupSelectionPopup(QContactManager *manager, QContact *contact, QGraphicsItem *parent): |
32 HbDialog(parent), |
34 HbDialog(parent), |
33 mListView(0), |
35 mListView(NULL), |
34 mSearchPanel(0), |
36 mEmptyListLabel(NULL), |
35 mEmptyListLabel(0), |
|
36 mContactManager(manager), |
37 mContactManager(manager), |
37 mCntModel(0), |
38 mContact(contact) |
38 mContact(contact), |
|
39 mContainerWidget(0), |
|
40 mContainerLayout(0) |
|
41 { |
39 { |
42 QList<QContactSortOrder> sortOrders; |
40 QList<QContactSortOrder> sortOrders; |
43 QContactSortOrder sortOrderFirstName; |
41 QContactSortOrder sortOrderFirstName; |
44 sortOrderFirstName.setDetailDefinitionName(QContactName::DefinitionName, QContactName::FieldFirst); |
42 sortOrderFirstName.setDetailDefinitionName(QContactName::DefinitionName, QContactName::FieldFirst); |
45 sortOrderFirstName.setCaseSensitivity(Qt::CaseInsensitive); |
43 sortOrderFirstName.setCaseSensitivity(Qt::CaseInsensitive); |
58 |
56 |
59 mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical); |
57 mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical); |
60 mContainerLayout->setContentsMargins(0, 0, 0, 0); |
58 mContainerLayout->setContentsMargins(0, 0, 0, 0); |
61 mContainerLayout->setSpacing(0); |
59 mContainerLayout->setSpacing(0); |
62 |
60 |
63 mContainerWidget = new QGraphicsWidget; |
61 mContainerWidget = new HbWidget(); |
64 } |
62 } |
65 |
63 |
66 CntGroupSelectionPopup::~CntGroupSelectionPopup() |
64 CntGroupSelectionPopup::~CntGroupSelectionPopup() |
67 { |
65 { |
68 delete mContainerWidget; |
66 delete mContainerWidget; |
69 mContainerWidget = 0; |
67 mContainerWidget = 0; |
70 |
68 |
71 delete mEmptyListLabel; |
|
72 mEmptyListLabel = 0; |
|
73 |
|
74 delete mCntModel; |
69 delete mCntModel; |
75 mCntModel = 0; |
70 mCntModel = 0; |
76 } |
71 } |
77 |
72 |
78 void CntGroupSelectionPopup::populateListOfContact() |
73 void CntGroupSelectionPopup::populateListOfContact() |
93 contactsFilter.setValue(QString(QLatin1String(QContactType::TypeContact))); |
88 contactsFilter.setValue(QString(QLatin1String(QContactType::TypeContact))); |
94 mCntModel->setFilterAndSortOrder(contactsFilter); |
89 mCntModel->setFilterAndSortOrder(contactsFilter); |
95 mCntModel->showMyCard(false); |
90 mCntModel->showMyCard(false); |
96 |
91 |
97 rFilter.setRelationshipType(QContactRelationship::HasMember); |
92 rFilter.setRelationshipType(QContactRelationship::HasMember); |
98 rFilter.setRelatedContactRole(QContactRelationshipFilter::First); |
93 rFilter.setRelatedContactRole(QContactRelationship::First); |
99 rFilter.setRelatedContactId(mContact->id()); |
94 rFilter.setRelatedContactId(mContact->id()); |
100 QList<QContactLocalId> contactsLocalIdList = mContactManager->contactIds(rFilter); |
95 QList<QContactLocalId> contactsLocalIdList = mContactManager->contactIds(rFilter); |
101 int countContacts = contactsLocalIdList.count(); |
96 int countContacts = contactsLocalIdList.count(); |
102 |
97 |
103 //Get the index of the contacts |
98 //Get the index of the contacts |
105 mListView->setModel(mCntModel); |
100 mListView->setModel(mCntModel); |
106 // set the listview to multiSelection mode, this will bring MarkAll functionality (from Orbit) |
101 // set the listview to multiSelection mode, this will bring MarkAll functionality (from Orbit) |
107 mListView->setSelectionMode(HbAbstractItemView::MultiSelection); |
102 mListView->setSelectionMode(HbAbstractItemView::MultiSelection); |
108 mListView->setFrictionEnabled(true); |
103 mListView->setFrictionEnabled(true); |
109 mListView->setScrollingStyle(HbScrollArea::PanOrFlick); |
104 mListView->setScrollingStyle(HbScrollArea::PanOrFlick); |
|
105 HbListViewItem *prototype = mListView->listItemPrototype(); |
|
106 prototype->setGraphicsSize(HbListViewItem::Thumbnail); |
110 |
107 |
111 for (int i=0; i < countContacts; i++ ) |
108 for (int i=0; i < countContacts; i++ ) |
112 { |
109 { |
113 // get QContact from QContactId |
110 // get QContact from QContactId |
114 QContact contactInList = mContactManager->contact(contactsLocalIdList.at(i)); |
111 QContact contactInList = mContactManager->contact(contactsLocalIdList.at(i)); |
115 QModelIndex contactIndex = mCntModel->indexOfContact(contactInList); |
112 QModelIndex contactIndex = mCntModel->indexOfContact(contactInList); |
116 mListView->selectionModel()->select(contactIndex, QItemSelectionModel::Select); |
113 mListView->selectionModel()->select(contactIndex, QItemSelectionModel::Select); |
117 } |
114 } |
118 |
115 |
119 setTimeout(0); |
116 setTimeout(HbPopup::NoTimeout); |
|
117 setDismissPolicy(HbPopup::NoDismiss); |
120 setModal(true); |
118 setModal(true); |
121 |
119 |
122 // Note that the layout takes ownership of the item(s) it contains. |
120 // Note that the layout takes ownership of the item(s) it contains. |
123 mContainerLayout->addItem(mListView); |
121 if (!mCntModel->rowCount()) |
|
122 { |
|
123 mListView->setVisible(false); |
|
124 if (mEmptyListLabel == 0) |
|
125 { |
|
126 mEmptyListLabel = new HbTextItem(hbTrId("(no matching contacts)")); |
|
127 mEmptyListLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
|
128 mEmptyListLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
129 mEmptyListLabel->setAlignment(Qt::AlignCenter); |
|
130 mContainerLayout->insertItem(0, mEmptyListLabel); |
|
131 } |
|
132 } |
|
133 else |
|
134 { |
|
135 mContainerLayout->addItem(mListView); |
|
136 } |
124 mContainerLayout->addItem(mSearchPanel); |
137 mContainerLayout->addItem(mSearchPanel); |
125 mContainerWidget->setLayout(mContainerLayout); |
138 mContainerWidget->setLayout(mContainerLayout); |
|
139 mContainerWidget->setPreferredHeight(mainWindow()->size().height()); |
|
140 mContainerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
126 |
141 |
127 setContentWidget(mContainerWidget); |
142 setContentWidget(mContainerWidget); |
128 |
143 |
129 HbAction *mPrimaryAction = new HbAction(hbTrId("Save")); |
144 HbAction *mPrimaryAction = new HbAction(hbTrId("Save")); |
130 setPrimaryAction(mPrimaryAction); |
145 setPrimaryAction(mPrimaryAction); |
157 void CntGroupSelectionPopup::saveOldGroup() |
172 void CntGroupSelectionPopup::saveOldGroup() |
158 { |
173 { |
159 // Use relationship filter to get list of contacts in the relationship (if any) |
174 // Use relationship filter to get list of contacts in the relationship (if any) |
160 QContactRelationshipFilter rFilter; |
175 QContactRelationshipFilter rFilter; |
161 rFilter.setRelationshipType(QContactRelationship::HasMember); |
176 rFilter.setRelationshipType(QContactRelationship::HasMember); |
162 rFilter.setRelatedContactRole(QContactRelationshipFilter::First); |
177 rFilter.setRelatedContactRole(QContactRelationship::First); |
163 rFilter.setRelatedContactId(mContact->id()); |
178 rFilter.setRelatedContactId(mContact->id()); |
164 |
179 |
165 QList<QContactLocalId> contactsLocalIdList = mContactManager->contactIds(rFilter); |
180 QList<QContactLocalId> contactsLocalIdList = mContactManager->contactIds(rFilter); |
166 |
181 |
167 // get the contact from new selection model indexes |
182 // get the contact from new selection model indexes |
208 relationship.setSecond(contactInOldList.id()); |
223 relationship.setSecond(contactInOldList.id()); |
209 removedRelationships.append(relationship); |
224 removedRelationships.append(relationship); |
210 } |
225 } |
211 } |
226 } |
212 // save & remove relationships |
227 // save & remove relationships |
213 mContactManager->removeRelationships(removedRelationships); |
228 QMap<int, QContactManager::Error> errors; |
214 mContactManager->saveRelationships(&addedRelationships); |
229 mContactManager->removeRelationships(removedRelationships, &errors); |
|
230 mContactManager->saveRelationships(&addedRelationships, &errors); |
215 } |
231 } |
216 |
232 |
217 void CntGroupSelectionPopup::closeFind() |
233 void CntGroupSelectionPopup::closeFind() |
218 { |
234 { |
219 if (mSearchPanel) |
235 if (mSearchPanel) |
239 QStringList searchList = filterString.split(QRegExp("\\s+"), QString::SkipEmptyParts); |
255 QStringList searchList = filterString.split(QRegExp("\\s+"), QString::SkipEmptyParts); |
240 |
256 |
241 // find matches and existing members |
257 // find matches and existing members |
242 QContactRelationshipFilter relationFilter; |
258 QContactRelationshipFilter relationFilter; |
243 relationFilter.setRelationshipType(QContactRelationship::HasMember); |
259 relationFilter.setRelationshipType(QContactRelationship::HasMember); |
244 relationFilter.setRelatedContactRole(QContactRelationshipFilter::First); |
260 relationFilter.setRelatedContactRole(QContactRelationship::First); |
245 relationFilter.setRelatedContactId(mContact->id()); |
261 relationFilter.setRelatedContactId(mContact->id()); |
246 |
262 |
247 QContactDetailFilter detailfilter; |
263 QContactDetailFilter detailfilter; |
248 detailfilter.setDetailDefinitionName(QContactDisplayLabel::DefinitionName, QContactDisplayLabel::FieldLabel); |
264 detailfilter.setDetailDefinitionName(QContactDisplayLabel::DefinitionName, QContactDisplayLabel::FieldLabel); |
249 detailfilter.setMatchFlags(QContactFilter::MatchStartsWith); |
265 detailfilter.setMatchFlags(QContactFilter::MatchStartsWith); |
264 QContact contactInList = mContactManager->contact(contactsLocalIdList.at(i)); |
280 QContact contactInList = mContactManager->contact(contactsLocalIdList.at(i)); |
265 QModelIndex contactIndex = mCntModel->indexOfContact(contactInList); |
281 QModelIndex contactIndex = mCntModel->indexOfContact(contactInList); |
266 mListView->selectionModel()->select(contactIndex, QItemSelectionModel::Select); |
282 mListView->selectionModel()->select(contactIndex, QItemSelectionModel::Select); |
267 } |
283 } |
268 |
284 |
269 if (!mCntModel->rowCount()) { |
285 if (!mCntModel->rowCount()) |
270 if (mEmptyListLabel == 0) { |
286 { |
|
287 if (mEmptyListLabel == 0) |
|
288 { |
|
289 mListView->setVisible(false); |
|
290 mContainerLayout->removeItem(mListView); |
|
291 |
271 mEmptyListLabel = new HbTextItem(hbTrId("(no matching contacts)")); |
292 mEmptyListLabel = new HbTextItem(hbTrId("(no matching contacts)")); |
272 mEmptyListLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
293 mEmptyListLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
273 mEmptyListLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
294 mEmptyListLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
274 mEmptyListLabel->setAlignment(Qt::AlignCenter); |
295 mEmptyListLabel->setAlignment(Qt::AlignCenter); |
275 mContainerLayout->insertItem(1, mEmptyListLabel); |
296 mContainerLayout->insertItem(0, mEmptyListLabel); |
276 } |
297 } |
277 } |
298 } |
278 else { |
299 else |
279 mContainerLayout->removeItem(mEmptyListLabel); |
300 { |
280 delete mEmptyListLabel; |
301 if (mEmptyListLabel != 0) |
281 mEmptyListLabel = 0; |
302 { |
282 } |
303 mListView->setVisible(true); |
283 } |
304 mContainerLayout->insertItem(0, mListView); |
|
305 |
|
306 mContainerLayout->removeItem(mEmptyListLabel); |
|
307 delete mEmptyListLabel; |
|
308 mEmptyListLabel = 0; |
|
309 } |
|
310 } |
|
311 } |