#include <QtGui>
#include <QtDebug>
#include <QInputDialog>
-
+#ifdef Q_WS_MAEMO_5
+#include <QtMaemo5/QMaemo5InformationBox>
+#endif
#include "mainwindow.h"
#include "optiondialog.h"
#include "time.h"
MainWindow::MainWindow()
: plman (this), settings (tr ("TomAmp"), "TomAmp"), isPlaying (false)
{
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5AutoOrientation, true);
-#endif
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mediaObject = new Phonon::MediaObject(this);
qsrand (time (NULL));
repeat = settings.value("repeat", false).toBool();
shuffle = settings.value("shuffle", false).toBool();
+ QStringList allowedHeaders;
+ allowedHeaders << "Artist" << "Title" << "Album" << "Controls";
+ foreach (QString h, settings.value ("headers", QStringList()).toStringList())
+ {
+ if (allowedHeaders.indexOf(h) >= 0)
+ headers << h;
+ }
+ if (!headers.size())
+ headers << "Artist" << "Title" << "Album";
+
setupShuffleList();
setupActions();
setupMenus();
- setupUi();
+/* foreach (QString s, Phonon::BackendCapabilities::availableMimeTypes())
+ qDebug () << s;*/
+
+/* if (settings.value("uiflipped", false).toBool())
+ setupUiFlipped();
+ else*/
+ setupUi ();
show ();
timeLcd->display("00:00:00");
plman.addStringList(settings.value("lastPlaylist").toStringList());
setItem (curind, false);
audioOutput->setVolume(settings.value("volume", .5).toReal());
QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
+ setOrientation();
}
MainWindow::~MainWindow()
settings.setValue("lastPlaylist", plman.playlistStrings());
settings.setValue("volume", audioOutput->volume());
settings.setValue("currentIndex", plman.indexOf(mediaObject->currentSource()));
+ settings.setValue("headers", headers);
for (int i = 0; i < musicTable->columnCount(); ++i)
{
QString lab = QString ("colWidth_%1").arg (i);
}
}
+void MainWindow::setOrientation ()
+{
+#ifdef Q_WS_MAEMO_5
+ QString orient = settings.value("orientation", "Automatic").toString();
+ if (orient == "Portrait")
+ {
+ setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+ }
+ else if (orient == "Landscape")
+ {
+ setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+ }
+ else
+ {
+ setAttribute(Qt::WA_Maemo5AutoOrientation, true);
+ }
+#endif
+}
+
void MainWindow::addFiles()
{
QString folder = settings.value("LastFolder").toString();
if (folder.isEmpty())
folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
+ QString ext = "*." + plman.allowedExt().join(" *.");
+ ext = "Music files (" + ext + ");;Playlists (*.m3u *.pls)";
QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Files To Add"),
- folder, "Music files (*.mp3 *.ogg *.wav *.flac);;Playlists (*.m3u *.pls)");
+ folder, ext, 0, QFileDialog::DontUseNativeDialog);
if (files.isEmpty())
return;
void MainWindow::about()
{
- QMessageBox::information(this, tr("About TomAmp v0.1"),
+ QMessageBox::information(this, tr("About TomAmp v0.2"),
tr("TomAmp is a simple playlist-based music player.\n\n"
"(c) 2010 Tamas Marki <tmarki@gmail.com>\n\n"
"Please send comments and bug reports to the above e-mail address.\n\n"
- "Icons by http://itweek.deviantart.com/"));
+ "Icons by http://itweek.deviantart.com/\n\n"
+ "Special thanks to Attila Csipa"));
}
void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
playAction->setEnabled(false);
pauseAction->setEnabled(true);
stopAction->setEnabled(true);
- //lastPlayed = plman.indexOf(mediaObject->currentSource());
+ unhighlightRow(lastPlayed);
+ lastPlayed = plman.indexOf(mediaObject->currentSource());
+ highlightRow(plman.indexOf(mediaObject->currentSource()));
+ musicTable->selectRow(plman.indexOf(mediaObject->currentSource()));
break;
case Phonon::StoppedState:
setWindowTitle("TomAmp");
bool wasPlaying = isPlaying;
if (mediaObject->state () == Phonon::ErrorState)
wasPlaying = true;
+ if (mediaObject->queue().size())
+ {
+ setItem (plman.indexOf(mediaObject->queue()[0]), wasPlaying);
+ mediaObject->queue().clear();
+ return;
+ }
int index = plman.indexOf(mediaObject->currentSource());
if (shuffle)
{
{
if (i < plman.size() && i >= 0)
{
- if (lastPlayed >= 0)
- unhighlightRow(lastPlayed);
+/* if (lastPlayed >= 0)
+ unhighlightRow(lastPlayed);*/
if (shuffle)
{
mediaObject->setCurrentSource(plman.at (shuffleList[i]));
void MainWindow::aboutToFinish()
{
+ if (mediaObject->queue().size())
+ return;
int index = plman.indexOf(mediaObject->currentSource()) + 1;
if (shuffle)
{
stopAction->setDisabled(true);
nextAction = new QAction(QIcon (QPixmap (":images/next")), "", this);
nextAction->setShortcut(tr("Ctrl+N"));
+ upAction = new QAction (QString::fromUtf8("▲"), this);
+ downAction = new QAction (QString::fromUtf8("▼"), this);
+ delAction = new QAction (QString::fromUtf8("╳"), this);
previousAction = new QAction(QIcon (QPixmap (":images/previous")), "", this);
previousAction->setShortcut(tr("Ctrl+R"));
if (repeat)
shuffleAction->setCheckable(true);
shuffleAction->setChecked(shuffle);
shuffleAction->setShortcut(tr("Ctrl+H"));
+ enqueueActionButton = new QAction (tr ("E"), this);
volumeAction = new QAction(QIcon (QPixmap (":images/volume")), "", this);
volumeAction->setCheckable(true);
volumeAction->setShortcut(tr("Ctrl+V"));
connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
+ connect(enqueueActionButton, SIGNAL(triggered()), this, SLOT(enqueueSelected()));
connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
connect (savePlaylistAction, SIGNAL (triggered()), this, SLOT (savePlaylist()));
connect (loadPlaylistAction, SIGNAL (triggered()), this, SLOT (loadPlaylist()));
connect (clearPlaylistAction, SIGNAL (triggered()), &plman, SLOT (clearPlaylist()));
- connect (optionAction, SIGNAL (triggered()), &plman, SLOT (showOptions()));
+ connect (optionAction, SIGNAL (triggered()), this, SLOT (showOptions()));
connect (nextAction, SIGNAL(triggered()), this, SLOT(next()));
connect (previousAction, SIGNAL(triggered()), this, SLOT(previous()));
+ connect (upAction, SIGNAL(triggered()), this, SLOT(upSelected()));
+ connect (downAction, SIGNAL(triggered()), this, SLOT(downSelected()));
+ connect (delAction, SIGNAL(triggered()), this, SLOT(removeSelectedItem()));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
void MainWindow::play()
{
mediaObject->play();
- lastPlayed = plman.indexOf(mediaObject->currentSource());
+// lastPlayed = plman.indexOf(mediaObject->currentSource());
highlightRow(lastPlayed);
isPlaying = true;
}
void MainWindow::setupUi()
{
QToolBar *bar = new QToolBar;
+ bool flip = settings.value("uiflipped", false).toBool();
- bar->setOrientation(Qt::Vertical);
+ if(!flip) bar->setOrientation(Qt::Vertical);
bar->setStyleSheet("padding:7px");
- //bar->addAction(volumeAction);
seekSlider = new Phonon::SeekSlider(this);
seekSlider->setMediaObject(mediaObject);
+ if (flip) seekSlider->setOrientation(Qt::Vertical);
volumeSlider = new Phonon::VolumeSlider(this);
volumeSlider->setAudioOutput(audioOutput);
- volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
- volumeSlider->setOrientation(Qt::Horizontal);
+ if (flip)
+ {
+ volumeSlider->setOrientation(Qt::Vertical);
+ volumeSlider->setMinimumHeight(150);
+ }
+ else
+ {
+ volumeSlider->setMinimumWidth(150);
+ }
volumeSlider->setMuteVisible(false);
-// volumeAddedAction = bar->addWidget(volumeSlider);
-// volumeAddedAction->setVisible(false);
bar->addAction(playAction);
bar->addAction(pauseAction);
bar->addAction(stopAction);
bar->addAction(shuffleAction);
bar->addAction(nextAction);
bar->addAction(previousAction);
+ bar->addAction(upAction);
+ bar->addAction(downAction);
+ bar->addAction(delAction);
+ bar->addAction(enqueueActionButton);
contextMenu = new QMenu (this);
+ enqueueAction = contextMenu->addAction(tr ("Enqueue"));
removeSelected = contextMenu->addAction(tr ("Remove selected"));
removeAllButSelected = contextMenu->addAction(tr("Remove all but selected"));
connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
connect (removeAllButSelected, SIGNAL (triggered()), this, SLOT (removeAllButSelectedItem()));
+ connect (enqueueAction, SIGNAL (triggered()), this, SLOT (enqueueSelected()));
timeLcd = new QLCDNumber;
- QStringList headers;
- headers << tr("Artist") << tr("Title") << tr("Album") << "Controls";
+ if (!headers.size ())
+ {
+ headers << "Artist" << "Title" << "Album";
+ settings.setValue("headers", headers);
+ }
- musicTable = new QTableWidget(0, 4);
+ musicTable = new QTableWidget(0, headers.size ());
musicTable->setHorizontalHeaderLabels(headers);
musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+// musicTable->setAlternatingRowColors(true);
+ musicTable->verticalHeader ()->hide();
connect(musicTable, SIGNAL(cellDoubleClicked(int,int)),
this, SLOT(tableClicked(int,int)));
connect(musicTable, SIGNAL(cellClicked(int,int)),
this, SLOT(cellClicked(int,int)));
-/* for (int i = 0; i < 3; ++i)
- {
- if (!musicTable->horizontalHeaderItem(i))
- continue;
- musicTable->horizontalHeaderItem(i)->setBackgroundColor(QColor (128, 128, 255));;
- musicTable->horizontalHeaderItem(i)->setForeground(QColor (255, 255, 255));
- }*/
for (int i = 0; i < musicTable->columnCount(); ++i)
{
QString lab = QString ("colWidth_%1").arg (i);
int val = settings.value(lab, 0).toInt();
if (val)
musicTable->setColumnWidth(i, val);
-// settings.setValue(lab, musicTable->columnWidth(i));
}
- QHBoxLayout *seekerLayout = new QHBoxLayout;
+ QLayout *seekerLayout;
+ QLayout *playbackLayout;
+ if (flip)
+ {
+ seekerLayout = new QVBoxLayout;
+ playbackLayout = new QHBoxLayout;
+ bar->addWidget(timeLcd);
+ }
+ else
+ {
+ seekerLayout = new QHBoxLayout;
+ playbackLayout = new QVBoxLayout;
+ }
QToolBar* bar2 = new QToolBar;
bar2->addAction(volumeAction);
seekerLayout->addWidget(bar2);
seekerLayout->addWidget(volumeSlider);
seekerLayout->addWidget(seekSlider);
- seekerLayout->addWidget(timeLcd);
-
- QVBoxLayout *playbackLayout = new QVBoxLayout;
+ if (!flip)
+ seekerLayout->addWidget(timeLcd);
volumeSlider->hide ();
playbackLayout->addWidget(bar);
QVBoxLayout *seekAndTableLayout = new QVBoxLayout;
seekAndTableLayout->addWidget(musicTable);
- seekAndTableLayout->addLayout(seekerLayout);
-
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(seekAndTableLayout);
- mainLayout->addLayout(playbackLayout);
+ if (flip)
+ {
+ seekAndTableLayout->addLayout(playbackLayout);
+ mainLayout->addLayout(seekerLayout);
+ }
+ else
+ {
+ seekAndTableLayout->addLayout(seekerLayout);
+ mainLayout->addLayout(playbackLayout);
+ }
+
QWidget *widget = new QWidget;
widget->setLayout(mainLayout);
{
}
+void MainWindow::enqueueSelected()
+{
+ int sel = musicTable->currentRow();
+ qDebug () << "Enqueue on " << sel;
+ if (sel >= 0)
+ {
+ mediaObject->queue().clear();
+ mediaObject->enqueue(plman.at(sel));
+#ifdef Q_WS_MAEMO_5
+ QMaemo5InformationBox::information(this, plman.getItem(sel).title + tr (" enqueued as next song"),
+ QMaemo5InformationBox::DefaultTimeout);
+#endif
+
+ }
+}
+
void MainWindow::contextMenuEvent (QContextMenuEvent*e)
{
if (!childAt (e->pos()))
QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u *.pls)");
if (filename.isEmpty())
return;
- plman.savePlaylist(filename);
+ if (!plman.savePlaylist(filename))
+ {
+#ifdef Q_WS_MAEMO_5
+ QMaemo5InformationBox::information(this, tr ("Error writing playlist file"),
+ QMaemo5InformationBox::DefaultTimeout);
+#else
+ QMessageBox::critical(this, "Write error", "Error writing playlist file", QMessageBox::Ok);
+#endif
+ }
+
}
void MainWindow::loadPlaylist ()
return;
if (item.artist.isEmpty() && item.title.isEmpty())
{
- QTableWidgetItem *item1 = new QTableWidgetItem(item.uri);
- item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
- musicTable->setItem(row, 1, item1);
+ int col = headers.indexOf("Title");
+ if (col >= 0)
+ {
+ QTableWidgetItem *item1 = new QTableWidgetItem(item.uri);
+ item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
+ musicTable->setItem(row, col, item1);
+ }
}
else
{
- QTableWidgetItem *item1 = new QTableWidgetItem(item.artist);
- item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
- musicTable->setItem(row, 0, item1);
- QTableWidgetItem *item2 = new QTableWidgetItem(item.title);
- item2->setFlags(item2->flags() ^ Qt::ItemIsEditable);
- musicTable->setItem(row, 1, item2);
- QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
- item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
- musicTable->setItem(row, 2, item3);
- }
-
- if (!musicTable->cellWidget(row, 3))
- {
- QToolBar* bar = new QToolBar;
- QLabel* up = new QLabel;
- up->setText(QString::fromUtf8("<b><a href='up'>▲</a></b>"));
- up->setStyleSheet("padding-right:3px;");
- up->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
- bar->addWidget(up);
- QLabel* down = new QLabel;
- down->setText(QString::fromUtf8("<b><a href='down'>▼</a></b>"));
- down->setStyleSheet("padding-right:3px;");
- bar->addWidget(down);
- QLabel* del = new QLabel;
- del->setText(QString::fromUtf8("<b><a href='del'>╳</a></b>"));
- del->setStyleSheet("padding-right:3px;");
- bar->addWidget(del);
- down->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
- bar->setProperty("row", row);
- musicTable->setCellWidget(row, 3, bar);
- connect (up, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonUp ()));
- connect (down, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonDown ()));
- connect (del, SIGNAL (linkActivated (const QString&)), this, SLOT (buttonDel ()));
- }
-}
-
-void MainWindow::buttonUp()
-{
- int i = sender()->parent()->property("row").toInt();
- qDebug () << "Presses up on " << i;
+ int col = headers.indexOf("Artist");
+ if (col >= 0)
+ {
+ QTableWidgetItem *item1 = new QTableWidgetItem(item.artist);
+ item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
+ musicTable->setItem(row, col, item1);
+ }
+ col = headers.indexOf("Title");
+ if (col >= 0)
+ {
+ if (!musicTable->item (row, col))
+ {
+ QTableWidgetItem *item2 = new QTableWidgetItem(item.title);
+ item2->setFlags(item2->flags() ^ Qt::ItemIsEditable);
+ musicTable->setItem(row, col, item2);
+ }
+ else
+ {
+ musicTable->item (row, col)->setText(item.title);
+ }
+ }
+ col = headers.indexOf("Album");
+ if (col >= 0)
+ {
+ QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
+ item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
+
+ musicTable->setItem(row, col, item3);
+ }
+ }
+
+ int controlCol = headers.indexOf("Controls");
+ if (controlCol >= 0 && !musicTable->cellWidget(row, controlCol))
+ {
+ QLabel* label = new QLabel;
+ 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='enq'>E</a></b>"));
+ label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+ label->setProperty("row", row);
+ musicTable->setCellWidget(row, controlCol, label);
+ connect (label, SIGNAL (linkActivated (const QString&)), this, SLOT (playlistControl (const QString&)));
+ }
+}
+
+void MainWindow::playlistControl (const QString& con)
+{
+ int i = sender ()->property("row").toInt();
+ if (con == "up")
+ buttonUp(i);
+ else if (con == "down")
+ buttonDown(i);
+ else if (con == "del")
+ buttonDel (i);
+ else if (con == "enq")
+ {
+ musicTable->selectRow(i);
+ enqueueSelected();
+ }
+ else
+ QMessageBox::information(this, tr ("Coming up..."), tr ("This feature is not implemented yet."));
+}
+
+
+void MainWindow::buttonUp(int i)
+{
if (i)
{
plman.moveItemUp(i);
setRowFromItem (i, plman.getItem(i));
setRowFromItem (i - 1, plman.getItem(i - 1));
- musicTable->cellWidget(i, 3)->setProperty("row", i);
- musicTable->cellWidget(i - 1, 3)->setProperty("row", i - 1);
+ int controlCol = headers.indexOf("Controls");
+ if (controlCol >= 0)
+ {
+ musicTable->cellWidget(i, controlCol)->setProperty("row", i);
+ musicTable->cellWidget(i - 1, controlCol)->setProperty("row", i - 1);
+ }
musicTable->selectRow(i - 1);
}
}
-void MainWindow::buttonDown()
+void MainWindow::buttonDown(int i)
{
- int i = sender()->parent()->property("row").toInt();
- qDebug () << "Presses down on " << i;
if (i < plman.size() - 1)
{
plman.moveItemDown(i);
setRowFromItem (i, plman.getItem(i));
setRowFromItem (i + 1, plman.getItem(i + 1));
- musicTable->cellWidget(i, 3)->setProperty("row", i);
- musicTable->cellWidget(i + 1, 3)->setProperty("row", i + 1);
+ int controlCol = headers.indexOf("Controls");
+ if (controlCol >= 0)
+ {
+ musicTable->cellWidget(i, controlCol)->setProperty("row", i);
+ musicTable->cellWidget(i + 1, controlCol)->setProperty("row", i + 1);
+ }
musicTable->selectRow(i + 1);
}
}
-void MainWindow::buttonDel()
+void MainWindow::buttonDel(int i)
{
- int i = sender()->parent()->property("row").toInt();
- qDebug () << "Presses del on " << i;
+ if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
+ return;
if (i < plman.size())
{
plman.removeItem(i);
void MainWindow::itemRemoved (int i)
{
musicTable->removeRow(i);
+ int controlCol = headers.indexOf("Controls");
+ if (controlCol < 0)
+ return;
for (int j = i ? (i - 1) : 0; j < musicTable->rowCount(); ++j)
{
- if (musicTable->cellWidget(j, 3))
- musicTable->cellWidget(j, 3)->setProperty("row", j);
+ if (musicTable->cellWidget(j, controlCol))
+ musicTable->cellWidget(j, controlCol)->setProperty("row", j);
}
}
+void MainWindow::upSelected()
+{
+ int sel = musicTable->currentRow();
+ if (sel > 0)
+ buttonUp(sel);
+}
+
+void MainWindow::downSelected()
+{
+ int sel = musicTable->currentRow();
+ if (sel >= 0)
+ buttonDown(sel);
+}
+
+
+
void MainWindow::showOptions ()
{
- OptionDialog dlg (this, settings);
- dlg.show();
+ bool flip = settings.value("uiflipped", false).toBool();
+ OptionDialog* dlg = new OptionDialog (this, settings);
+ dlg->exec();
+ delete dlg;
+ if (flip != settings.value("uiflipped", false).toBool())
+ {
+ delete centralWidget();
+ setupUi ();
+ }
+ setOrientation ();
+ if (headers != settings.value("headers", QStringList ()).toStringList())
+ {
+ headers = settings.value("headers", QStringList ()).toStringList();
+ musicTable->setColumnCount(headers.size ());
+ musicTable->setHorizontalHeaderLabels(headers);
+ playlistChanged(0);
+ }
+ int curitem = plman.indexOf(mediaObject->currentSource());
+ if (curitem >= 0 && isPlaying)
+ highlightRow(curitem);
}