|
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 // USER INCLUDES |
|
19 #include "lcviewmanager_p.h" |
|
20 #include "lcuicomponentrepository.h" |
|
21 #include "lcuidefs.h" |
|
22 #include "lcuiengine.h" |
|
23 #include "lcview.h" |
|
24 #include "lclogger.h" |
|
25 |
|
26 // SYSTEM INCLUDES |
|
27 #include <hbmainwindow.h> |
|
28 #include <hbdialog.h> |
|
29 #include <hbaction.h> |
|
30 #include <qcoreapplication.h> |
|
31 |
|
32 // CONSTANTS |
|
33 #define LC_VIEWMANAGER_SLOT_ACTIVATE_CURRENT_VIEW "activateCurrentView" |
|
34 |
|
35 |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // LcMainWindow::LcMainWindow |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 LcMainWindow::LcMainWindow() : |
|
42 HbMainWindow(0, Hb::WindowFlagFixedHorizontal | Hb::WindowFlagTransparent) |
|
43 { |
|
44 // TODO: remove flag WindowFlagFixedHorizontal if portait layout |
|
45 // is going to be supported. |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // LcMainWindow::~LcMainWindow |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 LcMainWindow::~LcMainWindow() |
|
53 { |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // LcMainWindow::event |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 bool LcMainWindow::event(QEvent *event) |
|
61 { |
|
62 if ( event->type() == QEvent::FocusIn ){ |
|
63 LC_QDEBUG( "livecomms [UI] -> LcMainWindow::event(), focus in" ) |
|
64 emit appFocusGained(); |
|
65 } else if ( event->type() == QEvent::FocusOut ){ |
|
66 LC_QDEBUG( "livecomms [UI] -> LcMainWindow::event(), focus out" ) |
|
67 emit appFocusLost(); |
|
68 } |
|
69 return HbMainWindow::event(event); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // LcViewManagerPrivate::LcViewManagerPrivate |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 LcViewManagerPrivate::LcViewManagerPrivate( |
|
77 const QString& engineName, |
|
78 const QString& applicationDisplayName) : |
|
79 mEngine( 0 ), |
|
80 mRepository( 0 ) |
|
81 { |
|
82 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::LcViewManagerPrivate()" ) |
|
83 |
|
84 mEngine = new LcUiEngine( engineName, applicationDisplayName ); |
|
85 mRepository = new LcUiComponentRepository( *mEngine ); |
|
86 setCurrentView( true ); |
|
87 |
|
88 // TODO: ignore orientation change at the moment, enable later |
|
89 /*connect( &mMainWindow, SIGNAL( orientationChanged(Qt::Orientation) ), |
|
90 this, SLOT( updateLayout() ) ); |
|
91 |
|
92 connect( &mMainWindow, SIGNAL( aboutToChangeOrientation() ), |
|
93 this, SLOT( prepareOrientationChange() ) ); |
|
94 */ |
|
95 |
|
96 connect(&mMainWindow, SIGNAL(appFocusGained()), mEngine, SLOT(maximize())); |
|
97 connect(&mMainWindow, SIGNAL(appFocusLost()), mEngine, SLOT(minimize())); |
|
98 |
|
99 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::LcViewManagerPrivate()" ) |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // LcViewManagerPrivate::~LcViewManagerPrivate |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 LcViewManagerPrivate::~LcViewManagerPrivate() |
|
107 { |
|
108 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::~LcViewManagerPrivate()" ) |
|
109 |
|
110 QList<HbView *> views = mMainWindow.views(); |
|
111 foreach( HbView* view, views ){ |
|
112 mMainWindow.removeView(view); |
|
113 } |
|
114 delete mRepository; |
|
115 delete mEngine; |
|
116 |
|
117 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::~LcViewManagerPrivate()" ) |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // LcViewManagerPrivate::terminateSession |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void LcViewManagerPrivate::terminateSession() |
|
125 { |
|
126 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::terminateSession" ) |
|
127 mEngine->stop(); |
|
128 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::terminateSession" ) |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // LcViewManagerPrivate::updateLayout |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void LcViewManagerPrivate::updateLayout() |
|
136 { |
|
137 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::updateLayout()" ) |
|
138 |
|
139 if ( mMainWindow.currentView() ) { |
|
140 LcView* currentView = static_cast<LcView*>( mMainWindow.currentView() ); |
|
141 QString layout = currentView->currentLayout(); |
|
142 mRepository->loadLayout( layout ); |
|
143 currentView->updateUiElements(); |
|
144 currentView->updateVideoRects(); |
|
145 } |
|
146 |
|
147 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::updateLayout()" ) |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // LcViewManagerPrivate::prepareOrientationChange |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void LcViewManagerPrivate::prepareOrientationChange() |
|
155 { |
|
156 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::prepareOrientationChange()" ) |
|
157 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::prepareOrientationChange()" ) |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // LcViewManagerPrivate::activateCurrentView |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void LcViewManagerPrivate::activateCurrentView(bool startup) |
|
165 { |
|
166 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::activateCurrentView()" ) |
|
167 if ( mMainWindow.currentView() ) { |
|
168 static_cast<LcView*>( mMainWindow.currentView() )->activated(); |
|
169 } |
|
170 |
|
171 if ( startup ){ |
|
172 LC_QDEBUG( "livecomms [UI] Start engine" ) |
|
173 startEngine(); |
|
174 } |
|
175 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::activateCurrentView()" ) |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // LcViewManagerPrivate::startEngine |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void LcViewManagerPrivate::startEngine() |
|
183 { |
|
184 connect(mEngine, SIGNAL(layoutChanged()), this, SLOT(changeView()), |
|
185 Qt::QueuedConnection ); |
|
186 connect(mEngine, SIGNAL(stopped()), this, SLOT(closeApp()), |
|
187 Qt::QueuedConnection ); |
|
188 |
|
189 mEngine->setUiComponents( mRepository->invitingNote(), |
|
190 mRepository->waitingNote(), |
|
191 mRepository->acceptQuery(), |
|
192 mRepository->recipientQuery(), |
|
193 mRepository->shareOwnVideoQuery() ); |
|
194 mEngine->start(); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // LcViewManagerPrivate::setCurrentView |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void LcViewManagerPrivate::setCurrentView(bool startup) |
|
202 { |
|
203 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::setCurrentView()" ) |
|
204 |
|
205 LcView* currView = currentView(); |
|
206 |
|
207 bool found(false); |
|
208 foreach ( HbView* view, mMainWindow.views() ){ |
|
209 found |= ( view == currView ); |
|
210 } |
|
211 if ( !found ){ |
|
212 mMainWindow.addView( currView ); |
|
213 } |
|
214 mMainWindow.setCurrentView( currView ); |
|
215 |
|
216 LcUtil::asyncSlotCall( |
|
217 this, LC_VIEWMANAGER_SLOT_ACTIVATE_CURRENT_VIEW, Q_ARG( bool, startup ) ); |
|
218 |
|
219 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::setCurrentView()" ) |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // LcViewManagerPrivate::currentView |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 LcView* LcViewManagerPrivate::currentView() |
|
227 { |
|
228 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::currentView()" ) |
|
229 |
|
230 LcViewLayoutHint hint = mEngine->viewLayout(); |
|
231 LcView* nextView = 0; |
|
232 |
|
233 switch ( hint ) { |
|
234 case Lc_ReceivedViewLayout: |
|
235 LC_QDEBUG( "livecomms [UI] - switching to receive view -" ) |
|
236 nextView = mRepository->receiveView(); |
|
237 break; |
|
238 case Lc_ReceivedOnlyViewLayout: |
|
239 LC_QDEBUG( "livecomms [UI] - switching to receive only view -" ) |
|
240 nextView = mRepository->receiveOnlyView(); |
|
241 break; |
|
242 case Lc_AllInOneViewLayout: |
|
243 LC_QDEBUG( "livecomms [UI] - switching to allinone view -" ) |
|
244 nextView = mRepository->allInOneView(); |
|
245 break; |
|
246 case Lc_TwowayViewLayout: |
|
247 LC_QDEBUG( "livecomms [UI] - switching to twoway view -" ) |
|
248 nextView = mRepository->twowayView(); |
|
249 break; |
|
250 case Lc_SharedViewLayout: |
|
251 LC_QDEBUG( "livecomms [UI] - switching to send view -" ) |
|
252 nextView = mRepository->sendView(); |
|
253 break; |
|
254 default: |
|
255 LC_QDEBUG( "livecomms [UI] - switching to idle view -" ) |
|
256 nextView = mRepository->idleView(); |
|
257 break; |
|
258 } |
|
259 if ( !nextView && hint > Lc_IdleViewLayout ) { |
|
260 LC_QDEBUG( "livecomms [UI] ! could not get view !" ) |
|
261 LC_QDEBUG( "livecomms [UI] - switching to idle view -" ) |
|
262 nextView = mRepository->idleView(); |
|
263 } |
|
264 |
|
265 if ( !nextView ) { |
|
266 LC_QCRITICAL( "livecomms [UI] ! still could not get view !. ABORT" ) |
|
267 LC_PANIC(); |
|
268 } |
|
269 |
|
270 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::currentView()" ) |
|
271 return nextView; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // LcViewManagerPrivate::changeView |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 void LcViewManagerPrivate::changeView() |
|
279 { |
|
280 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::changeView()" ) |
|
281 |
|
282 LcView* currentView = static_cast<LcView*>( mMainWindow.currentView() ); |
|
283 currentView->deactivated(); |
|
284 setCurrentView(); |
|
285 |
|
286 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::changeView()" ) |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // LcViewManagerPrivate::closeApp |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void LcViewManagerPrivate::closeApp() |
|
294 { |
|
295 LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::closeApp()" ) |
|
296 |
|
297 qApp->exit(0); |
|
298 |
|
299 LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::closeApp()" ) |
|
300 } |
|
301 |
|
302 // End of file |