3 #include <QInputDialog>
5 #include <QtMaemo5/QMaemo5InformationBox>
7 #include "mainwindow.h"
8 #include "optiondialog.h"
11 //#define AVOID_INPUT_DIALOG 0
13 MainWindow::MainWindow()
14 : plman (this), settings (tr ("TomAmp"), "TomAmp"), isPlaying (false)
17 audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
18 mediaObject = new Phonon::MediaObject(this);
20 mediaObject->setTickInterval(1000);
21 connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
22 connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
23 this, SLOT(stateChanged(Phonon::State,Phonon::State)));
24 connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
25 this, SLOT(sourceChanged(Phonon::MediaSource)));
26 connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
27 connect (&plman, SIGNAL (playlistChanged (int)), this, SLOT (playlistChanged(int)));
28 connect (&plman, SIGNAL (itemUpdated(int)), this, SLOT (itemUpdated (int)));
29 connect (&plman, SIGNAL (itemRemoved(int)), this, SLOT (itemRemoved (int)));
31 Phonon::createPath(mediaObject, audioOutput);
34 repeat = settings.value("repeat", false).toBool();
35 shuffle = settings.value("shuffle", false).toBool();
36 headers = settings.value ("headers", QStringList()).toStringList();
42 timeLcd->display("00:00:00");
43 plman.addStringList(settings.value("lastPlaylist").toStringList());
45 int curind = settings.value("currentIndex", -1).toInt ();
47 setItem (curind, false);
48 audioOutput->setVolume(settings.value("volume", .5).toReal());
49 QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
52 MainWindow::~MainWindow()
54 settings.setValue("shuffle", shuffle);
55 settings.setValue("repeat", repeat);
56 settings.setValue("lastPlaylist", plman.playlistStrings());
57 settings.setValue("volume", audioOutput->volume());
58 settings.setValue("currentIndex", plman.indexOf(mediaObject->currentSource()));
59 settings.setValue("headers", headers);
60 for (int i = 0; i < musicTable->columnCount(); ++i)
62 QString lab = QString ("colWidth_%1").arg (i);
63 settings.setValue(lab, musicTable->columnWidth(i));
67 void MainWindow::setOrientation ()
70 QString orient = settings.value("orientation", "Automatic").toString();
71 if (orient == "Portrait")
72 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
73 else if (orient == "Landscape")
74 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
76 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
80 void MainWindow::addFiles()
82 QString folder = settings.value("LastFolder").toString();
84 folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
85 QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Files To Add"),
86 folder, "Music files (*.mp3 *.ogg *.wav *.flac);;Playlists (*.m3u *.pls)");
91 QString dir = QFileInfo (files[0]).absoluteDir().absolutePath();
92 settings.setValue("LastFolder", dir);
94 foreach (QString string, files)
96 if (string.toLower().endsWith(".pls") || string.toLower().endsWith(".m3u"))
97 plman.addPlaylist(string);
99 toadd.append (string);
101 plman.addStringList(toadd);
104 void MainWindow::addFolder()
106 QString folder = settings.value("LastFolder").toString();
107 if (folder.isEmpty())
108 folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
109 QString dir = QFileDialog::getExistingDirectory(this,
110 tr("Select Directory To Add"),
116 settings.setValue("LastFolder", dir);
119 QStringList files = QDir (dir).entryList(filters, QDir::AllDirs);
120 files.removeAll(".");
121 files.removeAll("..");
122 bool recursive = false;
124 recursive = QMessageBox::question(this, "Add all folders", "Subfolders have been detected, add everything?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
125 plman.parseAndAddFolder(dir, recursive);
129 void MainWindow::addUrl()
131 #ifdef AVOID_INPUT_DIALOG
132 QString url = "http://war.str3am.com:7970";
134 QString url = QInputDialog::getText(this, "Get URL", "Please type in the stream URL");
136 if (url.isEmpty() || !url.toLower().startsWith("http"))
140 plman.addStringList(toadd);
144 void MainWindow::about()
146 QMessageBox::information(this, tr("About TomAmp v0.2"),
147 tr("TomAmp is a simple playlist-based music player.\n\n"
148 "(c) 2010 Tamas Marki <tmarki@gmail.com>\n\n"
149 "Please send comments and bug reports to the above e-mail address.\n\n"
150 "Icons by http://itweek.deviantart.com/"));
153 void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
157 case Phonon::ErrorState:
158 if (mediaObject->errorType() == Phonon::FatalError)
160 // QMessageBox::warning(this, tr("Fatal Error"),
161 // mediaObject->errorString() + mediaObject->currentSource().fileName() + ", " + mediaObject->currentSource().url().toString());
165 // QMessageBox::warning(this, tr("Error"),
166 // mediaObject->errorString());
170 case Phonon::PlayingState:
171 setWindowTitle(mediaObject->metaData().value("TITLE") + "(" + mediaObject->metaData().value("ARTIST") + ") - TomAmp");
172 pauseAction->setVisible(true);
173 playAction->setVisible (false);
174 playAction->setEnabled(false);
175 pauseAction->setEnabled(true);
176 stopAction->setEnabled(true);
177 //lastPlayed = plman.indexOf(mediaObject->currentSource());
179 case Phonon::StoppedState:
180 setWindowTitle("TomAmp");
181 stopAction->setEnabled(false);
182 playAction->setEnabled(true);
183 pauseAction->setVisible(false);
184 playAction->setVisible(true);
185 pauseAction->setEnabled(false);
186 timeLcd->display("00:00:00");
187 unhighlightRow(plman.indexOf(mediaObject->currentSource()));
189 case Phonon::PausedState:
190 pauseAction->setEnabled(false);
191 stopAction->setEnabled(true);
192 pauseAction->setVisible(false);
193 playAction->setVisible(true);
194 playAction->setEnabled(true);
196 case Phonon::BufferingState:
203 void MainWindow::next()
205 bool wasPlaying = isPlaying;
206 if (mediaObject->state () == Phonon::ErrorState)
208 if (mediaObject->queue().size())
210 setItem (plman.indexOf(mediaObject->queue()[0]), wasPlaying);
213 int index = plman.indexOf(mediaObject->currentSource());
216 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
217 while (index < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
221 if (index < shuffleList.size ())
223 setItem (index, wasPlaying);
228 while ((index) < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
232 setItem (index, wasPlaying);
238 while ((index) < plman.size () && !plman.getItem(index).playable)
242 if (index < plman.size())
244 setItem (index, wasPlaying);
249 while ((index) < plman.size () && !plman.getItem(index).playable)
253 setItem (index, wasPlaying);
258 void MainWindow::setItem(int i, bool doplay)
260 if (i < plman.size() && i >= 0)
263 unhighlightRow(lastPlayed);
266 mediaObject->setCurrentSource(plman.at (shuffleList[i]));
270 mediaObject->setCurrentSource(plman.at(i));
273 if (doplay && mediaObject->currentSource().type() != Phonon::MediaSource::Invalid)
281 void MainWindow::previous()
283 bool wasPlaying = isPlaying;//(mediaObject->state () == Phonon::PlayingState);
284 if (mediaObject->state () == Phonon::ErrorState)
286 int index = plman.indexOf(mediaObject->currentSource());
289 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) - 1;
290 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
296 setItem (index, wasPlaying);
300 index = plman.size () - 1;
301 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
305 setItem (index, wasPlaying);
308 wasPlaying = false;*/
314 while ((index) >= 0 && !plman.getItem(index).playable)
320 setItem (index, wasPlaying);
324 index = plman.size() - 1;
325 while ((index) >= 0 && !plman.getItem(index).playable)
329 setItem (index, wasPlaying);
334 void MainWindow::highlightRow (int i)
336 for (int j = 0; j < 3; ++j)
338 QTableWidgetItem* item = musicTable->item(i, j);
341 QFont font = item->font();
343 font.setItalic(true);
349 void MainWindow::unhighlightRow (int i)
351 for (int j = 0; j < 3; ++j)
353 QTableWidgetItem* item = musicTable->item(i, j);
356 QFont font = item->font();
358 font.setItalic(false);
365 void MainWindow::tick(qint64 time)
367 QTime displayTime((time / 3600000), (time / 60000) % 60, (time / 1000) % 60);
369 timeLcd->display(displayTime.toString("HH:mm:ss"));
372 void MainWindow::tableClicked(int row, int /* column */)
374 // bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
376 /* mediaObject->stop();
377 mediaObject->clearQueue();*/
379 if (row >= plman.size())
383 while (index < shuffleList.size () && !plman.getItem(index).playable)
387 if (plman.size() > index)
390 index = shuffleList.indexOf(index);
391 setItem (index, true);
392 // mediaObject->play();
397 while (index < plman.size () && !plman.getItem(index).playable)
401 if (plman.size() > index)
404 index = shuffleList.indexOf(index);
405 setItem (index, true);
406 // mediaObject->play();
412 void MainWindow::sourceChanged(const Phonon::MediaSource &source)
414 int ind = plman.indexOf(source);
416 unhighlightRow(lastPlayed);
418 musicTable->selectRow(ind);
419 timeLcd->display("00:00:00");
423 void MainWindow::aboutToFinish()
425 if (mediaObject->queue().size())
427 int index = plman.indexOf(mediaObject->currentSource()) + 1;
430 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
431 if (index < shuffleList.size ())
433 mediaObject->enqueue(plman.at (shuffleList[index]));
437 mediaObject->enqueue(plman.at (shuffleList[0]));
443 if (plman.size() > index)
445 mediaObject->enqueue(plman.at(index));
449 mediaObject->enqueue(plman.at(0));
454 void MainWindow::finished()
458 void MainWindow::setupActions()
460 playAction = new QAction(QIcon (QPixmap (":images/play")), "", this);
461 playAction->setShortcut(tr("Crl+P"));
462 playAction->setDisabled(true);
463 pauseAction = new QAction(QIcon (QPixmap (":images/pause")), "", this);
464 pauseAction->setShortcut(tr("Ctrl+A"));
465 pauseAction->setDisabled(true);
466 pauseAction->setVisible(false);
467 stopAction = new QAction(QIcon (QPixmap (":images/stop")), "", this);
468 stopAction->setShortcut(tr("Ctrl+S"));
469 stopAction->setDisabled(true);
470 nextAction = new QAction(QIcon (QPixmap (":images/next")), "", this);
471 nextAction->setShortcut(tr("Ctrl+N"));
472 upAction = new QAction (QString::fromUtf8("▲"), this);
473 downAction = new QAction (QString::fromUtf8("▼"), this);
474 delAction = new QAction (QString::fromUtf8("╳"), this);
475 previousAction = new QAction(QIcon (QPixmap (":images/previous")), "", this);
476 previousAction->setShortcut(tr("Ctrl+R"));
478 repeatAction = new QAction(QIcon (QPixmap (":images/repeatActive")), "", this);
480 repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), "", this);
481 repeatAction->setCheckable(true);
482 repeatAction->setChecked(repeat);
483 repeatAction->setShortcut(tr("Ctrl+I"));
485 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffleActive")), "", this);
487 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), "", this);
488 shuffleAction->setCheckable(true);
489 shuffleAction->setChecked(shuffle);
490 shuffleAction->setShortcut(tr("Ctrl+H"));
491 volumeAction = new QAction(QIcon (QPixmap (":images/volume")), "", this);
492 volumeAction->setCheckable(true);
493 volumeAction->setShortcut(tr("Ctrl+V"));
494 addFilesAction = new QAction(tr("Add &File"), this);
495 addFilesAction->setShortcut(tr("Ctrl+F"));
496 addFoldersAction = new QAction(tr("Add F&older"), this);
497 addFoldersAction->setShortcut(tr("Ctrl+O"));
498 addUrlAction = new QAction(tr("Add &Url"), this);
499 addUrlAction->setShortcut(tr("Ctrl+U"));
500 savePlaylistAction = new QAction (tr("Sa&ve Playlist"), this);
501 savePlaylistAction->setShortcut(tr ("Ctrl+V"));
502 loadPlaylistAction = new QAction (tr("&Load Playlist"), this);
503 loadPlaylistAction->setShortcut(tr("Ctrl+L"));
504 clearPlaylistAction = new QAction (tr("&Clear Playlist"), this);
505 clearPlaylistAction->setShortcut(tr("Ctrl+C"));
506 optionAction = new QAction (tr("Op&tions"), this);
507 optionAction->setShortcut(tr("Ctrl+T"));
508 exitAction = new QAction(tr("E&xit"), this);
509 exitAction->setShortcut(tr("Ctrl+X"));
510 aboutAction = new QAction(tr("A&bout"), this);
511 aboutAction->setShortcut(tr("Ctrl+B"));
512 aboutQtAction = new QAction(tr("About &Qt"), this);
513 aboutQtAction->setShortcut(tr("Ctrl+Q"));
514 /* removeSelected = new QAction (tr("&Delete from playlist"));
515 removeSelected->setShortcut(tr ("Ctrl+D"));*/
517 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
518 connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
519 connect(stopAction, SIGNAL(triggered()), this, SLOT(stop()));
520 connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
521 connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
522 connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
524 connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
525 connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
526 connect(addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
527 connect (savePlaylistAction, SIGNAL (triggered()), this, SLOT (savePlaylist()));
528 connect (loadPlaylistAction, SIGNAL (triggered()), this, SLOT (loadPlaylist()));
529 connect (clearPlaylistAction, SIGNAL (triggered()), &plman, SLOT (clearPlaylist()));
530 connect (optionAction, SIGNAL (triggered()), this, SLOT (showOptions()));
531 connect (nextAction, SIGNAL(triggered()), this, SLOT(next()));
532 connect (previousAction, SIGNAL(triggered()), this, SLOT(previous()));
533 connect (upAction, SIGNAL(triggered()), this, SLOT(upSelected()));
534 connect (downAction, SIGNAL(triggered()), this, SLOT(downSelected()));
535 connect (delAction, SIGNAL(triggered()), this, SLOT(removeSelectedItem()));
536 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
537 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
538 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
539 // connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
542 void MainWindow::removeSelectedItem()
544 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
546 int row = musicTable->currentRow();
548 plman.removeItem(row);
551 void MainWindow::removeAllButSelectedItem()
553 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove all other items?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
555 int row = musicTable->currentRow();
558 QString uri = plman.getItem(row).uri;
561 plman.clearPlaylist();
562 plman.addStringList(lst);
566 void MainWindow::repeatToggle ()
569 settings.setValue("repeat", QVariant (repeat));
571 repeatAction->setIcon(QIcon (QPixmap (":images/repeatActive")));
573 repeatAction->setIcon(QIcon (QPixmap (":images/repeat")));
576 void MainWindow::shuffleToggle ()
579 settings.setValue("shuffle", QVariant (shuffle));
581 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffleActive")));
583 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffle")));
586 void MainWindow::volumeToggle ()
588 volumeSlider->setVisible(volumeAction->isChecked());
591 void MainWindow::play()
594 lastPlayed = plman.indexOf(mediaObject->currentSource());
595 highlightRow(lastPlayed);
599 void MainWindow::stop()
606 void MainWindow::setupMenus()
608 QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
609 fileMenu->addAction(addFilesAction);
610 fileMenu->addAction(addFoldersAction);
611 fileMenu->addAction(addUrlAction);
612 fileMenu->addSeparator();
613 fileMenu->addAction(savePlaylistAction);
614 fileMenu->addAction(loadPlaylistAction);
615 fileMenu->addAction(clearPlaylistAction);
616 fileMenu->addAction(optionAction);
617 // fileMenu->addAction(exitAction);
619 QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
620 aboutMenu->addAction(aboutAction);
621 aboutMenu->addAction(aboutQtAction);
624 void MainWindow::setupUi()
626 QToolBar *bar = new QToolBar;
628 bar->setOrientation(Qt::Vertical);
629 bar->setStyleSheet("padding:7px");
630 //bar->addAction(volumeAction);
632 seekSlider = new Phonon::SeekSlider(this);
633 seekSlider->setMediaObject(mediaObject);
635 volumeSlider = new Phonon::VolumeSlider(this);
636 volumeSlider->setAudioOutput(audioOutput);
637 volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
638 volumeSlider->setOrientation(Qt::Horizontal);
639 volumeSlider->setMuteVisible(false);
640 // volumeAddedAction = bar->addWidget(volumeSlider);
641 // volumeAddedAction->setVisible(false);
642 bar->addAction(playAction);
643 bar->addAction(pauseAction);
644 bar->addAction(stopAction);
645 bar->addAction(repeatAction);
646 bar->addAction(shuffleAction);
647 bar->addAction(nextAction);
648 bar->addAction(previousAction);
649 bar->addAction(upAction);
650 bar->addAction(downAction);
651 bar->addAction(delAction);
653 contextMenu = new QMenu (this);
654 enqueueAction = contextMenu->addAction(tr ("Enqueue"));
655 removeSelected = contextMenu->addAction(tr ("Remove selected"));
656 removeAllButSelected = contextMenu->addAction(tr("Remove all but selected"));
657 connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
658 connect (removeAllButSelected, SIGNAL (triggered()), this, SLOT (removeAllButSelectedItem()));
659 connect (enqueueAction, SIGNAL (triggered()), this, SLOT (enqueueSelected()));
662 timeLcd = new QLCDNumber;
664 if (!headers.size ())
666 headers << "Artist" << "Title" << "Album";
667 settings.setValue("headers", headers);
670 musicTable = new QTableWidget(0, headers.size ());
671 musicTable->setHorizontalHeaderLabels(headers);
672 musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
673 musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
674 connect(musicTable, SIGNAL(cellDoubleClicked(int,int)),
675 this, SLOT(tableClicked(int,int)));
676 connect(musicTable, SIGNAL(cellClicked(int,int)),
677 this, SLOT(cellClicked(int,int)));
678 for (int i = 0; i < musicTable->columnCount(); ++i)
680 QString lab = QString ("colWidth_%1").arg (i);
681 int val = settings.value(lab, 0).toInt();
683 musicTable->setColumnWidth(i, val);
687 QHBoxLayout *seekerLayout = new QHBoxLayout;
688 QToolBar* bar2 = new QToolBar;
689 bar2->addAction(volumeAction);
690 seekerLayout->addWidget(bar2);
691 seekerLayout->addWidget(volumeSlider);
692 seekerLayout->addWidget(seekSlider);
693 seekerLayout->addWidget(timeLcd);
695 QVBoxLayout *playbackLayout = new QVBoxLayout;
696 volumeSlider->hide ();
697 playbackLayout->addWidget(bar);
699 QVBoxLayout *seekAndTableLayout = new QVBoxLayout;
701 seekAndTableLayout->addWidget(musicTable);
702 seekAndTableLayout->addLayout(seekerLayout);
704 QHBoxLayout *mainLayout = new QHBoxLayout;
705 mainLayout->addLayout(seekAndTableLayout);
706 mainLayout->addLayout(playbackLayout);
708 QWidget *widget = new QWidget;
709 widget->setLayout(mainLayout);
711 setCentralWidget(widget);
712 setWindowTitle("TomAmp");
715 void MainWindow::cellClicked(int /*row*/, int)
719 void MainWindow::enqueueSelected()
721 int sel = musicTable->currentRow();
724 mediaObject->queue().clear();
725 mediaObject->enqueue(plman.at(sel));
727 QMaemo5InformationBox::information(this, tr ("Enqueued as next song"),
728 QMaemo5InformationBox::DefaultTimeout);
734 void MainWindow::contextMenuEvent (QContextMenuEvent*e)
736 if (!childAt (e->pos()))
738 if (childAt (e->pos())->parentWidget() != musicTable)
740 contextMenu->popup(e->globalPos());
744 void MainWindow::setupShuffleList()
747 int index = plman.indexOf(mediaObject->currentSource());
750 for (int i = 0; i < plman.size(); ++i)
756 shuffleList.append (index);
759 int ind = qrand () % tmp.size();
760 shuffleList.append(tmp[ind]);
765 void MainWindow::savePlaylist ()
767 QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u *.pls)");
768 if (filename.isEmpty())
770 if (!plman.savePlaylist(filename))
773 QMaemo5InformationBox::information(this, tr ("Error writing playlist file"),
774 QMaemo5InformationBox::DefaultTimeout);
776 QMessageBox::critical(this, "Write error", "Error writing playlist file", QMessageBox::Ok);
782 void MainWindow::loadPlaylist ()
784 QString filename = QFileDialog::getOpenFileName(this, tr("Select playlist file to load"), "", "*.m3u *.pls");
785 if (filename.isEmpty())
787 plman.loadPlaylist (filename);
790 void MainWindow::playlistChanged(int from)
792 while (musicTable->rowCount() > from)
794 musicTable->removeRow(musicTable->rowCount () - 1);
797 for (int i = from; i < plman.size (); ++i)
799 if (firstGood < 0 && plman.getItem (i).playable)
801 int currentRow = musicTable->rowCount();
802 musicTable->insertRow(currentRow);
803 setRowFromItem (currentRow, plman.getItem(i));
805 /* if (plman.indexOf(mediaObject->currentSource()) < 0)
807 setItem (firstGood, false);
812 void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
814 if (row >= musicTable->rowCount())
816 if (item.artist.isEmpty() && item.title.isEmpty())
818 int col = headers.indexOf("Title");
821 QTableWidgetItem *item1 = new QTableWidgetItem(item.uri);
822 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
823 musicTable->setItem(row, col, item1);
828 int col = headers.indexOf("Artist");
831 QTableWidgetItem *item1 = new QTableWidgetItem(item.artist);
832 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
833 musicTable->setItem(row, col, item1);
835 col = headers.indexOf("Title");
838 if (!musicTable->item (row, col))
840 QTableWidgetItem *item2 = new QTableWidgetItem(item.title);
841 item2->setFlags(item2->flags() ^ Qt::ItemIsEditable);
842 musicTable->setItem(row, col, item2);
846 musicTable->item (row, col)->setText(item.title);
849 col = headers.indexOf("Album");
852 QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
853 item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
855 musicTable->setItem(row, col, item3);
859 int controlCol = headers.indexOf("Controls");
860 if (controlCol >= 0 && !musicTable->cellWidget(row, controlCol))
862 QLabel* label = new QLabel;
863 label->setText(QString::fromUtf8("<b><a style='text-decoration:none' href='up'>▲</a> <a style='text-decoration:none' href='down'>▼</a> <a style='text-decoration:none' href='del'>╳</a> <a style='text-decoration:none' href='info'>i</a></b>"));
864 label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
865 label->setProperty("row", row);
866 musicTable->setCellWidget(row, controlCol, label);
867 connect (label, SIGNAL (linkActivated (const QString&)), this, SLOT (playlistControl (const QString&)));
871 void MainWindow::playlistControl (const QString& con)
873 int i = sender ()->property("row").toInt();
874 qDebug () << "Playlist control: " << con << " on " << i;
877 else if (con == "down")
879 else if (con == "del")
882 QMessageBox::information(this, tr ("Coming up..."), tr ("This feature is not implemented yet."));
886 void MainWindow::buttonUp(int i)
888 qDebug () << "Presses up on " << i;
892 setRowFromItem (i, plman.getItem(i));
893 setRowFromItem (i - 1, plman.getItem(i - 1));
894 int controlCol = headers.indexOf("Controls");
897 musicTable->cellWidget(i, controlCol)->setProperty("row", i);
898 musicTable->cellWidget(i - 1, controlCol)->setProperty("row", i - 1);
900 musicTable->selectRow(i - 1);
904 void MainWindow::buttonDown(int i)
906 qDebug () << "Presses down on " << i;
907 if (i < plman.size() - 1)
909 plman.moveItemDown(i);
910 setRowFromItem (i, plman.getItem(i));
911 setRowFromItem (i + 1, plman.getItem(i + 1));
912 int controlCol = headers.indexOf("Controls");
915 musicTable->cellWidget(i, controlCol)->setProperty("row", i);
916 musicTable->cellWidget(i + 1, controlCol)->setProperty("row", i + 1);
918 musicTable->selectRow(i + 1);
922 void MainWindow::buttonDel(int i)
924 qDebug () << "Presses del on " << i;
925 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
927 if (i < plman.size())
933 void MainWindow::itemUpdated(int index)
935 if (plman.indexOf(mediaObject->currentSource()) < 0 && plman.getItem (index).playable)
937 setItem (index, false);
939 setRowFromItem (index, plman.getItem(index));
940 if (plman.indexOf(mediaObject->currentSource()) == index)
942 if (shuffle) index = shuffleList.indexOf(index);
943 setItem (index, false);
947 void MainWindow::itemRemoved (int i)
949 musicTable->removeRow(i);
950 int controlCol = headers.indexOf("Controls");
953 for (int j = i ? (i - 1) : 0; j < musicTable->rowCount(); ++j)
955 if (musicTable->cellWidget(j, controlCol))
956 musicTable->cellWidget(j, controlCol)->setProperty("row", j);
960 void MainWindow::upSelected()
962 int sel = musicTable->currentRow();
967 void MainWindow::downSelected()
969 int sel = musicTable->currentRow();
976 void MainWindow::showOptions ()
978 OptionDialog* dlg = new OptionDialog (this, settings);
982 if (headers != settings.value("headers", QStringList ()).toStringList())
984 headers = settings.value("headers", QStringList ()).toStringList();
985 musicTable->setColumnCount(headers.size ());
986 musicTable->setHorizontalHeaderLabels(headers);