radioapp/radioapplication/src/radioapplication.cpp
author hgs
Mon, 20 Sep 2010 18:04:48 +0300
changeset 51 bbebb0235466
parent 44 0a3ad94fc71c
permissions -rw-r--r--
201037
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
* All rights reserved.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
* Initial Contributors:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
* Contributors:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
* Description:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
*/
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
// System includes
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
#include <QTimer>
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
#include <HbDeviceMessageBox>
38
hgs
parents: 34
diff changeset
    21
#include <xqsettingsmanager.h>
hgs
parents: 34
diff changeset
    22
#include <xqsettingskey.h>
34
hgs
parents: 28
diff changeset
    23
#include <xqserviceutil.h>
hgs
parents: 28
diff changeset
    24
#include <HbSplashScreen>
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
// User includes
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
#include "radioapplication.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
#include "radiowindow.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
#include "radiouiengine.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
#include "radio_global.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
#include "radiologger.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
#ifdef BUILD_WIN32
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
#   include "testwindow_win32.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
#   define CREATE_WIN32_TEST_WINDOW \
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
        mWin32Window.reset( new Win32Window() ); \
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
        mMainWindow->setParent( mWin32Window.data() ); \
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
        mWin32Window->addHbWindow( mMainWindow.data() ); \
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
        mWin32Window->show();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
#   define INIT_WIN32_TEST_WINDOW \
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
        mWin32Window->init();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
#else
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
#   define CREATE_WIN32_TEST_WINDOW
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
#   define INIT_WIN32_TEST_WINDOW
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
#endif // BUILD_WIN32
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
38
hgs
parents: 34
diff changeset
    47
hgs
parents: 34
diff changeset
    48
static XQSettingsKey gConnectionKey( XQSettingsKey::TargetCentralRepository, CENREP_CORE_APPLICATION_UIS, ID_NETWORK_CONNECTION_ALLOWED );
hgs
parents: 34
diff changeset
    49
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
 * Constructor
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
RadioApplication::RadioApplication( int &argc, char *argv[] ) :
51
hgs
parents: 44
diff changeset
    54
    HbApplication( argc, argv, XQServiceUtil::isService(argc, argv) ? Hb::NoSplash : Hb::DefaultApplicationFlags ),
hgs
parents: 44
diff changeset
    55
    mMainWindow( new RadioWindow() ),
hgs
parents: 44
diff changeset
    56
    mSettingsManager( new XQSettingsManager( this ) ),
hgs
parents: 44
diff changeset
    57
    mInitialisationDone( false )
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
    // Initializes the radio engine utils if UI logs are entered into the engine log
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
    INIT_COMBINED_LOGGER
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
    LOG_TIMESTAMP( "Start radio" );
51
hgs
parents: 44
diff changeset
    63
hgs
parents: 44
diff changeset
    64
    QTimer::singleShot( 0, this, SLOT( construct() ) );
hgs
parents: 44
diff changeset
    65
}
hgs
parents: 44
diff changeset
    66
hgs
parents: 44
diff changeset
    67
/*!
hgs
parents: 44
diff changeset
    68
 *
hgs
parents: 44
diff changeset
    69
 */
hgs
parents: 44
diff changeset
    70
RadioApplication::~RadioApplication()
hgs
parents: 44
diff changeset
    71
{
hgs
parents: 44
diff changeset
    72
    // Destructor needs to be defined. See explanation from RadioEngineWrapperPrivate destructor.
hgs
parents: 44
diff changeset
    73
    // Releases the radio engine utils if it was initialized in the beginning
hgs
parents: 44
diff changeset
    74
    RELEASE_COMBINED_LOGGER
hgs
parents: 44
diff changeset
    75
}
hgs
parents: 44
diff changeset
    76
hgs
parents: 44
diff changeset
    77
/*!
hgs
parents: 44
diff changeset
    78
 * Private slot
hgs
parents: 44
diff changeset
    79
 *
hgs
parents: 44
diff changeset
    80
 */
