diff -r 2e1adbfc62af -r ee64f059b8e1 qtinternetradio/ui/src/irstationshare.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qtinternetradio/ui/src/irstationshare.cpp Fri May 14 15:43:29 2010 +0300 @@ -0,0 +1,195 @@ +/* +* 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 +#include +#include +#include + +#include "irstationshare.h" +#include "irqisdsdatastructure.h" + +const char KPlsFilePath[] = "c:\\data\\share.pls"; +const char KPlsFileHeading[] = "[playlist]"; +const char KPlsFileEntryNum[] = "NumberOfEntries"; +const char KPlsFileEnding[] = "Version=2"; +const char KPlsEntryElementFile[] = "File"; +const char KPlsEntryElementTitle[] = "Title"; +const char KPlsEntryElementLength[] = "Length"; +const char KPlsIndefiniteLength[] = "-1"; + +static void constructPlsElement( QTextStream &aOutput, + const IRQPreset &aPreset, + int &aStationIndexBase); + +// --------------------------------------------------------------------------- +// Constructor +// --------------------------------------------------------------------------- +// +IRStationShare::IRStationShare() + : iPlsFilePath(KPlsFilePath) +{ +} +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +IRStationShare::~IRStationShare() +{ +} + +// --------------------------------------------------------------------------- +// NOTE : MUST ensure no changes to all the elements in the list, +// so, can ONLY access element via const_iterator +// --------------------------------------------------------------------------- +// +bool IRStationShare::shareStations(const QList &aPresetList) +{ + if(!constructPlsFile(aPresetList)) + { + return false; + } + + ShareUi shareDialog; + QStringList fileList; + fileList.append(iPlsFilePath); + return shareDialog.send(fileList,true); +} + +bool IRStationShare::shareStations(const IRQPreset &aPreset) +{ + if(!constructPlsFile(aPreset)) + { + return false; + } + + ShareUi shareDialog; + QStringList fileList; + fileList.append(iPlsFilePath); + return shareDialog.send(fileList,true); +} + +// --------------------------------------------------------------------------- +// constructPlsFile +// NOTE : MUST ensure no changes to all the elements in the list, +// so, can ONLY access element via const_iterator +// --------------------------------------------------------------------------- +// +bool IRStationShare::constructPlsFile(const QList &aPresetList) +{ + if(0 == aPresetList.count()) + { + return false; + } + + QFile plsFile(iPlsFilePath); + if( !plsFile.open(QIODevice::ReadWrite | QIODevice::Truncate) ) + { + return false; + } + QTextStream outputStream( &plsFile ); + outputStream<::const_iterator it = aPresetList.begin(); it != aPresetList.end(); ++it) + { + entryNum += (*it)->getChannelURLCount(); + } + QString totalEntry; + totalEntry.setNum(entryNum); + outputStream<::const_iterator it = aPresetList.begin(); it != aPresetList.end(); ++it) + { + constructPlsElement(outputStream,*(*it),stationIndexBase); + } + + outputStream<