29 #include <hbdialog.h> |
29 #include <hbdialog.h> |
30 #include <hblabel.h> |
30 #include <hblabel.h> |
31 #include <hbsearchpanel.h> |
31 #include <hbsearchpanel.h> |
32 #include <hblineedit.h> |
32 #include <hblineedit.h> |
33 #include <hbaction.h> |
33 #include <hbaction.h> |
34 #include <hbtextitem.h> |
|
35 #include <hbstaticvkbhost.h> |
34 #include <hbstaticvkbhost.h> |
|
35 #include <hbstyleloader.h> |
36 |
36 |
37 #include <QGraphicsLinearLayout> |
37 #include <QGraphicsLinearLayout> |
38 #include <QCoreApplication> |
38 #include <QCoreApplication> |
|
39 #include <QtAlgorithms> |
|
40 |
39 const char *CNT_FETCHLIST_XML = ":/xml/contacts_fetchdialog.docml"; |
41 const char *CNT_FETCHLIST_XML = ":/xml/contacts_fetchdialog.docml"; |
40 |
42 |
41 CntFetchContactPopup::CntFetchContactPopup( QContactManager& aMgr ) : |
43 CntFetchContactPopup::CntFetchContactPopup( QContactManager& aMgr ) : |
42 mManager(aMgr), |
44 mManager(aMgr), |
43 mPopup( NULL ), |
45 mPopup( NULL ), |
48 mSearch( NULL ), |
50 mSearch( NULL ), |
49 mModel( NULL ), |
51 mModel( NULL ), |
50 mMarkAll( NULL ), |
52 mMarkAll( NULL ), |
51 mDoc( NULL ) |
53 mDoc( NULL ) |
52 { |
54 { |
|
55 HbStyleLoader::registerFilePath(":/temp/fetchdialog.css"); |
|
56 |
53 mDoc = new CntDocumentLoader(); |
57 mDoc = new CntDocumentLoader(); |
54 |
58 |
55 bool ok; |
59 bool ok; |
56 mDoc->load( CNT_FETCHLIST_XML, &ok ); |
60 mDoc->load( CNT_FETCHLIST_XML, &ok ); |
57 |
61 |
58 if ( !ok ) |
62 if ( !ok ) |
59 { |
63 { |
60 qFatal("Unable to read %S", CNT_FETCHLIST_XML ); |
64 qFatal("Unable to read %S", CNT_FETCHLIST_XML ); |
61 } |
65 } |
|
66 mDoc->load( CNT_FETCHLIST_XML, "size_section"); |
|
67 |
62 mPopup = static_cast<HbDialog*>( mDoc->findWidget( "dialog" ) ); |
68 mPopup = static_cast<HbDialog*>( mDoc->findWidget( "dialog" ) ); |
63 mSearch = static_cast<HbSearchPanel*>( mDoc->findWidget( "searchPanel" ) ); |
69 mSearch = static_cast<HbSearchPanel*>( mDoc->findWidget( "searchPanel" ) ); |
64 mMarkAll = static_cast<CntFetchMarkAll*>( mDoc->findWidget("markAll") ); |
70 mMarkAll = static_cast<CntFetchMarkAll*>( mDoc->findWidget("markAll") ); |
65 mEmptyView = static_cast<HbTextItem*>( mDoc->findWidget("emptyLabel" )); |
71 mEmptyView = static_cast<HbLabel*>( mDoc->findWidget("emptyLabel" )); |
66 mListView = static_cast<HbListView*>( mDoc->findWidget("listView") ); |
72 mListView = static_cast<HbListView*>( mDoc->findWidget("listView") ); |
67 mHeading = static_cast<HbLabel*>( mDoc->findWidget("heading") ); |
73 mHeading = static_cast<HbLabel*>( mDoc->findWidget("heading") ); |
68 |
74 |
69 connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(closePopup()) ); |
75 connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(closePopup()) ); |
70 connect(mPopup, SIGNAL(aboutToClose()), this, SLOT(closePopup()) ); |
76 connect(mPopup, SIGNAL(aboutToClose()), this, SLOT(closePopup()) ); |
76 mSearch->setCancelEnabled( false ); |
82 mSearch->setCancelEnabled( false ); |
77 |
83 |
78 mVirtualKeyboard = new HbStaticVkbHost(editor); |
84 mVirtualKeyboard = new HbStaticVkbHost(editor); |
79 connect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(handleKeypadOpen())); |
85 connect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(handleKeypadOpen())); |
80 connect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(handleKeypadClosed())); |
86 connect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(handleKeypadClosed())); |
|
87 |
|
88 mMarkAll->setZValue( 2 ); |
81 } |
89 } |
82 |
90 |
83 CntFetchContactPopup::~CntFetchContactPopup() |
91 CntFetchContactPopup::~CntFetchContactPopup() |
84 { |
92 { |
|
93 HbStyleLoader::unregisterFilePath(":/temp/fetchdialog.css"); |
85 delete mDoc; |
94 delete mDoc; |
86 delete mModel; |
95 delete mModel; |
87 } |
96 } |
88 |
97 |
89 CntFetchContactPopup* CntFetchContactPopup::createMultiSelectionPopup( QString aTitle, QString aAction, QContactManager& aManager ) |
98 CntFetchContactPopup* CntFetchContactPopup::createMultiSelectionPopup( QString aTitle, QString aAction, QContactManager& aManager ) |
106 { |
115 { |
107 CNT_ENTRY |
116 CNT_ENTRY |
108 if ( mListView->selectionMode() == HbAbstractItemView::MultiSelection ) |
117 if ( mListView->selectionMode() == HbAbstractItemView::MultiSelection ) |
109 { |
118 { |
110 mIdList.clear(); |
119 mIdList.clear(); |
111 |
|
112 foreach ( QContactLocalId id, aIds ) |
120 foreach ( QContactLocalId id, aIds ) |
113 { |
121 { |
114 mIdList.append( id ); |
122 mIdList.append( id ); |
115 QContact contact = mManager.contact(id); |
123 QModelIndex contactIndex = mModel->indexOfContactId(id); |
116 QModelIndex contactIndex = mModel->indexOfContact(contact); |
|
117 mSelectionModel->select( contactIndex, QItemSelectionModel::Select ); |
124 mSelectionModel->select( contactIndex, QItemSelectionModel::Select ); |
118 } |
125 } |
119 } |
126 } |
120 CNT_EXIT |
127 CNT_EXIT |
121 } |
128 } |
122 |
129 |
123 void CntFetchContactPopup::showPopup() |
130 void CntFetchContactPopup::showPopup() |
124 { |
131 { |
125 CNT_ENTRY |
132 CNT_ENTRY |
|
133 if ( mListView->selectionMode() == HbAbstractItemView::MultiSelection ) |
|
134 { |
|
135 mIds.clear(); |
|
136 mIds = mIdList; |
|
137 qSort(mIds.begin(), mIds.end()); |
|
138 } |
|
139 |
|
140 if ( mPrimaryAction ) |
|
141 { |
|
142 mPrimaryAction->setEnabled(false); |
|
143 } |
|
144 |
|
145 |
126 HbMainWindow* window = mPopup->mainWindow(); |
146 HbMainWindow* window = mPopup->mainWindow(); |
127 if ( window ) |
147 if ( window ) |
128 { |
148 { |
129 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), |
149 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), |
130 this, SLOT(loadLayout(Qt::Orientation)) ); |
150 this, SLOT(orientationChanged(Qt::Orientation)) ); |
131 } |
151 } |
132 |
152 |
133 mPopup->open( this, SLOT(dialogDismissed(HbAction*)) ); |
153 mPopup->open( this, SLOT(dialogDismissed(HbAction*)) ); |
134 CNT_EXIT |
154 CNT_EXIT |
135 } |
155 } |
136 |
156 |
137 void CntFetchContactPopup::handleKeypadOpen() |
157 void CntFetchContactPopup::handleKeypadOpen() |
138 { |
158 { |
139 CNT_ENTRY |
159 CNT_ENTRY |
|
160 HbListViewItem* prototype = mListView->listItemPrototype(); |
|
161 prototype->setTextFormat( Qt::RichText ); |
|
162 |
140 qreal height = mPopup->size().height() - |
163 qreal height = mPopup->size().height() - |
141 mVirtualKeyboard->keyboardArea().height() - |
164 mVirtualKeyboard->keyboardArea().height() - |
142 mSearch->size().height(); |
165 mSearch->size().height(); |
143 |
166 |
144 // in single selection we don't have the "mark all" option |
167 // in single selection we don't have the "mark all" option |
145 if ( mMarkAll ) |
168 if ( mMarkAll->isVisible() ) |
146 { |
169 { |
147 height = height - mMarkAll->size().height(); |
170 height = height - mMarkAll->size().height(); |
148 } |
171 } |
149 |
172 |
150 mEmptyView->setMaximumHeight( height ); |
173 mEmptyView->setMaximumHeight( height ); |
153 } |
176 } |
154 |
177 |
155 void CntFetchContactPopup::handleKeypadClosed() |
178 void CntFetchContactPopup::handleKeypadClosed() |
156 { |
179 { |
157 CNT_ENTRY |
180 CNT_ENTRY |
158 |
181 if (mSearch->criteria().isEmpty()) |
159 qreal height = mPopup->size().height() - mSearch->size().height(); |
182 { |
160 if ( mMarkAll ) |
183 HbListViewItem* prototype = mListView->listItemPrototype(); |
161 { |
184 prototype->setTextFormat( Qt::PlainText ); |
162 height = height - mMarkAll->size().height(); |
185 } |
163 } |
186 |
164 |
187 mListView->setMaximumHeight( -1 ); |
165 mListView->setMaximumHeight( height ); |
188 mEmptyView->setMaximumHeight( -1 ); |
166 mEmptyView->setMaximumHeight( height ); |
|
167 CNT_EXIT |
189 CNT_EXIT |
168 } |
190 } |
169 |
191 |
170 void CntFetchContactPopup::contactSelected( const QModelIndex& aIndex ) |
192 void CntFetchContactPopup::contactSelected( const QModelIndex& aIndex ) |
171 { |
193 { |
191 CNT_ENTRY |
213 CNT_ENTRY |
192 |
214 |
193 // remove all deselected items |
215 // remove all deselected items |
194 foreach ( QModelIndex index, aDeselected.indexes() ) |
216 foreach ( QModelIndex index, aDeselected.indexes() ) |
195 { |
217 { |
196 QContact contact = mModel->contact( index ); |
218 QContactLocalId id = mModel->contactId( index ); |
197 QContactLocalId id = contact.localId(); |
|
198 if ( mIdList.contains(id) ) |
219 if ( mIdList.contains(id) ) |
199 { |
220 { |
200 mIdList.removeAll( id ); |
221 mIdList.removeAll( id ); |
201 } |
222 } |
202 } |
223 } |
203 |
224 |
204 // add all selected items |
225 // add all selected items |
205 foreach ( QModelIndex index, aSelected.indexes() ) |
226 foreach ( QModelIndex index, aSelected.indexes() ) |
206 { |
227 { |
207 QContact contact = mModel->contact( index ); |
228 QContactLocalId id = mModel->contactId( index ); |
208 QContactLocalId id = contact.localId(); |
|
209 if ( !mIdList.contains(id) ) |
229 if ( !mIdList.contains(id) ) |
210 { |
230 { |
211 mIdList.append( id ); |
231 mIdList.append( id ); |
212 } |
232 } |
213 } |
233 } |
214 |
234 |
|
235 qSort(mIdList.begin(), mIdList.end()); |
|
236 if (mIdList == mIds) |
|
237 { |
|
238 mPrimaryAction->setEnabled(false); |
|
239 } |
|
240 else |
|
241 { |
|
242 mPrimaryAction->setEnabled(true); |
|
243 } |
|
244 |
215 mMarkAll->setSelectedContactCount( mIdList.size() ); |
245 mMarkAll->setSelectedContactCount( mIdList.size() ); |
216 CNT_EXIT |
246 CNT_EXIT |
217 } |
247 } |
218 |
248 |
219 void CntFetchContactPopup::selectAll( int aState ) |
249 void CntFetchContactPopup::selectAll( int aState ) |
253 this, SLOT(contactsSelected(const QItemSelection&, const QItemSelection&)) ); |
283 this, SLOT(contactsSelected(const QItemSelection&, const QItemSelection&)) ); |
254 |
284 |
255 QModelIndexList indexList = mSelectionModel->selectedIndexes(); |
285 QModelIndexList indexList = mSelectionModel->selectedIndexes(); |
256 foreach ( QModelIndex index, indexList ) |
286 foreach ( QModelIndex index, indexList ) |
257 { |
287 { |
258 QContact contact = mModel->contact( index ); |
288 mIdList.append(mModel->contactId(index)); |
259 mIdList.append( contact.localId() ); |
|
260 } |
289 } |
261 emit fetchReady( mIdList.toSet() ); |
290 emit fetchReady( mIdList.toSet() ); |
262 } |
291 } |
263 else |
292 else |
264 { |
293 { |
274 detailfilter.setMatchFlags( QContactFilter::MatchStartsWith ); |
303 detailfilter.setMatchFlags( QContactFilter::MatchStartsWith ); |
275 detailfilter.setValue( aFilter.split(QRegExp("\\s+"), QString::SkipEmptyParts) ); |
304 detailfilter.setValue( aFilter.split(QRegExp("\\s+"), QString::SkipEmptyParts) ); |
276 detailfilter.setDetailDefinitionName( |
305 detailfilter.setDetailDefinitionName( |
277 QContactDisplayLabel::DefinitionName, |
306 QContactDisplayLabel::DefinitionName, |
278 QContactDisplayLabel::FieldLabel); |
307 QContactDisplayLabel::FieldLabel); |
279 |
308 |
|
309 int oldRowCount = mModel->rowCount(); |
280 mModel->setFilter(detailfilter); |
310 mModel->setFilter(detailfilter); |
281 |
311 int newRowCount = mModel->rowCount(); |
282 HbMainWindow* window = mPopup->mainWindow(); |
312 |
283 if ( window ) |
313 // minor optimization, only reload layout when needed |
284 { |
314 if ((oldRowCount == 0 && newRowCount > 0) || (oldRowCount > 0 && newRowCount == 0)) |
285 loadLayout( window->orientation() ); |
315 { |
|
316 HbMainWindow* window = mPopup->mainWindow(); |
|
317 if ( window ) |
|
318 { |
|
319 loadLayout( window->orientation() ); |
|
320 } |
286 } |
321 } |
287 |
322 |
288 setSelectedContacts( mIdList.toSet() ); |
323 setSelectedContacts( mIdList.toSet() ); |
289 CNT_EXIT |
324 CNT_EXIT |
290 } |
325 } |
317 prototype->setGraphicsSize(HbListViewItem::Thumbnail); |
352 prototype->setGraphicsSize(HbListViewItem::Thumbnail); |
318 prototype->setStretchingStyle(HbListViewItem::StretchLandscape); |
353 prototype->setStretchingStyle(HbListViewItem::StretchLandscape); |
319 |
354 |
320 mListView->setSelectionMode( aMode ); |
355 mListView->setSelectionMode( aMode ); |
321 mListView->setModel( mModel ); |
356 mListView->setModel( mModel ); |
322 mListView->setSelectionModel( mSelectionModel ); |
357 mListView->setSelectionModel( mSelectionModel ); |
323 |
358 |
324 HbMainWindow* window = mPopup->mainWindow(); |
|
325 if ( window ) |
|
326 { |
|
327 loadLayout( window->orientation() ); |
|
328 } |
|
329 |
359 |
330 if ( !aAction.isEmpty() ) |
360 if ( !aAction.isEmpty() ) |
331 { |
361 { |
332 mPrimaryAction = new HbAction( aAction, mPopup ); |
362 mPrimaryAction = new HbAction( aAction, mPopup ); |
333 mPopup->addAction( mPrimaryAction ); |
363 mPopup->addAction( mPrimaryAction ); |
348 mMarkAll->setMaxContactCount( mModel->rowCount() ); |
378 mMarkAll->setMaxContactCount( mModel->rowCount() ); |
349 connect(mSelectionModel, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), |
379 connect(mSelectionModel, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), |
350 this, SLOT(contactsSelected(const QItemSelection&, const QItemSelection&)) ); |
380 this, SLOT(contactsSelected(const QItemSelection&, const QItemSelection&)) ); |
351 |
381 |
352 } |
382 } |
|
383 |
|
384 HbMainWindow* window = mPopup->mainWindow(); |
|
385 if ( window ) |
|
386 { |
|
387 loadLayout( window->orientation() ); |
|
388 } |
353 |
389 |
354 CNT_EXIT |
390 CNT_EXIT |
355 } |
391 } |
356 |
392 |
357 void CntFetchContactPopup::loadLayout( Qt::Orientation aOrientation ) |
393 void CntFetchContactPopup::loadLayout( Qt::Orientation aOrientation ) |
366 mPopup->setHeadingWidget( NULL ); |
402 mPopup->setHeadingWidget( NULL ); |
367 mDoc->load( CNT_FETCHLIST_XML, "find_list_landscape"); |
403 mDoc->load( CNT_FETCHLIST_XML, "find_list_landscape"); |
368 } |
404 } |
369 else |
405 else |
370 { |
406 { |
371 mHeading = new HbLabel( mTitle ); |
407 if (mPopup->headingWidget() == NULL) |
372 mPopup->setHeadingWidget( mHeading ); |
408 { |
373 qreal popupHeight = mPopup->mainWindow()->layoutRect().height(); |
409 mHeading = new HbLabel( mTitle ); |
374 mPopup->setMinimumHeight(popupHeight); |
410 mPopup->setHeadingWidget( mHeading ); |
|
411 } |
|
412 else |
|
413 { |
|
414 mHeading->setPlainText( mTitle ); |
|
415 } |
|
416 |
375 mDoc->load( CNT_FETCHLIST_XML, multi ? "find_list" : "find_list_single"); |
417 mDoc->load( CNT_FETCHLIST_XML, multi ? "find_list" : "find_list_single"); |
376 } |
418 } |
377 } |
419 } |
378 else |
420 else |
379 { |
421 { |
382 mPopup->setHeadingWidget( NULL ); |
424 mPopup->setHeadingWidget( NULL ); |
383 mDoc->load( CNT_FETCHLIST_XML, "find_empty_landscape" ); |
425 mDoc->load( CNT_FETCHLIST_XML, "find_empty_landscape" ); |
384 } |
426 } |
385 else |
427 else |
386 { |
428 { |
387 mHeading = new HbLabel( mTitle ); |
429 if (mPopup->headingWidget() == NULL) |
388 mPopup->setHeadingWidget( mHeading ); |
430 { |
389 qreal popupHeight = mPopup->mainWindow()->layoutRect().height(); |
431 mHeading = new HbLabel( mTitle ); |
390 mPopup->setMinimumHeight(popupHeight); |
432 mPopup->setHeadingWidget( mHeading ); |
|
433 } |
|
434 else |
|
435 { |
|
436 mHeading->setPlainText( mTitle ); |
|
437 } |
|
438 |
391 mDoc->load( CNT_FETCHLIST_XML, multi ? "find_empty" : "find_empty_single" ); |
439 mDoc->load( CNT_FETCHLIST_XML, multi ? "find_empty" : "find_empty_single" ); |
392 } |
440 } |
393 } |
441 } |
394 |
442 |
395 CNT_EXIT |
443 CNT_EXIT |
396 } |
444 } |
397 |
445 |
|
446 void CntFetchContactPopup::orientationChanged( Qt::Orientation aOrientation ) |
|
447 { |
|
448 CNT_ENTRY |
|
449 |
|
450 mDoc->load( CNT_FETCHLIST_XML, "size_section"); |
|
451 |
|
452 loadLayout(aOrientation); |
|
453 |
|
454 CNT_EXIT |
|
455 } |
|
456 |
398 void CntFetchContactPopup::closePopup() |
457 void CntFetchContactPopup::closePopup() |
399 { |
458 { |
400 CNT_ENTRY |
459 CNT_ENTRY |
|
460 mPopup->close(); |
401 disconnect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(handleKeypadOpen())); |
461 disconnect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(handleKeypadOpen())); |
402 disconnect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(handleKeypadClosed())); |
462 disconnect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(handleKeypadClosed())); |
403 |
463 |
404 deleteLater(); |
464 deleteLater(); |
405 CNT_EXIT |
465 CNT_EXIT |