phoneapp/phoneuiview2/src/phoneuiqtview.cpp
changeset 76 cfea66083b62
parent 60 1eef62f5c541
child 78 baacf668fe89
equal deleted inserted replaced
74:d1c62c765e48 76:cfea66083b62
    46     m_dialpad(0),
    46     m_dialpad(0),
    47     m_menuSignalMapper(0),
    47     m_menuSignalMapper(0),
    48     m_keyCapture(0),
    48     m_keyCapture(0),
    49     m_networkInfo(0),
    49     m_networkInfo(0),
    50     m_dialpadKeyHandler(0),
    50     m_dialpadKeyHandler(0),
    51     m_restrictedMode(false)
    51     m_restrictedMode(false),
    52 {
    52     m_optionsMenu(0)
       
    53 {
       
    54     PHONE_TRACE
    53     // Set network name
    55     // Set network name
    54     m_networkInfo = new QSystemNetworkInfo(this);
    56     m_networkInfo = new QSystemNetworkInfo(this);
    55     QString networkName = m_networkInfo->networkName(QSystemNetworkInfo::WcdmaMode);
    57     QString networkName = m_networkInfo->networkName(QSystemNetworkInfo::WcdmaMode);
    56     if(networkName.isEmpty()) {
    58     if(networkName.isEmpty()) {
    57         networkName = m_networkInfo->networkName(QSystemNetworkInfo::GsmMode);
    59         networkName = m_networkInfo->networkName(QSystemNetworkInfo::GsmMode);
    98     setRestrictedMode(false);
   100     setRestrictedMode(false);
    99 }
   101 }
   100 
   102 
   101 PhoneUIQtView::~PhoneUIQtView ()
   103 PhoneUIQtView::~PhoneUIQtView ()
   102 {
   104 {
       
   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);
   103     qDeleteAll(m_toolbarActions);
   113     qDeleteAll(m_toolbarActions);
   104     m_window.removeEventFilter(this);
   114     m_window.removeEventFilter(this);
       
   115     delete m_keyCapture;
   105     delete m_volumeSlider;
   116     delete m_volumeSlider;
   106     delete m_dialpad;
   117     delete m_dialpad;
       
   118     delete m_optionsMenu;
   107 }
   119 }
   108 
   120 
   109 BubbleManagerIF& PhoneUIQtView::bubbleManager()
   121 BubbleManagerIF& PhoneUIQtView::bubbleManager()
   110 {
   122 {
   111     return *m_bubbleManager;
   123     return *m_bubbleManager;
   113 
   125 
   114 void PhoneUIQtView::addBubbleCommand (
   126 void PhoneUIQtView::addBubbleCommand (
   115     int bubbleId,
   127     int bubbleId,
   116     const PhoneAction& action )
   128     const PhoneAction& action )
   117 {
   129 {
   118     HbAction* bubbleAction = new HbAction ();
   130     PHONE_TRACE
       
   131     HbAction *bubbleAction = new HbAction ();
   119     bubbleAction->setText (action.text());
   132     bubbleAction->setText (action.text());
   120     bubbleAction->setIcon (action.icon());
   133     bubbleAction->setIcon (action.icon());
   121     setActionRole(action,*bubbleAction);
   134     setActionRole(action,*bubbleAction);
   122     m_bubbleManager->addAction (bubbleId, bubbleAction);
   135     m_bubbleManager->addAction (bubbleId, bubbleAction);
   123 
   136 
   124     QList<int> bubbles = m_bubbleMap.keys();
   137     QList<int> bubbles = m_bubbleMap.keys();
   125     bool found(false);
   138     bool found(false);
   126 
   139 
   127     for ( int i=0; i<bubbles.size(); ++i ) {
   140     for ( int i=0; i<bubbles.size(); ++i ) {
   128         if (bubbleId==bubbles[i]){
   141         if (bubbleId==bubbles[i]){
   129             connect(bubbleAction, SIGNAL (triggered ()), m_bubbleMap.value(bubbleId), SLOT (map ()));
   142             connect(bubbleAction, SIGNAL (triggered ()), m_bubbleMap[bubbleId], SLOT (map ()));
   130             m_bubbleMap.value(bubbleId)->setMapping(bubbleAction, action.command());
   143             m_bubbleMap[bubbleId]->setMapping(bubbleAction, action.command());
   131             m_bubbleActionMap.value(bubbleId)->append(bubbleAction);
   144             m_bubbleActionMap[bubbleId]->append(bubbleAction);
   132             found = true;
   145             found = true;
   133         }
   146         }
   134     }
   147     }
   135 
   148 
   136     if (!found) {
   149     if (!found) {
   148 void PhoneUIQtView::addParticipantListAction(
   161 void PhoneUIQtView::addParticipantListAction(
   149     int commandId,
   162     int commandId,
   150     const QString& text,
   163     const QString& text,
   151     const HbIcon& icon)
   164     const HbIcon& icon)
   152 {
   165 {
       
   166     PHONE_TRACE
   153     HbAction* action = new HbAction ();
   167     HbAction* action = new HbAction ();
   154     action->setText (text);
   168     action->setText (text);
   155     action->setIcon (icon);
   169     action->setIcon (icon);
   156     m_bubbleManager->addParticipantListAction(action);
   170     m_bubbleManager->addParticipantListAction(action);
   157 
   171 
   165     m_participantListActions.append( action );
   179     m_participantListActions.append( action );
   166 }
   180 }
   167 
   181 
   168 void PhoneUIQtView::clearParticipantListActions()
   182 void PhoneUIQtView::clearParticipantListActions()
   169 {
   183 {
   170 
   184     PHONE_TRACE
   171     if (m_participantListSignalMapper) {
   185     if (m_participantListSignalMapper) {
   172         m_bubbleManager->clearParticipantListActions();
   186         m_bubbleManager->clearParticipantListActions();
   173 
   187 
   174         foreach (HbAction *action, m_participantListActions ) {
   188         foreach (HbAction *action, m_participantListActions ) {
   175             m_participantListSignalMapper->removeMappings(action);
   189             m_participantListSignalMapper->removeMappings(action);
   182 
   196 
   183 }
   197 }
   184 
   198 
   185 void PhoneUIQtView::clearBubbleCommands (int bubbleId)
   199 void PhoneUIQtView::clearBubbleCommands (int bubbleId)
   186 {
   200 {
       
   201     PHONE_TRACE
   187     m_bubbleManager->clearActions (bubbleId);
   202     m_bubbleManager->clearActions (bubbleId);
   188     QSignalMapper *mapper = m_bubbleMap.value(bubbleId);
   203     QSignalMapper *mapper = m_bubbleMap.value(bubbleId);
   189 
   204 
   190     if (mapper) {
   205     if (mapper) {
   191         QList<HbAction *> *actions = m_bubbleActionMap.value(bubbleId);
   206         QList<HbAction *> *actions = m_bubbleActionMap.value(bubbleId);
   206 
   221 
   207 }
   222 }
   208 
   223 
   209 void PhoneUIQtView::setToolbarActions(const QList<PhoneAction*>& actions)
   224 void PhoneUIQtView::setToolbarActions(const QList<PhoneAction*>& actions)
   210 {
   225 {
       
   226     PHONE_TRACE
   211     // clear current toolbar actions
   227     // clear current toolbar actions
   212     for (int i=0;i<toolBar()->actions().count();++i) {
   228     for (int i=0;i<toolBar()->actions().count();++i) {
   213         m_signalMapper->removeMappings(
   229         m_signalMapper->removeMappings(
   214                 static_cast<HbAction*>(toolBar()->actions().at(i)));
   230                 static_cast<HbAction*>(toolBar()->actions().at(i)));
   215     }
   231     }
   285 }
   301 }
   286 
   302 
   287 void PhoneUIQtView::setVolumeSliderValue (
   303 void PhoneUIQtView::setVolumeSliderValue (
   288         int value, int commandId, int maxVolumeValue, int minVolumeValue)
   304         int value, int commandId, int maxVolumeValue, int minVolumeValue)
   289 {
   305 {
       
   306     PHONE_TRACE
   290     m_volumeCommandId = commandId;
   307     m_volumeCommandId = commandId;
   291 
   308 
   292     if (!m_volumeSlider) {
   309     if (!m_volumeSlider) {
   293         m_volumeSlider = new HbVolumeSliderPopup ();
   310         m_volumeSlider = new HbVolumeSliderPopup ();
   294         m_volumeSlider->setDismissPolicy(HbDialog::TapOutside);
   311         m_volumeSlider->setDismissPolicy(HbDialog::TapOutside);
   317     emit command (m_volumeCommandId);
   334     emit command (m_volumeCommandId);
   318 }
   335 }
   319 
   336 
   320 void PhoneUIQtView::setExpandAction(int bubbleId, int commandId)
   337 void PhoneUIQtView::setExpandAction(int bubbleId, int commandId)
   321 {
   338 {
       
   339     PHONE_TRACE
   322     removeExpandAction(bubbleId);
   340     removeExpandAction(bubbleId);
   323 
   341 
   324     HbAction* action = new HbAction();
   342     HbAction* action = new HbAction();
   325     m_bubbleManager->setExpandAction(bubbleId, action);
   343     m_bubbleManager->setExpandAction(bubbleId, action);
   326 
   344 
   336     m_expandActionMap.insert(bubbleId,action);
   354     m_expandActionMap.insert(bubbleId,action);
   337 }
   355 }
   338 
   356 
   339 void PhoneUIQtView::removeExpandAction(int bubbleId)
   357 void PhoneUIQtView::removeExpandAction(int bubbleId)
   340 {
   358 {
       
   359     PHONE_TRACE
   341     if (m_expandActionMap.contains(bubbleId)) {
   360     if (m_expandActionMap.contains(bubbleId)) {
   342         m_bubbleManager->setExpandAction(bubbleId, 0);
   361         m_bubbleManager->setExpandAction(bubbleId, 0);
   343         HbAction* action = m_expandActionMap.value(bubbleId);
   362         HbAction* action = m_expandActionMap.value(bubbleId);
   344         m_expandSignalMapper->removeMappings(action);
   363         m_expandSignalMapper->removeMappings(action);
   345         m_expandActionMap.remove(bubbleId);
   364         m_expandActionMap.remove(bubbleId);
   386 {
   405 {
   387     m_window.show();
   406     m_window.show();
   388 }
   407 }
   389 
   408 
   390 void PhoneUIQtView::setMenuActions(const QList<PhoneAction*>& actions)
   409 void PhoneUIQtView::setMenuActions(const QList<PhoneAction*>& actions)
   391 {
   410 {   
   392 
   411     PHONE_TRACE    
   393     for (int i=menu()->actions().count(); 0<i; --i) {
   412     HbMenu* optionsMenu = m_optionsMenu ? m_optionsMenu : menu();
   394         HbAction* action = static_cast<HbAction*>(menu()->actions().at(i-1));
   413     
       
   414     for (int i=optionsMenu->actions().count(); 0<i; --i) {
       
   415         HbAction* action = static_cast<HbAction*>(optionsMenu->actions().at(i-1));
   395         m_menuSignalMapper->removeMappings(action);
   416         m_menuSignalMapper->removeMappings(action);
   396         menu()->removeAction(action);
   417         optionsMenu->removeAction(action);
   397         delete action;
   418         delete action;
   398     }
   419     }
   399 
       
   400     for (int i=0; i<actions.count(); ++i) {
   420     for (int i=0; i<actions.count(); ++i) {
   401         HbAction* action = new HbAction();
   421         HbAction* action = new HbAction();
   402         action->setText(actions.at(i)->text());
   422         action->setText(actions.at(i)->text());
   403         menu()->addAction(action);
   423         optionsMenu->addAction(action);
   404         connect(action, SIGNAL(triggered()), m_menuSignalMapper, SLOT(map()));
   424         connect(action, SIGNAL(triggered()), m_menuSignalMapper, SLOT(map()));
   405         m_menuSignalMapper->setMapping(action, actions.at(i)->command());
   425         m_menuSignalMapper->setMapping(action, actions.at(i)->command());
   406     }
   426     }    
   407 
   427     updateMenuVisibility();
   408 }
   428 }
   409 
   429 
   410 HbMenu &PhoneUIQtView::menuReference()
   430 HbMenu &PhoneUIQtView::menuReference()
   411 {
   431 {
   412     return *menu();
   432     PHONE_TRACE
       
   433     HbMenu* optionsMenu = m_optionsMenu ? m_optionsMenu : menu();
       
   434     return *optionsMenu;
   413 }
   435 }
   414 
   436 
   415 void PhoneUIQtView::captureKey(Qt::Key key, bool capture)
   437 void PhoneUIQtView::captureKey(Qt::Key key, bool capture)
   416 {
   438 {
   417     if (capture) {
   439     if (capture) {
   429     }
   451     }
   430 }
   452 }
   431 
   453 
   432 void PhoneUIQtView::handleOrientationChange(Qt::Orientation orientation)
   454 void PhoneUIQtView::handleOrientationChange(Qt::Orientation orientation)
   433 {
   455 {
       
   456     PHONE_TRACE
   434     if (orientation==Qt::Horizontal) {
   457     if (orientation==Qt::Horizontal) {
   435         toolBar()->setOrientation(Qt::Horizontal);
   458         toolBar()->setOrientation(Qt::Horizontal);
   436     }
   459     }
   437 
   460 
   438     m_bubbleManager->handleOrientationChange(orientation);
   461     m_bubbleManager->handleOrientationChange(orientation);
   457 }
   480 }
   458 
   481 
   459 bool PhoneUIQtView::eventFilter(QObject *watched, QEvent * event)
   482 bool PhoneUIQtView::eventFilter(QObject *watched, QEvent * event)
   460 {
   483 {
   461     Q_UNUSED(watched);
   484     Q_UNUSED(watched);
   462     PHONE_DEBUG2("PhoneUIQtView::eventFilter event type:", event->type());
   485     PHONE_TRACE2(":event type", event->type())
   463     
   486     
   464     // Allow send key only when there is callbutton enabled or no text in input field
   487     // Allow send key only when there is callbutton enabled or no text in input field
   465     bool sendKeyAllowed = m_dialpad->isCallButtonEnabled() || 
   488     bool sendKeyAllowed = m_dialpad->isCallButtonEnabled() || 
   466             (m_dialpad->editor().text().length() == 0);
   489             (m_dialpad->editor().text().length() == 0);
   467     
   490     
   498     }
   521     }
   499 }
   522 }
   500 
   523 
   501 void PhoneUIQtView::setDialpadPosition()
   524 void PhoneUIQtView::setDialpadPosition()
   502 {
   525 {
       
   526     PHONE_TRACE
   503     QRectF screenRect(m_window.layoutRect());
   527     QRectF screenRect(m_window.layoutRect());
   504                         	
   528                         	
   505     if (m_window.orientation() == Qt::Horizontal) {
   529     if (m_window.orientation() == Qt::Horizontal) {
   506             // dialpad takes half of the screen
   530             // dialpad takes half of the screen
   507         m_dialpad->setPos(QPointF(screenRect.width()/2,
   531         m_dialpad->setPos(QPointF(screenRect.width()/2,
   518     }
   542     }
   519 }
   543 }
   520 
   544 
   521 void PhoneUIQtView::setActionRole(const PhoneAction& pa, HbAction& action)
   545 void PhoneUIQtView::setActionRole(const PhoneAction& pa, HbAction& action)
   522 {
   546 {
       
   547     PHONE_TRACE
   523     if (pa.actionRole()==PhoneAction::Accept) {
   548     if (pa.actionRole()==PhoneAction::Accept) {
   524         action.setSoftKeyRole(QAction::PositiveSoftKey);
   549         action.setSoftKeyRole(QAction::PositiveSoftKey);
   525     } else if (pa.actionRole()==PhoneAction::Decline) {
   550     } else if (pa.actionRole()==PhoneAction::Decline) {
   526         action.setSoftKeyRole(QAction::NegativeSoftKey);
   551         action.setSoftKeyRole(QAction::NegativeSoftKey);
   527     }
   552     }
   528 }
   553 }
   529 
   554 
   530 void PhoneUIQtView::createToolBarActions()
   555 void PhoneUIQtView::createToolBarActions()
   531 {
   556 {
       
   557     PHONE_TRACE
   532     for (int i=0;i<4;++i) {
   558     for (int i=0;i<4;++i) {
   533         HbAction* action = new HbAction();
   559         HbAction* action = new HbAction();
   534         connect(action, SIGNAL(triggered()), m_signalMapper, SLOT(map()));
   560         connect(action, SIGNAL(triggered()), m_signalMapper, SLOT(map()));
   535         m_toolbarActions.append(action);
   561         m_toolbarActions.append(action);
   536     }
   562     }
   537 }
   563 }
   538 
   564 
       
   565 void PhoneUIQtView::updateMenuVisibility()
       
   566 {
       
   567     PHONE_TRACE
       
   568     bool visible = false;
       
   569     HbView* view = m_window.currentView();
       
   570     HbMenu* optionsMenu = m_optionsMenu ? m_optionsMenu : menu();
       
   571     foreach( QAction* action, optionsMenu->actions()){
       
   572         if(action->isVisible()){
       
   573             visible = true;
       
   574             break;
       
   575         }
       
   576     }
       
   577     PHONE_DEBUG2("PhoneUIQtView::updateMenuVisibility -  visible", visible);
       
   578     if (!visible && !m_optionsMenu) {
       
   579         PHONE_DEBUG("PhoneUIQtView::updateMenuVisibility - takeMenu");
       
   580         //takeMenu() - Removes the menu from the view and returns it to the caller.
       
   581         //ownership of the menu is transfered.        
       
   582         m_optionsMenu = view->takeMenu();
       
   583         
       
   584     } else if (visible && m_optionsMenu) {
       
   585         // ownership of the menu is transfered
       
   586         view->setMenu(m_optionsMenu);
       
   587         m_optionsMenu = 0;
       
   588     }
       
   589 }
       
   590 
   539 void PhoneUIQtView::shutdownPhoneApp()
   591 void PhoneUIQtView::shutdownPhoneApp()
   540 {
   592 {
   541     PHONE_DEBUG("PhoneUIQtView::shutdownPhoneApp");
   593     PHONE_DEBUG("PhoneUIQtView::shutdownPhoneApp");
   542     QCoreApplication::quit();
   594     QCoreApplication::quit();
   543 }
   595 }
   549     }
   601     }
   550 }
   602 }
   551 
   603 
   552 void PhoneUIQtView::setRestrictedMode(bool restrictedMode)
   604 void PhoneUIQtView::setRestrictedMode(bool restrictedMode)
   553 {
   605 {
       
   606     PHONE_TRACE
   554     m_restrictedMode = restrictedMode;
   607     m_restrictedMode = restrictedMode;
   555     m_backAction->setEnabled(!restrictedMode);
   608     m_backAction->setEnabled(!restrictedMode);
   556     m_dialpad->setCallButtonEnabled(false);
   609     m_dialpad->setCallButtonEnabled(false);
   557     m_dialpad->editor().setText(""); // Clead dialpad
   610     m_dialpad->editor().setText(""); // Clead dialpad
   558     if (m_restrictedMode) {
   611     if (m_restrictedMode) {