3 #include <QInputDialog>
5 #include "mainwindow.h"
8 //#define AVOID_INPUT_DIALOG 0
10 MainWindow::MainWindow()
11 : plman (this), settings (tr ("TomAmp"), "TomAmp"), isPlaying (false)
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)));
25 connect (&plman, SIGNAL (itemRemoved(int)), this, SLOT (itemRemoved (int)));
27 Phonon::createPath(mediaObject, audioOutput);
30 repeat = settings.value("repeat", false).toBool();
31 shuffle = settings.value("shuffle", false).toBool();
37 timeLcd->display("00:00:00");
38 plman.addStringList(settings.value("lastPlaylist").toStringList());
40 int curind = settings.value("currentIndex", -1).toInt ();
42 setItem (curind, false);
43 audioOutput->setVolume(settings.value("volume", .5).toReal());
44 QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
47 MainWindow::~MainWindow()
49 settings.setValue("shuffle", shuffle);
50 settings.setValue("repeat", repeat);
51 settings.setValue("lastPlaylist", plman.playlistStrings());
52 settings.setValue("volume", audioOutput->volume());
53 settings.setValue("currentIndex", plman.indexOf(mediaObject->currentSource()));
54 for (int i = 0; i < musicTable->columnCount(); ++i)
56 QString lab = QString ("colWidth_%1").arg (i);
57 settings.setValue(lab, musicTable->columnWidth(i));
61 void MainWindow::addFiles()
63 QString folder = settings.value("LastFolder").toString();
65 folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
66 QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Files To Add"),
67 folder, "Music files (*.mp3 *.ogg *.wav *.flac);;Playlists (*.m3u *.pls)");
72 QString dir = QFileInfo (files[0]).absoluteDir().absolutePath();
73 settings.setValue("LastFolder", dir);
75 foreach (QString string, files)
77 if (string.toLower().endsWith(".pls") || string.toLower().endsWith(".m3u"))
78 plman.addPlaylist(string);
80 toadd.append (string);
82 plman.addStringList(toadd);
85 void MainWindow::addFolder()
87 QString folder = settings.value("LastFolder").toString();
89 folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
90 QString dir = QFileDialog::getExistingDirectory(this,
91 tr("Select Directory To Add"),
97 settings.setValue("LastFolder", dir);
100 QStringList files = QDir (dir).entryList(filters, QDir::AllDirs);
101 files.removeAll(".");
102 files.removeAll("..");
103 bool recursive = false;
105 recursive = QMessageBox::question(this, "Add all folders", "Subfolders have been detected, add everything?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
106 plman.parseAndAddFolder(dir, recursive);
110 void MainWindow::addUrl()
112 #ifdef AVOID_INPUT_DIALOG
113 QString url = "http://war.str3am.com:7970";
115 QString url = QInputDialog::getText(this, "Get URL", "Please type in the stream URL");
117 if (url.isEmpty() || !url.toLower().startsWith("http"))
121 plman.addStringList(toadd);
125 void MainWindow::about()
127 QMessageBox::information(this, tr("About TomAmp v0.1"),
128 tr("TomAmp is a simple playlist-based music player.\n\n"
129 "(c) 2010 Tamas Marki <tmarki@gmail.com>\n\n"
130 "Please send comments and bug reports to the above e-mail address.\n\n"
131 "Icons by http://itweek.deviantart.com/"));
134 void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
138 case Phonon::ErrorState:
139 if (mediaObject->errorType() == Phonon::FatalError)
141 // QMessageBox::warning(this, tr("Fatal Error"),
142 // mediaObject->errorString() + mediaObject->currentSource().fileName() + ", " + mediaObject->currentSource().url().toString());
146 // QMessageBox::warning(this, tr("Error"),
147 // mediaObject->errorString());
151 case Phonon::PlayingState:
152 setWindowTitle(mediaObject->metaData().value("TITLE") + " - TomAmp");
153 pauseAction->setVisible(true);
154 playAction->setVisible (false);
155 playAction->setEnabled(false);
156 pauseAction->setEnabled(true);
157 stopAction->setEnabled(true);
158 //lastPlayed = plman.indexOf(mediaObject->currentSource());
160 case Phonon::StoppedState:
161 setWindowTitle("TomAmp");
162 stopAction->setEnabled(false);
163 playAction->setEnabled(true);
164 pauseAction->setVisible(false);
165 playAction->setVisible(true);
166 pauseAction->setEnabled(false);
167 timeLcd->display("00:00:00");
168 unhighlightRow(plman.indexOf(mediaObject->currentSource()));
170 case Phonon::PausedState:
171 pauseAction->setEnabled(false);
172 stopAction->setEnabled(true);
173 pauseAction->setVisible(false);
174 playAction->setVisible(true);
175 playAction->setEnabled(true);
177 case Phonon::BufferingState:
184 void MainWindow::next()
186 bool wasPlaying = isPlaying;
187 if (mediaObject->state () == Phonon::ErrorState)
189 int index = plman.indexOf(mediaObject->currentSource());
192 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
193 while (index < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
197 if (index < shuffleList.size ())
199 setItem (index, wasPlaying);
204 while ((index) < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
208 setItem (index, wasPlaying);
214 while ((index) < plman.size () && !plman.getItem(index).playable)
218 if (index < plman.size())
220 setItem (index, wasPlaying);
225 while ((index) < plman.size () && !plman.getItem(index).playable)
229 setItem (index, wasPlaying);
234 void MainWindow::setItem(int i, bool doplay)
236 if (i < plman.size() && i >= 0)
239 unhighlightRow(lastPlayed);
242 mediaObject->setCurrentSource(plman.at (shuffleList[i]));
246 mediaObject->setCurrentSource(plman.at(i));
249 if (doplay && mediaObject->currentSource().type() != Phonon::MediaSource::Invalid)
257 void MainWindow::previous()
259 bool wasPlaying = isPlaying;//(mediaObject->state () == Phonon::PlayingState);
260 if (mediaObject->state () == Phonon::ErrorState)
262 int index = plman.indexOf(mediaObject->currentSource());
265 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) - 1;
266 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
272 setItem (index, wasPlaying);
276 index = plman.size () - 1;
277 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
281 setItem (index, wasPlaying);
284 wasPlaying = false;*/
290 while ((index) >= 0 && !plman.getItem(index).playable)
296 setItem (index, wasPlaying);
300 index = plman.size() - 1;
301 while ((index) >= 0 && !plman.getItem(index).playable)
305 setItem (index, wasPlaying);
310 void MainWindow::highlightRow (int i)
312 for (int j = 0; j < 3; ++j)
314 QTableWidgetItem* item = musicTable->item(i, j);
317 QFont font = item->font();
319 font.setItalic(true);
325 void MainWindow::unhighlightRow (int i)
327 for (int j = 0; j < 3; ++j)
329 QTableWidgetItem* item = musicTable->item(i, j);
332 QFont font = item->font();
334 font.setItalic(false);
341 void MainWindow::tick(qint64 time)
343 QTime displayTime((time / 3600000), (time / 60000) % 60, (time / 1000) % 60);
345 timeLcd->display(displayTime.toString("HH:mm:ss"));
348 void MainWindow::tableClicked(int row, int /* column */)
350 // bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
352 /* mediaObject->stop();
353 mediaObject->clearQueue();*/
355 if (row >= plman.size())
359 while (index < shuffleList.size () && !plman.getItem(index).playable)
363 if (plman.size() > index)
366 index = shuffleList.indexOf(index);
367 setItem (index, true);
368 // mediaObject->play();
373 while (index < plman.size () && !plman.getItem(index).playable)
377 if (plman.size() > index)
380 index = shuffleList.indexOf(index);
381 setItem (index, true);
382 // mediaObject->play();
388 void MainWindow::sourceChanged(const Phonon::MediaSource &source)
390 int ind = plman.indexOf(source);
392 unhighlightRow(lastPlayed);
394 musicTable->selectRow(ind);
395 timeLcd->display("00:00:00");
399 void MainWindow::aboutToFinish()
401 int index = plman.indexOf(mediaObject->currentSource()) + 1;
404 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
405 if (index < shuffleList.size ())
407 mediaObject->enqueue(plman.at (shuffleList[index]));
411 mediaObject->enqueue(plman.at (shuffleList[0]));
417 if (plman.size() > index)
419 mediaObject->enqueue(plman.at(index));
423 mediaObject->enqueue(plman.at(0));
428 void MainWindow::finished()
432 void MainWindow::setupActions()
434 playAction = new QAction(QIcon (QPixmap (":images/play")), "", this);
435 playAction->setShortcut(tr("Crl+P"));
436 playAction->setDisabled(true);
437 pauseAction = new QAction(QIcon (QPixmap (":images/pause")), "", this);
438 pauseAction->setShortcut(tr("Ctrl+A"));
439 pauseAction->setDisabled(true);
440 pauseAction->setVisible(false);
441 stopAction = new QAction(QIcon (QPixmap (":images/stop")), "", this);
442 stopAction->setShortcut(tr("Ctrl+S"));
443 stopAction->setDisabled(true);
444 nextAction = new QAction(QIcon (QPixmap (":images/next")), "", this);
445 nextAction->setShortcut(tr("Ctrl+N"));
446 previousAction = new QAction(QIcon (QPixmap (":images/previous")), "", this);
447 previousAction->setShortcut(tr("Ctrl+R"));
449 repeatAction = new QAction(QIcon (QPixmap (":images/repeatActive")), "", this);
451 repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), "", this);
452 repeatAction->setCheckable(true);
453 repeatAction->setChecked(repeat);
454 repeatAction->setShortcut(tr("Ctrl+I"));
456 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffleActive")), "", this);
458 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), "", this);
459 shuffleAction->setCheckable(true);
460 shuffleAction->setChecked(shuffle);
461 shuffleAction->setShortcut(tr("Ctrl+H"));
462 volumeAction = new QAction(QIcon (QPixmap (":images/volume")), "", this);
463 volumeAction->setCheckable(true);
464 volumeAction->setShortcut(tr("Ctrl+V"));
465 addFilesAction = new QAction(tr("Add &File"), this);
466 addFilesAction->setShortcut(tr("Ctrl+F"));
467 addFoldersAction = new QAction(tr("Add F&older"), this);
468 addFoldersAction->setShortcut(tr("Ctrl+O"));
469 addUrlAction = new QAction(tr("Add &Url"), this);
470 addUrlAction->setShortcut(tr("Ctrl+U"));
471 savePlaylistAction = new QAction (tr("Sa&ve Playlist"), this);
472 savePlaylistAction->setShortcut(tr ("Ctrl+V"));
473 loadPlaylistAction = new QAction (tr("&Load Playlist"), this);
474 loadPlaylistAction->setShortcut(tr("Ctrl+L"));
475 clearPlaylistAction = new QAction (tr("&Clear Playlist"), this);
476 clearPlaylistAction->setShortcut(tr("Ctrl+C"));
477 exitAction = new QAction(tr("E&xit"), this);
478 exitAction->setShortcut(tr("Ctrl+X"));
479 aboutAction = new QAction(tr("A&bout"), this);
480 aboutAction->setShortcut(tr("Ctrl+B"));
481 aboutQtAction = new QAction(tr("About &Qt"), this);
482 aboutQtAction->setShortcut(tr("Ctrl+Q"));
483 /* removeSelected = new QAction (tr("&Delete from playlist"));
484 removeSelected->setShortcut(tr ("Ctrl+D"));*/
486 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
487 connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
488 connect(stopAction, SIGNAL(triggered()), this, SLOT(stop()));
489 connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
490 connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
491 connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
493 connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
494 connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
495 connect(addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
496 connect (savePlaylistAction, SIGNAL (triggered()), this, SLOT (savePlaylist()));
497 connect (loadPlaylistAction, SIGNAL (triggered()), this, SLOT (loadPlaylist()));
498 connect (clearPlaylistAction, SIGNAL (triggered()), &plman, SLOT (clearPlaylist()));
499 connect (nextAction, SIGNAL(triggered()), this, SLOT(next()));
500 connect (previousAction, SIGNAL(triggered()), this, SLOT(previous()));
501 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
502 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
503 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
504 // connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
507 void MainWindow::removeSelectedItem()
509 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
511 int row = musicTable->currentRow();
513 plman.removeItem(row);
516 void MainWindow::removeAllButSelectedItem()
518 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove all other items?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
520 int row = musicTable->currentRow();
523 QString uri = plman.getItem(row).uri;
526 plman.clearPlaylist();
527 plman.addStringList(lst);
531 void MainWindow::repeatToggle ()
534 settings.setValue("repeat", QVariant (repeat));
536 repeatAction->setIcon(QIcon (QPixmap (":images/repeatActive")));
538 repeatAction->setIcon(QIcon (QPixmap (":images/repeat")));
541 void MainWindow::shuffleToggle ()
544 settings.setValue("shuffle", QVariant (shuffle));
546 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffleActive")));
548 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffle")));
551 void MainWindow::volumeToggle ()
553 volumeSlider->setVisible(volumeAction->isChecked());
556 void MainWindow::play()
559 lastPlayed = plman.indexOf(mediaObject->currentSource());
560 highlightRow(lastPlayed);
564 void MainWindow::stop()
571 void MainWindow::setupMenus()
573 QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
574 fileMenu->addAction(addFilesAction);
575 fileMenu->addAction(addFoldersAction);
576 fileMenu->addAction(addUrlAction);
577 fileMenu->addSeparator();
578 fileMenu->addAction(savePlaylistAction);
579 fileMenu->addAction(loadPlaylistAction);
580 fileMenu->addAction(clearPlaylistAction);
581 // fileMenu->addAction(exitAction);
583 QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
584 aboutMenu->addAction(aboutAction);
585 aboutMenu->addAction(aboutQtAction);
588 void MainWindow::setupUi()
590 QToolBar *bar = new QToolBar;
592 bar->setOrientation(Qt::Vertical);
593 bar->setStyleSheet("padding:7px");
594 //bar->addAction(volumeAction);
596 seekSlider = new Phonon::SeekSlider(this);
597 seekSlider->setMediaObject(mediaObject);
599 volumeSlider = new Phonon::VolumeSlider(this);
600 volumeSlider->setAudioOutput(audioOutput);
601 volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
602 volumeSlider->setOrientation(Qt::Horizontal);
603 volumeSlider->setMuteVisible(false);
604 // volumeAddedAction = bar->addWidget(volumeSlider);
605 // volumeAddedAction->setVisible(false);
606 bar->addAction(playAction);
607 bar->addAction(pauseAction);
608 bar->addAction(stopAction);
609 bar->addAction(repeatAction);
610 bar->addAction(shuffleAction);
611 bar->addAction(nextAction);
612 bar->addAction(previousAction);
614 contextMenu = new QMenu (this);
615 removeSelected = contextMenu->addAction(tr ("Remove selected"));
616 removeAllButSelected = contextMenu->addAction(tr("Remove all but selected"));
617 connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
618 connect (removeAllButSelected, SIGNAL (triggered()), this, SLOT (removeAllButSelectedItem()));
621 timeLcd = new QLCDNumber;
624 headers << tr("Artist") << tr("Title") << tr("Album") << "Controls";
626 musicTable = new QTableWidget(0, 4);
627 musicTable->setHorizontalHeaderLabels(headers);
628 musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
629 musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
630 connect(musicTable, SIGNAL(cellDoubleClicked(int,int)),
631 this, SLOT(tableClicked(int,int)));
632 connect(musicTable, SIGNAL(cellClicked(int,int)),
633 this, SLOT(cellClicked(int,int)));
634 /* for (int i = 0; i < 3; ++i)
636 if (!musicTable->horizontalHeaderItem(i))
638 musicTable->horizontalHeaderItem(i)->setBackgroundColor(QColor (128, 128, 255));;
639 musicTable->horizontalHeaderItem(i)->setForeground(QColor (255, 255, 255));
641 for (int i = 0; i < musicTable->columnCount(); ++i)
643 QString lab = QString ("colWidth_%1").arg (i);
644 int val = settings.value(lab, 0).toInt();
646 musicTable->setColumnWidth(i, val);
647 // settings.setValue(lab, musicTable->columnWidth(i));
651 QHBoxLayout *seekerLayout = new QHBoxLayout;
652 QToolBar* bar2 = new QToolBar;
653 bar2->addAction(volumeAction);
654 seekerLayout->addWidget(bar2);
655 seekerLayout->addWidget(volumeSlider);
656 seekerLayout->addWidget(seekSlider);
657 seekerLayout->addWidget(timeLcd);
659 QVBoxLayout *playbackLayout = new QVBoxLayout;
660 volumeSlider->hide ();
661 playbackLayout->addWidget(bar);
663 QVBoxLayout *seekAndTableLayout = new QVBoxLayout;
665 seekAndTableLayout->addWidget(musicTable);
666 seekAndTableLayout->addLayout(seekerLayout);
668 QHBoxLayout *mainLayout = new QHBoxLayout;
669 mainLayout->addLayout(seekAndTableLayout);
670 mainLayout->addLayout(playbackLayout);
672 QWidget *widget = new QWidget;
673 widget->setLayout(mainLayout);
675 setCentralWidget(widget);
676 setWindowTitle("TomAmp");
679 void MainWindow::cellClicked(int /*row*/, int)
683 void MainWindow::contextMenuEvent (QContextMenuEvent*e)
685 if (!childAt (e->pos()))
687 if (childAt (e->pos())->parentWidget() != musicTable)
689 contextMenu->popup(e->globalPos());
693 void MainWindow::setupShuffleList()
696 int index = plman.indexOf(mediaObject->currentSource());
699 for (int i = 0; i < plman.size(); ++i)
705 shuffleList.append (index);
708 int ind = qrand () % tmp.size();
709 shuffleList.append(tmp[ind]);
714 void MainWindow::savePlaylist ()
716 QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u *.pls)");
717 if (filename.isEmpty())
719 plman.savePlaylist(filename);
722 void MainWindow::loadPlaylist ()
724 QString filename = QFileDialog::getOpenFileName(this, tr("Select playlist file to load"), "", "*.m3u *.pls");
725 if (filename.isEmpty())
727 plman.loadPlaylist (filename);
730 void MainWindow::playlistChanged(int from)
732 while (musicTable->rowCount() > from)
734 musicTable->removeRow(musicTable->rowCount () - 1);
737 for (int i = from; i < plman.size (); ++i)
739 if (firstGood < 0 && plman.getItem (i).playable)
741 int currentRow = musicTable->rowCount();
742 musicTable->insertRow(currentRow);
743 setRowFromItem (currentRow, plman.getItem(i));
745 /* if (plman.indexOf(mediaObject->currentSource()) < 0)
747 setItem (firstGood, false);
752 void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
754 if (row >= musicTable->rowCount())
756 if (item.artist.isEmpty() && item.title.isEmpty())
758 QTableWidgetItem *item1 = new QTableWidgetItem(item.uri);
759 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
760 musicTable->setItem(row, 1, item1);
764 QTableWidgetItem *item1 = new QTableWidgetItem(item.artist);
765 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
766 musicTable->setItem(row, 0, item1);
767 QTableWidgetItem *item2 = new QTableWidgetItem(item.title);
768 item2->setFlags(item2->flags() ^ Qt::ItemIsEditable);
769 musicTable->setItem(row, 1, item2);
770 QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
771 item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
772 musicTable->setItem(row, 2, item3);
775 if (!musicTable->cellWidget(row, 3))
777 QToolBar* bar = new QToolBar;
778 QLabel* up = new QLabel;
779 up->setText(QString::fromUtf8("<b><a href='up'>▲</a></b>"));
780 up->setStyleSheet("padding-right:3px;");
781 up->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
783 QLabel* down = new QLabel;
784 down->setText(QString::fromUtf8("<b><a href='down'>▼</a></b>"));
785 down->setStyleSheet("padding-right:3px;");
786 bar->addWidget(down);
787 QLabel* del = new QLabel;
788 del->setText(QString::fromUtf8("<b><a href='del'>╳</a></b>"));
789 del->setStyleSheet("padding-right:3px;");
791 down->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
792 bar->setProperty("row", row);
793 musicTable->setCellWidget(row, 3, bar);
794 connect (up, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonUp ()));
795 connect (down, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonDown ()));
796 connect (del, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonDel ()));
800 void MainWindow::buttonUp()
802 int i = sender()->parent()->property("row").toInt();
803 qDebug () << "Presses up on " << i;
807 setRowFromItem (i, plman.getItem(i));
808 setRowFromItem (i - 1, plman.getItem(i - 1));
809 musicTable->cellWidget(i, 3)->setProperty("row", i);
810 musicTable->cellWidget(i - 1, 3)->setProperty("row", i - 1);
811 musicTable->selectRow(i - 1);
815 void MainWindow::buttonDown()
817 int i = sender()->parent()->property("row").toInt();
818 qDebug () << "Presses down on " << i;
819 if (i < plman.size() - 1)
821 plman.moveItemDown(i);
822 setRowFromItem (i, plman.getItem(i));
823 setRowFromItem (i + 1, plman.getItem(i + 1));
824 musicTable->cellWidget(i, 3)->setProperty("row", i);
825 musicTable->cellWidget(i + 1, 3)->setProperty("row", i + 1);
826 musicTable->selectRow(i + 1);
830 void MainWindow::buttonDel()
832 int i = sender()->parent()->property("row").toInt();
833 qDebug () << "Presses del on " << i;
834 if (i < plman.size())
840 void MainWindow::itemUpdated(int index)
842 if (plman.indexOf(mediaObject->currentSource()) < 0 && plman.getItem (index).playable)
844 setItem (index, false);
846 setRowFromItem (index, plman.getItem(index));
847 if (plman.indexOf(mediaObject->currentSource()) == index)
849 if (shuffle) index = shuffleList.indexOf(index);
850 setItem (index, false);
854 void MainWindow::itemRemoved (int i)
856 musicTable->removeRow(i);
857 for (int j = i ? (i - 1) : 0; j < musicTable->rowCount(); ++j)
859 if (musicTable->cellWidget(j, 3))
860 musicTable->cellWidget(j, 3)->setProperty("row", j);