MainWindow::MainWindow()
: plman (this), settings (tr ("TomAmp"), "TomAmp"), isPlaying (false)
{
- setOrientation();
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();
- headers = settings.value ("headers", QStringList()).toStringList();
+ 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()
#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
}
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]));
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()));
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(upAction);
bar->addAction(downAction);
bar->addAction(delAction);
+ bar->addAction(enqueueActionButton);
contextMenu = new QMenu (this);
enqueueAction = contextMenu->addAction(tr ("Enqueue"));
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)),
}
- 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, tr ("Song enqueued as next song"),
+ QMaemo5InformationBox::information(this, plman.getItem(sel).title + tr (" enqueued as next song"),
QMaemo5InformationBox::DefaultTimeout);
#endif
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 ()
{
QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
+
musicTable->setItem(row, col, item3);
}
}
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='info'>i</a></b>"));
+ 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);
void MainWindow::playlistControl (const QString& con)
{
int i = sender ()->property("row").toInt();
- qDebug () << "Playlist control: " << con << " on " << i;
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)
{
- qDebug () << "Presses up on " << i;
if (i)
{
plman.moveItemUp(i);
void MainWindow::buttonDown(int i)
{
- qDebug () << "Presses down on " << i;
if (i < plman.size() - 1)
{
plman.moveItemDown(i);
void MainWindow::buttonDel(int i)
{
- 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())
void MainWindow::showOptions ()
{
+ 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())
{
musicTable->setHorizontalHeaderLabels(headers);
playlistChanged(0);
}
+ int curitem = plman.indexOf(mediaObject->currentSource());
+ if (curitem >= 0 && isPlaying)
+ highlightRow(curitem);
}