radioapp/radiouiengine/src/radiohistoryitem.cpp
changeset 32 189d20c34778
parent 24 6df133bd92e1
child 37 451b2e1545b2
child 51 bbebb0235466
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
    27 
    27 
    28 /*!
    28 /*!
    29  *
    29  *
    30  */
    30  */
    31 RadioHistoryItem::RadioHistoryItem() :
    31 RadioHistoryItem::RadioHistoryItem() :
    32     QObject( 0 )
    32     mData( shared_null() )
       
    33 {
       
    34     mData->ref.ref();
       
    35 }
       
    36 
       
    37 /*!
       
    38  *
       
    39  */
       
    40 RadioHistoryItem::RadioHistoryItem( const QString& artist, const QString& title ) :
       
    41     mData( new RadioHistoryItemPrivate( artist, title ) )
       
    42 {
       
    43 }
       
    44 
       
    45 /*!
       
    46  *
       
    47  */
       
    48 RadioHistoryItem::RadioHistoryItem( const RadioHistoryItem& other ) :
       
    49     mData( other.mData )
       
    50 {
       
    51 }
       
    52 
       
    53 /*!
       
    54  *
       
    55  */
       
    56 RadioHistoryItem::~RadioHistoryItem()
       
    57 {
       
    58 }
       
    59 
       
    60 /*!
       
    61  *
       
    62  */
       
    63 RadioHistoryItem& RadioHistoryItem::operator=( const RadioHistoryItem& other )
       
    64 {
       
    65     mData = other.mData;
       
    66     return *this;
       
    67 }
       
    68 
       
    69 /*!
       
    70  *
       
    71  */
       
    72 bool RadioHistoryItem::isValid() const
       
    73 {
       
    74     return id() != 0 && !title().isEmpty();
       
    75 }
       
    76 
       
    77 /*!
       
    78  *
       
    79  */
       
    80 void RadioHistoryItem::reset()
    33 {
    81 {
    34     mData = shared_null();
    82     mData = shared_null();
    35     mData->ref.ref();
       
    36 }
       
    37 
       
    38 /*!
       
    39  *
       
    40  */
       
    41 RadioHistoryItem::RadioHistoryItem( const QString& artist, const QString& title ) :
       
    42     QObject( 0 )
       
    43 {
       
    44     mData = new RadioHistoryItemPrivate( artist, title );
       
    45 }
       
    46 
       
    47 /*!
       
    48  *
       
    49  */
       
    50 RadioHistoryItem::RadioHistoryItem( const RadioHistoryItem& other ) :
       
    51     QObject( 0 )
       
    52 {
       
    53     mData = other.mData;
       
    54     mData->ref.ref();
       
    55 }
       
    56 
       
    57 /*!
       
    58  *
       
    59  */
       
    60 RadioHistoryItem::~RadioHistoryItem()
       
    61 {
       
    62     decrementReferenceCount();
       
    63 }
       
    64 
       
    65 /*!
       
    66  *
       
    67  */
       
    68 RadioHistoryItem& RadioHistoryItem::operator=( const RadioHistoryItem& other )
       
    69 {
       
    70     qAtomicAssign( mData, other.mData );
       
    71     return *this;
       
    72 }
       
    73 
       
    74 /*!
       
    75  *
       
    76  */
       
    77 bool RadioHistoryItem::isValid() const
       
    78 {
       
    79     return id() != 0 && !title().isEmpty();
       
    80 }
       
    81 
       
    82 /*!
       
    83  *
       
    84  */
       
    85 void RadioHistoryItem::reset()
       
    86 {
       
    87     decrementReferenceCount();
       
    88     mData = shared_null();
       
    89     mData->ref.ref();
       
    90 }
    83 }
    91 
    84 
    92 /*!
    85 /*!
    93  *
    86  *
    94  */
    87  */
   109  *
   102  *
   110  */
   103  */
   111 void RadioHistoryItem::setArtist( const QString& artist )
   104 void RadioHistoryItem::setArtist( const QString& artist )
   112 {
   105 {
   113     if ( artist.compare( mData->mArtist ) != 0 ) {
   106     if ( artist.compare( mData->mArtist ) != 0 ) {
   114         detach();
       
   115         mData->mArtist = artist;
   107         mData->mArtist = artist;
   116     }
   108     }
   117 }
   109 }
   118 
   110 
   119 /*!
   111 /*!
   128  *
   120  *
   129  */
   121  */
   130 void RadioHistoryItem::setTitle( const QString& title )
   122 void RadioHistoryItem::setTitle( const QString& title )
   131 {
   123 {
   132     if ( title.compare( mData->mTitle ) != 0 ) {
   124     if ( title.compare( mData->mTitle ) != 0 ) {
   133         detach();
       
   134         mData->mTitle = title;
   125         mData->mTitle = title;
   135     }
   126     }
   136 }
   127 }
   137 
   128 
   138 /*!
   129 /*!
   147  *
   138  *
   148  */
   139  */
   149 void RadioHistoryItem::setStation( const QString& station )
   140 void RadioHistoryItem::setStation( const QString& station )
   150 {
   141 {
   151     if ( station.compare( mData->mStation ) != 0 ) {
   142     if ( station.compare( mData->mStation ) != 0 ) {
   152         detach();
       
   153         mData->mStation = station;
   143         mData->mStation = station;
   154     }
   144     }
   155 }
   145 }
   156 
   146 
   157 /*!
   147 /*!
   166  *
   156  *
   167  */
   157  */
   168 void RadioHistoryItem::setFrequency( uint frequency )
   158 void RadioHistoryItem::setFrequency( uint frequency )
   169 {
   159 {
   170     if ( frequency != mData->mFrequency ) {
   160     if ( frequency != mData->mFrequency ) {
   171         detach();
       
   172         mData->mFrequency = frequency;
   161         mData->mFrequency = frequency;
   173     }
   162     }
   174 }
   163 }
   175 
   164 
   176 /*!
   165 /*!
   184 /*!
   173 /*!
   185  *
   174  *
   186  */
   175  */
   187 void RadioHistoryItem::setCurrentTime()
   176 void RadioHistoryItem::setCurrentTime()
   188 {
   177 {
   189     detach();
   178     mData->mTime = QDateTime::currentDateTime();
   190     mData->mTime.currentDateTime();
   179 }
   191 }
       
   192 
       
   193 
   180 
   194 /*!
   181 /*!
   195  *
   182  *
   196  */
   183  */
   197 bool RadioHistoryItem::isTagged() const
   184 bool RadioHistoryItem::isTagged() const
   205 bool RadioHistoryItem::isRecognizedByRds() const
   192 bool RadioHistoryItem::isRecognizedByRds() const
   206 {
   193 {
   207     return mData->mFromRds;
   194     return mData->mFromRds;
   208 }
   195 }
   209 
   196 
   210 /**
   197 /*!
   211  * Decrements the reference count of the implicitly shared data.
   198  *
   212  */
       
   213 void RadioHistoryItem::decrementReferenceCount()
       
   214 {
       
   215     if ( !mData->ref.deref() ) {
       
   216         delete mData;
       
   217         mData = 0;
       
   218     }
       
   219 }
       
   220 
       
   221 /**
       
   222  * Detach from the implicitly shared data
       
   223  */
       
   224 void RadioHistoryItem::detach()
       
   225 {
       
   226     if ( !isDetached() ) {
       
   227         RadioHistoryItemPrivate* newData = new RadioHistoryItemPrivate( *mData );
       
   228 
       
   229         decrementReferenceCount();
       
   230 
       
   231         newData->ref = 1;
       
   232         mData = newData;
       
   233     }
       
   234 }
       
   235 
       
   236 /**
       
   237  * Checks if the class is detached from implicitly shared data
       
   238  */
   199  */
   239 bool RadioHistoryItem::isDetached() const
   200 bool RadioHistoryItem::isDetached() const
   240 {
   201 {
   241     return mData->ref == 1;
   202     return mData->ref == 1;
   242 }
   203 }