phoneuis/bubblemanager2/tsrc/bubbletest2/bubbletestview.cpp
changeset 21 92ab7f8d0eab
child 22 6bb1b21d2484
equal deleted inserted replaced
4:c84cf270c54f 21:92ab7f8d0eab
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtGui>
       
    19 #include <QDebug>
       
    20 #include <hbaction.h>
       
    21 #include <hbtoolbar.h>
       
    22 #include <bubblemanager2.h>
       
    23 #include <hbmenu.h>
       
    24 #include <hbmainwindow.h>
       
    25 
       
    26 #include "bubbletestview.h"
       
    27 #include "bubbletester.h"
       
    28 
       
    29 BubbleTestView::BubbleTestView(HbMainWindow& window, QGraphicsItem *parent) :
       
    30     HbView (parent), mMainWindow(window), mMuted(0), mConfBubbleId(-1),
       
    31     mProvideJoin(false)
       
    32 {
       
    33     setFlags (QGraphicsItem::ItemIsFocusable);
       
    34     setFocusPolicy (Qt::StrongFocus);
       
    35     setTitle("BubbleTest2");
       
    36     
       
    37     // the widget under the test
       
    38     mBubbleManager = new BubbleManager (this);
       
    39     setWidget(mBubbleManager);
       
    40 
       
    41     // init toolbar
       
    42     createToolBarActions();
       
    43     //toolBar()->setOrientation(mMainWindow.orientation());
       
    44     connect( &mMainWindow,SIGNAL(orientationChanged(Qt::Orientation)),
       
    45              this,SLOT(handleOrientationChange(Qt::Orientation)));
       
    46     
       
    47     // init menu
       
    48     createMenuActions();
       
    49 
       
    50     // create actions for push buttons
       
    51     createBubbleActions();
       
    52 
       
    53     // tester
       
    54     mBubbleTester = new BubbleTester();
       
    55     connect(mBubbleTester,SIGNAL(dataChanged()),this,SLOT(handleTesterDataChanged()));
       
    56     mBubbleTester->connectToServer();
       
    57 
       
    58     // create state map
       
    59     mStateMap.insert("Idle", BubbleManagerIF::None );
       
    60     mStateMap.insert("Incoming", BubbleManagerIF::Incoming );
       
    61     mStateMap.insert("Active", BubbleManagerIF::Active );
       
    62     mStateMap.insert("Disconnected", BubbleManagerIF::Disconnected );
       
    63     mStateMap.insert("Outgoing", BubbleManagerIF::Outgoing );
       
    64     mStateMap.insert("Waiting", BubbleManagerIF::Waiting );
       
    65     mStateMap.insert("OnHold", BubbleManagerIF::OnHold );
       
    66     // create label map
       
    67     mLabelMap.insert("Idle", "" );
       
    68     mLabelMap.insert("Incoming", "calling" );
       
    69     mLabelMap.insert("Active", "" );
       
    70     mLabelMap.insert("Disconnected", "disconnected" );
       
    71     mLabelMap.insert("Outgoing", "Calling" );
       
    72     mLabelMap.insert("Waiting", "waiting" );
       
    73     mLabelMap.insert("OnHold", "on hold" );
       
    74 }
       
    75 
       
    76 BubbleTestView::~BubbleTestView()
       
    77 {
       
    78     delete mBubbleTester;
       
    79 }
       
    80 
       
    81 void BubbleTestView::keyPressEvent(QKeyEvent *event)
       
    82 {
       
    83     switch( event->key() )
       
    84     {
       
    85     case '1': // create incoming call
       
    86     {
       
    87         if ( mEmergencyCall->isChecked() ) {
       
    88             return; // not supported
       
    89         }
       
    90 
       
    91         if ( mCalls.count() == 0 ) {
       
    92             bubbleManager().startChanges();
       
    93             int bubbleId = bubbleManager().createCallHeader();
       
    94             setBubbleData(bubbleId, BubbleManager::Incoming);
       
    95             setBubbleActions(bubbleId, BubbleManager::Incoming);
       
    96             bubbleManager().endChanges();
       
    97             
       
    98             // store this call
       
    99             TestCall call;
       
   100             call.bubbleId = bubbleId;
       
   101             call.callState = BubbleManager::Incoming;
       
   102             mCalls.append( call );
       
   103 
       
   104             updateToolBarActions();
       
   105 
       
   106         } else if ( !initializingCallExists() ) {
       
   107             // waiting call
       
   108             bubbleManager().startChanges();
       
   109             int bubbleId = bubbleManager().createCallHeader();
       
   110             setBubbleData(bubbleId, BubbleManager::Waiting);
       
   111             setBubbleActions( bubbleId, BubbleManager::Waiting );
       
   112             bubbleManager().setExpandedConferenceCallHeader(false);
       
   113             bubbleManager().endChanges();
       
   114 
       
   115             // store this call
       
   116             TestCall call;
       
   117             call.bubbleId = bubbleId;
       
   118             call.callState = BubbleManager::Waiting;
       
   119             mCalls.append( call );
       
   120 
       
   121             setExpandActions();
       
   122             updateToolBarActions();
       
   123         }
       
   124         break;
       
   125     }
       
   126     
       
   127     case '2': // create outgoing call
       
   128     {
       
   129         if ( !initializingCallExists() && (callCount()<3) ) {
       
   130             bubbleManager().startChanges();
       
   131             int bubbleId = bubbleManager().createCallHeader();
       
   132             setBubbleData(bubbleId, BubbleManager::Outgoing);
       
   133             setBubbleActions( bubbleId, BubbleManager::Outgoing );
       
   134             bubbleManager().endChanges();
       
   135 
       
   136             // store this call
       
   137             TestCall call;
       
   138             call.bubbleId = bubbleId;
       
   139             call.callState = BubbleManager::Outgoing;
       
   140             mCalls.append( call );
       
   141 
       
   142             bubbleManager().setBubbleSelectionDisabled(true);
       
   143             updateToolBarActions();
       
   144        }
       
   145        break;
       
   146     }
       
   147     
       
   148     case '3': // connect
       
   149     {
       
   150         int i,j;
       
   151 
       
   152         if (callIndexByState(BubbleManagerIF::Outgoing, i)) {
       
   153             // outgoing to alerting
       
   154             bubbleManager().startChanges();
       
   155             setBubbleData(mCalls[i].bubbleId, BubbleManager::Alerting);
       
   156             bubbleManager().endChanges();
       
   157             mCalls[i].callState = BubbleManager::Alerting;
       
   158             return;
       
   159         }
       
   160 
       
   161         if (callCount()==3) {
       
   162             // replace active call
       
   163             bubbleManager().startChanges();
       
   164             Q_ASSERT(callIndexByState(BubbleManagerIF::Active, j));
       
   165             bubbleManager().removeCallHeader(mCalls[j].bubbleId);
       
   166             mCalls.removeAt(j);
       
   167             Q_ASSERT(callIndexByState(BubbleManagerIF::Waiting, i));
       
   168             setBubbleData(mCalls[i].bubbleId, BubbleManager::Active);
       
   169             setBubbleActions(mCalls[i].bubbleId, BubbleManager::Active);
       
   170             bubbleManager().endChanges();
       
   171             mCalls[i].callState = BubbleManager::Active;
       
   172             setExpandActions();
       
   173             updateToolBarActions();
       
   174             bubbleManager().setBubbleSelectionDisabled(false);
       
   175         } else if (callIndexByState(BubbleManagerIF::Incoming, i)||
       
   176                    callIndexByState(BubbleManagerIF::Alerting, i)||
       
   177                    callIndexByState(BubbleManagerIF::Waiting, i)) {
       
   178             bubbleManager().startChanges();
       
   179             setBubbleData(mCalls[i].bubbleId, BubbleManager::Active);
       
   180             mProvideJoin = true; // bit hackish
       
   181             setBubbleActions(mCalls[i].bubbleId, BubbleManager::Active);
       
   182             mProvideJoin = false;
       
   183             if (callIndexByState(BubbleManagerIF::Active, j)) {
       
   184                 setBubbleData(mCalls[j].bubbleId, BubbleManager::OnHold);
       
   185                 setBubbleActions(mCalls[j].bubbleId, BubbleManager::OnHold);
       
   186                 mCalls[j].callState = BubbleManager::OnHold;
       
   187             }
       
   188             bubbleManager().endChanges();
       
   189             mCalls[i].callState = BubbleManager::Active;
       
   190             setExpandActions();
       
   191             updateToolBarActions();
       
   192             bubbleManager().setBubbleSelectionDisabled(false);
       
   193         }
       
   194         break;
       
   195     }
       
   196 
       
   197     case '4': // hold
       
   198     {
       
   199         int i,j;
       
   200 
       
   201         if (callCount()==1) {
       
   202             // toggle hold
       
   203             bubbleManager().startChanges();
       
   204             if (callIndexByState(BubbleManagerIF::Active, i)||
       
   205                 callIndexByState(BubbleManagerIF::OnHold, i)) {
       
   206                 BubbleManagerIF::PhoneCallState state =
       
   207                     mCalls[i].callState == BubbleManagerIF::Active ?
       
   208                     BubbleManagerIF::OnHold : BubbleManagerIF::Active;
       
   209 
       
   210                 setBubbleData(mCalls[i].bubbleId, state);
       
   211                 setBubbleActions(mCalls[i].bubbleId, state );
       
   212                 mCalls[i].callState=state;
       
   213             }
       
   214             bubbleManager().endChanges();
       
   215             updateToolBarActions();
       
   216         } else if (callIndexByState(BubbleManagerIF::Active, i)) {
       
   217             // swap calls
       
   218             bubbleManager().startChanges();
       
   219             if (callIndexByState(BubbleManagerIF::OnHold, j)) {
       
   220                 setBubbleData(mCalls[j].bubbleId, BubbleManager::Active);
       
   221                 setBubbleActions(mCalls[j].bubbleId, BubbleManager::Active );
       
   222                 mCalls[j].callState=BubbleManager::Active;
       
   223             }
       
   224             setBubbleData(mCalls[i].bubbleId, BubbleManager::OnHold);
       
   225             setBubbleActions(mCalls[i].bubbleId, BubbleManager::OnHold );
       
   226             mCalls[i].callState=BubbleManager::OnHold;
       
   227             if (conferenceCallExists()) {
       
   228                 bubbleManager().setExpandedConferenceCallHeader(
       
   229                     bubbleIdByState(BubbleManager::Active)==mConfBubbleId);
       
   230             }
       
   231             bubbleManager().endChanges();
       
   232             setExpandActions();
       
   233             updateToolBarActions();
       
   234         } else if (callIndexByState(BubbleManagerIF::Waiting, i)) {
       
   235             // activate held call
       
   236             bubbleManager().startChanges();
       
   237             if (callIndexByState(BubbleManagerIF::OnHold, j)) {
       
   238                 setBubbleData(mCalls[j].bubbleId, BubbleManager::Active);
       
   239                 setBubbleActions(mCalls[j].bubbleId, BubbleManager::Active );
       
   240                 mCalls[j].callState=BubbleManager::Active;
       
   241             }
       
   242             bubbleManager().endChanges();
       
   243             setExpandActions();
       
   244             updateToolBarActions();
       
   245         }
       
   246         break;
       
   247     }
       
   248     
       
   249     case '5': // disconnect
       
   250     {
       
   251         int i,j;
       
   252 
       
   253         if (callIndexByState(BubbleManagerIF::Disconnected, i)) {
       
   254             bubbleManager().startChanges();
       
   255             bubbleManager().removeCallHeader(mCalls[i].bubbleId);
       
   256             // remove call
       
   257             mCalls.removeAt(i);
       
   258 
       
   259             if (mMuted) {
       
   260                 setMuted(); // unmute
       
   261             }
       
   262 
       
   263             bool expand = true;
       
   264             QListIterator<TestCall> calls(mCalls);
       
   265             while(calls.hasNext()) {
       
   266                 TestCall call = calls.next();
       
   267                   if (!call.isConf && !call.isInConf) {
       
   268                       expand = false;
       
   269                   }
       
   270             }
       
   271             bubbleManager().setExpandedConferenceCallHeader(expand);
       
   272             bubbleManager().endChanges();
       
   273 
       
   274             updateToolBarActions();
       
   275             return;
       
   276         }
       
   277 
       
   278         if (callCount()) {
       
   279             int expanded = bubbleManager().expandedBubble();
       
   280             callIndexByBubbleId(expanded,i);
       
   281             bubbleManager().startChanges();
       
   282 
       
   283             if (mCalls.at(i).isConf) {
       
   284                 bubbleManager().removeConference();
       
   285                 mConfBubbleId = -1;
       
   286                 mCalls.removeAt(i);
       
   287 
       
   288                 QMutableListIterator<TestCall> calls(mCalls);
       
   289                 j=0;
       
   290                 while(calls.hasNext()) {                  
       
   291                     if (mCalls[j].isInConf) {
       
   292                         bubbleManager().removeCallHeader(mCalls[j].bubbleId);
       
   293                         mCalls.removeAt(j);
       
   294                     } else {
       
   295                         j++;
       
   296                     }
       
   297                     calls.next();
       
   298                 }
       
   299             } else {
       
   300                 setBubbleData(mCalls[i].bubbleId, BubbleManager::Disconnected);
       
   301                 setBubbleActions(mCalls[i].bubbleId, BubbleManager::Disconnected);
       
   302                 mCalls[i].callState=BubbleManager::Disconnected;
       
   303             }
       
   304             bubbleManager().endChanges();
       
   305             updateToolBarActions();
       
   306         }
       
   307         break;
       
   308     }
       
   309     
       
   310     case '7': // create/join conference
       
   311     {
       
   312         int activeCallId = bubbleIdByState(BubbleManagerIF::Active);
       
   313         int heldCallId = bubbleIdByState(BubbleManagerIF::OnHold);
       
   314         int i;
       
   315 
       
   316         if (conferenceCallExists()&&(activeCallId!=-1)) {
       
   317             callIndexByBubbleId(activeCallId,i);
       
   318             mCalls[i].isInConf = true;
       
   319             bubbleManager().startChanges();
       
   320             bubbleManager().addRowToConference(activeCallId);
       
   321             bubbleManager().setExpandedConferenceCallHeader(true);
       
   322             bubbleManager().setState(mConfBubbleId,BubbleManagerIF::Active);
       
   323             setBubbleActions(mConfBubbleId,BubbleManagerIF::Active);
       
   324             bubbleManager().endChanges();            
       
   325         } else if (activeCallId!=-1 && heldCallId!=-1) {
       
   326             bubbleManager().startChanges();
       
   327             mConfBubbleId = bubbleManager().createConference(heldCallId, activeCallId);
       
   328             bubbleManager().setExpandedConferenceCallHeader(true);
       
   329             bubbleManager().setState(mConfBubbleId,BubbleManagerIF::Active);
       
   330             bubbleManager().setCli(mConfBubbleId,"Conference call",Qt::ElideRight);
       
   331             if (mCallTimer->isChecked()) {
       
   332                 bubbleManager().setCallTime( mConfBubbleId, "0:00" );
       
   333             }
       
   334             bubbleManager().addAction(mConfBubbleId, mEndConference);
       
   335             bubbleManager().clearParticipantListActions();
       
   336             bubbleManager().addParticipantListAction(mPrivate);
       
   337             bubbleManager().addParticipantListAction(mDrop);
       
   338             bubbleManager().setState(heldCallId,BubbleManagerIF::Active);
       
   339             bubbleManager().endChanges();
       
   340 
       
   341             callIndexByBubbleId(activeCallId,i);
       
   342             mCalls[i].isInConf = true;
       
   343             callIndexByBubbleId(heldCallId,i);
       
   344             mCalls[i].isInConf = true;
       
   345 
       
   346             // store the call
       
   347             TestCall call;
       
   348             call.bubbleId = mConfBubbleId;
       
   349             call.callState = BubbleManagerIF::Active;
       
   350             call.isConf = true;
       
   351             call.isInConf = false;
       
   352             mCalls.append(call);
       
   353         }
       
   354         break;
       
   355     }
       
   356 
       
   357     case '9': // conference shortcut
       
   358     {
       
   359         conferenceWizard();
       
   360         break;
       
   361     }
       
   362 
       
   363     case '0': // updates
       
   364     case Qt::Key_Space: // updates
       
   365     {
       
   366         if (mCallTimer->isChecked()) {
       
   367             foreach (TestCall call, mCalls) {
       
   368                 if ( call.callState == BubbleManager::Active ||
       
   369                      call.callState == BubbleManager::OnHold ) {
       
   370                     bubbleManager().updateCallTime(call.bubbleId,"0:01");
       
   371                 }
       
   372             }
       
   373         }
       
   374     }
       
   375     
       
   376     default:
       
   377     break;
       
   378     }
       
   379 }
       
   380 
       
   381 bool BubbleTestView::initializingCallExists() const
       
   382 {
       
   383     bool result = false;
       
   384     foreach(TestCall call, mCalls) {
       
   385         if (call.callState>=BubbleManagerIF::Incoming) {
       
   386             result = true;
       
   387             break;
       
   388         }
       
   389     }
       
   390 
       
   391     return result;
       
   392 }
       
   393 
       
   394 bool BubbleTestView::conferenceCallExists() const
       
   395 {
       
   396     bool result = false;
       
   397     QListIterator<TestCall> i(mCalls);
       
   398     while (i.hasNext()) {
       
   399         if (i.next().isConf) {
       
   400             result = true;
       
   401             break;
       
   402         }
       
   403     }
       
   404     return result;
       
   405 }
       
   406 
       
   407 int BubbleTestView::callCount() const
       
   408 {
       
   409     int count = 0;
       
   410     foreach(TestCall call, mCalls) {
       
   411         if (!call.isInConf) {
       
   412             count++;
       
   413         }
       
   414     }
       
   415 
       
   416     return count;
       
   417 }
       
   418 
       
   419 bool BubbleTestView::callIndexByState(
       
   420     BubbleManagerIF::PhoneCallState state, int& index)
       
   421 {
       
   422     bool result = false;
       
   423     int i = 0;
       
   424     foreach(TestCall call, mCalls) {
       
   425         if (call.callState==state && !call.isInConf) {
       
   426             result = true;
       
   427             index = i;
       
   428             break;
       
   429         }
       
   430         i++;
       
   431     }
       
   432 
       
   433     return result;
       
   434 }
       
   435 
       
   436 bool BubbleTestView::callIndexByBubbleId(int bubbleId, int& index)
       
   437 {
       
   438     bool result = false;
       
   439     int i = 0;
       
   440     foreach(TestCall call, mCalls) {
       
   441         if (call.bubbleId==bubbleId) {
       
   442             result = true;
       
   443             index = i;
       
   444             break;
       
   445         }
       
   446         i++;
       
   447     }
       
   448 
       
   449     return result;
       
   450 }
       
   451 
       
   452 BubbleManagerIF& BubbleTestView::bubbleManager()
       
   453 {
       
   454     return *mBubbleManager;
       
   455 }
       
   456 
       
   457 void BubbleTestView::setBubbleData(int bubble, BubbleManagerIF::PhoneCallState state)
       
   458 {
       
   459     bubbleManager().setState(bubble, state);
       
   460 
       
   461     switch (state) {
       
   462     case BubbleManager::Incoming:
       
   463         {
       
   464         if ( mContactName->isChecked() ) {
       
   465             bubbleManager().setCli(bubble, "Gloria Andersson", Qt::ElideRight);
       
   466             bubbleManager().setSecondaryCli( bubble, "+35850123456789" );
       
   467             mPhoneNumber.clear();
       
   468         } else {
       
   469             mPhoneNumber.append("+35850123456789");
       
   470             bubbleManager().setCli(bubble, mPhoneNumber, Qt::ElideRight);
       
   471         }
       
   472 
       
   473         setCallObject(bubble, ":resources/contactpic.jpg");
       
   474         bubbleManager().setNumberType(bubble, BubbleManager::Mobile);
       
   475         bubbleManager().setCallFlag(bubble, BubbleManager::Diverted, mCallDivert->isChecked());
       
   476         bubbleManager().setLabel(bubble, "calling", Qt::ElideRight);
       
   477         break;
       
   478         }
       
   479 
       
   480     case BubbleManager::Waiting:
       
   481         {
       
   482         if ( mContactName->isChecked() ) {
       
   483             if (callCount()==2) {
       
   484                 bubbleManager().setCli(bubble, "Mary Poppins", Qt::ElideRight);
       
   485                 bubbleManager().setSecondaryCli(bubble, "+35840987654321");
       
   486             } else {
       
   487                 bubbleManager().setCli(bubble, "John Doe", Qt::ElideRight);
       
   488                 bubbleManager().setSecondaryCli(bubble, "+35840987654321");
       
   489             }
       
   490             mPhoneNumber.clear();
       
   491         } else {
       
   492             if (callCount()==2) {
       
   493                 mPhoneNumber.append("+35850232323232");
       
   494             } else {
       
   495                 mPhoneNumber.append("+35840987654321");
       
   496             }
       
   497             bubbleManager().setCli(bubble, mPhoneNumber, Qt::ElideRight);
       
   498         }
       
   499         setCallObject(bubble, ":resources/contactpic3.png");
       
   500         bubbleManager().setNumberType(bubble, BubbleManager::Mobile);
       
   501         bubbleManager().setCallFlag(bubble, BubbleManager::Diverted, mCallDivert->isChecked());
       
   502         bubbleManager().setLabel(bubble, "waiting", Qt::ElideRight);
       
   503         break;
       
   504         }
       
   505 
       
   506     case BubbleManager::Outgoing:
       
   507         {
       
   508         if (mEmergencyCall->isChecked()) {
       
   509             bubbleManager().setCli( bubble, "emergency call", Qt::ElideRight );
       
   510             bubbleManager().setLabel( bubble, "Attempting", Qt::ElideRight );
       
   511         } else {
       
   512             if ( mContactName->isChecked() ) {
       
   513                 bubbleManager().setCli( bubble, "Bart Simpson", Qt::ElideRight );
       
   514                 bubbleManager().setSecondaryCli( bubble, "+35890987654321" );
       
   515                 mPhoneNumber.clear();
       
   516             } else {
       
   517                 mPhoneNumber.append("+35890987654321");
       
   518                 bubbleManager().setCli( bubble, mPhoneNumber, Qt::ElideRight );
       
   519             }
       
   520             setCallObject(bubble, ":resources/contactpic2.jpg");
       
   521             bubbleManager().setLabel( bubble, "Calling", Qt::ElideRight );
       
   522         }
       
   523         break;
       
   524         }
       
   525 
       
   526     case BubbleManager::Alerting:
       
   527         {
       
   528         if ( mPhoneNumber.length() ) {
       
   529             QString cli("Call %1");
       
   530             QString index;
       
   531             index.setNum(bubble+1);
       
   532             cli = cli.arg(index);
       
   533             bubbleManager().setCli( bubble, cli, Qt::ElideRight );
       
   534             bubbleManager().setSecondaryCli( bubble, mPhoneNumber );
       
   535             mPhoneNumber.clear();
       
   536         }
       
   537 
       
   538         if ( mEmergencyCall->isChecked() ) {
       
   539             bubbleManager().setCli( bubble, "Emergency call", Qt::ElideRight );
       
   540         }
       
   541         break;
       
   542         }
       
   543 
       
   544     case BubbleManager::Active:
       
   545         {
       
   546         if ( mPhoneNumber.length() && bubble!=mConfBubbleId ) {
       
   547             QString cli("Call %1");
       
   548             QString index;
       
   549             index.setNum(bubble+1);
       
   550             cli = cli.arg(index);
       
   551             bubbleManager().setCli( bubble, cli, Qt::ElideRight );
       
   552             bubbleManager().setSecondaryCli( bubble, mPhoneNumber );
       
   553             mPhoneNumber.clear();
       
   554         }
       
   555 
       
   556         if ( mCallTimer->isChecked() ) {
       
   557             bubbleManager().setCallTime( bubble, "0:00" );
       
   558         }
       
   559         break;
       
   560         }
       
   561 
       
   562     case BubbleManager::OnHold:
       
   563         {
       
   564         bubbleManager().setLabel( bubble, "on hold", Qt::ElideRight );
       
   565         break;
       
   566         }
       
   567 
       
   568     case BubbleManager::Disconnected:
       
   569         {
       
   570         bubbleManager().setLabel( bubble, "disconnected", Qt::ElideRight );
       
   571         break;
       
   572         }
       
   573 
       
   574     default:
       
   575         {
       
   576         break;
       
   577         }
       
   578     }
       
   579 }
       
   580 
       
   581 void BubbleTestView::setCallObject(int bubble, const QString& filename)
       
   582 {
       
   583     if (mContactPicture->isChecked()) {
       
   584         bubbleManager().setCallObjectImage(bubble, filename);
       
   585     } else {
       
   586         bubbleManager().setCallObjectFromTheme(bubble);
       
   587     }
       
   588 }
       
   589 
       
   590 void BubbleTestView::setBubbleActions(int bubble, BubbleManagerIF::PhoneCallState state )
       
   591 {
       
   592     if (bubble==mConfBubbleId) {
       
   593         // check, if all call are in conference
       
   594         bool swapButton = false;
       
   595         QListIterator<TestCall> calls(mCalls);
       
   596         while(calls.hasNext()) {
       
   597             TestCall call = calls.next();
       
   598             if (!call.isConf && !call.isInConf) {
       
   599                 swapButton = true;
       
   600             }
       
   601         }
       
   602 
       
   603         bubbleManager().clearActions(bubble);
       
   604 
       
   605         if (swapButton) {
       
   606             bubbleManager().addAction(bubble, mSwap);
       
   607         }
       
   608 
       
   609         bubbleManager().addAction(bubble, mEndConference);
       
   610         return;
       
   611     }
       
   612 
       
   613     bubbleManager().clearActions(bubble);
       
   614 
       
   615     switch (state) {
       
   616     case BubbleManager::Incoming:
       
   617     case BubbleManager::Waiting:
       
   618         {
       
   619         if (callCount()==2) {
       
   620             bubbleManager().addAction( bubble, mReplace );
       
   621         } else {
       
   622             bubbleManager().addAction( bubble, mAnswer );
       
   623             bubbleManager().addAction( bubble, mReject );
       
   624         }
       
   625         break;
       
   626         }
       
   627     case BubbleManager::Outgoing:
       
   628     case BubbleManager::Alerting: // flow through
       
   629         {
       
   630         bubbleManager().addAction( bubble, mEndCall );
       
   631         break;
       
   632         }
       
   633     case BubbleManager::OnHold:
       
   634         {
       
   635         bubbleManager().addAction( bubble, mUnhold );
       
   636         bubbleManager().addAction( bubble, mEndCall );
       
   637         }
       
   638         break;
       
   639     default: // Active call
       
   640         {
       
   641         HbAction* action;
       
   642 
       
   643         if (!mEmergencyCall->isChecked()) {
       
   644             int i;
       
   645             if ( (mCalls.count()>1 && !callIndexByState(BubbleManagerIF::Waiting,i))
       
   646                   || (mCalls.count()> 1 && mProvideJoin) ) {
       
   647                 action = mJoin;
       
   648             } else {
       
   649                 action = mHold;
       
   650             }
       
   651 
       
   652             bubbleManager().addAction( bubble, action );
       
   653         }
       
   654                     
       
   655         bubbleManager().addAction( bubble, mEndCall );
       
   656         break;
       
   657         }
       
   658     }
       
   659 }
       
   660 
       
   661 void BubbleTestView::setExpandActions()
       
   662 {
       
   663     if (callCount() >= 2) {
       
   664         int i;
       
   665         int j;
       
   666         int heldBubble = -1;
       
   667         if (callIndexByState(BubbleManagerIF::Active,i) &&
       
   668             callIndexByState(BubbleManagerIF::OnHold,j)) {
       
   669             heldBubble = mCalls[j].bubbleId;
       
   670             bubbleManager().setExpandAction(heldBubble, mSwap);
       
   671         } else if (callIndexByState(BubbleManagerIF::Waiting,i) &&
       
   672                    callIndexByState(BubbleManagerIF::OnHold,j)) {
       
   673             heldBubble = mCalls[j].bubbleId;
       
   674             bubbleManager().setExpandAction(heldBubble, mUnhold);
       
   675         }
       
   676 
       
   677         // for rest set update toolbar action
       
   678         QListIterator<TestCall> calls(mCalls);
       
   679         while (calls.hasNext()) {
       
   680             TestCall call = calls.next();
       
   681             if (!call.isInConf && call.bubbleId!=heldBubble) {
       
   682                 bubbleManager().setExpandAction(call.bubbleId, mUpdateUiControls);
       
   683             }
       
   684         }
       
   685     }
       
   686 }
       
   687 
       
   688 void BubbleTestView::answerCall()
       
   689 {
       
   690     QKeyEvent event( QEvent::KeyPress, '3', 0 );
       
   691     keyPressEvent(&event);
       
   692 }
       
   693 
       
   694 void BubbleTestView::endCall()
       
   695 {
       
   696     QKeyEvent event( QEvent::KeyPress, '5', 0 );
       
   697     keyPressEvent(&event);
       
   698     keyPressEvent(&event);
       
   699 }
       
   700 
       
   701 void BubbleTestView::endConferenceCall()
       
   702 {
       
   703     QKeyEvent event( QEvent::KeyPress, '5', 0 );
       
   704     keyPressEvent(&event);
       
   705 }
       
   706 
       
   707 void BubbleTestView::rejectCall()
       
   708 {
       
   709     QKeyEvent event( QEvent::KeyPress, '5', 0 );
       
   710     keyPressEvent(&event);
       
   711     keyPressEvent(&event);
       
   712 }
       
   713 
       
   714 void BubbleTestView::toggleHold()
       
   715 {
       
   716     if (callCount() > 1) {
       
   717         QTimer::singleShot(1000, this, SLOT(toggleHoldDelayed()));
       
   718     } else {
       
   719         QKeyEvent event( QEvent::KeyPress, '4', 0 );
       
   720         keyPressEvent(&event);
       
   721     }
       
   722 }
       
   723 
       
   724 void BubbleTestView::toggleHoldDelayed()
       
   725 {
       
   726     QKeyEvent event( QEvent::KeyPress, '4', 0 );
       
   727     keyPressEvent(&event);
       
   728 }
       
   729 
       
   730 void BubbleTestView::createIncomingCall()
       
   731 {
       
   732     QKeyEvent event( QEvent::KeyPress, '1', 0 );
       
   733     keyPressEvent(&event);
       
   734     setFocus(); // hack because toolbar steals the focus
       
   735 }
       
   736 
       
   737 void BubbleTestView::createOutgoingCall()
       
   738 {
       
   739     QKeyEvent event( QEvent::KeyPress, '2', 0 );
       
   740     keyPressEvent(&event);
       
   741     setFocus(); // hack because toolbar steals the focus
       
   742 }
       
   743 
       
   744 void BubbleTestView::setMuted()
       
   745 {
       
   746     mMuted = !mMuted;
       
   747     updateToolBarActions();
       
   748     bubbleManager().setPhoneMuted( mMuted );
       
   749     setFocus(); // hack because toolbar steals the focus
       
   750 }
       
   751 
       
   752 void BubbleTestView::joinToConference()
       
   753 {
       
   754     QKeyEvent event( QEvent::KeyPress, '7', 0 );
       
   755     keyPressEvent(&event);
       
   756 }
       
   757 
       
   758 void BubbleTestView::handlePrivate()
       
   759 {
       
   760     int i;
       
   761     qDebug() << "Handle private";
       
   762     int selection = bubbleManager().selectionIdInConference();
       
   763     qDebug() << "bubble:" << selection;
       
   764     bubbleManager().startChanges();
       
   765     if (bubbleManager().conferenceRowCount()>2) {
       
   766         bubbleManager().removeRowFromConference(selection);
       
   767         bubbleManager().setExpandedConferenceCallHeader(false);
       
   768         callIndexByBubbleId(selection,i);
       
   769         mCalls[i].isInConf = false;
       
   770         setBubbleActions(mCalls[i].bubbleId,BubbleManagerIF::Active);
       
   771         setBubbleData(mConfBubbleId,BubbleManagerIF::OnHold);
       
   772         setExpandActions();
       
   773     } else {
       
   774         bubbleManager().removeConference();
       
   775         callIndexByBubbleId(mConfBubbleId,i);
       
   776         mCalls.removeAt(i);
       
   777         mConfBubbleId = -1;
       
   778         callIndexByBubbleId(selection,i);
       
   779         int held = (i==0) ? 1 : 0;
       
   780         setBubbleActions(selection,BubbleManagerIF::Active);
       
   781         setBubbleData(selection,BubbleManagerIF::Active);
       
   782         setBubbleActions(held,BubbleManagerIF::OnHold);
       
   783         setBubbleData(held,BubbleManagerIF::OnHold);
       
   784         mCalls[0].isInConf = false;
       
   785         mCalls[1].isInConf = false;
       
   786         setExpandActions();
       
   787     }
       
   788     bubbleManager().endChanges();
       
   789 }
       
   790 
       
   791 void BubbleTestView::handleDrop()
       
   792 {
       
   793     int i;
       
   794     qDebug() << "Handle drop";
       
   795     int selection = bubbleManager().selectionIdInConference();
       
   796     qDebug() << "bubble:" << selection;
       
   797     bubbleManager().startChanges();
       
   798     if (bubbleManager().conferenceRowCount()>2) {
       
   799         bubbleManager().removeRowFromConference(selection);
       
   800         bubbleManager().removeCallHeader(selection);
       
   801         callIndexByBubbleId(selection,i);
       
   802         mCalls.removeAt(i);
       
   803     } else {
       
   804         bubbleManager().removeConference();
       
   805         callIndexByBubbleId(mConfBubbleId,i);
       
   806         mCalls.removeAt(i);
       
   807         mConfBubbleId = -1;
       
   808         bubbleManager().removeCallHeader(selection);
       
   809         callIndexByBubbleId(selection,i);
       
   810         mCalls.removeAt(i);
       
   811         mCalls[0].isInConf = false;
       
   812         setBubbleActions(mCalls[0].bubbleId,BubbleManagerIF::Active);
       
   813         setExpandActions();
       
   814     }
       
   815     bubbleManager().endChanges();
       
   816 }
       
   817 
       
   818 void BubbleTestView::replaceActiveCall()
       
   819 {
       
   820     QKeyEvent event( QEvent::KeyPress, '3', 0 );
       
   821     keyPressEvent(&event);
       
   822 }
       
   823 
       
   824 void BubbleTestView::updateUiControls()
       
   825 {
       
   826     if (conferenceCallExists()) {
       
   827         bubbleManager().startChanges();
       
   828         bubbleManager().setExpandedConferenceCallHeader(
       
   829             bubbleManager().expandedBubble()==mConfBubbleId );
       
   830         bubbleManager().endChanges();
       
   831     }
       
   832 
       
   833     updateToolBarActions();
       
   834 }
       
   835 
       
   836 void BubbleTestView::createToolBarActions()
       
   837 {
       
   838     mCallIn = new HbAction("Call in", this);
       
   839     connect( mCallIn, SIGNAL(triggered()), this, SLOT(createIncomingCall()), Qt::QueuedConnection );
       
   840 
       
   841     mCallOut = new HbAction("Call out", this);
       
   842     connect( mCallOut, SIGNAL(triggered()), this, SLOT(createOutgoingCall()), Qt::QueuedConnection );
       
   843 
       
   844     mMute = new HbAction(HbIcon(":resources/qtg_large_tb_mute.svg"), "", this);
       
   845     connect( mMute, SIGNAL(triggered()), this, SLOT(setMuted()), Qt::QueuedConnection );
       
   846 
       
   847     mUnmute = new HbAction(HbIcon(":resources/qtg_large_tb_unmute.svg"), "", this);
       
   848     connect( mUnmute, SIGNAL(triggered()), this, SLOT(setMuted()), Qt::QueuedConnection );
       
   849 
       
   850     // not connected to anywhere
       
   851     mActivateLoudspeaker = new HbAction(HbIcon(":resources/qtg_large_tb_loudsp_unmute.svg"), "", this);
       
   852     mActivateHandset = new HbAction(HbIcon(":resources/qtg_large_tb_loudsp_mute.svg"), "", this);
       
   853     mSendMessage = new HbAction(HbIcon(":resources/qtg_large_tb_message.svg"), "", this);
       
   854     mSilence = new HbAction(HbIcon(":resources/qtg_large_tb_silence.svg"), "", this);
       
   855     mOpenDialer = new HbAction(HbIcon(":resources/qtg_large_tb_dialler.svg"), "", this);
       
   856     mOpenContacts = new HbAction(HbIcon(":resources/qtg_large_tb_contacts.svg"), "", this);
       
   857 
       
   858     updateToolBarActions();
       
   859 }
       
   860 
       
   861 void BubbleTestView::createMenuActions()
       
   862 {
       
   863     // HbMenu* typeMenu = menu()->addMenu("Call type"); current submenu layout sucks
       
   864     menu()->addAction("Switch orientation",this,SLOT(switchOrientation()));
       
   865     mCallDivert = menu()->addAction("Diverted call");
       
   866     mCallTimer = menu()->addAction("Call timer");
       
   867     mContactName = menu()->addAction("Contact name");
       
   868     mContactPicture = menu()->addAction("Contact picture");
       
   869     mEmergencyCall = menu()->addAction( "Emergency call" );
       
   870     HbAction* exit = menu()->addAction( "Exit" );
       
   871     mCallDivert->setCheckable(true);
       
   872     mCallTimer->setCheckable(true);
       
   873     mContactPicture->setCheckable(true);
       
   874     mContactName->setCheckable(true);
       
   875     mEmergencyCall->setCheckable(true);
       
   876     connect( exit, SIGNAL(triggered()), qApp, SLOT(quit()) );
       
   877 }
       
   878 
       
   879 void BubbleTestView::updateToolBarActions()
       
   880 {
       
   881     toolBar()->clearActions();
       
   882 
       
   883     if (!mCalls.count()) {
       
   884         toolBar()->addAction(mCallIn);
       
   885         toolBar()->addAction(mCallOut);
       
   886         return;
       
   887     }
       
   888 
       
   889     int bubble = bubbleManager().expandedBubble();
       
   890     int i;
       
   891     callIndexByBubbleId(bubble,i);
       
   892     int state = mCalls[i].callState;
       
   893 
       
   894     if ( state == BubbleManagerIF::Incoming ||
       
   895          state == BubbleManagerIF::Waiting ) {
       
   896         toolBar()->addAction(mSendMessage);
       
   897         toolBar()->addAction(mSilence);
       
   898     } else {
       
   899         toolBar()->addAction(mOpenDialer);
       
   900         if (!mMuted) {
       
   901             toolBar()->addAction(mMute);
       
   902         } else if (mMuted) {
       
   903             toolBar()->addAction(mUnmute);
       
   904         }
       
   905         toolBar()->addAction(mActivateLoudspeaker);
       
   906         toolBar()->addAction(mOpenContacts);
       
   907     }
       
   908 }
       
   909 
       
   910 void BubbleTestView::createBubbleActions()
       
   911 {
       
   912     mAnswer = new HbAction( HbIcon(":resources/qtg_mono_answer_call.svg"),"Answer", this);
       
   913     mAnswer->setSoftKeyRole(QAction::PositiveSoftKey);
       
   914     connect( mAnswer, SIGNAL( triggered() ), this, SLOT( answerCall() ) );
       
   915 
       
   916     mReject= new HbAction( HbIcon(":resources/qtg_mono_reject_call.svg"),"Reject", this);
       
   917     mReject->setSoftKeyRole(QAction::NegativeSoftKey);
       
   918     connect( mReject, SIGNAL( triggered() ), this, SLOT( rejectCall() ) );
       
   919 
       
   920     mHold = new HbAction( HbIcon(":resources/qtg_mono_hold_call.svg"),"Hold", this);
       
   921     connect( mHold, SIGNAL( triggered() ), this, SLOT( toggleHold() ) );
       
   922 
       
   923     mUnhold = new HbAction( HbIcon(":resources/qtg_mono_answer_call.svg"),"Activate", this);
       
   924     connect( mUnhold, SIGNAL( triggered() ), this, SLOT( toggleHold() ) );
       
   925 
       
   926     mSwap = new HbAction( HbIcon(":resources/qtg_mono_hold_call.svg"),"Swap", this);
       
   927     connect( mSwap, SIGNAL( triggered() ), this, SLOT( toggleHold() ) );
       
   928 
       
   929     mEndCall = new HbAction(HbIcon(":resources/qtg_mono_end_call.svg"),"End call", this);
       
   930     mEndCall->setSoftKeyRole(QAction::NegativeSoftKey);
       
   931     connect( mEndCall, SIGNAL( triggered() ), this, SLOT( endCall() ) );
       
   932 
       
   933     mEndConference = new HbAction(HbIcon(":resources/qtg_mono_end_call.svg"),"End conference", this);
       
   934     mEndConference->setSoftKeyRole(QAction::NegativeSoftKey);
       
   935     connect( mEndConference, SIGNAL( triggered() ), this, SLOT( endConferenceCall() ) );
       
   936 
       
   937     mJoin = new HbAction(HbIcon(":resources/qtg_mono_join_call.svg"),"Join", this);
       
   938     connect( mJoin, SIGNAL( triggered() ), this, SLOT(joinToConference()) );
       
   939 
       
   940     mPrivate = new HbAction(HbIcon(":resources/qtg_mono_private_call.svg"),"Private", this);
       
   941     connect( mPrivate, SIGNAL( triggered() ), this, SLOT(handlePrivate()) );
       
   942 
       
   943     mDrop = new HbAction(HbIcon(":resources/qtg_mono_drop_call.svg"),"Drop", this);
       
   944     connect( mDrop, SIGNAL( triggered() ), this, SLOT(handleDrop()) );
       
   945 
       
   946     mReplace = new HbAction(HbIcon(":resources/qtg_mono_replace_call.svg"),"Replace", this);
       
   947     connect( mReplace, SIGNAL( triggered() ), this, SLOT(replaceActiveCall()) );
       
   948 
       
   949     mUpdateUiControls = new HbAction(QString(), this);
       
   950     connect( mUpdateUiControls, SIGNAL(triggered()), this, SLOT(updateUiControls()) );
       
   951 }
       
   952 
       
   953 int BubbleTestView::bubbleIdByState(BubbleManagerIF::PhoneCallState state)
       
   954 {
       
   955     int bubbleId=-1;
       
   956     foreach(TestCall call, mCalls) {
       
   957         if ((call.callState==state) && !call.isInConf) {
       
   958             bubbleId = call.bubbleId;
       
   959             break;
       
   960         }
       
   961     }
       
   962 
       
   963     return bubbleId;
       
   964 }
       
   965 
       
   966 void BubbleTestView::conferenceWizard() {
       
   967     bubbleManager().startChanges();
       
   968 
       
   969     for (int i=0; i<5; i++) {
       
   970         sendKeyEvent('1');
       
   971         sendKeyEvent('3');
       
   972         sendKeyEvent('7');
       
   973     }
       
   974 
       
   975     bubbleManager().endChanges();
       
   976 }
       
   977 
       
   978 void BubbleTestView::sendKeyEvent(int key)
       
   979 {
       
   980     QKeyEvent event( QEvent::KeyPress, key, 0 );
       
   981     keyPressEvent(&event);
       
   982 }
       
   983 
       
   984 void BubbleTestView::switchOrientation()
       
   985 {
       
   986     if (mMainWindow.orientation()==Qt::Vertical) {
       
   987         mMainWindow.setOrientation(Qt::Horizontal);
       
   988 
       
   989     } else {
       
   990         mMainWindow.setOrientation(Qt::Vertical);
       
   991     }
       
   992 }
       
   993 
       
   994 void BubbleTestView::handleOrientationChange(Qt::Orientation orientation)
       
   995 {
       
   996     if (orientation==Qt::Horizontal) {
       
   997         toolBar()->setOrientation(Qt::Horizontal);
       
   998     }
       
   999 
       
  1000     mBubbleManager->handleOrientationChange(orientation);
       
  1001 }
       
  1002 
       
  1003 void BubbleTestView::connectToTester()
       
  1004 {
       
  1005     mBubbleTester->connectToServer();
       
  1006 }
       
  1007 
       
  1008 void BubbleTestView::handleTesterDataChanged()
       
  1009 {
       
  1010     bubbleManager().startChanges();
       
  1011 
       
  1012     QString mute = mBubbleTester->dataField("mute");
       
  1013     bubbleManager().setPhoneMuted( mute == "On" );
       
  1014 
       
  1015     QList<QString> testBubbles = mBubbleTester->bubbles();
       
  1016 
       
  1017     foreach (QString bubbleId, testBubbles) {
       
  1018         QString state = mBubbleTester->dataField(bubbleId,"state");
       
  1019 
       
  1020         // create or remove bubble
       
  1021         if ( mTestBubbleIds.contains(bubbleId) && state=="Idle" ) {
       
  1022             bubbleManager().removeCallHeader(mTestBubbleIds.value(bubbleId));
       
  1023             mTestBubbleIds.remove(bubbleId);
       
  1024         } else if (!mTestBubbleIds.contains(bubbleId) && state!="Idle" ) {
       
  1025             int id = bubbleManager().createCallHeader();
       
  1026             mTestBubbleIds.insert(bubbleId,id);
       
  1027         }
       
  1028 
       
  1029         // set data
       
  1030         if (mTestBubbleIds.contains(bubbleId)) {
       
  1031             int id = mTestBubbleIds.value(bubbleId);
       
  1032 
       
  1033             QString name = mBubbleTester->dataField(bubbleId,"name");
       
  1034             QString number = mBubbleTester->dataField(bubbleId,"number");
       
  1035             QString divert = mBubbleTester->dataField(bubbleId,"divert");
       
  1036 
       
  1037             bubbleManager().setState(id, mStateMap.value(state));
       
  1038             bubbleManager().setCli(id, name, Qt::ElideRight);
       
  1039             bubbleManager().setSecondaryCli(id, number );
       
  1040             bubbleManager().setLabel(id, mLabelMap.value(state), Qt::ElideRight);
       
  1041 
       
  1042             bubbleManager().setCallFlag(id, BubbleManager::Diverted, (divert == "On") );
       
  1043 
       
  1044             setCallObject(id,":resources/contactpic.jpg");
       
  1045 
       
  1046             setBubbleActions(id, mStateMap.value(state) );
       
  1047         }
       
  1048     }
       
  1049 
       
  1050     bubbleManager().endChanges();
       
  1051 }