qtinternetradio/irqcommon/src/irqisdsdatastructure.cpp
changeset 14 896e9dbc5f19
parent 11 f683e24efca3
child 16 5723da102db1
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
    29     aStream<<serverName<<url<<bitrate;
    29     aStream<<serverName<<url<<bitrate;
    30 }
    30 }
    31 
    31 
    32 //we need to initialize all the member for sometimes, it will 
    32 //we need to initialize all the member for sometimes, it will 
    33 //crash by overflow if we don't do this. 
    33 //crash by overflow if we don't do this. 
    34 EXPORT_C IRQPreset::IRQPreset():uniqID(0),type(0),presetId(0),
    34 IRQPreset::IRQPreset():uniqID(0),type(0),presetId(0),
    35                                 iIsSorted(false),iChannelUrlCount(0)
    35                                 iIsSorted(false),iChannelUrlCount(0)
    36 {
    36 {
    37  
    37  
    38 }
    38 }
    39 
    39 
    40 EXPORT_C IRQPreset::~IRQPreset()
    40 IRQPreset::~IRQPreset()
    41 {
    41 {
    42     urlArray.clear();
    42     urlArray.clear();
    43     logoData.Close();
    43     logoData.Close();
    44 }
    44 }
    45 
    45 
    46 EXPORT_C IRQPreset& IRQPreset::operator =(const IRQPreset& aOther)
    46 IRQPreset& IRQPreset::operator =(const IRQPreset& aOther)
    47 {
    47 {
    48     if (this == &aOther)
    48     if (this == &aOther)
    49         return *this;
    49         return *this;
    50 
    50 
    51     urlArray.clear();
    51     urlArray.clear();
    81     this->iChannelUrlCount = aOther.iChannelUrlCount;
    81     this->iChannelUrlCount = aOther.iChannelUrlCount;
    82     this->uniqID = aOther.uniqID;
    82     this->uniqID = aOther.uniqID;
    83     return *this;
    83     return *this;
    84 }
    84 }
    85 
    85 
    86 EXPORT_C void IRQPreset::internalize(QDataStream &aStream)
    86 void IRQPreset::internalize(QDataStream &aStream)
    87 {
    87 {
    88     aStream>>uniqID>>presetId>>type>>iChannelUrlCount;
    88     aStream>>uniqID>>presetId>>type>>iChannelUrlCount;
    89     
    89     
    90     aStream>>languageCode>>languageName 
    90     aStream>>languageCode>>languageName 
    91            >>countryCode>>countryName
    91            >>countryCode>>countryName
   102         url.internalize(aStream);
   102         url.internalize(aStream);
   103         urlArray.append(url);
   103         urlArray.append(url);
   104     }
   104     }
   105 }
   105 }
   106 
   106 
   107 EXPORT_C void IRQPreset::externalize(QDataStream &aStream) const
   107 void IRQPreset::externalize(QDataStream &aStream) const
   108 {
   108 {
   109     aStream<<uniqID<<presetId<<type<<iChannelUrlCount;
   109     aStream<<uniqID<<presetId<<type<<iChannelUrlCount;
   110     
   110     
   111     aStream<<languageCode<<languageName
   111     aStream<<languageCode<<languageName
   112            <<countryCode<<countryName
   112            <<countryCode<<countryName
   121         urlArray.at(i).externalize(aStream);
   121         urlArray.at(i).externalize(aStream);
   122     }
   122     }
   123 }
   123 }
   124    
   124    
   125 //get the bitrates of the preset. Duplicated bitrate will just save once.
   125 //get the bitrates of the preset. Duplicated bitrate will just save once.
   126 EXPORT_C void IRQPreset::getAvailableBitrates(QList<int>& aBitrates) const
   126 void IRQPreset::getAvailableBitrates(QList<int>& aBitrates) const
   127 {
   127 {
   128     aBitrates.clear();
   128     aBitrates.clear();
   129     int bitrate = 0;
   129     int bitrate = 0;
   130 
   130 
   131     for (int i = 0; i < urlArray.count(); i++)
   131     for (int i = 0; i < urlArray.count(); i++)
   139 }
   139 }
   140 
   140 
   141 //get the url for the specify bitrate
   141 //get the url for the specify bitrate
   142 //the caller should delete the QList 
   142 //the caller should delete the QList 
   143 //
   143 //
   144 EXPORT_C QList<QString> * IRQPreset::getURLsForBitrate(int aBitrate) const
   144 QList<QString> * IRQPreset::getURLsForBitrate(int aBitrate) const
   145 {
   145 {
   146     int upLimit = urlArray.count();
   146     int upLimit = urlArray.count();
   147     
   147     
   148     //if the urls list has no item
   148     //if the urls list has no item
   149     if( 0 == upLimit )
   149     if( 0 == upLimit )
   171     return stringList;
   171     return stringList;
   172 }
   172 }
   173 
   173 
   174 //the following functions may be changed in future 
   174 //the following functions may be changed in future 
   175 //
   175 //
   176 EXPORT_C int IRQPreset::getChannelUrlAt(int aIndex, QString& aURL) const
   176 int IRQPreset::getChannelUrlAt(int aIndex, QString& aURL) const
   177 {
   177 {
   178     int upLimit = urlArray.count();
   178     int upLimit = urlArray.count();
   179 
   179 
   180     if (aIndex < 0 || aIndex >= upLimit)
   180     if (aIndex < 0 || aIndex >= upLimit)
   181         return EIRQErrorBadParameter;
   181         return EIRQErrorBadParameter;
   182 
   182 
   183     aURL = urlArray[aIndex].url;
   183     aURL = urlArray[aIndex].url;
   184     return EIRQErrorNone;
   184     return EIRQErrorNone;
   185 }
   185 }
   186 
   186 
   187 EXPORT_C int IRQPreset::getChannelBitrate(unsigned int aIndex, unsigned int &aBitrate) const
   187 int IRQPreset::getChannelBitrate(unsigned int aIndex, unsigned int &aBitrate) const
   188 {
   188 {
   189     if ( aIndex < urlArray.count())
   189     if ( aIndex < urlArray.count())
   190     {
   190     {
   191         aBitrate = urlArray[aIndex].bitrate;
   191         aBitrate = urlArray[aIndex].bitrate;
   192         return EIRQErrorNone;
   192         return EIRQErrorNone;
   195     return EIRQErrorBadParameter;
   195     return EIRQErrorBadParameter;
   196 }
   196 }
   197 
   197 
   198 //append a channel server into a internal list 
   198 //append a channel server into a internal list 
   199 //
   199 //
   200 EXPORT_C void IRQPreset::insertChannelServer(const IRQChannelServerURL& aURL)
   200 void IRQPreset::insertChannelServer(const IRQChannelServerURL& aURL)
   201 {
   201 {
   202     urlArray.append(aURL);
   202     urlArray.append(aURL);
   203     iChannelUrlCount++;
   203     iChannelUrlCount++;
   204     iIsSorted = false;
   204     iIsSorted = false;
   205 }
   205 }
   206 
   206 
   207 EXPORT_C void IRQPreset::clearChannelServerList()
   207 void IRQPreset::clearChannelServerList()
   208 {
   208 {
   209     urlArray.clear();
   209     urlArray.clear();
   210     iChannelUrlCount = 0;
   210     iChannelUrlCount = 0;
   211     iIsSorted = false;
   211     iIsSorted = false;
   212 }
   212 }
   213 
   213 
   214 //sort the urlArray with bitrates by ascending. for 
   214 //sort the urlArray with bitrates by ascending. for 
   215 //there are not many items, here we use bubble sorting.
   215 //there are not many items, here we use bubble sorting.
   216 //
   216 //
   217 EXPORT_C void IRQPreset::sortURLArray()
   217 void IRQPreset::sortURLArray()
   218 {
   218 {
   219     if (iIsSorted)
   219     if (iIsSorted)
   220         return;
   220         return;
   221 
   221 
   222     qSort(urlArray.begin(), urlArray.end(),  bitrateLessThan);
   222     qSort(urlArray.begin(), urlArray.end(),  bitrateLessThan);
   223 
   223 
   224     iIsSorted = true;
   224     iIsSorted = true;
   225 }
   225 }
   226 
   226 
   227 EXPORT_C bool IRQPreset::setUrlBitrate(const unsigned int aUrlIndex, const unsigned int aBitrate)
   227 bool IRQPreset::setUrlBitrate(const unsigned int aUrlIndex, const unsigned int aBitrate)
   228 {
   228 {
   229     if( aUrlIndex > (urlArray.count()-1) )
   229     if( aUrlIndex > (urlArray.count()-1) )
   230     {
   230     {
   231         return false;
   231         return false;
   232     }
   232     }
   235     return true;
   235     return true;
   236 }
   236 }
   237 
   237 
   238 //check wether the internal list is sorted 
   238 //check wether the internal list is sorted 
   239 //
   239 //
   240 EXPORT_C bool IRQPreset::isSorted() const
   240 bool IRQPreset::isSorted() const
   241 {
   241 {
   242     return iIsSorted;
   242     return iIsSorted;
   243 }
   243 }
   244 
   244 
   245 EXPORT_C int IRQPreset::getChannelURLCount() const
   245 int IRQPreset::getChannelURLCount() const
   246 {
   246 {
   247     return iChannelUrlCount;
   247     return iChannelUrlCount;
   248 }
   248 }
   249 
   249 
   250 bool bitrateLessThan(const IRQChannelServerURL &url1,
   250 bool bitrateLessThan(const IRQChannelServerURL &url1,