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