hgs
parents: 44
diff changeset
    81
void RadioApplication::construct()
hgs
parents: 44
diff changeset
    82
{
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
    setApplicationName( hbTrId( "txt_rad_title_fm_radio" ) );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
38
hgs
parents: 34
diff changeset
    85
    if ( XQServiceUtil::isService() ) {
hgs
parents: 34
diff changeset
    86
        // Radio was started as a highway service from homescreen widget.
hgs
parents: 34
diff changeset
    87
        // Widget has already done the offline mode check so we can start without checking
hgs
parents: 34
diff changeset
    88
        init();
hgs
parents: 34
diff changeset
    89
hgs
parents: 34
diff changeset
    90
    } else {
hgs
parents: 34
diff changeset
    91
hgs
parents: 34
diff changeset
    92
        if ( isInOfflineMode() ) {
hgs
parents: 34
diff changeset
    93
            askOfflineModePermission( hbTrId( "txt_rad_info_activate_radio_in_offline_mode" ) );
hgs
parents: 34
diff changeset
    94
        } else {
hgs
parents: 34
diff changeset
    95
            init();
hgs
parents: 34
diff changeset
    96
        }
hgs
parents: 34
diff changeset
    97
34
hgs
parents: 28
diff changeset
    98
    }
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
/*!
34
hgs
parents: 28
diff changeset
   103
 * Private slot
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
 */
38
hgs
parents: 34
diff changeset
   106
void RadioApplication::checkOfflineMode()
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
{
38
hgs
parents: 34
diff changeset
   108
    if ( isInOfflineMode() ) {
hgs
parents: 34
diff changeset
   109
        askOfflineModePermission( hbTrId( "txt_rad_info_continue_using_the_radio_in_offline" ) );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
    }
38
hgs
parents: 34
diff changeset
   111
}
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
38
hgs
parents: 34
diff changeset
   113
/*!
hgs
parents: 34
diff changeset
   114
 * Private slot
hgs
parents: 34
diff changeset
   115
 *
hgs
parents: 34
diff changeset
   116
 */
hgs
parents: 34
diff changeset
   117
void RadioApplication::handleOfflineQueryAnswer()
hgs
parents: 34
diff changeset
   118
{
hgs
parents: 34
diff changeset
   119
    HbDeviceMessageBox* box = static_cast<HbDeviceMessageBox*>( sender() );
hgs
parents: 34
diff changeset
   120
    box->deleteLater();
hgs
parents: 34
diff changeset
   121
    if ( box->isAcceptAction( box->triggeredAction() ) ) {
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   122
38
hgs
parents: 34
diff changeset
   123
        // If main window has not been created yet it means the offline question was asked during startup
hgs
parents: 34
diff changeset
   124
        // so we must continue with the startup sequence. If the main window was already created it means
hgs
parents: 34
diff changeset
   125
        // the question was asked when the radio was already running and the offline mode was activated.
hgs
parents: 34
diff changeset
   126
        // In that case there is no need to do anything since the user wants to continue listening to radio.
51
hgs
parents: 44
diff changeset
   127
        if ( !mInitialisationDone ) {
38
hgs
parents: 34
diff changeset
   128
            init();
hgs
parents: 34
diff changeset
   129
        }
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   130
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   131
    } else {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   132
        quit();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   133
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   134
}
38
hgs
parents: 34
diff changeset
   135
hgs
parents: 34
diff changeset
   136
/*!
hgs
parents: 34
diff changeset
   137
 *
hgs
parents: 34
diff changeset
   138
 */
hgs
parents: 34
diff changeset
   139
void RadioApplication::init()
hgs
parents: 34
diff changeset
   140
{
hgs
parents: 34
diff changeset
   141
    // Try to optimize startup time by launching the radio server process as soon as possible.
hgs
parents: 34
diff changeset
   142
    // This way the server and UI are being initialized at the same time and the startup is faster.
hgs
parents: 34
diff changeset
   143
//        RadioUiEngine::launchRadioServer();
hgs
parents: 34
diff changeset
   144
hgs
parents: 34
diff changeset
   145
    // Splash screen needs to be shown when not started by homescreen widget
hgs
parents: 34
diff changeset
   146
hgs
parents: 34
diff changeset
   147
    Radio::connect( mSettingsManager,   SIGNAL(valueChanged(XQSettingsKey,QVariant)),
hgs
parents: 34
diff changeset
   148
                    this,               SLOT(checkOfflineMode()) );
hgs
parents: 34
diff changeset
   149
hgs
parents: 34
diff changeset
   150
    bool monitoringStarted = mSettingsManager->startMonitoring( gConnectionKey );
hgs
parents: 34
diff changeset
   151
    LOG_ASSERT( monitoringStarted, LOG( "Failed to start monitoring Offline mode!" ) );
hgs
parents: 34
diff changeset
   152
    Q_UNUSED( monitoringStarted );
hgs
parents: 34
diff changeset
   153
hgs
parents: 34
diff changeset
   154
    CREATE_WIN32_TEST_WINDOW
hgs
parents: 34
diff changeset
   155
hgs
parents: 34
diff changeset
   156
    INIT_WIN32_TEST_WINDOW
hgs
parents: 34
diff changeset
   157
hgs
parents: 34
diff changeset
   158
    // Construct the real views
hgs
parents: 34
diff changeset
   159
    mMainWindow->init();
51
hgs
parents: 44
diff changeset
   160
    mInitialisationDone = true;
38
hgs
parents: 34
diff changeset
   161
hgs
parents: 34
diff changeset
   162
    mMainWindow->show();
hgs
parents: 34
diff changeset
   163
}
hgs
parents: 34
diff changeset
   164
hgs
parents: 34
diff changeset
   165
/*!
hgs
parents: 34
diff changeset
   166
 *
hgs
parents: 34
diff changeset
   167
 */
hgs
parents: 34
diff changeset
   168
bool RadioApplication::isInOfflineMode() const
hgs
parents: 34
diff changeset
   169
{
hgs
parents: 34
diff changeset
   170
    const QVariant connectionAllowed = mSettingsManager->readItemValue( gConnectionKey );
hgs
parents: 34
diff changeset
   171
    if ( connectionAllowed.canConvert( QVariant::Int ) && connectionAllowed.toInt() == NetworkNotAllowed ) {
hgs
parents: 34
diff changeset
   172
        return true;
hgs
parents: 34
diff changeset
   173
    }
hgs
parents: 34
diff changeset
   174
hgs
parents: 34
diff changeset
   175
    return false;
hgs
parents: 34
diff changeset
   176
}
hgs
parents: 34
diff changeset
   177
hgs
parents: 34
diff changeset
   178
/*!
hgs
parents: 34
diff changeset
   179
 *
hgs
parents: 34
diff changeset
   180
 */
hgs
parents: 34
diff changeset
   181
void RadioApplication::askOfflineModePermission( const QString& question )
hgs
parents: 34
diff changeset
   182
{
hgs
parents: 34
diff changeset
   183
    HbDeviceMessageBox* box = new HbDeviceMessageBox( question, HbMessageBox::MessageTypeQuestion, this );
hgs
parents: 34
diff changeset
   184
    box->setStandardButtons( HbMessageBox::Yes | HbMessageBox::No );
hgs
parents: 34
diff changeset
   185
    box->setTimeout( HbPopup::NoTimeout );
hgs
parents: 34
diff changeset
   186
    box->setDismissPolicy( HbPopup::NoDismiss );
hgs
parents: 34
diff changeset
   187
    Radio::connect( box,    SIGNAL(aboutToClose()),
hgs
parents: 34
diff changeset
   188
                    this,   SLOT(handleOfflineQueryAnswer()) );
hgs
parents: 34
diff changeset
   189
    box->show();
hgs
parents: 34
diff changeset
   190
}