locationpickerservice/src/locationpickerview.cpp
branchRCL_3
changeset 18 870918037e16
parent 17 1fc85118c3ae
equal deleted inserted replaced
17:1fc85118c3ae 18:870918037e16
     1 /*
       
     2 * Copyright (c) 2010 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: LocationPickerView implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "locationpickerview.h"
       
    19 
       
    20 #include <HbMainWindow>
       
    21 #include <qstandarditemmodel.h>
       
    22 #include <HbListView>
       
    23 #include <HbListViewItem>
       
    24 #include <HbAction>
       
    25 #include <HbMenu>
       
    26 #include <HbToolBar>
       
    27 #include <HbStyleLoader>
       
    28 #include <QGraphicsLinearLayout>
       
    29 #include <HbDialog>
       
    30 
       
    31 #include "hgwidgetdatamodel.h"
       
    32 #include "locationpickerproxymodel.h"
       
    33 #include "locationpickerdatamanager.h"
       
    34 #include "locationpickercontent.h" 
       
    35 #include "locationpickercollectionlistcontent.h"
       
    36 #include "locationpickercollectioncontent.h"
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 // ----------------------------------------------------
       
    41 // LocationPickerView::LocationPickerView()
       
    42 // ----------------------------------------------------
       
    43 LocationPickerView::LocationPickerView( HbDocumentLoader* aLoader )
       
    44     :mDocumentLoader(aLoader),
       
    45     mLocationPickerCollectionListContent(NULL),
       
    46     mProxyModel(NULL),
       
    47     mAllAction(NULL),
       
    48     mCollectionAction(NULL),
       
    49     mSearchAction(NULL),
       
    50     mAscendingAction(NULL),
       
    51     mDescendingAction(NULL),
       
    52     mListView(NULL),
       
    53     mCollectionContent(NULL),
       
    54     mViewType(ELocationPickerContent),
       
    55     mLinerLayout(NULL),
       
    56     mColllabel(NULL),
       
    57     mEmptyLabel(NULL),
       
    58     mDialog(NULL),
       
    59     mMapIconLabel(NULL),
       
    60     mTitleLabel(NULL),
       
    61     mAddressMiddle(NULL),
       
    62     mAddressBottom(NULL),
       
    63     mLongPressMenu(NULL),
       
    64     mSelectAction(NULL),
       
    65     mDetailsAction(NULL),
       
    66     mPopulated(false)
       
    67 {   
       
    68     //Create Action Items
       
    69     mAllAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
    70             QString("allAction")));
       
    71     mCollectionAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
    72             QString("collectionAction")));
       
    73     mSearchAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
    74             QString("searchAction")));
       
    75     mAscendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
    76             QString("ascendingAction")));
       
    77     mDescendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
    78             QString("descendingAction")));
       
    79     if( !mAllAction || !mCollectionAction || !mSearchAction || !mAscendingAction || !mDescendingAction )
       
    80     {
       
    81         qFatal("Error Reading Docml");
       
    82     }
       
    83     // create back action
       
    84     mBackAction = new HbAction(Hb::BackNaviAction);
       
    85     // add back key action
       
    86     setNavigationAction(mBackAction);
       
    87     //connect to slots
       
    88      connect(mBackAction, SIGNAL(triggered()), this,
       
    89             SLOT(backTriggered()));     
       
    90     //create list item  
       
    91     mListItem = new HbListViewItem();
       
    92     //set the graphics size
       
    93     mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
    94 }
       
    95 // ----------------------------------------------------
       
    96 // LocationPickerView::~LocationPickerView()
       
    97 // ----------------------------------------------------
       
    98 LocationPickerView::~LocationPickerView()
       
    99 {
       
   100     delete mListItem;
       
   101     delete mBackAction;
       
   102     if(mPopulated)
       
   103     {
       
   104     	mLinerLayout->removeItem(mListView);
       
   105     	mLinerLayout->removeItem(mWidget);
       
   106     	delete mCollectionContent;
       
   107     	delete mLocationPickerCollectionListContent;
       
   108     	delete mListView;
       
   109     	delete mWidget;
       
   110     	delete mHgModel;
       
   111     	delete mProxyModel;
       
   112     	delete mColllabel;
       
   113     }
       
   114 }
       
   115 
       
   116 // ----------------------------------------------------------------------------
       
   117 // LocationPickerView::backButtonTriggered()
       
   118 // ----------------------------------------------------------------------------
       
   119 void LocationPickerView::backTriggered()
       
   120 {
       
   121     //if current model is collection content, go back to collectionlist content  
       
   122     if(mViewType == ELocationPickerCollectionContent)
       
   123     {
       
   124         mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
       
   125 		removeDetailsLabel();
       
   126         mAscendingAction->setDisabled(true);
       
   127         mDescendingAction->setDisabled(true);
       
   128         mAllAction->setChecked(false);
       
   129         mViewType = ELocationPickerCollectionListContent;
       
   130         manageListView();
       
   131 
       
   132         clearContentModel();
       
   133     }
       
   134     else
       
   135     {
       
   136         //complete the service
       
   137         emit completeService();
       
   138     } 
       
   139     
       
   140 }
       
   141 
       
   142 
       
   143 // ----------------------------------------------------
       
   144 // LocationPickerView::init()
       
   145 // ----------------------------------------------------
       
   146 void LocationPickerView::init( Qt::Orientation aOrientation, QStandardItemModel *aModel )
       
   147 {   
       
   148     mPopulated = true;
       
   149     // Create Collection List Content
       
   150     mLocationPickerCollectionListContent = new LocationPickerCollectionListContent();
       
   151     mModel = aModel;        
       
   152     // Create Collection List Content
       
   153     mLocationPickerCollectionListContent = new LocationPickerCollectionListContent();
       
   154     //create proxy model
       
   155     mProxyModel = new LocationPickerProxyModel( this  );
       
   156     mProxyModel->setSourceModel(aModel);
       
   157     // set sort properties
       
   158     mProxyModel->setDynamicSortFilter(TRUE);
       
   159     mProxyModel->setSortRole(Qt::DisplayRole);
       
   160     mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
       
   161     // sort in ascending order
       
   162     mProxyModel->sort(0, Qt::AscendingOrder); 
       
   163     mLinerLayout = static_cast<QGraphicsLinearLayout*>(widget()->layout());
       
   164     //Get HbAction items
       
   165     mListView = new HbListView();
       
   166     mColllabel =  new HbLabel();
       
   167     createHurriganesWidget();  
       
   168     mWidget->setModel(mHgModel);
       
   169     //connect to slots
       
   170     connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
       
   171     connect(mDescendingAction, SIGNAL(triggered()), this,
       
   172             SLOT(sortDescending()));
       
   173     //connect all action Items to respective slots
       
   174     connect(mAllAction, SIGNAL(triggered()), this, SLOT(allTabTriggered()));
       
   175     connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered()));
       
   176     connect(mSearchAction, SIGNAL(triggered()), this,
       
   177             SLOT(searchTabTriggered()));
       
   178     // connect the signal of the list activated to a slot.
       
   179     connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &)));
       
   180     connect(mListView,SIGNAL(longPressed(HbAbstractViewItem*, const QPointF &)),this,
       
   181             SLOT(launchPopUpMenu(HbAbstractViewItem*, const QPointF &)));
       
   182     //set widget according to orientation
       
   183     if(aOrientation == Qt::Horizontal)
       
   184     {
       
   185         manageHgWidget();
       
   186     }
       
   187     else
       
   188     {
       
   189         manageListView();
       
   190     }
       
   191 }
       
   192 
       
   193 
       
   194 void LocationPickerView::createHurriganesWidget()
       
   195 {
       
   196     //hurrriganes widget
       
   197     mHgModel = new HgWidgetDataModel( mProxyModel, this );
       
   198     mHgModel->setImageDataType(HgWidgetDataModel::ETypeQImage);
       
   199     //create MediaWall Object
       
   200     mWidget = new HgMediawall();
       
   201     HbIcon defaultIcon(KDummyImage);
       
   202     QPainter painter;
       
   203     QPixmap defaultImage(defaultIcon.width(),defaultIcon.height());
       
   204     painter.begin(&defaultImage);
       
   205     defaultIcon.paint(&painter,QRectF(0,0,defaultIcon.width(),defaultIcon.height()));
       
   206     painter.end();
       
   207     mWidget->setDefaultImage( defaultImage.toImage() );
       
   208     HgMediawall* mediawall = qobject_cast<HgMediawall*>( mWidget );
       
   209     mediawall->setObjectName("location");
       
   210     HbStyleLoader::registerFilePath(":/location.hgmediawall.widgetml");
       
   211     HbStyleLoader::registerFilePath(":/location.hgmediawall.css");
       
   212     mediawall->enableReflections(false);
       
   213     mediawall->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   214     mediawall->setItemSize(QSize(4,3));
       
   215     connect(this->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),mWidget,
       
   216             SLOT(orientationChanged(Qt::Orientation)));
       
   217 
       
   218     mWidget->setAcceptTouchEvents(true);
       
   219     connect(mWidget, SIGNAL(activated(const QModelIndex &)),this, SLOT(handleActivated(const QModelIndex &)));
       
   220     connect(mWidget, SIGNAL(longPressed(const QModelIndex &, const QPointF &)),this, 
       
   221             SLOT(launchPopUpMenu(const QModelIndex &, const QPointF &)));
       
   222     mWidget->setLongPressEnabled(true);
       
   223     mWidget->scrollTo(mWidget->currentIndex());
       
   224 }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // LocationPickerView::manageHgWidget()
       
   228 // -----------------------------------------------------------------------------
       
   229 void LocationPickerView::manageHgWidget()
       
   230 {   
       
   231     removeDetailsLabel();
       
   232     mLinerLayout->removeItem(mListView);
       
   233     mListView->hide();
       
   234     mWidget->show();
       
   235     mLinerLayout->updateGeometry();
       
   236     //set the appropriate model
       
   237     switch(mViewType)
       
   238     {
       
   239         case ELocationPickerContent:
       
   240         {  
       
   241             mHgModel->resetModel(mProxyModel);
       
   242             mAllAction->setChecked(true);
       
   243             mCollectionAction->setChecked(false);
       
   244             mLinerLayout->insertItem(1,mWidget);
       
   245         }
       
   246         break;
       
   247         case ELocationPickerCollectionContent:
       
   248         {
       
   249             setCollectionData(mCategoryId);
       
   250             mCollectionAction->setChecked(true);
       
   251             mAllAction->setChecked(false);
       
   252         }
       
   253         break;
       
   254     }
       
   255 }
       
   256 
       
   257 // ----------------------------------------------------
       
   258 // LocationPickerView::manageListView()
       
   259 // ----------------------------------------------------
       
   260 void LocationPickerView::manageListView()
       
   261 {   
       
   262     if(mEmptyLabel)
       
   263     {
       
   264         removeDetailsLabel();
       
   265     }
       
   266     else
       
   267     {
       
   268         mLinerLayout->removeItem(mWidget);
       
   269         mWidget->hide();   
       
   270     }
       
   271     mLinerLayout->insertItem(1,mListView);
       
   272     mListView->show();
       
   273     //set the appropriate model
       
   274     switch(mViewType)
       
   275     {
       
   276         case ELocationPickerContent:
       
   277         {   
       
   278             mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
   279             mListView->setModel(mProxyModel,mListItem);
       
   280             mAllAction->setChecked(true);
       
   281             mCollectionAction->setChecked(false);
       
   282             mViewType = ELocationPickerContent;
       
   283         }
       
   284         break;
       
   285         case ELocationPickerCollectionListContent:
       
   286         {
       
   287             mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
       
   288             mCollectionAction->setChecked(true);
       
   289             mAllAction->setChecked(false);
       
   290             if(mAscendingAction->isEnabled())
       
   291             {
       
   292                 mAscendingAction->setDisabled(true);
       
   293                 mDescendingAction->setDisabled(true);
       
   294             }
       
   295             mViewType = ELocationPickerCollectionListContent;
       
   296         }
       
   297         break;
       
   298         case ELocationPickerCollectionContent:
       
   299         {
       
   300             mCollectionAction->setChecked(true);
       
   301             mAllAction->setChecked(false);
       
   302             mViewType = ELocationPickerCollectionContent;
       
   303             setCollectionData(mCategoryId);
       
   304         }
       
   305         break;
       
   306         default:
       
   307             break;
       
   308     }
       
   309 }
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // LocationPickerView::disableTabs()
       
   313 // -----------------------------------------------------------------------------
       
   314 void LocationPickerView::disableTabs()
       
   315 {
       
   316     //if no location entries present
       
   317     mLinerLayout = static_cast<QGraphicsLinearLayout*>(widget()->layout());
       
   318     mEmptyLabel =  new HbTextItem( hbTrId( "txt_lint_list_no_location_entries_present" ) );
       
   319     mEmptyLabel->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
       
   320     mEmptyLabel->setFontSpec( HbFontSpec( HbFontSpec::Primary ) );
       
   321     mEmptyLabel->setAlignment( Qt::AlignCenter );
       
   322     mLinerLayout->insertItem( 1, mEmptyLabel );
       
   323     mAllAction->setDisabled( true );
       
   324     mCollectionAction->setDisabled( true );
       
   325     mSearchAction->setDisabled( true );
       
   326     mAscendingAction->setDisabled( true );
       
   327     mDescendingAction->setDisabled( true );
       
   328 }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // LocationPickerView::handleActivated()
       
   332 // -----------------------------------------------------------------------------
       
   333 void LocationPickerView::handleActivated( const QModelIndex &aIndex )
       
   334 {
       
   335     QModelIndex  index;
       
   336     QStandardItem* item;
       
   337     int row= aIndex.row();
       
   338     int col = aIndex.column();
       
   339     //handle the activated signal according to model set
       
   340     switch(mViewType)
       
   341     {    
       
   342         case ELocationPickerContent:
       
   343         {   
       
   344             if(mainWindow()->orientation() == Qt::Vertical)
       
   345             {
       
   346                 index = mProxyModel->mapToSource(
       
   347                     aIndex);
       
   348                 item = mModel->item( index.row(), index.column() );
       
   349             }
       
   350             else
       
   351             {
       
   352                 QModelIndex proxyModelIndex = mProxyModel->index(row,col);
       
   353                 index = mProxyModel->mapToSource(
       
   354                         proxyModelIndex);
       
   355                 item = mModel->item( index.row(), index.column() );
       
   356             }
       
   357             QVariant var = item->data( Qt::UserRole );
       
   358             quint32 lm = var.toUInt();
       
   359             //item selected, complete request
       
   360             emit selectItem( lm );
       
   361         }
       
   362             break;
       
   363         case ELocationPickerCollectionListContent:
       
   364         {
       
   365             mLocationPickerCollectionListContent->getData(
       
   366                     aIndex, mCategoryId );
       
   367             setCollectionData(mCategoryId);
       
   368             mViewType = ELocationPickerCollectionContent;
       
   369         }
       
   370             break;
       
   371         case ELocationPickerCollectionContent:
       
   372         {
       
   373             if(mainWindow()->orientation() == Qt::Vertical)
       
   374             {
       
   375                 index = mCollectionContent->getProxyModel()->mapToSource(
       
   376                     aIndex);
       
   377             }
       
   378             else
       
   379             {
       
   380                 QModelIndex proxyModelIndex = mCollectionContent->getProxyModel()->index(row,col);
       
   381                 index = mCollectionContent->getProxyModel()->mapToSource(
       
   382                         proxyModelIndex);
       
   383             }
       
   384             quint32 lm = 0;
       
   385             mCollectionContent->getData(index, lm);
       
   386             //item selected, complete request
       
   387             emit selectItem(lm);
       
   388         }
       
   389             break;
       
   390         default:
       
   391             break;
       
   392     }
       
   393 }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // LocationPickerView::sortAscending()
       
   397 // -----------------------------------------------------------------------------
       
   398 void LocationPickerView::sortAscending()
       
   399 {   
       
   400     //check the model set and do sorting accordingly
       
   401     if (mViewType == ELocationPickerContent)
       
   402     {
       
   403         mProxyModel->sort( 0, Qt::AscendingOrder );
       
   404         if(mainWindow()->orientation()==Qt::Horizontal)
       
   405             mHgModel->resetModel(mProxyModel);
       
   406     }
       
   407     else
       
   408     {
       
   409         mCollectionContent->getProxyModel()->sort( 0, Qt::AscendingOrder );
       
   410         if(mainWindow()->orientation()==Qt::Horizontal)
       
   411                     mHgModel->resetModel(mCollectionContent->getProxyModel());
       
   412     }
       
   413 }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // LocationPickerView::sortDescending()
       
   417 // -----------------------------------------------------------------------------
       
   418 void LocationPickerView::sortDescending()
       
   419 {
       
   420     //check the model set and do sorting accordingly
       
   421     if (mViewType == ELocationPickerContent)
       
   422     {
       
   423         mProxyModel->sort(0, Qt::DescendingOrder);
       
   424         if(mainWindow()->orientation()==Qt::Horizontal)
       
   425                     mHgModel->resetModel(mProxyModel);
       
   426     }
       
   427     else
       
   428     {
       
   429         mCollectionContent->getProxyModel()->sort( 0, Qt::DescendingOrder );
       
   430         if(mainWindow()->orientation()==Qt::Horizontal)
       
   431                     mHgModel->resetModel(mCollectionContent->getProxyModel());
       
   432     }
       
   433 }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // LocationPickerView::allTabTriggered()
       
   437 // -----------------------------------------------------------------------------
       
   438 void LocationPickerView::allTabTriggered()
       
   439 {
       
   440     removeDetailsLabel();
       
   441     //execute only if tab is not pressed
       
   442     if (mAllAction->isChecked())
       
   443     {    
       
   444         mViewType = ELocationPickerContent;
       
   445         mCollectionAction->setChecked(false);
       
   446         mAscendingAction->setEnabled(true);
       
   447         mDescendingAction->setEnabled(true);
       
   448         //delete mCollectionContent if coming back from collectioncontent
       
   449         if (mCollectionContent)
       
   450         {
       
   451             delete mCollectionContent;
       
   452             mCollectionContent = NULL;
       
   453         }
       
   454         if(mainWindow()->orientation() == Qt::Vertical)
       
   455         {
       
   456             manageListView();
       
   457         }
       
   458         else
       
   459         {
       
   460             manageHgWidget();
       
   461         }
       
   462     }
       
   463     else
       
   464     {
       
   465         //Keep the tab pressed
       
   466         mAllAction->setChecked(true);
       
   467     }
       
   468     
       
   469 }
       
   470 
       
   471 // -----------------------------------------------------------------------------
       
   472 // LocationPickerView::colectionTabTriggered()
       
   473 // -----------------------------------------------------------------------------
       
   474 void LocationPickerView::colectionTabTriggered()
       
   475 {
       
   476 	  if( mViewType == ELocationPickerCollectionListContent ||
       
   477 	      mViewType == ELocationPickerCollectionContent )
       
   478 	  {
       
   479 	  	  mCollectionAction->setChecked(true);
       
   480 	      return;
       
   481 	  }
       
   482     mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
       
   483     removeDetailsLabel();
       
   484     //execute only if tab is not pressed
       
   485     if (mCollectionAction->isChecked())
       
   486     {           
       
   487         mAscendingAction->setDisabled(true);
       
   488         mDescendingAction->setDisabled(true);
       
   489         mAllAction->setChecked(false);
       
   490         mViewType = ELocationPickerCollectionListContent;
       
   491         manageListView();
       
   492     }
       
   493     else
       
   494     {
       
   495         //Keep the tab pressed
       
   496         mCollectionAction->setChecked(true);
       
   497     }
       
   498 }
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 // LocationPickerView::searchTabTriggered()
       
   502 // -----------------------------------------------------------------------------
       
   503 void LocationPickerView::searchTabTriggered()
       
   504 {
       
   505     mWidget->hide();
       
   506     emit switchToSearchView();
       
   507 }
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // LocationPickerView::setCollectionData()
       
   511 // -----------------------------------------------------------------------------
       
   512 void LocationPickerView::setCollectionData( quint32 acategoryId )
       
   513 {
       
   514     if(!mCollectionContent)
       
   515     {
       
   516         mCollectionContent
       
   517         = new LocationPickerCollectionContent( acategoryId );
       
   518     }
       
   519     
       
   520     if(mainWindow()->orientation() == Qt::Vertical)
       
   521     {
       
   522         QString categoryname;
       
   523         removeDetailsLabel();    
       
   524         switch(acategoryId)
       
   525         {
       
   526 
       
   527             case 1: categoryname = QString(hbTrId("txt_lint_subhead_places"));
       
   528             break;
       
   529             case 8: categoryname = QString(hbTrId("txt_lint_subhead_contact_addresses"));     
       
   530             break;
       
   531             case 9: categoryname = QString(hbTrId("txt_lint_subhead_calendar_event_locations"));
       
   532             break;
       
   533         }
       
   534         if(mCollectionContent->locationFound())
       
   535         {
       
   536             mListView->setModel( mCollectionContent->getProxyModel(),mListItem );
       
   537             //Enable the options
       
   538             mAscendingAction->setEnabled(true);
       
   539             mDescendingAction->setEnabled(true);
       
   540             mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
   541         }
       
   542         else
       
   543         {
       
   544             displayNoEntries();
       
   545         }
       
   546         mCollectionAction->setChecked(true);
       
   547 
       
   548         if(mColllabel)
       
   549         {
       
   550             mLinerLayout->insertItem(0,mColllabel);
       
   551             mColllabel->setPlainText(categoryname);   
       
   552             mColllabel->show();
       
   553         }
       
   554     }
       
   555     else
       
   556     {
       
   557            if(mCollectionContent->locationFound())
       
   558            {
       
   559                mHgModel->resetModel( mCollectionContent->getProxyModel() );
       
   560                //Enable the options
       
   561                mAscendingAction->setEnabled(true);
       
   562                mDescendingAction->setEnabled(true);
       
   563                mLinerLayout->removeItem(mListView);
       
   564                mListView->hide();
       
   565                mLinerLayout->insertItem(1,mWidget);
       
   566                mWidget->show();
       
   567                mLinerLayout->updateGeometry();
       
   568            }
       
   569            else
       
   570            {
       
   571                displayNoEntries();
       
   572            }
       
   573     }
       
   574     mViewType = ELocationPickerCollectionContent;
       
   575 }
       
   576 
       
   577 // -----------------------------------------------------------------------------
       
   578 // LocationPickerView::getViewType()
       
   579 // -----------------------------------------------------------------------------
       
   580 TViewType LocationPickerView::getViewType()
       
   581 {
       
   582     return mViewType;
       
   583 }
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // LocationPickerView::setViewType()
       
   587 // -----------------------------------------------------------------------------
       
   588 void LocationPickerView::setViewType( TViewType aViewType )
       
   589 {
       
   590     mViewType = aViewType;
       
   591 }
       
   592 
       
   593 
       
   594 // -----------------------------------------------------------------------------
       
   595 // LocationPickerView::clearContentModel()
       
   596 // -----------------------------------------------------------------------------
       
   597 void LocationPickerView::clearContentModel()
       
   598 {
       
   599     if(mCollectionContent)
       
   600     {
       
   601     	delete mCollectionContent;
       
   602     	mCollectionContent = NULL;
       
   603     }
       
   604 }
       
   605 
       
   606 // -----------------------------------------------------------------------------
       
   607 // LocationPickerView::launchPopUpMenu()
       
   608 // -----------------------------------------------------------------------------
       
   609 void LocationPickerView::launchPopUpMenu( HbAbstractViewItem *aItem, const QPointF &aPoint )
       
   610 {
       
   611     mLongPressMenu = new HbMenu();
       
   612     mLongPressMenu->setTimeout(HbMenu::NoTimeout);
       
   613     connect(mLongPressMenu,SIGNAL(aboutToClose ()),this,SLOT(deleteMenu()));
       
   614     mSelectAction  = mLongPressMenu->addAction(hbTrId("txt_lint_list_select"));
       
   615     if( mViewType == ELocationPickerCollectionContent || mViewType == ELocationPickerContent )
       
   616     {
       
   617         mDetailsAction  = mLongPressMenu->addAction(hbTrId("txt_lint_menu_details"));
       
   618         connect(mDetailsAction, SIGNAL(triggered()), this, SLOT(handleDetails()));
       
   619     }
       
   620     mIndex = aItem->modelIndex();
       
   621     connect(mSelectAction, SIGNAL(triggered()), this, SLOT(handleSelect()));
       
   622     mLongPressMenu->setPreferredPos(aPoint);
       
   623     mLongPressMenu->open();
       
   624 }
       
   625 
       
   626 // -----------------------------------------------------------------------------
       
   627 // LocationPickerView::launchPopUpMenu()
       
   628 // -----------------------------------------------------------------------------
       
   629 void LocationPickerView::launchPopUpMenu( const QModelIndex &aIndex, const QPointF &aPoint )
       
   630 {
       
   631     mLongPressMenu = new HbMenu();
       
   632     mLongPressMenu->setTimeout(HbMenu::NoTimeout);
       
   633     connect(mLongPressMenu,SIGNAL(aboutToClose ()),this,SLOT(deleteMenu()));
       
   634     mSelectAction  = mLongPressMenu->addAction(hbTrId("txt_lint_list_select"));
       
   635     mIndex = aIndex;
       
   636     connect(mSelectAction, SIGNAL(triggered()), this, SLOT(handleSelect()));
       
   637     mLongPressMenu->setPreferredPos(aPoint);
       
   638     mLongPressMenu->open();
       
   639 }
       
   640 // -----------------------------------------------------------------------------
       
   641 // LocationPickerView::handleSelect()
       
   642 // -----------------------------------------------------------------------------
       
   643 void LocationPickerView::handleSelect()
       
   644 {
       
   645     handleActivated(mIndex);
       
   646 }
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // LocationPickerView::deleteMenu()
       
   650 // -----------------------------------------------------------------------------
       
   651 void LocationPickerView::deleteMenu()
       
   652 {
       
   653     mLongPressMenu->deleteLater();
       
   654     mLongPressMenu = NULL;
       
   655     mSelectAction->deleteLater();
       
   656     mSelectAction = NULL;
       
   657     mDetailsAction->deleteLater();
       
   658     mDetailsAction = NULL;
       
   659     
       
   660 }
       
   661 
       
   662 // -----------------------------------------------------------------------------
       
   663 // LocationPickerView::handleSelect()
       
   664 // -----------------------------------------------------------------------------
       
   665 void LocationPickerView::handleDetails()
       
   666 {
       
   667     HbDocumentLoader* loader = new HbDocumentLoader();
       
   668 
       
   669     bool ok = false;
       
   670     //load the popup dialog
       
   671     loader->load(":/popupdialog.docml", &ok);
       
   672     Q_ASSERT_X(ok,"locationpickerservice","invalid DocML file");
       
   673     //find graphics popup dialog
       
   674     QGraphicsWidget *popUpDialog = loader->findWidget("dialog");
       
   675     Q_ASSERT_X((popUpDialog != 0), "locationpickerservice", "invalid DocML file");
       
   676     mDialog = qobject_cast<HbDialog*>(popUpDialog);
       
   677     mMapIconLabel = qobject_cast<HbLabel*>(loader->findWidget("mapLabel"));
       
   678     mTitleLabel = qobject_cast<HbLabel*>(loader->findWidget("titleLabel"));
       
   679     mAddressMiddle = qobject_cast<HbLabel*>(loader->findWidget("addressMiddle"));
       
   680     mAddressBottom = qobject_cast<HbLabel*>(loader->findWidget("addressBottom"));
       
   681     mDone = qobject_cast<HbAction*>(loader->findObject(QString("action")));
       
   682     mTitleLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   683     mDialog->setDismissPolicy(HbDialog::NoDismiss);
       
   684     mDialog->setTimeout(HbDialog::NoTimeout);
       
   685     connect(mDone, SIGNAL(triggered()), this, SLOT(closeDetailsDialog()));
       
   686     QStringList adressDetail;
       
   687     QString iconName;
       
   688     mMapIconLabel->setAlignment(Qt::AlignCenter);
       
   689     if(mViewType == ELocationPickerContent)
       
   690     {
       
   691         adressDetail = mProxyModel->data(mIndex,Qt::UserRole+3).toStringList();
       
   692         iconName =  mProxyModel->data(mIndex,Qt::UserRole+1).toString();
       
   693     }
       
   694     else
       
   695     {
       
   696         adressDetail = mCollectionContent->getProxyModel()->data(mIndex,Qt::UserRole+3).toStringList();
       
   697         iconName =  mCollectionContent->getProxyModel()->data(mIndex,Qt::UserRole+1).toString();
       
   698     }
       
   699     if(iconName.isEmpty())
       
   700     {
       
   701         mMapIconLabel->setIcon(KDummyImage); 
       
   702     }
       
   703     else
       
   704     {
       
   705         mMapIconLabel->setIcon(HbIcon(iconName)); 
       
   706     }
       
   707 
       
   708     if(adressDetail[0].isEmpty() && adressDetail[1].isEmpty())
       
   709     {
       
   710         mTitleLabel->setPlainText(adressDetail[2]);
       
   711         mAddressMiddle->setPlainText(QString(""));
       
   712         mAddressBottom->setPlainText(QString(""));
       
   713     }
       
   714     else if(adressDetail[0].isEmpty())
       
   715     {
       
   716         mTitleLabel->setPlainText(adressDetail[1]);
       
   717         mAddressMiddle->setPlainText(adressDetail[2]);
       
   718         mAddressBottom->setPlainText(QString(""));
       
   719     }
       
   720     else if (adressDetail[1].isEmpty())
       
   721     {
       
   722         mTitleLabel->setPlainText(adressDetail[0]);
       
   723         mAddressMiddle->setPlainText(adressDetail[2]);
       
   724         mAddressBottom->setPlainText(QString(""));
       
   725     }
       
   726     else
       
   727     {
       
   728         mTitleLabel->setPlainText(adressDetail[0]);
       
   729         mAddressMiddle->setPlainText(adressDetail[1]);
       
   730         mAddressBottom->setPlainText(adressDetail[2]);
       
   731     }
       
   732  
       
   733     mDialog->open();
       
   734     delete loader;
       
   735 }
       
   736 
       
   737 // -----------------------------------------------------------------------------
       
   738 // LocationPickerView::closeDetailsDialog()
       
   739 // -----------------------------------------------------------------------------
       
   740 void LocationPickerView::closeDetailsDialog()
       
   741 {
       
   742     if(mDialog)
       
   743     {
       
   744         mDialog->close();
       
   745         delete mDialog;
       
   746         mDialog = NULL;
       
   747     }
       
   748 }
       
   749 // -----------------------------------------------------------------------------
       
   750 // LocationPickerView::displayNoEntries()
       
   751 // -----------------------------------------------------------------------------
       
   752 void LocationPickerView::displayNoEntries()
       
   753 {
       
   754     if(!mEmptyLabel)
       
   755     {
       
   756         mEmptyLabel =  new HbTextItem(hbTrId("txt_lint_list_no_location_entries_present"));
       
   757         mEmptyLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
       
   758         mEmptyLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   759         mEmptyLabel->setAlignment(Qt::AlignCenter);
       
   760         mLinerLayout->removeItem(mListView);
       
   761         mListView->hide();
       
   762         mWidget->setVisible(false);
       
   763         mLinerLayout->insertItem(0, mEmptyLabel);
       
   764     }
       
   765     
       
   766 }
       
   767 
       
   768 // -----------------------------------------------------------------------------
       
   769 // LocationPickerView::removeDetailsLabel()
       
   770 // -----------------------------------------------------------------------------
       
   771 void LocationPickerView::removeDetailsLabel()
       
   772 {
       
   773     if (mLinerLayout && mColllabel)
       
   774     {
       
   775         mColllabel->setPlainText("");
       
   776         mLinerLayout->removeItem(mColllabel);
       
   777         mColllabel->hide();
       
   778     }
       
   779     if(mEmptyLabel)
       
   780     {   
       
   781         mLinerLayout->removeItem(mEmptyLabel);
       
   782         mEmptyLabel->hide();
       
   783         delete mEmptyLabel;
       
   784         mEmptyLabel = NULL;
       
   785     }
       
   786 }
       
   787