phoneapp/phoneuiview2/src/phoneuiqtview.cpp
changeset 78 baacf668fe89
parent 76 cfea66083b62
equal deleted inserted replaced
76:cfea66083b62 78:baacf668fe89
     1 /*!
     1 /*!
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 *
    13 *
    14 * Description:  Phone UI's Qt view.
    14 * Description:  Phone UI's Qt view.
    15 *
    15 *
    16 */
    16 */
    17 #include <hbinstance.h>
    17 #include <hbinstance.h>
    18 #include <QSignalMapper>
       
    19 #include <hbaction.h>
    18 #include <hbaction.h>
    20 #include <hbtoolbar.h>
    19 #include <hbtoolbar.h>
    21 #include <hbvolumesliderpopup.h>
       
    22 #include <hbnamespace.h>
    20 #include <hbnamespace.h>
    23 #include <bubblemanager2.h>
    21 #include <bubblemanager2.h>
    24 #include <hblineedit.h>
    22 #include <hblineedit.h>
    25 #include <hbmenu.h>
    23 #include <hbmenu.h>
    26 
       
    27 #include <xqserviceutil.h>
       
    28 #include <xqkeycapture.h>
       
    29 #include <dialpad.h>
    24 #include <dialpad.h>
    30 #include <dialpadkeyhandler.h>
    25 
    31 
    26 #include "phoneuiqtview_p.h"
    32 #include "phoneuiqtview.h"
    27 #include "phoneuiqtview.h"
    33 #include "phoneaction.h"
       
    34 #include "qtphonelog.h"
    28 #include "qtphonelog.h"
    35 
    29 
    36 PhoneUIQtView::PhoneUIQtView (HbMainWindow &window, QGraphicsItem *parent) :
    30 PhoneUIQtView::PhoneUIQtView (HbMainWindow &window, QGraphicsItem *parent) :
    37     HbView (parent),
    31     HbView(parent),
    38     m_window(window),
    32     m_priv(new PhoneUIQtViewPrivate(window, *this))
    39     m_bubbleManager(0),
       
    40     m_signalMapper(0),
       
    41     m_volumeSlider (0),
       
    42     m_expandSignalMapper(0),
       
    43     m_participantListSignalMapper(0),
       
    44     m_volumeCommandId(0),
       
    45     m_backAction(0),
       
    46     m_dialpad(0),
       
    47     m_menuSignalMapper(0),
       
    48     m_keyCapture(0),
       
    49     m_networkInfo(0),
       
    50     m_dialpadKeyHandler(0),
       
    51     m_restrictedMode(false),
       
    52     m_optionsMenu(0)
       
    53 {
    33 {
    54     PHONE_TRACE
    34     PHONE_TRACE
    55     // Set network name
    35     // Set network name
    56     m_networkInfo = new QSystemNetworkInfo(this);
    36     setTitle(m_priv->networkName());
    57     QString networkName = m_networkInfo->networkName(QSystemNetworkInfo::WcdmaMode);
       
    58     if(networkName.isEmpty()) {
       
    59         networkName = m_networkInfo->networkName(QSystemNetworkInfo::GsmMode);
       
    60     }
       
    61     connect(m_networkInfo, SIGNAL (networkNameChanged(QSystemNetworkInfo::NetworkMode,QString)),
       
    62             this, SLOT(networkNameChanged(QSystemNetworkInfo::NetworkMode, QString)));
       
    63     setTitle(networkName);
       
    64 
       
    65     // Capturing long press of end key
       
    66     m_keyCapture = new XQKeyCapture();
       
    67     
       
    68     // Dialpad
       
    69     m_dialpad = new Dialpad(m_window);
       
    70     m_dialpad->setCallButtonEnabled(false);
       
    71     m_dialpad->setTapOutsideDismiss(true);
       
    72     connect(m_dialpad,SIGNAL(aboutToClose()),this,
       
    73                 SLOT(dialpadClosed()));
       
    74     
    37     
    75     // Call handling widget
    38     // Call handling widget
    76     m_bubbleManager = new BubbleManager (this);
    39     setWidget(m_priv->m_bubbleManager);
    77     setWidget(m_bubbleManager);
       
    78 
       
    79     // Set event filter
       
    80     m_window.installEventFilter(this);
       
    81 
       
    82     m_signalMapper = new QSignalMapper (this);
       
    83     connect(m_signalMapper, SIGNAL (mapped (int)), this, SIGNAL (command (int)));
       
    84     connect(&m_window,SIGNAL(orientationChanged(Qt::Orientation)),
       
    85             this,SLOT(handleOrientationChange(Qt::Orientation)));
       
    86 
       
    87     m_menuSignalMapper = new QSignalMapper(this);
       
    88     connect(m_menuSignalMapper, SIGNAL(mapped(int)), this, SIGNAL(command(int)));
       
    89 
       
    90     m_bubbleManager->handleOrientationChange(m_window.orientation());
       
    91 
    40 
    92     // change exit softkey to back button
    41     // change exit softkey to back button
    93     m_backAction = new HbAction(Hb::BackNaviAction, this);
    42     setNavigationAction(m_priv->m_backAction);
    94     connect(m_backAction, SIGNAL(triggered()), this, SLOT(backButtonClicked()));
       
    95     setNavigationAction(m_backAction);
       
    96 
       
    97     createToolBarActions();
       
    98 
    43 
    99     // Set restricted mode off, normal state
    44     // Set restricted mode off, normal state
   100     setRestrictedMode(false);
    45     setRestrictedMode(false);
   101 }
    46 }
   102 
    47 
   103 PhoneUIQtView::~PhoneUIQtView ()
    48 PhoneUIQtView::~PhoneUIQtView ()
   104 {
    49 {
   105     foreach (QList<HbAction *> *actions, m_bubbleActionMap) {
       
   106         qDeleteAll(*actions);
       
   107         delete actions;
       
   108     }
       
   109     
       
   110     qDeleteAll(m_participantListActions);
       
   111     qDeleteAll(m_expandActionMap);
       
   112     qDeleteAll(m_bubbleMap);
       
   113     qDeleteAll(m_toolbarActions);
       
   114     m_window.removeEventFilter(this);
       
   115     delete m_keyCapture;
       
   116     delete m_volumeSlider;
       
   117     delete m_dialpad;
       
   118     delete m_optionsMenu;
       
   119 }
    50 }
   120 
    51 
   121 BubbleManagerIF& PhoneUIQtView::bubbleManager()
    52 BubbleManagerIF& PhoneUIQtView::bubbleManager()
   122 {
    53 {
   123     return *m_bubbleManager;
    54     return *m_priv->m_bubbleManager;
   124 }
    55 }
   125 
    56 
   126 void PhoneUIQtView::addBubbleCommand (
    57 void PhoneUIQtView::addBubbleCommand (
   127     int bubbleId,
    58     int bubbleId,
   128     const PhoneAction& action )
    59     HbAction* action )
   129 {
    60 {
   130     PHONE_TRACE
    61     PHONE_TRACE
   131     HbAction *bubbleAction = new HbAction ();
    62     m_priv->addBubbleCommand(bubbleId, action);
   132     bubbleAction->setText (action.text());
       
   133     bubbleAction->setIcon (action.icon());
       
   134     setActionRole(action,*bubbleAction);
       
   135     m_bubbleManager->addAction (bubbleId, bubbleAction);
       
   136 
       
   137     QList<int> bubbles = m_bubbleMap.keys();
       
   138     bool found(false);
       
   139 
       
   140     for ( int i=0; i<bubbles.size(); ++i ) {
       
   141         if (bubbleId==bubbles[i]){
       
   142             connect(bubbleAction, SIGNAL (triggered ()), m_bubbleMap[bubbleId], SLOT (map ()));
       
   143             m_bubbleMap[bubbleId]->setMapping(bubbleAction, action.command());
       
   144             m_bubbleActionMap[bubbleId]->append(bubbleAction);
       
   145             found = true;
       
   146         }
       
   147     }
       
   148 
       
   149     if (!found) {
       
   150         QSignalMapper *mapper = new QSignalMapper();
       
   151         connect(mapper, SIGNAL (mapped (int)), this, SIGNAL (command (int)));
       
   152         connect(bubbleAction, SIGNAL (triggered ()), mapper, SLOT (map ()));
       
   153         mapper->setMapping (bubbleAction, action.command());
       
   154         QList<HbAction *> *actionList = new QList<HbAction *>();
       
   155         actionList->append( bubbleAction );
       
   156         m_bubbleActionMap.insert(bubbleId,actionList);
       
   157         m_bubbleMap.insert(bubbleId,mapper);
       
   158     }
       
   159 }
    63 }
   160 
    64 
   161 void PhoneUIQtView::addParticipantListAction(
    65 void PhoneUIQtView::addParticipantListAction(
   162     int commandId,
    66     int commandId,
   163     const QString& text,
    67     const QString& text,
   164     const HbIcon& icon)
    68     const HbIcon& icon)
   165 {
    69 {
   166     PHONE_TRACE
    70     PHONE_TRACE
   167     HbAction* action = new HbAction ();
    71     m_priv->addParticipantListAction(commandId, text, icon);
   168     action->setText (text);
       
   169     action->setIcon (icon);
       
   170     m_bubbleManager->addParticipantListAction(action);
       
   171 
       
   172     if (!m_participantListSignalMapper) {
       
   173         m_participantListSignalMapper = new QSignalMapper();
       
   174         connect(m_participantListSignalMapper, SIGNAL (mapped (int)), this, SIGNAL (command (int)));
       
   175     }
       
   176 
       
   177     connect(action, SIGNAL (triggered ()), m_participantListSignalMapper, SLOT (map ()));
       
   178     m_participantListSignalMapper->setMapping (action, commandId);
       
   179     m_participantListActions.append( action );
       
   180 }
    72 }
   181 
    73 
   182 void PhoneUIQtView::clearParticipantListActions()
    74 void PhoneUIQtView::clearParticipantListActions()
   183 {
    75 {
   184     PHONE_TRACE
    76     PHONE_TRACE
   185     if (m_participantListSignalMapper) {
    77     m_priv->clearParticipantListActions();
   186         m_bubbleManager->clearParticipantListActions();
       
   187 
       
   188         foreach (HbAction *action, m_participantListActions ) {
       
   189             m_participantListSignalMapper->removeMappings(action);
       
   190         }
       
   191 		qDeleteAll(m_participantListActions);
       
   192         m_participantListActions.clear();
       
   193         delete m_participantListSignalMapper;
       
   194         m_participantListSignalMapper = 0;
       
   195     }
       
   196 
       
   197 }
    78 }
   198 
    79 
   199 void PhoneUIQtView::clearBubbleCommands (int bubbleId)
    80 void PhoneUIQtView::clearBubbleCommands (int bubbleId)
   200 {
    81 {
   201     PHONE_TRACE
    82     PHONE_TRACE
   202     m_bubbleManager->clearActions (bubbleId);
    83     m_priv->clearBubbleCommands(bubbleId);
   203     QSignalMapper *mapper = m_bubbleMap.value(bubbleId);
    84 }
   204 
    85 
   205     if (mapper) {
    86 void PhoneUIQtView::setToolbarActions(
   206         QList<HbAction *> *actions = m_bubbleActionMap.value(bubbleId);
    87         const QList<HbAction *> &newToolBarActions)
   207         if (actions) {
    88 {
   208             foreach (HbAction *action, *actions ) {
    89     PHONE_TRACE
   209                 mapper->removeMappings(action);
    90     m_priv->replaceActions(*toolBar(), newToolBarActions);
   210             }
    91 
   211 
    92     if ( m_priv->m_window.orientation() == Qt::Horizontal ) {
   212             qDeleteAll(*actions);
       
   213             actions->clear();
       
   214             delete actions;
       
   215         }
       
   216         
       
   217         m_bubbleMap.remove(bubbleId);
       
   218         m_bubbleActionMap.remove(bubbleId);
       
   219         delete mapper;
       
   220     }
       
   221 
       
   222 }
       
   223 
       
   224 void PhoneUIQtView::setToolbarActions(const QList<PhoneAction*>& actions)
       
   225 {
       
   226     PHONE_TRACE
       
   227     // clear current toolbar actions
       
   228     for (int i=0;i<toolBar()->actions().count();++i) {
       
   229         m_signalMapper->removeMappings(
       
   230                 static_cast<HbAction*>(toolBar()->actions().at(i)));
       
   231     }
       
   232 
       
   233     QList<QAction*> toolBarActions = toolBar()->actions();
       
   234 
       
   235     if (toolBarActions.size()<actions.size()) {
       
   236         for (int i=toolBarActions.size(); i<actions.size(); ++i) {
       
   237             toolBar()->addAction(m_toolbarActions.at(i));
       
   238         }
       
   239     } else if (toolBarActions.size()>actions.size()) {
       
   240         for (int i=toolBarActions.size(); 0<i; --i) {
       
   241             if (i>actions.size()) {
       
   242                 HbAction* action = static_cast<HbAction*>(toolBarActions.at(i-1));
       
   243                 toolBar()->removeAction(action);
       
   244             }
       
   245         }
       
   246     }
       
   247 
       
   248     for (int i=0; i<toolBar()->actions().size(); ++i) {
       
   249 
       
   250         if (i<actions.count()) {
       
   251             HbAction* action = static_cast<HbAction*>(toolBar()->actions().at(i));
       
   252             action->setText(actions.at(i)->text());
       
   253             action->setIcon(actions.at(i)->icon());
       
   254             action->setDisabled(actions.at(i)->isDisabled());
       
   255 
       
   256             m_signalMapper->setMapping(action, actions.at(i)->command());
       
   257         }
       
   258     }
       
   259 
       
   260     if ( m_window.orientation() == Qt::Horizontal ) {
       
   261         toolBar()->setOrientation(Qt::Horizontal);
    93         toolBar()->setOrientation(Qt::Horizontal);
   262     }
    94     }
   263     // update toolbar
    95     // update toolbar
   264     toolBar()->update();
    96     toolBar()->update();
   265 }
    97 }
   266 
    98 
   267 void PhoneUIQtView::hideToolbar ()
    99 void PhoneUIQtView::hideToolbar ()
   268 {
   100 {
   269     toolBar()->hide ();
   101     toolBar()->hide();
   270 }
   102 }
   271 
   103 
   272 void PhoneUIQtView::showToolbar ()
   104 void PhoneUIQtView::showToolbar ()
   273 {
   105 {
   274     setFocus();
   106     setFocus();
   275     toolBar()->show();
   107     toolBar()->show();
   276 }
   108 }
   277 
   109 
   278 int PhoneUIQtView::volumeSliderValue ()
   110 int PhoneUIQtView::volumeSliderValue ()
   279 {
   111 {
   280     if (m_volumeSlider) {
   112     return m_priv->volumeSliderValue();
   281         return m_volumeSlider->value ();
       
   282     } else {
       
   283         return -1;
       
   284     }
       
   285 }
       
   286 
       
   287 void PhoneUIQtView::removeVolumeSlider ()
       
   288 {
       
   289     if (m_volumeSlider) {
       
   290         if (m_volumeSlider->isVisible()) {
       
   291             m_volumeSlider->hide();
       
   292         }
       
   293         m_volumeSlider->deleteLater();
       
   294         m_volumeSlider = 0;
       
   295     }
       
   296 }
       
   297 
       
   298 void PhoneUIQtView::volumeSliderClosed ()
       
   299 {
       
   300     removeVolumeSlider();
       
   301 }
   113 }
   302 
   114 
   303 void PhoneUIQtView::setVolumeSliderValue (
   115 void PhoneUIQtView::setVolumeSliderValue (
   304         int value, int commandId, int maxVolumeValue, int minVolumeValue)
   116         int value, int commandId, int maxVolumeValue, int minVolumeValue)
   305 {
   117 {
   306     PHONE_TRACE
   118     PHONE_TRACE
   307     m_volumeCommandId = commandId;
   119     m_priv->setVolumeSliderValue(
   308 
   120             value, commandId, maxVolumeValue, minVolumeValue);
   309     if (!m_volumeSlider) {
   121 }
   310         m_volumeSlider = new HbVolumeSliderPopup ();
   122 
   311         m_volumeSlider->setDismissPolicy(HbDialog::TapOutside);
   123 void PhoneUIQtView::removeVolumeSlider()
   312         m_volumeSlider->setTimeout (10000); // TODO: 10 seconds for now, replace with correct value when spec is ready and says what it is
   124 {
   313         connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(volumeSliderChanged(int)));
   125     PHONE_TRACE
   314         connect(m_volumeSlider, SIGNAL(aboutToClose()), this, SLOT(volumeSliderClosed()));
   126     m_priv->removeVolumeSlider();
   315     }
       
   316 
       
   317 
       
   318     if (m_volumeSlider->minimum() != minVolumeValue ||
       
   319             m_volumeSlider->maximum() !=  maxVolumeValue  ) {
       
   320         m_volumeSlider->setRange (minVolumeValue, maxVolumeValue);
       
   321     }
       
   322 
       
   323     if (value != m_volumeSlider->value())
       
   324         m_volumeSlider->setValue (value);
       
   325 
       
   326     if (false == m_volumeSlider->isVisible()) {
       
   327         m_volumeSlider->show();
       
   328     }
       
   329 }
       
   330 
       
   331 void PhoneUIQtView::volumeSliderChanged(int value)
       
   332 {
       
   333     Q_UNUSED (value);
       
   334     emit command (m_volumeCommandId);
       
   335 }
   127 }
   336 
   128 
   337 void PhoneUIQtView::setExpandAction(int bubbleId, int commandId)
   129 void PhoneUIQtView::setExpandAction(int bubbleId, int commandId)
   338 {
   130 {
   339     PHONE_TRACE
   131     PHONE_TRACE
   340     removeExpandAction(bubbleId);
   132     m_priv->setExpandAction(bubbleId, commandId);
   341 
       
   342     HbAction* action = new HbAction();
       
   343     m_bubbleManager->setExpandAction(bubbleId, action);
       
   344 
       
   345     if (!m_expandSignalMapper) {
       
   346         m_expandSignalMapper = new QSignalMapper(this);
       
   347         connect(m_expandSignalMapper, SIGNAL (mapped (int)),
       
   348                 this, SIGNAL (command (int)));
       
   349     }
       
   350 
       
   351     connect(action, SIGNAL (triggered ()), m_expandSignalMapper, SLOT (map ()));
       
   352     m_expandSignalMapper->setMapping(action, commandId);
       
   353 
       
   354     m_expandActionMap.insert(bubbleId,action);
       
   355 }
   133 }
   356 
   134 
   357 void PhoneUIQtView::removeExpandAction(int bubbleId)
   135 void PhoneUIQtView::removeExpandAction(int bubbleId)
   358 {
   136 {
   359     PHONE_TRACE
   137     PHONE_TRACE
   360     if (m_expandActionMap.contains(bubbleId)) {
   138     m_priv->removeExpandAction(bubbleId);
   361         m_bubbleManager->setExpandAction(bubbleId, 0);
       
   362         HbAction* action = m_expandActionMap.value(bubbleId);
       
   363         m_expandSignalMapper->removeMappings(action);
       
   364         m_expandActionMap.remove(bubbleId);
       
   365         delete action;
       
   366     }
       
   367 }
   139 }
   368 
   140 
   369 void PhoneUIQtView::showDialpad()
   141 void PhoneUIQtView::showDialpad()
   370 {
   142 {
   371     if (false == m_dialpad->isVisible()) {
   143     m_priv->showDialpad();
   372         setDialpadPosition();
       
   373         m_dialpad->openDialpad();
       
   374     }
       
   375 }
   144 }
   376 
   145 
   377 void PhoneUIQtView::hideDialpad()
   146 void PhoneUIQtView::hideDialpad()
   378 {
   147 {
   379     if (true == m_dialpad->isVisible())
   148     m_priv->hideDialpad();
   380         m_dialpad->closeDialpad();
       
   381 }
   149 }
   382 
   150 
   383 bool PhoneUIQtView::isDialpadVisible()
   151 bool PhoneUIQtView::isDialpadVisible()
   384 {
   152 {
   385     return m_dialpad->isVisible();
   153     return m_priv->m_dialpad->isVisible();
   386 }
   154 }
   387 
   155 
   388 QString PhoneUIQtView::dialpadText()
   156 QString PhoneUIQtView::dialpadText()
   389 {
   157 {
   390     return m_dialpad->editor().text();
   158     return m_priv->m_dialpad->editor().text();
   391 }
   159 }
   392 
   160 
   393 void PhoneUIQtView::clearAndHideDialpad()
   161 void PhoneUIQtView::clearAndHideDialpad()
   394 {
   162 {
   395     m_dialpad->editor().setText(QString(""));
   163     m_priv->m_dialpad->editor().setText(QString(""));
   396     m_dialpad->closeDialpad();
   164     m_priv->m_dialpad->closeDialpad();
   397 }
   165 }
   398 
   166 
   399 void PhoneUIQtView::clearDialpad()
   167 void PhoneUIQtView::clearDialpad()
   400 {
   168 {
   401     m_dialpad->editor().setText(QString(""));
   169     m_priv->m_dialpad->editor().setText(QString(""));
   402 }
   170 }
   403 
   171 
   404 void PhoneUIQtView::bringToForeground()
   172 void PhoneUIQtView::bringToForeground()
   405 {
   173 {
   406     m_window.show();
   174     m_priv->m_window.show(); 
   407 }
   175     m_priv->m_window.raise();
   408 
   176 }
   409 void PhoneUIQtView::setMenuActions(const QList<PhoneAction*>& actions)
   177 
       
   178 void PhoneUIQtView::hide()
       
   179 {
       
   180     m_priv->m_window.hide();   
       
   181     m_priv->m_window.lower();     
       
   182 }
       
   183 
       
   184 void PhoneUIQtView::setMenuActions(
       
   185         const QList<HbAction*> &actions)
   410 {   
   186 {   
   411     PHONE_TRACE    
   187     PHONE_TRACE
   412     HbMenu* optionsMenu = m_optionsMenu ? m_optionsMenu : menu();
   188     HbMenu *optionsMenu = &menuReference();
       
   189     m_priv->replaceActions(*optionsMenu, actions);
   413     
   190     
   414     for (int i=optionsMenu->actions().count(); 0<i; --i) {
       
   415         HbAction* action = static_cast<HbAction*>(optionsMenu->actions().at(i-1));
       
   416         m_menuSignalMapper->removeMappings(action);
       
   417         optionsMenu->removeAction(action);
       
   418         delete action;
       
   419     }
       
   420     for (int i=0; i<actions.count(); ++i) {
       
   421         HbAction* action = new HbAction();
       
   422         action->setText(actions.at(i)->text());
       
   423         optionsMenu->addAction(action);
       
   424         connect(action, SIGNAL(triggered()), m_menuSignalMapper, SLOT(map()));
       
   425         m_menuSignalMapper->setMapping(action, actions.at(i)->command());
       
   426     }    
       
   427     updateMenuVisibility();
       
   428 }
       
   429 
       
   430 HbMenu &PhoneUIQtView::menuReference()
       
   431 {
       
   432     PHONE_TRACE
       
   433     HbMenu* optionsMenu = m_optionsMenu ? m_optionsMenu : menu();
       
   434     return *optionsMenu;
       
   435 }
       
   436 
       
   437 void PhoneUIQtView::captureKey(Qt::Key key, bool capture)
       
   438 {
       
   439     if (capture) {
       
   440         if (!m_keyCaptures.contains(key)) {
       
   441             m_keyCapture->captureLongKey(key);
       
   442             m_keyCapture->captureKey(key);
       
   443             m_keyCaptures.append(key);
       
   444         }
       
   445     } else {
       
   446         if (m_keyCaptures.contains(key)) {
       
   447             m_keyCapture->cancelCaptureKey(key);
       
   448             m_keyCapture->cancelCaptureLongKey(key);
       
   449             m_keyCaptures.removeOne(key);
       
   450         }
       
   451     }
       
   452 }
       
   453 
       
   454 void PhoneUIQtView::handleOrientationChange(Qt::Orientation orientation)
       
   455 {
       
   456     PHONE_TRACE
       
   457     if (orientation==Qt::Horizontal) {
       
   458         toolBar()->setOrientation(Qt::Horizontal);
       
   459     }
       
   460 
       
   461     m_bubbleManager->handleOrientationChange(orientation);
       
   462 
       
   463     setDialpadPosition();
       
   464 }
       
   465 
       
   466 void PhoneUIQtView::backButtonClicked()
       
   467 {
       
   468     XQServiceUtil::toBackground(true);
       
   469 }
       
   470 
       
   471 void PhoneUIQtView::onEditorContentChanged()
       
   472 {
       
   473     m_dialpad->setCallButtonEnabled(
       
   474         m_dialpad->editor().text().length());
       
   475 }
       
   476 
       
   477 void PhoneUIQtView::dialpadClosed()
       
   478 {
       
   479     emit dialpadIsAboutToClose();
       
   480 }
       
   481 
       
   482 bool PhoneUIQtView::eventFilter(QObject *watched, QEvent * event)
       
   483 {
       
   484     Q_UNUSED(watched);
       
   485     PHONE_TRACE2(":event type", event->type())
       
   486     
       
   487     // Allow send key only when there is callbutton enabled or no text in input field
       
   488     bool sendKeyAllowed = m_dialpad->isCallButtonEnabled() || 
       
   489             (m_dialpad->editor().text().length() == 0);
       
   490     
       
   491     if(event->type() == QEvent::KeyPress) {
       
   492         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
   493         PHONE_DEBUG2("PhoneUIQtView::eventFilter pressed key:", keyEvent->key());
       
   494         PHONE_DEBUG2("PhoneUIQtView::eventFilter isAutoRepeat:", keyEvent->isAutoRepeat());
       
   495         if ( (keyEvent->key() != Qt::Key_Yes && keyEvent->key() != Qt::Key_Enter) ||
       
   496                 sendKeyAllowed) {
       
   497             emit keyPressed(keyEvent);        
       
   498             keyEvent->accept();
       
   499         }
       
   500         
       
   501         return false;
       
   502     } else if(event->type() == QEvent::KeyRelease) {
       
   503         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
   504         PHONE_DEBUG2("PhoneUIQtView::eventFilter released key:", keyEvent->key());
       
   505         if ( (keyEvent->key() != Qt::Key_Yes && keyEvent->key() != Qt::Key_Enter) ||
       
   506                 sendKeyAllowed) {
       
   507             emit keyReleased(keyEvent);
       
   508             keyEvent->accept();
       
   509         }
       
   510         return false;
       
   511     } else if (event->type() == QEvent::WindowActivate){
       
   512         PHONE_DEBUG("PhoneUIQtView::eventFilter WindowActivate");
       
   513         emit windowActivated();
       
   514         return false;
       
   515     } else if (event->type() == QEvent::WindowDeactivate){
       
   516         PHONE_DEBUG("PhoneUIQtView::eventFilter WindowDeactivate");
       
   517         emit windowDeactivated();
       
   518         return false;
       
   519     }else{
       
   520         return false;
       
   521     }
       
   522 }
       
   523 
       
   524 void PhoneUIQtView::setDialpadPosition()
       
   525 {
       
   526     PHONE_TRACE
       
   527     QRectF screenRect(m_window.layoutRect());
       
   528                         	
       
   529     if (m_window.orientation() == Qt::Horizontal) {
       
   530             // dialpad takes half of the screen
       
   531         m_dialpad->setPos(QPointF(screenRect.width()/2,
       
   532                                   this->scenePos().y()));
       
   533         m_dialpad->setPreferredSize(screenRect.width()/2,
       
   534                                            (screenRect.height()-scenePos().y()));
       
   535     } else {
       
   536         // dialpad takes 65% of the screen height
       
   537         qreal screenHeight = screenRect.height();
       
   538         m_dialpad->setPos(QPointF(0,
       
   539                                   screenHeight/2.25));
       
   540         m_dialpad->setPreferredSize(screenRect.width(),
       
   541                                     screenHeight-screenHeight/2.25);
       
   542     }
       
   543 }
       
   544 
       
   545 void PhoneUIQtView::setActionRole(const PhoneAction& pa, HbAction& action)
       
   546 {
       
   547     PHONE_TRACE
       
   548     if (pa.actionRole()==PhoneAction::Accept) {
       
   549         action.setSoftKeyRole(QAction::PositiveSoftKey);
       
   550     } else if (pa.actionRole()==PhoneAction::Decline) {
       
   551         action.setSoftKeyRole(QAction::NegativeSoftKey);
       
   552     }
       
   553 }
       
   554 
       
   555 void PhoneUIQtView::createToolBarActions()
       
   556 {
       
   557     PHONE_TRACE
       
   558     for (int i=0;i<4;++i) {
       
   559         HbAction* action = new HbAction();
       
   560         connect(action, SIGNAL(triggered()), m_signalMapper, SLOT(map()));
       
   561         m_toolbarActions.append(action);
       
   562     }
       
   563 }
       
   564 
       
   565 void PhoneUIQtView::updateMenuVisibility()
       
   566 {
       
   567     PHONE_TRACE
       
   568     bool visible = false;
   191     bool visible = false;
   569     HbView* view = m_window.currentView();
   192     foreach (HbAction* action, actions) {
   570     HbMenu* optionsMenu = m_optionsMenu ? m_optionsMenu : menu();
       
   571     foreach( QAction* action, optionsMenu->actions()){
       
   572         if(action->isVisible()){
   193         if(action->isVisible()){
   573             visible = true;
   194             visible = true;
   574             break;
   195             break;
   575         }
   196         }
   576     }
   197     }
   577     PHONE_DEBUG2("PhoneUIQtView::updateMenuVisibility -  visible", visible);
   198     PHONE_DEBUG2("-  visible", visible);
   578     if (!visible && !m_optionsMenu) {
   199     HbView* view = m_priv->m_window.currentView();
   579         PHONE_DEBUG("PhoneUIQtView::updateMenuVisibility - takeMenu");
   200     if (!visible && !m_priv->m_optionsMenu) {
       
   201         PHONE_DEBUG("- takeMenu");
   580         //takeMenu() - Removes the menu from the view and returns it to the caller.
   202         //takeMenu() - Removes the menu from the view and returns it to the caller.
   581         //ownership of the menu is transfered.        
   203         //ownership of the menu is transfered.        
   582         m_optionsMenu = view->takeMenu();
   204         m_priv->m_optionsMenu = view->takeMenu();
   583         
   205         
   584     } else if (visible && m_optionsMenu) {
   206     } else if (visible && m_priv->m_optionsMenu) {
   585         // ownership of the menu is transfered
   207         // ownership of the menu is transfered
   586         view->setMenu(m_optionsMenu);
   208         view->setMenu(m_priv->m_optionsMenu);
   587         m_optionsMenu = 0;
   209         m_priv->m_optionsMenu = 0;
       
   210     }
       
   211 }
       
   212 
       
   213 HbMenu &PhoneUIQtView::menuReference()
       
   214 {
       
   215     PHONE_TRACE
       
   216     HbMenu* optionsMenu = m_priv->m_optionsMenu ?
       
   217             m_priv->m_optionsMenu : menu();
       
   218     return *optionsMenu;
       
   219 }
       
   220 
       
   221 void PhoneUIQtView::captureKey(Qt::Key key, bool capture)
       
   222 {
       
   223     m_priv->captureKey(key, capture);
       
   224 }
       
   225 
       
   226 void PhoneUIQtView::handleOrientationChange(
       
   227         Qt::Orientation orientation)
       
   228 {
       
   229     PHONE_TRACE
       
   230     if (orientation==Qt::Horizontal) {
       
   231         toolBar()->setOrientation(Qt::Horizontal);
   588     }
   232     }
   589 }
   233 }
   590 
   234 
   591 void PhoneUIQtView::shutdownPhoneApp()
   235 void PhoneUIQtView::shutdownPhoneApp()
   592 {
   236 {
   593     PHONE_DEBUG("PhoneUIQtView::shutdownPhoneApp");
   237     PHONE_TRACE
   594     QCoreApplication::quit();
   238     QCoreApplication::quit();
   595 }
   239 }
   596 
   240 
   597 void PhoneUIQtView::setBackButtonVisible(bool visible)
   241 void PhoneUIQtView::setBackButtonVisible(bool visible)
   598 {
   242 {
   599     if (!m_restrictedMode) {
   243     if (!m_priv->m_restrictedMode) {
   600         m_backAction->setEnabled(visible);
   244         m_priv->m_backAction->setEnabled(visible);
   601     }
   245     }
   602 }
   246 }
   603 
   247 
   604 void PhoneUIQtView::setRestrictedMode(bool restrictedMode)
   248 void PhoneUIQtView::setRestrictedMode(bool restrictedMode)
   605 {
   249 {
   606     PHONE_TRACE
   250     PHONE_TRACE
   607     m_restrictedMode = restrictedMode;
   251     m_priv->setRestrictedMode(restrictedMode);
   608     m_backAction->setEnabled(!restrictedMode);
   252 }
   609     m_dialpad->setCallButtonEnabled(false);
       
   610     m_dialpad->editor().setText(""); // Clead dialpad
       
   611     if (m_restrictedMode) {
       
   612         delete m_dialpadKeyHandler;
       
   613         m_dialpadKeyHandler = 0;
       
   614         m_dialpadKeyHandler = new DialpadKeyHandler(
       
   615                 m_dialpad, DialpadKeyHandler::EmergencyCall, this);
       
   616         disconnect(&m_dialpad->editor(),SIGNAL(contentsChanged()),
       
   617                 this, SLOT(onEditorContentChanged())); // Let emergency handler do updating 
       
   618     } else {
       
   619         delete m_dialpadKeyHandler;
       
   620         m_dialpadKeyHandler = 0;
       
   621         // enable key sequence handling during a call
       
   622         m_dialpadKeyHandler = new DialpadKeyHandler(
       
   623                 m_dialpad, DialpadKeyHandler::KeySequence, this);
       
   624         connect(&m_dialpad->editor(),SIGNAL(contentsChanged()),
       
   625                 SLOT(onEditorContentChanged())); // Update our self
       
   626     }
       
   627     
       
   628 }
       
   629 
       
   630 void PhoneUIQtView::networkNameChanged(QSystemNetworkInfo::NetworkMode mode, const QString &netName)
       
   631 {
       
   632     if((mode == QSystemNetworkInfo::GsmMode) || 
       
   633        (mode == QSystemNetworkInfo::WcdmaMode)) {
       
   634         setTitle(netName);
       
   635     }	
       
   636 }
       
   637