72
|
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 |
#include "cntfetchcontactpopup.h"
|
|
18 |
#include "cntdocumentloader.h"
|
|
19 |
#include "cntfetchmarkall.h"
|
|
20 |
#include "cntdebug.h"
|
|
21 |
|
|
22 |
#include <cntlistmodel.h>
|
|
23 |
#include <hblistview.h>
|
|
24 |
#include <hbstyleloader.h>
|
|
25 |
#include <hbindexfeedback.h>
|
|
26 |
#include <hblistviewitem.h>
|
|
27 |
#include <hbscrollbar.h>
|
|
28 |
#include <hbmainwindow.h>
|
|
29 |
#include <hbdialog.h>
|
|
30 |
#include <hblabel.h>
|
|
31 |
#include <hbsearchpanel.h>
|
|
32 |
#include <hblineedit.h>
|
|
33 |
#include <hbaction.h>
|
|
34 |
#include <hbstaticvkbhost.h>
|
|
35 |
#include <hbstyleloader.h>
|
|
36 |
#include <hbstyle.h>
|
|
37 |
|
|
38 |
#include <QGraphicsLinearLayout>
|
|
39 |
#include <QCoreApplication>
|
|
40 |
#include <QtAlgorithms>
|
|
41 |
|
|
42 |
const char *CNT_FETCHLIST_XML = ":/xml/contacts_fetchdialog.docml";
|
|
43 |
|
|
44 |
CntFetchContactPopup::CntFetchContactPopup( QContactManager& aMgr ) :
|
|
45 |
mManager(aMgr),
|
|
46 |
mPopup( NULL ),
|
|
47 |
mListView( NULL ),
|
|
48 |
mEmptyView( NULL ),
|
|
49 |
mHeading( NULL ),
|
|
50 |
mPrimaryAction( NULL ),
|
|
51 |
mSearch( NULL ),
|
|
52 |
mModel( NULL ),
|
|
53 |
mMarkAll( NULL ),
|
|
54 |
mDoc( NULL )
|
|
55 |
{
|
|
56 |
HbStyleLoader::registerFilePath(":/temp/fetchdialog.css");
|
|
57 |
|
|
58 |
mDoc = new CntDocumentLoader();
|
|
59 |
|
|
60 |
bool ok;
|
|
61 |
mDoc->load( CNT_FETCHLIST_XML, &ok );
|
|
62 |
|
|
63 |
if ( !ok )
|
|
64 |
{
|
|
65 |
qFatal("Unable to read %S", CNT_FETCHLIST_XML );
|
|
66 |
}
|
|
67 |
mDoc->load( CNT_FETCHLIST_XML, "size_section");
|
|
68 |
|
|
69 |
mPopup = static_cast<HbDialog*>( mDoc->findWidget( "dialog" ) );
|
|
70 |
mSearch = static_cast<HbSearchPanel*>( mDoc->findWidget( "searchPanel" ) );
|
|
71 |
mMarkAll = static_cast<CntFetchMarkAll*>( mDoc->findWidget("markAll") );
|
|
72 |
mListView = static_cast<HbListView*>( mDoc->findWidget("listView") );
|
|
73 |
mEmptyView = static_cast<HbLabel*>( mDoc->findWidget("emptyLabel" ));
|
|
74 |
mEmptyView->setSizePolicy(mListView->sizePolicy());
|
|
75 |
mHeading = static_cast<HbLabel*>( mDoc->findWidget("heading") );
|
|
76 |
|
|
77 |
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(closePopup()));
|
|
78 |
connect(mPopup, SIGNAL(aboutToClose()), this, SLOT(disconnectSignalsAndDelete()));
|
|
79 |
connect(mSearch, SIGNAL(criteriaChanged(QString)), this, SLOT(setFilter(QString)));
|
|
80 |
connect(mMarkAll, SIGNAL(markAll(int)), this, SLOT(selectAll(int)) );
|
|
81 |
|
|
82 |
HbLineEdit *editor = static_cast<HbLineEdit*>( mSearch->primitive("lineedit"));
|
|
83 |
editor->setInputMethodHints(Qt::ImhNoPredictiveText);
|
|
84 |
mSearch->setCancelEnabled( false );
|
|
85 |
|
|
86 |
mVirtualKeyboard = new HbStaticVkbHost(editor);
|
|
87 |
connect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(handleKeypadOpen()));
|
|
88 |
connect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(handleKeypadClosed()));
|
|
89 |
|
|
90 |
mMarkAll->setZValue( 2 );
|
|
91 |
}
|
|
92 |
|
|
93 |
CntFetchContactPopup::~CntFetchContactPopup()
|
|
94 |
{
|
|
95 |
HbStyleLoader::unregisterFilePath(":/temp/fetchdialog.css");
|
|
96 |
delete mDoc;
|
|
97 |
}
|
|
98 |
|
|
99 |
CntFetchContactPopup* CntFetchContactPopup::createMultiSelectionPopup( QString aTitle, QString aAction, QContactManager& aManager )
|
|
100 |
{
|
|
101 |
CntFetchContactPopup* popup = new CntFetchContactPopup( aManager );
|
|
102 |
popup->constructPopupDialog( aTitle, aAction, HbAbstractItemView::MultiSelection );
|
|
103 |
return popup;
|
|
104 |
}
|
|
105 |
|
|
106 |
CntFetchContactPopup* CntFetchContactPopup::createSingleSelectionPopup( QString aTitle, QContactManager& aManager )
|
|
107 |
{
|
|
108 |
CntFetchContactPopup* popup = new CntFetchContactPopup( aManager );
|
|
109 |
popup->constructPopupDialog( aTitle, "", HbAbstractItemView::NoSelection );
|
|
110 |
|
|
111 |
return popup;
|
|
112 |
}
|
|
113 |
|
|
114 |
void CntFetchContactPopup::setSelectedContacts( QSet<QContactLocalId> aIds )
|
|
115 |
{
|
|
116 |
CNT_ENTRY
|
|
117 |
if ( mListView->selectionMode() == HbAbstractItemView::MultiSelection )
|
|
118 |
{
|
|
119 |
mIdList.clear();
|
|
120 |
foreach ( QContactLocalId id, aIds )
|
|
121 |
{
|
|
122 |
mIdList.append( id );
|
|
123 |
QModelIndex contactIndex = mModel->indexOfContactId(id);
|
|
124 |
mSelectionModel->select( contactIndex, QItemSelectionModel::Select );
|
|
125 |
}
|
|
126 |
}
|
|
127 |
CNT_EXIT
|
|
128 |
}
|
|
129 |
|
|
130 |
void CntFetchContactPopup::showPopup()
|
|
131 |
{
|
|
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 |
|
|
146 |
HbMainWindow* window = mPopup->mainWindow();
|
|
147 |
if ( window )
|
|
148 |
{
|
|
149 |
connect(window, SIGNAL(orientationChanged(Qt::Orientation)),
|
|
150 |
this, SLOT(orientationChanged(Qt::Orientation)) );
|
|
151 |
}
|
|
152 |
|
|
153 |
mPopup->open( this, SLOT(dialogDismissed(HbAction*)) );
|
|
154 |
CNT_EXIT
|
|
155 |
}
|
|
156 |
|
|
157 |
void CntFetchContactPopup::handleKeypadOpen()
|
|
158 |
{
|
|
159 |
CNT_ENTRY
|
|
160 |
|
|
161 |
HbListViewItem* prototype = mListView->listItemPrototype();
|
|
162 |
prototype->setTextFormat( Qt::RichText );
|
|
163 |
|
|
164 |
qreal margin;
|
|
165 |
HbStyle style;
|
|
166 |
style.parameter("hb-param-margin-gene-popup", margin);
|
|
167 |
|
|
168 |
if (mPopup->mainWindow()->orientation() == Qt::Horizontal)
|
|
169 |
margin /= 2;
|
|
170 |
|
|
171 |
qreal height = mPopup->size().height() -
|
|
172 |
mVirtualKeyboard->keyboardArea().height() -
|
|
173 |
mSearch->size().height() +
|
|
174 |
margin;
|
|
175 |
|
|
176 |
// in single selection we don't have the "mark all" option
|
|
177 |
if ( mMarkAll->isVisible() )
|
|
178 |
{
|
|
179 |
height = height - mMarkAll->size().height();
|
|
180 |
}
|
|
181 |
|
|
182 |
mEmptyView->setMaximumHeight( height );
|
|
183 |
mListView->setMaximumHeight( height );
|
|
184 |
CNT_EXIT
|
|
185 |
}
|
|
186 |
|
|
187 |
void CntFetchContactPopup::handleKeypadClosed()
|
|
188 |
{
|
|
189 |
CNT_ENTRY
|
|
190 |
|
|
191 |
if (mSearch->criteria().isEmpty())
|
|
192 |
{
|
|
193 |
HbListViewItem* prototype = mListView->listItemPrototype();
|
|
194 |
prototype->setTextFormat( Qt::PlainText );
|
|
195 |
}
|
|
196 |
|
|
197 |
mListView->setMaximumHeight( -1 );
|
|
198 |
mEmptyView->setMaximumHeight( -1 );
|
|
199 |
CNT_EXIT
|
|
200 |
}
|
|
201 |
|
|
202 |
void CntFetchContactPopup::contactSelected( const QModelIndex& aIndex )
|
|
203 |
{
|
|
204 |
CNT_ENTRY
|
|
205 |
if ( aIndex.isValid() )
|
|
206 |
{
|
|
207 |
QContact contact = mModel->contact( aIndex );
|
|
208 |
mIdList.append( contact.localId() );
|
|
209 |
|
|
210 |
emit fetchReady( mIdList.toSet() );
|
|
211 |
}
|
|
212 |
|
|
213 |
disconnect(mListView, SIGNAL(activated(const QModelIndex&)),
|
|
214 |
this, SLOT(contactSelected(const QModelIndex&)) );
|
|
215 |
mPopup->close();
|
|
216 |
CNT_EXIT
|
|
217 |
}
|
|
218 |
|
|
219 |
void CntFetchContactPopup::contactsSelected(
|
|
220 |
const QItemSelection& aSelected,
|
|
221 |
const QItemSelection& aDeselected )
|
|
222 |
{
|
|
223 |
CNT_ENTRY
|
|
224 |
|
|
225 |
// remove all deselected items
|
|
226 |
foreach ( QModelIndex index, aDeselected.indexes() )
|
|
227 |
{
|
|
228 |
QContactLocalId id = mModel->contactId( index );
|
|
229 |
if ( mIdList.contains(id) )
|
|
230 |
{
|
|
231 |
mIdList.removeAll( id );
|
|
232 |
}
|
|
233 |
}
|
|
234 |
|
|
235 |
// add all selected items
|
|
236 |
foreach ( QModelIndex index, aSelected.indexes() )
|
|
237 |
{
|
|
238 |
QContactLocalId id = mModel->contactId( index );
|
|
239 |
if ( !mIdList.contains(id) )
|
|
240 |
{
|
|
241 |
mIdList.append( id );
|
|
242 |
}
|
|
243 |
}
|
|
244 |
|
|
245 |
qSort(mIdList.begin(), mIdList.end());
|
|
246 |
if (mIdList == mIds)
|
|
247 |
{
|
|
248 |
mPrimaryAction->setEnabled(false);
|
|
249 |
}
|
|
250 |
else
|
|
251 |
{
|
|
252 |
mPrimaryAction->setEnabled(true);
|
|
253 |
}
|
|
254 |
|
|
255 |
mMarkAll->setSelectedContactCount( mIdList.size() );
|
|
256 |
CNT_EXIT
|
|
257 |
}
|
|
258 |
|
|
259 |
void CntFetchContactPopup::selectAll( int aState )
|
|
260 |
{
|
|
261 |
CNT_ENTRY
|
|
262 |
if ( mListView->selectionMode() == HbAbstractItemView::MultiSelection )
|
|
263 |
{
|
|
264 |
switch ( aState )
|
|
265 |
{
|
|
266 |
case Qt::Checked:
|
|
267 |
mListView->selectAll();
|
|
268 |
mMarkAll->setSelectedContactCount( mIdList.count() );
|
|
269 |
break;
|
|
270 |
|
|
271 |
case Qt::Unchecked:
|
|
272 |
mListView->clearSelection();
|
|
273 |
mMarkAll->setSelectedContactCount( 0 );
|
|
274 |
break;
|
|
275 |
default:
|
|
276 |
break;
|
|
277 |
}
|
|
278 |
}
|
|
279 |
CNT_EXIT
|
|
280 |
}
|
|
281 |
|
|
282 |
void CntFetchContactPopup::dialogDismissed( HbAction* aAction )
|
|
283 |
{
|
|
284 |
CNT_ENTRY
|
|
285 |
|
|
286 |
if ( aAction != mPrimaryAction )
|
|
287 |
{
|
|
288 |
emit fetchCancelled();
|
|
289 |
}
|
|
290 |
else if ( aAction )
|
|
291 |
{
|
|
292 |
disconnect(mSelectionModel, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
|
|
293 |
this, SLOT(contactsSelected(const QItemSelection&, const QItemSelection&)) );
|
|
294 |
|
|
295 |
QModelIndexList indexList = mSelectionModel->selectedIndexes();
|
|
296 |
foreach ( QModelIndex index, indexList )
|
|
297 |
{
|
|
298 |
mIdList.append(mModel->contactId(index));
|
|
299 |
}
|
|
300 |
emit fetchReady( mIdList.toSet() );
|
|
301 |
}
|
|
302 |
else
|
|
303 |
{
|
|
304 |
// ignore.
|
|
305 |
}
|
|
306 |
CNT_EXIT
|
|
307 |
}
|
|
308 |
|
|
309 |
void CntFetchContactPopup::setFilter( const QString& aFilter )
|
|
310 |
{
|
|
311 |
CNT_ENTRY
|
|
312 |
QContactDetailFilter detailfilter;
|
|
313 |
detailfilter.setMatchFlags( QContactFilter::MatchStartsWith );
|
|
314 |
detailfilter.setValue( aFilter.split(QRegExp("\\s+"), QString::SkipEmptyParts) );
|
|
315 |
detailfilter.setDetailDefinitionName(
|
|
316 |
QContactDisplayLabel::DefinitionName,
|
|
317 |
QContactDisplayLabel::FieldLabel);
|
|
318 |
|
|
319 |
int oldRowCount = mModel->rowCount();
|
|
320 |
mModel->setFilter(detailfilter);
|
|
321 |
int newRowCount = mModel->rowCount();
|
|
322 |
|
|
323 |
// minor optimization, only reload layout when needed
|
|
324 |
if ((oldRowCount == 0 && newRowCount > 0) || (oldRowCount > 0 && newRowCount == 0))
|
|
325 |
{
|
|
326 |
HbMainWindow* window = mPopup->mainWindow();
|
|
327 |
if ( window )
|
|
328 |
{
|
|
329 |
loadLayout( window->orientation() );
|
|
330 |
}
|
|
331 |
}
|
|
332 |
|
|
333 |
setSelectedContacts( mIdList.toSet() );
|
|
334 |
CNT_EXIT
|
|
335 |
}
|
|
336 |
|
|
337 |
void CntFetchContactPopup::constructPopupDialog( QString aTitle, QString aAction, HbAbstractItemView::SelectionMode aMode )
|
|
338 |
{
|
|
339 |
CNT_ENTRY
|
|
340 |
mIdList.clear();
|
|
341 |
mTitle = aTitle;
|
|
342 |
|
|
343 |
mPopup->setAttribute( Qt::WA_DeleteOnClose, true );
|
|
344 |
|
|
345 |
QContactDetailFilter contactsFilter;
|
|
346 |
contactsFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
|
|
347 |
contactsFilter.setValue(QString(QLatin1String(QContactType::TypeContact)));
|
|
348 |
|
|
349 |
mModel = new CntListModel( &mManager, contactsFilter, false, mPopup);
|
|
350 |
mModel->showMyCard(false);
|
|
351 |
mSelectionModel = new QItemSelectionModel( mModel );
|
|
352 |
|
|
353 |
mListView->setFrictionEnabled(true);
|
|
354 |
mListView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
|
|
355 |
mListView->verticalScrollBar()->setInteractive(true);
|
|
356 |
|
|
357 |
HbIndexFeedback* indexFeedback = new HbIndexFeedback(mPopup);
|
|
358 |
indexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
|
|
359 |
indexFeedback->setItemView(mListView);
|
|
360 |
|
|
361 |
HbListViewItem *prototype = mListView->listItemPrototype();
|
|
362 |
prototype->setGraphicsSize(HbListViewItem::Thumbnail);
|
|
363 |
prototype->setStretchingStyle(HbListViewItem::StretchLandscape);
|
|
364 |
|
|
365 |
mListView->setSelectionMode( aMode );
|
|
366 |
mListView->setModel( mModel );
|
|
367 |
mListView->setSelectionModel( mSelectionModel );
|
|
368 |
|
|
369 |
|
|
370 |
if ( !aAction.isEmpty() )
|
|
371 |
{
|
|
372 |
mPrimaryAction = new HbAction( aAction, mPopup );
|
|
373 |
mPopup->addAction( mPrimaryAction );
|
|
374 |
}
|
|
375 |
|
|
376 |
HbAction* secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), mPopup);
|
|
377 |
mPopup->addAction( secondaryAction );
|
|
378 |
|
|
379 |
if ( aMode != HbListView::MultiSelection )
|
|
380 |
{
|
|
381 |
connect(mListView, SIGNAL(activated(const QModelIndex&)),
|
|
382 |
this, SLOT(contactSelected(const QModelIndex&)) );
|
|
383 |
mMarkAll->setVisible( false );
|
|
384 |
}
|
|
385 |
else
|
|
386 |
{
|
|
387 |
mMarkAll->setMaxContactCount( mModel->rowCount() );
|
|
388 |
mMarkAll->setSelectedContactCount( 0 );
|
|
389 |
|
|
390 |
connect(mSelectionModel, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
|
|
391 |
this, SLOT(contactsSelected(const QItemSelection&, const QItemSelection&)) );
|
|
392 |
|
|
393 |
}
|
|
394 |
|
|
395 |
HbMainWindow* window = mPopup->mainWindow();
|
|
396 |
if ( window )
|
|
397 |
{
|
|
398 |
loadLayout( window->orientation() );
|
|
399 |
}
|
|
400 |
|
|
401 |
CNT_EXIT
|
|
402 |
}
|
|
403 |
|
|
404 |
void CntFetchContactPopup::loadLayout( Qt::Orientation aOrientation )
|
|
405 |
{
|
|
406 |
CNT_ENTRY
|
|
407 |
|
|
408 |
bool multi = mListView->selectionMode() == HbAbstractItemView::MultiSelection;
|
|
409 |
if ( mModel->rowCount() > 0 )
|
|
410 |
{
|
|
411 |
if ( aOrientation == Qt::Horizontal )
|
|
412 |
{
|
|
413 |
mPopup->setHeadingWidget( NULL );
|
|
414 |
mDoc->load( CNT_FETCHLIST_XML, "find_list_landscape");
|
|
415 |
}
|
|
416 |
else
|
|
417 |
{
|
|
418 |
if (mPopup->headingWidget() == NULL)
|
|
419 |
{
|
|
420 |
mHeading = new HbLabel( mTitle );
|
|
421 |
mPopup->setHeadingWidget( mHeading );
|
|
422 |
}
|
|
423 |
else
|
|
424 |
{
|
|
425 |
mHeading->setPlainText( mTitle );
|
|
426 |
}
|
|
427 |
|
|
428 |
mDoc->load( CNT_FETCHLIST_XML, multi ? "find_list" : "find_list_single");
|
|
429 |
}
|
|
430 |
}
|
|
431 |
else
|
|
432 |
{
|
|
433 |
if ( aOrientation == Qt::Horizontal )
|
|
434 |
{
|
|
435 |
mPopup->setHeadingWidget( NULL );
|
|
436 |
mDoc->load( CNT_FETCHLIST_XML, "find_empty_landscape" );
|
|
437 |
}
|
|
438 |
else
|
|
439 |
{
|
|
440 |
if (mPopup->headingWidget() == NULL)
|
|
441 |
{
|
|
442 |
mHeading = new HbLabel( mTitle );
|
|
443 |
mPopup->setHeadingWidget( mHeading );
|
|
444 |
}
|
|
445 |
else
|
|
446 |
{
|
|
447 |
mHeading->setPlainText( mTitle );
|
|
448 |
}
|
|
449 |
|
|
450 |
mDoc->load( CNT_FETCHLIST_XML, multi ? "find_empty" : "find_empty_single" );
|
|
451 |
}
|
|
452 |
}
|
|
453 |
|
|
454 |
CNT_EXIT
|
|
455 |
}
|
|
456 |
|
|
457 |
void CntFetchContactPopup::orientationChanged( Qt::Orientation aOrientation )
|
|
458 |
{
|
|
459 |
CNT_ENTRY
|
|
460 |
|
|
461 |
mDoc->load( CNT_FETCHLIST_XML, "size_section");
|
|
462 |
|
|
463 |
loadLayout(aOrientation);
|
|
464 |
|
|
465 |
CNT_EXIT
|
|
466 |
}
|
|
467 |
|
|
468 |
void CntFetchContactPopup::closePopup()
|
|
469 |
{
|
|
470 |
CNT_ENTRY
|
|
471 |
|
|
472 |
mPopup->close();
|
|
473 |
|
|
474 |
disconnectSignalsAndDelete();
|
|
475 |
|
|
476 |
CNT_EXIT
|
|
477 |
}
|
|
478 |
|
|
479 |
void CntFetchContactPopup::disconnectSignalsAndDelete()
|
|
480 |
{
|
|
481 |
CNT_ENTRY
|
|
482 |
disconnect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(handleKeypadOpen()));
|
|
483 |
disconnect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(handleKeypadClosed()));
|
|
484 |
|
|
485 |
deleteLater();
|
|
486 |
CNT_EXIT
|
|
487 |
}
|
|
488 |
// End of File
|