radioapp/radiouiengine/inc/radiostation.h
changeset 32 189d20c34778
parent 28 075425b8d9a4
child 33 11b6825f0862
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
    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 
    47 {
    48 {
    48     friend class RadioStationModel;
    49     friend class RadioStationModel;
    49     friend class RadioStationModelPrivate;
    50     friend class RadioStationModelPrivate;
    50     friend class TestRadioUiEngine;
    51     friend class TestRadioUiEngine;
    51     friend class TestRadioPresetStorage;
    52     friend class TestRadioPresetStorage;
    52     
    53 
    53 public:
    54 public:
    54 
    55 
    55     /**
    56     /**
    56      * 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.
    57      * 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
    79     enum TypeFlag
    80     enum TypeFlag
    80     {
    81     {
    81        Favorite         = 1 << 0,
    82        Favorite         = 1 << 0,
    82        LocalStation     = 1 << 1,
    83        LocalStation     = 1 << 1,
    83        PreDefined       = 1 << 2,
    84        PreDefined       = 1 << 2,
    84        Temporary        = 1 << 3
    85        ManualStation    = 1 << 3
    85     };
    86     };
    86     Q_DECLARE_FLAGS( Type, TypeFlag )
    87     Q_DECLARE_FLAGS( Type, TypeFlag )
    87 
    88 
    88     /**
    89     /**
    89      * 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
    99 
   100 
   100     /**
   101     /**
   101      * Magical values used as preset indexes to signify certain conditions.
   102      * Magical values used as preset indexes to signify certain conditions.
   102      * NotFound means that a find function could not find a station
   103      * NotFound means that a find function could not find a station
   103      * 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
   104      */
   106      */
   105     enum PresetFlag { NotFound = -1, Invalid = -100, SharedNull = -200 };
   107     enum PresetFlag { NotFound = -1, Invalid = -100, SharedNull = -200 };
   106 
   108 
   107     /**
   109     /**
   108      * Static convenience function to parse a frequency
   110      * Static convenience function to parse a frequency
   114 
   116 
   115     ~RadioStation();
   117     ~RadioStation();
   116 
   118 
   117     RadioStation& operator=( const RadioStation& other );
   119     RadioStation& operator=( const RadioStation& other );
   118 
   120 
   119 public:
   121 private:
   120 
   122 
   121     explicit RadioStation( int presetIndex, uint frequency );
   123     explicit RadioStation( int presetIndex, uint frequency );
   122 
   124 
   123     void reset();
   125     void reset();
   124     void setChangeFlags( Change flags );
   126     void setChangeFlags( Change flags );
   147     void setUserDefinedName( const QString& name );
   149     void setUserDefinedName( const QString& name );
   148     bool isRenamed() const;
   150     bool isRenamed() const;
   149 
   151 
   150     int genre() const;
   152     int genre() const;
   151 
   153 
   152     QString frequencyMhz() const;
   154     QString frequencyString() const;
   153     QString nameOrFrequencyMhz() const;
       
   154     uint frequency() const;
   155     uint frequency() const;
   155     int presetIndex() const;
   156     int presetIndex() const;
   156 
   157 
   157     void setFavorite( bool favorite );
   158     void setFavorite( bool favorite );
   158     bool isFavorite() const;
   159     bool isFavorite() const;
   176     bool hasChanged() const;
   177     bool hasChanged() const;
   177     void resetChangeFlags();
   178     void resetChangeFlags();
   178 
   179 
   179 private:
   180 private:
   180 
   181 
   181     /**
       
   182      * Decrements the reference count of the implicitly shared data.
       
   183      * Data is deleted if no instance uses it anymore.
       
   184      */
       
   185     void decrementReferenceCount();
       
   186 
       
   187     // Methods for converting PI code into call sign
   182     // Methods for converting PI code into call sign
   188     QString piCodeToCallSign( uint programmeIdentification );
   183     QString piCodeToCallSign( uint programmeIdentification );
   189     QString iterateCallSign( int piBase, int programmeIdentification );
   184     QString iterateCallSign( int piBase, int programmeIdentification );
   190     QString callSignString( uint programmeIdentification );
   185     QString callSignString( uint programmeIdentification );
   191     char callSignChar( uint decimalValue );
   186     char callSignChar( uint decimalValue );
   194 
   189 
   195     /**
   190     /**
   196      * Pointer to the implicitly shared private implementation
   191      * Pointer to the implicitly shared private implementation
   197      * Own.
   192      * Own.
   198      */
   193      */
   199     class RadioStationPrivate* mData;
   194     QSharedDataPointer<RadioStationPrivate> mData;
   200 
   195 
   201 public:
   196 public:
   202 
       
   203     /**
       
   204      * Detach from the implicitly shared data
       
   205      */
       
   206     void detach();
       
   207 
   197 
   208     /**
   198     /**
   209      * Checks if the class is detached from implicitly shared data
   199      * Checks if the class is detached from implicitly shared data
   210      * Required by many QT convenience functions for implicitly shared classes
   200      * Required by many QT convenience functions for implicitly shared classes
   211      */
   201      */
   212     bool isDetached() const;
   202     bool isDetached() const;
   213 
   203 
   214     typedef RadioStationPrivate* DataPtr;
   204     typedef QSharedDataPointer<RadioStationPrivate> DataPtr;
   215     inline DataPtr &data_ptr() { return mData; }
   205     inline DataPtr& data_ptr() { return mData; }
   216 
   206 
   217 };
   207 };
   218 
   208 
   219 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Change )
   209 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Change )
   220 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Type )
   210 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStation::Type )