radioapp/radiouiengine/inc/radiostation.h
changeset 23 a2b50a479edf
parent 19 afea38384506
child 24 6df133bd92e1
equal deleted inserted replaced
19:afea38384506 23:a2b50a479edf
     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 #ifndef RADIOSTATION_H_
       
    19 #define RADIOSTATION_H_
       
    20 
       
    21 // System includes
       
    22 #include <QString>
       
    23 #include <QMetaType>
       
    24 #include <QObject>
       
    25 
       
    26 // User includes
       
    27 #include "radiouiengineexport.h"
       
    28 #include "radio_global.h"
       
    29 
       
    30 // Constants
       
    31 const int KLastCallSignCharCode = 25;
       
    32 const uint KThreeLetterCallSignCount = 72;
       
    33 const uint KKxxxCallSignPiFirst = 0x1000;
       
    34 const uint KWxxxCallSignPiFirst = 0x54A8;
       
    35 const uint KWxxxCallSignPiLast = 0x994F;
       
    36 const uint KxxxCallSignPiFirst = 0x9950;
       
    37 const uint KxxxCallSignPiLast = 0x99B9;
       
    38 
       
    39 // Forward declarations
       
    40 class RadioStationPrivate;
       
    41 
       
    42 // Class declaration
       
    43 
       
    44 /*!
       
    45  * RadioStation is a data container that holds all information of a radio station.
       
    46  * It is implicitly shared to make it cheap to copy and pass around as a signal parameter.
       
    47  * It uses the "shared null" idiom to initialize empty instances quickly and efficiently.
       
    48  *
       
    49  * Note! It is derived from QObject even though architecturally it shouldn't be.
       
    50  * It is done only to satisfy the WINSCW build which doesn't export the destructor in UREL
       
    51  * build. This causes mismatching def files and annoying warnings. Deriving from QObject fixes this
       
    52  */
       
    53 class UI_ENGINE_DLL_EXPORT RadioStation : public QObject
       
    54 {
       
    55     friend class RadioStationModel;
       
    56     friend class RadioStationModelPrivate;
       
    57     friend class TestRadioUiEngine;
       
    58     friend class TestRadioPresetStorage;
       
    59     
       
    60 public:
       
    61 
       
    62     /**
       
    63      * Flags to indicate how the RadioStation has changed since last save or reset.
       
    64      * Declared to use QFlags<> to ease flag usage and to enforce type safety
       
    65      */
       
    66     enum ChangeFlag
       
    67     {
       
    68          NoChange               = 0
       
    69         ,PersistentDataChanged  = 1 << 0
       
    70         ,NameChanged            = 1 << 1
       
    71         ,FavoriteChanged        = 1 << 2
       
    72         ,GenreChanged           = 1 << 3
       
    73         ,UrlChanged             = 1 << 4
       
    74         ,TypeChanged            = 1 << 5
       
    75         ,PiCodeChanged          = 1 << 6
       
    76         ,PsTypeChanged          = 1 << 7
       
    77         ,RadioTextChanged       = 1 << 8
       
    78         ,DynamicPsChanged       = 1 << 9
       
    79     };
       
    80     Q_DECLARE_FLAGS( Change, ChangeFlag )
       
    81 
       
    82     /**
       
    83      * Flags ot indicate station type.
       
    84      * Declared to use QFlags<> to ease flag usage and to enforce type safety
       
    85      */
       
    86     enum TypeFlag
       
    87     {
       
    88        Favorite         = 1 << 0,
       
    89        LocalStation     = 1 << 1,
       
    90        PreDefined       = 1 << 2,
       
    91        Temporary        = 1 << 3
       
    92     };
       
    93     Q_DECLARE_FLAGS( Type, TypeFlag )
       
    94 
       
    95     /**
       
    96      * Flag to indiate whether or not station uses dynamic PS and if the check has been performed
       
    97      * Declared to use QFlags<> to ease flag usage and to enforce type safety
       
    98      */
       
    99     enum PsTypeFlag
       
   100     {
       
   101         Unknown,
       
   102         Dynamic,
       
   103         Static
       
   104     };
       
   105     Q_DECLARE_FLAGS( PsType, PsTypeFlag )
       
   106 
       
   107     /**
       
   108      * Magical values used as preset indexes to signify certain conditions.
       
   109      * NotFound means that a find function could not find a station
       
   110      * Invalid means that the station instance has not been initialized
       
   111      */
       
   112     enum PresetFlag { NotFound = -1, Invalid = -100, SharedNull = -200 };
       
   113 
       
   114     /**
       
   115      * Static convenience function to parse a frequency
       
   116      */
       
   117     static QString parseFrequency( uint frequency );
       
   118 
       
   119     RadioStation();
       
   120     RadioStation( const RadioStation& other );
       
   121 
       
   122     ~RadioStation();
       
   123 
       
   124     RadioStation& operator=( const RadioStation& other );
       
   125 
       
   126 public:
       
   127 
       
   128     explicit RadioStation( int presetIndex, uint frequency );
       
   129 
       
   130     void reset();
       
   131     void setChangeFlags( Change flags );
       
   132 
       
   133     // Setters for persistent data
       
   134     void setPresetIndex( int presetIndex );
       
   135     void setFrequency( uint frequency );
       
   136     void setName( const QString& name );
       
   137     void setGenre( const int genre );
       
   138     void setUrl( const QString& url );
       
   139     bool setPiCode( int piCode, RadioRegion::Region region );
       
   140 
       
   141     // Setters for non-persistent data
       
   142     void setPsType( PsType psType );
       
   143     void setRadioText( const QString& radioText );
       
   144     void setRadioTextPlus( const int rtPlusClass, const QString& rtPlusItem );
       
   145     void setDynamicPsText( const QString& dynamicPsText );
       
   146 
       
   147 public: // Getters and setters
       
   148 
       
   149     // Setters & Getters for persistent data
       
   150 
       
   151     bool isValid() const;
       
   152 
       
   153     QString name() const;
       
   154     void setUserDefinedName( const QString& name );
       
   155     bool isRenamed() const;
       
   156 
       
   157     int genre() const;
       
   158 
       
   159     QString frequencyMhz() const;
       
   160     uint frequency() const;
       
   161     int presetIndex() const;
       
   162 
       
   163     void setFavorite( bool favorite );
       
   164     bool isFavorite() const;
       
   165 
       
   166     QString url() const;
       
   167 
       
   168     bool hasPiCode() const;
       
   169     bool hasRds() const;
       
   170 
       
   171     void setType( RadioStation::Type type );
       
   172     void unsetType( RadioStation::Type type );
       
   173     bool isType( RadioStation::Type type ) const;
       
   174 
       
   175     // Getters for non-persistent data
       
   176 
       
   177     PsType psType() const;
       
   178     QString radioText() const;
       
   179     QString dynamicPsText() const;
       
   180     Change changeFlags() const;
       
   181     bool hasDataChanged( Change flags ) const;
       
   182     bool hasChanged() const;
       
   183     void resetChangeFlags();
       
   184 
       
   185 private:
       
   186 
       
   187     /**
       
   188      * Decrements the reference count of the implicitly shared data.
       
   189      * Data is deleted if no instance uses it anymore.
       
   190      */
       
   191     void decrementReferenceCount();
       
   192 
       
   193     // Methods for converting PI code into call sign
       
   194     QString piCodeToCallSign( uint programmeIdentification );
       
   195     QString iterateCallSign( int piBase, int programmeIdentification );
       
   196     QString callSignString( uint programmeIdentification );
       
   197     char callSignChar( uint decimalValue );
       
   198 
       
   199 private: // data
       
   200 
       
   201     /**
       
   202      * Pointer to the implicitly shared private implementation
       
   203      * Own.
       
   204      */
       
   205     class RadioStationPrivate* mData;
       
   206 
       
   207 public:
       
   208 
       
   209     /**
       
   210      * Detach from the implicitly shared data
       
   211      */
       
   212     void detach();
       
   213 
       
   214     /**
       
   215      * Checks if the class is detached from implicitly shared data
       
   216      * Required by many QT convenience functions for implicitly shared classes
       
   217      */
       
   218     bool isDetached() const;
       
   219 
       
   220     typedef RadioStationPrivate* DataPtr;
       
   221     inline DataPtr &data_ptr() { return mData; }
       
   222 
       
   223 };
       
   224 
       
   225 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Change )
       
   226 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Type )
       
   227 
       
   228 Q_DECLARE_TYPEINFO( RadioStation, Q_MOVABLE_TYPE );  // Can be moved around in memory by containers if necessary
       
   229 Q_DECLARE_SHARED( RadioStation )                     // Uses implicit sharing
       
   230 Q_DECLARE_METATYPE( RadioStation )                   // To be usable in a QVariant
       
   231 
       
   232 #endif // RADIOSTATION_H_