reorganisation, added debian package stuff
authortmarki <tmarki@gmail.com>
Thu, 12 Aug 2010 23:05:20 +0000 (01:05 +0200)
committertmarki <tmarki@gmail.com>
Thu, 12 Aug 2010 23:05:20 +0000 (01:05 +0200)
59 files changed:
LICENSE [new file with mode: 0644]
ampres.qrc [deleted file]
bugs.txt [deleted file]
data/26x26/Tomamp.png [new file with mode: 0644]
data/40x40/Tomamp.png [new file with mode: 0644]
data/64x64/Tomamp.png [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/dirs [new file with mode: 0644]
debian/docs [new file with mode: 0644]
debian/optify [new file with mode: 0644]
debian/rules [new file with mode: 0755]
debian/tomamp.install [new file with mode: 0644]
debian/tomamp.postinst [new file with mode: 0755]
debian/tomamp.postrm [new file with mode: 0755]
debian/tomamp.preinst [new file with mode: 0644]
images/Button Next.png [deleted file]
images/Button Pause.png [deleted file]
images/Button Play.png [deleted file]
images/Button Previous.png [deleted file]
images/Button Reload Active.png [deleted file]
images/Button Reload.png [deleted file]
images/Button Stop.png [deleted file]
images/Tomamp.png [deleted file]
images/audio-volume-high.png [deleted file]
images/shuffle Active.png [deleted file]
images/shuffle.png [deleted file]
main.cpp [deleted file]
mainwindow.cpp [deleted file]
mainwindow.h [deleted file]
optiondialog.cpp [deleted file]
optiondialog.h [deleted file]
playlistmanager.cpp [deleted file]
playlistmanager.h [deleted file]
tomamp.pro
tomamp/README [new file with mode: 0644]
tomamp/ampres.qrc [new file with mode: 0644]
tomamp/bugs.txt [new file with mode: 0644]
tomamp/images/Button Next.png [new file with mode: 0644]
tomamp/images/Button Pause.png [new file with mode: 0644]
tomamp/images/Button Play.png [new file with mode: 0644]
tomamp/images/Button Previous.png [new file with mode: 0644]
tomamp/images/Button Reload Active.png [new file with mode: 0644]
tomamp/images/Button Reload.png [new file with mode: 0644]
tomamp/images/Button Stop.png [new file with mode: 0644]
tomamp/images/Tomamp.png [new file with mode: 0644]
tomamp/images/audio-volume-high.png [new file with mode: 0644]
tomamp/images/shuffle Active.png [new file with mode: 0644]
tomamp/images/shuffle.png [new file with mode: 0644]
tomamp/main.cpp [new file with mode: 0644]
tomamp/mainwindow.cpp [new file with mode: 0644]
tomamp/mainwindow.h [new file with mode: 0644]
tomamp/optiondialog.cpp [new file with mode: 0644]
tomamp/optiondialog.h [new file with mode: 0644]
tomamp/playlistmanager.cpp [new file with mode: 0644]
tomamp/playlistmanager.h [new file with mode: 0644]
tomamp/tomamp.pro [new file with mode: 0644]

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..199b9e7
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,66 @@
+GNU LESSER GENERAL PUBLIC LICENSE
+
+Version 3, 29 June 2007
+
+Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
+
+Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
+
+This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
+0. Additional Definitions.
+
+As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
+
+“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
+
+An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
+
+A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
+
+The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
+
+The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
+1. Exception to Section 3 of the GNU GPL.
+
+You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
+2. Conveying Modified Versions.
+
+If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
+
+    * a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
+        * b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
+
+        3. Object Code Incorporating Material from Library Header Files.
+
+        The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
+
+            * a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
+                * b) Accompany the object code with a copy of the GNU GPL and this license document.
+
+                4. Combined Works.
+
+                You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
+
+                    * a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
+                        * b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
+                            * c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
+                                * d) Do one of the following:
+                                          o 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
+                                                    o 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
+                                                        * e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
+
+    5. Combined Libraries.
+
+    You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
+
+        * a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
+            * b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
+
+            6. Revised Versions of the GNU Lesser General Public License.
+
+            The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
+
+            Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
+
+            If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
+
diff --git a/ampres.qrc b/ampres.qrc
deleted file mode 100644 (file)
index 1673f53..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<RCC>
-    <qresource prefix="/images">
-        <file alias="volume">images/audio-volume-high.png</file>
-        <file alias="shuffle">images/shuffle.png</file>
-        <file alias="next">images/Button Next.png</file>
-        <file alias="pause">images/Button Pause.png</file>
-        <file alias="play">images/Button Play.png</file>
-        <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>
diff --git a/bugs.txt b/bugs.txt
deleted file mode 100644 (file)
index 8001ce8..0000000
--- a/bugs.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-- remember folder position when adding songs (takes time as adding a song and going one folder up for next song jumps to top of folder)
-- when saving a playlist, the default path seems invalid, so playlist doesn's save, and no error given
-- for some reasom, one folder shows 0 files, but filled with mp3 files (?)
-- quit while reading tags causes crash
-
-Fixed:
-+ context menu event outside of musicTable causes crash
-+ cancel add folder, add url causes crash
-+ doesn't remember add folder folder
-+ adding some files can cause a crash ("Blessing, Compassion")
-+ bold-italic highlight does not move on normal track switch (when one ends and the next starts)
-+ quick next-next while playing stops playback
-+ meta info display mismatch (title duplication, some files receive some other file's meta info instead of their ("reality")) (might be related to previous)
diff --git a/data/26x26/Tomamp.png b/data/26x26/Tomamp.png
new file mode 100644 (file)
index 0000000..5a92bc5
Binary files /dev/null and b/data/26x26/Tomamp.png differ
diff --git a/data/40x40/Tomamp.png b/data/40x40/Tomamp.png
new file mode 100644 (file)
index 0000000..5a92bc5
Binary files /dev/null and b/data/40x40/Tomamp.png differ
diff --git a/data/64x64/Tomamp.png b/data/64x64/Tomamp.png
new file mode 100644 (file)
index 0000000..5a92bc5
Binary files /dev/null and b/data/64x64/Tomamp.png differ
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..a0b1419
--- /dev/null
@@ -0,0 +1,20 @@
+tomamp (0.1-maemo2) unstable; urgency=low
+
+  * Package fix again :(
+  
+
+ -- Tamas Marki <tmarki@gmail.com>  Tue, 10 Aug 2010 11:59:07 +0200
+
+tomamp (0.1-maemo1) unstable; urgency=low
+
+  * Package fix (hopefully)
+  
+
+ -- Tamas Marki <tmarki@gmail.com>  Mon, 09 Aug 2010 21:34:07 +0200
+tomamp (0.1-maemo0) unstable; urgency=low
+
+  * Initial release
+  
+
+ -- Tamas Marki <tmarki@gmail.com>  Mon, 09 Aug 2010 21:34:07 +0200
+
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..c8e49e2
--- /dev/null
@@ -0,0 +1,17 @@
+Source: tomamp
+Section: user/multimedia
+Priority: extra
+Maintainer: Tamas Marki <tmarki@gmail.com>
+Build-Depends: debhelper (>= 5), libqt4-dev (>= 4.5.0)
+Standards-Version: 3.8.0
+Homepage: http://tmarki.com/wp/tomamp
+XSBC-Bugtracker: mailto:tmarki@gmail.com
+
+Package: tomamp
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Simple playlist-based music player
+ TomAmp is a simple, easy to use, playlist-based audio player
+ for Maemo.
+ .
+XB-Maemo-Display-Name: TomAmp Music Player
diff --git a/debian/copyright b/debian/copyright
new file mode 100644 (file)
index 0000000..6185bbf
--- /dev/null
@@ -0,0 +1,52 @@
+This package was debianized by:
+
+    Tamas Marki <tmarki@gmail.com> on Mon, 09 Aug 2010 21:37:54 +0200
+
+It was downloaded from:
+
+    <url://example.com>
+
+Upstream Author(s):
+
+    <put author's name and email here>
+    <likewise for another author>
+
+Copyright:
+
+    <Copyright (C) YYYY Firtname Lastname>
+    <likewise for another author>
+
+License:
+
+### SELECT: ###
+    This package is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+### OR ###
+   This package is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License version 2 as
+   published by the Free Software Foundation.
+##########
+
+    This package is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this package; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+On Debian systems, the complete text of the GNU General
+Public License can be found in `/usr/share/common-licenses/GPL'.
+
+The Debian packaging is:
+
+    Copyright C) 2010, Tamas Marki <tmarki@gmail.com>
+
+and is licensed under the GPL, see above.
+
+
+# Please also look if there are files or directories which have a
+# different copyright/license attached and list them here.
diff --git a/debian/dirs b/debian/dirs
new file mode 100644 (file)
index 0000000..e772481
--- /dev/null
@@ -0,0 +1 @@
+usr/bin
diff --git a/debian/docs b/debian/docs
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/debian/optify b/debian/optify
new file mode 100644 (file)
index 0000000..865faf1
--- /dev/null
@@ -0,0 +1 @@
+auto
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..4e97e7c
--- /dev/null
@@ -0,0 +1,60 @@
+#!/usr/bin/make -f
+APPNAME := tomamp
+builddir:
+       mkdir -p builddir
+
+builddir/Makefile: builddir
+#      qmake -v
+#      cd builddir && /opt/qt4-maemo5/bin/qmake PREFIX=/usr ../$(APPNAME).pro
+       cd builddir && qmake-qt4 PREFIX=/usr ../$(APPNAME).pro
+
+build: build-stamp
+
+build-stamp: builddir/Makefile
+       dh_testdir
+       # Add here commands to compile the package.
+       cd builddir && $(MAKE)
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp
+       # Add here commands to clean up after the build process.
+       rm -rf builddir
+       dh_clean
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k
+       dh_installdirs
+#      dh_install -X.svn
+
+
+       # Add here commands to install the package into debian/your_appname
+       cd builddir && $(MAKE) INSTALL_ROOT=$(CURDIR)/debian/$(APPNAME) install
+#      cd builddir && $(MAKE) INSTALL_ROOT=$(CURDIR)/debian/$(APPNAME)-experimental install
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_installdocs
+       dh_installexamples
+       dh_installman
+       dh_link
+       dh_strip
+       dh_compress
+       dh_fixperms
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
+
diff --git a/debian/tomamp.install b/debian/tomamp.install
new file mode 100644 (file)
index 0000000..379002e
--- /dev/null
@@ -0,0 +1,3 @@
+tomamp/*.desktop usr/share/applications/hildon
+tomamp/images/Tomamp.png usr/share/icons/hicolor/26x26/apps
+
diff --git a/debian/tomamp.postinst b/debian/tomamp.postinst
new file mode 100755 (executable)
index 0000000..fd751fa
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+gtk-update-icon-cache /usr/share/icons/hicolor
+
diff --git a/debian/tomamp.postrm b/debian/tomamp.postrm
new file mode 100755 (executable)
index 0000000..13f4793
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+
diff --git a/debian/tomamp.preinst b/debian/tomamp.preinst
new file mode 100644 (file)
index 0000000..594dd96
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+rm -f /home/user/.config/TomAmp/TomAmp.conf
+
diff --git a/images/Button Next.png b/images/Button Next.png
deleted file mode 100644 (file)
index 3e18aad..0000000
Binary files a/images/Button Next.png and /dev/null differ
diff --git a/images/Button Pause.png b/images/Button Pause.png
deleted file mode 100644 (file)
index 76ba422..0000000
Binary files a/images/Button Pause.png and /dev/null differ
diff --git a/images/Button Play.png b/images/Button Play.png
deleted file mode 100644 (file)
index de1a5f3..0000000
Binary files a/images/Button Play.png and /dev/null differ
diff --git a/images/Button Previous.png b/images/Button Previous.png
deleted file mode 100644 (file)
index dcaad8d..0000000
Binary files a/images/Button Previous.png and /dev/null differ
diff --git a/images/Button Reload Active.png b/images/Button Reload Active.png
deleted file mode 100644 (file)
index 5f983dd..0000000
Binary files a/images/Button Reload Active.png and /dev/null differ
diff --git a/images/Button Reload.png b/images/Button Reload.png
deleted file mode 100644 (file)
index 4d98b97..0000000
Binary files a/images/Button Reload.png and /dev/null differ
diff --git a/images/Button Stop.png b/images/Button Stop.png
deleted file mode 100644 (file)
index 2415154..0000000
Binary files a/images/Button Stop.png and /dev/null differ
diff --git a/images/Tomamp.png b/images/Tomamp.png
deleted file mode 100644 (file)
index 5a92bc5..0000000
Binary files a/images/Tomamp.png and /dev/null differ
diff --git a/images/audio-volume-high.png b/images/audio-volume-high.png
deleted file mode 100644 (file)
index 70ae43a..0000000
Binary files a/images/audio-volume-high.png and /dev/null differ
diff --git a/images/shuffle Active.png b/images/shuffle Active.png
deleted file mode 100644 (file)
index 996ae97..0000000
Binary files a/images/shuffle Active.png and /dev/null differ
diff --git a/images/shuffle.png b/images/shuffle.png
deleted file mode 100644 (file)
index 3ce441a..0000000
Binary files a/images/shuffle.png and /dev/null differ
diff --git a/main.cpp b/main.cpp
deleted file mode 100644 (file)
index 29dd3e6..0000000
--- a/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <QtGui/QApplication>
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
-    QApplication a(argc, argv);
-    a.setApplicationName("tomamp");
-    MainWindow w;
-#if defined(Q_WS_S60)
-    w.showMaximized();
-#else
-    w.show();
-#endif
-
-    return a.exec();
-}
diff --git a/mainwindow.cpp b/mainwindow.cpp
deleted file mode 100644 (file)
index a3f1bde..0000000
+++ /dev/null
@@ -1,865 +0,0 @@
-#include <QtGui>
-#include <QtDebug>
-#include <QInputDialog>
-
-#include "mainwindow.h"
-#include "time.h"
-
-//#define AVOID_INPUT_DIALOG 0
-
-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);
-
-    mediaObject->setTickInterval(1000);
-    connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
-    connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
-        this, SLOT(stateChanged(Phonon::State,Phonon::State)));
-    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
-        this, SLOT(sourceChanged(Phonon::MediaSource)));
-    connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
-    connect (&plman, SIGNAL (playlistChanged (int)), this, SLOT (playlistChanged(int)));
-    connect (&plman, SIGNAL (itemUpdated(int)), this, SLOT (itemUpdated (int)));
-    connect (&plman, SIGNAL (itemRemoved(int)), this, SLOT (itemRemoved (int)));
-
-    Phonon::createPath(mediaObject, audioOutput);
-
-    qsrand (time (NULL));
-    repeat = settings.value("repeat", false).toBool();
-    shuffle = settings.value("shuffle", false).toBool();
-    setupShuffleList();
-    setupActions();
-    setupMenus();
-    setupUi();
-    show ();
-    timeLcd->display("00:00:00");
-    plman.addStringList(settings.value("lastPlaylist").toStringList());
-    setupShuffleList();
-    int curind = settings.value("currentIndex", -1).toInt ();
-    if (curind >= 0)
-        setItem (curind, false);
-    audioOutput->setVolume(settings.value("volume", .5).toReal());
-    QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
-}
-
-MainWindow::~MainWindow()
-{
-    settings.setValue("shuffle", shuffle);
-    settings.setValue("repeat", repeat);
-    settings.setValue("lastPlaylist", plman.playlistStrings());
-    settings.setValue("volume", audioOutput->volume());
-    settings.setValue("currentIndex", plman.indexOf(mediaObject->currentSource()));
-    for (int i = 0; i < musicTable->columnCount(); ++i)
-    {
-        QString lab = QString ("colWidth_%1").arg (i);
-        settings.setValue(lab, musicTable->columnWidth(i));
-    }
-}
-
-void MainWindow::addFiles()
-{
-    QString folder = settings.value("LastFolder").toString();
-    if (folder.isEmpty())
-        folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
-    QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Files To Add"),
-                    folder, "Music files (*.mp3 *.ogg *.wav *.flac);;Playlists (*.m3u *.pls)");
-
-    if (files.isEmpty())
-        return;
-
-    QString dir = QFileInfo (files[0]).absoluteDir().absolutePath();
-    settings.setValue("LastFolder", dir);
-    QStringList toadd;
-    foreach (QString string, files)
-    {
-        if (string.toLower().endsWith(".pls") || string.toLower().endsWith(".m3u"))
-            plman.addPlaylist(string);
-        else
-            toadd.append (string);
-    }
-    plman.addStringList(toadd);
-}
-
-void MainWindow::addFolder()
-{
-    QString folder = settings.value("LastFolder").toString();
-    if (folder.isEmpty())
-        folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
-    QString dir = QFileDialog::getExistingDirectory(this,
-            tr("Select Directory To Add"),
-            folder);
-
-    if (dir.isEmpty())
-        return;
-
-    settings.setValue("LastFolder", dir);
-
-    QStringList filters;
-    QStringList files = QDir (dir).entryList(filters, QDir::AllDirs);
-    files.removeAll(".");
-    files.removeAll("..");
-    bool recursive = false;
-    if (files.size())
-        recursive = QMessageBox::question(this, "Add all folders", "Subfolders have been detected, add everything?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
-    plman.parseAndAddFolder(dir, recursive);
-}
-
-
-void MainWindow::addUrl()
-{
-#ifdef AVOID_INPUT_DIALOG
-    QString url = "http://war.str3am.com:7970";
-#else
-    QString url = QInputDialog::getText(this, "Get URL", "Please type in the stream URL");
-#endif
-    if (url.isEmpty() || !url.toLower().startsWith("http"))
-        return;
-    QStringList toadd;
-    toadd << url;
-    plman.addStringList(toadd);
-}
-
-
-void MainWindow::about()
-{
-    QMessageBox::information(this, tr("About TomAmp v0.1"),
-        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/"));
-}
-
-void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
-{
-    switch (newState)
-    {
-        case Phonon::ErrorState:
-            if (mediaObject->errorType() == Phonon::FatalError)
-            {
-//                QMessageBox::warning(this, tr("Fatal Error"),
-//                mediaObject->errorString() + mediaObject->currentSource().fileName() + ", " + mediaObject->currentSource().url().toString());
-            }
-            else
-            {
-//                QMessageBox::warning(this, tr("Error"),
-//                mediaObject->errorString());
-            }
-            next ();
-            break;
-        case Phonon::PlayingState:
-            setWindowTitle(mediaObject->metaData().value("TITLE") + " - TomAmp");
-            pauseAction->setVisible(true);
-            playAction->setVisible (false);
-            playAction->setEnabled(false);
-            pauseAction->setEnabled(true);
-            stopAction->setEnabled(true);
-            //lastPlayed = plman.indexOf(mediaObject->currentSource());
-            break;
-        case Phonon::StoppedState:
-            setWindowTitle("TomAmp");
-            stopAction->setEnabled(false);
-            playAction->setEnabled(true);
-            pauseAction->setVisible(false);
-            playAction->setVisible(true);
-            pauseAction->setEnabled(false);
-            timeLcd->display("00:00:00");
-            unhighlightRow(plman.indexOf(mediaObject->currentSource()));
-            break;
-        case Phonon::PausedState:
-            pauseAction->setEnabled(false);
-            stopAction->setEnabled(true);
-            pauseAction->setVisible(false);
-            playAction->setVisible(true);
-            playAction->setEnabled(true);
-            break;
-        case Phonon::BufferingState:
-            break;
-        default:
-        ;
-    }
-}
-
-void MainWindow::next()
-{
-    bool wasPlaying = isPlaying;
-    if (mediaObject->state () == Phonon::ErrorState)
-        wasPlaying = true;
-    int index = plman.indexOf(mediaObject->currentSource());
-    if (shuffle)
-    {
-        index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
-        while (index < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
-        {
-            index += 1;
-        }
-        if (index < shuffleList.size ())
-        {
-            setItem (index, wasPlaying);
-        }
-        else if (repeat)
-        {
-            index = 0;
-            while ((index) < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
-            {
-                index += 1;
-            }
-            setItem (index, wasPlaying);
-        }
-    }
-    else
-    {
-        index++;
-        while ((index) < plman.size () && !plman.getItem(index).playable)
-        {
-            index += 1;
-        }
-        if (index < plman.size())
-        {
-            setItem (index, wasPlaying);
-        }
-        else if (repeat)
-        {
-            index = 0;
-            while ((index) < plman.size () && !plman.getItem(index).playable)
-            {
-                index += 1;
-            }
-            setItem (index, wasPlaying);
-        }
-    }
-}
-
-void MainWindow::setItem(int i, bool doplay)
-{
-    if (i < plman.size() && i >= 0)
-    {
-        if (lastPlayed >= 0)
-            unhighlightRow(lastPlayed);
-        if (shuffle)
-        {
-            mediaObject->setCurrentSource(plman.at (shuffleList[i]));
-        }
-        else
-        {
-            mediaObject->setCurrentSource(plman.at(i));
-        }
-    }
-    if (doplay && mediaObject->currentSource().type() != Phonon::MediaSource::Invalid)
-    {
-        play();
-    }
-    else
-        stop ();
-}
-
-void MainWindow::previous()
-{
-    bool wasPlaying = isPlaying;//(mediaObject->state () == Phonon::PlayingState);
-    if (mediaObject->state () == Phonon::ErrorState)
-        wasPlaying = true;
-    int index = plman.indexOf(mediaObject->currentSource());
-    if (shuffle)
-    {
-        index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) - 1;
-        while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
-        {
-            index--;
-        }
-        if (index >= 0)
-        {
-            setItem (index, wasPlaying);
-        }
-        else if (repeat)
-        {
-            index = plman.size () - 1;
-            while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
-            {
-                index--;
-            }
-            setItem (index, wasPlaying);
-        }
-/*        if (index < 0)
-            wasPlaying = false;*/
-
-    }
-    else
-    {
-        index--;
-        while ((index) >= 0 && !plman.getItem(index).playable)
-        {
-            index--;
-        }
-        if (index >= 0)
-        {
-            setItem (index, wasPlaying);
-        }
-        else if (repeat)
-        {
-            index = plman.size() - 1;
-            while ((index) >= 0 && !plman.getItem(index).playable)
-            {
-                index--;
-            }
-            setItem (index, wasPlaying);
-        }
-    }
-}
-
-void MainWindow::highlightRow (int i)
-{
-    for (int j = 0; j < 3; ++j)
-    {
-        QTableWidgetItem* item = musicTable->item(i, j);
-        if (item)
-        {
-            QFont font = item->font();
-            font.setBold(true);
-            font.setItalic(true);
-            item->setFont(font);
-        }
-    }
-}
-
-void MainWindow::unhighlightRow (int i)
-{
-    for (int j = 0; j < 3; ++j)
-    {
-        QTableWidgetItem* item = musicTable->item(i, j);
-        if (item)
-        {
-            QFont font = item->font();
-            font.setBold(false);
-            font.setItalic(false);
-            item->setFont(font);
-        }
-    }
-}
-
-
-void MainWindow::tick(qint64 time)
-{
-    QTime displayTime((time / 3600000), (time / 60000) % 60, (time / 1000) % 60);
-
-    timeLcd->display(displayTime.toString("HH:mm:ss"));
-}
-
-void MainWindow::tableClicked(int row, int /* column */)
-{
-//    bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
-
-/*    mediaObject->stop();
-    mediaObject->clearQueue();*/
-
-    if (row >= plman.size())
-        return;
-
-    int index = row;
-    while (index < shuffleList.size () && !plman.getItem(index).playable)
-    {
-        index += 1;
-    }
-    if (plman.size() > index)
-    {
-        if (shuffle)
-            index = shuffleList.indexOf(index);
-        setItem (index, true);
-//        mediaObject->play();
-    }
-    else
-    {
-        index = 0;
-        while (index < plman.size () && !plman.getItem(index).playable)
-        {
-            index += 1;
-        }
-        if (plman.size() > index)
-        {
-            if (shuffle)
-                index = shuffleList.indexOf(index);
-            setItem (index, true);
-//            mediaObject->play();
-        }
-    }
-
-}
-
-void MainWindow::sourceChanged(const Phonon::MediaSource &source)
-{
-    int ind = plman.indexOf(source);
-    highlightRow(ind);
-    unhighlightRow(lastPlayed);
-    lastPlayed = ind;
-    musicTable->selectRow(ind);
-    timeLcd->display("00:00:00");
-}
-
-
-void MainWindow::aboutToFinish()
-{
-    int index = plman.indexOf(mediaObject->currentSource()) + 1;
-    if (shuffle)
-    {
-        index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
-        if (index < shuffleList.size ())
-        {
-            mediaObject->enqueue(plman.at (shuffleList[index]));
-        }
-        else if (repeat)
-        {
-            mediaObject->enqueue(plman.at (shuffleList[0]));
-        }
-
-    }
-    else
-    {
-        if (plman.size() > index)
-        {
-            mediaObject->enqueue(plman.at(index));
-        }
-        else if (repeat)
-        {
-            mediaObject->enqueue(plman.at(0));
-        }
-    }
-}
-
-void MainWindow::finished()
-{
-}
-
-void MainWindow::setupActions()
-{
-    playAction = new QAction(QIcon (QPixmap (":images/play")), "", this);
-    playAction->setShortcut(tr("Crl+P"));
-    playAction->setDisabled(true);
-    pauseAction = new QAction(QIcon (QPixmap (":images/pause")), "", this);
-    pauseAction->setShortcut(tr("Ctrl+A"));
-    pauseAction->setDisabled(true);
-    pauseAction->setVisible(false);
-    stopAction = new QAction(QIcon (QPixmap (":images/stop")), "", this);
-    stopAction->setShortcut(tr("Ctrl+S"));
-    stopAction->setDisabled(true);
-    nextAction = new QAction(QIcon (QPixmap (":images/next")), "", this);
-    nextAction->setShortcut(tr("Ctrl+N"));
-    previousAction = new QAction(QIcon (QPixmap (":images/previous")), "", this);
-    previousAction->setShortcut(tr("Ctrl+R"));
-    if (repeat)
-        repeatAction = new QAction(QIcon (QPixmap (":images/repeatActive")), "", this);
-    else
-        repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), "", this);
-    repeatAction->setCheckable(true);
-    repeatAction->setChecked(repeat);
-    repeatAction->setShortcut(tr("Ctrl+I"));
-    if (shuffle)
-        shuffleAction = new QAction(QIcon (QPixmap (":images/shuffleActive")), "", this);
-    else
-        shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), "", this);
-    shuffleAction->setCheckable(true);
-    shuffleAction->setChecked(shuffle);
-    shuffleAction->setShortcut(tr("Ctrl+H"));
-    volumeAction = new QAction(QIcon (QPixmap (":images/volume")), "", this);
-    volumeAction->setCheckable(true);
-    volumeAction->setShortcut(tr("Ctrl+V"));
-    addFilesAction = new QAction(tr("Add &File"), this);
-    addFilesAction->setShortcut(tr("Ctrl+F"));
-    addFoldersAction = new QAction(tr("Add F&older"), this);
-    addFoldersAction->setShortcut(tr("Ctrl+O"));
-    addUrlAction = new QAction(tr("Add &Url"), this);
-    addUrlAction->setShortcut(tr("Ctrl+U"));
-    savePlaylistAction = new QAction (tr("Sa&ve Playlist"), this);
-    savePlaylistAction->setShortcut(tr ("Ctrl+V"));
-    loadPlaylistAction = new QAction (tr("&Load Playlist"), this);
-    loadPlaylistAction->setShortcut(tr("Ctrl+L"));
-    clearPlaylistAction = new QAction (tr("&Clear Playlist"), this);
-    clearPlaylistAction->setShortcut(tr("Ctrl+C"));
-    exitAction = new QAction(tr("E&xit"), this);
-    exitAction->setShortcut(tr("Ctrl+X"));
-    aboutAction = new QAction(tr("A&bout"), this);
-    aboutAction->setShortcut(tr("Ctrl+B"));
-    aboutQtAction = new QAction(tr("About &Qt"), this);
-    aboutQtAction->setShortcut(tr("Ctrl+Q"));
-/*    removeSelected = new QAction (tr("&Delete from playlist"));
-    removeSelected->setShortcut(tr ("Ctrl+D"));*/
-
-    connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
-    connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
-    connect(stopAction, SIGNAL(triggered()), this, SLOT(stop()));
-    connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
-    connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
-    connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
-
-    connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
-    connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
-    connect(addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
-    connect (savePlaylistAction, SIGNAL (triggered()), this, SLOT (savePlaylist()));
-    connect (loadPlaylistAction, SIGNAL (triggered()), this, SLOT (loadPlaylist()));
-    connect (clearPlaylistAction, SIGNAL (triggered()), &plman, SLOT (clearPlaylist()));
-    connect (nextAction, SIGNAL(triggered()), this, SLOT(next()));
-    connect (previousAction, SIGNAL(triggered()), this, SLOT(previous()));
-    connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
-    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
-    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
-//    connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
-}
-
-void MainWindow::removeSelectedItem()
-{
-    if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
-        return;
-    int row = musicTable->currentRow();
-    if (row >= 0)
-        plman.removeItem(row);
-}
-
-void MainWindow::removeAllButSelectedItem()
-{
-    if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove all other items?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
-        return;
-    int row = musicTable->currentRow();
-    if (row >= 0)
-    {
-        QString uri = plman.getItem(row).uri;
-        QStringList lst;
-        lst << uri;
-        plman.clearPlaylist();
-        plman.addStringList(lst);
-    }
-}
-
-void MainWindow::repeatToggle ()
-{
-    repeat = !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 ()
-{
-    volumeSlider->setVisible(volumeAction->isChecked());
-}
-
-void MainWindow::play()
-{
-    mediaObject->play();
-    lastPlayed = plman.indexOf(mediaObject->currentSource());
-    highlightRow(lastPlayed);
-    isPlaying = true;
-}
-
-void MainWindow::stop()
-{
-    mediaObject->stop();
-    isPlaying = false;
-}
-
-
-void MainWindow::setupMenus()
-{
-    QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
-    fileMenu->addAction(addFilesAction);
-    fileMenu->addAction(addFoldersAction);
-    fileMenu->addAction(addUrlAction);
-    fileMenu->addSeparator();
-    fileMenu->addAction(savePlaylistAction);
-    fileMenu->addAction(loadPlaylistAction);
-    fileMenu->addAction(clearPlaylistAction);
-//    fileMenu->addAction(exitAction);
-
-    QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
-    aboutMenu->addAction(aboutAction);
-    aboutMenu->addAction(aboutQtAction);
-}
-
-void MainWindow::setupUi()
-{
-    QToolBar *bar = new QToolBar;
-
-    bar->setOrientation(Qt::Vertical);
-    bar->setStyleSheet("padding:7px");
-    //bar->addAction(volumeAction);
-
-    seekSlider = new Phonon::SeekSlider(this);
-    seekSlider->setMediaObject(mediaObject);
-
-    volumeSlider = new Phonon::VolumeSlider(this);
-    volumeSlider->setAudioOutput(audioOutput);
-    volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
-    volumeSlider->setOrientation(Qt::Horizontal);
-    volumeSlider->setMuteVisible(false);
-//    volumeAddedAction = bar->addWidget(volumeSlider);
-//    volumeAddedAction->setVisible(false);
-    bar->addAction(playAction);
-    bar->addAction(pauseAction);
-    bar->addAction(stopAction);
-    bar->addAction(repeatAction);
-    bar->addAction(shuffleAction);
-    bar->addAction(nextAction);
-    bar->addAction(previousAction);
-
-    contextMenu = new QMenu (this);
-    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()));
-
-
-    timeLcd = new QLCDNumber;
-
-    QStringList headers;
-    headers << tr("Artist") << tr("Title") << tr("Album") << "Controls";
-
-    musicTable = new QTableWidget(0, 4);
-    musicTable->setHorizontalHeaderLabels(headers);
-    musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
-    musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
-    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;
-    QToolBar* bar2 = new QToolBar;
-    bar2->addAction(volumeAction);
-    seekerLayout->addWidget(bar2);
-    seekerLayout->addWidget(volumeSlider);
-    seekerLayout->addWidget(seekSlider);
-    seekerLayout->addWidget(timeLcd);
-
-    QVBoxLayout *playbackLayout = new QVBoxLayout;
-    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);
-
-    QWidget *widget = new QWidget;
-    widget->setLayout(mainLayout);
-
-    setCentralWidget(widget);
-    setWindowTitle("TomAmp");
-}
-
-void MainWindow::cellClicked(int /*row*/, int)
-{
-}
-
-void MainWindow::contextMenuEvent (QContextMenuEvent*e)
-{
-    if (!childAt (e->pos()))
-        return;
-    if (childAt (e->pos())->parentWidget() != musicTable)
-        return;
-    contextMenu->popup(e->globalPos());
-}
-
-
-void MainWindow::setupShuffleList()
-{
-    QList<int> tmp;
-    int index = plman.indexOf(mediaObject->currentSource());
-    if (index < 0)
-        index = 0;
-    for (int i = 0; i < plman.size(); ++i)
-    {
-        if ((i != index))
-            tmp.append(i);
-    }
-    shuffleList.clear();
-    shuffleList.append (index);
-    while (tmp.size ())
-    {
-        int ind = qrand () % tmp.size();
-        shuffleList.append(tmp[ind]);
-        tmp.removeAt(ind);
-    }
-}
-
-void MainWindow::savePlaylist ()
-{
-    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 *.pls");
-    if (filename.isEmpty())
-        return;
-    plman.loadPlaylist (filename);
-}
-
-void MainWindow::playlistChanged(int from)
-{
-    while (musicTable->rowCount() > from)
-    {
-        musicTable->removeRow(musicTable->rowCount () - 1);
-    }
-    int firstGood = -1;
-    for (int i = from; i < plman.size (); ++i)
-    {
-        if (firstGood < 0 && plman.getItem (i).playable)
-            firstGood = i;
-        int currentRow = musicTable->rowCount();
-        musicTable->insertRow(currentRow);
-        setRowFromItem (currentRow, plman.getItem(i));
-    }
-/*    if (plman.indexOf(mediaObject->currentSource()) < 0)
-    {
-        setItem (firstGood, false);
-    }*/
-    setupShuffleList();
-}
-
-void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
-{
-    if (row >= musicTable->rowCount())
-        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);
-    }
-    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;
-    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);
-        musicTable->selectRow(i - 1);
-    }
-}
-
-void MainWindow::buttonDown()
-{
-    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);
-        musicTable->selectRow(i + 1);
-    }
-}
-
-void MainWindow::buttonDel()
-{
-    int i = sender()->parent()->property("row").toInt();
-    qDebug () << "Presses del on " << i;
-    if (i < plman.size())
-    {
-        plman.removeItem(i);
-    }
-}
-
-void MainWindow::itemUpdated(int index)
-{
-    if (plman.indexOf(mediaObject->currentSource()) < 0 && plman.getItem (index).playable)
-    {
-        setItem (index, false);
-    }
-    setRowFromItem (index, plman.getItem(index));
-    if (plman.indexOf(mediaObject->currentSource()) == index)
-    {
-        if (shuffle) index = shuffleList.indexOf(index);
-        setItem (index, false);
-    }
-}
-
-void MainWindow::itemRemoved (int i)
-{
-    musicTable->removeRow(i);
-    for (int j = i ? (i - 1) : 0; j < musicTable->rowCount(); ++j)
-    {
-        if (musicTable->cellWidget(j, 3))
-            musicTable->cellWidget(j, 3)->setProperty("row", j);
-    }
-}
diff --git a/mainwindow.h b/mainwindow.h
deleted file mode 100644 (file)
index ce4edca..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial Usage
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights.  These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QSettings>
-#include <phonon/audiooutput.h>
-#include <phonon/seekslider.h>
-#include <phonon/mediaobject.h>
-#include <phonon/volumeslider.h>
-#include <phonon/backendcapabilities.h>
-#include <QList>
-#include "playlistmanager.h"
-
-class QAction;
-class QTableWidget;
-class QLCDNumber;
-
-
-class MainWindow : public QMainWindow
-{
-    Q_OBJECT
-
-public:
-    MainWindow();
-    ~MainWindow ();
-
-    QSize sizeHint() const
-    {
-        return QSize(800, 480);
-    }
-
-private slots:
-    void addFiles();
-    void addFolder();
-    void addUrl ();
-    void repeatToggle ();
-    void shuffleToggle ();
-    void volumeToggle ();
-    void about();
-    void stateChanged(Phonon::State newState, Phonon::State oldState);
-    void tick(qint64 time);
-    void sourceChanged(const Phonon::MediaSource &source);
-    void aboutToFinish();
-    void finished();
-    void tableClicked(int row, int column);
-    void play();
-    void stop();
-    void next();
-    void previous();
-    void cellClicked(int row, int column);
-    void savePlaylist ();
-    void loadPlaylist ();
-    void playlistChanged (int from);
-    void itemUpdated (int index);
-    void setItem (int ind, bool doplay);
-    void removeSelectedItem ();
-    void removeAllButSelectedItem ();
-    void highlightRow (int i);
-    void unhighlightRow (int i);
-    void buttonUp ();
-    void buttonDown ();
-    void buttonDel ();
-    void itemRemoved (int i);
-
-protected:
-    void contextMenuEvent (QContextMenuEvent*e);
-private:
-    void setupActions();
-    void setupMenus();
-    void setupUi();
-    void setupShuffleList();
-    void setRowFromItem (int row, const PlaylistItem& item);
-
-    Phonon::SeekSlider *seekSlider;
-    Phonon::MediaObject *mediaObject;
-    Phonon::AudioOutput *audioOutput;
-    Phonon::VolumeSlider *volumeSlider;
-
-    PlaylistManager plman;
-
-    QAction *playAction;
-    QAction *pauseAction;
-    QAction *stopAction;
-    QAction *repeatAction;
-    QAction *shuffleAction;
-    QAction *volumeAction;
-    QAction *volumeAddedAction;
-    QAction *nextAction;
-    QAction *previousAction;
-    QAction *addFilesAction;
-    QAction *addFoldersAction;
-    QAction *addUrlAction;
-    QAction *savePlaylistAction;
-    QAction *loadPlaylistAction;
-    QAction *clearPlaylistAction;
-    QAction *exitAction;
-    QAction *aboutAction;
-    QAction *aboutQtAction;
-    QAction *removeSelected;
-    QAction *removeAllButSelected;
-    QMenu   *contextMenu;
-    QToolBar *bar;
-    QLCDNumber *timeLcd;
-    QTableWidget *musicTable;
-    bool        repeat;
-    bool        shuffle;
-    QSettings settings;
-    QList<int>  shuffleList;
-    int lastPlayed;
-    bool isPlaying;
-};
-
-#endif
diff --git a/optiondialog.cpp b/optiondialog.cpp
deleted file mode 100644 (file)
index ed40032..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "optiondialog.h"
-
-OptionDialog::OptionDialog(QWidget *parent) :
-    QDialog(parent)
-{
-}
diff --git a/optiondialog.h b/optiondialog.h
deleted file mode 100644 (file)
index 12d15ce..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef OPTIONDIALOG_H
-#define OPTIONDIALOG_H
-
-#include <QDialog>
-
-class OptionDialog : public QDialog
-{
-    Q_OBJECT
-public:
-    explicit OptionDialog(QWidget *parent = 0);
-
-signals:
-
-public slots:
-
-};
-
-#endif // OPTIONDIALOG_H
diff --git a/playlistmanager.cpp b/playlistmanager.cpp
deleted file mode 100644 (file)
index 61681a2..0000000
+++ /dev/null
@@ -1,349 +0,0 @@
-#include "playlistmanager.h"
-#include <QDir>
-#include <QUrl>
-#include <QMap>
-
-QStringList allowedExtensions;
-
-
-PlaylistManager::PlaylistManager(QWidget* parent)
-    : parentWidget (parent), lastMetaRead (-1)
-{
-    allowedExtensions << "mp3" << "ogg" << "wav" << "wmv" << "wma";
-//    qDebug () << Phonon::BackendCapabilities::availableMimeTypes();
-    metaInformationResolver = new Phonon::MediaObject(parent);
-    connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
-        this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
-}
-
-int PlaylistManager::indexOf(const Phonon::MediaSource &s) const
-{
-    for (int i = 0; i < items.size(); ++i)
-    {
-        if (items[i].source == s)
-            return i;
-    }
-    return -1;
-}
-
-void PlaylistManager::parseAndAddFolder(const QString &dir, bool recursive)
-{
-    QStringList filters;
-//    filters << "*.mp3";
-
-    QStringList files = QDir (dir).entryList(filters);
-
-    if (files.isEmpty())
-        return;
-
-    qDebug () << "Parsing folder " << dir;
-
-    //settings.setValue("LastFolder", dir);
-    int index = items.size();
-    foreach (QString string, files)
-    {
-        if (string == "."  || string == "..")
-            continue;
-        QString fname = dir + "/" + string;
-        QFileInfo fi (fname);
-        if (fi.isDir())
-        {
-            if (recursive)
-                parseAndAddFolder(fname, true);
-            continue;
-        }
-        if (fileSupported(fname))
-        {
-            qDebug () << "Adding: " << fname;
-            items.append(PlaylistItem (PlaylistItem (fname)));
-        }
-    }
-//    if (!items.isEmpty())
-    if (items.size () > index)
-    {
-        metaInformationResolver->setCurrentSource(items.at(index).source);
-        lastMetaRead = index;
-    }
-    qDebug () << " SIZE: " << items.size ();
-    emit playlistChanged (index);
-}
-
-void PlaylistManager::addStringList(const QStringList& list)
-{
-    int index = items.size();
-    foreach (QString string, list)
-    {
-        if (fileSupported(string) || string.toLower().startsWith("http"))
-        {
-            qDebug () << "Adding " << string;
-            items.append(PlaylistItem (string));
-        }
-    }
-//    if (!items.isEmpty())
-    if (items.size () > index)
-    {
-        metaInformationResolver->setCurrentSource(items.at(index).source);
-        lastMetaRead = index;
-    }
-    emit playlistChanged(index);
-}
-
-void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State oldState)
-{
-    qDebug () << "Meta state now " << newState << " old state " << oldState;
-    // This is an ugly hack, since the metaInformationResolver doesn't properly load the assigned source when it's in the error state
-    // In order to properly read the next file we have to set it as current source again when the resolver entered the stopped state after the error
-    static bool wasError = false;
-    if (wasError && newState == Phonon::StoppedState)
-    {
-        metaInformationResolver->setCurrentSource(items[lastMetaRead].source);
-        wasError = false;
-        return;
-    }
-    if (newState == Phonon::ErrorState)
-    {
-        wasError = true;
-    }
-
-    if (newState != Phonon::StoppedState && newState != Phonon::ErrorState)
-    {
-        return;
-    }
-
-    int index = lastMetaRead;
-    qDebug () << "Reading meta info of " << metaInformationResolver->currentSource().fileName() << " => " << index;
-
-    QMap<QString, QString> metaData = metaInformationResolver->metaData();
-
-
-    if (index >= 0 && newState != Phonon::ErrorState)
-    {
-        items[index].artist = metaData.value("ARTIST");
-        items[index].title = metaData.value("TITLE");
-        items[index].album = metaData.value("ALBUM");
-        qDebug () << "Info is: " << items[index].artist << " - " << items[index].title;
-        if (metaData.isEmpty())
-            qDebug () << "Detected to be empty: " << items[index].uri;
-        else
-            items[index].playable = true;
-        emit itemUpdated (index);
-    }
-    if (index >= 0 && items.size () > index + 1)
-    {
-        metaInformationResolver->setCurrentSource(items[index + 1].source);
-        lastMetaRead = index + 1;
-    }
-}
-
-void PlaylistManager::savePlaylist(const QString& filenam)
-{
-    QString filename = filenam;
-    if (filename.isEmpty())
-        return;
-    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)
-        {
-            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 (...)
-    {
-//        QMessageBox::critical(this, "Write error", "Could not write playlist file", QMessageBox::Ok);
-    }
-}
-
-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);
-        lastMetaRead = 0;
-    }
-    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.size () > index)
-//    if (!items.isEmpty())
-    {
-        metaInformationResolver->setCurrentSource(items.at(index).source);
-        lastMetaRead = index;
-        emit playlistChanged (index);
-    }
-}
-
-void PlaylistManager::appendPlaylist(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");
-    foreach (QString l, lines)
-    {
-        if (l.isEmpty() || (!QFileInfo (l).exists() && (l.indexOf("http") != 0)))
-        {
-            continue;
-        }
-        qDebug () << "Load " << l;
-        items.append(PlaylistItem (l));
-    }
-}
-
-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();
-    emit playlistChanged(0);
-/*    while (musicTable->rowCount())
-        musicTable->removeRow(0);
-    mediaObject->clear();*/
-}
-
-QStringList PlaylistManager::playlistStrings() const
-{
-    QStringList ret;
-    for (int i = 0; i < items.size (); ++i)
-        ret << items[i].uri;
-    qDebug () << "Returning playlist " << ret << " SIZE: " << items.size ();
-    return ret;
-}
-
-void PlaylistManager::removeItem(int i)
-{
-    items.removeAt (i);
-    emit itemRemoved(i);
-}
-
-
-bool PlaylistManager::fileSupported (const QString& fname) const
-{
-    QString ext = fname.right(3).toLower();
-    foreach (QString e, allowedExtensions)
-    {
-        if (ext == e)
-            return true;
-    }
-
-    return false;
-}
-
-bool PlaylistManager::moveItemUp (int i)
-{
-    if (i)
-    {
-        PlaylistItem tmp = items[i - 1];
-        items[i - 1] = items[i];
-        items[i] = tmp;
-        return true;
-//        emit playlistChanged(i - 1);
-    }
-    return false;
-}
-
-bool PlaylistManager::moveItemDown (int i)
-{
-    if (i < items.size () - 1)
-    {
-        PlaylistItem tmp = items[i + 1];
-        items[i + 1] = items[i];
-        items[i] = tmp;
-        return true;
-//        emit playlistChanged(i - 1);
-    }
-    return false;
-}
diff --git a/playlistmanager.h b/playlistmanager.h
deleted file mode 100644 (file)
index d1bbaba..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef PLAYLISTMANAGER_H
-#define PLAYLISTMANAGER_H
-
-#include <QWidget>
-#include <phonon/mediaobject.h>
-#include <phonon/backendcapabilities.h>
-
-
-
-struct PlaylistItem
-{
-    Phonon::MediaSource source;
-    QString uri;
-    bool playable;
-    bool localFile;
-    QString title;
-    QString artist;
-    QString album;
-    PlaylistItem (const QString& uri) : source (Phonon::MediaSource (uri)), uri (uri), playable (false), localFile (false) {  }
-    bool operator ==(const Phonon::MediaSource& s) const { return source == s; }
-};
-
-class PlaylistManager : public QObject
-{
-    Q_OBJECT
-public:
-    PlaylistManager(QWidget* parent);
-    void addStringList (const QStringList&);
-    void parseAndAddFolder (const QString& dir, bool recursive);
-    void removeItem (int i);
-
-    QStringList playlistStrings () const;
-    int size () const { return items.size (); }
-    int indexOf (const Phonon::MediaSource& s) const;
-    const Phonon::MediaSource& at (int i) { return items[i].source; }
-    const PlaylistItem& getItem (int i) const { return items[i]; }
-    bool moveItemUp (int i);
-    bool moveItemDown (int i);
-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 itemRemoved (int i);
-    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:
-    bool fileSupported (const QString& fname) const;
-
-    Phonon::MediaObject *metaInformationResolver;
-    QList<PlaylistItem> items;
-    QWidget* parentWidget;
-    int lastMetaRead;
-};
-
-#endif // PLAYLISTMANAGER_H
index 13eaa0f..e39cc6a 100644 (file)
@@ -1,73 +1,8 @@
-#-------------------------------------------------
-#
-# Project created by QtCreator 2010-07-15T14:44:54
-#
-#-------------------------------------------------
-
-QT       += core gui phonon
-
-TARGET = tomamp
-TEMPLATE = app
-
-
-SOURCES += main.cpp\
-        mainwindow.cpp \
-    playlistmanager.cpp \
-    optiondialog.cpp
-
-HEADERS  += mainwindow.h \
-    playlistmanager.h \
-    optiondialog.h
-
-FORMS    +=
-
-CONFIG += mobility
-MOBILITY = 
-
-symbian {
-    TARGET.UID3 = 0xe3107f4b
-    # TARGET.CAPABILITY += 
-    TARGET.EPOCSTACKSIZE = 0x14000
-    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
+QMAKEVERSION = $$[QMAKE_VERSION]
+ISQT4 = $$find(QMAKEVERSION, ^[2-9])
+isEmpty( ISQT4 ) {
+error("Use the qmake include with Qt4.4 or greater, on Debian that is qmake-qt4");
 }
+TEMPLATE = subdirs
+SUBDIRS  = tomamp
 
-RESOURCES += \
-    ampres.qrc
-
-OTHER_FILES += \
-    bugs.txt \
-    README
-
-unix {
-    # VARIABLES
-    isEmpty(PREFIX):PREFIX = /usr #/local ?
-    BINDIR = $$PREFIX/bin
-    DATADIR = $$PREFIX/share
-    DEFINES += DATADIR=\"$$DATADIR\" \
-        PKGDATADIR=\"$$PKGDATADIR\"
-
-    contains(QT_CONFIG, hildon):{
-          DEFINES += CHIMGDIR=\'\"$$DATADIR/$${TARGET}\"\'
-    }
-    # MAKE INSTALL
-    INSTALLS += target \
-        imagery \
-        desktop \
-        iconxpm \
-        icon26 \
-        icon40 \
-        icon64
-    target.path = $$BINDIR
-    imagery.path = $$DATADIR/$${TARGET}/images
-    imagery.files += ../src/images/*png
-    desktop.path = $$DATADIR/applications/hildon
-    desktop.files += $${TARGET}.desktop
-    iconxpm.path = $$DATADIR/pixmap
-    iconxpm.files += ../data/maemo/$${TARGET}.xpm
-    icon26.path = $$DATADIR/icons/hicolor/26x26/apps
-    icon26.files += ../data/26x26/Tomamp.png
-    icon40.path = $$DATADIR/icons/hicolor/40x40/apps
-    icon40.files += ../data/40x40/Tomamp.png
-    icon64.path = $$DATADIR/icons/hicolor/64x64/apps
-    icon64.files += ../data/64x64/Tomamp.png
-}
diff --git a/tomamp/README b/tomamp/README
new file mode 100644 (file)
index 0000000..9ef4f0b
--- /dev/null
@@ -0,0 +1,7 @@
+TomAmp v0.1
+(c) 2010 Tamas Marki <tmarki@gmail.com>
+
+TomAmp is a simple playlist-based audio player written in Qt, designed for Maemo.
+
+
+The project is released under the LGPL license. See http://www.gnu.org/licenses/lgpl.html
diff --git a/tomamp/ampres.qrc b/tomamp/ampres.qrc
new file mode 100644 (file)
index 0000000..1673f53
--- /dev/null
@@ -0,0 +1,15 @@
+<RCC>
+    <qresource prefix="/images">
+        <file alias="volume">images/audio-volume-high.png</file>
+        <file alias="shuffle">images/shuffle.png</file>
+        <file alias="next">images/Button Next.png</file>
+        <file alias="pause">images/Button Pause.png</file>
+        <file alias="play">images/Button Play.png</file>
+        <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>
diff --git a/tomamp/bugs.txt b/tomamp/bugs.txt
new file mode 100644 (file)
index 0000000..8001ce8
--- /dev/null
@@ -0,0 +1,13 @@
+- remember folder position when adding songs (takes time as adding a song and going one folder up for next song jumps to top of folder)
+- when saving a playlist, the default path seems invalid, so playlist doesn's save, and no error given
+- for some reasom, one folder shows 0 files, but filled with mp3 files (?)
+- quit while reading tags causes crash
+
+Fixed:
++ context menu event outside of musicTable causes crash
++ cancel add folder, add url causes crash
++ doesn't remember add folder folder
++ adding some files can cause a crash ("Blessing, Compassion")
++ bold-italic highlight does not move on normal track switch (when one ends and the next starts)
++ quick next-next while playing stops playback
++ meta info display mismatch (title duplication, some files receive some other file's meta info instead of their ("reality")) (might be related to previous)
diff --git a/tomamp/images/Button Next.png b/tomamp/images/Button Next.png
new file mode 100644 (file)
index 0000000..3e18aad
Binary files /dev/null and b/tomamp/images/Button Next.png differ
diff --git a/tomamp/images/Button Pause.png b/tomamp/images/Button Pause.png
new file mode 100644 (file)
index 0000000..76ba422
Binary files /dev/null and b/tomamp/images/Button Pause.png differ
diff --git a/tomamp/images/Button Play.png b/tomamp/images/Button Play.png
new file mode 100644 (file)
index 0000000..de1a5f3
Binary files /dev/null and b/tomamp/images/Button Play.png differ
diff --git a/tomamp/images/Button Previous.png b/tomamp/images/Button Previous.png
new file mode 100644 (file)
index 0000000..dcaad8d
Binary files /dev/null and b/tomamp/images/Button Previous.png differ
diff --git a/tomamp/images/Button Reload Active.png b/tomamp/images/Button Reload Active.png
new file mode 100644 (file)
index 0000000..5f983dd
Binary files /dev/null and b/tomamp/images/Button Reload Active.png differ
diff --git a/tomamp/images/Button Reload.png b/tomamp/images/Button Reload.png
new file mode 100644 (file)
index 0000000..4d98b97
Binary files /dev/null and b/tomamp/images/Button Reload.png differ
diff --git a/tomamp/images/Button Stop.png b/tomamp/images/Button Stop.png
new file mode 100644 (file)
index 0000000..2415154
Binary files /dev/null and b/tomamp/images/Button Stop.png differ
diff --git a/tomamp/images/Tomamp.png b/tomamp/images/Tomamp.png
new file mode 100644 (file)
index 0000000..5a92bc5
Binary files /dev/null and b/tomamp/images/Tomamp.png differ
diff --git a/tomamp/images/audio-volume-high.png b/tomamp/images/audio-volume-high.png
new file mode 100644 (file)
index 0000000..70ae43a
Binary files /dev/null and b/tomamp/images/audio-volume-high.png differ
diff --git a/tomamp/images/shuffle Active.png b/tomamp/images/shuffle Active.png
new file mode 100644 (file)
index 0000000..996ae97
Binary files /dev/null and b/tomamp/images/shuffle Active.png differ
diff --git a/tomamp/images/shuffle.png b/tomamp/images/shuffle.png
new file mode 100644 (file)
index 0000000..3ce441a
Binary files /dev/null and b/tomamp/images/shuffle.png differ
diff --git a/tomamp/main.cpp b/tomamp/main.cpp
new file mode 100644 (file)
index 0000000..29dd3e6
--- /dev/null
@@ -0,0 +1,16 @@
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    a.setApplicationName("tomamp");
+    MainWindow w;
+#if defined(Q_WS_S60)
+    w.showMaximized();
+#else
+    w.show();
+#endif
+
+    return a.exec();
+}
diff --git a/tomamp/mainwindow.cpp b/tomamp/mainwindow.cpp
new file mode 100644 (file)
index 0000000..a3f1bde
--- /dev/null
@@ -0,0 +1,865 @@
+#include <QtGui>
+#include <QtDebug>
+#include <QInputDialog>
+
+#include "mainwindow.h"
+#include "time.h"
+
+//#define AVOID_INPUT_DIALOG 0
+
+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);
+
+    mediaObject->setTickInterval(1000);
+    connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
+    connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
+        this, SLOT(stateChanged(Phonon::State,Phonon::State)));
+    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
+        this, SLOT(sourceChanged(Phonon::MediaSource)));
+    connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
+    connect (&plman, SIGNAL (playlistChanged (int)), this, SLOT (playlistChanged(int)));
+    connect (&plman, SIGNAL (itemUpdated(int)), this, SLOT (itemUpdated (int)));
+    connect (&plman, SIGNAL (itemRemoved(int)), this, SLOT (itemRemoved (int)));
+
+    Phonon::createPath(mediaObject, audioOutput);
+
+    qsrand (time (NULL));
+    repeat = settings.value("repeat", false).toBool();
+    shuffle = settings.value("shuffle", false).toBool();
+    setupShuffleList();
+    setupActions();
+    setupMenus();
+    setupUi();
+    show ();
+    timeLcd->display("00:00:00");
+    plman.addStringList(settings.value("lastPlaylist").toStringList());
+    setupShuffleList();
+    int curind = settings.value("currentIndex", -1).toInt ();
+    if (curind >= 0)
+        setItem (curind, false);
+    audioOutput->setVolume(settings.value("volume", .5).toReal());
+    QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
+}
+
+MainWindow::~MainWindow()
+{
+    settings.setValue("shuffle", shuffle);
+    settings.setValue("repeat", repeat);
+    settings.setValue("lastPlaylist", plman.playlistStrings());
+    settings.setValue("volume", audioOutput->volume());
+    settings.setValue("currentIndex", plman.indexOf(mediaObject->currentSource()));
+    for (int i = 0; i < musicTable->columnCount(); ++i)
+    {
+        QString lab = QString ("colWidth_%1").arg (i);
+        settings.setValue(lab, musicTable->columnWidth(i));
+    }
+}
+
+void MainWindow::addFiles()
+{
+    QString folder = settings.value("LastFolder").toString();
+    if (folder.isEmpty())
+        folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
+    QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Files To Add"),
+                    folder, "Music files (*.mp3 *.ogg *.wav *.flac);;Playlists (*.m3u *.pls)");
+
+    if (files.isEmpty())
+        return;
+
+    QString dir = QFileInfo (files[0]).absoluteDir().absolutePath();
+    settings.setValue("LastFolder", dir);
+    QStringList toadd;
+    foreach (QString string, files)
+    {
+        if (string.toLower().endsWith(".pls") || string.toLower().endsWith(".m3u"))
+            plman.addPlaylist(string);
+        else
+            toadd.append (string);
+    }
+    plman.addStringList(toadd);
+}
+
+void MainWindow::addFolder()
+{
+    QString folder = settings.value("LastFolder").toString();
+    if (folder.isEmpty())
+        folder = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
+    QString dir = QFileDialog::getExistingDirectory(this,
+            tr("Select Directory To Add"),
+            folder);
+
+    if (dir.isEmpty())
+        return;
+
+    settings.setValue("LastFolder", dir);
+
+    QStringList filters;
+    QStringList files = QDir (dir).entryList(filters, QDir::AllDirs);
+    files.removeAll(".");
+    files.removeAll("..");
+    bool recursive = false;
+    if (files.size())
+        recursive = QMessageBox::question(this, "Add all folders", "Subfolders have been detected, add everything?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
+    plman.parseAndAddFolder(dir, recursive);
+}
+
+
+void MainWindow::addUrl()
+{
+#ifdef AVOID_INPUT_DIALOG
+    QString url = "http://war.str3am.com:7970";
+#else
+    QString url = QInputDialog::getText(this, "Get URL", "Please type in the stream URL");
+#endif
+    if (url.isEmpty() || !url.toLower().startsWith("http"))
+        return;
+    QStringList toadd;
+    toadd << url;
+    plman.addStringList(toadd);
+}
+
+
+void MainWindow::about()
+{
+    QMessageBox::information(this, tr("About TomAmp v0.1"),
+        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/"));
+}
+
+void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
+{
+    switch (newState)
+    {
+        case Phonon::ErrorState:
+            if (mediaObject->errorType() == Phonon::FatalError)
+            {
+//                QMessageBox::warning(this, tr("Fatal Error"),
+//                mediaObject->errorString() + mediaObject->currentSource().fileName() + ", " + mediaObject->currentSource().url().toString());
+            }
+            else
+            {
+//                QMessageBox::warning(this, tr("Error"),
+//                mediaObject->errorString());
+            }
+            next ();
+            break;
+        case Phonon::PlayingState:
+            setWindowTitle(mediaObject->metaData().value("TITLE") + " - TomAmp");
+            pauseAction->setVisible(true);
+            playAction->setVisible (false);
+            playAction->setEnabled(false);
+            pauseAction->setEnabled(true);
+            stopAction->setEnabled(true);
+            //lastPlayed = plman.indexOf(mediaObject->currentSource());
+            break;
+        case Phonon::StoppedState:
+            setWindowTitle("TomAmp");
+            stopAction->setEnabled(false);
+            playAction->setEnabled(true);
+            pauseAction->setVisible(false);
+            playAction->setVisible(true);
+            pauseAction->setEnabled(false);
+            timeLcd->display("00:00:00");
+            unhighlightRow(plman.indexOf(mediaObject->currentSource()));
+            break;
+        case Phonon::PausedState:
+            pauseAction->setEnabled(false);
+            stopAction->setEnabled(true);
+            pauseAction->setVisible(false);
+            playAction->setVisible(true);
+            playAction->setEnabled(true);
+            break;
+        case Phonon::BufferingState:
+            break;
+        default:
+        ;
+    }
+}
+
+void MainWindow::next()
+{
+    bool wasPlaying = isPlaying;
+    if (mediaObject->state () == Phonon::ErrorState)
+        wasPlaying = true;
+    int index = plman.indexOf(mediaObject->currentSource());
+    if (shuffle)
+    {
+        index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
+        while (index < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
+        {
+            index += 1;
+        }
+        if (index < shuffleList.size ())
+        {
+            setItem (index, wasPlaying);
+        }
+        else if (repeat)
+        {
+            index = 0;
+            while ((index) < shuffleList.size () && !plman.getItem(shuffleList[index]).playable)
+            {
+                index += 1;
+            }
+            setItem (index, wasPlaying);
+        }
+    }
+    else
+    {
+        index++;
+        while ((index) < plman.size () && !plman.getItem(index).playable)
+        {
+            index += 1;
+        }
+        if (index < plman.size())
+        {
+            setItem (index, wasPlaying);
+        }
+        else if (repeat)
+        {
+            index = 0;
+            while ((index) < plman.size () && !plman.getItem(index).playable)
+            {
+                index += 1;
+            }
+            setItem (index, wasPlaying);
+        }
+    }
+}
+
+void MainWindow::setItem(int i, bool doplay)
+{
+    if (i < plman.size() && i >= 0)
+    {
+        if (lastPlayed >= 0)
+            unhighlightRow(lastPlayed);
+        if (shuffle)
+        {
+            mediaObject->setCurrentSource(plman.at (shuffleList[i]));
+        }
+        else
+        {
+            mediaObject->setCurrentSource(plman.at(i));
+        }
+    }
+    if (doplay && mediaObject->currentSource().type() != Phonon::MediaSource::Invalid)
+    {
+        play();
+    }
+    else
+        stop ();
+}
+
+void MainWindow::previous()
+{
+    bool wasPlaying = isPlaying;//(mediaObject->state () == Phonon::PlayingState);
+    if (mediaObject->state () == Phonon::ErrorState)
+        wasPlaying = true;
+    int index = plman.indexOf(mediaObject->currentSource());
+    if (shuffle)
+    {
+        index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) - 1;
+        while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
+        {
+            index--;
+        }
+        if (index >= 0)
+        {
+            setItem (index, wasPlaying);
+        }
+        else if (repeat)
+        {
+            index = plman.size () - 1;
+            while (index >= 0 && !plman.getItem(shuffleList[index]).playable)
+            {
+                index--;
+            }
+            setItem (index, wasPlaying);
+        }
+/*        if (index < 0)
+            wasPlaying = false;*/
+
+    }
+    else
+    {
+        index--;
+        while ((index) >= 0 && !plman.getItem(index).playable)
+        {
+            index--;
+        }
+        if (index >= 0)
+        {
+            setItem (index, wasPlaying);
+        }
+        else if (repeat)
+        {
+            index = plman.size() - 1;
+            while ((index) >= 0 && !plman.getItem(index).playable)
+            {
+                index--;
+            }
+            setItem (index, wasPlaying);
+        }
+    }
+}
+
+void MainWindow::highlightRow (int i)
+{
+    for (int j = 0; j < 3; ++j)
+    {
+        QTableWidgetItem* item = musicTable->item(i, j);
+        if (item)
+        {
+            QFont font = item->font();
+            font.setBold(true);
+            font.setItalic(true);
+            item->setFont(font);
+        }
+    }
+}
+
+void MainWindow::unhighlightRow (int i)
+{
+    for (int j = 0; j < 3; ++j)
+    {
+        QTableWidgetItem* item = musicTable->item(i, j);
+        if (item)
+        {
+            QFont font = item->font();
+            font.setBold(false);
+            font.setItalic(false);
+            item->setFont(font);
+        }
+    }
+}
+
+
+void MainWindow::tick(qint64 time)
+{
+    QTime displayTime((time / 3600000), (time / 60000) % 60, (time / 1000) % 60);
+
+    timeLcd->display(displayTime.toString("HH:mm:ss"));
+}
+
+void MainWindow::tableClicked(int row, int /* column */)
+{
+//    bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
+
+/*    mediaObject->stop();
+    mediaObject->clearQueue();*/
+
+    if (row >= plman.size())
+        return;
+
+    int index = row;
+    while (index < shuffleList.size () && !plman.getItem(index).playable)
+    {
+        index += 1;
+    }
+    if (plman.size() > index)
+    {
+        if (shuffle)
+            index = shuffleList.indexOf(index);
+        setItem (index, true);
+//        mediaObject->play();
+    }
+    else
+    {
+        index = 0;
+        while (index < plman.size () && !plman.getItem(index).playable)
+        {
+            index += 1;
+        }
+        if (plman.size() > index)
+        {
+            if (shuffle)
+                index = shuffleList.indexOf(index);
+            setItem (index, true);
+//            mediaObject->play();
+        }
+    }
+
+}
+
+void MainWindow::sourceChanged(const Phonon::MediaSource &source)
+{
+    int ind = plman.indexOf(source);
+    highlightRow(ind);
+    unhighlightRow(lastPlayed);
+    lastPlayed = ind;
+    musicTable->selectRow(ind);
+    timeLcd->display("00:00:00");
+}
+
+
+void MainWindow::aboutToFinish()
+{
+    int index = plman.indexOf(mediaObject->currentSource()) + 1;
+    if (shuffle)
+    {
+        index = shuffleList.indexOf(plman.indexOf(mediaObject->currentSource())) + 1;
+        if (index < shuffleList.size ())
+        {
+            mediaObject->enqueue(plman.at (shuffleList[index]));
+        }
+        else if (repeat)
+        {
+            mediaObject->enqueue(plman.at (shuffleList[0]));
+        }
+
+    }
+    else
+    {
+        if (plman.size() > index)
+        {
+            mediaObject->enqueue(plman.at(index));
+        }
+        else if (repeat)
+        {
+            mediaObject->enqueue(plman.at(0));
+        }
+    }
+}
+
+void MainWindow::finished()
+{
+}
+
+void MainWindow::setupActions()
+{
+    playAction = new QAction(QIcon (QPixmap (":images/play")), "", this);
+    playAction->setShortcut(tr("Crl+P"));
+    playAction->setDisabled(true);
+    pauseAction = new QAction(QIcon (QPixmap (":images/pause")), "", this);
+    pauseAction->setShortcut(tr("Ctrl+A"));
+    pauseAction->setDisabled(true);
+    pauseAction->setVisible(false);
+    stopAction = new QAction(QIcon (QPixmap (":images/stop")), "", this);
+    stopAction->setShortcut(tr("Ctrl+S"));
+    stopAction->setDisabled(true);
+    nextAction = new QAction(QIcon (QPixmap (":images/next")), "", this);
+    nextAction->setShortcut(tr("Ctrl+N"));
+    previousAction = new QAction(QIcon (QPixmap (":images/previous")), "", this);
+    previousAction->setShortcut(tr("Ctrl+R"));
+    if (repeat)
+        repeatAction = new QAction(QIcon (QPixmap (":images/repeatActive")), "", this);
+    else
+        repeatAction = new QAction(QIcon (QPixmap (":images/repeat")), "", this);
+    repeatAction->setCheckable(true);
+    repeatAction->setChecked(repeat);
+    repeatAction->setShortcut(tr("Ctrl+I"));
+    if (shuffle)
+        shuffleAction = new QAction(QIcon (QPixmap (":images/shuffleActive")), "", this);
+    else
+        shuffleAction = new QAction(QIcon (QPixmap (":images/shuffle")), "", this);
+    shuffleAction->setCheckable(true);
+    shuffleAction->setChecked(shuffle);
+    shuffleAction->setShortcut(tr("Ctrl+H"));
+    volumeAction = new QAction(QIcon (QPixmap (":images/volume")), "", this);
+    volumeAction->setCheckable(true);
+    volumeAction->setShortcut(tr("Ctrl+V"));
+    addFilesAction = new QAction(tr("Add &File"), this);
+    addFilesAction->setShortcut(tr("Ctrl+F"));
+    addFoldersAction = new QAction(tr("Add F&older"), this);
+    addFoldersAction->setShortcut(tr("Ctrl+O"));
+    addUrlAction = new QAction(tr("Add &Url"), this);
+    addUrlAction->setShortcut(tr("Ctrl+U"));
+    savePlaylistAction = new QAction (tr("Sa&ve Playlist"), this);
+    savePlaylistAction->setShortcut(tr ("Ctrl+V"));
+    loadPlaylistAction = new QAction (tr("&Load Playlist"), this);
+    loadPlaylistAction->setShortcut(tr("Ctrl+L"));
+    clearPlaylistAction = new QAction (tr("&Clear Playlist"), this);
+    clearPlaylistAction->setShortcut(tr("Ctrl+C"));
+    exitAction = new QAction(tr("E&xit"), this);
+    exitAction->setShortcut(tr("Ctrl+X"));
+    aboutAction = new QAction(tr("A&bout"), this);
+    aboutAction->setShortcut(tr("Ctrl+B"));
+    aboutQtAction = new QAction(tr("About &Qt"), this);
+    aboutQtAction->setShortcut(tr("Ctrl+Q"));
+/*    removeSelected = new QAction (tr("&Delete from playlist"));
+    removeSelected->setShortcut(tr ("Ctrl+D"));*/
+
+    connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
+    connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
+    connect(stopAction, SIGNAL(triggered()), this, SLOT(stop()));
+    connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
+    connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
+    connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
+
+    connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
+    connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
+    connect(addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
+    connect (savePlaylistAction, SIGNAL (triggered()), this, SLOT (savePlaylist()));
+    connect (loadPlaylistAction, SIGNAL (triggered()), this, SLOT (loadPlaylist()));
+    connect (clearPlaylistAction, SIGNAL (triggered()), &plman, SLOT (clearPlaylist()));
+    connect (nextAction, SIGNAL(triggered()), this, SLOT(next()));
+    connect (previousAction, SIGNAL(triggered()), this, SLOT(previous()));
+    connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
+    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
+    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+//    connect (removeSelected, SIGNAL (triggered()), this, SLOT (removeSelectedItem()));
+}
+
+void MainWindow::removeSelectedItem()
+{
+    if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
+        return;
+    int row = musicTable->currentRow();
+    if (row >= 0)
+        plman.removeItem(row);
+}
+
+void MainWindow::removeAllButSelectedItem()
+{
+    if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove all other items?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
+        return;
+    int row = musicTable->currentRow();
+    if (row >= 0)
+    {
+        QString uri = plman.getItem(row).uri;
+        QStringList lst;
+        lst << uri;
+        plman.clearPlaylist();
+        plman.addStringList(lst);
+    }
+}
+
+void MainWindow::repeatToggle ()
+{
+    repeat = !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 ()
+{
+    volumeSlider->setVisible(volumeAction->isChecked());
+}
+
+void MainWindow::play()
+{
+    mediaObject->play();
+    lastPlayed = plman.indexOf(mediaObject->currentSource());
+    highlightRow(lastPlayed);
+    isPlaying = true;
+}
+
+void MainWindow::stop()
+{
+    mediaObject->stop();
+    isPlaying = false;
+}
+
+
+void MainWindow::setupMenus()
+{
+    QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+    fileMenu->addAction(addFilesAction);
+    fileMenu->addAction(addFoldersAction);
+    fileMenu->addAction(addUrlAction);
+    fileMenu->addSeparator();
+    fileMenu->addAction(savePlaylistAction);
+    fileMenu->addAction(loadPlaylistAction);
+    fileMenu->addAction(clearPlaylistAction);
+//    fileMenu->addAction(exitAction);
+
+    QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
+    aboutMenu->addAction(aboutAction);
+    aboutMenu->addAction(aboutQtAction);
+}
+
+void MainWindow::setupUi()
+{
+    QToolBar *bar = new QToolBar;
+
+    bar->setOrientation(Qt::Vertical);
+    bar->setStyleSheet("padding:7px");
+    //bar->addAction(volumeAction);
+
+    seekSlider = new Phonon::SeekSlider(this);
+    seekSlider->setMediaObject(mediaObject);
+
+    volumeSlider = new Phonon::VolumeSlider(this);
+    volumeSlider->setAudioOutput(audioOutput);
+    volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
+    volumeSlider->setOrientation(Qt::Horizontal);
+    volumeSlider->setMuteVisible(false);
+//    volumeAddedAction = bar->addWidget(volumeSlider);
+//    volumeAddedAction->setVisible(false);
+    bar->addAction(playAction);
+    bar->addAction(pauseAction);
+    bar->addAction(stopAction);
+    bar->addAction(repeatAction);
+    bar->addAction(shuffleAction);
+    bar->addAction(nextAction);
+    bar->addAction(previousAction);
+
+    contextMenu = new QMenu (this);
+    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()));
+
+
+    timeLcd = new QLCDNumber;
+
+    QStringList headers;
+    headers << tr("Artist") << tr("Title") << tr("Album") << "Controls";
+
+    musicTable = new QTableWidget(0, 4);
+    musicTable->setHorizontalHeaderLabels(headers);
+    musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
+    musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+    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;
+    QToolBar* bar2 = new QToolBar;
+    bar2->addAction(volumeAction);
+    seekerLayout->addWidget(bar2);
+    seekerLayout->addWidget(volumeSlider);
+    seekerLayout->addWidget(seekSlider);
+    seekerLayout->addWidget(timeLcd);
+
+    QVBoxLayout *playbackLayout = new QVBoxLayout;
+    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);
+
+    QWidget *widget = new QWidget;
+    widget->setLayout(mainLayout);
+
+    setCentralWidget(widget);
+    setWindowTitle("TomAmp");
+}
+
+void MainWindow::cellClicked(int /*row*/, int)
+{
+}
+
+void MainWindow::contextMenuEvent (QContextMenuEvent*e)
+{
+    if (!childAt (e->pos()))
+        return;
+    if (childAt (e->pos())->parentWidget() != musicTable)
+        return;
+    contextMenu->popup(e->globalPos());
+}
+
+
+void MainWindow::setupShuffleList()
+{
+    QList<int> tmp;
+    int index = plman.indexOf(mediaObject->currentSource());
+    if (index < 0)
+        index = 0;
+    for (int i = 0; i < plman.size(); ++i)
+    {
+        if ((i != index))
+            tmp.append(i);
+    }
+    shuffleList.clear();
+    shuffleList.append (index);
+    while (tmp.size ())
+    {
+        int ind = qrand () % tmp.size();
+        shuffleList.append(tmp[ind]);
+        tmp.removeAt(ind);
+    }
+}
+
+void MainWindow::savePlaylist ()
+{
+    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 *.pls");
+    if (filename.isEmpty())
+        return;
+    plman.loadPlaylist (filename);
+}
+
+void MainWindow::playlistChanged(int from)
+{
+    while (musicTable->rowCount() > from)
+    {
+        musicTable->removeRow(musicTable->rowCount () - 1);
+    }
+    int firstGood = -1;
+    for (int i = from; i < plman.size (); ++i)
+    {
+        if (firstGood < 0 && plman.getItem (i).playable)
+            firstGood = i;
+        int currentRow = musicTable->rowCount();
+        musicTable->insertRow(currentRow);
+        setRowFromItem (currentRow, plman.getItem(i));
+    }
+/*    if (plman.indexOf(mediaObject->currentSource()) < 0)
+    {
+        setItem (firstGood, false);
+    }*/
+    setupShuffleList();
+}
+
+void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
+{
+    if (row >= musicTable->rowCount())
+        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);
+    }
+    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;
+    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);
+        musicTable->selectRow(i - 1);
+    }
+}
+
+void MainWindow::buttonDown()
+{
+    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);
+        musicTable->selectRow(i + 1);
+    }
+}
+
+void MainWindow::buttonDel()
+{
+    int i = sender()->parent()->property("row").toInt();
+    qDebug () << "Presses del on " << i;
+    if (i < plman.size())
+    {
+        plman.removeItem(i);
+    }
+}
+
+void MainWindow::itemUpdated(int index)
+{
+    if (plman.indexOf(mediaObject->currentSource()) < 0 && plman.getItem (index).playable)
+    {
+        setItem (index, false);
+    }
+    setRowFromItem (index, plman.getItem(index));
+    if (plman.indexOf(mediaObject->currentSource()) == index)
+    {
+        if (shuffle) index = shuffleList.indexOf(index);
+        setItem (index, false);
+    }
+}
+
+void MainWindow::itemRemoved (int i)
+{
+    musicTable->removeRow(i);
+    for (int j = i ? (i - 1) : 0; j < musicTable->rowCount(); ++j)
+    {
+        if (musicTable->cellWidget(j, 3))
+            musicTable->cellWidget(j, 3)->setProperty("row", j);
+    }
+}
diff --git a/tomamp/mainwindow.h b/tomamp/mainwindow.h
new file mode 100644 (file)
index 0000000..ce4edca
--- /dev/null
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QSettings>
+#include <phonon/audiooutput.h>
+#include <phonon/seekslider.h>
+#include <phonon/mediaobject.h>
+#include <phonon/volumeslider.h>
+#include <phonon/backendcapabilities.h>
+#include <QList>
+#include "playlistmanager.h"
+
+class QAction;
+class QTableWidget;
+class QLCDNumber;
+
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    MainWindow();
+    ~MainWindow ();
+
+    QSize sizeHint() const
+    {
+        return QSize(800, 480);
+    }
+
+private slots:
+    void addFiles();
+    void addFolder();
+    void addUrl ();
+    void repeatToggle ();
+    void shuffleToggle ();
+    void volumeToggle ();
+    void about();
+    void stateChanged(Phonon::State newState, Phonon::State oldState);
+    void tick(qint64 time);
+    void sourceChanged(const Phonon::MediaSource &source);
+    void aboutToFinish();
+    void finished();
+    void tableClicked(int row, int column);
+    void play();
+    void stop();
+    void next();
+    void previous();
+    void cellClicked(int row, int column);
+    void savePlaylist ();
+    void loadPlaylist ();
+    void playlistChanged (int from);
+    void itemUpdated (int index);
+    void setItem (int ind, bool doplay);
+    void removeSelectedItem ();
+    void removeAllButSelectedItem ();
+    void highlightRow (int i);
+    void unhighlightRow (int i);
+    void buttonUp ();
+    void buttonDown ();
+    void buttonDel ();
+    void itemRemoved (int i);
+
+protected:
+    void contextMenuEvent (QContextMenuEvent*e);
+private:
+    void setupActions();
+    void setupMenus();
+    void setupUi();
+    void setupShuffleList();
+    void setRowFromItem (int row, const PlaylistItem& item);
+
+    Phonon::SeekSlider *seekSlider;
+    Phonon::MediaObject *mediaObject;
+    Phonon::AudioOutput *audioOutput;
+    Phonon::VolumeSlider *volumeSlider;
+
+    PlaylistManager plman;
+
+    QAction *playAction;
+    QAction *pauseAction;
+    QAction *stopAction;
+    QAction *repeatAction;
+    QAction *shuffleAction;
+    QAction *volumeAction;
+    QAction *volumeAddedAction;
+    QAction *nextAction;
+    QAction *previousAction;
+    QAction *addFilesAction;
+    QAction *addFoldersAction;
+    QAction *addUrlAction;
+    QAction *savePlaylistAction;
+    QAction *loadPlaylistAction;
+    QAction *clearPlaylistAction;
+    QAction *exitAction;
+    QAction *aboutAction;
+    QAction *aboutQtAction;
+    QAction *removeSelected;
+    QAction *removeAllButSelected;
+    QMenu   *contextMenu;
+    QToolBar *bar;
+    QLCDNumber *timeLcd;
+    QTableWidget *musicTable;
+    bool        repeat;
+    bool        shuffle;
+    QSettings settings;
+    QList<int>  shuffleList;
+    int lastPlayed;
+    bool isPlaying;
+};
+
+#endif
diff --git a/tomamp/optiondialog.cpp b/tomamp/optiondialog.cpp
new file mode 100644 (file)
index 0000000..ed40032
--- /dev/null
@@ -0,0 +1,6 @@
+#include "optiondialog.h"
+
+OptionDialog::OptionDialog(QWidget *parent) :
+    QDialog(parent)
+{
+}
diff --git a/tomamp/optiondialog.h b/tomamp/optiondialog.h
new file mode 100644 (file)
index 0000000..12d15ce
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef OPTIONDIALOG_H
+#define OPTIONDIALOG_H
+
+#include <QDialog>
+
+class OptionDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit OptionDialog(QWidget *parent = 0);
+
+signals:
+
+public slots:
+
+};
+
+#endif // OPTIONDIALOG_H
diff --git a/tomamp/playlistmanager.cpp b/tomamp/playlistmanager.cpp
new file mode 100644 (file)
index 0000000..61681a2
--- /dev/null
@@ -0,0 +1,349 @@
+#include "playlistmanager.h"
+#include <QDir>
+#include <QUrl>
+#include <QMap>
+
+QStringList allowedExtensions;
+
+
+PlaylistManager::PlaylistManager(QWidget* parent)
+    : parentWidget (parent), lastMetaRead (-1)
+{
+    allowedExtensions << "mp3" << "ogg" << "wav" << "wmv" << "wma";
+//    qDebug () << Phonon::BackendCapabilities::availableMimeTypes();
+    metaInformationResolver = new Phonon::MediaObject(parent);
+    connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
+        this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
+}
+
+int PlaylistManager::indexOf(const Phonon::MediaSource &s) const
+{
+    for (int i = 0; i < items.size(); ++i)
+    {
+        if (items[i].source == s)
+            return i;
+    }
+    return -1;
+}
+
+void PlaylistManager::parseAndAddFolder(const QString &dir, bool recursive)
+{
+    QStringList filters;
+//    filters << "*.mp3";
+
+    QStringList files = QDir (dir).entryList(filters);
+
+    if (files.isEmpty())
+        return;
+
+    qDebug () << "Parsing folder " << dir;
+
+    //settings.setValue("LastFolder", dir);
+    int index = items.size();
+    foreach (QString string, files)
+    {
+        if (string == "."  || string == "..")
+            continue;
+        QString fname = dir + "/" + string;
+        QFileInfo fi (fname);
+        if (fi.isDir())
+        {
+            if (recursive)
+                parseAndAddFolder(fname, true);
+            continue;
+        }
+        if (fileSupported(fname))
+        {
+            qDebug () << "Adding: " << fname;
+            items.append(PlaylistItem (PlaylistItem (fname)));
+        }
+    }
+//    if (!items.isEmpty())
+    if (items.size () > index)
+    {
+        metaInformationResolver->setCurrentSource(items.at(index).source);
+        lastMetaRead = index;
+    }
+    qDebug () << " SIZE: " << items.size ();
+    emit playlistChanged (index);
+}
+
+void PlaylistManager::addStringList(const QStringList& list)
+{
+    int index = items.size();
+    foreach (QString string, list)
+    {
+        if (fileSupported(string) || string.toLower().startsWith("http"))
+        {
+            qDebug () << "Adding " << string;
+            items.append(PlaylistItem (string));
+        }
+    }
+//    if (!items.isEmpty())
+    if (items.size () > index)
+    {
+        metaInformationResolver->setCurrentSource(items.at(index).source);
+        lastMetaRead = index;
+    }
+    emit playlistChanged(index);
+}
+
+void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State oldState)
+{
+    qDebug () << "Meta state now " << newState << " old state " << oldState;
+    // This is an ugly hack, since the metaInformationResolver doesn't properly load the assigned source when it's in the error state
+    // In order to properly read the next file we have to set it as current source again when the resolver entered the stopped state after the error
+    static bool wasError = false;
+    if (wasError && newState == Phonon::StoppedState)
+    {
+        metaInformationResolver->setCurrentSource(items[lastMetaRead].source);
+        wasError = false;
+        return;
+    }
+    if (newState == Phonon::ErrorState)
+    {
+        wasError = true;
+    }
+
+    if (newState != Phonon::StoppedState && newState != Phonon::ErrorState)
+    {
+        return;
+    }
+
+    int index = lastMetaRead;
+    qDebug () << "Reading meta info of " << metaInformationResolver->currentSource().fileName() << " => " << index;
+
+    QMap<QString, QString> metaData = metaInformationResolver->metaData();
+
+
+    if (index >= 0 && newState != Phonon::ErrorState)
+    {
+        items[index].artist = metaData.value("ARTIST");
+        items[index].title = metaData.value("TITLE");
+        items[index].album = metaData.value("ALBUM");
+        qDebug () << "Info is: " << items[index].artist << " - " << items[index].title;
+        if (metaData.isEmpty())
+            qDebug () << "Detected to be empty: " << items[index].uri;
+        else
+            items[index].playable = true;
+        emit itemUpdated (index);
+    }
+    if (index >= 0 && items.size () > index + 1)
+    {
+        metaInformationResolver->setCurrentSource(items[index + 1].source);
+        lastMetaRead = index + 1;
+    }
+}
+
+void PlaylistManager::savePlaylist(const QString& filenam)
+{
+    QString filename = filenam;
+    if (filename.isEmpty())
+        return;
+    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)
+        {
+            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 (...)
+    {
+//        QMessageBox::critical(this, "Write error", "Could not write playlist file", QMessageBox::Ok);
+    }
+}
+
+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);
+        lastMetaRead = 0;
+    }
+    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.size () > index)
+//    if (!items.isEmpty())
+    {
+        metaInformationResolver->setCurrentSource(items.at(index).source);
+        lastMetaRead = index;
+        emit playlistChanged (index);
+    }
+}
+
+void PlaylistManager::appendPlaylist(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");
+    foreach (QString l, lines)
+    {
+        if (l.isEmpty() || (!QFileInfo (l).exists() && (l.indexOf("http") != 0)))
+        {
+            continue;
+        }
+        qDebug () << "Load " << l;
+        items.append(PlaylistItem (l));
+    }
+}
+
+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();
+    emit playlistChanged(0);
+/*    while (musicTable->rowCount())
+        musicTable->removeRow(0);
+    mediaObject->clear();*/
+}
+
+QStringList PlaylistManager::playlistStrings() const
+{
+    QStringList ret;
+    for (int i = 0; i < items.size (); ++i)
+        ret << items[i].uri;
+    qDebug () << "Returning playlist " << ret << " SIZE: " << items.size ();
+    return ret;
+}
+
+void PlaylistManager::removeItem(int i)
+{
+    items.removeAt (i);
+    emit itemRemoved(i);
+}
+
+
+bool PlaylistManager::fileSupported (const QString& fname) const
+{
+    QString ext = fname.right(3).toLower();
+    foreach (QString e, allowedExtensions)
+    {
+        if (ext == e)
+            return true;
+    }
+
+    return false;
+}
+
+bool PlaylistManager::moveItemUp (int i)
+{
+    if (i)
+    {
+        PlaylistItem tmp = items[i - 1];
+        items[i - 1] = items[i];
+        items[i] = tmp;
+        return true;
+//        emit playlistChanged(i - 1);
+    }
+    return false;
+}
+
+bool PlaylistManager::moveItemDown (int i)
+{
+    if (i < items.size () - 1)
+    {
+        PlaylistItem tmp = items[i + 1];
+        items[i + 1] = items[i];
+        items[i] = tmp;
+        return true;
+//        emit playlistChanged(i - 1);
+    }
+    return false;
+}
diff --git a/tomamp/playlistmanager.h b/tomamp/playlistmanager.h
new file mode 100644 (file)
index 0000000..d1bbaba
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef PLAYLISTMANAGER_H
+#define PLAYLISTMANAGER_H
+
+#include <QWidget>
+#include <phonon/mediaobject.h>
+#include <phonon/backendcapabilities.h>
+
+
+
+struct PlaylistItem
+{
+    Phonon::MediaSource source;
+    QString uri;
+    bool playable;
+    bool localFile;
+    QString title;
+    QString artist;
+    QString album;
+    PlaylistItem (const QString& uri) : source (Phonon::MediaSource (uri)), uri (uri), playable (false), localFile (false) {  }
+    bool operator ==(const Phonon::MediaSource& s) const { return source == s; }
+};
+
+class PlaylistManager : public QObject
+{
+    Q_OBJECT
+public:
+    PlaylistManager(QWidget* parent);
+    void addStringList (const QStringList&);
+    void parseAndAddFolder (const QString& dir, bool recursive);
+    void removeItem (int i);
+
+    QStringList playlistStrings () const;
+    int size () const { return items.size (); }
+    int indexOf (const Phonon::MediaSource& s) const;
+    const Phonon::MediaSource& at (int i) { return items[i].source; }
+    const PlaylistItem& getItem (int i) const { return items[i]; }
+    bool moveItemUp (int i);
+    bool moveItemDown (int i);
+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 itemRemoved (int i);
+    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:
+    bool fileSupported (const QString& fname) const;
+
+    Phonon::MediaObject *metaInformationResolver;
+    QList<PlaylistItem> items;
+    QWidget* parentWidget;
+    int lastMetaRead;
+};
+
+#endif // PLAYLISTMANAGER_H
diff --git a/tomamp/tomamp.pro b/tomamp/tomamp.pro
new file mode 100644 (file)
index 0000000..13eaa0f
--- /dev/null
@@ -0,0 +1,73 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-07-15T14:44:54
+#
+#-------------------------------------------------
+
+QT       += core gui phonon
+
+TARGET = tomamp
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+        mainwindow.cpp \
+    playlistmanager.cpp \
+    optiondialog.cpp
+
+HEADERS  += mainwindow.h \
+    playlistmanager.h \
+    optiondialog.h
+
+FORMS    +=
+
+CONFIG += mobility
+MOBILITY = 
+
+symbian {
+    TARGET.UID3 = 0xe3107f4b
+    # TARGET.CAPABILITY += 
+    TARGET.EPOCSTACKSIZE = 0x14000
+    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
+}
+
+RESOURCES += \
+    ampres.qrc
+
+OTHER_FILES += \
+    bugs.txt \
+    README
+
+unix {
+    # VARIABLES
+    isEmpty(PREFIX):PREFIX = /usr #/local ?
+    BINDIR = $$PREFIX/bin
+    DATADIR = $$PREFIX/share
+    DEFINES += DATADIR=\"$$DATADIR\" \
+        PKGDATADIR=\"$$PKGDATADIR\"
+
+    contains(QT_CONFIG, hildon):{
+          DEFINES += CHIMGDIR=\'\"$$DATADIR/$${TARGET}\"\'
+    }
+    # MAKE INSTALL
+    INSTALLS += target \
+        imagery \
+        desktop \
+        iconxpm \
+        icon26 \
+        icon40 \
+        icon64
+    target.path = $$BINDIR
+    imagery.path = $$DATADIR/$${TARGET}/images
+    imagery.files += ../src/images/*png
+    desktop.path = $$DATADIR/applications/hildon
+    desktop.files += $${TARGET}.desktop
+    iconxpm.path = $$DATADIR/pixmap
+    iconxpm.files += ../data/maemo/$${TARGET}.xpm
+    icon26.path = $$DATADIR/icons/hicolor/26x26/apps
+    icon26.files += ../data/26x26/Tomamp.png
+    icon40.path = $$DATADIR/icons/hicolor/40x40/apps
+    icon40.files += ../data/40x40/Tomamp.png
+    icon64.path = $$DATADIR/icons/hicolor/64x64/apps
+    icon64.files += ../data/64x64/Tomamp.png
+}