|
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 // System includes |
|
19 #include <QTimer> |
|
20 #include <HbDeviceMessageBox> |
|
21 #include <xqsettingsmanager.h> |
|
22 #include <xqsettingskey.h> |
|
23 #include <xqserviceutil.h> |
|
24 #include <HbSplashScreen> |
|
25 |
|
26 // User includes |
|
27 #include "radioapplication.h" |
|
28 #include "radiowindow.h" |
|
29 #include "radiouiengine.h" |
|
30 #include "radio_global.h" |
|
31 #include "radiologger.h" |
|
32 |
|
33 #ifdef BUILD_WIN32 |
|
34 # include "testwindow_win32.h" |
|
35 # define CREATE_WIN32_TEST_WINDOW \ |
|
36 mWin32Window.reset( new Win32Window() ); \ |
|
37 mMainWindow->setParent( mWin32Window.data() ); \ |
|
38 mWin32Window->addHbWindow( mMainWindow.data() ); \ |
|
39 mWin32Window->show(); |
|
40 # define INIT_WIN32_TEST_WINDOW \ |
|
41 mWin32Window->init(); |
|
42 #else |
|
43 # define CREATE_WIN32_TEST_WINDOW |
|
44 # define INIT_WIN32_TEST_WINDOW |
|
45 #endif // BUILD_WIN32 |
|
46 |
|
47 |
|
48 static XQSettingsKey gConnectionKey( XQSettingsKey::TargetCentralRepository, CENREP_CORE_APPLICATION_UIS, ID_NETWORK_CONNECTION_ALLOWED ); |
|
49 |
|
50 /*! |
|
51 * Constructor |
|
52 */ |
|
53 RadioApplication::RadioApplication( int &argc, char *argv[] ) : |
|
54 HbApplication( argc, argv, Hb::NoSplash ), |
|
55 mSettingsManager( new XQSettingsManager( this ) ) |
|
56 { |
|
57 // Initializes the radio engine utils if UI logs are entered into the engine log |
|
58 INIT_COMBINED_LOGGER |
|
59 |
|
60 LOG_TIMESTAMP( "Start radio" ); |
|
61 setApplicationName( hbTrId( "txt_rad_title_fm_radio" ) ); |
|
62 |
|
63 if ( XQServiceUtil::isService() ) { |
|
64 |
|
65 // Radio was started as a highway service from homescreen widget. |
|
66 // Widget has already done the offline mode check so we can start without checking |
|
67 init(); |
|
68 |
|
69 } else { |
|
70 |
|
71 if ( isInOfflineMode() ) { |
|
72 askOfflineModePermission( hbTrId( "txt_rad_info_activate_radio_in_offline_mode" ) ); |
|
73 } else { |
|
74 init(); |
|
75 } |
|
76 |
|
77 } |
|
78 } |
|
79 |
|
80 /*! |
|
81 * |
|
82 */ |
|
83 RadioApplication::~RadioApplication() |
|
84 { |
|
85 // Destructor needs to be defined. See explanation from RadioEngineWrapperPrivate destructor. |
|
86 // Releases the radio engine utils if it was initialized in the beginning |
|
87 RELEASE_COMBINED_LOGGER |
|
88 } |
|
89 |
|
90 /*! |
|
91 * Private slot |
|
92 * |
|
93 */ |
|
94 void RadioApplication::checkOfflineMode() |
|
95 { |
|
96 if ( isInOfflineMode() ) { |
|
97 askOfflineModePermission( hbTrId( "txt_rad_info_continue_using_the_radio_in_offline" ) ); |
|
98 } |
|
99 } |
|
100 |
|
101 /*! |
|
102 * Private slot |
|
103 * |
|
104 */ |
|
105 void RadioApplication::handleOfflineQueryAnswer() |
|
106 { |
|
107 HbDeviceMessageBox* box = static_cast<HbDeviceMessageBox*>( sender() ); |
|
108 box->deleteLater(); |
|
109 if ( box->isAcceptAction( box->triggeredAction() ) ) { |
|
110 |
|
111 // If main window has not been created yet it means the offline question was asked during startup |
|
112 // so we must continue with the startup sequence. If the main window was already created it means |
|
113 // the question was asked when the radio was already running and the offline mode was activated. |
|
114 // In that case there is no need to do anything since the user wants to continue listening to radio. |
|
115 if ( !mMainWindow ) { |
|
116 init(); |
|
117 } |
|
118 |
|
119 } else { |
|
120 quit(); |
|
121 } |
|
122 } |
|
123 |
|
124 /*! |
|
125 * |
|
126 */ |
|
127 void RadioApplication::init() |
|
128 { |
|
129 // Try to optimize startup time by launching the radio server process as soon as possible. |
|
130 // This way the server and UI are being initialized at the same time and the startup is faster. |
|
131 // RadioUiEngine::launchRadioServer(); |
|
132 |
|
133 // Splash screen needs to be shown when not started by homescreen widget |
|
134 if ( !XQServiceUtil::isService() ) { |
|
135 HbSplashScreen::setAppId( "0x2002FF4E" ); |
|
136 HbSplashScreen::start(); |
|
137 } |
|
138 |
|
139 Radio::connect( mSettingsManager, SIGNAL(valueChanged(XQSettingsKey,QVariant)), |
|
140 this, SLOT(checkOfflineMode()) ); |
|
141 |
|
142 bool monitoringStarted = mSettingsManager->startMonitoring( gConnectionKey ); |
|
143 LOG_ASSERT( monitoringStarted, LOG( "Failed to start monitoring Offline mode!" ) ); |
|
144 Q_UNUSED( monitoringStarted ); |
|
145 |
|
146 mMainWindow.reset( new RadioWindow() ); |
|
147 |
|
148 CREATE_WIN32_TEST_WINDOW |
|
149 |
|
150 INIT_WIN32_TEST_WINDOW |
|
151 |
|
152 // Construct the real views |
|
153 mMainWindow->init(); |
|
154 |
|
155 mMainWindow->show(); |
|
156 } |
|
157 |
|
158 /*! |
|
159 * |
|
160 */ |
|
161 bool RadioApplication::isInOfflineMode() const |
|
162 { |
|
163 const QVariant connectionAllowed = mSettingsManager->readItemValue( gConnectionKey ); |
|
164 if ( connectionAllowed.canConvert( QVariant::Int ) && connectionAllowed.toInt() == NetworkNotAllowed ) { |
|
165 return true; |
|
166 } |
|
167 |
|
168 return false; |
|
169 } |
|
170 |
|
171 /*! |
|
172 * |
|
173 */ |
|
174 void RadioApplication::askOfflineModePermission( const QString& question ) |
|
175 { |
|
176 HbDeviceMessageBox* box = new HbDeviceMessageBox( question, HbMessageBox::MessageTypeQuestion, this ); |
|
177 box->setStandardButtons( HbMessageBox::Yes | HbMessageBox::No ); |
|
178 box->setTimeout( HbPopup::NoTimeout ); |
|
179 box->setDismissPolicy( HbPopup::NoDismiss ); |
|
180 Radio::connect( box, SIGNAL(aboutToClose()), |
|
181 this, SLOT(handleOfflineQueryAnswer()) ); |
|
182 box->show(); |
|
183 } |