locationpickerservice/src/locationpickerpotraitview.cpp
changeset 17 0f22fb80ebba
child 20 cd10d5b85554
equal deleted inserted replaced
15:13ae750350c9 17:0f22fb80ebba
       
     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 "locationpickerpotraitview.h"
       
    19 
       
    20 #include <HbMainWindow>
       
    21 #include <qstandarditemmodel.h>
       
    22 #include <HbListView>
       
    23 #include <HbListViewItem>
       
    24 #include <HbAction>
       
    25 
       
    26 #include "locationpickerproxymodel.h"
       
    27 #include "locationpickerdatamanager.h"
       
    28 #include "locationpickercontent.h" 
       
    29 #include "locationpickercollectionlistcontent.h"
       
    30 #include "locationpickercollectioncontent.h"
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 // ----------------------------------------------------
       
    35 // LocationPickerPotraitView::LocationPickerView()
       
    36 // ----------------------------------------------------
       
    37 LocationPickerPotraitView::LocationPickerPotraitView(HbDocumentLoader* aLoader)
       
    38     :mDocumentLoader(aLoader),
       
    39     mLocationPickerContent(NULL),
       
    40     mLocationPickerCollectionListContent(NULL),
       
    41     mAllAction(NULL),
       
    42     mCollectionAction(NULL),
       
    43     mSearchAction(NULL),
       
    44     mAscendingAction(NULL),
       
    45     mDescendingAction(NULL),
       
    46     mListView(NULL),
       
    47     mCollectionContent(NULL),
       
    48     mViewType(ELocationPickerContent)
       
    49 {   
       
    50     // create back action
       
    51     mPotraitBackAction = new HbAction(Hb::BackAction);
       
    52     // add back key action
       
    53     setNavigationAction(mPotraitBackAction);
       
    54     //connect to slots
       
    55      connect(mPotraitBackAction, SIGNAL(triggered()), this,
       
    56             SLOT(backTriggered()));     
       
    57     //create list item  
       
    58     mListItem = new HbListViewItem();
       
    59     //set the graphics size
       
    60     mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
    61 }
       
    62 // ----------------------------------------------------
       
    63 // LocationPickerPotraitView::~LocationPickerView()
       
    64 // ----------------------------------------------------
       
    65 LocationPickerPotraitView::~LocationPickerPotraitView()
       
    66 {
       
    67     delete mCollectionContent;
       
    68     delete mLocationPickerContent;
       
    69     delete mLocationPickerCollectionListContent;
       
    70     delete mAllAction;
       
    71     delete mCollectionAction;
       
    72     delete mAscendingAction;
       
    73     delete mDescendingAction;
       
    74     delete mListView;
       
    75 }
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // LocationPickerPotraitView::backButtonTriggered()
       
    79 // ----------------------------------------------------------------------------
       
    80 void LocationPickerPotraitView::backTriggered()
       
    81 {
       
    82     //if current model is collection content, go back to collectionlist content  
       
    83     if(mViewType == ELocationPickerCollectionContent)
       
    84     {
       
    85         colectionTabTriggered();
       
    86         delete mCollectionContent;
       
    87         mCollectionContent=NULL; 
       
    88     }
       
    89     else
       
    90     {
       
    91         //complete the service
       
    92         emit completeService();
       
    93     } 
       
    94 }
       
    95 
       
    96 
       
    97 // ----------------------------------------------------
       
    98 // LocationPickerPotraitView::init()
       
    99 // ----------------------------------------------------
       
   100 void LocationPickerPotraitView::init(Qt::Orientation aOrientation )
       
   101 {   
       
   102     // Create Collection List Content
       
   103     mLocationPickerCollectionListContent = new LocationPickerCollectionListContent(aOrientation);
       
   104     mLocationPickerContent = new LocationPickerContent(aOrientation);
       
   105 
       
   106     //Get HbAction items
       
   107     mListView = qobject_cast<HbListView*> (mDocumentLoader->findObject(QString(
       
   108             "ListView")));
       
   109 
       
   110     //get the action items from docml
       
   111     mAllAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(QString(
       
   112             "allAction")));
       
   113     mCollectionAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   114             QString("collectionAction")));
       
   115     mSearchAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(QString(
       
   116             "searchAction")));
       
   117     mAscendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   118             QString("ascendingAction")));
       
   119     mDescendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   120             QString("descendingAction")));
       
   121       if( !mAllAction || !mCollectionAction || !mSearchAction || !mListView || !mAscendingAction || !mDescendingAction)
       
   122       {
       
   123           qFatal("Error Reading Docml");
       
   124       }
       
   125 
       
   126     //connect to slots
       
   127     connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
       
   128     connect(mDescendingAction, SIGNAL(triggered()), this,
       
   129             SLOT(sortDescending()));
       
   130     //connect all action Items to respective slots
       
   131     connect(mAllAction, SIGNAL(triggered()), this, SLOT(allTabTriggered()));
       
   132     connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered()));
       
   133     connect(mSearchAction, SIGNAL(triggered()), this,
       
   134             SLOT(searchTabTriggered()));
       
   135     // connect the signal of the list activated to a slot.
       
   136     connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &)));
       
   137 }
       
   138 
       
   139 void LocationPickerPotraitView::manageListView()
       
   140 {
       
   141     if (!mLocationPickerContent->locationsFound())
       
   142     {
       
   143         //if no location entries present
       
   144         mListView->setModel(mLocationPickerContent->getStandardModel(),mListItem);
       
   145         disableTabs();
       
   146     }
       
   147     else
       
   148     {   
       
   149         //set the appropriate model
       
   150         switch(mViewType)
       
   151         {
       
   152             case ELocationPickerContent:
       
   153             {   
       
   154                 mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
   155                 mListView->setModel(mLocationPickerContent->getListProxyModel(),mListItem);
       
   156                 mAllAction->setChecked(true);
       
   157                 mCollectionAction->setChecked(false);
       
   158                 mViewType = ELocationPickerContent;
       
   159             }
       
   160                 break;
       
   161             case ELocationPickerCollectionListContent:
       
   162             {
       
   163                  mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
       
   164                  mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
       
   165                  mCollectionAction->setChecked(true);
       
   166                  mAllAction->setChecked(false);
       
   167                  mViewType = ELocationPickerCollectionListContent;
       
   168             }
       
   169                 break;
       
   170             case ELocationPickerCollectionContent:
       
   171             {
       
   172                  setCollectionData(mCategoryId);
       
   173                  mCollectionAction->setChecked(true);
       
   174                  mAllAction->setChecked(false);
       
   175                  mViewType = ELocationPickerCollectionContent;
       
   176             }
       
   177                 break;
       
   178             default:
       
   179                 break;
       
   180         }
       
   181         
       
   182     }
       
   183 }
       
   184 
       
   185 
       
   186 void LocationPickerPotraitView::disableTabs()
       
   187 {
       
   188     mAllAction->setDisabled(true);
       
   189     mCollectionAction->setDisabled(true);
       
   190     mSearchAction->setDisabled(true);
       
   191     mAscendingAction->setDisabled(true);
       
   192     mDescendingAction->setDisabled(true);
       
   193 }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // LocationPickerView::handleActivated()
       
   197 // -----------------------------------------------------------------------------
       
   198 void LocationPickerPotraitView::handleActivated(const QModelIndex &aIndex)
       
   199 {   
       
   200     //handle the activated signal according to model set
       
   201     switch(mViewType)
       
   202     {
       
   203         case ELocationPickerContent:
       
   204         {
       
   205             QModelIndex   index = mLocationPickerContent->getListProxyModel()->mapToSource(
       
   206                     aIndex);
       
   207             quint32 lm = 0;
       
   208             mLocationPickerContent->getDataManager()->getData(index.row(), lm);
       
   209             //item selected, complete request
       
   210             emit selectItem( lm );
       
   211         }
       
   212             break;
       
   213         case ELocationPickerCollectionListContent:
       
   214         {
       
   215             mLocationPickerCollectionListContent->getDataManager()->getData(
       
   216                     aIndex.row(), mCategoryId);
       
   217             mViewType = ELocationPickerCollectionContent;
       
   218             //send categoryID to set the collection content
       
   219             emit sendCategoryID(mCategoryId);
       
   220         }
       
   221             break;
       
   222         case ELocationPickerCollectionContent:
       
   223         {
       
   224             QModelIndex  index = mCollectionContent->getProxyModel()->mapToSource(
       
   225                         aIndex);
       
   226             quint32 lm = 0;
       
   227             mCollectionContent->getDataManager()->getData(index.row(), lm);
       
   228             //item selected, complete request
       
   229             emit selectItem(lm);
       
   230         }
       
   231             break;
       
   232         default:
       
   233             break;
       
   234     }
       
   235 }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // LocationPickerView::sortAscending()
       
   239 // -----------------------------------------------------------------------------
       
   240 void LocationPickerPotraitView::sortAscending()
       
   241 {   
       
   242     //check the model set and do sorting accordingly
       
   243     if (mViewType == ELocationPickerContent)
       
   244     {
       
   245         mLocationPickerContent->getListProxyModel()->sort(0, Qt::AscendingOrder);
       
   246     }
       
   247     else
       
   248     {
       
   249         mCollectionContent->getProxyModel()->sort(0, Qt::AscendingOrder);
       
   250     }
       
   251 }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // LocationPickerView::sortDescending()
       
   255 // -----------------------------------------------------------------------------
       
   256 void LocationPickerPotraitView::sortDescending()
       
   257 {
       
   258     //check the model set and do sorting accordingly
       
   259     if (mViewType == ELocationPickerContent)
       
   260     {
       
   261         mLocationPickerContent->getListProxyModel()->sort(0, Qt::DescendingOrder);
       
   262     }
       
   263     else
       
   264     {
       
   265         mCollectionContent->getProxyModel()->sort(0, Qt::DescendingOrder);
       
   266     }
       
   267 }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // LocationPickerView::handleAllTab()
       
   271 // -----------------------------------------------------------------------------
       
   272 void LocationPickerPotraitView::allTabTriggered()
       
   273 {
       
   274     //execute only if tab is not pressed
       
   275     if (mAllAction->isChecked())
       
   276     {    
       
   277         mViewType = ELocationPickerContent;
       
   278         if(this->mainWindow()->orientation() == Qt::Horizontal)
       
   279         {
       
   280             //if in landscape send signal to launch grid view
       
   281             emit handleAllList();
       
   282         }
       
   283         else
       
   284         {
       
   285             mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
   286             mListView->setModel(mLocationPickerContent->getListProxyModel(),mListItem);
       
   287             mCollectionAction->setChecked(false);
       
   288         }
       
   289         mAscendingAction->setEnabled(true);
       
   290         mDescendingAction->setEnabled(true);
       
   291         //delete mCollectionContent if coming back from collectioncontent
       
   292         if (mCollectionContent)
       
   293         {
       
   294             delete mCollectionContent;
       
   295             mCollectionContent = NULL;
       
   296         }
       
   297     }
       
   298     else
       
   299     {
       
   300         //Keep the tab pressed
       
   301         mAllAction->setChecked(true);
       
   302     }
       
   303     
       
   304 }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // LocationPickerView::handleCollectionTab()
       
   308 // -----------------------------------------------------------------------------
       
   309 void LocationPickerPotraitView::colectionTabTriggered()
       
   310 {
       
   311     //execute only if tab is not pressed
       
   312     if (mCollectionAction->isChecked())
       
   313     {   
       
   314         mListItem->setGraphicsSize(HbListViewItem::MediumIcon);
       
   315         mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem);
       
   316         mAscendingAction->setDisabled(true);
       
   317         mDescendingAction->setDisabled(true);
       
   318         mAllAction->setChecked(false);
       
   319         mViewType = ELocationPickerCollectionListContent;
       
   320     }
       
   321     else
       
   322     {
       
   323         //Keep the tab pressed
       
   324         mCollectionAction->setChecked(true);
       
   325     }
       
   326 }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // LocationPickerView::searchTabTriggered()
       
   330 // -----------------------------------------------------------------------------
       
   331 void LocationPickerPotraitView::searchTabTriggered()
       
   332 {
       
   333     emit switchToSearchView();
       
   334 }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // LocationPickerView::setCollectionData()
       
   338 // -----------------------------------------------------------------------------
       
   339 void LocationPickerPotraitView::setCollectionData( quint32 acategoryId )
       
   340 {
       
   341     mCollectionContent
       
   342     = new LocationPickerCollectionContent(this->mainWindow()->orientation() , acategoryId);
       
   343     mListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
   344     mListView->setModel(mCollectionContent->getProxyModel(),mListItem);
       
   345     mViewType = ELocationPickerCollectionContent;
       
   346     //Enable the options
       
   347     mAscendingAction->setEnabled(true);
       
   348     mDescendingAction->setEnabled(true);
       
   349     mCollectionAction->setChecked(true);
       
   350 }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // LocationPickerView::setCategoryID()
       
   354 // -----------------------------------------------------------------------------
       
   355 void LocationPickerPotraitView::setCategoryID( quint32 aCategoryId  )
       
   356 {
       
   357     mCategoryId = aCategoryId;
       
   358 }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // LocationPickerView::getViewType()
       
   362 // -----------------------------------------------------------------------------
       
   363 TViewType LocationPickerPotraitView::getViewType()
       
   364 {
       
   365     return mViewType;
       
   366 }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // LocationPickerView::setViewType()
       
   370 // -----------------------------------------------------------------------------
       
   371 void LocationPickerPotraitView::setViewType(TViewType aViewType)
       
   372 {
       
   373     mViewType = aViewType;
       
   374 }