From 7cafbc957ab70386902b3ebb805f4e92b65028f3 Mon Sep 17 00:00:00 2001 From: tmarki Date: Sun, 8 Aug 2010 02:34:44 +0200 Subject: [PATCH] some bugs fixed --- bugs.txt | 10 +++-- mainwindow.cpp | 113 ++++++++++++++++----------------------------------- mainwindow.h | 2 + playlistmanager.cpp | 107 +++++++++++++++++------------------------------- playlistmanager.h | 1 + 5 files changed, 81 insertions(+), 152 deletions(-) diff --git a/bugs.txt b/bugs.txt index 1de9077..d1d4d75 100644 --- a/bugs.txt +++ b/bugs.txt @@ -1,7 +1,9 @@ -- context menu event outside of musicTable causes crash -- cancel add folder, add url causes crash -- doesn't remember add folder folder -- adding some files can cause a crash ("Blessing, Compassion") - meta info display mismatch (title duplication, some files receive some other file's meta info instead of their ("reality")) (might be related to previous) - quick next-next while playing stops playback - bold-italic highlight does not move on normal track switch (when one ends and the next starts) + +Fixed: ++ context menu event outside of musicTable causes crash ++ cancel add folder, add url causes crash ++ doesn't remember add folder folder ++ adding some files can cause a crash ("Blessing, Compassion") diff --git a/mainwindow.cpp b/mainwindow.cpp index dfd01f9..14cf5ee 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -8,7 +8,7 @@ //#define AVOID_INPUT_DIALOG 0 MainWindow::MainWindow() - : plman (this), settings (tr ("TomAmp"), "TomAmp") + : plman (this), settings (tr ("TomAmp"), "TomAmp"), isPlaying (false) { audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); mediaObject = new Phonon::MediaObject(this); @@ -89,11 +89,15 @@ void MainWindow::addFolder() tr("Select Directory To Add"), folder); + if (dir.isEmpty()) + return; + + settings.setValue("LastFolder", dir); + QStringList filters; QStringList files = QDir (dir).entryList(filters, QDir::AllDirs); files.removeAll("."); files.removeAll(".."); - qDebug () << files; bool recursive = false; if (files.size()) recursive = QMessageBox::question(this, "Add all folders", "Subfolders have been detected, add everything?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes; @@ -108,6 +112,8 @@ void MainWindow::addUrl() #else QString url = QInputDialog::getText(this, "Get URL", "Please type in the stream URL"); #endif + if (url.isEmpty() || !url.toLower().startsWith("http")) + return; QStringList toadd; toadd << url; plman.addStringList(toadd); @@ -125,7 +131,6 @@ void MainWindow::about() void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */) { - qDebug () << "State: " << newState; switch (newState) { case Phonon::ErrorState: @@ -148,7 +153,7 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState playAction->setEnabled(false); pauseAction->setEnabled(true); stopAction->setEnabled(true); - lastPlayed = plman.indexOf(mediaObject->currentSource()); + //lastPlayed = plman.indexOf(mediaObject->currentSource()); break; case Phonon::StoppedState: setWindowTitle("TomAmp"); @@ -166,18 +171,8 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState pauseAction->setVisible(false); playAction->setVisible(true); playAction->setEnabled(true); - qDebug () << "Queue size: " << mediaObject->queue().size (); - if (mediaObject->queue().size ()) - { -/* mediaObject->setCurrentSource(mediaObject->queue()[0]); - musicTable->selectRow(plman.indexOf(mediaObject->currentSource()));*/ - setItem (plman.indexOf(mediaObject->queue()[0]), true); -// mediaObject->play(); - } - mediaObject->clearQueue(); break; case Phonon::BufferingState: - qDebug () << "Buffering"; break; default: ; @@ -186,24 +181,17 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState void MainWindow::next() { - bool wasPlaying = (mediaObject->state () == Phonon::PlayingState); + bool wasPlaying = isPlaying; if (mediaObject->state () == Phonon::ErrorState) wasPlaying = true; - qDebug () << "NEXT, repeat=" << repeat << ", shuffle=" << shuffle << ", ShuffleLis size=" << shuffleList.size (); - if (shuffleList.size() != plman.size()) - qDebug () << "WHOA STRANGE SHUFFLE: " << shuffleList; int index = plman.indexOf(mediaObject->currentSource()); - qDebug () << "Current index is " << index; if (shuffle) { - qDebug () << "Shuffle next " << index; index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1; while (index < shuffleList.size () && !plman.getItem(shuffleList[index]).playable) { index += 1; - qDebug () << "Index increase a " << index; } - qDebug () << "Shuffle next 2 " << index; if (index < shuffleList.size ()) { setItem (index, wasPlaying); @@ -213,46 +201,32 @@ void MainWindow::next() index = 0; while ((index) < shuffleList.size () && !plman.getItem(shuffleList[index]).playable) { - qDebug () << "Index increase 2a " << index; index += 1; } setItem (index, wasPlaying); } -/* if (index >= shuffleList.size ()) - wasPlaying = false;*/ - } else { index++; - qDebug () << "Normal next"; while ((index) < plman.size () && !plman.getItem(index).playable) { index += 1; - qDebug () << "Index increase " << index; } - qDebug () << "Normal next 2 " << index; if (index < plman.size()) { setItem (index, wasPlaying); } else if (repeat) { - qDebug () << "Repeat on"; index = 0; while ((index) < plman.size () && !plman.getItem(index).playable) { index += 1; - qDebug () << "Index increase " << index; } setItem (index, wasPlaying); } -/* if (index >= shuffleList.size ()) - wasPlaying = false;*/ } -/* if (wasPlaying) - mediaObject->play();*/ - qDebug () << "wasPlaying: " << wasPlaying << ", playbutton visible: " << playAction->isVisible(); } void MainWindow::setItem(int i, bool doplay) @@ -263,44 +237,34 @@ void MainWindow::setItem(int i, bool doplay) unhighlightRow(lastPlayed); if (shuffle) { - qDebug () << "SetItem with shuffle, index = " << i << " real index is " << shuffleList[i]; - qDebug () << "ShuffleList: " << shuffleList; - if (doplay) - highlightRow(shuffleList[i]); mediaObject->setCurrentSource(plman.at (shuffleList[i])); -// musicTable->selectRow (shuffleList[i]); } else { - qDebug () << "SetItem without shuffle, index = " << i; - if (doplay) - highlightRow(i); mediaObject->setCurrentSource(plman.at(i)); -// musicTable->selectRow (i); } } if (doplay && mediaObject->currentSource().type() != Phonon::MediaSource::Invalid) - mediaObject->play(); + { + play(); + } + else + stop (); } void MainWindow::previous() { - bool wasPlaying = (mediaObject->state () == Phonon::PlayingState); + bool wasPlaying = isPlaying;//(mediaObject->state () == Phonon::PlayingState); if (mediaObject->state () == Phonon::ErrorState) wasPlaying = true; - qDebug () << "PREVIOUS, repeat=" << repeat << ", shuffle=" << shuffle; int index = plman.indexOf(mediaObject->currentSource()); - qDebug () << "Current index is " << index; if (shuffle) { - qDebug () << "Shuffle next"; index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) - 1; while (index >= 0 && !plman.getItem(shuffleList[index]).playable) { index--; - qDebug () << "Index increase a " << index; } - qDebug () << "Shuffle next 2 " << index; if (index >= 0) { setItem (index, wasPlaying); @@ -310,7 +274,6 @@ void MainWindow::previous() index = plman.size () - 1; while (index >= 0 && !plman.getItem(shuffleList[index]).playable) { - qDebug () << "Index increase 2a " << index; index--; } setItem (index, wasPlaying); @@ -322,36 +285,24 @@ void MainWindow::previous() else { index--; - qDebug () << "Normal next"; while ((index) >= 0 && !plman.getItem(index).playable) { index--; - qDebug () << "Index increase " << index; } - qDebug () << "Normal next 2 " << index; if (index >= 0) { setItem (index, wasPlaying); } else if (repeat) { - qDebug () << "Repeat on"; index = plman.size() - 1; while ((index) >= 0 && !plman.getItem(index).playable) { index--; - qDebug () << "Index increase " << index; } setItem (index, wasPlaying); } -/* if (index < 0) - wasPlaying = false;*/ } -/* if (wasPlaying) - mediaObject->play();*/ - qDebug () << "wasPlaying: " << wasPlaying << ", playbutton visible: " << playAction->isVisible(); - - } void MainWindow::highlightRow (int i) @@ -434,14 +385,17 @@ void MainWindow::tableClicked(int row, int /* column */) void MainWindow::sourceChanged(const Phonon::MediaSource &source) { - musicTable->selectRow(plman.indexOf(source)); + int ind = plman.indexOf(source); + highlightRow(ind); + unhighlightRow(lastPlayed); + lastPlayed = ind; + musicTable->selectRow(ind); timeLcd->display("00:00"); } void MainWindow::aboutToFinish() { - qDebug () << "Abouttotfinish"; int index = plman.indexOf(mediaObject->currentSource()) + 1; if (shuffle) { @@ -461,19 +415,16 @@ void MainWindow::aboutToFinish() if (plman.size() > index) { mediaObject->enqueue(plman.at(index)); - qDebug () << "Enqueue " << index << " pfm " << mediaObject->prefinishMark(); } else if (repeat) { mediaObject->enqueue(plman.at(0)); - qDebug () << "Enqueue " << 0 << " pfm " << mediaObject->prefinishMark(); } } } void MainWindow::finished() { - qDebug () << "Finished"; } void MainWindow::setupActions() @@ -530,9 +481,9 @@ void MainWindow::setupActions() /* removeSelected = new QAction (tr("&Delete from playlist")); removeSelected->setShortcut(tr ("Ctrl+D"));*/ - connect(playAction, SIGNAL(triggered()), mediaObject, SLOT(play())); + connect(playAction, SIGNAL(triggered()), this, SLOT(play())); connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) ); - connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop())); + connect(stopAction, SIGNAL(triggered()), this, SLOT(stop())); connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle())); connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle())); connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle())); @@ -553,7 +504,6 @@ void MainWindow::setupActions() void MainWindow::removeSelectedItem() { - qDebug () << "Remove Selected!"; int row = musicTable->currentRow(); if (row >= 0) plman.removeItem(row); @@ -561,7 +511,6 @@ void MainWindow::removeSelectedItem() void MainWindow::removeAllButSelectedItem() { - qDebug () << "Remove Selected!"; int row = musicTable->currentRow(); if (row >= 0) { @@ -576,7 +525,6 @@ void MainWindow::removeAllButSelectedItem() void MainWindow::repeatToggle () { repeat = !repeat; - qDebug() << "Repeat toggled to " << repeat; settings.setValue("repeat", QVariant (repeat)); if (repeat) repeatAction->setIcon(QIcon (QPixmap (":images/repeatActive"))); @@ -596,13 +544,21 @@ void MainWindow::shuffleToggle () void MainWindow::volumeToggle () { - qDebug () << "Volumetoggle: " << volumeAction->isChecked(); volumeSlider->setVisible(volumeAction->isChecked()); } void MainWindow::play() { + mediaObject->play(); + lastPlayed = plman.indexOf(mediaObject->currentSource()); + highlightRow(lastPlayed); + isPlaying = true; +} +void MainWindow::stop() +{ + mediaObject->stop(); + isPlaying = false; } @@ -712,7 +668,6 @@ void MainWindow::setupUi() setCentralWidget(widget); setWindowTitle("TomAmp"); - qDebug () << "cucc: " << musicTable->columnWidth(1); } void MainWindow::cellClicked(int /*row*/, int) @@ -721,7 +676,8 @@ void MainWindow::cellClicked(int /*row*/, int) void MainWindow::contextMenuEvent (QContextMenuEvent*e) { - qDebug () << "Context menu event!"; + if (!childAt (e->pos())) + return; if (childAt (e->pos())->parentWidget() != musicTable) return; contextMenu->popup(e->globalPos()); @@ -747,7 +703,6 @@ void MainWindow::setupShuffleList() shuffleList.append(tmp[ind]); tmp.removeAt(ind); } - qDebug () << shuffleList; } void MainWindow::savePlaylist () diff --git a/mainwindow.h b/mainwindow.h index 898df91..023f673 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -85,6 +85,7 @@ private slots: void finished(); void tableClicked(int row, int column); void play(); + void stop(); void next(); void previous(); void cellClicked(int row, int column); @@ -143,6 +144,7 @@ private: QSettings settings; QList shuffleList; int lastPlayed; + bool isPlaying; }; #endif diff --git a/playlistmanager.cpp b/playlistmanager.cpp index 8ee44ed..a172cdd 100644 --- a/playlistmanager.cpp +++ b/playlistmanager.cpp @@ -47,8 +47,11 @@ void PlaylistManager::parseAndAddFolder(const QString &dir, bool recursive) parseAndAddFolder(fname, true); continue; } - qDebug () << "Adding: " << fname; - items.append(PlaylistItem (PlaylistItem (fname))); + if (fileSupported(fname)) + { + qDebug () << "Adding: " << fname; + items.append(PlaylistItem (PlaylistItem (fname))); + } } if (!items.isEmpty()) metaInformationResolver->setCurrentSource(items.at(index).source); @@ -61,47 +64,44 @@ void PlaylistManager::addStringList(const QStringList& list) int index = items.size(); foreach (QString string, list) { - qDebug () << "Adding " << string; - items.append(PlaylistItem (string)); + if (fileSupported(string) || string.toLower().startsWith("http")) + { + qDebug () << "Adding " << string; + items.append(PlaylistItem (string)); + } } if (!items.isEmpty()) metaInformationResolver->setCurrentSource(items.at(index).source); emit playlistChanged(index); } -void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */) +void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State oldState) { + qDebug () << "Meta state now " << newState << " old state " << oldState; + if (oldState == Phonon::ErrorState) + { +/* int index = indexOf (metaInformationResolver->currentSource()); + metaInformationResolver->setCurrentSource(items[index].source);*/ + } if (newState == Phonon::ErrorState) { -// QMessageBox::warning(this, tr("Error opening files"), -// metaInformationResolver->errorString()); -// while (!items.isEmpty() && -// !(items.takeLast().source == metaInformationResolver->currentSource())) {} /* loop */; int index = indexOf (metaInformationResolver->currentSource()); - if (index >= 0 && items.size () > index - 1) + if (index >= 0 && items.size () > index + 1) + { +/* metaInformationResolver->disconnect(); + delete metaInformationResolver; + metaInformationResolver = new Phonon::MediaObject(parent()); + connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));*/ metaInformationResolver->setCurrentSource(items[index + 1].source); +// metaInformationResolver->clear(); + qDebug () << "Set " << items[index + 1].source.fileName() << " error type: " << metaInformationResolver->errorString() << " (" << metaInformationResolver->errorType() << ")"; + } qDebug () << "Error for item " << index; -/* int index = sources.indexOf(metaInformationResolver->currentSource()); - if (index >= 0) - { - sources.removeAt(index); - qDebug () << "Removing invalid file in " << index << ": " << metaInformationResolver->currentSource().fileName(); - if (sources.size() > index) - { - metaInformationResolver->setCurrentSource(sources.at(index)); - qDebug () << "Setting new info source " << sources.at(index).fileName(); - } - }*/ -// int index = sources.indexOf(metaInformationResolver->currentSource()) + 1; -// sources.removeAt(index - 1); -// if (items.size()) -// { -// metaInformationResolver->setCurrentSource(sources.at(0)); -// } return; } - if (newState != Phonon::StoppedState && newState != Phonon::PausedState) + if (newState != Phonon::StoppedState/* && newState != Phonon::PausedState*/) { return; } @@ -109,24 +109,17 @@ void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State /* if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid) return; int index = indexOf (metaInformationResolver->currentSource()); - qDebug () << "Reading meta info of " << metaInformationResolver->currentSource().fileName() << " " << index; - - qDebug () << "Index of this source is " << indexOf(metaInformationResolver->currentSource()); + qDebug () << "Reading meta info of " << metaInformationResolver->currentSource().fileName() << " => " << index; QMap metaData = metaInformationResolver->metaData(); -/* QString title = metaData.value("TITLE"); - if (title == "") - title = metaInformationResolver->currentSource().fileName(); - - if (title == "") - title = metaInformationResolver->currentSource().url().toString();*/ if (index >= 0) { items[index].artist = metaData.value("ARTIST"); items[index].title = metaData.value("TITLE"); items[index].album = metaData.value("ALBUM"); + qDebug () << "Info is: " << items[index].artist << " - " << items[index].title; if (metaData.isEmpty()) qDebug () << "Detected to be empty: " << items[index].uri; else @@ -135,38 +128,6 @@ void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State /* if (index >= 0 && items.size () > index + 1) metaInformationResolver->setCurrentSource(items[index + 1].source); } - - /*QTableWidgetItem *titleItem = new QTableWidgetItem(title); - titleItem->setFlags(titleItem->flags() ^ Qt::ItemIsEditable); - QTableWidgetItem *artistItem = new QTableWidgetItem(metaData.value("ARTIST")); - artistItem->setFlags(artistItem->flags() ^ Qt::ItemIsEditable); - QTableWidgetItem *albumItem = new QTableWidgetItem(metaData.value("ALBUM")); - albumItem->setFlags(albumItem->flags() ^ Qt::ItemIsEditable);*/ - -/* int currentRow = musicTable->rowCount(); - musicTable->insertRow(currentRow); - musicTable->setItem(currentRow, 0, artistItem); - musicTable->setItem(currentRow, 1, titleItem); - musicTable->setItem(currentRow, 2, albumItem);*/ - - -/* if (musicTable->selectedItems().isEmpty()) - { - musicTable->selectRow(0); - qDebug () << "Setting current media " + metaInformationResolver->currentSource().fileName(); - mediaObject->setCurrentSource(metaInformationResolver->currentSource()); - } - - Phonon::MediaSource source = metaInformationResolver->currentSource(); - int index = sources.indexOf(metaInformationResolver->currentSource()) + 1; - if (sources.size() > index) - { - metaInformationResolver->setCurrentSource(sources.at(index)); - } - else - { - musicTable->resizeColumnsToContents(); - }*/ } void PlaylistManager::savePlaylist(const QString& filenam) @@ -339,3 +300,11 @@ void PlaylistManager::removeItem(int i) items.removeAt (i); emit playlistChanged(i); } + +bool PlaylistManager::fileSupported (const QString& fname) const +{ + QString ext = fname.right(3).toLower(); +// if (ext != "mp3") +// return false; + return true; +} diff --git a/playlistmanager.h b/playlistmanager.h index a22008b..25e6dde 100644 --- a/playlistmanager.h +++ b/playlistmanager.h @@ -45,6 +45,7 @@ private slots: void appendPlaylist (const QString& filename); void appendPlaylistPLS (const QString& filename); private: + bool fileSupported (const QString& fname) const; Phonon::MediaObject *metaInformationResolver; QList items; -- 1.7.9.5