radioapp/radiowidgets/src/radioutil.cpp
changeset 28 075425b8d9a4
child 32 189d20c34778
equal deleted inserted replaced
24:6df133bd92e1 28:075425b8d9a4
       
     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 <HbEffect>
       
    20 #include <HbNotificationDialog>
       
    21 
       
    22 // User includes
       
    23 #include "radioutil.h"
       
    24 #include "radiofrequencystrip.h"
       
    25 #include "radiostationcarousel.h"
       
    26 #include "radiofrequencyscanner.h"
       
    27 #include "radiologger.h"
       
    28 
       
    29 // Constants
       
    30 
       
    31 static RadioUtil* theInstance = 0;
       
    32 
       
    33 /*!
       
    34  *
       
    35  */
       
    36 RadioUtil::RadioUtil() :
       
    37     mScanStatus( Scan::NotScanning )
       
    38 {
       
    39 }
       
    40 
       
    41 /*!
       
    42  *
       
    43  */
       
    44 RadioUtil::~RadioUtil()
       
    45 {
       
    46 }
       
    47 
       
    48 /*!
       
    49  *
       
    50  */
       
    51 bool RadioUtil::addEffects( QEffectList list )
       
    52 {
       
    53     bool allAvailable = true;
       
    54     QEffectList added;
       
    55     foreach ( EffectInfo info, list ) {
       
    56 #ifdef USE_LAYOUT_FROM_E_DRIVE
       
    57         info.mPath.replace( QString( ":/" ), QString( "e:/radiotest/" ) );
       
    58 #endif
       
    59         if ( HbEffect::add( info.mItem, info.mPath, info.mEvent ) ) {
       
    60             added.append( info );
       
    61         } else {
       
    62             allAvailable = false;
       
    63             break;
       
    64         }
       
    65     }
       
    66 
       
    67     if ( !allAvailable ) {
       
    68         foreach ( const EffectInfo& info, added ) {
       
    69             HbEffect::remove( info.mItem, info.mPath, info.mEvent );
       
    70         }
       
    71     }
       
    72 
       
    73     return allAvailable;
       
    74 }
       
    75 
       
    76 
       
    77 /*!
       
    78  *
       
    79  */
       
    80 RadioFrequencyStrip* RadioUtil::frequencyStrip()
       
    81 {
       
    82     return instance().mFrequencyStrip;
       
    83 }
       
    84 
       
    85 /*!
       
    86  *
       
    87  */
       
    88 RadioStationCarousel* RadioUtil::carousel()
       
    89 {
       
    90     return instance().mCarousel;
       
    91 }
       
    92 
       
    93 /*!
       
    94  *
       
    95  */
       
    96 bool RadioUtil::isScannerAlive()
       
    97 {
       
    98     RadioFrequencyScanner* scanner = instance().mScanner;
       
    99     if ( scanner ) {
       
   100         return scanner->isAlive();
       
   101     }
       
   102     return false;
       
   103 }
       
   104 
       
   105 /*!
       
   106  *
       
   107  */
       
   108 Scan::Status RadioUtil::scanStatus()
       
   109 {
       
   110     return instance().mScanStatus;
       
   111 }
       
   112 
       
   113 /*!
       
   114  *
       
   115  */
       
   116 void RadioUtil::setFrequencyStrip( RadioFrequencyStrip* frequencyStrip )
       
   117 {
       
   118     instance().mFrequencyStrip = frequencyStrip;
       
   119 }
       
   120 
       
   121 /*!
       
   122  *
       
   123  */
       
   124 void RadioUtil::setCarousel( RadioStationCarousel* carousel )
       
   125 {
       
   126     instance().mCarousel = carousel;
       
   127 }
       
   128 
       
   129 /*!
       
   130  *
       
   131  */
       
   132 void RadioUtil::setFrequencyScanner( RadioFrequencyScanner* scanner )
       
   133 {
       
   134     instance().mScanner = scanner;
       
   135 }
       
   136 
       
   137 /*!
       
   138  *
       
   139  */
       
   140 void RadioUtil::setScanStatus( Scan::Status status )
       
   141 {
       
   142     instance().mScanStatus = status;
       
   143 }
       
   144 
       
   145 /*!
       
   146  *
       
   147  */
       
   148 Scroll::Direction RadioUtil::scrollDirectionFromSkipMode( int skipMode )
       
   149 {
       
   150     return ( skipMode == StationSkip::Next || skipMode == StationSkip::NextFavorite )
       
   151            ? Scroll::Left : Scroll::Right;
       
   152 }
       
   153 
       
   154 /*!
       
   155  *
       
   156  */
       
   157 Scroll::Direction RadioUtil::scrollDirection( int direction )
       
   158 {
       
   159     return static_cast<Scroll::Direction>( direction );
       
   160 }
       
   161 
       
   162 /*!
       
   163  *
       
   164  */
       
   165 TuneReason::Reason RadioUtil::tuneReason( int tuneReason )
       
   166 {
       
   167     return static_cast<TuneReason::Reason>( tuneReason );
       
   168 }
       
   169 
       
   170 /*!
       
   171  *
       
   172  */
       
   173 void RadioUtil::showDiscreetNote( const QString& text )
       
   174 {
       
   175     RadioUtil& self = instance();
       
   176     if ( !self.mNotificationDialog ) {
       
   177         self.mNotificationDialog = new HbNotificationDialog();
       
   178     }
       
   179     self.mNotificationDialog->setAttribute( Qt::WA_DeleteOnClose );
       
   180     self.mNotificationDialog->setTitle( text );
       
   181     self.mNotificationDialog->show();
       
   182 }
       
   183 
       
   184 /*!
       
   185  *
       
   186  */
       
   187 RadioUtil& RadioUtil::instance()
       
   188 {
       
   189     if ( !::theInstance ) {
       
   190         ::theInstance = new RadioUtil;
       
   191     }
       
   192     return *::theInstance;
       
   193 }
       
   194