homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsmenuview.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
child 85 35368b604b28
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    26 #include <HbSearchPanel>
    26 #include <HbSearchPanel>
    27 #include <HbPushButton>
    27 #include <HbPushButton>
    28 #include <HbToolBar>
    28 #include <HbToolBar>
    29 #include <HbView>
    29 #include <HbView>
    30 #include <HbToolBarExtension>
    30 #include <HbToolBarExtension>
    31 #include <HbStaticVkbHost>
    31 #include <HbShrinkingVkbHost>
    32 
    32 
    33 #include "hsallappsstate.h"
    33 #include "hsallappsstate.h"
    34 #include "hsallcollectionsstate.h"
    34 #include "hsallcollectionsstate.h"
    35 #include "hscollectionstate.h"
    35 #include "hscollectionstate.h"
       
    36 #include "hsmainwindow.h"
    36 #include "hsmenuitemmodel.h"
    37 #include "hsmenuitemmodel.h"
    37 #include "hsmenuview.h"
    38 #include "hsmenuview.h"
    38 #include "hslistviewitem.h"
    39 #include "hslistviewitem.h"
       
    40 #include "hssearchview.h"
    39 
    41 
    40 /*!
    42 /*!
    41     \class HsMenuView
    43     \class HsMenuView
    42     \ingroup group_hsmenustateplugin
    44     \ingroup group_hsmenustateplugin
    43 
    45 
    47 
    49 
    48     \sa HsAppLibraryState
    50     \sa HsAppLibraryState
    49 */
    51 */
    50 
    52 
    51 /*!
    53 /*!
    52  Constructor
    54 
    53 
    55  Retrieves UI objects for a requested context and sets up signals' connections.
    54  Builds UI objects
       
    55  Sets up signals connections.
       
    56 
    56 
    57  \param builder Menu View builder.
    57  \param builder Menu View builder.
    58  \param viewContext variable representing view context the view is to be prepared for.
    58  \param stateContext Variable representing view context the view is to be prepared for.
    59  */
    59  \param mainWindow Object responsible for making a given view
    60 HsMenuView::HsMenuView(HsMenuViewBuilder &builder, HsViewContext viewContext):
    60     a currently displayed view.
    61     mViewContext(viewContext),
    61  */
       
    62 HsMenuView::HsMenuView(HsMenuViewBuilder &builder,
       
    63                        HsStateContext stateContext,
       
    64                        HsMainWindow &mainWindow):
    62     mBuilder(builder),
    65     mBuilder(builder),
    63     mProxyModel(new QSortFilterProxyModel(this)),
    66     mStateContext(stateContext),
    64     mView(NULL),
    67     mOperationalContext(HsItemViewContext),
    65     mListView(NULL),
    68     mMainWindow(mainWindow),
    66     mViewLabel(NULL),
    69     mHsSearchView(new HsSearchView(mBuilder, mStateContext, mMainWindow))
    67     mSearchListView(NULL),
    70 {
    68     mSearchPanel(NULL), 
    71     synchronizeCache();
    69     mVkbHost(NULL)
       
    70 {
       
    71     mBuilder.setOperationalContext(HsItemViewContext);
       
    72     mBuilder.setViewContext(mViewContext);
       
    73     mBuilder.build();
       
    74 
       
    75     mView = mBuilder.currentView();
       
    76     mListView = mBuilder.currentListView();
       
    77 
       
    78     mViewLabel= mBuilder.currentViewLabel();
       
    79 
       
    80     mCollectionButton = mBuilder.collectionButton();
       
    81 
       
    82     mProxyModel->setFilterRole(CaItemModel::TextRole);
       
    83     mProxyModel->setFilterKeyColumn(1);
       
    84     mProxyModel->setSortRole(CaItemModel::TextRole);
       
    85 
       
    86     mVkbHost = new HbStaticVkbHost(mView);
       
    87     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
       
    88     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
       
    89 
    72 
    90     connect(mListView,
    73     connect(mListView,
    91             SIGNAL(activated(QModelIndex)),
    74             SIGNAL(activated(QModelIndex)),
    92             this, SIGNAL(activated(QModelIndex)));
    75             this, SIGNAL(activated(QModelIndex)));
    93     connect(mListView,
    76     connect(mListView,
    94             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
    77             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
    95             this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)));
    78             this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)));
    96 }
    79 
    97 
    80     connect(mHsSearchView.data(), SIGNAL(activated(QModelIndex)),
    98 /*!
    81             this, SIGNAL(activated(QModelIndex)));
    99  Destructor
    82     connect(mHsSearchView.data(),
   100 
    83             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   101  Disconnects signals.
    84                         this, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)));
       
    85 }
       
    86 
       
    87 /*!
       
    88     Empty.
   102  */
    89  */
   103 HsMenuView::~HsMenuView()
    90 HsMenuView::~HsMenuView()
   104 {
    91 {
   105 }
    92 }
   106 
    93 
   107 
    94 
   108 /*!
    95 /*!
   109  Sets model for item view.
    96  Sets model for list item view if available in current context otherwise
       
    97  ingores the request.
   110 
    98 
   111  \param model Model the view is to represent in HsItemViewMode.
    99  \param model Model the view is to represent in HsItemViewMode.
   112  */
   100  */
   113 void HsMenuView::setModel(HsMenuItemModel *model)
   101 void HsMenuView::setModel(QAbstractItemModel *model)
   114 {
   102 {
   115     HSMENUTEST_FUNC_ENTRY("HsMenuView::setModel");
   103     HSMENUTEST_FUNC_ENTRY("HsMenuView::setModel");
   116 
   104 
   117     if (mListView->model()) {
   105     if (mListView != NULL) {
   118         disconnect(mListView->model(),
   106         if (mListView->model()) {
   119                    SIGNAL(scrollTo(int, QAbstractItemView::ScrollHint)),
   107             disconnect(mListView->model(),
   120                    this,
   108                        SIGNAL(scrollTo(int, QAbstractItemView::ScrollHint)),
   121                    SLOT(scrollToRow(int, QAbstractItemView::ScrollHint)));
   109                        this,
   122     }
   110                        SLOT(scrollToRow(int, QAbstractItemView::ScrollHint)));
   123     mListView->setModel(model);
   111             disconnect(mListView->model(), SIGNAL(countChange()),
   124     mListView->setItemPrototype(new HsListViewItem());
   112                        this,
   125     if (mListView->model()) {
   113                         SIGNAL(listViewChange()));
   126         connect(mListView->model(),
   114         }
   127                 SIGNAL(scrollTo(int, QAbstractItemView::ScrollHint)),
   115 
   128                 this,
   116         mListView->setItemPixmapCacheEnabled(true); // TODO: remove when enabled from default
   129                 SLOT(scrollToRow(int, QAbstractItemView::ScrollHint)));
   117         mListView->setModel(model, new HsListViewItem());
   130     }
   118 
       
   119         if (mListView->model()) {
       
   120             connect(mListView->model(),
       
   121                     SIGNAL(scrollTo(int, QAbstractItemView::ScrollHint)),
       
   122                     this,
       
   123                     SLOT(scrollToRow(int, QAbstractItemView::ScrollHint)));
       
   124             connect(mListView->model(), SIGNAL(countChange()),
       
   125                     this,
       
   126                     SIGNAL(listViewChange()));
       
   127         }
       
   128     }
       
   129 
   131     HSMENUTEST_FUNC_EXIT("HsMenuView::setModel");
   130     HSMENUTEST_FUNC_EXIT("HsMenuView::setModel");
   132 }
   131 }
   133 
   132 
       
   133 /*!
       
   134  Returns model for list item view.
       
   135  */
       
   136 QAbstractItemModel *HsMenuView::model() const
       
   137 {
       
   138     return mListView->model();
       
   139 }
       
   140 
       
   141 /*!
       
   142 \return View widget of the menu view.
       
   143  */
       
   144 HbView *HsMenuView::view() const
       
   145 {
       
   146     return mView;
       
   147 }
       
   148 
       
   149 /*!
       
   150 \return List view widget of the menu view
       
   151  if available in the context or NULL otherwise.
       
   152  */
       
   153 HbListView *HsMenuView::listView() const
       
   154 {
       
   155     return mListView;
       
   156 }
   134 
   157 
   135 /*!
   158 /*!
   136     Returns label appropriate for the view.
   159     Returns label appropriate for the view.
   137     \return pointer to the label or NULL if the view has no label.
   160     \return Pointer to the label
       
   161     if available in the context or NULL otherwise.
   138  */
   162  */
   139 HbGroupBox *HsMenuView::viewLabel() const
   163 HbGroupBox *HsMenuView::viewLabel() const
   140 {
   164 {
   141     return mViewLabel;
   165     return mViewLabel;
   142 }
   166 }
   143 
   167 
   144 /*!
   168 /*!
   145     \return first visible item index if any or default QModelIndex otherwise.
       
   146  */
       
   147 QModelIndex HsMenuView::firstVisibleItemIndex(const HbListView *view) const
       
   148 {
       
   149     QModelIndex result;
       
   150 
       
   151     const QList<HbAbstractViewItem *> array =
       
   152         view->visibleItems();
       
   153 
       
   154     if (array.count() >= 1) {
       
   155         result = array[0]->modelIndex();
       
   156     }
       
   157     return result;
       
   158 }
       
   159 
       
   160 /*!
       
   161     Makes the UI to show or hide view search panel.
       
   162     When search panel is shown the view toolbar and status pane
       
   163     are hidden until search panel is hidden.
       
   164     \param visible When true search panel will be shown,
       
   165      otherwise it will be hidden.
       
   166  */
       
   167 void HsMenuView::setSearchPanelVisible(bool visible)
       
   168 {
       
   169     HSMENUTEST_FUNC_ENTRY("HsMenuView::setSearchPanelVisible");
       
   170 
       
   171     if (visible) {
       
   172 
       
   173         mSearchViewInitialIndex = firstVisibleItemIndex(mListView);
       
   174 
       
   175         searchBegins();
       
   176 
       
   177         connectSearchItemViewsSignals();
       
   178         connectSearchPanelSignals();
       
   179         
       
   180     } else if (mSearchListView != NULL) {
       
   181 
       
   182         mIndexToScrollAfterSearchDone =
       
   183             firstVisibleItemIndex(mSearchListView);
       
   184 
       
   185         disconnectSearchPanelSignals();
       
   186         disconnectSearchItemViewsSignals();
       
   187 
       
   188         searchFinished();
       
   189     }
       
   190     HSMENUTEST_FUNC_EXIT("HsMenuView::setSearchPanelVisible");
       
   191 }
       
   192 
       
   193 /*!
       
   194     Makes the UI to show or hide view add collection button
       
   195     \param visibility When true button will be shown,
       
   196      otherwise it will be hidden.
       
   197  */
       
   198 void HsMenuView::setContext(HsViewContext viewContext,
       
   199                             HsOperationalContext context)
       
   200 {
       
   201     mBuilder.setViewContext(viewContext);
       
   202     mBuilder.setOperationalContext(context);
       
   203     mBuilder.build();
       
   204 }
       
   205 
       
   206 
       
   207 /*!
       
   208 \return View widget of the menu view.
       
   209  */
       
   210 HbView *HsMenuView::view() const
       
   211 {
       
   212     return mView;
       
   213 }
       
   214 
       
   215 /*!
       
   216 \return List view widget of the menu view.
       
   217  */
       
   218 HbListView *HsMenuView::listView() const
       
   219 {
       
   220     return mListView;
       
   221 }
       
   222 
       
   223 /*!
       
   224 \return Collection button
   169 \return Collection button
   225  */
   170  if available in the context or NULL otherwise.
   226 HbPushButton *HsMenuView::collectionButton() const
   171  */
   227 {
   172 HbPushButton *HsMenuView::contentButton() const
   228     return mCollectionButton;
   173 {
       
   174     return mAddContentButton;
   229 }
   175 }
   230 
   176 
   231 /*!
   177 /*!
   232  Makes search panel visible.
   178  Makes search panel visible.
   233  Equivalent to \a setSearchPanelVisible(true)
   179  Equivalent to \a setSearchPanelVisible(true)
   234  */
   180  */
   235 void HsMenuView::showSearchPanel()
   181 void HsMenuView::showSearchPanel()
   236 {
   182 {
   237     HSMENUTEST_FUNC_ENTRY("HsMenuView::showSearchPanel");
   183     HSMENUTEST_FUNC_ENTRY("HsMenuView::showSearchPanel");
   238 
   184 
   239     setSearchPanelVisible(true);
   185     mHsSearchView->setSearchPanelVisible(true);
   240 
   186 
   241     HSMENUTEST_FUNC_EXIT("HsMenuView::showSearchPanel");
   187     HSMENUTEST_FUNC_EXIT("HsMenuView::showSearchPanel");
   242 }
   188 }
   243 #ifdef COVERAGE_MEASUREMENT
       
   244 #pragma CTC SKIP
       
   245 #endif //COVERAGE_MEASUREMENT skipped: it doubles other method
       
   246 
   189 
   247 /*!
   190 /*!
   248  Makes search panel invisible.
   191  Makes search panel invisible.
   249  Equivalent to \a setSearchPanelVisible(false).
   192  Equivalent to \a setSearchPanelVisible(false).
   250  */
   193  */
   251 void HsMenuView::hideSearchPanel()
   194 void HsMenuView::hideSearchPanel()
   252 {
   195 {
   253     HSMENUTEST_FUNC_ENTRY("HsMenuView::hideSearchPanel");
   196     HSMENUTEST_FUNC_ENTRY("HsMenuView::hideSearchPanel");
   254     setSearchPanelVisible(false);
   197 
       
   198     mHsSearchView->setSearchPanelVisible(false);
       
   199 
   255     HSMENUTEST_FUNC_EXIT("HsMenuView::hideSearchPanel");
   200     HSMENUTEST_FUNC_EXIT("HsMenuView::hideSearchPanel");
   256 }
   201 }
   257 #ifdef COVERAGE_MEASUREMENT
       
   258 #pragma CTC ENDSKIP
       
   259 #endif //COVERAGE_MEASUREMENT
       
   260 
   202 
   261 /*!
   203 /*!
   262  Disable or enable search action button.
   204  Disable or enable search action button.
   263  \param disable If true action is disabled.
   205  \param disable If true action gets disabled.
   264  */
   206  */
   265 void HsMenuView::disableSearch(bool disable)
   207 void HsMenuView::disableSearch(bool disable)
   266 {
   208 {
   267     mBuilder.searchAction()->setDisabled(disable);
   209     mBuilder.searchAction()->setDisabled(disable);
   268 }
   210 }
   269 
   211 
   270 /*!
   212 /*!
   271  Scrolls item view to requested row.
   213  Scrolls list item view to requested row.
   272  \param row The row which is to get at the position pointed by \a hint.
   214  \param row The row which is to get at the position pointed by \a hint.
   273  \param hint Position in the view the row should be scrolled to.
   215  \param hint Position in the view the row should be scrolled to.
   274   */
   216   */
   275 void HsMenuView::scrollToRow(int row, QAbstractItemView::ScrollHint hint)
   217 void HsMenuView::scrollToRow(int row, QAbstractItemView::ScrollHint hint)
   276 {
   218 {
   277     HSMENUTEST_FUNC_ENTRY("HsMenuView::scrollToRow");
   219     HSMENUTEST_FUNC_ENTRY("HsMenuView::scrollToRow");
   278 
   220 
   279     mListView->scrollTo(mListView->model()->index(row, 0),
   221     if (mListView != NULL) {
   280                         convertScrollHint(hint));
   222         mListView->scrollTo(
       
   223             mListView->model()->index(row, 0), convertScrollHint(hint));
       
   224     }
   281 
   225 
   282     HSMENUTEST_FUNC_EXIT("HsMenuView::scrollToRow");
   226     HSMENUTEST_FUNC_EXIT("HsMenuView::scrollToRow");
   283 }
   227 }
   284 
   228 
   285 /*!
   229 /*!
   301     default:
   245     default:
   302         return HbAbstractItemView::PositionAtCenter;
   246         return HbAbstractItemView::PositionAtCenter;
   303     }
   247     }
   304 }
   248 }
   305 
   249 
   306 /*
   250 /*!
   307  Connects \a activated and \a longPressed signals coming from search list
   251  Add the view to main window and connect search action with \a showSearchPanel
   308  view to emit corresponding signal of this object with translated model index
       
   309 */
       
   310 void HsMenuView::connectSearchItemViewsSignals()
       
   311 {
       
   312     connect(mSearchListView, SIGNAL(activated(QModelIndex)),
       
   313             this, SLOT(activatedProxySlot(QModelIndex)));
       
   314     connect(mSearchListView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
       
   315             this, SLOT(longPressedProxySlot(HbAbstractViewItem *, QPointF)));
       
   316 
       
   317 }
       
   318 
       
   319 /*!
       
   320  Disconnects \a activated and \a longPressed signals coming from list
       
   321  view from to emit corresponding signal
       
   322  of this object with translated model index.
       
   323 */
       
   324 void HsMenuView::disconnectSearchItemViewsSignals()
       
   325 {
       
   326     disconnect(mSearchListView, SIGNAL(activated(QModelIndex)),
       
   327                this, SLOT(activatedProxySlot(QModelIndex)));
       
   328     disconnect(mSearchListView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
       
   329                this,
       
   330                SLOT(longPressedProxySlot(HbAbstractViewItem *, QPointF)));
       
   331 }
       
   332 
       
   333 
       
   334 /*!
       
   335  Connects signals \a exitClicked and \a criteriaChanged emitted
       
   336  by search panel with handling slots of the object or its members.
       
   337 */
       
   338 void HsMenuView::connectSearchPanelSignals()
       
   339 {
       
   340     connect(mSearchPanel, SIGNAL(exitClicked()),
       
   341             this, SLOT(hideSearchPanel()));
       
   342     connect(mSearchPanel, SIGNAL(criteriaChanged(QString)),
       
   343             this, SLOT(findItem(QString)));
       
   344 
       
   345 
       
   346 }
       
   347 
       
   348 /*!
       
   349  Disconnects signals \a exitClicked and \a criteriaChanged emitted
       
   350  by search panel from handling slots of the object or its members
       
   351  Scrolls view to state before connections.
       
   352 */
       
   353 void HsMenuView::disconnectSearchPanelSignals()
       
   354 {
       
   355     disconnect(mSearchPanel, SIGNAL(exitClicked()),
       
   356                this, SLOT(hideSearchPanel()));
       
   357 
       
   358     disconnect(mSearchPanel, SIGNAL(criteriaChanged(QString)),
       
   359                this, SLOT(findItem(QString)));
       
   360 
       
   361 }
       
   362 
       
   363 
       
   364 /*!
       
   365  Looks up for item and if found scrolls to it.
       
   366  \param criteriaStr The item name to find.
       
   367  */
       
   368 void HsMenuView::findItem(QString criteriaStr)
       
   369 {
       
   370     qDebug
       
   371     () << QString("hsmenuview::findItem: %1").arg(criteriaStr);
       
   372     HSMENUTEST_FUNC_ENTRY("hsmenuview::findItem");
       
   373 
       
   374     if ("" != criteriaStr) {
       
   375         mProxyModel->invalidate();
       
   376         mProxyModel->setSourceModel(mListView->model());
       
   377         mProxyModel->setFilterRegExp(QRegExp(
       
   378                 QString("(^|\\b)%1").arg(criteriaStr), Qt::CaseInsensitive));
       
   379         mSearchListView->scrollTo(mProxyModel->index(0,0),
       
   380                                   HbAbstractItemView::PositionAtTop);
       
   381     } else {
       
   382         mProxyModel->setFilterRegExp(QRegExp(QString(".*"),
       
   383                                              Qt::CaseInsensitive, QRegExp::RegExp));
       
   384 
       
   385         // scroll to first item in model
       
   386         mSearchListView->scrollTo(
       
   387             mProxyModel->index(0, 0),
       
   388 
       
   389             HbAbstractItemView::PositionAtTop);
       
   390     }
       
   391     HSMENUTEST_FUNC_EXIT("hsmenuview::findItem");
       
   392 }
       
   393 
       
   394 /*!
       
   395  Makes the view display search panel with view representing search results.
       
   396  */
       
   397 void HsMenuView::searchBegins()
       
   398 {
       
   399     HSMENUTEST_FUNC_ENTRY("hsmenuview::searchBegins");
       
   400 
       
   401 
       
   402     mBuilder.setViewContext(mViewContext);
       
   403     mBuilder.setOperationalContext(HsSearchContext);
       
   404     mBuilder.build();
       
   405     mSearchListView = mBuilder.currentListView();
       
   406     mSearchPanel = mBuilder.currentSearchPanel();
       
   407 
       
   408     mView->hideItems(Hb::AllItems);
       
   409 
       
   410     mProxyModel->invalidate();
       
   411     mProxyModel->setSourceModel(mListView->model());
       
   412     mProxyModel->setFilterRegExp(QRegExp(QString(".*"), Qt::CaseInsensitive,
       
   413                                          QRegExp::RegExp));
       
   414     mSearchListView->setModel(mProxyModel);
       
   415     mSearchListView->setItemPrototype(new HsListViewItem());
       
   416     
       
   417     mSearchListView->scrollTo(
       
   418         mProxyModel->mapFromSource(mSearchViewInitialIndex),
       
   419         HbAbstractItemView::PositionAtTop);
       
   420     HSMENUTEST_FUNC_EXIT("hsmenuview::searchBegins");
       
   421 }
       
   422 
       
   423 /*!
       
   424   Ensures view does not contain search related elements and is scrolled
       
   425   to item chosen in search mode.
       
   426  */
       
   427 void HsMenuView::searchFinished()
       
   428 {
       
   429     HSMENUTEST_FUNC_ENTRY("hsmenuview::searchFinished");
       
   430     
       
   431     mBuilder.setViewContext(mViewContext);
       
   432     mBuilder.setOperationalContext(HsItemViewContext);
       
   433     mBuilder.build();
       
   434     mView->showItems(Hb::AllItems);
       
   435 
       
   436     const QModelIndex indexToScroll =
       
   437         mProxyModel->mapToSource(mIndexToScrollAfterSearchDone);
       
   438 
       
   439     mListView->scrollTo(indexToScroll, HbAbstractItemView::PositionAtTop);
       
   440 
       
   441     mSearchListView = NULL;
       
   442     mSearchPanel = NULL;
       
   443     vkbClosed();
       
   444     HSMENUTEST_FUNC_EXIT("hsmenuview::searchFinished");
       
   445 }
       
   446 
       
   447 /*!
       
   448  Slot used to translate activated signal from proxy model to normal model.
       
   449  \param index representing an item activated in search list view.
       
   450  */
       
   451 void HsMenuView::activatedProxySlot(const QModelIndex &index)
       
   452 {
       
   453     emit activated(mProxyModel->mapToSource(index));
       
   454 }
       
   455 
       
   456 /*!
       
   457  Slot used to forward 'long pressed' signal with item description transladed 
       
   458  from search view context to context of the view search was requested from. 
       
   459  */
       
   460 void HsMenuView::longPressedProxySlot(HbAbstractViewItem *item,
       
   461                                       const QPointF &coords)
       
   462 {
       
   463     /*
       
   464       this is a kind of hack, introduced for reasons:
       
   465       item object should be reusable later, but orbit (or qt) prevents setting
       
   466       its index model to previous state
       
   467       */
       
   468     mSearchViewLongPressedIndex =
       
   469         mProxyModel->mapToSource(item->modelIndex());
       
   470     QScopedPointer<HbAbstractViewItem> itemNew(item->createItem());
       
   471     itemNew->setModelIndex(mSearchViewLongPressedIndex);
       
   472     emit longPressed(itemNew.data(), coords);
       
   473 }
       
   474 
       
   475 /*!
       
   476  Add the view to main window and search action with \a showSearchPanel
       
   477  slot of the window.
   252  slot of the window.
   478  */
   253  */
   479 void HsMenuView::activate()
   254 void HsMenuView::activate()
   480 {
   255 {
       
   256     mMainWindow.setCurrentView(mView);
   481     connect(mBuilder.searchAction(), SIGNAL(triggered()),
   257     connect(mBuilder.searchAction(), SIGNAL(triggered()),
   482             this, SLOT(showSearchPanel()));
   258             this, SLOT(showSearchPanel()), Qt::UniqueConnection);
   483 }
   259 }
   484 
   260 
   485 /*!
   261 /*!
   486  Disconnecs search action and \a showSearchPanel slot of the window.
   262  Disconnects search action and disconnects \a showSearchPanel slot from the window.
   487  */
   263  */
   488 void HsMenuView::inactivate()
   264 void HsMenuView::inactivate()
   489 {
   265 {
   490     // handle app key event
   266     // handle app key event
   491     mBuilder.toolBarExtension()->close();
   267     mBuilder.toolBarExtension()->close();
   492 
   268 
   493     disconnect(mBuilder.searchAction(), SIGNAL(triggered()),
   269     disconnect(mBuilder.searchAction(), SIGNAL(triggered()),
   494                this, SLOT(showSearchPanel()));
   270                this, SLOT(showSearchPanel()));
   495 }
   271 }
   496 
   272 
   497 
   273 /*!
   498 /*!
   274   Makes a new view to be activated. Ensure navigation action and view label
   499  change size of view when VKB is opened
   275   heading are preserved after reset.
   500  */
   276   \param operationalContext Context indicating which view to activate.
   501 void HsMenuView::vkbOpened()
   277  */
   502 {
   278 void HsMenuView::reset(HsOperationalContext operationalContext)
   503     mView->setMaximumHeight(mVkbHost->applicationArea().height());   
   279 {
   504 }
   280     QString viewLabelHeading;
   505 
   281 
   506 /*!
   282     // before changing context read current view label heading ...
   507  change size of view when VKB is closed
   283     synchronizeCache();
   508  */
   284 
   509 void HsMenuView::vkbClosed()
   285     if (mBuilder.currentViewLabel() != 0) {
   510 {
   286         viewLabelHeading = mBuilder.currentViewLabel()->heading();
   511      mView->setMaximumHeight(-1);   
   287     }
   512 }
   288     // ... and back-key action
   513 
   289     HbAction *const backKeyAction(mView->navigationAction());
       
   290 
       
   291     // now we can switch the context
       
   292     mOperationalContext = operationalContext;
       
   293     synchronizeCache();
       
   294 
       
   295     if (mBuilder.currentViewLabel() != 0) {
       
   296         mBuilder.currentViewLabel()->setHeading(viewLabelHeading);
       
   297     }
       
   298     mView->setNavigationAction(backKeyAction);
       
   299 }
       
   300 
       
   301 /*!
       
   302  Builder can be shared between many instances of HsMenuView
       
   303  being in different contexts. Before using builder make sure
       
   304  it is in context matching the current HsMenuView.
       
   305  */
       
   306 
       
   307 void HsMenuView::switchBuilderContext()
       
   308 {
       
   309     mBuilder.setStateContext(mStateContext);
       
   310     mBuilder.setOperationalContext(mOperationalContext);
       
   311 }
       
   312 
       
   313 /*!
       
   314  Updates internal data references to widgets.
       
   315  */
       
   316 void HsMenuView::synchronizeCache()
       
   317 {
       
   318     switchBuilderContext();
       
   319 
       
   320     mView = mBuilder.currentView();
       
   321     mListView = mBuilder.currentListView();
       
   322     mViewLabel = mBuilder.currentViewLabel();
       
   323     mAddContentButton = mBuilder.currentAddContentButton();
       
   324 }