qtinternetradio/irqfavoritesdb/src/irqfavoritesdb_p.cpp
changeset 17 38bbf2dcd608
parent 16 5723da102db1
equal deleted inserted replaced
16:5723da102db1 17:38bbf2dcd608
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "irfavoritesdb.h"
       
    19 #include "irqfavoritesdb.h"
       
    20 #include "irqfavoritesdb_p.h"
       
    21 #include "irqenums.h"
       
    22 #include "irqutility.h" 
       
    23 #include "irqisdsdatastructure.h"
       
    24 #include "irpreset.h"
       
    25 #include "irisdspreset.h"
       
    26 
       
    27 IRQFavoritesDBPrivate::IRQFavoritesDBPrivate(IRQFavoritesDB *aIRQFavorites) : q_ptr(aIRQFavorites),
       
    28                                                                               mIRFavoritesDb(NULL)
       
    29 {
       
    30 }
       
    31 
       
    32 IRQFavoritesDBPrivate::~IRQFavoritesDBPrivate()
       
    33 {
       
    34     delete mIRFavoritesDb;
       
    35     mIRFavoritesDb = NULL;
       
    36 }
       
    37 
       
    38 void IRQFavoritesDBPrivate::init()
       
    39 {
       
    40     TRAPD(err, mIRFavoritesDb = CIRFavoritesDb::NewL());
       
    41     if (KErrNone != err)
       
    42     {
       
    43         return;
       
    44     }
       
    45 
       
    46     /* add self to the observers of the CIRFavoritesDb. When the call back function
       
    47     * is called, it means that preset is changed and we send a signal to the uper layer*/
       
    48     mIRFavoritesDb->AddObserver(*this);
       
    49 }
       
    50 
       
    51 int IRQFavoritesDBPrivate::addPreset(const IRQPreset& aPreset)
       
    52 {
       
    53     int returnCode = 0;
       
    54     TRAPD(err, addPresetL(aPreset, returnCode));
       
    55     
       
    56     int result = 0;
       
    57     if (KErrNone != err)
       
    58     {
       
    59         IRQUtility::convertSError2QError(err, result);
       
    60     }
       
    61     else
       
    62     {
       
    63         IRQUtility::convertSError2QError(returnCode, result);
       
    64     }
       
    65     return result;
       
    66 }
       
    67 
       
    68 int IRQFavoritesDBPrivate::addPreset(const QString& aName, const QString& aURL)
       
    69 {
       
    70     if (0 == aName.size() || 0 == aURL.size())
       
    71     {
       
    72         return EIRQErrorBadParameter;
       
    73     }
       
    74     
       
    75     TPtrC16 nameptr(reinterpret_cast<const TUint16*> (aName.utf16()));
       
    76     TPtrC16 urlptr(reinterpret_cast<const TUint16*> (aURL.utf16()));
       
    77     int returnCode = 0;
       
    78     TRAPD(err, mIRFavoritesDb->AddPresetL(nameptr, urlptr, returnCode));
       
    79     
       
    80     int result = 0;
       
    81     if (KErrNone != err)
       
    82     {
       
    83         IRQUtility::convertSError2QError(err, result);
       
    84     }
       
    85     else
       
    86     {
       
    87         IRQUtility::convertSError2QError(returnCode, result);
       
    88     }
       
    89     return result;
       
    90 }
       
    91 
       
    92 int IRQFavoritesDBPrivate::getUniqId(int aNum) const
       
    93 {
       
    94     if ( aNum < 0 || aNum >= mIRFavoritesDb->iFavPresetList.Count())
       
    95     {
       
    96         return EIRQErrorBadParameter;
       
    97     }
       
    98         
       
    99     //the preset's uniqid is equal to the CIRPreset's id
       
   100     return mIRFavoritesDb->iFavPresetList[aNum]->Id();
       
   101 }
       
   102 
       
   103 int IRQFavoritesDBPrivate::deletePreset(int aUniqId)
       
   104 {
       
   105     TRAPD(err, (mIRFavoritesDb->DeletePresetL(aUniqId)));
       
   106     int result = 0;
       
   107     IRQUtility::convertSError2QError(err, result);
       
   108     return result;
       
   109 }
       
   110 
       
   111 int IRQFavoritesDBPrivate::searchPreset(int aUniqPresetId, int aIsdsPresetId)
       
   112 {
       
   113     int returnCode = 0;
       
   114     int result = 0; //for QT
       
   115     returnCode = mIRFavoritesDb->SearchPreset(aUniqPresetId, aIsdsPresetId);
       
   116     IRQUtility::convertSError2QError(returnCode, result);
       
   117     return result;
       
   118 }
       
   119 
       
   120 int IRQFavoritesDBPrivate::getPreviousPreset(int aIndex)
       
   121 {
       
   122     return mIRFavoritesDb->GetPreviousPreset(aIndex);
       
   123 }
       
   124 
       
   125 int IRQFavoritesDBPrivate::getNextPreset(int aIndex)
       
   126 {
       
   127     return mIRFavoritesDb->GetNextPreset(aIndex);
       
   128 }
       
   129 
       
   130 int IRQFavoritesDBPrivate::replacePreset(const IRQPreset& aNewPreset)
       
   131 {
       
   132     TRAPD(err, replacePresetL(aNewPreset));
       
   133     int result = 0;
       
   134     IRQUtility::convertSError2QError(err, result);
       
   135     return result;
       
   136 }
       
   137 
       
   138 int IRQFavoritesDBPrivate::replaceUserDefinedPreset(const IRQPreset& aNewPreset)
       
   139 {
       
   140     TRAPD(err, replaceUserDefinedPresetL(aNewPreset));
       
   141     int result = 0;
       
   142     IRQUtility::convertSError2QError(err, result);
       
   143     return result;
       
   144 }
       
   145 
       
   146 int IRQFavoritesDBPrivate::makePresetUserDefined(int aChannelId, int aUserDefinedChannelId)
       
   147 {
       
   148     TRAPD(err, mIRFavoritesDb->MakePresetUserDefinedL(aChannelId, aUserDefinedChannelId));
       
   149     int result = 0;
       
   150     IRQUtility::convertSError2QError(err, result);
       
   151     return result;
       
   152 }
       
   153 
       
   154 int IRQFavoritesDBPrivate::emptyPresetCount() const
       
   155 {
       
   156     return mIRFavoritesDb->EmptyPresetCount();
       
   157 }
       
   158 
       
   159 int IRQFavoritesDBPrivate::maxPresetCount()
       
   160 {
       
   161     return mIRFavoritesDb->MaxPresetCount();
       
   162 }
       
   163 
       
   164 void IRQFavoritesDBPrivate::setMoveStatus(bool aStatus)
       
   165 {
       
   166     mIRFavoritesDb->SetMoveStatus(aStatus);  
       
   167 }
       
   168 
       
   169 bool IRQFavoritesDBPrivate::getMoveStatus()
       
   170 {
       
   171     if (mIRFavoritesDb->GetMoveStatus())
       
   172     {
       
   173         return true;
       
   174     }
       
   175     else
       
   176     {
       
   177         return false;
       
   178     }
       
   179 }
       
   180 
       
   181 QList<IRQPreset*>* IRQFavoritesDBPrivate::getPresets() const
       
   182 {
       
   183     QList<IRQPreset*> * presetList = new QList<IRQPreset*> ();
       
   184     const RIRPresetArray& cirPresetList = mIRFavoritesDb->GetAllSortedPresets();
       
   185     int counts = cirPresetList.Count();
       
   186     for (int i = 0; i < counts; i++)
       
   187     {
       
   188         IRQPreset *irqPreset = new IRQPreset();
       
   189         IRQUtility::convertCIRPreset2IRQPreset(*(cirPresetList[i]), *irqPreset);
       
   190         presetList->append(irqPreset);
       
   191     }
       
   192     return presetList;
       
   193 }
       
   194 
       
   195 void IRQFavoritesDBPrivate::increasePlayedTimes(const IRQPreset &aPreset)
       
   196 {
       
   197     TRAP_IGNORE(increasePlayedTimesL(aPreset));
       
   198 }
       
   199 
       
   200 int IRQFavoritesDBPrivate::renamePreset(const IRQPreset &aPreset, const QString &aNewName)
       
   201 {
       
   202     int returnCode = 0;
       
   203     TRAPD(err, returnCode = renamePresetL(aPreset, aNewName));
       
   204     
       
   205     int result = 0;
       
   206     if (KErrNone != err)
       
   207     {
       
   208         IRQUtility::convertSError2QError(err, result);
       
   209     }
       
   210     else
       
   211     {
       
   212         IRQUtility::convertSError2QError(returnCode, result);
       
   213     }
       
   214     return result;
       
   215 }
       
   216 
       
   217 /* from MPSPresetObserver */
       
   218 void IRQFavoritesDBPrivate::HandlePresetChangedL(TInt aId, TUid aDataHandler, MPSPresetObserver::TPSReason aType)
       
   219 {
       
   220     IRQFavoritesDB::PSReason reason = IRQFavoritesDB::PSCreated;
       
   221     switch (aType)
       
   222     {
       
   223     case EPSCreated:
       
   224         reason = IRQFavoritesDB::PSCreated;
       
   225         break;
       
   226         
       
   227     case EPSDeleted:
       
   228         reason = IRQFavoritesDB::PSDeleted;
       
   229         break;
       
   230         
       
   231     case EPSModified:
       
   232         reason = IRQFavoritesDB::PSModified;
       
   233         break;
       
   234         
       
   235     default:
       
   236         Q_ASSERT(false);
       
   237         break;
       
   238     }
       
   239     
       
   240     emit q_ptr->presetChanged(aId, aDataHandler.iUid, reason);
       
   241 }
       
   242 
       
   243 void IRQFavoritesDBPrivate::addPresetL(const IRQPreset& aPreset, int& aRetValue)
       
   244 {
       
   245     CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC();
       
   246     IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset);
       
   247     mIRFavoritesDb->AddPresetL(*cirPreset, aRetValue);
       
   248     CleanupStack::PopAndDestroy(cirPreset);
       
   249 }
       
   250 
       
   251 void IRQFavoritesDBPrivate::replacePresetL(const IRQPreset& aNewPreset)
       
   252 {
       
   253     CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC();
       
   254     IRQUtility::convertIRQPreset2CIRIsdsPreset(aNewPreset, *cirPreset);
       
   255     mIRFavoritesDb->ReplacePresetL(*cirPreset);
       
   256     CleanupStack::PopAndDestroy(cirPreset);
       
   257 }
       
   258 
       
   259 void IRQFavoritesDBPrivate::replaceUserDefinedPresetL(const IRQPreset& aNewPreset)
       
   260 {
       
   261     CIRIsdsPreset *cirPreset = CIRIsdsPreset::NewLC();
       
   262     IRQUtility::convertIRQPreset2CIRIsdsPreset(aNewPreset, *cirPreset);
       
   263     mIRFavoritesDb->ReplaceUserDefinedPresetL(*cirPreset);
       
   264     CleanupStack::PopAndDestroy(cirPreset);
       
   265 }
       
   266 
       
   267 void IRQFavoritesDBPrivate::increasePlayedTimesL(const IRQPreset &aPreset)
       
   268 {
       
   269     CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC();
       
   270     IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset);
       
   271     mIRFavoritesDb->IncreasePlayedTimesL(*cirPreset);    
       
   272     CleanupStack::PopAndDestroy(cirPreset);
       
   273 }
       
   274 
       
   275 int IRQFavoritesDBPrivate::renamePresetL(const IRQPreset &aPreset, const QString &aNewName)
       
   276 {
       
   277     CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC();
       
   278     IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset);
       
   279     TPtrC newName(reinterpret_cast<const TUint16*>(aNewName.utf16()), aNewName.length());
       
   280     int ret = mIRFavoritesDb->RenamePresetL(*cirPreset, newName);
       
   281     CleanupStack::PopAndDestroy(cirPreset);
       
   282     
       
   283     return ret;
       
   284 }