41 #else |
42 #else |
42 # define CREATE_WIN32_TEST_WINDOW |
43 # define CREATE_WIN32_TEST_WINDOW |
43 # define INIT_WIN32_TEST_WINDOW |
44 # define INIT_WIN32_TEST_WINDOW |
44 #endif // BUILD_WIN32 |
45 #endif // BUILD_WIN32 |
45 |
46 |
|
47 |
|
48 static XQSettingsKey gConnectionKey( XQSettingsKey::TargetCentralRepository, CENREP_CORE_APPLICATION_UIS, ID_NETWORK_CONNECTION_ALLOWED ); |
|
49 |
46 /*! |
50 /*! |
47 * Constructor |
51 * Constructor |
48 */ |
52 */ |
49 RadioApplication::RadioApplication( int &argc, char *argv[] ) : |
53 RadioApplication::RadioApplication( int &argc, char *argv[] ) : |
50 HbApplication( argc, argv, Hb::NoSplash ) |
54 HbApplication( argc, argv, Hb::NoSplash ), |
|
55 mSettingsManager( new XQSettingsManager( this ) ) |
51 { |
56 { |
52 // Initializes the radio engine utils if UI logs are entered into the engine log |
57 // Initializes the radio engine utils if UI logs are entered into the engine log |
53 INIT_COMBINED_LOGGER |
58 INIT_COMBINED_LOGGER |
54 |
59 |
55 LOG_TIMESTAMP( "Start radio" ); |
60 LOG_TIMESTAMP( "Start radio" ); |
56 setApplicationName( hbTrId( "txt_rad_title_fm_radio" ) ); |
61 setApplicationName( hbTrId( "txt_rad_title_fm_radio" ) ); |
57 |
62 |
58 if ( !XQServiceUtil::isService() ) { |
63 if ( XQServiceUtil::isService() ) { |
59 HbSplashScreen::start(); |
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 |
60 } |
77 } |
61 |
|
62 QTimer::singleShot( 0, this, SLOT(init()) ); |
|
63 } |
78 } |
64 |
79 |
65 /*! |
80 /*! |
66 * |
81 * |
67 */ |
82 */ |
74 |
89 |
75 /*! |
90 /*! |
76 * Private slot |
91 * Private slot |
77 * |
92 * |
78 */ |
93 */ |
79 void RadioApplication::init() |
94 void RadioApplication::checkOfflineMode() |
80 { |
95 { |
81 // If started as a service, there is no need for offline-check |
96 if ( isInOfflineMode() ) { |
82 bool okToStart = XQServiceUtil::isService(); |
97 askOfflineModePermission( hbTrId( "txt_rad_info_continue_using_the_radio_in_offline" ) ); |
83 QScopedPointer<QtMobility::QSystemDeviceInfo> deviceInfo( new QtMobility::QSystemDeviceInfo() ); |
98 } |
|
99 } |
84 |
100 |
85 if ( !okToStart ) { |
101 /*! |
86 if ( deviceInfo->currentProfile() != QtMobility::QSystemDeviceInfo::OfflineProfile ) { |
102 * Private slot |
87 okToStart = true; |
103 * |
88 } else { |
104 */ |
89 // Device is in offline profile, ask the user for permission to start |
105 void RadioApplication::handleOfflineQueryAnswer() |
90 HbDeviceMessageBox box( hbTrId( "txt_rad_info_activate_radio_in_offline_mode" ), HbMessageBox::MessageTypeQuestion ); |
106 { |
91 box.setTimeout( HbPopup::NoTimeout ); |
107 HbDeviceMessageBox* box = static_cast<HbDeviceMessageBox*>( sender() ); |
92 box.exec(); |
108 box->deleteLater(); |
93 okToStart = box.isAcceptAction( box.triggeredAction() ); |
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(); |
94 } |
117 } |
95 } |
|
96 |
118 |
97 if ( okToStart ) { |
|
98 |
|
99 // Try to optimize startup time by launching the radio server process as soon as possible. |
|
100 // This way the server and UI are being initialized at the same time and the startup is faster. |
|
101 // RadioUiEngine::launchRadioServer(); |
|
102 |
|
103 mMainWindow.reset( new RadioWindow() ); |
|
104 |
|
105 CREATE_WIN32_TEST_WINDOW |
|
106 |
|
107 INIT_WIN32_TEST_WINDOW |
|
108 |
|
109 // Construct the real views |
|
110 mMainWindow->init( deviceInfo.take() ); |
|
111 |
|
112 mMainWindow->show(); |
|
113 } else { |
119 } else { |
114 quit(); |
120 quit(); |
115 } |
121 } |
116 } |
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( "fmradio" ); |
|
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 } |