radioapp/radiouiengine/inc/radiostation.h
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 16 f54ebcfc1b80
parent 33 11b6825f0862
--- a/radioapp/radiouiengine/inc/radiostation.h	Fri Jun 11 16:24:13 2010 +0100
+++ b/radioapp/radiouiengine/inc/radiostation.h	Thu Jul 22 16:33:45 2010 +0100
@@ -19,22 +19,16 @@
 #define RADIOSTATION_H_
 
 // System includes
+#include <QObject>
+#include <QSharedDataPointer>
 #include <QString>
 #include <QMetaType>
-#include <QObject>
 
 // User includes
 #include "radiouiengineexport.h"
 #include "radio_global.h"
 
 // Constants
-const int KLastCallSignCharCode = 25;
-const uint KThreeLetterCallSignCount = 72;
-const uint KKxxxCallSignPiFirst = 0x1000;
-const uint KWxxxCallSignPiFirst = 0x54A8;
-const uint KWxxxCallSignPiLast = 0x994F;
-const uint KxxxCallSignPiFirst = 0x9950;
-const uint KxxxCallSignPiLast = 0x99B9;
 
 // Forward declarations
 class RadioStationPrivate;
@@ -56,7 +50,7 @@
     friend class RadioStationModelPrivate;
     friend class TestRadioUiEngine;
     friend class TestRadioPresetStorage;
-    
+
 public:
 
     /**
@@ -88,7 +82,7 @@
        Favorite         = 1 << 0,
        LocalStation     = 1 << 1,
        PreDefined       = 1 << 2,
-       Temporary        = 1 << 3
+       ManualStation    = 1 << 3
     };
     Q_DECLARE_FLAGS( Type, TypeFlag )
 
@@ -108,6 +102,7 @@
      * Magical values used as preset indexes to signify certain conditions.
      * NotFound means that a find function could not find a station
      * Invalid means that the station instance has not been initialized
+     * SharedNull identifies the empty "null" station that every newly created station points to
      */
     enum PresetFlag { NotFound = -1, Invalid = -100, SharedNull = -200 };
 
@@ -123,7 +118,7 @@
 
     RadioStation& operator=( const RadioStation& other );
 
-public:
+private:
 
     explicit RadioStation( int presetIndex, uint frequency );
 
@@ -156,7 +151,7 @@
 
     int genre() const;
 
-    QString frequencyMhz() const;
+    QString frequencyString() const;
     uint frequency() const;
     int presetIndex() const;
 
@@ -165,13 +160,23 @@
 
     QString url() const;
 
-    bool hasPiCode() const;
-    bool hasRds() const;
+    int piCode() const;
 
     void setType( RadioStation::Type type );
     void unsetType( RadioStation::Type type );
     bool isType( RadioStation::Type type ) const;
 
+    // Convenience checkers
+
+    inline bool hasPiCode() const       { return piCode() != -1; }
+    inline bool hasName() const         { return !name().isEmpty(); }
+    inline bool hasUrl() const          { return !url().isEmpty(); }
+    inline bool hasRadiotext() const    { return !radioText().isEmpty(); }
+    inline bool hasDynamicPs() const    { return !dynamicPsText().isEmpty(); }
+    inline bool hasGenre() const        { return genre() != -1; }
+    inline bool hasRds() const          { return hasPiCode() || hasGenre() || hasDynamicPs() ||
+                                                 hasRadiotext() || hasUrl() || ( !hasName() && !isRenamed() ); }
+
     // Getters for non-persistent data
 
     PsType psType() const;
@@ -184,12 +189,6 @@
 
 private:
 
-    /**
-     * Decrements the reference count of the implicitly shared data.
-     * Data is deleted if no instance uses it anymore.
-     */
-    void decrementReferenceCount();
-
     // Methods for converting PI code into call sign
     QString piCodeToCallSign( uint programmeIdentification );
     QString iterateCallSign( int piBase, int programmeIdentification );
@@ -202,23 +201,18 @@
      * Pointer to the implicitly shared private implementation
      * Own.
      */
-    class RadioStationPrivate* mData;
+    QSharedDataPointer<RadioStationPrivate> mData;
 
 public:
 
     /**
-     * Detach from the implicitly shared data
-     */
-    void detach();
-
-    /**
      * Checks if the class is detached from implicitly shared data
      * Required by many QT convenience functions for implicitly shared classes
      */
     bool isDetached() const;
 
-    typedef RadioStationPrivate* DataPtr;
-    inline DataPtr &data_ptr() { return mData; }
+    typedef QSharedDataPointer<RadioStationPrivate> DataPtr;
+    inline DataPtr& data_ptr() { return mData; }
 
 };