qtinternetradio/ui/src/irlastplayedstationinfo.cpp
changeset 0 09774dfdd46b
child 12 608f67c22514
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     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 #include <QDataStream>
       
    18 #include <QFile>
       
    19 
       
    20 #include "irqisdsdatastructure.h"
       
    21 #include "irlastplayedstationinfo.h"
       
    22 
       
    23 const QString KFileName("C:\\Private\\E28364bb\\lastPlayed.dat");
       
    24 
       
    25 IRLastPlayedStationInfo::IRLastPlayedStationInfo() : iLastPlayedStation(NULL), iUpdated(false),
       
    26                                                      iConnectedFrom(EIRQIsds)
       
    27 {
       
    28     readLastPlayedStation();
       
    29 }
       
    30     
       
    31 IRLastPlayedStationInfo::~IRLastPlayedStationInfo()
       
    32 {
       
    33     delete iLastPlayedStation;
       
    34     iLastPlayedStation = NULL;
       
    35 }
       
    36     
       
    37 void IRLastPlayedStationInfo::updateLastPlayedStation(IRQPreset *aPreset, IRQConnectedFrom aConnectedFrom)
       
    38 {
       
    39     Q_ASSERT(aPreset);
       
    40     
       
    41     if (iLastPlayedStation == NULL)
       
    42     {
       
    43         iLastPlayedStation = new IRQPreset;
       
    44     }
       
    45     
       
    46     *iLastPlayedStation = *aPreset;
       
    47     
       
    48     iConnectedFrom = aConnectedFrom;
       
    49     
       
    50     iUpdated = true;
       
    51 }
       
    52     
       
    53 void IRLastPlayedStationInfo::commitLastPlayedStation()
       
    54 {
       
    55     if (NULL == iLastPlayedStation || false == iUpdated)
       
    56     {
       
    57         return;
       
    58     }
       
    59     
       
    60     QFile file(KFileName);
       
    61     bool ret = file.open(QIODevice::Truncate | QIODevice::WriteOnly);
       
    62     if (!ret)
       
    63     {
       
    64         return;
       
    65     }
       
    66     
       
    67     QDataStream outStream(&file);
       
    68     qint32 connectedFrom = iConnectedFrom;
       
    69     outStream<<connectedFrom;
       
    70     iLastPlayedStation->externalize(outStream);
       
    71     file.close();
       
    72     iUpdated = false;
       
    73 }
       
    74 
       
    75 IRQPreset * IRLastPlayedStationInfo::getLastPlayedStation() const
       
    76 {
       
    77     return iLastPlayedStation;
       
    78 }
       
    79 
       
    80 void IRLastPlayedStationInfo::readLastPlayedStation()
       
    81 { 
       
    82     if (!QFile::exists(KFileName))
       
    83     {
       
    84         return;
       
    85     }
       
    86     
       
    87     QFile file(KFileName);
       
    88     bool ret = file.open(QIODevice::ReadOnly);
       
    89     if (!ret)
       
    90     {
       
    91         return;
       
    92     }
       
    93     
       
    94     QDataStream inStream(&file);
       
    95     qint32 connectedFrom = EIRQIsds;
       
    96     inStream>>connectedFrom;
       
    97     if(connectedFrom < EIRQConnectedFromMaxValue)
       
    98     {
       
    99         iConnectedFrom = static_cast<IRQConnectedFrom>(connectedFrom);
       
   100     }
       
   101     else
       
   102     {
       
   103         iConnectedFrom = EIRQIsds;
       
   104     }
       
   105     
       
   106     iLastPlayedStation = new IRQPreset;
       
   107     iLastPlayedStation->internalize(inStream);
       
   108     file.close();
       
   109 }
       
   110 
       
   111 IRQConnectedFrom IRLastPlayedStationInfo::connectedFrom() const
       
   112 {
       
   113     return iConnectedFrom;
       
   114 }
       
   115