phonebookui/pbkcommonui/src/cntfetchcontactsview.cpp
changeset 37 fd64c38c277d
parent 31 2a11b5b00470
child 40 b46a585f6909
equal deleted inserted replaced
31:2a11b5b00470 37:fd64c38c277d
    25 #include <hblistviewitem.h>
    25 #include <hblistviewitem.h>
    26 #include <hblistview.h>
    26 #include <hblistview.h>
    27 #include <hbsearchpanel.h>
    27 #include <hbsearchpanel.h>
    28 #include <hbstaticvkbhost.h>
    28 #include <hbstaticvkbhost.h>
    29 #include <QGraphicsLinearLayout>
    29 #include <QGraphicsLinearLayout>
    30 #include <QContactId.h>
    30 #include <qcontactid.h>
    31 #include <QDebug>
    31 #include <QDebug>
    32 #include <mobcntmodel.h>
    32 #include <mobcntmodel.h>
    33 #include "cntfetchcontactsview.h"
    33 #include "cntfetchcontactsview.h"
    34 
    34 
    35 /*!
    35 /*!
    51 mSecondaryAction(NULL),
    51 mSecondaryAction(NULL),
    52 mIndexFeedback(NULL)
    52 mIndexFeedback(NULL)
    53 {
    53 {
    54     mSearchPanel = new HbSearchPanel();
    54     mSearchPanel = new HbSearchPanel();
    55     mSearchPanel->setVisible(false);
    55     mSearchPanel->setVisible(false);
    56     connect(mSearchPanel, SIGNAL(exitClicked()), this, SLOT(closeFind()));
    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     mLayout = new QGraphicsLinearLayout(Qt::Vertical);
    59     mLayout = new QGraphicsLinearLayout(Qt::Vertical);
    60     
    60     
    61     mContainerWidget = new HbWidget();
    61     mContainerWidget = new HbWidget();
   143 QSet<QContactLocalId> CntFetchContacts::getSelectedContacts() const
   143 QSet<QContactLocalId> CntFetchContacts::getSelectedContacts() const
   144 {
   144 {
   145    return mCurrentlySelected;
   145    return mCurrentlySelected;
   146 }
   146 }
   147 
   147 
   148 void CntFetchContacts::closeFind()
       
   149 {
       
   150     if (mSearchPanel) {
       
   151          QContactDetailFilter filter;
       
   152          filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
       
   153          QString typeContact = QContactType::TypeContact;
       
   154          filter.setValue(typeContact);
       
   155 
       
   156          mSearchPanel->deleteLater();
       
   157      }
       
   158 }
       
   159 
       
   160 void CntFetchContacts::setFilter(const QString &filterString)
   148 void CntFetchContacts::setFilter(const QString &filterString)
   161 {
   149 {
   162     QStringList searchList = filterString.split(QRegExp("\\s+"), QString::SkipEmptyParts);
   150     QStringList searchList = filterString.split(QRegExp("\\s+"), QString::SkipEmptyParts);
   163 
   151 
   164     QContactDetailFilter detailfilter;
   152     QContactDetailFilter detailfilter;
   252         }
   240         }
   253         else {
   241         else {
   254             mCurrentlySelected.remove(contactId);
   242             mCurrentlySelected.remove(contactId);
   255         }
   243         }
   256     }
   244     }
       
   245     
       
   246     // Check for the case where there is a cancel button only. If so, 
       
   247     // after selecting any contact, should dismiss the dialog immediately.
       
   248     if (mButtonText.isEmpty() && mSelectionMode == HbAbstractItemView::SingleSelection) {
       
   249         mPopup->close();
       
   250     }
   257 }
   251 }
   258 
   252 
   259 void CntFetchContacts::doInitialize(HbAbstractItemView::SelectionMode aMode,
   253 void CntFetchContacts::doInitialize(HbAbstractItemView::SelectionMode aMode,
   260                                                 QSet<QContactLocalId> aContacts)
   254                                                 QSet<QContactLocalId> aContacts)
   261 {
   255 {
   262     mSelectionMode = aMode;
   256     mSelectionMode = aMode;
   263     mCurrentlySelected = aContacts;
   257     mCurrentlySelected = aContacts;
   264 
   258 
   265     mSearchPanel->setVisible(true);
   259     mSearchPanel->setVisible(true);
   266 
   260 
   267     mPopup = new HbDialog;
   261     if (!mPopup) {
   268     mListView = new HbListView(mPopup);
   262         mPopup = new HbDialog;
   269     mListView->setModel(mCntModel);
   263     }
   270     mListView->setSelectionMode(mSelectionMode);
   264     
   271     mListView->setFrictionEnabled(true);
   265     if (!mListView) {
   272     mListView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
   266         mListView = new HbListView(mPopup);
   273     mListView->verticalScrollBar()->setInteractive(true);
   267         mListView->setModel(mCntModel);
   274 
   268         mListView->setSelectionMode(mSelectionMode);
   275     HbListViewItem *prototype = mListView->listItemPrototype();
   269         mListView->setFrictionEnabled(true);
   276     prototype->setGraphicsSize(HbListViewItem::Thumbnail);
   270         mListView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
   277     prototype->setStretchingStyle(HbListViewItem::StretchLandscape);
   271         mListView->verticalScrollBar()->setInteractive(true);
   278 
   272 
   279     mIndexFeedback = new HbIndexFeedback(mPopup);
   273         HbListViewItem *prototype = mListView->listItemPrototype();
   280     mIndexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
   274         prototype->setGraphicsSize(HbListViewItem::Thumbnail);
   281     mIndexFeedback->setItemView(mListView);
   275         prototype->setStretchingStyle(HbListViewItem::StretchLandscape);
   282     
   276 
   283     // Note that the layout takes ownership of the item(s) it contains.
   277         mIndexFeedback = new HbIndexFeedback(mPopup);
   284     if (!mCntModel->rowCount()) {
   278         mIndexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
   285         mListView->setVisible(false);
   279         mIndexFeedback->setItemView(mListView);
   286         if (!mEmptyListLabel) {
   280 
   287             mEmptyListLabel = new HbTextItem(hbTrId("(no matching contacts)"));
   281         // Note that the layout takes ownership of the item(s) it contains.
   288             mEmptyListLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
   282         if (!mCntModel->rowCount()) {
   289             mEmptyListLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary));
   283             mListView->setVisible(false);
   290             mEmptyListLabel->setAlignment(Qt::AlignCenter);
   284             if (!mEmptyListLabel) {
   291             mLayout->insertItem(0, mEmptyListLabel);
   285                 mEmptyListLabel = new HbTextItem(hbTrId("txt_phob_info_no_matching_contacts"));
   292         }
   286                 mEmptyListLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
   293     }
   287                 mEmptyListLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary));
   294     else {
   288                 mEmptyListLabel->setAlignment(Qt::AlignCenter);
   295         mLayout->addItem(mListView);
   289                 mLayout->insertItem(0, mEmptyListLabel);
   296     }
   290             }
   297     
   291         }
   298     mCntModel->showMyCard(false);
   292         else {
       
   293             mLayout->addItem(mListView);
       
   294         }
       
   295 
       
   296         mCntModel->showMyCard(false);
       
   297     }
   299 }
   298 }
   300 
   299 
   301 void CntFetchContacts::connectSignal()
   300 void CntFetchContacts::connectSignal()
   302 {
   301 {
   303     connect(mListView, SIGNAL(activated(const QModelIndex&)),
   302     connect(mListView, SIGNAL(activated(const QModelIndex&)),
   320     if (!mLabel) {
   319     if (!mLabel) {
   321         mLabel = new HbLabel(hbTrId("txt_phob_title_contacts"));
   320         mLabel = new HbLabel(hbTrId("txt_phob_title_contacts"));
   322     }
   321     }
   323     mPopup->setHeadingWidget(mLabel);
   322     mPopup->setHeadingWidget(mLabel);
   324 
   323 
   325     if (!mButtonText.isEmpty()) {
   324     if (!mButtonText.isEmpty() && !mPrimaryAction) {
   326         mPrimaryAction = new HbAction(hbTrId(mButtonText.toAscii()));
   325         mPrimaryAction = new HbAction(hbTrId(mButtonText.toAscii()));
   327         mPopup->addAction(mPrimaryAction);
   326         mPopup->addAction(mPrimaryAction);
   328     }
   327     }
   329     
   328     
   330     mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
   329     if (!mSecondaryAction) {
   331     mPopup->addAction(mSecondaryAction);
   330         mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   331         mPopup->addAction(mSecondaryAction);
       
   332     }
   332 
   333 
   333     mPopup->open(this, SLOT(handleUserResponse(HbAction*)));
   334     mPopup->open(this, SLOT(handleUserResponse(HbAction*)));
   334 }
   335 }
   335 
   336 
   336 void CntFetchContacts::markMembersInView()
   337 void CntFetchContacts::markMembersInView()