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)
14 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
16 audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
17 mediaObject = new Phonon::MediaObject(this);
19 mediaObject->setTickInterval(1000);
20 connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
21 connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
22 this, SLOT(stateChanged(Phonon::State,Phonon::State)));
23 connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
24 this, SLOT(sourceChanged(Phonon::MediaSource)));
25 connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
26 connect (&plman, SIGNAL (playlistChanged (int)), this, SLOT (playlistChanged(int)));
27 connect (&plman, SIGNAL (itemUpdated(int)), this, SLOT (itemUpdated (int)));
28 connect (&plman, SIGNAL (itemRemoved(int)), this, SLOT (itemRemoved (int)));
30 Phonon::createPath(mediaObject, audioOutput);
33 repeat = settings.value("repeat", false).toBool();
34 shuffle = settings.value("shuffle", false).toBool();
40 timeLcd->display("00:00:00");
41 plman.addStringList(settings.value("lastPlaylist").toStringList());
43 int curind = settings.value("currentIndex", -1).toInt ();
45 setItem (curind, false);
46 audioOutput->setVolume(settings.value("volume", .5).toReal());
47 QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
50 MainWindow::~MainWindow()
52 settings.setValue("shuffle", shuffle);
53 settings.setValue("repeat", repeat);
54 settings.setValue("lastPlaylist", plman.playlistStrings());
55 settings.setValue("volume", audioOutput->volume());
56 settings.setValue("currentIndex", plman.indexOf(mediaObject->currentSource()));
57 for (int i = 0; i < musicTable->columnCount(); ++i)
59 QString lab = QString ("colWidth_%1").arg (i);
60 settings.setValue(lab, musicTable->columnWidth(i));
64 void MainWindow::addFiles()
66 QString folder = settings.value("LastFolder").toString();
68 folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
69 QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Files To Add"),
70 folder, "Music files (*.mp3 *.ogg *.wav *.flac);;Playlists (*.m3u *.pls)");
75 QString dir = QFileInfo (files[0]).absoluteDir().absolutePath();
76 settings.setValue("LastFolder", dir);
78 foreach (QString string, files)
80 if (string.toLower().endsWith(".pls") || string.toLower().endsWith(".m3u"))
81 plman.addPlaylist(string);
83 toadd.append (string);
85 plman.addStringList(toadd);
88 void MainWindow::addFolder()
90 QString folder = settings.value("LastFolder").toString();
92 folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
93 QString dir = QFileDialog::getExistingDirectory(this,
94 tr("Select Directory To Add"),
100 settings.setValue("LastFolder", dir);
103 QStringList files = QDir (dir).entryList(filters, QDir::AllDirs);
104 files.removeAll(".");
105 files.removeAll("..");
106 bool recursive = false;
108 recursive = QMessageBox::question(this, "Add all folders", "Subfolders have been detected, add everything?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
109 plman.parseAndAddFolder(dir, recursive);
113 void MainWindow::addUrl()
115 #ifdef AVOID_INPUT_DIALOG
116 QString url = "http://war.str3am.com:7970";
118 QString url = QInputDialog::getText(this, "Get URL", "Please type in the stream URL");
120 if (url.isEmpty() || !url.toLower().startsWith("http"))
124 plman.addStringList(toadd);
128 void MainWindow::about()
130 QMessageBox::information(this, tr("About TomAmp v0.1"),
131 tr("TomAmp is a simple playlist-based music player.\n\n"
132 "(c) 2010 Tamas Marki <tmarki@gmail.com>\n\n"
133 "Please send comments and bug reports to the above e-mail address.\n\n"
134 "Icons by http://itweek.deviantart.com/"));
137 void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
141 case Phonon::ErrorState:
142 if (mediaObject->errorType() == Phonon::FatalError)
144 // QMessageBox::warning(this, tr("Fatal Error"),
145 // mediaObject->errorString() + mediaObject->currentSource().fileName() + ", " + mediaObject->currentSource().url().toString());
149 // QMessageBox::warning(this, tr("Error"),
150 // mediaObject->errorString());
154 case Phonon::PlayingState:
155 setWindowTitle(mediaObject->metaData().value("TITLE") + " - TomAmp");
156 pauseAction->setVisible(true);
157 playAction->setVisible (false);
158 playAction->setEnabled(false);
159 pauseAction->setEnabled(true);
160 stopAction->setEnabled(true);
161 //lastPlayed = plman.indexOf(mediaObject->currentSource());
163 case Phonon::StoppedState:
164 setWindowTitle("TomAmp");
165 stopAction->setEnabled(false);
166 playAction->setEnabled(true);
167 pauseAction->setVisible(false);
168 playAction->setVisible(true);
169 pauseAction->setEnabled(false);
170 timeLcd->display("00:00:00");
171 unhighlightRow(plman.indexOf(mediaObject->currentSource()));
173 case Phonon::PausedState:
174 pauseAction->setEnabled(false);
175 stopAction->setEnabled(true);
176 pauseAction->setVisible(false);
177 playAction->setVisible(true);
178 playAction->setEnabled(true);
180 case Phonon::BufferingState:
187 void MainWindow::next()
189 bool wasPlaying = isPlaying;
190 if (mediaObject->state () == Phonon::ErrorState)
192 int index = plman.indexOf(mediaObject->currentSource());
195 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
196 while (index < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
200 if (index < shuffleList.size ())
202 setItem (index, wasPlaying);
207 while ((index) < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
211 setItem (index, wasPlaying);
217 while ((index) < plman.size () && !plman.getItem(index).playable)
221 if (index < plman.size())
223 setItem (index, wasPlaying);
228 while ((index) < plman.size () && !plman.getItem(index).playable)
232 setItem (index, wasPlaying);
237 void MainWindow::setItem(int i, bool doplay)
239 if (i < plman.size() && i >= 0)
242 unhighlightRow(lastPlayed);
245 mediaObject->setCurrentSource(plman.at (shuffleList[i]));
249 mediaObject->setCurrentSource(plman.at(i));
252 if (doplay && mediaObject->currentSource().type() != Phonon::MediaSource::Invalid)
260 void MainWindow::previous()
262 bool wasPlaying = isPlaying;//(mediaObject->state () == Phonon::PlayingState);
263 if (mediaObject->state () == Phonon::ErrorState)
265 int index = plman.indexOf(mediaObject->currentSource());
268 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) - 1;
269 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
275 setItem (index, wasPlaying);
279 index = plman.size () - 1;
280 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
284 setItem (index, wasPlaying);
287 wasPlaying = false;*/
293 while ((index) >= 0 && !plman.getItem(index).playable)
299 setItem (index, wasPlaying);
303 index = plman.size() - 1;
304 while ((index) >= 0 && !plman.getItem(index).playable)
308 setItem (index, wasPlaying);
313 void MainWindow::highlightRow (int i)
315 for (int j = 0; j < 3; ++j)
317 QTableWidgetItem* item = musicTable->item(i, j);
320 QFont font = item->font();
322 font.setItalic(true);
328 void MainWindow::unhighlightRow (int i)
330 for (int j = 0; j < 3; ++j)
332 QTableWidgetItem* item = musicTable->item(i, j);
335 QFont font = item->font();
337 font.setItalic(false);
344 void MainWindow::tick(qint64 time)
346 QTime displayTime((time / 3600000), (time / 60000) % 60, (time / 1000) % 60);
348 timeLcd->display(displayTime.toString("HH:mm:ss"));
351 void MainWindow::tableClicked(int row, int /* column */)
353 // bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
355 /* mediaObject->stop();
356 mediaObject->clearQueue();*/
358 if (row >= plman.size())
362 while (index < shuffleList.size () && !plman.getItem(index).playable)
366 if (plman.size() > index)
369 index = shuffleList.indexOf(index);
370 setItem (index, true);
371 // mediaObject->play();
376 while (index < plman.size () && !plman.getItem(index).playable)
380 if (plman.size() > index)
383 index = shuffleList.indexOf(index);
384 setItem (index, true);
385 // mediaObject->play();
391 void MainWindow::sourceChanged(const Phonon::MediaSource &source)
393 int ind = plman.indexOf(source);
395 unhighlightRow(lastPlayed);
397 musicTable->selectRow(ind);
398 timeLcd->display("00:00:00");
402 void MainWindow::aboutToFinish()
404 int index = plman.indexOf(mediaObject->currentSource()) + 1;
407 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
408 if (index < shuffleList.size ())
410 mediaObject->enqueue(plman.at (shuffleList[index]));
414 mediaObject->enqueue(plman.at (shuffleList[0]));
420 if (plman.size() > index)
422 mediaObject->enqueue(plman.at(index));
426 mediaObject->enqueue(plman.at(0));
431 void MainWindow::finished()
435 void MainWindow::setupActions()
437 playAction = new QAction(QIcon (QPixmap (":images/play")), "", this);
438 playAction->setShortcut(tr("Crl+P"));
439 playAction->setDisabled(true);
440 pauseAction = new QAction(QIcon (QPixmap (":images/pause")), "", this);
441 pauseAction->setShortcut(tr("Ctrl+A"));
442 pauseAction->setDisabled(true);
443 pauseAction->setVisible(false);
444 stopAction = new QAction(QIcon (QPixmap (":images/stop")), "", this);
445 stopAction->setShortcut(tr("Ctrl+S"));
446 stopAction->setDisabled(true);
447 nextAction = new QAction(QIcon (QPixmap (":images/next")), "", this);
448 nextAction->setShortcut(tr("Ctrl+N"));
449 previousAction = new QAction(QIcon (QPixmap (":images/previous")), "", this);
450 previousAction->setShortcut(tr("Ctrl+R"));
452 repeatAction = new QAction(QIcon (QPixmap (":images/repeatActive")), "", this);
454 repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), "", this);
455 repeatAction->setCheckable(true);
456 repeatAction->setChecked(repeat);
457 repeatAction->setShortcut(tr("Ctrl+I"));
459 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffleActive")), "", this);
461 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), "", this);
462 shuffleAction->setCheckable(true);
463 shuffleAction->setChecked(shuffle);
464 shuffleAction->setShortcut(tr("Ctrl+H"));
465 volumeAction = new QAction(QIcon (QPixmap (":images/volume")), "", this);
466 volumeAction->setCheckable(true);
467 volumeAction->setShortcut(tr("Ctrl+V"));
468 addFilesAction = new QAction(tr("Add &File"), this);
469 addFilesAction->setShortcut(tr("Ctrl+F"));
470 addFoldersAction = new QAction(tr("Add F&older"), this);
471 addFoldersAction->setShortcut(tr("Ctrl+O"));
472 addUrlAction = new QAction(tr("Add &Url"), this);
473 addUrlAction->setShortcut(tr("Ctrl+U"));
474 savePlaylistAction = new QAction (tr("Sa&ve Playlist"), this);
475 savePlaylistAction->setShortcut(tr ("Ctrl+V"));
476 loadPlaylistAction = new QAction (tr("&Load Playlist"), this);
477 loadPlaylistAction->setShortcut(tr("Ctrl+L"));
478 clearPlaylistAction = new QAction (tr("&Clear Playlist"), this);
479 clearPlaylistAction->setShortcut(tr("Ctrl+C"));
480 exitAction = new QAction(tr("E&xit"), this);
481 exitAction->setShortcut(tr("Ctrl+X"));
482 aboutAction = new QAction(tr("A&bout"), this);
483 aboutAction->setShortcut(tr("Ctrl+B"));
484 aboutQtAction = new QAction(tr("About &Qt"), this);
485 aboutQtAction->setShortcut(tr("Ctrl+Q"));
486 /* removeSelected = new QAction (tr("&Delete from playlist"));
487 removeSelected->setShortcut(tr ("Ctrl+D"));*/
489 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
490 connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
491 connect(stopAction, SIGNAL(triggered()), this, SLOT(stop()));
492 connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
493 connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
494 connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
496 connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
497 connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
498 connect(addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
499 connect (savePlaylistAction, SIGNAL (triggered()), this, SLOT (savePlaylist()));
500 connect (loadPlaylistAction, SIGNAL (triggered()), this, SLOT (loadPlaylist()));
501 connect (clearPlaylistAction, SIGNAL (triggered()), &plman, SLOT (clearPlaylist()));
502 connect (nextAction, SIGNAL(triggered()), this, SLOT(next()));
503 connect (previousAction, SIGNAL(triggered()), this, SLOT(previous()));
504 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
505 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
506 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
507 // connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
510 void MainWindow::removeSelectedItem()
512 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
514 int row = musicTable->currentRow();
516 plman.removeItem(row);
519 void MainWindow::removeAllButSelectedItem()
521 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove all other items?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
523 int row = musicTable->currentRow();
526 QString uri = plman.getItem(row).uri;
529 plman.clearPlaylist();
530 plman.addStringList(lst);
534 void MainWindow::repeatToggle ()
537 settings.setValue("repeat", QVariant (repeat));
539 repeatAction->setIcon(QIcon (QPixmap (":images/repeatActive")));
541 repeatAction->setIcon(QIcon (QPixmap (":images/repeat")));
544 void MainWindow::shuffleToggle ()
547 settings.setValue("shuffle", QVariant (shuffle));
549 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffleActive")));
551 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffle")));
554 void MainWindow::volumeToggle ()
556 volumeSlider->setVisible(volumeAction->isChecked());
559 void MainWindow::play()
562 lastPlayed = plman.indexOf(mediaObject->currentSource());
563 highlightRow(lastPlayed);
567 void MainWindow::stop()
574 void MainWindow::setupMenus()
576 QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
577 fileMenu->addAction(addFilesAction);
578 fileMenu->addAction(addFoldersAction);
579 fileMenu->addAction(addUrlAction);
580 fileMenu->addSeparator();
581 fileMenu->addAction(savePlaylistAction);
582 fileMenu->addAction(loadPlaylistAction);
583 fileMenu->addAction(clearPlaylistAction);
584 // fileMenu->addAction(exitAction);
586 QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
587 aboutMenu->addAction(aboutAction);
588 aboutMenu->addAction(aboutQtAction);
591 void MainWindow::setupUi()
593 QToolBar *bar = new QToolBar;
595 bar->setOrientation(Qt::Vertical);
596 bar->setStyleSheet("padding:7px");
597 //bar->addAction(volumeAction);
599 seekSlider = new Phonon::SeekSlider(this);
600 seekSlider->setMediaObject(mediaObject);
602 volumeSlider = new Phonon::VolumeSlider(this);
603 volumeSlider->setAudioOutput(audioOutput);
604 volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
605 volumeSlider->setOrientation(Qt::Horizontal);
606 volumeSlider->setMuteVisible(false);
607 // volumeAddedAction = bar->addWidget(volumeSlider);
608 // volumeAddedAction->setVisible(false);
609 bar->addAction(playAction);
610 bar->addAction(pauseAction);
611 bar->addAction(stopAction);
612 bar->addAction(repeatAction);
613 bar->addAction(shuffleAction);
614 bar->addAction(nextAction);
615 bar->addAction(previousAction);
617 contextMenu = new QMenu (this);
618 removeSelected = contextMenu->addAction(tr ("Remove selected"));
619 removeAllButSelected = contextMenu->addAction(tr("Remove all but selected"));
620 connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
621 connect (removeAllButSelected, SIGNAL (triggered()), this, SLOT (removeAllButSelectedItem()));
624 timeLcd = new QLCDNumber;
627 headers << tr("Artist") << tr("Title") << tr("Album") << "Controls";
629 musicTable = new QTableWidget(0, 4);
630 musicTable->setHorizontalHeaderLabels(headers);
631 musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
632 musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
633 connect(musicTable, SIGNAL(cellDoubleClicked(int,int)),
634 this, SLOT(tableClicked(int,int)));
635 connect(musicTable, SIGNAL(cellClicked(int,int)),
636 this, SLOT(cellClicked(int,int)));
637 /* for (int i = 0; i < 3; ++i)
639 if (!musicTable->horizontalHeaderItem(i))
641 musicTable->horizontalHeaderItem(i)->setBackgroundColor(QColor (128, 128, 255));;
642 musicTable->horizontalHeaderItem(i)->setForeground(QColor (255, 255, 255));
644 for (int i = 0; i < musicTable->columnCount(); ++i)
646 QString lab = QString ("colWidth_%1").arg (i);
647 int val = settings.value(lab, 0).toInt();
649 musicTable->setColumnWidth(i, val);
650 // settings.setValue(lab, musicTable->columnWidth(i));
654 QHBoxLayout *seekerLayout = new QHBoxLayout;
655 QToolBar* bar2 = new QToolBar;
656 bar2->addAction(volumeAction);
657 seekerLayout->addWidget(bar2);
658 seekerLayout->addWidget(volumeSlider);
659 seekerLayout->addWidget(seekSlider);
660 seekerLayout->addWidget(timeLcd);
662 QVBoxLayout *playbackLayout = new QVBoxLayout;
663 volumeSlider->hide ();
664 playbackLayout->addWidget(bar);
666 QVBoxLayout *seekAndTableLayout = new QVBoxLayout;
668 seekAndTableLayout->addWidget(musicTable);
669 seekAndTableLayout->addLayout(seekerLayout);
671 QHBoxLayout *mainLayout = new QHBoxLayout;
672 mainLayout->addLayout(seekAndTableLayout);
673 mainLayout->addLayout(playbackLayout);
675 QWidget *widget = new QWidget;
676 widget->setLayout(mainLayout);
678 setCentralWidget(widget);
679 setWindowTitle("TomAmp");
682 void MainWindow::cellClicked(int /*row*/, int)
686 void MainWindow::contextMenuEvent (QContextMenuEvent*e)
688 if (!childAt (e->pos()))
690 if (childAt (e->pos())->parentWidget() != musicTable)
692 contextMenu->popup(e->globalPos());
696 void MainWindow::setupShuffleList()
699 int index = plman.indexOf(mediaObject->currentSource());
702 for (int i = 0; i < plman.size(); ++i)
708 shuffleList.append (index);
711 int ind = qrand () % tmp.size();
712 shuffleList.append(tmp[ind]);
717 void MainWindow::savePlaylist ()
719 QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u *.pls)");
720 if (filename.isEmpty())
722 plman.savePlaylist(filename);
725 void MainWindow::loadPlaylist ()
727 QString filename = QFileDialog::getOpenFileName(this, tr("Select playlist file to load"), "", "*.m3u *.pls");
728 if (filename.isEmpty())
730 plman.loadPlaylist (filename);
733 void MainWindow::playlistChanged(int from)
735 while (musicTable->rowCount() > from)
737 musicTable->removeRow(musicTable->rowCount () - 1);
740 for (int i = from; i < plman.size (); ++i)
742 if (firstGood < 0 && plman.getItem (i).playable)
744 int currentRow = musicTable->rowCount();
745 musicTable->insertRow(currentRow);
746 setRowFromItem (currentRow, plman.getItem(i));
748 /* if (plman.indexOf(mediaObject->currentSource()) < 0)
750 setItem (firstGood, false);
755 void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
757 if (row >= musicTable->rowCount())
759 if (item.artist.isEmpty() && item.title.isEmpty())
761 QTableWidgetItem *item1 = new QTableWidgetItem(item.uri);
762 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
763 musicTable->setItem(row, 1, item1);
767 QTableWidgetItem *item1 = new QTableWidgetItem(item.artist);
768 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
769 musicTable->setItem(row, 0, item1);
770 QTableWidgetItem *item2 = new QTableWidgetItem(item.title);
771 item2->setFlags(item2->flags() ^ Qt::ItemIsEditable);
772 musicTable->setItem(row, 1, item2);
773 QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
774 item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
775 musicTable->setItem(row, 2, item3);
778 if (!musicTable->cellWidget(row, 3))
780 QToolBar* bar = new QToolBar;
781 QLabel* up = new QLabel;
782 up->setText(QString::fromUtf8("<b><a href='up'>▲</a></b>"));
783 up->setStyleSheet("padding-right:3px;");
784 up->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
786 QLabel* down = new QLabel;
787 down->setText(QString::fromUtf8("<b><a href='down'>▼</a></b>"));
788 down->setStyleSheet("padding-right:3px;");
789 bar->addWidget(down);
790 QLabel* del = new QLabel;
791 del->setText(QString::fromUtf8("<b><a href='del'>╳</a></b>"));
792 del->setStyleSheet("padding-right:3px;");
794 down->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
795 bar->setProperty("row", row);
796 musicTable->setCellWidget(row, 3, bar);
797 connect (up, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonUp ()));
798 connect (down, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonDown ()));
799 connect (del, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonDel ()));
803 void MainWindow::buttonUp()
805 int i = sender()->parent()->property("row").toInt();
806 qDebug () << "Presses up on " << i;
810 setRowFromItem (i, plman.getItem(i));
811 setRowFromItem (i - 1, plman.getItem(i - 1));
812 musicTable->cellWidget(i, 3)->setProperty("row", i);
813 musicTable->cellWidget(i - 1, 3)->setProperty("row", i - 1);
814 musicTable->selectRow(i - 1);
818 void MainWindow::buttonDown()
820 int i = sender()->parent()->property("row").toInt();
821 qDebug () << "Presses down on " << i;
822 if (i < plman.size() - 1)
824 plman.moveItemDown(i);
825 setRowFromItem (i, plman.getItem(i));
826 setRowFromItem (i + 1, plman.getItem(i + 1));
827 musicTable->cellWidget(i, 3)->setProperty("row", i);
828 musicTable->cellWidget(i + 1, 3)->setProperty("row", i + 1);
829 musicTable->selectRow(i + 1);
833 void MainWindow::buttonDel()
835 int i = sender()->parent()->property("row").toInt();
836 qDebug () << "Presses del on " << i;
837 if (i < plman.size())
843 void MainWindow::itemUpdated(int index)
845 if (plman.indexOf(mediaObject->currentSource()) < 0 && plman.getItem (index).playable)
847 setItem (index, false);
849 setRowFromItem (index, plman.getItem(index));
850 if (plman.indexOf(mediaObject->currentSource()) == index)
852 if (shuffle) index = shuffleList.indexOf(index);
853 setItem (index, false);
857 void MainWindow::itemRemoved (int i)
859 musicTable->removeRow(i);
860 for (int j = i ? (i - 1) : 0; j < musicTable->rowCount(); ++j)
862 if (musicTable->cellWidget(j, 3))
863 musicTable->cellWidget(j, 3)->setProperty("row", j);