qtinternetradio/ui/src/irlastplayedstationinfo.cpp
changeset 0 09774dfdd46b
child 12 608f67c22514
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qtinternetradio/ui/src/irlastplayedstationinfo.cpp	Mon Apr 19 14:01:53 2010 +0300
@@ -0,0 +1,115 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+#include <QDataStream>
+#include <QFile>
+
+#include "irqisdsdatastructure.h"
+#include "irlastplayedstationinfo.h"
+
+const QString KFileName("C:\\Private\\E28364bb\\lastPlayed.dat");
+
+IRLastPlayedStationInfo::IRLastPlayedStationInfo() : iLastPlayedStation(NULL), iUpdated(false),
+                                                     iConnectedFrom(EIRQIsds)
+{
+    readLastPlayedStation();
+}
+    
+IRLastPlayedStationInfo::~IRLastPlayedStationInfo()
+{
+    delete iLastPlayedStation;
+    iLastPlayedStation = NULL;
+}
+    
+void IRLastPlayedStationInfo::updateLastPlayedStation(IRQPreset *aPreset, IRQConnectedFrom aConnectedFrom)
+{
+    Q_ASSERT(aPreset);
+    
+    if (iLastPlayedStation == NULL)
+    {
+        iLastPlayedStation = new IRQPreset;
+    }
+    
+    *iLastPlayedStation = *aPreset;
+    
+    iConnectedFrom = aConnectedFrom;
+    
+    iUpdated = true;
+}
+    
+void IRLastPlayedStationInfo::commitLastPlayedStation()
+{
+    if (NULL == iLastPlayedStation || false == iUpdated)
+    {
+        return;
+    }
+    
+    QFile file(KFileName);
+    bool ret = file.open(QIODevice::Truncate | QIODevice::WriteOnly);
+    if (!ret)
+    {
+        return;
+    }
+    
+    QDataStream outStream(&file);
+    qint32 connectedFrom = iConnectedFrom;
+    outStream<<connectedFrom;
+    iLastPlayedStation->externalize(outStream);
+    file.close();
+    iUpdated = false;
+}
+
+IRQPreset * IRLastPlayedStationInfo::getLastPlayedStation() const
+{
+    return iLastPlayedStation;
+}
+
+void IRLastPlayedStationInfo::readLastPlayedStation()
+{ 
+    if (!QFile::exists(KFileName))
+    {
+        return;
+    }
+    
+    QFile file(KFileName);
+    bool ret = file.open(QIODevice::ReadOnly);
+    if (!ret)
+    {
+        return;
+    }
+    
+    QDataStream inStream(&file);
+    qint32 connectedFrom = EIRQIsds;
+    inStream>>connectedFrom;
+    if(connectedFrom < EIRQConnectedFromMaxValue)
+    {
+        iConnectedFrom = static_cast<IRQConnectedFrom>(connectedFrom);
+    }
+    else
+    {
+        iConnectedFrom = EIRQIsds;
+    }
+    
+    iLastPlayedStation = new IRQPreset;
+    iLastPlayedStation->internalize(inStream);
+    file.close();
+}
+
+IRQConnectedFrom IRLastPlayedStationInfo::connectedFrom() const
+{
+    return iConnectedFrom;
+}
+