First commit woohoo
authorTamas <tmarki@gmail.com>
Thu, 15 Jul 2010 19:47:59 +0000 (21:47 +0200)
committertamas <tamas@brutus.(none)>
Thu, 15 Jul 2010 19:47:59 +0000 (21:47 +0200)
main.cpp [new file with mode: 0644]
mainwindow.cpp [new file with mode: 0644]
mainwindow.h [new file with mode: 0644]
mainwindow.ui [new file with mode: 0644]
playlist.cpp [new file with mode: 0644]
playlist.h [new file with mode: 0644]
tomamp.pro [new file with mode: 0644]

diff --git a/main.cpp b/main.cpp
new file mode 100644 (file)
index 0000000..29dd3e6
--- /dev/null
+++ b/main.cpp
@@ -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/mainwindow.cpp b/mainwindow.cpp
new file mode 100644 (file)
index 0000000..07a208a
--- /dev/null
@@ -0,0 +1,396 @@
+/****************************************************************************
+**
+** 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$
+**
+***************************************************************************/
+
+#include <QtGui>
+#include <QtDebug>
+
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+    : settings (tr ("TomAmp"), "TomAmp")
+{
+    audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
+    mediaObject = new Phonon::MediaObject(this);
+    metaInformationResolver = 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(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
+    this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
+    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
+    this, SLOT(sourceChanged(Phonon::MediaSource)));
+    connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
+
+    Phonon::createPath(mediaObject, audioOutput);
+
+    setupActions();
+    setupMenus();
+    setupUi();
+    timeLcd->display("00:00");
+}
+
+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);
+
+    if (files.isEmpty())
+        return;
+
+    QString dir = QFileInfo (files[0]).absoluteDir().absolutePath();
+    settings.setValue("LastFolder", dir);
+    int index = sources.size();
+    foreach (QString string, files)
+    {
+        Phonon::MediaSource source (string);
+        sources.append(source);
+    }
+    if (!sources.isEmpty())
+        metaInformationResolver->setCurrentSource(sources.at(index));
+
+}
+
+void MainWindow::addFolders()
+{
+    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);
+
+    QStringList filters;
+    filters << "*.mp3";
+
+    QStringList files = QDir (dir).entryList(filters);
+
+    if (files.isEmpty())
+        return;
+
+    settings.setValue("LastFolder", dir);
+    int index = sources.size();
+    foreach (QString string, files)
+    {
+        QString fname = dir + "/" + string;
+        qDebug () << fname;
+        Phonon::MediaSource source(fname);
+        sources.append(source);
+    }
+    if (!sources.isEmpty())
+        metaInformationResolver->setCurrentSource(sources.at(index));
+
+}
+
+
+void MainWindow::about()
+{
+    QMessageBox::information(this, tr("About Music Player"),
+        tr("The Music Player example shows how to use Phonon - the multimedia"
+        " framework that comes with Qt - to create a simple music player."));
+}
+
+void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
+{
+    qDebug () << "State: " << newState;
+    switch (newState)
+    {
+        case Phonon::ErrorState:
+            if (mediaObject->errorType() == Phonon::FatalError)
+            {
+                QMessageBox::warning(this, tr("Fatal Error"),
+                mediaObject->errorString());
+            }
+            else
+            {
+                QMessageBox::warning(this, tr("Error"),
+                mediaObject->errorString());
+            }
+            break;
+        case Phonon::PlayingState:
+            setWindowTitle(metaInformationResolver->metaData().value("TITLE") + " - TomAmp");
+            playAction->setEnabled(false);
+            pauseAction->setEnabled(true);
+            stopAction->setEnabled(true);
+            break;
+        case Phonon::StoppedState:
+            stopAction->setEnabled(false);
+            playAction->setEnabled(true);
+            pauseAction->setEnabled(false);
+            timeLcd->display("00:00");
+            break;
+        case Phonon::PausedState:
+            pauseAction->setEnabled(false);
+            stopAction->setEnabled(true);
+            playAction->setEnabled(true);
+            qDebug () << "Queue size: " << mediaObject->queue().size ();
+            if (mediaObject->queue().size ())
+            {
+                int index = sources.indexOf(mediaObject->currentSource());
+                mediaObject->setCurrentSource(
+                    sources.at(index));
+                mediaObject->play ();
+                musicTable->setCurrentCell(index, 0);;
+            }
+            break;
+        case Phonon::BufferingState:
+            break;
+        default:
+        ;
+    }
+}
+
+void MainWindow::tick(qint64 time)
+{
+    QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
+
+    timeLcd->display(displayTime.toString("mm:ss"));
+}
+
+void MainWindow::tableClicked(int row, int /* column */)
+{
+//    bool wasPlaying = mediaObject->state() == Phonon::PlayingState;
+
+    mediaObject->stop();
+    mediaObject->clearQueue();
+
+    if (row >= sources.size())
+        return;
+
+    mediaObject->setCurrentSource(sources[row]);
+
+    mediaObject->play();
+}
+
+void MainWindow::sourceChanged(const Phonon::MediaSource &source)
+{
+    musicTable->selectRow(sources.indexOf(source));
+    timeLcd->display("00:00");
+}
+
+void MainWindow::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */)
+{
+    if (newState == Phonon::ErrorState)
+    {
+        QMessageBox::warning(this, tr("Error opening files"),
+        metaInformationResolver->errorString());
+        while (!sources.isEmpty() &&
+            !(sources.takeLast() == metaInformationResolver->currentSource())) {}  /* loop */;
+        return;
+    }
+
+    if (newState != Phonon::StoppedState && newState != Phonon::PausedState)
+    {
+        return;
+    }
+
+    if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid)
+        return;
+
+    QMap<QString, QString> metaData = metaInformationResolver->metaData();
+
+    QString title = metaData.value("TITLE");
+    if (title == "")
+        title = metaInformationResolver->currentSource().fileName();
+
+    QTableWidgetItem *titleItem = new QTableWidgetItem(title);
+    titleItem->setFlags(titleItem->flags() ^ Qt::ItemIsEditable);
+    QTableWidgetItem *artistItem = new QTableWidgetItem(metaData.value("ARTIST"));
+    artistItem->setFlags(artistItem->flags() ^ Qt::ItemIsEditable);
+    QTableWidgetItem *albumItem = new QTableWidgetItem(metaData.value("ALBUM"));
+    albumItem->setFlags(albumItem->flags() ^ Qt::ItemIsEditable);
+    QTableWidgetItem *yearItem = new QTableWidgetItem(metaData.value("DATE"));
+    yearItem->setFlags(yearItem->flags() ^ Qt::ItemIsEditable);
+
+    int currentRow = musicTable->rowCount();
+    musicTable->insertRow(currentRow);
+    musicTable->setItem(currentRow, 0, artistItem);
+    musicTable->setItem(currentRow, 1, titleItem);
+    musicTable->setItem(currentRow, 2, albumItem);
+    musicTable->setItem(currentRow, 3, yearItem);
+
+
+    if (musicTable->selectedItems().isEmpty())
+    {
+        musicTable->selectRow(0);
+        mediaObject->setCurrentSource(metaInformationResolver->currentSource());
+    }
+
+    Phonon::MediaSource source = metaInformationResolver->currentSource();
+    int index = sources.indexOf(metaInformationResolver->currentSource()) + 1;
+    if (sources.size() > index)
+    {
+        metaInformationResolver->setCurrentSource(sources.at(index));
+    }
+    else
+    {
+        musicTable->resizeColumnsToContents();
+        if (musicTable->columnWidth(0) > 300)
+            musicTable->setColumnWidth(0, 300);
+    }
+}
+
+void MainWindow::aboutToFinish()
+{
+    int index = sources.indexOf(mediaObject->currentSource()) + 1;
+    if (sources.size() > index)
+    {
+        mediaObject->enqueue(sources.at(index));
+        qDebug () << "Enqueue " << index;
+    }
+}
+
+void MainWindow::setupActions()
+{
+    playAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay), tr("Play"), this);
+    playAction->setShortcut(tr("Crl+P"));
+    playAction->setDisabled(true);
+    pauseAction = new QAction(style()->standardIcon(QStyle::SP_MediaPause), tr("Pause"), this);
+    pauseAction->setShortcut(tr("Ctrl+A"));
+    pauseAction->setDisabled(true);
+    stopAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop), tr("Stop"), this);
+    stopAction->setShortcut(tr("Ctrl+S"));
+    stopAction->setDisabled(true);
+    nextAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipForward), tr("Next"), this);
+    nextAction->setShortcut(tr("Ctrl+N"));
+    previousAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipBackward), tr("Previous"), this);
+    previousAction->setShortcut(tr("Ctrl+R"));
+    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"));
+    exitAction = new QAction(tr("E&xit"), this);
+    exitAction->setShortcuts(QKeySequence::Quit);
+    aboutAction = new QAction(tr("A&bout"), this);
+    aboutAction->setShortcut(tr("Ctrl+B"));
+    aboutQtAction = new QAction(tr("About &Qt"), this);
+    aboutQtAction->setShortcut(tr("Ctrl+Q"));
+
+    connect(playAction, SIGNAL(triggered()), mediaObject, SLOT(play()));
+    connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) );
+    connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop()));
+    connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
+    connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolders()));
+    connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
+    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
+    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::setupMenus()
+{
+    QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+    fileMenu->addAction(addFilesAction);
+    fileMenu->addAction(addFoldersAction);
+    fileMenu->addSeparator();
+    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->addAction(playAction);
+    bar->addAction(pauseAction);
+    bar->addAction(stopAction);
+
+    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::Vertical);
+
+    QLabel *volumeLabel = new QLabel;
+    volumeLabel->setPixmap(QPixmap("images/volume.png"));
+
+/*    QPalette palette;
+    palette.setBrush(QPalette::Light, Qt::darkGray);*/
+
+    timeLcd = new QLCDNumber;
+//    timeLcd->setPalette(palette);
+
+    QStringList headers;
+    headers << tr("Artist") << tr("Title") << tr("Album") << tr("Year");
+
+    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)));
+
+    QHBoxLayout *seekerLayout = new QHBoxLayout;
+    seekerLayout->addWidget(seekSlider);
+    seekerLayout->addWidget(timeLcd);
+
+    QVBoxLayout *playbackLayout = new QVBoxLayout;
+    playbackLayout->addWidget(bar);
+    playbackLayout->addStretch();
+    playbackLayout->addWidget(volumeSlider);
+    playbackLayout->addWidget(volumeLabel);
+
+    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");
+//    ui.setupUi(this);
+}
+
diff --git a/mainwindow.h b/mainwindow.h
new file mode 100644 (file)
index 0000000..32041a3
--- /dev/null
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** 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 "ui_mainwindow.h"
+
+class QAction;
+class QTableWidget;
+class QLCDNumber;
+
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    MainWindow();
+
+    QSize sizeHint() const
+    {
+        return QSize(500, 300);
+    }
+
+private slots:
+    void addFiles();
+    void addFolders();
+    void about();
+    void stateChanged(Phonon::State newState, Phonon::State oldState);
+    void tick(qint64 time);
+    void sourceChanged(const Phonon::MediaSource &source);
+    void metaStateChanged(Phonon::State newState, Phonon::State oldState);
+    void aboutToFinish();
+//    void finished();
+    void tableClicked(int row, int column);
+
+private:
+    void setupActions();
+    void setupMenus();
+    void setupUi();
+
+    Phonon::SeekSlider *seekSlider;
+    Phonon::MediaObject *mediaObject;
+    Phonon::MediaObject *metaInformationResolver;
+    Phonon::AudioOutput *audioOutput;
+    Phonon::VolumeSlider *volumeSlider;
+    QList<Phonon::MediaSource> sources;
+
+    QAction *playAction;
+    QAction *pauseAction;
+    QAction *stopAction;
+    QAction *nextAction;
+    QAction *previousAction;
+    QAction *addFilesAction;
+    QAction *addFoldersAction;
+    QAction *exitAction;
+    QAction *aboutAction;
+    QAction *aboutQtAction;
+    QLCDNumber *timeLcd;
+    QTableWidget *musicTable;
+    Ui::MainWindow ui;
+    QSettings settings;
+};
+
+#endif
diff --git a/mainwindow.ui b/mainwindow.ui
new file mode 100644 (file)
index 0000000..9fc46b0
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>480</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <widget class="QLCDNumber" name="timeLcd">
+    <property name="geometry">
+     <rect>
+      <x>683</x>
+      <y>422</y>
+      <width>111</width>
+      <height>51</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QTableWidget" name="musicTable">
+    <property name="geometry">
+     <rect>
+      <x>10</x>
+      <y>10</y>
+      <width>601</width>
+      <height>411</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QSlider" name="horizontalSlider">
+    <property name="geometry">
+     <rect>
+      <x>10</x>
+      <y>430</y>
+      <width>661</width>
+      <height>20</height>
+     </rect>
+    </property>
+    <property name="orientation">
+     <enum>Qt::Horizontal</enum>
+    </property>
+   </widget>
+  </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/playlist.cpp b/playlist.cpp
new file mode 100644 (file)
index 0000000..cc0c625
--- /dev/null
@@ -0,0 +1,18 @@
+#include "playlist.h"
+
+PlayList::PlayList()
+{
+}
+
+void PlayList::addFiles (const QString& path, const QStringList &thelist)
+{
+    foreach (QString p, thelist)
+    {
+        entrylist.append (PlayListEntry (path, p));
+    }
+}
+
+QList<PlayListEntry> PlayList::getList()
+{
+    return entrylist;
+}
diff --git a/playlist.h b/playlist.h
new file mode 100644 (file)
index 0000000..79d96f8
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef PLAYLIST_H
+#define PLAYLIST_H
+
+#include<QStringList>
+#include<QList>
+
+class PlayListEntry
+{
+public:
+    PlayListEntry (const QString& thepath, const QString& thename) : path (thepath), name (thename) { }
+    QString getName () { return name; }
+    QString getPath () { return path; }
+private:
+    QString path;
+    QString name;
+};
+
+class PlayList
+{
+public:
+    PlayList();
+    void addFiles (const QString& dir, const QStringList& thelist);
+    QList<PlayListEntry> getList ();
+private:
+    QList<PlayListEntry> entrylist;
+};
+
+
+#endif // PLAYLIST_H
diff --git a/tomamp.pro b/tomamp.pro
new file mode 100644 (file)
index 0000000..484b01c
--- /dev/null
@@ -0,0 +1,30 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-07-15T14:44:54
+#
+#-------------------------------------------------
+
+QT       += core gui phonon
+
+TARGET = tomamp
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+        mainwindow.cpp \
+    playlist.cpp
+
+HEADERS  += mainwindow.h \
+    playlist.h
+
+FORMS    += mainwindow.ui
+
+CONFIG += mobility
+MOBILITY = 
+
+symbian {
+    TARGET.UID3 = 0xe3107f4b
+    # TARGET.CAPABILITY += 
+    TARGET.EPOCSTACKSIZE = 0x14000
+    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
+}