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