radioapp/radiouiengine/inc/radiostation.h
changeset 34 bc10a61bd7d3
parent 28 075425b8d9a4
child 36 ba22309243a1
--- a/radioapp/radiouiengine/inc/radiostation.h	Fri Jun 11 13:38:32 2010 +0300
+++ b/radioapp/radiouiengine/inc/radiostation.h	Fri Jun 25 19:09:05 2010 +0300
@@ -19,9 +19,10 @@
 #define RADIOSTATION_H_
 
 // System includes
+#include <QObject>
+#include <QSharedDataPointer>
 #include <QString>
 #include <QMetaType>
-#include <QObject>
 
 // User includes
 #include "radiouiengineexport.h"
@@ -49,7 +50,7 @@
     friend class RadioStationModelPrivate;
     friend class TestRadioUiEngine;
     friend class TestRadioPresetStorage;
-    
+
 public:
 
     /**
@@ -81,7 +82,7 @@
        Favorite         = 1 << 0,
        LocalStation     = 1 << 1,
        PreDefined       = 1 << 2,
-       Temporary        = 1 << 3
+       ManualStation    = 1 << 3
     };
     Q_DECLARE_FLAGS( Type, TypeFlag )
 
@@ -101,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 };
 
@@ -116,7 +118,7 @@
 
     RadioStation& operator=( const RadioStation& other );
 
-public:
+private:
 
     explicit RadioStation( int presetIndex, uint frequency );
 
@@ -149,8 +151,7 @@
 
     int genre() const;
 
-    QString frequencyMhz() const;
-    QString nameOrFrequencyMhz() const;
+    QString frequencyString() const;
     uint frequency() const;
     int presetIndex() const;
 
@@ -159,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;
@@ -178,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 );
@@ -196,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; }
 
 };