phonebookui/pbkcommonui/src/cntfetchcontactsview.cpp
changeset 50 77bc263e1626
parent 47 7cbcb2896f0e
equal deleted inserted replaced
49:74b30151afd6 50:77bc263e1626
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include "cntfetchcontactsview.h"
       
    19 
       
    20 #include <cntlistmodel.h>
       
    21 
       
    22 #include <QGraphicsLinearLayout>
       
    23 
       
    24 #include <qcontactid.h>
    18 #include <hbdialog.h>
    25 #include <hbdialog.h>
    19 #include <hbscrollbar.h>
    26 #include <hbscrollbar.h>
    20 #include <hbindexfeedback.h>
    27 #include <hbindexfeedback.h>
    21 #include <hbaction.h>
    28 #include <hbaction.h>
    22 #include <hblabel.h>
    29 #include <hblabel.h>
    25 #include <hbmainwindow.h>
    32 #include <hbmainwindow.h>
    26 #include <hblistviewitem.h>
    33 #include <hblistviewitem.h>
    27 #include <hblistview.h>
    34 #include <hblistview.h>
    28 #include <hbsearchpanel.h>
    35 #include <hbsearchpanel.h>
    29 #include <hbstaticvkbhost.h>
    36 #include <hbstaticvkbhost.h>
    30 #include <QGraphicsLinearLayout>
       
    31 #include <qcontactid.h>
       
    32 #include <cntlistmodel.h>
       
    33 #include "cntfetchcontactsview.h"
       
    34 
    37 
    35 /*!
    38 /*!
    36 Given a contact manager, CntFetchContacts is responsible for 
    39 Given a contact manager, CntFetchContacts is responsible for 
    37 retrieving a set of contacts, if any were chosen by the user. 
    40 retrieving a set of contacts, if any were chosen by the user. 
    38 */
    41 */
    39 CntFetchContacts::CntFetchContacts(QContactManager &aManager) :
    42 CntFetchContacts::CntFetchContacts(QContactManager &aManager) :
    40 QObject(),
    43     QObject(),
    41 mPopup(NULL),
    44     mPopup(NULL),
    42 mCntModel(NULL),
    45     mCntModel(NULL),
    43 mListView(NULL),
    46     mListView(NULL),
    44 mEmptyListLabel(NULL),
    47     mEmptyListLabel(NULL),
    45 mSelectionMode(HbAbstractItemView::MultiSelection),
    48     mSelectionMode(HbAbstractItemView::MultiSelection),
    46 mManager(&aManager),
    49     mManager(&aManager),
    47 mWasCanceled(false),
    50     mWasCanceled(false),
    48 mLabel(NULL),
    51     mLabel(NULL),
    49 mVirtualKeyboard(NULL),
    52     mVirtualKeyboard(NULL),
    50 mPrimaryAction(NULL),
    53     mPrimaryAction(NULL),
    51 mSecondaryAction(NULL),
    54     mSecondaryAction(NULL),
    52 mIndexFeedback(NULL)
    55     mIndexFeedback(NULL)
    53 {
    56 {
    54     mSearchPanel = new HbSearchPanel();
    57     mSearchPanel = new HbSearchPanel();
    55     mSearchPanel->setVisible(false);
    58     mSearchPanel->setVisible(false);
    56     mSearchPanel->setCancelEnabled(false);
    59     mSearchPanel->setCancelEnabled(false);
    57     connect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this, SLOT(setFilter(QString)));
    60     connect(mSearchPanel, SIGNAL(criteriaChanged(QString)), this, SLOT(setFilter(QString)));
    66 
    69 
    67 CntFetchContacts::~CntFetchContacts()
    70 CntFetchContacts::~CntFetchContacts()
    68 {
    71 {
    69     delete mCntModel;
    72     delete mCntModel;
    70     mCntModel = NULL;
    73     mCntModel = NULL;
    71     
       
    72     delete mVirtualKeyboard;
       
    73     mVirtualKeyboard = NULL;
       
    74     
       
    75     delete mIndexFeedback;
       
    76     mIndexFeedback = NULL;
       
    77 }
    74 }
    78 
    75 
    79 /*!
    76 /*!
    80 Query to see if the user decided to press Cancel after selecting 
    77 Query to see if the user decided to press Cancel after selecting 
    81 group members. Must be called to see if results are valid.
    78 group members. Must be called to see if results are valid.
    89 {
    86 {
    90     mButtonText = aButtonText;
    87     mButtonText = aButtonText;
    91     
    88     
    92     if (!mLabel) {
    89     if (!mLabel) {
    93         mLabel = new HbLabel(aTitle);
    90         mLabel = new HbLabel(aTitle);
       
    91     }
       
    92     else {
       
    93         mLabel->setPlainText(aTitle);
    94     }
    94     }
    95 }
    95 }
    96 
    96 
    97 /*!
    97 /*!
    98 Brings up a list of contacts, awaiting user response. This function is asynchronous.
    98 Brings up a list of contacts, awaiting user response. This function is asynchronous.
   128         mLayout->removeItem(mListView);
   128         mLayout->removeItem(mListView);
   129         
   129         
   130         if (mEmptyListLabel) {
   130         if (mEmptyListLabel) {
   131             qreal searchHeight = mSearchPanel->size().height();
   131             qreal searchHeight = mSearchPanel->size().height();
   132             HbLabel* heading = static_cast<HbLabel*>(mPopup->headingWidget());
   132             HbLabel* heading = static_cast<HbLabel*>(mPopup->headingWidget());
   133             qreal heightToSet =  mPopup->size().height() - mVirtualKeyboard->keyboardArea().height() - searchHeight - heading->size().height();
   133             qreal heightToSet =  mPopup->size().height() - mVirtualKeyboard->keyboardArea().height() - searchHeight;
   134             mEmptyListLabel->setMaximumHeight(heightToSet);
   134             mEmptyListLabel->setMaximumHeight(heightToSet);
   135             mEmptyListLabel->setVisible(true);
   135             mEmptyListLabel->setVisible(true);
   136             mLayout->insertItem(0, mEmptyListLabel);
   136             mLayout->insertItem(0, mEmptyListLabel);
   137         }
   137         }
   138 
   138 
   151 
   151 
   152 void CntFetchContacts::handleKeypadOpen()
   152 void CntFetchContacts::handleKeypadOpen()
   153 {
   153 {
   154     qreal searchHeight = mSearchPanel->size().height();
   154     qreal searchHeight = mSearchPanel->size().height();
   155     HbLabel* heading = static_cast<HbLabel*>(mPopup->headingWidget());
   155     HbLabel* heading = static_cast<HbLabel*>(mPopup->headingWidget());
   156     qreal heightToSet =  mPopup->size().height() - mVirtualKeyboard->keyboardArea().height() - searchHeight - heading->size().height();
   156     qreal heightToSet =  mPopup->size().height() - mVirtualKeyboard->keyboardArea().height() - searchHeight;
   157 
   157 
   158     if (mEmptyListLabel) {
   158     if (mEmptyListLabel) {
   159         mEmptyListLabel->setMaximumHeight( heightToSet - mEmptyListLabel->size().height() );
   159         mEmptyListLabel->setMaximumHeight(heightToSet);
   160     }
   160     }
   161     
   161     
   162     mListView->setMaximumHeight(heightToSet);
   162     mListView->setMaximumHeight(heightToSet);
   163 }
   163 }
   164 
   164 
   215     }
   215     }
   216     
   216     
   217     // Check for the case where there is a cancel button only. If so, 
   217     // Check for the case where there is a cancel button only. If so, 
   218     // after selecting any contact, should dismiss the dialog immediately.
   218     // after selecting any contact, should dismiss the dialog immediately.
   219     if (mButtonText.isEmpty() && mSelectionMode == HbAbstractItemView::SingleSelection) {
   219     if (mButtonText.isEmpty() && mSelectionMode == HbAbstractItemView::SingleSelection) {
       
   220         disconnect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(handleKeypadOpen()));
       
   221         disconnect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(handleKeypadClose()));
   220         mPopup->close();
   222         mPopup->close();
   221     }
   223     }
   222 }
   224 }
   223 
   225 
   224 void CntFetchContacts::doInitialize(HbAbstractItemView::SelectionMode aMode,
   226 void CntFetchContacts::doInitialize(HbAbstractItemView::SelectionMode aMode,
   227     mSelectionMode = aMode;
   229     mSelectionMode = aMode;
   228     mCurrentlySelected = aContacts;
   230     mCurrentlySelected = aContacts;
   229 
   231 
   230     if (!mPopup) {
   232     if (!mPopup) {
   231         mPopup = new HbDialog;
   233         mPopup = new HbDialog;
       
   234         mPopup->setAttribute(Qt::WA_DeleteOnClose, true);
   232     }
   235     }
   233 
   236 
   234     QContactDetailFilter contactsFilter;
   237     QContactDetailFilter contactsFilter;
   235     contactsFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
   238     contactsFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
   236     contactsFilter.setValue(QString(QLatin1String(QContactType::TypeContact)));
   239     contactsFilter.setValue(QString(QLatin1String(QContactType::TypeContact)));
   309         mLabel = new HbLabel(hbTrId("txt_phob_title_contacts"));
   312         mLabel = new HbLabel(hbTrId("txt_phob_title_contacts"));
   310     }
   313     }
   311     mPopup->setHeadingWidget(mLabel);
   314     mPopup->setHeadingWidget(mLabel);
   312 
   315 
   313     if (!mButtonText.isEmpty() && !mPrimaryAction) {
   316     if (!mButtonText.isEmpty() && !mPrimaryAction) {
   314         mPrimaryAction = new HbAction(hbTrId(mButtonText.toAscii()));
   317         mPrimaryAction = new HbAction(mButtonText, mPopup);
   315         mPopup->addAction(mPrimaryAction);
   318         mPopup->addAction(mPrimaryAction);
   316     }
   319     }
   317     
   320     
   318     if (!mSecondaryAction) {
   321     if (!mSecondaryAction) {
   319         mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
   322         mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), mPopup);
   320         mPopup->addAction(mSecondaryAction);
   323         mPopup->addAction(mSecondaryAction);
   321     }
   324     }
   322 
   325 
   323     mPopup->open(this, SLOT(handleUserResponse(HbAction*)));
   326     mPopup->open(this, SLOT(handleUserResponse(HbAction*)));
   324 }
   327 }