3 #include <QInputDialog>
5 #include "mainwindow.h"
8 //#define AVOID_INPUT_DIALOG 0
10 MainWindow::MainWindow()
11 : plman (this), settings (tr ("TomAmp"), "TomAmp")
13 audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
14 mediaObject = new Phonon::MediaObject(this);
16 mediaObject->setTickInterval(1000);
17 connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
18 connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
19 this, SLOT(stateChanged(Phonon::State,Phonon::State)));
20 connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
21 this, SLOT(sourceChanged(Phonon::MediaSource)));
22 connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
23 connect (&plman, SIGNAL (playlistChanged (int)), this, SLOT (playlistChanged(int)));
24 connect (&plman, SIGNAL (itemUpdated(int)), this, SLOT (itemUpdated (int)));
26 Phonon::createPath(mediaObject, audioOutput);
29 repeat = settings.value("repeat", false).toBool();
30 shuffle = settings.value("shuffle", false).toBool();
35 timeLcd->display("00:00");
36 plman.addStringList(settings.value("lastPlaylist").toStringList());
38 int curind = settings.value("currentIndex", -1).toInt ();
40 setItem (curind, false);
41 audioOutput->setVolume(settings.value("volume", .5).toReal());
42 QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
45 MainWindow::~MainWindow()
47 settings.setValue("shuffle", shuffle);
48 settings.setValue("repeat", repeat);
49 settings.setValue("lastPlaylist", plman.playlistStrings());
50 settings.setValue("volume", audioOutput->volume());
51 settings.setValue("currentIndex", plman.indexOf(mediaObject->currentSource()));
52 for (int i = 0; i < musicTable->columnCount(); ++i)
54 QString lab = QString ("colWidth_%1").arg (i);
55 settings.setValue(lab, musicTable->columnWidth(i));
59 void MainWindow::addFiles()
61 QString folder = settings.value("LastFolder").toString();
63 folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
64 QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Files To Add"),
65 folder, "Music files (*.mp3 *.ogg *.wav *.flac);;Playlists (*.m3u *.pls)");
70 QString dir = QFileInfo (files[0]).absoluteDir().absolutePath();
71 settings.setValue("LastFolder", dir);
73 foreach (QString string, files)
75 if (string.toLower().endsWith(".pls") || string.toLower().endsWith(".m3u"))
76 plman.addPlaylist(string);
78 toadd.append (string);
80 plman.addStringList(toadd);
83 void MainWindow::addFolder()
85 QString folder = settings.value("LastFolder").toString();
87 folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
88 QString dir = QFileDialog::getExistingDirectory(this,
89 tr("Select Directory To Add"),
93 QStringList files = QDir (dir).entryList(filters, QDir::AllDirs);
95 files.removeAll("..");
97 bool recursive = false;
99 recursive = QMessageBox::question(this, "Add all folders", "Subfolders have been detected, add everything?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
100 plman.parseAndAddFolder(dir, recursive);
104 void MainWindow::addUrl()
106 #ifdef AVOID_INPUT_DIALOG
107 QString url = "http://war.str3am.com:7970";
109 QString url = QInputDialog::getText(this, "Get URL", "Please type in the stream URL");
113 plman.addStringList(toadd);
117 void MainWindow::about()
119 QMessageBox::information(this, tr("About TomAmp v0.1"),
120 tr("TomAmp is a simple playlist-based music player.\n\n"
121 "(c) 2010 Tamas Marki <tmarki@gmail.com>\n\n"
122 "Please send comments and bug reports to the above e-mail address.\n\n"
123 "Icons by http://itweek.deviantart.com/"));
126 void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
128 qDebug () << "State: " << newState;
131 case Phonon::ErrorState:
132 if (mediaObject->errorType() == Phonon::FatalError)
134 // QMessageBox::warning(this, tr("Fatal Error"),
135 // mediaObject->errorString() + mediaObject->currentSource().fileName() + ", " + mediaObject->currentSource().url().toString());
139 // QMessageBox::warning(this, tr("Error"),
140 // mediaObject->errorString());
144 case Phonon::PlayingState:
145 setWindowTitle(mediaObject->metaData().value("TITLE") + " - TomAmp");
146 pauseAction->setVisible(true);
147 playAction->setVisible (false);
148 playAction->setEnabled(false);
149 pauseAction->setEnabled(true);
150 stopAction->setEnabled(true);
151 lastPlayed = plman.indexOf(mediaObject->currentSource());
153 case Phonon::StoppedState:
154 setWindowTitle("TomAmp");
155 stopAction->setEnabled(false);
156 playAction->setEnabled(true);
157 pauseAction->setVisible(false);
158 playAction->setVisible(true);
159 pauseAction->setEnabled(false);
160 timeLcd->display("00:00");
161 unhighlightRow(plman.indexOf(mediaObject->currentSource()));
163 case Phonon::PausedState:
164 pauseAction->setEnabled(false);
165 stopAction->setEnabled(true);
166 pauseAction->setVisible(false);
167 playAction->setVisible(true);
168 playAction->setEnabled(true);
169 qDebug () << "Queue size: " << mediaObject->queue().size ();
170 if (mediaObject->queue().size ())
172 /* mediaObject->setCurrentSource(mediaObject->queue()[0]);
173 musicTable->selectRow(plman.indexOf(mediaObject->currentSource()));*/
174 setItem (plman.indexOf(mediaObject->queue()[0]), true);
175 // mediaObject->play();
177 mediaObject->clearQueue();
179 case Phonon::BufferingState:
180 qDebug () << "Buffering";
187 void MainWindow::next()
189 bool wasPlaying = (mediaObject->state () == Phonon::PlayingState);
190 if (mediaObject->state () == Phonon::ErrorState)
192 qDebug () << "NEXT, repeat=" << repeat << ", shuffle=" << shuffle << ", ShuffleLis size=" << shuffleList.size ();
193 if (shuffleList.size() != plman.size())
194 qDebug () << "WHOA STRANGE SHUFFLE: " << shuffleList;
195 int index = plman.indexOf(mediaObject->currentSource());
196 qDebug () << "Current index is " << index;
199 qDebug () << "Shuffle next " << index;
200 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
201 while (index < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
204 qDebug () << "Index increase a " << index;
206 qDebug () << "Shuffle next 2 " << index;
207 if (index < shuffleList.size ())
209 setItem (index, wasPlaying);
214 while ((index) < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
216 qDebug () << "Index increase 2a " << index;
219 setItem (index, wasPlaying);
221 /* if (index >= shuffleList.size ())
222 wasPlaying = false;*/
228 qDebug () << "Normal next";
229 while ((index) < plman.size () && !plman.getItem(index).playable)
232 qDebug () << "Index increase " << index;
234 qDebug () << "Normal next 2 " << index;
235 if (index < plman.size())
237 setItem (index, wasPlaying);
241 qDebug () << "Repeat on";
243 while ((index) < plman.size () && !plman.getItem(index).playable)
246 qDebug () << "Index increase " << index;
248 setItem (index, wasPlaying);
250 /* if (index >= shuffleList.size ())
251 wasPlaying = false;*/
254 mediaObject->play();*/
255 qDebug () << "wasPlaying: " << wasPlaying << ", playbutton visible: " << playAction->isVisible();
258 void MainWindow::setItem(int i, bool doplay)
260 if (i < plman.size() && i >= 0)
263 unhighlightRow(lastPlayed);
266 qDebug () << "SetItem with shuffle, index = " << i << " real index is " << shuffleList[i];
267 qDebug () << "ShuffleList: " << shuffleList;
269 highlightRow(shuffleList[i]);
270 mediaObject->setCurrentSource(plman.at (shuffleList[i]));
271 // musicTable->selectRow (shuffleList[i]);
275 qDebug () << "SetItem without shuffle, index = " << i;
278 mediaObject->setCurrentSource(plman.at(i));
279 // musicTable->selectRow (i);
282 if (doplay && mediaObject->currentSource().type() != Phonon::MediaSource::Invalid)
286 void MainWindow::previous()
288 bool wasPlaying = (mediaObject->state () == Phonon::PlayingState);
289 if (mediaObject->state () == Phonon::ErrorState)
291 qDebug () << "PREVIOUS, repeat=" << repeat << ", shuffle=" << shuffle;
292 int index = plman.indexOf(mediaObject->currentSource());
293 qDebug () << "Current index is " << index;
296 qDebug () << "Shuffle next";
297 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) - 1;
298 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
301 qDebug () << "Index increase a " << index;
303 qDebug () << "Shuffle next 2 " << index;
306 setItem (index, wasPlaying);
310 index = plman.size () - 1;
311 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
313 qDebug () << "Index increase 2a " << index;
316 setItem (index, wasPlaying);
319 wasPlaying = false;*/
325 qDebug () << "Normal next";
326 while ((index) >= 0 && !plman.getItem(index).playable)
329 qDebug () << "Index increase " << index;
331 qDebug () << "Normal next 2 " << index;
334 setItem (index, wasPlaying);
338 qDebug () << "Repeat on";
339 index = plman.size() - 1;
340 while ((index) >= 0 && !plman.getItem(index).playable)
343 qDebug () << "Index increase " << index;
345 setItem (index, wasPlaying);
348 wasPlaying = false;*/
351 mediaObject->play();*/
352 qDebug () << "wasPlaying: " << wasPlaying << ", playbutton visible: " << playAction->isVisible();
357 void MainWindow::highlightRow (int i)
359 for (int j = 0; j < 3; ++j)
361 QTableWidgetItem* item = musicTable->item(i, j);
364 QFont font = item->font();
366 font.setItalic(true);
372 void MainWindow::unhighlightRow (int i)
374 for (int j = 0; j < 3; ++j)
376 QTableWidgetItem* item = musicTable->item(i, j);
379 QFont font = item->font();
381 font.setItalic(false);
388 void MainWindow::tick(qint64 time)
390 QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
392 timeLcd->display(displayTime.toString("mm:ss"));
395 void MainWindow::tableClicked(int row, int /* column */)
397 // bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
399 /* mediaObject->stop();
400 mediaObject->clearQueue();*/
402 if (row >= plman.size())
406 while (index < shuffleList.size () && !plman.getItem(index).playable)
410 if (plman.size() > index)
413 index = shuffleList.indexOf(index);
414 setItem (index, true);
415 // mediaObject->play();
420 while (index < plman.size () && !plman.getItem(index).playable)
424 if (plman.size() > index)
427 index = shuffleList.indexOf(index);
428 setItem (index, true);
429 // mediaObject->play();
435 void MainWindow::sourceChanged(const Phonon::MediaSource &source)
437 musicTable->selectRow(plman.indexOf(source));
438 timeLcd->display("00:00");
442 void MainWindow::aboutToFinish()
444 qDebug () << "Abouttotfinish";
445 int index = plman.indexOf(mediaObject->currentSource()) + 1;
448 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
449 if (index < shuffleList.size ())
451 mediaObject->enqueue(plman.at (shuffleList[index]));
455 mediaObject->enqueue(plman.at (shuffleList[0]));
461 if (plman.size() > index)
463 mediaObject->enqueue(plman.at(index));
464 qDebug () << "Enqueue " << index << " pfm " << mediaObject->prefinishMark();
468 mediaObject->enqueue(plman.at(0));
469 qDebug () << "Enqueue " << 0 << " pfm " << mediaObject->prefinishMark();
474 void MainWindow::finished()
476 qDebug () << "Finished";
479 void MainWindow::setupActions()
481 playAction = new QAction(QIcon (QPixmap (":images/play")), tr("Play"), this);
482 playAction->setShortcut(tr("Crl+P"));
483 playAction->setDisabled(true);
484 pauseAction = new QAction(QIcon (QPixmap (":images/pause")), tr("Pause"), this);
485 pauseAction->setShortcut(tr("Ctrl+A"));
486 pauseAction->setDisabled(true);
487 pauseAction->setVisible(false);
488 stopAction = new QAction(QIcon (QPixmap (":images/stop")), tr("Stop"), this);
489 stopAction->setShortcut(tr("Ctrl+S"));
490 stopAction->setDisabled(true);
491 nextAction = new QAction(QIcon (QPixmap (":images/next")), tr("Next"), this);
492 nextAction->setShortcut(tr("Ctrl+N"));
493 previousAction = new QAction(QIcon (QPixmap (":images/previous")), tr("Previous"), this);
494 previousAction->setShortcut(tr("Ctrl+R"));
496 repeatAction = new QAction(QIcon (QPixmap (":images/repeatActive")), tr("Repeat"), this);
498 repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), tr("Repeat"), this);
499 repeatAction->setCheckable(true);
500 repeatAction->setChecked(repeat);
501 repeatAction->setShortcut(tr("Ctrl+I"));
503 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffleActive")), tr("Shuffle"), this);
505 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), tr("Shuffle"), this);
506 shuffleAction->setCheckable(true);
507 shuffleAction->setChecked(shuffle);
508 shuffleAction->setShortcut(tr("Ctrl+H"));
509 volumeAction = new QAction(QIcon (QPixmap (":images/volume")), tr("Volume"), this);
510 volumeAction->setCheckable(true);
511 volumeAction->setShortcut(tr("Ctrl+V"));
512 addFilesAction = new QAction(tr("Add &File"), this);
513 addFilesAction->setShortcut(tr("Ctrl+F"));
514 addFoldersAction = new QAction(tr("Add F&older"), this);
515 addFoldersAction->setShortcut(tr("Ctrl+O"));
516 addUrlAction = new QAction(tr("Add &Url"), this);
517 addUrlAction->setShortcut(tr("Ctrl+U"));
518 savePlaylistAction = new QAction (tr("Sa&ve Playlist"), this);
519 savePlaylistAction->setShortcut(tr ("Ctrl+V"));
520 loadPlaylistAction = new QAction (tr("&Load Playlist"), this);
521 loadPlaylistAction->setShortcut(tr("Ctrl+L"));
522 clearPlaylistAction = new QAction (tr("&Clear Playlist"), this);
523 clearPlaylistAction->setShortcut(tr("Ctrl+C"));
524 exitAction = new QAction(tr("E&xit"), this);
525 exitAction->setShortcut(tr("Ctrl+X"));
526 aboutAction = new QAction(tr("A&bout"), this);
527 aboutAction->setShortcut(tr("Ctrl+B"));
528 aboutQtAction = new QAction(tr("About &Qt"), this);
529 aboutQtAction->setShortcut(tr("Ctrl+Q"));
530 /* removeSelected = new QAction (tr("&Delete from playlist"));
531 removeSelected->setShortcut(tr ("Ctrl+D"));*/
533 connect(playAction, SIGNAL(triggered()), mediaObject, SLOT(play()));
534 connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
535 connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop()));
536 connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
537 connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
538 connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
540 connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
541 connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
542 connect(addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
543 connect (savePlaylistAction, SIGNAL (triggered()), this, SLOT (savePlaylist()));
544 connect (loadPlaylistAction, SIGNAL (triggered()), this, SLOT (loadPlaylist()));
545 connect (clearPlaylistAction, SIGNAL (triggered()), &plman, SLOT (clearPlaylist()));
546 connect (nextAction, SIGNAL(triggered()), this, SLOT(next()));
547 connect (previousAction, SIGNAL(triggered()), this, SLOT(previous()));
548 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
549 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
550 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
551 // connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
554 void MainWindow::removeSelectedItem()
556 qDebug () << "Remove Selected!";
557 int row = musicTable->currentRow();
559 plman.removeItem(row);
562 void MainWindow::removeAllButSelectedItem()
564 qDebug () << "Remove Selected!";
565 int row = musicTable->currentRow();
568 QString uri = plman.getItem(row).uri;
571 plman.clearPlaylist();
572 plman.addStringList(lst);
576 void MainWindow::repeatToggle ()
579 qDebug() << "Repeat toggled to " << repeat;
580 settings.setValue("repeat", QVariant (repeat));
582 repeatAction->setIcon(QIcon (QPixmap (":images/repeatActive")));
584 repeatAction->setIcon(QIcon (QPixmap (":images/repeat")));
587 void MainWindow::shuffleToggle ()
590 settings.setValue("shuffle", QVariant (shuffle));
592 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffleActive")));
594 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffle")));
597 void MainWindow::volumeToggle ()
599 qDebug () << "Volumetoggle: " << volumeAction->isChecked();
600 volumeSlider->setVisible(volumeAction->isChecked());
603 void MainWindow::play()
609 void MainWindow::setupMenus()
611 QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
612 fileMenu->addAction(addFilesAction);
613 fileMenu->addAction(addFoldersAction);
614 fileMenu->addAction(addUrlAction);
615 fileMenu->addSeparator();
616 fileMenu->addAction(savePlaylistAction);
617 fileMenu->addAction(loadPlaylistAction);
618 fileMenu->addAction(clearPlaylistAction);
619 // fileMenu->addAction(exitAction);
621 QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
622 aboutMenu->addAction(aboutAction);
623 aboutMenu->addAction(aboutQtAction);
626 void MainWindow::setupUi()
628 QToolBar *bar = new QToolBar;
630 bar->setOrientation(Qt::Vertical);
631 bar->setStyleSheet("padding:7px");
632 //bar->addAction(volumeAction);
634 seekSlider = new Phonon::SeekSlider(this);
635 seekSlider->setMediaObject(mediaObject);
637 volumeSlider = new Phonon::VolumeSlider(this);
638 volumeSlider->setAudioOutput(audioOutput);
639 volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
640 volumeSlider->setOrientation(Qt::Horizontal);
641 volumeSlider->setMuteVisible(false);
642 // volumeAddedAction = bar->addWidget(volumeSlider);
643 // volumeAddedAction->setVisible(false);
644 bar->addAction(playAction);
645 bar->addAction(pauseAction);
646 bar->addAction(stopAction);
647 bar->addAction(repeatAction);
648 bar->addAction(shuffleAction);
649 bar->addAction(nextAction);
650 bar->addAction(previousAction);
652 contextMenu = new QMenu (this);
653 removeSelected = contextMenu->addAction(tr ("Remove selected"));
654 removeAllButSelected = contextMenu->addAction(tr("Remove all but selected"));
655 connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
656 connect (removeAllButSelected, SIGNAL (triggered()), this, SLOT (removeAllButSelectedItem()));
659 timeLcd = new QLCDNumber;
662 headers << tr("Artist") << tr("Title") << tr("Album");
664 musicTable = new QTableWidget(0, 3);
665 musicTable->setHorizontalHeaderLabels(headers);
666 musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
667 musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
668 connect(musicTable, SIGNAL(cellDoubleClicked(int,int)),
669 this, SLOT(tableClicked(int,int)));
670 connect(musicTable, SIGNAL(cellClicked(int,int)),
671 this, SLOT(cellClicked(int,int)));
672 /* for (int i = 0; i < 3; ++i)
674 if (!musicTable->horizontalHeaderItem(i))
676 musicTable->horizontalHeaderItem(i)->setBackgroundColor(QColor (128, 128, 255));;
677 musicTable->horizontalHeaderItem(i)->setForeground(QColor (255, 255, 255));
679 for (int i = 0; i < musicTable->columnCount(); ++i)
681 QString lab = QString ("colWidth_%1").arg (i);
682 int val = settings.value(lab, 0).toInt();
684 musicTable->setColumnWidth(i, val);
685 // settings.setValue(lab, musicTable->columnWidth(i));
689 QHBoxLayout *seekerLayout = new QHBoxLayout;
690 QToolBar* bar2 = new QToolBar;
691 bar2->addAction(volumeAction);
692 seekerLayout->addWidget(bar2);
693 seekerLayout->addWidget(volumeSlider);
694 seekerLayout->addWidget(seekSlider);
695 seekerLayout->addWidget(timeLcd);
697 QVBoxLayout *playbackLayout = new QVBoxLayout;
698 volumeSlider->hide ();
699 playbackLayout->addWidget(bar);
701 QVBoxLayout *seekAndTableLayout = new QVBoxLayout;
703 seekAndTableLayout->addWidget(musicTable);
704 seekAndTableLayout->addLayout(seekerLayout);
706 QHBoxLayout *mainLayout = new QHBoxLayout;
707 mainLayout->addLayout(seekAndTableLayout);
708 mainLayout->addLayout(playbackLayout);
710 QWidget *widget = new QWidget;
711 widget->setLayout(mainLayout);
713 setCentralWidget(widget);
714 setWindowTitle("TomAmp");
715 qDebug () << "cucc: " << musicTable->columnWidth(1);
718 void MainWindow::cellClicked(int /*row*/, int)
722 void MainWindow::contextMenuEvent (QContextMenuEvent*e)
724 qDebug () << "Context menu event!";
725 if (childAt (e->pos())->parentWidget() != musicTable)
727 contextMenu->popup(e->globalPos());
731 void MainWindow::setupShuffleList()
734 int index = plman.indexOf(mediaObject->currentSource());
737 for (int i = 0; i < plman.size(); ++i)
743 shuffleList.append (index);
746 int ind = qrand () % tmp.size();
747 shuffleList.append(tmp[ind]);
750 qDebug () << shuffleList;
753 void MainWindow::savePlaylist ()
755 QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u *.pls)");
756 if (filename.isEmpty())
758 plman.savePlaylist(filename);
761 void MainWindow::loadPlaylist ()
763 QString filename = QFileDialog::getOpenFileName(this, tr("Select playlist file to load"), "", "*.m3u *.pls");
764 if (filename.isEmpty())
766 plman.loadPlaylist (filename);
769 void MainWindow::playlistChanged(int from)
771 while (musicTable->rowCount() > from)
773 musicTable->removeRow(musicTable->rowCount () - 1);
776 for (int i = from; i < plman.size (); ++i)
778 if (firstGood < 0 && plman.getItem (i).playable)
780 int currentRow = musicTable->rowCount();
781 musicTable->insertRow(currentRow);
782 setRowFromItem (currentRow, plman.getItem(i));
784 if (plman.indexOf(mediaObject->currentSource()) < 0)
786 setItem (firstGood, false);
791 void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
793 if (row >= musicTable->rowCount())
795 if (item.artist.isEmpty() && item.title.isEmpty())
797 QTableWidgetItem *item1 = new QTableWidgetItem(item.uri);
798 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
799 musicTable->setItem(row, 1, item1);
803 QTableWidgetItem *item1 = new QTableWidgetItem(item.artist);
804 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
805 musicTable->setItem(row, 0, item1);
806 QTableWidgetItem *item2 = new QTableWidgetItem(item.title);
807 item2->setFlags(item2->flags() ^ Qt::ItemIsEditable);
808 musicTable->setItem(row, 1, item2);
809 QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
810 item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
811 musicTable->setItem(row, 2, item3);
815 void MainWindow::itemUpdated(int index)
817 if (plman.indexOf(mediaObject->currentSource()) < 0 && plman.getItem (index).playable)
819 setItem (index, false);
821 setRowFromItem (index, plman.getItem(index));
822 if (plman.indexOf(mediaObject->currentSource()) == index)
824 if (shuffle) index = shuffleList.indexOf(index);
825 setItem (index, false);