qtinternetradio/irqfavoritesdb/src/irqfavoritesdb.cpp
changeset 3 ee64f059b8e1
parent 0 09774dfdd46b
child 8 3b03c28289e6
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 #include <e32err.h>
       
    18 #include "irqfavoritesdb.h" 
    17 #include "irqfavoritesdb.h" 
    19 #include "irqenums.h"
    18 #include "irqfavoritesdb_p.h"
    20 #include "irqutility.h" 
       
    21 #include "irqisdsdatastructure.h"
       
    22 #include "irisdspreset.h"
       
    23 #include "irpreset.h"
       
    24 #include "irfavoritesdb.h"
       
    25 
    19 
    26 EXPORT_C IRQFavoritesDB::IRQFavoritesDB()
    20 IRQFavoritesDB::IRQFavoritesDB() : d_ptr(new IRQFavoritesDBPrivate(this))
    27 {
    21 {    
    28     TRAPD(err, iIRFavoritesDb = CIRFavoritesDb::NewL());
    22     d_ptr->init();
    29     if( KErrNone != err)
    23 }
    30         return;
       
    31 
    24 
    32     /* add self to the observers of the CIRFavoritesDb. When the call back function
       
    33      * is called, it means that preset is changed and we send a signal to the uper layer*/
       
    34     iIRFavoritesDb->AddObserver(*this);
       
    35 }
       
    36 IRQFavoritesDB::~IRQFavoritesDB()
    25 IRQFavoritesDB::~IRQFavoritesDB()
    37 {
    26 {
    38     delete iIRFavoritesDb;
    27     delete d_ptr;
    39 }
    28 }
    40 
    29 
    41 //add a preset 
    30 //add a preset 
    42 //@param CIRIsdsPreset& the isds preset
    31 //@param IRQPreset& the preset
    43 //@return  errcode
    32 //@return  errcode
    44 EXPORT_C int IRQFavoritesDB::addPreset(const IRQPreset& aPreset)
    33 int IRQFavoritesDB::addPreset(const IRQPreset& aPreset)
    45 {
    34 {
    46     int returnCode = 0;
    35     return d_ptr->addPreset(aPreset);
    47     TRAPD(err, addPresetL(aPreset, returnCode));
       
    48     RETURN_IF_ERR(err);
       
    49 
       
    50     int result = 0;
       
    51     IRQUtility::convertSError2QError(returnCode, result);
       
    52     return result;
       
    53 }
    36 }
    54 
    37 
    55 //add a preset manually
    38 //add a preset manually
    56 //@return  errcode
    39 //@return  errcode
    57 //@param 
    40 //@param 
    58 //
    41 //
    59 EXPORT_C int IRQFavoritesDB::addPreset(const QString& aName,
    42 int IRQFavoritesDB::addPreset(const QString& aName, const QString& aURL)
    60         const QString& aURL)
       
    61 {
    43 {
    62     
    44     return d_ptr->addPreset(aName, aURL);
    63     if( 0 == aName.size() || 0 == aURL.size())
       
    64         return EIRQErrorBadParameter;
       
    65     
       
    66     TPtrC16 nameptr(reinterpret_cast<const TUint16*> (aName.utf16()));
       
    67     TPtrC16 urlptr(reinterpret_cast<const TUint16*> (aURL.utf16()));
       
    68     int returnCode = 0;
       
    69     TRAPD(err, (iIRFavoritesDb->AddPresetL(nameptr, urlptr, returnCode)));
       
    70     RETURN_IF_ERR(err);
       
    71 
       
    72     int result = 0;
       
    73     IRQUtility::convertSError2QError(returnCode, result);
       
    74     return result;
       
    75 }
    45 }
    76 
    46 
    77 //get a preset uniq id
    47 //get a preset uniq id
    78 //@return errcode
    48 //@return errcode
    79 //@param
    49 //@param
    80 //
    50 //
    81 EXPORT_C int IRQFavoritesDB::getUniqId(int aNum)
    51 int IRQFavoritesDB::getUniqId(int aNum) const
    82 {
    52 {
    83     if( aNum < 0 || aNum >= iIRFavoritesDb->iFavPresetList.Count())
    53     return d_ptr->getUniqId(aNum);
    84         return EIRQErrorBadParameter;
       
    85     
       
    86     return iIRFavoritesDb->iFavPresetList[aNum]->Id();
       
    87 }
    54 }
    88 
    55 
    89 //delete a preset by uniq id
    56 //delete a preset by uniq id
    90 //@return errcode
    57 //@return errcode
    91 //@param
    58 //@param
    92 //
    59 //
    93 EXPORT_C int IRQFavoritesDB::deletePreset(int aUniqId)
    60 int IRQFavoritesDB::deletePreset(int aUniqId)
    94 {
    61 {
    95     TRAPD( err, (iIRFavoritesDb->DeletePresetL(aUniqId)));
    62     return d_ptr->deletePreset(aUniqId);
    96     RETURN_IF_ERR(err);
       
    97     return EIRQErrorNone;
       
    98 }
    63 }
    99 
    64 
   100 //search a preset by uniqpresetId / isdspresetid
    65 //search a preset by uniqpresetId / isdspresetid
   101 //warning: the function needs further checking
    66 //warning: the function needs further checking
   102 //@return errcode
    67 //@return errcode
   103 //
    68 //
   104 EXPORT_C int IRQFavoritesDB::searchPreset(int aUniqPresetId, int aIsdsPresetId)
    69 int IRQFavoritesDB::searchPreset(int aUniqPresetId, int aIsdsPresetId)
   105 {
    70 {
   106     int returnCode = 0;
    71     return d_ptr->searchPreset(aUniqPresetId, aIsdsPresetId);
   107     int result = 0; //for QT
       
   108     returnCode = iIRFavoritesDb->SearchPreset(aUniqPresetId, aIsdsPresetId);
       
   109     IRQUtility::convertSError2QError(returnCode, result);
       
   110     return result;
       
   111 }
    72 }
   112 
    73 
   113 //
    74 //
   114 //get the previouse preset index in the internal list
    75 //get the previouse preset index in the internal list
   115 //@return the index
    76 //@return the index
   116 //
    77 //
   117 EXPORT_C int IRQFavoritesDB::getPreviousPreset(int aIndex)
    78 int IRQFavoritesDB::getPreviousPreset(int aIndex)
   118 {
    79 {
   119     return iIRFavoritesDb->GetPreviousPreset(aIndex);
    80     return d_ptr->getPreviousPreset(aIndex);
   120 }
    81 }
   121 
    82 
   122 //
    83 //
   123 //get the next preset index
    84 //get the next preset index
   124 //@return the index
    85 //@return the index
   125 //
    86 //
   126 EXPORT_C int IRQFavoritesDB::getNextPreset(int aIndex)
    87 int IRQFavoritesDB::getNextPreset(int aIndex)
   127 {
    88 {
   128     return iIRFavoritesDb->GetNextPreset(aIndex);
    89     return d_ptr->getNextPreset(aIndex);
   129 }
    90 }
   130 
       
   131  
    91  
   132 //replace with new preset
    92 //replace with new preset
   133 //@return errcode 
    93 //@return errcode 
   134 //
    94 //
   135 EXPORT_C int IRQFavoritesDB::replacePreset(const IRQPreset& aNewPreset)
    95 int IRQFavoritesDB::replacePreset(const IRQPreset& aNewPreset)
   136 {
    96 {
   137     TRAPD(err, replacePresetL(aNewPreset));
    97     return d_ptr->replacePreset(aNewPreset);
   138     RETURN_IF_ERR(err);
       
   139     return EIRQErrorNone;
       
   140 }
    98 }
   141 
    99 
   142 //@return errcode
   100 //@return errcode
   143 //
   101 //
   144 EXPORT_C int IRQFavoritesDB::replaceUserDefinedPreset(const IRQPreset& aNewPreset)
   102 int IRQFavoritesDB::replaceUserDefinedPreset(const IRQPreset& aNewPreset)
   145 {
   103 {
   146     TRAPD(err, replaceUserDefinedPresetL(aNewPreset));
   104     return d_ptr->replaceUserDefinedPreset(aNewPreset);
   147     RETURN_IF_ERR(err);
       
   148     return EIRQErrorNone;
       
   149 }
   105 }
   150 
   106 
   151 //change the preset type to user defined
   107 //change the preset type to user defined
   152 //@return errcode
   108 //@return errcode
   153 //
   109 //
   154 EXPORT_C int IRQFavoritesDB::makePresetUserDefined(int aChannelId,
   110 int IRQFavoritesDB::makePresetUserDefined(int aChannelId, int aUserDefinedChannelId)
   155         int aUserDefinedChannelId)
       
   156 {
   111 {
   157     TRAPD(err, (iIRFavoritesDb->MakePresetUserDefinedL(aChannelId, aUserDefinedChannelId)));
   112     return d_ptr->makePresetUserDefined(aChannelId, aUserDefinedChannelId);
   158     RETURN_IF_ERR(err);
       
   159     return EIRQErrorNone;
       
   160 }
   113 }
   161 
   114 
   162 //get the empty preset left count
   115 //get the empty preset left count
   163 //@return the count of empty presets left 
   116 //@return the count of empty presets left 
   164 //
   117 //
   165 EXPORT_C int IRQFavoritesDB::emptyPresetCount() const
   118 int IRQFavoritesDB::emptyPresetCount() const
   166 {
   119 {
   167     return iIRFavoritesDb->EmptyPresetCount();
   120     return d_ptr->emptyPresetCount();
   168 }
   121 }
   169 
   122 
   170 //get the max preset count supported now
   123 //get the max preset count supported now
   171 //@return errcode 
   124 //@return errcode 
   172 //
   125 //
   173 EXPORT_C int IRQFavoritesDB::maxPresetCount()
   126 int IRQFavoritesDB::maxPresetCount()
   174 {
   127 {
   175     return iIRFavoritesDb->MaxPresetCount();
   128     return d_ptr->maxPresetCount();
   176 }
   129 }
   177 
   130 
   178 //the interface is not used currently.
   131 //the interface is not used currently.
   179 //
   132 //
   180 EXPORT_C void IRQFavoritesDB::setMoveStatus(bool aStatus)
   133 void IRQFavoritesDB::setMoveStatus(bool aStatus)
   181 {
   134 {
   182     iIRFavoritesDb->SetMoveStatus(aStatus);    
   135     d_ptr->setMoveStatus(aStatus);  
   183 }
   136 }
   184 
   137 
   185 //the interface is not used currently 
   138 //the interface is not used currently 
   186 //
   139 //
   187 EXPORT_C bool IRQFavoritesDB::getMoveStatus()
   140 bool IRQFavoritesDB::getMoveStatus()
   188 {
   141 {
   189     return iIRFavoritesDb->GetMoveStatus();
   142     return d_ptr->getMoveStatus();
   190 }
   143 }
   191 
   144 
   192 //for CIRPreset is just an interface so we can wrapper it into the IRQPreset.
   145 //for CIRPreset is just an interface so we can wrapper it into the IRQPreset.
   193 //the interface get the IRQPreset list. The upper layer will free all the items
   146 //the interface get the IRQPreset list. The upper layer will free all the items
   194 //in the list and the list self
   147 //in the list and the list self
   195 //
   148 //
   196 EXPORT_C QList<IRQPreset*>* IRQFavoritesDB::getPresets() const
   149 QList<IRQPreset*>* IRQFavoritesDB::getPresets() const
   197 {
   150 {
   198     QList<IRQPreset*> * presetList = new QList<IRQPreset*> ();
   151     return d_ptr->getPresets();
   199     const RIRPresetArray& cirPresetList = iIRFavoritesDb->GetAllSortedPresets();
       
   200     int counts = cirPresetList.Count();
       
   201     for (int i = 0; i < counts; i++)
       
   202     {
       
   203         IRQPreset *irqPreset = new IRQPreset();
       
   204         IRQUtility::convertCIRPreset2IRQPreset(*(cirPresetList[i]), *irqPreset);
       
   205         presetList->append(irqPreset);
       
   206     }
       
   207     return presetList;
       
   208 }
   152 }
   209 
   153 
   210 /*
   154 /*
   211  * Increase the played times of the preset if it's in the favorites
   155  * Increase the played times of the preset if it's in the favorites
   212  */
   156  */
   213 EXPORT_C void IRQFavoritesDB::increasePlayedTimes(const IRQPreset &aPreset)
   157 void IRQFavoritesDB::increasePlayedTimes(const IRQPreset &aPreset)
   214 {
   158 {
   215     TRAP_IGNORE(increasePlayedTimesL(aPreset));
   159     d_ptr->increasePlayedTimes(aPreset);
   216 }
   160 }
   217 
   161 
   218 EXPORT_C CIRFavoritesDb * IRQFavoritesDB::getCIRFavoriteDB() const
       
   219 {
       
   220     return iIRFavoritesDb;
       
   221 }
       
   222 
       
   223 /*  None export functions */
       
   224 
       
   225 void IRQFavoritesDB::HandlePresetChangedL(TInt aId, TUid aDataHandler,
       
   226         MPSPresetObserver::TPSReason aType)
       
   227 {
       
   228     emit presetChanged(aId, aDataHandler, aType);
       
   229 }
       
   230 
       
   231 void IRQFavoritesDB::addPresetL(const IRQPreset& aPreset, int& aRetValue)
       
   232 {
       
   233     CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC();
       
   234     IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset);
       
   235     iIRFavoritesDb->AddPresetL(*cirPreset, aRetValue);
       
   236     CleanupStack::PopAndDestroy(cirPreset);
       
   237 }
       
   238 
       
   239 void IRQFavoritesDB::replacePresetL(const IRQPreset& aNewPreset)
       
   240 {
       
   241     CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC();
       
   242     IRQUtility::convertIRQPreset2CIRIsdsPreset(aNewPreset, *cirPreset);
       
   243     iIRFavoritesDb->ReplacePresetL(*cirPreset);
       
   244     CleanupStack::PopAndDestroy(cirPreset);
       
   245 }
       
   246 
       
   247 void IRQFavoritesDB::replaceUserDefinedPresetL(const IRQPreset& aNewPreset)
       
   248 {
       
   249     CIRIsdsPreset *cirPreset = CIRIsdsPreset::NewLC();
       
   250     IRQUtility::convertIRQPreset2CIRIsdsPreset(aNewPreset, *cirPreset);
       
   251     iIRFavoritesDb->ReplaceUserDefinedPresetL(*cirPreset);
       
   252     CleanupStack::PopAndDestroy(cirPreset);
       
   253 }
       
   254 
       
   255 void IRQFavoritesDB::increasePlayedTimesL(const IRQPreset &aPreset)
       
   256 {
       
   257     CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC();
       
   258     IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset);
       
   259     iIRFavoritesDb->IncreasePlayedTimesL(*cirPreset);    
       
   260     CleanupStack::PopAndDestroy(cirPreset);
       
   261 }
       
   262 
   162 
   263 
   163 
   264 
   164 
   265  
   165  
   266 
   166