phoneuis/bubblemanager2/bubblecore/src/bubbleconferencehandler.cpp
branchRCL_3
changeset 61 41a7f70b3818
equal deleted inserted replaced
58:40a3f856b14d 61:41a7f70b3818
       
     1 /*!
       
     2 * Copyright (c) 2009 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:  Conference call bubble handler.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QTimer>
       
    19 
       
    20 #include <hbaction.h>
       
    21 #include <hbtextitem.h>
       
    22 #include <hblabel.h>
       
    23 #include <hblistview.h>
       
    24 
       
    25 #include "bubblemanager2.h"
       
    26 #include "bubbleconferencehandler.h"
       
    27 #include "bubbleconferenceheader.h"
       
    28 #include "bubbleutils.h"
       
    29 #include "bubbleparticipantlistitem.h"
       
    30 #include "bubbleparticipantlistmodel.h"
       
    31 #include "bubblebutton.h"
       
    32 #include "bubbleheadingwidget.h"
       
    33 
       
    34 static const int BUBBLE_SELECTION_TIMEOUT = 3000;
       
    35 
       
    36 BubbleConferenceHandler::BubbleConferenceHandler(
       
    37     BubbleWidgetManager& widgetManager,
       
    38     BubbleWidgetManager::View view,
       
    39     BubbleWidgetManager::Container container,
       
    40     QObject* parent )
       
    41     : BubbleHandler(widgetManager,view,container,parent)
       
    42 {
       
    43     mHeading =
       
    44         qobject_cast<BubbleHeadingWidget*>(widget(BubbleWidgetManager::Heading));
       
    45     Q_ASSERT(mHeading);
       
    46 
       
    47     mButtonCenter =
       
    48         qobject_cast<BubbleButton*>(widget(BubbleWidgetManager::CenterButton));
       
    49     Q_ASSERT(mButtonCenter);
       
    50     mButtonLeft =
       
    51         qobject_cast<BubbleButton*>(widget(BubbleWidgetManager::LeftButton));
       
    52     Q_ASSERT(mButtonLeft);
       
    53     mButtonRight =
       
    54         qobject_cast<BubbleButton*>(widget(BubbleWidgetManager::RightButton));
       
    55     Q_ASSERT(mButtonRight);
       
    56 
       
    57     mList =
       
    58         qobject_cast<HbListView*>(widget(BubbleWidgetManager::ParticipantList));
       
    59     Q_ASSERT(mList);
       
    60     mModel = new BubbleParticipantListModel();
       
    61     mList->setModel(mModel);
       
    62     
       
    63     HbAbstractItemView::ItemAnimations noCreationAndRemovalAnimations = HbAbstractItemView::All;
       
    64     noCreationAndRemovalAnimations ^= HbAbstractItemView::Appear;
       
    65     noCreationAndRemovalAnimations ^= HbAbstractItemView::Disappear;
       
    66     mList->setEnabledAnimations(noCreationAndRemovalAnimations);
       
    67 
       
    68     mPrototype =
       
    69         qobject_cast<BubbleParticipantListItem*>(
       
    70             widgetManager.createParticipantListItem());
       
    71     Q_ASSERT(mPrototype);
       
    72     mList->setItemPrototype(mPrototype);
       
    73     connect(mList->selectionModel(),
       
    74             SIGNAL(currentChanged(QModelIndex,QModelIndex)),
       
    75             this,
       
    76             SLOT(handleItemSelected(QModelIndex,QModelIndex)));
       
    77 
       
    78     mSelectionTimer = new QTimer(this);
       
    79     connect(mSelectionTimer,SIGNAL(timeout()),SLOT(clearSelection()));
       
    80     mSelectionTimer->setSingleShot(true);
       
    81 
       
    82     reset();
       
    83 }
       
    84 
       
    85 BubbleConferenceHandler::~BubbleConferenceHandler()
       
    86 {
       
    87 }
       
    88 
       
    89 void BubbleConferenceHandler::reset()
       
    90 {  
       
    91     mHeader = 0;
       
    92 
       
    93     mSelectionTimer->stop();
       
    94     mPrototype->clearActions();
       
    95     mHeading->reset();
       
    96     mButtonCenter->hide();
       
    97     mButtonCenter->setDown(false);
       
    98     mButtonCenter->disconnect();
       
    99     mButtonLeft->hide();
       
   100     mButtonLeft->setDown(false);
       
   101     mButtonLeft->disconnect();
       
   102     mButtonRight->hide();
       
   103     mButtonRight->setDown(false);
       
   104     mButtonRight->disconnect();
       
   105 }
       
   106 
       
   107 void BubbleConferenceHandler::readBubbleHeader( const BubbleHeader& header )
       
   108 {
       
   109     Q_ASSERT(header.isConference());
       
   110     mHeader = static_cast<const BubbleConferenceHeader*>(&header);
       
   111 
       
   112     // set actions to item prototype
       
   113     QList<HbAbstractViewItem*> prototypes = mList->itemPrototypes();
       
   114     QList<HbAction*> actions = mHeader->participantListActions();
       
   115     foreach (HbAction* action, actions ) {
       
   116         mPrototype->addAction(action);
       
   117     }
       
   118 
       
   119     // populate participant list model
       
   120     QList<BubbleHeader*> participants = mHeader->headers();
       
   121     foreach(BubbleHeader* participant, participants) {
       
   122          mModel->addParticipant(
       
   123             participant->bubbleId(),
       
   124             participant->cli(),
       
   125             participant->cliClipDirection());
       
   126     }
       
   127 
       
   128     mHeading->readBubbleHeader(header);
       
   129 
       
   130     setButtons(mHeader->actions());
       
   131 
       
   132     clearSelection();
       
   133 }
       
   134 
       
   135 void BubbleConferenceHandler::setButtons(const QList<HbAction*>& actions)
       
   136 {
       
   137     if ( actions.count()==1 && mButtonCenter ) {
       
   138         HbAction* action = actions.at(0);
       
   139         mButtonCenter->setIcon( action->icon() );
       
   140         BubbleUtils::setButtonStyleForAction(*mButtonCenter,*action);
       
   141         connect(mButtonCenter, SIGNAL( clicked() ),
       
   142                 action, SLOT( trigger() ) );
       
   143         connect(mButtonCenter, SIGNAL( longPress(QPointF)),
       
   144                 action, SLOT( trigger() ) );
       
   145         mButtonCenter->show();
       
   146     } else  if (actions.count()==2 && mButtonLeft && mButtonRight ) {
       
   147         // Left button
       
   148         HbAction* action1 = actions.at(0);
       
   149         mButtonLeft->setIcon( action1->icon() );
       
   150         BubbleUtils::setButtonStyleForAction(*mButtonLeft,*action1);
       
   151         connect( mButtonLeft, SIGNAL( clicked() ),
       
   152                  action1, SLOT( trigger() ) );
       
   153         connect(mButtonLeft, SIGNAL( longPress(QPointF)),
       
   154                 action1, SLOT( trigger() ) );
       
   155         mButtonLeft->show();
       
   156         // Right button
       
   157         HbAction* action2 = actions.at(1);
       
   158         mButtonRight->setIcon( action2->icon() );
       
   159         BubbleUtils::setButtonStyleForAction(*mButtonRight,*action2);
       
   160         connect( mButtonRight, SIGNAL( clicked() ),
       
   161                  action2, SLOT( trigger() ) );
       
   162         connect(mButtonRight, SIGNAL( longPress(QPointF)),
       
   163                 action2, SLOT( trigger() ) );
       
   164         mButtonRight->show();
       
   165     }
       
   166 }
       
   167 
       
   168 QGraphicsWidget* BubbleConferenceHandler::graphicsWidgetForAction(
       
   169     HbAction* action ) const
       
   170 {
       
   171     if ( mButtonLeft->text() == action->text() ) {
       
   172         return mButtonLeft;
       
   173     } else if ( mButtonRight->text() == action->text() ) {
       
   174         return mButtonRight;
       
   175     } else if ( mButtonCenter->text() == action->text() ) {
       
   176         return mButtonCenter;
       
   177     } else {
       
   178         return 0;
       
   179     }
       
   180 }
       
   181 
       
   182 void BubbleConferenceHandler::updateTimerDisplayNow()
       
   183 {
       
   184     mHeading->updateTimerDisplayNow();
       
   185 }
       
   186 
       
   187 void BubbleConferenceHandler::handleItemSelected(
       
   188     const QModelIndex & current,
       
   189     const QModelIndex & previous )
       
   190 {
       
   191     Q_UNUSED(previous);
       
   192 
       
   193     if (current.isValid()) {
       
   194         Q_ASSERT( mHeader != 0 );
       
   195         // need to cast constness away
       
   196         BubbleConferenceHeader& mutableHeader =
       
   197             const_cast<BubbleConferenceHeader&>(*mHeader);
       
   198         mutableHeader.setSelectedHeader(mModel->bubbleId(current.row()));
       
   199         mSelectionTimer->stop();
       
   200         mSelectionTimer->start(BUBBLE_SELECTION_TIMEOUT);
       
   201     }
       
   202 }
       
   203 
       
   204 void BubbleConferenceHandler::clearSelection()
       
   205 {
       
   206     mList->selectionModel()->clear();
       
   207 }
       
   208 
       
   209 void BubbleConferenceHandler::conferenceMemberRemoved(int bubbleId)
       
   210 {
       
   211     mModel->removeParticipant(bubbleId);
       
   212 }
       
   213 
       
   214 void BubbleConferenceHandler::conferenceRemoved()
       
   215 {
       
   216     mModel->reset();
       
   217     mList->reset();
       
   218 }