radioapp/radiouiengine/inc/radiostation.h
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 16 f54ebcfc1b80
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    17 
    17 
    18 #ifndef RADIOSTATION_H_
    18 #ifndef RADIOSTATION_H_
    19 #define RADIOSTATION_H_
    19 #define RADIOSTATION_H_
    20 
    20 
    21 // System includes
    21 // System includes
       
    22 #include <QObject>
       
    23 #include <QSharedDataPointer>
    22 #include <QString>
    24 #include <QString>
    23 #include <QMetaType>
    25 #include <QMetaType>
    24 #include <QObject>
       
    25 
    26 
    26 // User includes
    27 // User includes
    27 #include "radiouiengineexport.h"
    28 #include "radiouiengineexport.h"
    28 #include "radio_global.h"
    29 #include "radio_global.h"
    29 
    30 
    30 // Constants
    31 // 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 
    32 
    39 // Forward declarations
    33 // Forward declarations
    40 class RadioStationPrivate;
    34 class RadioStationPrivate;
    41 
    35 
    42 // Class declaration
    36 // Class declaration
    54 {
    48 {
    55     friend class RadioStationModel;
    49     friend class RadioStationModel;
    56     friend class RadioStationModelPrivate;
    50     friend class RadioStationModelPrivate;
    57     friend class TestRadioUiEngine;
    51     friend class TestRadioUiEngine;
    58     friend class TestRadioPresetStorage;
    52     friend class TestRadioPresetStorage;
    59     
    53 
    60 public:
    54 public:
    61 
    55 
    62     /**
    56     /**
    63      * Flags to indicate how the RadioStation has changed since last save or reset.
    57      * 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
    58      * Declared to use QFlags<> to ease flag usage and to enforce type safety
    86     enum TypeFlag
    80     enum TypeFlag
    87     {
    81     {
    88        Favorite         = 1 << 0,
    82        Favorite         = 1 << 0,
    89        LocalStation     = 1 << 1,
    83        LocalStation     = 1 << 1,
    90        PreDefined       = 1 << 2,
    84        PreDefined       = 1 << 2,
    91        Temporary        = 1 << 3
    85        ManualStation    = 1 << 3
    92     };
    86     };
    93     Q_DECLARE_FLAGS( Type, TypeFlag )
    87     Q_DECLARE_FLAGS( Type, TypeFlag )
    94 
    88 
    95     /**
    89     /**
    96      * Flag to indiate whether or not station uses dynamic PS and if the check has been performed
    90      * Flag to indiate whether or not station uses dynamic PS and if the check has been performed
   106 
   100 
   107     /**
   101     /**
   108      * Magical values used as preset indexes to signify certain conditions.
   102      * Magical values used as preset indexes to signify certain conditions.
   109      * NotFound means that a find function could not find a station
   103      * NotFound means that a find function could not find a station
   110      * Invalid means that the station instance has not been initialized
   104      * Invalid means that the station instance has not been initialized
       
   105      * SharedNull identifies the empty "null" station that every newly created station points to
   111      */
   106      */
   112     enum PresetFlag { NotFound = -1, Invalid = -100, SharedNull = -200 };
   107     enum PresetFlag { NotFound = -1, Invalid = -100, SharedNull = -200 };
   113 
   108 
   114     /**
   109     /**
   115      * Static convenience function to parse a frequency
   110      * Static convenience function to parse a frequency
   121 
   116 
   122     ~RadioStation();
   117     ~RadioStation();
   123 
   118 
   124     RadioStation& operator=( const RadioStation& other );
   119     RadioStation& operator=( const RadioStation& other );
   125 
   120 
   126 public:
   121 private:
   127 
   122 
   128     explicit RadioStation( int presetIndex, uint frequency );
   123     explicit RadioStation( int presetIndex, uint frequency );
   129 
   124 
   130     void reset();
   125     void reset();
   131     void setChangeFlags( Change flags );
   126     void setChangeFlags( Change flags );
   154     void setUserDefinedName( const QString& name );
   149     void setUserDefinedName( const QString& name );
   155     bool isRenamed() const;
   150     bool isRenamed() const;
   156 
   151 
   157     int genre() const;
   152     int genre() const;
   158 
   153 
   159     QString frequencyMhz() const;
   154     QString frequencyString() const;
   160     uint frequency() const;
   155     uint frequency() const;
   161     int presetIndex() const;
   156     int presetIndex() const;
   162 
   157 
   163     void setFavorite( bool favorite );
   158     void setFavorite( bool favorite );
   164     bool isFavorite() const;
   159     bool isFavorite() const;
   165 
   160 
   166     QString url() const;
   161     QString url() const;
   167 
   162 
   168     bool hasPiCode() const;
   163     int piCode() const;
   169     bool hasRds() const;
       
   170 
   164 
   171     void setType( RadioStation::Type type );
   165     void setType( RadioStation::Type type );
   172     void unsetType( RadioStation::Type type );
   166     void unsetType( RadioStation::Type type );
   173     bool isType( RadioStation::Type type ) const;
   167     bool isType( RadioStation::Type type ) const;
       
   168 
       
   169     // Convenience checkers
       
   170 
       
   171     inline bool hasPiCode() const       { return piCode() != -1; }
       
   172     inline bool hasName() const         { return !name().isEmpty(); }
       
   173     inline bool hasUrl() const          { return !url().isEmpty(); }
       
   174     inline bool hasRadiotext() const    { return !radioText().isEmpty(); }
       
   175     inline bool hasDynamicPs() const    { return !dynamicPsText().isEmpty(); }
       
   176     inline bool hasGenre() const        { return genre() != -1; }
       
   177     inline bool hasRds() const          { return hasPiCode() || hasGenre() || hasDynamicPs() ||
       
   178                                                  hasRadiotext() || hasUrl() || ( !hasName() && !isRenamed() ); }
   174 
   179 
   175     // Getters for non-persistent data
   180     // Getters for non-persistent data
   176 
   181 
   177     PsType psType() const;
   182     PsType psType() const;
   178     QString radioText() const;
   183     QString radioText() const;
   182     bool hasChanged() const;
   187     bool hasChanged() const;
   183     void resetChangeFlags();
   188     void resetChangeFlags();
   184 
   189 
   185 private:
   190 private:
   186 
   191 
   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
   192     // Methods for converting PI code into call sign
   194     QString piCodeToCallSign( uint programmeIdentification );
   193     QString piCodeToCallSign( uint programmeIdentification );
   195     QString iterateCallSign( int piBase, int programmeIdentification );
   194     QString iterateCallSign( int piBase, int programmeIdentification );
   196     QString callSignString( uint programmeIdentification );
   195     QString callSignString( uint programmeIdentification );
   197     char callSignChar( uint decimalValue );
   196     char callSignChar( uint decimalValue );
   200 
   199 
   201     /**
   200     /**
   202      * Pointer to the implicitly shared private implementation
   201      * Pointer to the implicitly shared private implementation
   203      * Own.
   202      * Own.
   204      */
   203      */
   205     class RadioStationPrivate* mData;
   204     QSharedDataPointer<RadioStationPrivate> mData;
   206 
   205 
   207 public:
   206 public:
   208 
       
   209     /**
       
   210      * Detach from the implicitly shared data
       
   211      */
       
   212     void detach();
       
   213 
   207 
   214     /**
   208     /**
   215      * Checks if the class is detached from implicitly shared data
   209      * Checks if the class is detached from implicitly shared data
   216      * Required by many QT convenience functions for implicitly shared classes
   210      * Required by many QT convenience functions for implicitly shared classes
   217      */
   211      */
   218     bool isDetached() const;
   212     bool isDetached() const;
   219 
   213 
   220     typedef RadioStationPrivate* DataPtr;
   214     typedef QSharedDataPointer<RadioStationPrivate> DataPtr;
   221     inline DataPtr &data_ptr() { return mData; }
   215     inline DataPtr& data_ptr() { return mData; }
   222 
   216 
   223 };
   217 };
   224 
   218 
   225 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Change )
   219 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Change )
   226 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Type )
   220 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Type )