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.1"),
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 int index = plman.indexOf(mediaObject->currentSource());
211 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
212 while (index < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
216 if (index < shuffleList.size ())
218 setItem (index, wasPlaying);
223 while ((index) < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
227 setItem (index, wasPlaying);
233 while ((index) < plman.size () && !plman.getItem(index).playable)
237 if (index < plman.size())
239 setItem (index, wasPlaying);
244 while ((index) < plman.size () && !plman.getItem(index).playable)
248 setItem (index, wasPlaying);
253 void MainWindow::setItem(int i, bool doplay)
255 if (i < plman.size() && i >= 0)
258 unhighlightRow(lastPlayed);
261 mediaObject->setCurrentSource(plman.at (shuffleList[i]));
265 mediaObject->setCurrentSource(plman.at(i));
268 if (doplay && mediaObject->currentSource().type() != Phonon::MediaSource::Invalid)
276 void MainWindow::previous()
278 bool wasPlaying = isPlaying;//(mediaObject->state () == Phonon::PlayingState);
279 if (mediaObject->state () == Phonon::ErrorState)
281 int index = plman.indexOf(mediaObject->currentSource());
284 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) - 1;
285 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
291 setItem (index, wasPlaying);
295 index = plman.size () - 1;
296 while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
300 setItem (index, wasPlaying);
303 wasPlaying = false;*/
309 while ((index) >= 0 && !plman.getItem(index).playable)
315 setItem (index, wasPlaying);
319 index = plman.size() - 1;
320 while ((index) >= 0 && !plman.getItem(index).playable)
324 setItem (index, wasPlaying);
329 void MainWindow::highlightRow (int i)
331 for (int j = 0; j < 3; ++j)
333 QTableWidgetItem* item = musicTable->item(i, j);
336 QFont font = item->font();
338 font.setItalic(true);
344 void MainWindow::unhighlightRow (int i)
346 for (int j = 0; j < 3; ++j)
348 QTableWidgetItem* item = musicTable->item(i, j);
351 QFont font = item->font();
353 font.setItalic(false);
360 void MainWindow::tick(qint64 time)
362 QTime displayTime((time / 3600000), (time / 60000) % 60, (time / 1000) % 60);
364 timeLcd->display(displayTime.toString("HH:mm:ss"));
367 void MainWindow::tableClicked(int row, int /* column */)
369 // bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
371 /* mediaObject->stop();
372 mediaObject->clearQueue();*/
374 if (row >= plman.size())
378 while (index < shuffleList.size () && !plman.getItem(index).playable)
382 if (plman.size() > index)
385 index = shuffleList.indexOf(index);
386 setItem (index, true);
387 // mediaObject->play();
392 while (index < plman.size () && !plman.getItem(index).playable)
396 if (plman.size() > index)
399 index = shuffleList.indexOf(index);
400 setItem (index, true);
401 // mediaObject->play();
407 void MainWindow::sourceChanged(const Phonon::MediaSource &source)
409 int ind = plman.indexOf(source);
411 unhighlightRow(lastPlayed);
413 musicTable->selectRow(ind);
414 timeLcd->display("00:00:00");
418 void MainWindow::aboutToFinish()
420 if (mediaObject->queue().size())
422 int index = plman.indexOf(mediaObject->currentSource()) + 1;
425 index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
426 if (index < shuffleList.size ())
428 mediaObject->enqueue(plman.at (shuffleList[index]));
432 mediaObject->enqueue(plman.at (shuffleList[0]));
438 if (plman.size() > index)
440 mediaObject->enqueue(plman.at(index));
444 mediaObject->enqueue(plman.at(0));
449 void MainWindow::finished()
453 void MainWindow::setupActions()
455 playAction = new QAction(QIcon (QPixmap (":images/play")), "", this);
456 playAction->setShortcut(tr("Crl+P"));
457 playAction->setDisabled(true);
458 pauseAction = new QAction(QIcon (QPixmap (":images/pause")), "", this);
459 pauseAction->setShortcut(tr("Ctrl+A"));
460 pauseAction->setDisabled(true);
461 pauseAction->setVisible(false);
462 stopAction = new QAction(QIcon (QPixmap (":images/stop")), "", this);
463 stopAction->setShortcut(tr("Ctrl+S"));
464 stopAction->setDisabled(true);
465 nextAction = new QAction(QIcon (QPixmap (":images/next")), "", this);
466 nextAction->setShortcut(tr("Ctrl+N"));
467 upAction = new QAction (QString::fromUtf8("▲"), this);
468 downAction = new QAction (QString::fromUtf8("▼"), this);
469 delAction = new QAction (QString::fromUtf8("╳"), this);
470 previousAction = new QAction(QIcon (QPixmap (":images/previous")), "", this);
471 previousAction->setShortcut(tr("Ctrl+R"));
473 repeatAction = new QAction(QIcon (QPixmap (":images/repeatActive")), "", this);
475 repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), "", this);
476 repeatAction->setCheckable(true);
477 repeatAction->setChecked(repeat);
478 repeatAction->setShortcut(tr("Ctrl+I"));
480 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffleActive")), "", this);
482 shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), "", this);
483 shuffleAction->setCheckable(true);
484 shuffleAction->setChecked(shuffle);
485 shuffleAction->setShortcut(tr("Ctrl+H"));
486 volumeAction = new QAction(QIcon (QPixmap (":images/volume")), "", this);
487 volumeAction->setCheckable(true);
488 volumeAction->setShortcut(tr("Ctrl+V"));
489 addFilesAction = new QAction(tr("Add &File"), this);
490 addFilesAction->setShortcut(tr("Ctrl+F"));
491 addFoldersAction = new QAction(tr("Add F&older"), this);
492 addFoldersAction->setShortcut(tr("Ctrl+O"));
493 addUrlAction = new QAction(tr("Add &Url"), this);
494 addUrlAction->setShortcut(tr("Ctrl+U"));
495 savePlaylistAction = new QAction (tr("Sa&ve Playlist"), this);
496 savePlaylistAction->setShortcut(tr ("Ctrl+V"));
497 loadPlaylistAction = new QAction (tr("&Load Playlist"), this);
498 loadPlaylistAction->setShortcut(tr("Ctrl+L"));
499 clearPlaylistAction = new QAction (tr("&Clear Playlist"), this);
500 clearPlaylistAction->setShortcut(tr("Ctrl+C"));
501 optionAction = new QAction (tr("Op&tions"), this);
502 optionAction->setShortcut(tr("Ctrl+T"));
503 exitAction = new QAction(tr("E&xit"), this);
504 exitAction->setShortcut(tr("Ctrl+X"));
505 aboutAction = new QAction(tr("A&bout"), this);
506 aboutAction->setShortcut(tr("Ctrl+B"));
507 aboutQtAction = new QAction(tr("About &Qt"), this);
508 aboutQtAction->setShortcut(tr("Ctrl+Q"));
509 /* removeSelected = new QAction (tr("&Delete from playlist"));
510 removeSelected->setShortcut(tr ("Ctrl+D"));*/
512 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
513 connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
514 connect(stopAction, SIGNAL(triggered()), this, SLOT(stop()));
515 connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
516 connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
517 connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
519 connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
520 connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
521 connect(addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
522 connect (savePlaylistAction, SIGNAL (triggered()), this, SLOT (savePlaylist()));
523 connect (loadPlaylistAction, SIGNAL (triggered()), this, SLOT (loadPlaylist()));
524 connect (clearPlaylistAction, SIGNAL (triggered()), &plman, SLOT (clearPlaylist()));
525 connect (optionAction, SIGNAL (triggered()), this, SLOT (showOptions()));
526 connect (nextAction, SIGNAL(triggered()), this, SLOT(next()));
527 connect (previousAction, SIGNAL(triggered()), this, SLOT(previous()));
528 connect (upAction, SIGNAL(triggered()), this, SLOT(upSelected()));
529 connect (downAction, SIGNAL(triggered()), this, SLOT(downSelected()));
530 connect (delAction, SIGNAL(triggered()), this, SLOT(removeSelectedItem()));
531 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
532 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
533 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
534 // connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
537 void MainWindow::removeSelectedItem()
539 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
541 int row = musicTable->currentRow();
543 plman.removeItem(row);
546 void MainWindow::removeAllButSelectedItem()
548 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove all other items?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
550 int row = musicTable->currentRow();
553 QString uri = plman.getItem(row).uri;
556 plman.clearPlaylist();
557 plman.addStringList(lst);
561 void MainWindow::repeatToggle ()
564 settings.setValue("repeat", QVariant (repeat));
566 repeatAction->setIcon(QIcon (QPixmap (":images/repeatActive")));
568 repeatAction->setIcon(QIcon (QPixmap (":images/repeat")));
571 void MainWindow::shuffleToggle ()
574 settings.setValue("shuffle", QVariant (shuffle));
576 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffleActive")));
578 shuffleAction->setIcon(QIcon (QPixmap (":images/shuffle")));
581 void MainWindow::volumeToggle ()
583 volumeSlider->setVisible(volumeAction->isChecked());
586 void MainWindow::play()
589 lastPlayed = plman.indexOf(mediaObject->currentSource());
590 highlightRow(lastPlayed);
594 void MainWindow::stop()
601 void MainWindow::setupMenus()
603 QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
604 fileMenu->addAction(addFilesAction);
605 fileMenu->addAction(addFoldersAction);
606 fileMenu->addAction(addUrlAction);
607 fileMenu->addSeparator();
608 fileMenu->addAction(savePlaylistAction);
609 fileMenu->addAction(loadPlaylistAction);
610 fileMenu->addAction(clearPlaylistAction);
611 fileMenu->addAction(optionAction);
612 // fileMenu->addAction(exitAction);
614 QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
615 aboutMenu->addAction(aboutAction);
616 aboutMenu->addAction(aboutQtAction);
619 void MainWindow::setupUi()
621 QToolBar *bar = new QToolBar;
623 bar->setOrientation(Qt::Vertical);
624 bar->setStyleSheet("padding:7px");
625 //bar->addAction(volumeAction);
627 seekSlider = new Phonon::SeekSlider(this);
628 seekSlider->setMediaObject(mediaObject);
630 volumeSlider = new Phonon::VolumeSlider(this);
631 volumeSlider->setAudioOutput(audioOutput);
632 volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
633 volumeSlider->setOrientation(Qt::Horizontal);
634 volumeSlider->setMuteVisible(false);
635 // volumeAddedAction = bar->addWidget(volumeSlider);
636 // volumeAddedAction->setVisible(false);
637 bar->addAction(playAction);
638 bar->addAction(pauseAction);
639 bar->addAction(stopAction);
640 bar->addAction(repeatAction);
641 bar->addAction(shuffleAction);
642 bar->addAction(nextAction);
643 bar->addAction(previousAction);
644 bar->addAction(upAction);
645 bar->addAction(downAction);
646 bar->addAction(delAction);
648 contextMenu = new QMenu (this);
649 enqueueAction = contextMenu->addAction(tr ("Enqueue"));
650 removeSelected = contextMenu->addAction(tr ("Remove selected"));
651 removeAllButSelected = contextMenu->addAction(tr("Remove all but selected"));
652 connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
653 connect (removeAllButSelected, SIGNAL (triggered()), this, SLOT (removeAllButSelectedItem()));
654 connect (enqueueAction, SIGNAL (triggered()), this, SLOT (enqueueSelected()));
657 timeLcd = new QLCDNumber;
659 if (!headers.size ())
661 headers << "Artist" << "Title" << "Album";
662 settings.setValue("headers", headers);
665 musicTable = new QTableWidget(0, headers.size ());
666 musicTable->setHorizontalHeaderLabels(headers);
667 musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
668 musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
669 connect(musicTable, SIGNAL(cellDoubleClicked(int,int)),
670 this, SLOT(tableClicked(int,int)));
671 connect(musicTable, SIGNAL(cellClicked(int,int)),
672 this, SLOT(cellClicked(int,int)));
673 for (int i = 0; i < musicTable->columnCount(); ++i)
675 QString lab = QString ("colWidth_%1").arg (i);
676 int val = settings.value(lab, 0).toInt();
678 musicTable->setColumnWidth(i, val);
682 QHBoxLayout *seekerLayout = new QHBoxLayout;
683 QToolBar* bar2 = new QToolBar;
684 bar2->addAction(volumeAction);
685 seekerLayout->addWidget(bar2);
686 seekerLayout->addWidget(volumeSlider);
687 seekerLayout->addWidget(seekSlider);
688 seekerLayout->addWidget(timeLcd);
690 QVBoxLayout *playbackLayout = new QVBoxLayout;
691 volumeSlider->hide ();
692 playbackLayout->addWidget(bar);
694 QVBoxLayout *seekAndTableLayout = new QVBoxLayout;
696 seekAndTableLayout->addWidget(musicTable);
697 seekAndTableLayout->addLayout(seekerLayout);
699 QHBoxLayout *mainLayout = new QHBoxLayout;
700 mainLayout->addLayout(seekAndTableLayout);
701 mainLayout->addLayout(playbackLayout);
703 QWidget *widget = new QWidget;
704 widget->setLayout(mainLayout);
706 setCentralWidget(widget);
707 setWindowTitle("TomAmp");
710 void MainWindow::cellClicked(int /*row*/, int)
714 void MainWindow::enqueueSelected()
716 int sel = musicTable->currentRow();
719 mediaObject->queue().clear();
720 mediaObject->enqueue(plman.at(sel));
722 QMaemo5InformationBox::information(this, tr ("Song enqueued as next song"),
723 QMaemo5InformationBox::DefaultTimeout);
729 void MainWindow::contextMenuEvent (QContextMenuEvent*e)
731 if (!childAt (e->pos()))
733 if (childAt (e->pos())->parentWidget() != musicTable)
735 contextMenu->popup(e->globalPos());
739 void MainWindow::setupShuffleList()
742 int index = plman.indexOf(mediaObject->currentSource());
745 for (int i = 0; i < plman.size(); ++i)
751 shuffleList.append (index);
754 int ind = qrand () % tmp.size();
755 shuffleList.append(tmp[ind]);
760 void MainWindow::savePlaylist ()
762 QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u *.pls)");
763 if (filename.isEmpty())
765 plman.savePlaylist(filename);
768 void MainWindow::loadPlaylist ()
770 QString filename = QFileDialog::getOpenFileName(this, tr("Select playlist file to load"), "", "*.m3u *.pls");
771 if (filename.isEmpty())
773 plman.loadPlaylist (filename);
776 void MainWindow::playlistChanged(int from)
778 while (musicTable->rowCount() > from)
780 musicTable->removeRow(musicTable->rowCount () - 1);
783 for (int i = from; i < plman.size (); ++i)
785 if (firstGood < 0 && plman.getItem (i).playable)
787 int currentRow = musicTable->rowCount();
788 musicTable->insertRow(currentRow);
789 setRowFromItem (currentRow, plman.getItem(i));
791 /* if (plman.indexOf(mediaObject->currentSource()) < 0)
793 setItem (firstGood, false);
798 void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
800 if (row >= musicTable->rowCount())
802 if (item.artist.isEmpty() && item.title.isEmpty())
804 int col = headers.indexOf("Title");
807 QTableWidgetItem *item1 = new QTableWidgetItem(item.uri);
808 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
809 musicTable->setItem(row, col, item1);
814 int col = headers.indexOf("Artist");
817 QTableWidgetItem *item1 = new QTableWidgetItem(item.artist);
818 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
819 musicTable->setItem(row, col, item1);
821 col = headers.indexOf("Title");
824 if (!musicTable->item (row, col))
826 QTableWidgetItem *item2 = new QTableWidgetItem(item.title);
827 item2->setFlags(item2->flags() ^ Qt::ItemIsEditable);
828 musicTable->setItem(row, col, item2);
832 musicTable->item (row, col)->setText(item.title);
835 col = headers.indexOf("Album");
838 QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
839 item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
840 musicTable->setItem(row, col, item3);
844 int controlCol = headers.indexOf("Controls");
845 if (controlCol >= 0 && !musicTable->cellWidget(row, controlCol))
847 QLabel* label = new QLabel;
848 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>"));
849 label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
850 label->setProperty("row", row);
851 musicTable->setCellWidget(row, controlCol, label);
852 connect (label, SIGNAL (linkActivated (const QString&)), this, SLOT (playlistControl (const QString&)));
856 void MainWindow::playlistControl (const QString& con)
858 int i = sender ()->property("row").toInt();
859 qDebug () << "Playlist control: " << con << " on " << i;
862 else if (con == "down")
864 else if (con == "del")
867 QMessageBox::information(this, tr ("Coming up..."), tr ("This feature is not implemented yet."));
871 void MainWindow::buttonUp(int i)
873 qDebug () << "Presses up on " << i;
877 setRowFromItem (i, plman.getItem(i));
878 setRowFromItem (i - 1, plman.getItem(i - 1));
879 int controlCol = headers.indexOf("Controls");
882 musicTable->cellWidget(i, controlCol)->setProperty("row", i);
883 musicTable->cellWidget(i - 1, controlCol)->setProperty("row", i - 1);
885 musicTable->selectRow(i - 1);
889 void MainWindow::buttonDown(int i)
891 qDebug () << "Presses down on " << i;
892 if (i < plman.size() - 1)
894 plman.moveItemDown(i);
895 setRowFromItem (i, plman.getItem(i));
896 setRowFromItem (i + 1, plman.getItem(i + 1));
897 int controlCol = headers.indexOf("Controls");
900 musicTable->cellWidget(i, controlCol)->setProperty("row", i);
901 musicTable->cellWidget(i + 1, controlCol)->setProperty("row", i + 1);
903 musicTable->selectRow(i + 1);
907 void MainWindow::buttonDel(int i)
909 qDebug () << "Presses del on " << i;
910 if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
912 if (i < plman.size())
918 void MainWindow::itemUpdated(int index)
920 if (plman.indexOf(mediaObject->currentSource()) < 0 && plman.getItem (index).playable)
922 setItem (index, false);
924 setRowFromItem (index, plman.getItem(index));
925 if (plman.indexOf(mediaObject->currentSource()) == index)
927 if (shuffle) index = shuffleList.indexOf(index);
928 setItem (index, false);
932 void MainWindow::itemRemoved (int i)
934 musicTable->removeRow(i);
935 int controlCol = headers.indexOf("Controls");
938 for (int j = i ? (i - 1) : 0; j < musicTable->rowCount(); ++j)
940 if (musicTable->cellWidget(j, controlCol))
941 musicTable->cellWidget(j, controlCol)->setProperty("row", j);
945 void MainWindow::upSelected()
947 int sel = musicTable->currentRow();
952 void MainWindow::downSelected()
954 int sel = musicTable->currentRow();
961 void MainWindow::showOptions ()
963 OptionDialog* dlg = new OptionDialog (this, settings);
967 if (headers != settings.value("headers", QStringList ()).toStringList())
969 headers = settings.value("headers", QStringList ()).toStringList();
970 musicTable->setColumnCount(headers.size ());
971 musicTable->setHorizontalHeaderLabels(headers);