|
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 <QtGui> |
|
19 #include <hbaction.h> |
|
20 #include <hbpushbutton.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 "bubblebuttonstyle.h" |
|
30 #include "bubbleparticipantlistitem.h" |
|
31 #include "bubbleparticipantlistmodel.h" |
|
32 |
|
33 static const int BUBBLE_SELECTION_TIMEOUT = 3000; |
|
34 |
|
35 BubbleConferenceHandler::BubbleConferenceHandler( |
|
36 BubbleWidgetManager& widgetManager, |
|
37 BubbleWidgetManager::View view, |
|
38 BubbleWidgetManager::Container container, |
|
39 QObject* parent ) |
|
40 : BubbleHandler(widgetManager,view,container,parent) |
|
41 { |
|
42 mTimerLabel = |
|
43 qobject_cast<HbLabel*>(widget(BubbleWidgetManager::ConferenceTimer)); |
|
44 Q_ASSERT(mTimerLabel); |
|
45 HbDeviceProfile profile; |
|
46 HbFontSpec spec(HbFontSpec::Secondary); |
|
47 spec.setTextHeight(4*HbDeviceProfile::current().unitValue()); |
|
48 mTimerLabel->setFontSpec(spec); |
|
49 mTimerLabel->setAlignment(Qt::AlignLeft); |
|
50 |
|
51 mButtonCenter = |
|
52 qobject_cast<HbPushButton*>(widget(BubbleWidgetManager::CenterButton)); |
|
53 Q_ASSERT(mButtonCenter); |
|
54 mButtonLeft = |
|
55 qobject_cast<HbPushButton*>(widget(BubbleWidgetManager::LeftButton)); |
|
56 Q_ASSERT(mButtonLeft); |
|
57 mButtonRight = |
|
58 qobject_cast<HbPushButton*>(widget(BubbleWidgetManager::RightButton)); |
|
59 Q_ASSERT(mButtonRight); |
|
60 |
|
61 mList = |
|
62 qobject_cast<HbListView*>(widget(BubbleWidgetManager::ParticipantList)); |
|
63 Q_ASSERT(mList); |
|
64 mModel = new BubbleParticipantListModel(); |
|
65 mList->setModel(mModel); |
|
66 |
|
67 mPrototype = |
|
68 qobject_cast<BubbleParticipantListItem*>( |
|
69 widgetManager.createParticipantListItem()); |
|
70 Q_ASSERT(mPrototype); |
|
71 mList->setItemPrototype(mPrototype); |
|
72 connect(mPrototype,SIGNAL(selectionChanged(int)), |
|
73 SLOT(handleItemSelected(int))); |
|
74 |
|
75 mSelectionTimer = new QTimer(this); |
|
76 connect(mSelectionTimer,SIGNAL(timeout()),SLOT(clearSelection())); |
|
77 mSelectionTimer->setSingleShot(true); |
|
78 |
|
79 reset(); |
|
80 } |
|
81 |
|
82 BubbleConferenceHandler::~BubbleConferenceHandler() |
|
83 { |
|
84 } |
|
85 |
|
86 void BubbleConferenceHandler::reset() |
|
87 { |
|
88 mHeader = 0; |
|
89 |
|
90 mModel->reset(); |
|
91 mList->reset(); |
|
92 mSelectionTimer->stop(); |
|
93 mPrototype->clearActions(); |
|
94 mTimerLabel->hide(); |
|
95 mButtonCenter->hide(); |
|
96 mButtonCenter->setDown(false); |
|
97 mButtonCenter->disconnect(); |
|
98 mButtonCenter->setText(""); |
|
99 mButtonLeft->hide(); |
|
100 mButtonLeft->setDown(false); |
|
101 mButtonLeft->disconnect(); |
|
102 mButtonLeft->setText(""); |
|
103 mButtonRight->hide(); |
|
104 mButtonRight->setDown(false); |
|
105 mButtonRight->disconnect(); |
|
106 mButtonRight->setText(""); |
|
107 } |
|
108 |
|
109 void BubbleConferenceHandler::readBubbleHeader( const BubbleHeader& header ) |
|
110 { |
|
111 Q_ASSERT(header.isConference()); |
|
112 mHeader = static_cast<const BubbleConferenceHeader*>(&header); |
|
113 |
|
114 // populate participant list model |
|
115 QList<BubbleHeader*> participants = mHeader->headers(); |
|
116 foreach(BubbleHeader* participant, participants) { |
|
117 mModel->addParticipant(participant->bubbleId(), |
|
118 participant->cli(), |
|
119 (int)participant->callState()); |
|
120 } |
|
121 |
|
122 // set actions to item prototype |
|
123 QList<HbAbstractViewItem*> prototypes = mList->itemPrototypes(); |
|
124 QList<HbAction*> actions = mHeader->participantListActions(); |
|
125 foreach (HbAction* action, actions ) { |
|
126 mPrototype->addAction(action); |
|
127 } |
|
128 |
|
129 mList->reset(); |
|
130 |
|
131 if (header.timerCost().length()) { |
|
132 mTimerLabel->setPlainText(header.timerCost()); |
|
133 mTimerLabel->show(); |
|
134 } |
|
135 |
|
136 setButtons(mHeader->actions()); |
|
137 } |
|
138 |
|
139 void BubbleConferenceHandler::setButtons(const QList<HbAction*>& actions) |
|
140 { |
|
141 if ( actions.count()==1 && mButtonCenter ) { |
|
142 HbAction* action = actions.at(0); |
|
143 mButtonCenter->setIcon( action->icon() ); |
|
144 BubbleUtils::setButtonStyleForAction(*mButtonCenter,*action); |
|
145 connect(mButtonCenter, SIGNAL( clicked() ), |
|
146 action, SLOT( trigger() ) ); |
|
147 mButtonCenter->show(); |
|
148 } else if (actions.count()==2 && mButtonLeft && mButtonRight ) { |
|
149 // Left button |
|
150 HbAction* action1 = actions.at(0); |
|
151 mButtonLeft->setIcon( action1->icon() ); |
|
152 BubbleUtils::setButtonStyleForAction(*mButtonLeft,*action1); |
|
153 connect( mButtonLeft, SIGNAL( clicked() ), |
|
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 mButtonRight->show(); |
|
163 } |
|
164 } |
|
165 |
|
166 QGraphicsWidget* BubbleConferenceHandler::graphicsWidgetForAction( |
|
167 HbAction* action ) const |
|
168 { |
|
169 if ( mButtonLeft->text() == action->text() ) { |
|
170 return mButtonLeft; |
|
171 } else if ( mButtonRight->text() == action->text() ) { |
|
172 return mButtonRight; |
|
173 } else if ( mButtonCenter->text() == action->text() ) { |
|
174 return mButtonCenter; |
|
175 } else { |
|
176 return 0; |
|
177 } |
|
178 } |
|
179 |
|
180 void BubbleConferenceHandler::updateTimerDisplayNow() |
|
181 { |
|
182 Q_ASSERT(mHeader); |
|
183 |
|
184 mTimerLabel->setPlainText(mHeader->timerCost()); |
|
185 mTimerLabel->update(); |
|
186 } |
|
187 |
|
188 void BubbleConferenceHandler::handleItemSelected(int row) |
|
189 { |
|
190 Q_ASSERT( mHeader != 0 ); |
|
191 // need to cast constness away |
|
192 BubbleConferenceHeader& mutableHeader = |
|
193 const_cast<BubbleConferenceHeader&>(*mHeader); |
|
194 mutableHeader.setSelectedHeader(mModel->bubbleId(row)); |
|
195 mSelectionTimer->stop(); |
|
196 mSelectionTimer->start(BUBBLE_SELECTION_TIMEOUT); |
|
197 } |
|
198 |
|
199 void BubbleConferenceHandler::clearSelection() |
|
200 { |
|
201 mList->selectionModel()->clear(); |
|
202 } |