<file alias="repeat">images/Button Reload.png</file>
<file alias="stop">images/Button Stop.png</file>
<file alias="previous">images/Button Previous.png</file>
+ <file alias="shuffleActive">images/shuffle Active.png</file>
+ <file alias="repeatActive">images/Button Reload Active.png</file>
+ <file alias="tomamp">images/Tomamp.png</file>
</qresource>
</RCC>
if (curind >= 0)
setItem (curind, false);
audioOutput->setVolume(settings.value("volume", .5).toReal());
+ QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
}
MainWindow::~MainWindow()
if (folder.isEmpty())
folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Files To Add"),
- folder);
+ folder, "Music files (*.mp3 *.ogg *.wav *.flac);;Playlists (*.m3u *.pls)");
if (files.isEmpty())
return;
QStringList toadd;
foreach (QString string, files)
{
- toadd.append (string);
+ if (string.toLower().endsWith(".pls") || string.toLower().endsWith(".m3u"))
+ plman.addPlaylist(string);
+ else
+ toadd.append (string);
}
plman.addStringList(toadd);
}
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 deleket (http://www.deleket.com)"));
+ "Icons by http://itweek.deviantart.com/"));
}
void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
lastPlayed = plman.indexOf(mediaObject->currentSource());
break;
case Phonon::StoppedState:
+ setWindowTitle("TomAmp");
stopAction->setEnabled(false);
playAction->setEnabled(true);
pauseAction->setVisible(false);
nextAction->setShortcut(tr("Ctrl+N"));
previousAction = new QAction(QIcon (QPixmap (":images/previous")), tr("Previous"), this);
previousAction->setShortcut(tr("Ctrl+R"));
- repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), tr("Repeat"), this);
+ if (repeat)
+ repeatAction = new QAction(QIcon (QPixmap (":images/repeatActive")), tr("Repeat"), this);
+ else
+ repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), tr("Repeat"), this);
repeatAction->setCheckable(true);
repeatAction->setChecked(repeat);
repeatAction->setShortcut(tr("Ctrl+I"));
- shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), tr("Shuffle"), this);
+ if (shuffle)
+ shuffleAction = new QAction(QIcon (QPixmap (":images/shuffleActive")), tr("Shuffle"), this);
+ else
+ shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), tr("Shuffle"), this);
shuffleAction->setCheckable(true);
shuffleAction->setChecked(shuffle);
shuffleAction->setShortcut(tr("Ctrl+H"));
repeat = !repeat;
qDebug() << "Repeat toggled to " << repeat;
settings.setValue("repeat", QVariant (repeat));
+ if (repeat)
+ repeatAction->setIcon(QIcon (QPixmap (":images/repeatActive")));
+ else
+ repeatAction->setIcon(QIcon (QPixmap (":images/repeat")));
}
void MainWindow::shuffleToggle ()
{
shuffle = !shuffle;
settings.setValue("shuffle", QVariant (shuffle));
+ if (shuffle)
+ shuffleAction->setIcon(QIcon (QPixmap (":images/shuffleActive")));
+ else
+ shuffleAction->setIcon(QIcon (QPixmap (":images/shuffle")));
}
void MainWindow::volumeToggle ()
void MainWindow::contextMenuEvent (QContextMenuEvent*e)
{
qDebug () << "Context menu event!";
+ if (childAt (e->pos())->parentWidget() != musicTable)
+ return;
contextMenu->popup(e->globalPos());
}
void MainWindow::savePlaylist ()
{
- QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u)");
- plman.loadPlaylist(filename);
+ QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u *.pls)");
+ if (filename.isEmpty())
+ return;
+ plman.savePlaylist(filename);
}
void MainWindow::loadPlaylist ()
{
- QString filename = QFileDialog::getOpenFileName(this, tr("Select playlist file to load"), "", "*.m3u");
+ QString filename = QFileDialog::getOpenFileName(this, tr("Select playlist file to load"), "", "*.m3u *.pls");
+ if (filename.isEmpty())
+ return;
plman.loadPlaylist (filename);
}
#include "playlistmanager.h"
#include <QDir>
#include <QUrl>
+#include <QMap>
PlaylistManager::PlaylistManager(QWidget* parent)
: parentWidget (parent)
QString filename = filenam;
if (filename.isEmpty())
return;
- if (filename.length() < 4 || filename.right(4).toLower() != ".m3u")
- filename += ".m3u";
+ bool writepls = false;
+ if (filename.length() < 4 || (filename.right(4).toLower() != ".m3u" && filename.right(4).toLower() != ".pls"))
+ {
+ filename += ".pls";
+ writepls = true;
+ }
+ else if (filename.right(4).toLower() == ".pls")
+ writepls = true;
QFile f (filename);
try
{
f.open(QFile::WriteOnly);
+ if (writepls)
+ {
+ f.write ("[playlist]\n");
+ f.write (QString ("NumberOfEntries=%1\n").arg (items.size ()).toAscii());
+ }
for (int i = 0; i < items.size(); ++i)
{
- f.write (items[i].uri.toAscii());
- f.write ("\n");
+ if (writepls)
+ {
+ f.write (QString ("File%1=%2\n").arg (i + 1).arg (items[i].uri).toAscii());
+ f.write (QString ("Title%1=%2 - %3 - %4\n").arg (i + 1).arg (items[i].artist).arg (items[i].title).arg (items[i].album).toAscii());
+ }
+ else
+ {
+ f.write (items[i].uri.toAscii());
+ f.write ("\n");
+ }
}
+ if (writepls)
+ f.write ("Version=2\n");
f.close ();
}
catch (...)
void PlaylistManager::loadPlaylist(const QString& filename)
{
+ clearPlaylist();
+ if (filename.right(4).toLower() == ".m3u")
+ appendPlaylist(filename);
+ else if (filename.right(4).toLower() == ".pls")
+ appendPlaylistPLS(filename);
+ if (!items.isEmpty())
+ {
+ metaInformationResolver->setCurrentSource(items.at(0).source);
+ }
+ emit playlistChanged (0);
+}
+
+void PlaylistManager::addPlaylist(const QString& filename)
+{
+ int index = items.size();
+ if (filename.right(4).toLower() == ".m3u")
+ appendPlaylist(filename);
+ else if (filename.right(4).toLower() == ".pls")
+ appendPlaylistPLS(filename);
+ if (!items.isEmpty())
+ {
+ metaInformationResolver->setCurrentSource(items.at(index).source);
+ emit playlistChanged (index);
+ }
+}
+
+void PlaylistManager::appendPlaylist(const QString& filename)
+{
qDebug () << "Attempting to load playlist: " << filename;
QFile f(filename);
if (!f.open (QFile::ReadOnly))
QString tmp = f.readAll();
f.close ();
QStringList lines = tmp.split("\n");
- clearPlaylist();
foreach (QString l, lines)
{
if (l.isEmpty() || (!QFileInfo (l).exists() && (l.indexOf("http") != 0)))
qDebug () << "Load " << l;
items.append(PlaylistItem (l));
}
- if (!items.isEmpty())
- metaInformationResolver->setCurrentSource(items.at(0).source);
- emit playlistChanged (0);
}
+void PlaylistManager::appendPlaylistPLS(const QString& filename)
+{
+ qDebug () << "Attempting to load playlist: " << filename;
+ QFile f(filename);
+ if (!f.open (QFile::ReadOnly))
+ return;
+ QString tmp = f.readAll();
+ f.close ();
+ QStringList lines = tmp.split("\n");
+ QMap<int, int> filemap;
+
+ foreach (QString l, lines)
+ {
+ if (l.isEmpty() || l.trimmed().toLower() == "[playlist]" || l.trimmed().toLower() == "version=2")
+ {
+ continue;
+ }
+ qDebug () << "PLS " << l;
+ if (l.trimmed().toLower().left(4) == "file")
+ {
+ QStringList tokens = l.split('=');
+ if (tokens.size () < 2)
+ continue;
+ tokens[0] = tokens[0].mid (4);
+ filemap.insert(tokens[0].toInt (), items.size ());
+ qDebug () << tokens;
+ items.append(PlaylistItem (tokens[1]));
+ }
+ else if (l.trimmed().toLower().left(5) == "title")
+ {
+ QStringList tokens = l.split('=');
+ if (tokens.size () < 2)
+ continue;
+ tokens[0] = tokens[0].mid (5);
+ int toupdate = filemap[tokens[0].toInt()];
+ qDebug () << "Need to update " << toupdate << " for " << l;
+ QStringList metatok = tokens[1].split (" - ");
+ qDebug () << metatok;
+ if (metatok.size() > 2 && toupdate >= 0 && toupdate < items.size ())
+ {
+ items[toupdate].artist = metatok[0];
+ items[toupdate].title = metatok[1];
+ metatok = metatok.mid (2);
+ items[toupdate].album = metatok.join (" - ");
+ }
+ else
+ {
+ items[toupdate].title = metatok.join (" - ");
+ }
+ }
+ }
+}
+
+
void PlaylistManager::clearPlaylist()
{
items.clear();
void savePlaylist(const QString& filename);
void loadPlaylist(const QString& filename);
void clearPlaylist();
+ void addPlaylist (const QString& filename);
signals:
void playlistChanged (int from);
void itemUpdated (int index);
private slots:
void metaStateChanged(Phonon::State newState, Phonon::State oldState);
+ void appendPlaylist (const QString& filename);
+ void appendPlaylistPLS (const QString& filename);
private:
Phonon::MediaObject *metaInformationResolver;