PDA

View Full Version : [Tab play list]Load play lists on start



petrusPL
18th March 2011, 18:12
Hello. I try make a music player with play lists in tabs.
I saved open play lists when program is closing to temp file and i want load it on startup.
tmp file looks like this:
play list name 1
file 1
file 2
file 3
separator
play list name 2
file 1
file 2
etc.
i have struct and i have load data to the struct

struct PLL
{
QString name;
QList<Phonon::MediaSource> sources;
};

void Window::load_on_start()
{
QFile file("tmp.txt");
if(file.open(QFile::ReadOnly | QFile::Text))
{
QTextStream in(&file);
QString line;
PLL pl[1000];
int indeX = 0;
do{
line = in.readLine();
if(!line.isEmpty())
{
if(!line.contains("/"))
{
if(line == ">>>")
indeX++;
else
pl[indeX].name = line;
}
else
{
Phonon::MediaSource source(line);
pl[indeX].sources.append(source);
}

}
}while(!line.isEmpty());

qDebug() << indeX << pl[0].name << pl[0].sources.size();
qDebug() << indeX << pl[1].name << pl[1].sources.size();
for(int i = 0; i <= indeX; i++)
{
if(true == true) //!pl[i].sources.isEmpty()
{
sources.clear();
int ind = sources.size();
sources = pl[i].sources;
tabWidget->setTabText(tabWidget->currentIndex(), pl[i].name);
metaInfo->setCurrentSource(sources.at(0));
qDebug() << "TEST = >" << ind << pl[i].name << sources.size() << sources.at(0).fileName();
if(i < indeX) add_new_playList();
}
}

}
file.close();
}

void Window::metaInfoLoad(Phonon::State newState, Phonon::State)
{
if (newState == Phonon::ErrorState){
QMessageBox::warning(this, "BÅ‚Ä…d podczas otwierania pliku", metaInfo->errorString());

while (!sources.isEmpty() && !(sources.takeLast() == metaInfo->currentSource())) {} /* loop */;
return;
}

if (newState != Phonon::StoppedState && newState != Phonon::PausedState)
return;

QString icon;

if(metaInfo->currentSource().type() == Phonon::MediaSource::Invalid) icon = "2";
else icon = "0";

QMap<QString, QString> metaData = metaInfo->metaData();

QString title = metaData.value("TITLE");
if (title == "")
title = metaInfo->currentSource().fileName();

QTime total(0, (metaInfo->totalTime() / 60000) % 60, (metaInfo->totalTime() / 1000) % 60);
QString totalTime = total.toString("mm:ss");

int playListIndex = tabWidget->tabWhatsThis(tabWidget->currentIndex()).toInt();

QListWidgetItem *item = new QListWidgetItem(playList[playListIndex]);
item->setText(title+"|"+totalTime+"|"+icon);
item->setStatusTip(metaInfo->currentSource().fileName());

int index = sources.indexOf(metaInfo->currentSource()) + 1;
if (sources.size() > index) {
metaInfo->setCurrentSource(sources.at(index));
}
else return;
}


It is work when i have one playlist. When i have more it set correct names for tabs but set item to qlistwidget only for last playlist : /

What i do wrong ?

PS. sorry for my English :P