//#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);
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;
#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);
void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
{
- qDebug () << "State: " << newState;
switch (newState)
{
case Phonon::ErrorState:
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");
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:
;
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);
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)
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);
index = plman.size () - 1;
while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
{
- qDebug () << "Index increase 2a " << index;
index--;
}
setItem (index, wasPlaying);
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)
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)
{
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()
/* 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()));
void MainWindow::removeSelectedItem()
{
- qDebug () << "Remove Selected!";
int row = musicTable->currentRow();
if (row >= 0)
plman.removeItem(row);
void MainWindow::removeAllButSelectedItem()
{
- qDebug () << "Remove Selected!";
int row = musicTable->currentRow();
if (row >= 0)
{
void MainWindow::repeatToggle ()
{
repeat = !repeat;
- qDebug() << "Repeat toggled to " << repeat;
settings.setValue("repeat", QVariant (repeat));
if (repeat)
repeatAction->setIcon(QIcon (QPixmap (":images/repeatActive")));
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;
}
setCentralWidget(widget);
setWindowTitle("TomAmp");
- qDebug () << "cucc: " << musicTable->columnWidth(1);
}
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());
shuffleList.append(tmp[ind]);
tmp.removeAt(ind);
}
- qDebug () << shuffleList;
}
void MainWindow::savePlaylist ()
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);
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;
}
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<QString, QString> 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
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)
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;
+}