radioapp/radiouiengine/src/radiouiengine_p.cpp
branchRCL_3
changeset 20 93c594350b9a
parent 19 cce62ebc198e
equal deleted inserted replaced
19:cce62ebc198e 20:93c594350b9a
     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 <QApplication>
       
    20 #include <QStringList>
       
    21 #include <QDateTime>
       
    22 #ifndef BUILD_WIN32
       
    23 #   include <XQSettingsManager>
       
    24 #   include <XQPublishAndSubscribeSettingsKey>
       
    25 #   include <XQPublishAndSubscribeUtils>
       
    26 #endif
       
    27 
       
    28 // User includes
       
    29 #include "radiouiengine.h"
       
    30 #include "radiouiengine_p.h"
       
    31 #include "radioenginewrapper.h"
       
    32 #include "radiostationmodel.h"
       
    33 #include "radiostationmodel_p.h"
       
    34 #include "radiohistorymodel.h"
       
    35 #include "radiopresetstorage.h"
       
    36 #include "radiosettings.h"
       
    37 #include "radiostation.h"
       
    38 #include "radioscannerengine.h"
       
    39 #include "radiostationhandlerif.h"
       
    40 #include "radiocontrolservice.h"
       
    41 #include "radiomonitorservice.h"
       
    42 #include "radioservicedef.h"
       
    43 #include "radiologger.h"
       
    44 
       
    45 /*!
       
    46  *
       
    47  */
       
    48 RadioUiEnginePrivate::RadioUiEnginePrivate( RadioUiEngine* engine ) :
       
    49     q_ptr( engine ),
       
    50     mPowerOffTimer( NULL )
       
    51 {
       
    52 }
       
    53 
       
    54 /*!
       
    55  *
       
    56  */
       
    57 RadioUiEnginePrivate::~RadioUiEnginePrivate()
       
    58 {
       
    59 #ifndef BUILD_WIN32
       
    60     XQSettingsManager settingsManager;
       
    61     XQPublishAndSubscribeUtils utils( settingsManager );
       
    62     XQPublishAndSubscribeSettingsKey radioStartupKey( KRadioPSUid, KRadioStartupKey );
       
    63     bool deleted = utils.deleteProperty( radioStartupKey );
       
    64     LOG_ASSERT( deleted, LOG( "RadioUiEnginePrivate::~RadioUiEnginePrivate(). Failed to remove P&S key" ) );
       
    65 #endif
       
    66 }
       
    67 
       
    68 /*!
       
    69  *
       
    70  */
       
    71 RadioUiEngine& RadioUiEnginePrivate::api()
       
    72 {
       
    73     Q_Q( RadioUiEngine );
       
    74     return *q;
       
    75 }
       
    76 
       
    77 /*!
       
    78  *
       
    79  */
       
    80 bool RadioUiEnginePrivate::init()
       
    81 {
       
    82     mControlService.reset( new RadioControlService( *q_ptr ) );
       
    83     mMonitorService.reset( new RadioMonitorService( *this ) );
       
    84     mStationModel.reset( new RadioStationModel( *this ) );
       
    85 
       
    86     mEngineWrapper.reset( new RadioEngineWrapper( mStationModel->stationHandlerIf() ) );
       
    87     if ( !mEngineWrapper->init() ) {
       
    88         return false;
       
    89     }
       
    90     mEngineWrapper->addObserver( this );
       
    91 
       
    92     mPresetStorage.reset( new RadioPresetStorage() );
       
    93     mStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
       
    94     mHistoryModel.reset( new RadioHistoryModel( *q_ptr ) );
       
    95 
       
    96 #ifndef BUILD_WIN32
       
    97     // Write the startup timestamp to P&S key for the homescreen widget
       
    98     XQSettingsManager settingsManager;
       
    99     XQPublishAndSubscribeUtils utils( settingsManager );
       
   100     XQPublishAndSubscribeSettingsKey radioStartupKey( KRadioPSUid, KRadioStartupKey );
       
   101     bool defined = utils.defineProperty( radioStartupKey, XQSettingsManager::TypeInt );
       
   102     if ( defined ) {
       
   103         settingsManager.writeItemValue( radioStartupKey, (int)QDateTime::currentDateTime().toTime_t() );
       
   104     }
       
   105 #endif
       
   106 
       
   107     mMonitorService->init();
       
   108 
       
   109     return true;
       
   110 }
       
   111 
       
   112 /*!
       
   113  *
       
   114  */
       
   115 void RadioUiEnginePrivate::cancelSeeking()
       
   116 {
       
   117     mEngineWrapper->cancelSeeking();
       
   118 }
       
   119 
       
   120 /*!
       
   121  *
       
   122  */
       
   123 RadioEngineWrapper& RadioUiEnginePrivate::wrapper()
       
   124 {
       
   125     return *mEngineWrapper;
       
   126 }
       
   127 
       
   128 /*!
       
   129  *
       
   130  */
       
   131 void RadioUiEnginePrivate::tunedToFrequency( uint frequency, int reason )
       
   132 {
       
   133     Q_Q( RadioUiEngine );
       
   134     q->emitTunedToFrequency( frequency, reason );
       
   135 }
       
   136 
       
   137 /*!
       
   138  *
       
   139  */
       
   140 void RadioUiEnginePrivate::radioStatusChanged( bool radioIsOn )
       
   141 {
       
   142     Q_Q( RadioUiEngine );
       
   143     q->emitRadioStatusChanged( radioIsOn );
       
   144 }
       
   145 
       
   146 /*!
       
   147  *
       
   148  */
       
   149 void RadioUiEnginePrivate::rdsAvailabilityChanged( bool available )
       
   150 {
       
   151     Q_Q( RadioUiEngine );
       
   152     q->emitRdsAvailabilityChanged( available );
       
   153 }
       
   154 
       
   155 /*!
       
   156  *
       
   157  */
       
   158 void RadioUiEnginePrivate::increaseVolume()
       
   159 {
       
   160     Q_Q( RadioUiEngine );
       
   161     if( q->isScanning() ){
       
   162         // volume not changed while scanning
       
   163     } else {
       
   164         mEngineWrapper->increaseVolume();
       
   165     }
       
   166 }
       
   167 
       
   168 /*!
       
   169  *
       
   170  */
       
   171 void RadioUiEnginePrivate::decreaseVolume()
       
   172 {
       
   173     Q_Q( RadioUiEngine );
       
   174     if( q->isScanning() ) {
       
   175         // volume not changed while scanning
       
   176     } else {
       
   177         mEngineWrapper->decreaseVolume();
       
   178     }
       
   179 }
       
   180 
       
   181 /*!
       
   182  *
       
   183  */
       
   184 void RadioUiEnginePrivate::volumeChanged( int volume )
       
   185 {
       
   186     Q_Q( RadioUiEngine );
       
   187     q->emitVolumeChanged( volume );
       
   188 }
       
   189 
       
   190 /*!
       
   191  *
       
   192  */
       
   193 void RadioUiEnginePrivate::muteChanged( bool muted )
       
   194 {
       
   195     Q_Q( RadioUiEngine );
       
   196     q->emitMuteChanged( muted );
       
   197 }
       
   198 
       
   199 /*!
       
   200  *
       
   201  */
       
   202 void RadioUiEnginePrivate::audioRouteChanged( bool loudspeaker )
       
   203 {
       
   204     Q_Q( RadioUiEngine );
       
   205     q->emitAudioRouteChanged( loudspeaker );
       
   206 }
       
   207 
       
   208 /*!
       
   209  *
       
   210  */
       
   211 void RadioUiEnginePrivate::antennaStatusChanged( bool connected )
       
   212 {
       
   213     Q_Q( RadioUiEngine );
       
   214     q->emitAntennaStatusChanged( connected );
       
   215 }
       
   216 
       
   217 /*!
       
   218  *
       
   219  */
       
   220 void RadioUiEnginePrivate::skipPrevious()
       
   221 {
       
   222     skip( StationSkip::PreviousFavorite, 0, TuneReason::SkipFromEngine );
       
   223 }
       
   224 
       
   225 /*!
       
   226  *
       
   227  */
       
   228 void RadioUiEnginePrivate::skipNext()
       
   229 {
       
   230     skip( StationSkip::NextFavorite, 0, TuneReason::SkipFromEngine );
       
   231 }
       
   232 
       
   233 /*!
       
   234  * Tunes to next or previous station
       
   235  */
       
   236 uint RadioUiEnginePrivate::skip( StationSkip::Mode mode, uint startFrequency, const int reason )
       
   237 {
       
   238     LOG_FORMAT( "RadioUiEnginePrivate::skip: mode: %d", mode );
       
   239     if ( startFrequency == 0 ) {
       
   240         startFrequency = mEngineWrapper->currentFrequency();
       
   241     }
       
   242 
       
   243     const int favoriteCount = mStationModel->favoriteCount();
       
   244     if ( favoriteCount < 2 ) {
       
   245         if ( mode == StationSkip::NextFavorite ) {
       
   246             mode = StationSkip::Next;
       
   247         } else if ( mode == StationSkip::PreviousFavorite ) {
       
   248             mode = StationSkip::Previous;
       
   249         }
       
   250     }
       
   251 
       
   252     const RadioStation station = mStationModel->findClosest( startFrequency, mode );
       
   253     if ( station.isValid() ) {
       
   254         const uint newFrequency = station.frequency();
       
   255 
       
   256         LOG_FORMAT( "RadioUiEnginePrivate::skip. CurrentFreq: %u, tuning to: %u", startFrequency, newFrequency );
       
   257         mEngineWrapper->setFrequency( newFrequency, reason );
       
   258         return newFrequency;
       
   259     }
       
   260     return startFrequency;
       
   261 }
       
   262