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 <HbMenu> |
|
19 #include <HbAction> |
|
20 #include <HbEffect> |
|
21 #include <QCoreApplication> |
|
22 #include <HbMessageBox> |
|
23 |
|
24 #include "radioviewbase.h" |
|
25 #include "radiowindow.h" |
|
26 #include "radiostationmodel.h" |
|
27 #include "radiouiloader.h" |
|
28 #include "radiouiengine.h" |
|
29 #include "radiologger.h" |
|
30 |
|
31 /*! |
|
32 * |
|
33 */ |
|
34 RadioViewBase::RadioViewBase( bool transient ) : |
|
35 HbView( 0 ), |
|
36 mMainWindow( 0 ), |
|
37 mUiLoader( 0 ), |
|
38 mTransientView( transient ), |
|
39 mUseLoudspeakerAction( 0 ), |
|
40 mOrientation( Qt::Vertical ) |
|
41 { |
|
42 } |
|
43 |
|
44 /*! |
|
45 * |
|
46 */ |
|
47 RadioViewBase::~RadioViewBase() |
|
48 { |
|
49 if ( mUiLoader ) { |
|
50 mUiLoader->reset(); |
|
51 } |
|
52 } |
|
53 |
|
54 /*! |
|
55 * |
|
56 */ |
|
57 void RadioViewBase::setMembers( RadioWindow* mainWindow, RadioUiLoader* uiLoader ) |
|
58 { |
|
59 mMainWindow = mainWindow; |
|
60 mUiLoader.reset( uiLoader ); |
|
61 } |
|
62 |
|
63 /*! |
|
64 * |
|
65 */ |
|
66 void RadioViewBase::preLazyLoadInit() |
|
67 { |
|
68 // Default implementation does nothing |
|
69 } |
|
70 |
|
71 /*! |
|
72 * |
|
73 */ |
|
74 void RadioViewBase::initialize( QSharedPointer<RadioUiEngine> uiEngine ) |
|
75 { |
|
76 mUiEngine = uiEngine; |
|
77 init(); |
|
78 } |
|
79 |
|
80 /*! |
|
81 * |
|
82 */ |
|
83 bool RadioViewBase::isInitialized() const |
|
84 { |
|
85 return mUiEngine; |
|
86 } |
|
87 |
|
88 /*! |
|
89 * |
|
90 */ |
|
91 bool RadioViewBase::isTransient() const |
|
92 { |
|
93 return mTransientView; |
|
94 } |
|
95 |
|
96 /*! |
|
97 * |
|
98 */ |
|
99 void RadioViewBase::updateOrientation( Qt::Orientation orientation, bool forceUpdate ) |
|
100 { |
|
101 if ( orientation != mOrientation || forceUpdate ) { |
|
102 mOrientation = orientation; |
|
103 setOrientation(); |
|
104 } |
|
105 } |
|
106 |
|
107 /*! |
|
108 * |
|
109 */ |
|
110 void RadioViewBase::bringToForeground() |
|
111 { |
|
112 mMainWindow->raise(); |
|
113 } |
|
114 |
|
115 /*! |
|
116 * Protected slot |
|
117 * |
|
118 */ |
|
119 void RadioViewBase::updateAudioRouting( bool loudspeaker ) |
|
120 { |
|
121 if ( mUseLoudspeakerAction ) { |
|
122 mUseLoudspeakerAction->setText( loudspeaker ? hbTrId( "txt_common_opt_deactivate_loudspeaker" ) |
|
123 : hbTrId( "txt_common_opt_activate_loudspeaker" ) ); |
|
124 } |
|
125 } |
|
126 |
|
127 /*! |
|
128 * Protected slot |
|
129 * |
|
130 */ |
|
131 void RadioViewBase::activatePreviousView() |
|
132 { |
|
133 mMainWindow->activateMainView(); |
|
134 } |
|
135 |
|
136 /*! |
|
137 * Protected slot |
|
138 * |
|
139 */ |
|
140 void RadioViewBase::quit() |
|
141 { |
|
142 qApp->quit(); |
|
143 } |
|
144 |
|
145 /*! |
|
146 * Private slot |
|
147 */ |
|
148 void RadioViewBase::handleUserAnswer( HbAction* answer ) |
|
149 { |
|
150 HbMessageBox* dlg = static_cast<HbMessageBox*>( sender() ); |
|
151 if( dlg->actions().first() == answer ) { |
|
152 userAccepted(); |
|
153 } |
|
154 } |
|
155 |
|
156 /*! |
|
157 * |
|
158 */ |
|
159 void RadioViewBase::initBackAction() |
|
160 { |
|
161 // The default back button activates the tuning view |
|
162 HbAction* backAction = new HbAction( Hb::BackNaviAction, this ); |
|
163 Radio::connect( backAction, SIGNAL(triggered()), |
|
164 mMainWindow, SLOT(activateMainView()) ); |
|
165 setNavigationAction( backAction ); |
|
166 } |
|
167 |
|
168 /*! |
|
169 * |
|
170 */ |
|
171 void RadioViewBase::connectCommonMenuItem( int menuItem ) |
|
172 { |
|
173 switch ( menuItem ) { |
|
174 case MenuItem::UseLoudspeaker: |
|
175 mUseLoudspeakerAction = mUiLoader->findObject<HbAction>( DOCML::NAME_LOUDSPEAKER_ACTION ); |
|
176 if ( mUseLoudspeakerAction ) { |
|
177 Radio::connect( mUseLoudspeakerAction, SIGNAL(triggered()), mUiEngine.data(), SLOT(toggleAudioRoute()) ); |
|
178 updateAudioRouting( mUiEngine->isUsingLoudspeaker() ); |
|
179 Radio::connect( mUiEngine.data(), SIGNAL(audioRouteChanged(bool)), this, SLOT(updateAudioRouting(bool)) ); |
|
180 } |
|
181 break; |
|
182 |
|
183 case MenuItem::Exit: |
|
184 if ( HbAction* exitAction = mUiLoader->findObject<HbAction>( DOCML::NAME_EXIT_ACTION ) ) { |
|
185 Radio::connect( exitAction, SIGNAL(triggered()), this, SLOT(quit()) ); |
|
186 } |
|
187 break; |
|
188 |
|
189 default: |
|
190 break; |
|
191 } |
|
192 } |
|
193 |
|
194 /*! |
|
195 * |
|
196 */ |
|
197 void RadioViewBase::connectXmlElement( const QString& name, const char* signal, QObject* receiver, const char* slot ) |
|
198 { |
|
199 if ( QObject* action = mUiLoader->findObject<QObject>( name ) ) { |
|
200 Radio::connect( action, signal, receiver, slot ); |
|
201 } |
|
202 } |
|
203 |
|
204 /*! |
|
205 * |
|
206 */ |
|
207 void RadioViewBase::connectViewChangeMenuItem( QString name, const char* slot ) |
|
208 { |
|
209 if ( QObject* action = mUiLoader->findObject<QObject>( name ) ) { |
|
210 Radio::connect( action, SIGNAL(triggered()), mMainWindow, slot ); |
|
211 } |
|
212 } |
|
213 |
|
214 /*! |
|
215 * |
|
216 */ |
|
217 void RadioViewBase::loadSection( const QString& docml, const QString& section ) |
|
218 { |
|
219 LOG_FORMAT( "RadioViewBase::loadSection: Docml: %s, section: %s", GETSTRING( docml ), GETSTRING( section ) ); |
|
220 bool ok = false; |
|
221 mUiLoader->load( docml, section, &ok ); |
|
222 LOG_ASSERT( ok, LOG_FORMAT( "Loading of section %s failed!", GETSTRING( section ) ) ); |
|
223 } |
|
224 |
|
225 /*! |
|
226 * |
|
227 */ |
|
228 void RadioViewBase::askQuestion( const QString& question ) |
|
229 { |
|
230 HbMessageBox::question( question, this, SLOT(handleUserAnswer(HbAction*)), HbMessageBox::Yes | HbMessageBox::No ); |
|
231 } |
|
232 |
|
233 /*! |
|
234 * |
|
235 */ |
|
236 void RadioViewBase::setOrientation() |
|
237 { |
|
238 // Default implementation does nothing |
|
239 } |
|
240 |
|
241 /*! |
|
242 * |
|
243 */ |
|
244 void RadioViewBase::userAccepted() |
|
245 { |
|
246 // Default implementation does nothing |
|
247 } |
|