19 #include <hbscrollbar.h> |
19 #include <hbscrollbar.h> |
20 #include <hbindexfeedback.h> |
20 #include <hbindexfeedback.h> |
21 #include <hbaction.h> |
21 #include <hbaction.h> |
22 #include <hblabel.h> |
22 #include <hblabel.h> |
23 #include <hbaction.h> |
23 #include <hbaction.h> |
|
24 #include <hblineedit.h> |
24 #include <hbmainwindow.h> |
25 #include <hbmainwindow.h> |
25 #include <hblistviewitem.h> |
26 #include <hblistviewitem.h> |
26 #include <hblistview.h> |
27 #include <hblistview.h> |
27 #include <hbsearchpanel.h> |
28 #include <hbsearchpanel.h> |
28 #include <hbstaticvkbhost.h> |
29 #include <hbstaticvkbhost.h> |
29 #include <QGraphicsLinearLayout> |
30 #include <QGraphicsLinearLayout> |
30 #include <qcontactid.h> |
31 #include <qcontactid.h> |
31 #include <QDebug> |
|
32 #include <cntlistmodel.h> |
32 #include <cntlistmodel.h> |
33 #include "cntfetchcontactsview.h" |
33 #include "cntfetchcontactsview.h" |
34 |
34 |
35 /*! |
35 /*! |
36 Given a contact manager, CntFetchContacts is responsible for |
36 Given a contact manager, CntFetchContacts is responsible for |
53 { |
53 { |
54 mSearchPanel = new HbSearchPanel(); |
54 mSearchPanel = new HbSearchPanel(); |
55 mSearchPanel->setVisible(false); |
55 mSearchPanel->setVisible(false); |
56 mSearchPanel->setCancelEnabled(false); |
56 mSearchPanel->setCancelEnabled(false); |
57 connect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this, SLOT(setFilter(QString))); |
57 connect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this, SLOT(setFilter(QString))); |
58 |
58 |
|
59 HbLineEdit *editor = static_cast<HbLineEdit*>(mSearchPanel->primitive("lineedit")); |
|
60 editor->setInputMethodHints(Qt::ImhNoPredictiveText); |
|
61 |
59 mLayout = new QGraphicsLinearLayout(Qt::Vertical); |
62 mLayout = new QGraphicsLinearLayout(Qt::Vertical); |
60 |
63 |
61 mContainerWidget = new HbWidget(); |
64 mContainerWidget = new HbWidget(); |
62 |
|
63 // set up the list with all contacts |
|
64 QList<QContactSortOrder> sortOrders; |
|
65 QContactSortOrder sortOrderFirstName; |
|
66 sortOrderFirstName.setDetailDefinitionName(QContactName::DefinitionName, QContactName::FieldFirstName); |
|
67 sortOrderFirstName.setCaseSensitivity(Qt::CaseInsensitive); |
|
68 sortOrders.append(sortOrderFirstName); |
|
69 |
|
70 QContactSortOrder sortOrderLastName; |
|
71 sortOrderLastName.setDetailDefinitionName(QContactName::DefinitionName, QContactName::FieldLastName); |
|
72 sortOrderLastName.setCaseSensitivity(Qt::CaseInsensitive); |
|
73 sortOrders.append(sortOrderLastName); |
|
74 |
|
75 QContactDetailFilter contactsFilter; |
|
76 contactsFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
|
77 contactsFilter.setValue(QString(QLatin1String(QContactType::TypeContact))); |
|
78 mCntModel = new CntListModel(mManager, contactsFilter, sortOrders, false); |
|
79 } |
65 } |
80 |
66 |
81 CntFetchContacts::~CntFetchContacts() |
67 CntFetchContacts::~CntFetchContacts() |
82 { |
68 { |
83 delete mCntModel; |
69 delete mCntModel; |
128 connectSignal(); |
114 connectSignal(); |
129 showPopup(); |
115 showPopup(); |
130 |
116 |
131 mLayout->addItem(mSearchPanel); |
117 mLayout->addItem(mSearchPanel); |
132 mContainerWidget->setLayout(mLayout); |
118 mContainerWidget->setLayout(mLayout); |
133 mContainerWidget->setPreferredHeight(mListView->mainWindow()->size().height()); |
119 |
|
120 // Main window is NULL in unit tests |
|
121 HbMainWindow* window = mListView->mainWindow(); |
|
122 if (window) { |
|
123 mContainerWidget->setPreferredHeight(mListView->mainWindow()->size().height()); |
|
124 } |
134 mContainerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
125 mContainerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
126 |
135 break; |
127 break; |
136 } |
128 } |
137 |
129 |
138 default: |
130 default: |
139 break; |
131 break; |
152 QContactDetailFilter detailfilter; |
144 QContactDetailFilter detailfilter; |
153 detailfilter.setDetailDefinitionName(QContactDisplayLabel::DefinitionName, QContactDisplayLabel::FieldLabel); |
145 detailfilter.setDetailDefinitionName(QContactDisplayLabel::DefinitionName, QContactDisplayLabel::FieldLabel); |
154 detailfilter.setMatchFlags(QContactFilter::MatchStartsWith); |
146 detailfilter.setMatchFlags(QContactFilter::MatchStartsWith); |
155 detailfilter.setValue(searchList); |
147 detailfilter.setValue(searchList); |
156 |
148 |
157 mCntModel->setFilterAndSortOrder(detailfilter); |
149 mCntModel->setFilter(detailfilter); |
158 |
150 |
159 markMembersInView(); |
151 markMembersInView(); |
160 |
152 |
161 if (mCntModel->rowCount() == 0) { |
153 if (mCntModel->rowCount() == 0) { |
162 mLayout->removeItem(mListView); |
154 mLayout->removeItem(mListView); |
211 |
203 |
212 bool userCanceled = (action == mSecondaryAction); |
204 bool userCanceled = (action == mSecondaryAction); |
213 if (popup && userCanceled) { |
205 if (popup && userCanceled) { |
214 mCurrentlySelected.clear(); |
206 mCurrentlySelected.clear(); |
215 |
207 |
216 // Notify that the user canceled. |
|
217 mWasCanceled = true; |
208 mWasCanceled = true; |
218 } |
209 } |
219 else { |
210 else { |
220 mWasCanceled = false; |
211 mWasCanceled = false; |
221 } |
212 } |
|
213 |
|
214 mPopup->setVisible(false); |
|
215 mListView->setModel(NULL); |
|
216 delete mCntModel; |
|
217 mCntModel = NULL; |
222 |
218 |
223 emit clicked(); |
219 emit clicked(); |
224 } |
220 } |
225 |
221 |
226 void CntFetchContacts::memberSelectionChanged(const QModelIndex &index) |
222 void CntFetchContacts::memberSelectionChanged(const QModelIndex &index) |
258 |
254 |
259 mSearchPanel->setVisible(true); |
255 mSearchPanel->setVisible(true); |
260 |
256 |
261 if (!mPopup) { |
257 if (!mPopup) { |
262 mPopup = new HbDialog; |
258 mPopup = new HbDialog; |
|
259 } |
|
260 |
|
261 QContactDetailFilter contactsFilter; |
|
262 contactsFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
|
263 contactsFilter.setValue(QString(QLatin1String(QContactType::TypeContact))); |
|
264 if (!mCntModel) { |
|
265 mCntModel = new CntListModel(mManager, contactsFilter, false); |
263 } |
266 } |
264 |
267 |
265 if (!mListView) { |
268 if (!mListView) { |
266 mListView = new HbListView(mPopup); |
269 mListView = new HbListView(mPopup); |
267 mListView->setModel(mCntModel); |
270 mListView->setModel(mCntModel); |
293 mLayout->addItem(mListView); |
296 mLayout->addItem(mListView); |
294 } |
297 } |
295 |
298 |
296 mCntModel->showMyCard(false); |
299 mCntModel->showMyCard(false); |
297 } |
300 } |
|
301 |
|
302 // Handle the case where the model was removed for the list view |
|
303 if (!mListView->model()) { |
|
304 mListView->setModel(mCntModel); |
|
305 } |
298 } |
306 } |
299 |
307 |
300 void CntFetchContacts::connectSignal() |
308 void CntFetchContacts::connectSignal() |
301 { |
309 { |
302 connect(mListView, SIGNAL(activated(const QModelIndex&)), |
310 connect(mListView, SIGNAL(activated(const QModelIndex&)), |
334 mPopup->open(this, SLOT(handleUserResponse(HbAction*))); |
342 mPopup->open(this, SLOT(handleUserResponse(HbAction*))); |
335 } |
343 } |
336 |
344 |
337 void CntFetchContacts::markMembersInView() |
345 void CntFetchContacts::markMembersInView() |
338 { |
346 { |
339 // if there are no contacts matching the current filter, |
347 // If there are no contacts matching the current filter, |
340 // show "no matching contacts" label |
348 // show "no matching contacts" label |
341 if (mCntModel->rowCount() == 0) { |
349 if (mCntModel->rowCount() == 0) { |
342 if (!mEmptyListLabel) { |
350 if (!mEmptyListLabel) { |
343 mEmptyListLabel = new HbTextItem(hbTrId("txt_phob_info_no_matching_contacts")); |
351 mEmptyListLabel = new HbTextItem(hbTrId("txt_phob_info_no_matching_contacts")); |
344 mEmptyListLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
352 mEmptyListLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |