new buttons, loads pls files
authortamas <tamas@brutus.(none)>
Sat, 24 Jul 2010 18:11:09 +0000 (20:11 +0200)
committertamas <tamas@brutus.(none)>
Sat, 24 Jul 2010 18:11:09 +0000 (20:11 +0200)
14 files changed:
ampres.qrc
images/Button Next.png
images/Button Pause.png
images/Button Play.png
images/Button Previous.png
images/Button Reload Active.png [new file with mode: 0644]
images/Button Reload.png
images/Button Stop.png
images/Tomamp.png [new file with mode: 0644]
images/shuffle Active.png [new file with mode: 0644]
images/shuffle.png
mainwindow.cpp
playlistmanager.cpp
playlistmanager.h

index cb310b9..1673f53 100644 (file)
@@ -8,5 +8,8 @@
         <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>
index 2c273df..3e18aad 100644 (file)
Binary files a/images/Button Next.png and b/images/Button Next.png differ
index ae49a13..76ba422 100644 (file)
Binary files a/images/Button Pause.png and b/images/Button Pause.png differ
index 45fafc6..de1a5f3 100644 (file)
Binary files a/images/Button Play.png and b/images/Button Play.png differ
index f620643..dcaad8d 100644 (file)
Binary files a/images/Button Previous.png and b/images/Button Previous.png differ
diff --git a/images/Button Reload Active.png b/images/Button Reload Active.png
new file mode 100644 (file)
index 0000000..5f983dd
Binary files /dev/null and b/images/Button Reload Active.png differ
index 741adfa..4d98b97 100644 (file)
Binary files a/images/Button Reload.png and b/images/Button Reload.png differ
index 32e4775..2415154 100644 (file)
Binary files a/images/Button Stop.png and b/images/Button Stop.png differ
diff --git a/images/Tomamp.png b/images/Tomamp.png
new file mode 100644 (file)
index 0000000..5a92bc5
Binary files /dev/null and b/images/Tomamp.png differ
diff --git a/images/shuffle Active.png b/images/shuffle Active.png
new file mode 100644 (file)
index 0000000..996ae97
Binary files /dev/null and b/images/shuffle Active.png differ
index 1372d24..3ce441a 100644 (file)
Binary files a/images/shuffle.png and b/images/shuffle.png differ
index 78fc6bb..dfd01f9 100644 (file)
@@ -39,6 +39,7 @@ MainWindow::MainWindow()
     if (curind >= 0)
         setItem (curind, false);
     audioOutput->setVolume(settings.value("volume", .5).toReal());
+    QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
 }
 
 MainWindow::~MainWindow()
@@ -61,7 +62,7 @@ void MainWindow::addFiles()
     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;
@@ -71,7 +72,10 @@ void MainWindow::addFiles()
     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);
 }
@@ -116,7 +120,7 @@ void MainWindow::about()
         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 */)
@@ -147,6 +151,7 @@ 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);
@@ -487,11 +492,17 @@ void MainWindow::setupActions()
     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"));
@@ -567,12 +578,20 @@ void MainWindow::repeatToggle ()
     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 ()
@@ -703,6 +722,8 @@ void MainWindow::cellClicked(int /*row*/, int)
 void MainWindow::contextMenuEvent (QContextMenuEvent*e)
 {
     qDebug () << "Context menu event!";
+    if (childAt (e->pos())->parentWidget() != musicTable)
+        return;
     contextMenu->popup(e->globalPos());
 }
 
@@ -731,13 +752,17 @@ void MainWindow::setupShuffleList()
 
 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);
 }
 
index 0293bf0..8ee44ed 100644 (file)
@@ -1,6 +1,7 @@
 #include "playlistmanager.h"
 #include <QDir>
 #include <QUrl>
+#include <QMap>
 
 PlaylistManager::PlaylistManager(QWidget* parent)
     : parentWidget (parent)
@@ -173,17 +174,38 @@ void PlaylistManager::savePlaylist(const QString& filenam)
     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 (...)
@@ -194,6 +216,34 @@ void PlaylistManager::savePlaylist(const QString& filenam)
 
 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))
@@ -201,7 +251,6 @@ void PlaylistManager::loadPlaylist(const QString& filename)
     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)))
@@ -211,11 +260,62 @@ void PlaylistManager::loadPlaylist(const QString& filename)
         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();
index 49484b9..a22008b 100644 (file)
@@ -36,11 +36,14 @@ public slots:
     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;