From 9a50c13ad99d40115bb023aa1a89a9f0c1a352bb Mon Sep 17 00:00:00 2001 From: No'am Rosenthal Date: Thu, 26 Nov 2009 15:26:27 -0800 Subject: removed fringe features --- examples/mediaplayer/main.cpp | 98 ---------- examples/mediaplayer/mediaplayer.pro | 23 --- examples/mediaplayer/mediaplayer.qrc | 5 - examples/mediaplayer/mediaplayer.scxml | 240 ------------------------- examples/mediaplayer/mediaplayer.ui | 145 --------------- examples/mediaplayer/songdata.h | 55 ------ examples/mediaplayer/spengine.cpp | 124 ------------- examples/mediaplayer/spengine.h | 81 --------- examples/mediaplayer/spharvester.cpp | 108 ------------ examples/mediaplayer/spharvester.h | 65 ------- examples/mediaplayer/spmodel.cpp | 314 --------------------------------- examples/mediaplayer/spmodel.h | 104 ----------- examples/mediaplayer/spview.cpp | 137 -------------- examples/mediaplayer/spview.h | 77 -------- 14 files changed, 1576 deletions(-) delete mode 100644 examples/mediaplayer/main.cpp delete mode 100644 examples/mediaplayer/mediaplayer.pro delete mode 100644 examples/mediaplayer/mediaplayer.qrc delete mode 100644 examples/mediaplayer/mediaplayer.scxml delete mode 100644 examples/mediaplayer/mediaplayer.ui delete mode 100644 examples/mediaplayer/songdata.h delete mode 100644 examples/mediaplayer/spengine.cpp delete mode 100644 examples/mediaplayer/spengine.h delete mode 100644 examples/mediaplayer/spharvester.cpp delete mode 100644 examples/mediaplayer/spharvester.h delete mode 100644 examples/mediaplayer/spmodel.cpp delete mode 100644 examples/mediaplayer/spmodel.h delete mode 100644 examples/mediaplayer/spview.cpp delete mode 100644 examples/mediaplayer/spview.h (limited to 'examples/mediaplayer') diff --git a/examples/mediaplayer/main.cpp b/examples/mediaplayer/main.cpp deleted file mode 100644 index 4c4e927..0000000 --- a/examples/mediaplayer/main.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qscxml.h" -#include "spview.h" -#include "spmodel.h" -#include "spengine.h" -#include "spharvester.h" -#include "math.h" -#include "time.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -int main( int argc, char **argv) -{ - QApplication app(argc, argv); - QString dir; - bool recurse; - if (argc > 1) { - dir = QString(argv[1]); - if (argc > 2) - { - recurse = !strcmp(argv[2],"-recurse"); - } - } else { - printf("Usage: stateplayer directory [-recurse]"); - return 0; - } - - app.setApplicationName("SCXML-mediaplayer"); - - SPView* view = new SPView(NULL); - QScxml *sm = QScxml::load(":/mediaplayer.scxml"); - QObject::connect (sm, SIGNAL(finished()), &app, SLOT(quit())); - SPModel* model= new SPModel(NULL); - view->setModel(model); - model->setObjectName("model"); - SPEngine* engine = new SPEngine(sm); - engine->setObjectName("engine"); - SPHarvester* harvester = new SPHarvester (view); - QObject::connect (harvester, SIGNAL(foundTrack(SongData)), model, SLOT(addSong(SongData))); - harvester->harvest(dir,recurse); - view->setObjectName("view"); - sm->registerObject(model); - sm->registerObject(engine); - sm->registerObject(view,"",true); - view->show (); - sm->start (); - return app.exec (); -} diff --git a/examples/mediaplayer/mediaplayer.pro b/examples/mediaplayer/mediaplayer.pro deleted file mode 100644 index 70c06f1..0000000 --- a/examples/mediaplayer/mediaplayer.pro +++ /dev/null @@ -1,23 +0,0 @@ -TEMPLATE = app -TARGET = scxmlplayer -QT += script \ - sql \ - phonon -include(../../src/qscxml.pri) - -HEADERS += spmodel.h \ - spengine.h \ - spview.h \ - spharvester.h \ - songdata.h -SOURCES += main.cpp \ - spmodel.cpp \ - spengine.cpp \ - spview.cpp \ - spharvester.cpp -FORMS += mediaplayer.ui -RESOURCES += mediaplayer.qrc -win32:CONFIG += console -mac:CONFIG -= app_bundle -INCLUDEPATH += . -DEPENDPATH += . diff --git a/examples/mediaplayer/mediaplayer.qrc b/examples/mediaplayer/mediaplayer.qrc deleted file mode 100644 index ff8226f..0000000 --- a/examples/mediaplayer/mediaplayer.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - mediaplayer.scxml - - diff --git a/examples/mediaplayer/mediaplayer.scxml b/examples/mediaplayer/mediaplayer.scxml deleted file mode 100644 index 323d9c9..0000000 --- a/examples/mediaplayer/mediaplayer.scxml +++ /dev/null @@ -1,240 +0,0 @@ - - - - - [[listView,'styleSheet','QListView {font-size:20px}']] - - - - - - [[stackedWidget,"currentIndex",0]] - - - - - - - { "parent" : listView, "windowTitle" : - "Music Player", "styleSheet" : "QMenu {font-size:24px; width: 505;height:1000;}" + - "QMenu::item:hover {background-color: blue;color: black;}", - "children": function() { var c = [ - {"type" : "action","id" : "artists", "text" : "Artists" }, - {"type" : "action", "id" : "albums", "text" : "Albums" }, - {"type" : "action", "id" : "genres", "text" : "Genres" }, - {"type" : "action", "id" : "allsongs", "text" : "All Songs" }]; - if (model.currentSongTitle != '') - c[c.length] = {type: "action", id: "curplaying", text: model.currentSongTitle}; - return c; }() - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ - [selectButton,"enabled",false], - [playingLabel,"text",model.currentSongTitle], - [midLabel,"text",model.currentSongArtist], - [posSlider,"minimum",0], - [posSlider,"maximum",engine.totalTime], - [stackedWidget,"currentIndex",1] - ] - - - - - - - - - - - - - - - - - - - - - - - - - [[stopButton,"enabled",false]] - - - - - [[stopButton,"enabled",true]] - - - - - - - [[playButton,"text","Pause"]] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [[stopButton,"enabled",false], - [playButton,"enabled",false], - [prevButton,"enabled",false], - [nextButton,"enabled",false]] - - - - - - - - diff --git a/examples/mediaplayer/mediaplayer.ui b/examples/mediaplayer/mediaplayer.ui deleted file mode 100644 index dbbc6fd..0000000 --- a/examples/mediaplayer/mediaplayer.ui +++ /dev/null @@ -1,145 +0,0 @@ - - - mediaPlayerWidget - - - - 0 - 0 - 394 - 287 - - - - SCXML Media Player - - - - - - 0 - - - - - - - - - - - - - 0 - 50 - 291 - 61 - - - - QLabel {font-size: 24px; color: #336699} - - - TextLabel - - - - - - 0 - 120 - 291 - 21 - - - - TextLabel - - - - - - 0 - 180 - 301 - 16 - - - - 0 - - - Qt::Horizontal - - - - - - - - - - - - Home - - - - - - - Play - - - - - - - Prev - - - - - - - Next - - - - - - - Stop - - - - - - - Qt::Vertical - - - - - - - Select - - - - - - - Back - - - - - - - - - - - - diff --git a/examples/mediaplayer/songdata.h b/examples/mediaplayer/songdata.h deleted file mode 100644 index ab9937c..0000000 --- a/examples/mediaplayer/songdata.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef SONGDATA_H -#define SONGDATA_H - -#include - -struct SongData -{ - QString url; - QString title; - QString album; - QString artist; - QStringList genres; - int trackNumber; -}; -#endif diff --git a/examples/mediaplayer/spengine.cpp b/examples/mediaplayer/spengine.cpp deleted file mode 100644 index 6e087ee..0000000 --- a/examples/mediaplayer/spengine.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "spengine.h" -#include - -using namespace Phonon; - -class SPEnginePvt -{ - public: - MediaObject* mediaObject; - AudioOutput* audioOutput; -}; -void SPEngine::clearQueue() -{ - pvt->mediaObject->clearQueue(); -} - -int SPEngine::currentTime() const -{ - return pvt->mediaObject->currentTime (); -} -int SPEngine::totalTime() const -{ - return pvt->mediaObject->totalTime(); -} - -void SPEngine::enqueue (const QUrl & u) -{ - pvt->mediaObject->enqueue(MediaSource(u)); -} -void SPEngine::setTrack(const QUrl & u) -{ - pvt->mediaObject->setCurrentSource(MediaSource(u)); -} -void SPEngine::play() -{ - pvt->mediaObject->play (); -} - -void SPEngine::pause() -{ - pvt->mediaObject->pause (); -} - -void SPEngine::stop() -{ - pvt->mediaObject->stop(); -} - -void SPEngine::seek(qint64 pos) -{ - pvt->mediaObject->seek(pos); -} - -void SPEngine::setVolume(int v) -{ - pvt->audioOutput->setVolume((qreal)v/100); -} - -void SPEngine::onVolumeChanged(qreal r) -{ - emit volumeChanged(r*100); -} -int SPEngine::volume() const -{ - return pvt->audioOutput->volume()*100; -} - -SPEngine::SPEngine(QObject* p) : QObject(p) -{ - pvt = new SPEnginePvt; - pvt->mediaObject = new Phonon::MediaObject(this); - pvt->audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); - createPath (pvt->mediaObject, pvt->audioOutput); - pvt->mediaObject->setTickInterval(500); - connect (pvt->mediaObject, SIGNAL(aboutToFinish()), this, SIGNAL(aboutToFinish())); - connect (pvt->mediaObject, SIGNAL(tick(qint64)), this, SIGNAL(tick(qint64))); - connect (pvt->mediaObject, SIGNAL(totalTimeChanged(qint64)), this, SIGNAL(totalTimeChanged(qint64))); - connect (pvt->audioOutput, SIGNAL(volumeChanged(qreal)), this, SLOT(onVolumeChanged(qreal))); -} - -SPEngine::~SPEngine () -{ - delete pvt; -} diff --git a/examples/mediaplayer/spengine.h b/examples/mediaplayer/spengine.h deleted file mode 100644 index 9bb762c..0000000 --- a/examples/mediaplayer/spengine.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef SPENGINE_H -#define SPENGINE_H -#include -#include -class SPEngine : public QObject -{ - Q_OBJECT - Q_PROPERTY(int totalTime READ totalTime) - Q_PROPERTY(int currentTime READ currentTime) - Q_PROPERTY(int volume READ volume WRITE setVolume) - - Q_SIGNALS: - void aboutToFinish(); - void tick(qint64); - void totalTimeChanged(qint64); - void volumeChanged(int); - - public Q_SLOTS: - void clearQueue(); - void enqueue (const QUrl &); - void setTrack(const QUrl &); - void play(); - void pause(); - void seek(qint64); - void stop (); - - protected Q_SLOTS: - void onVolumeChanged(qreal); - - public: - SPEngine(QObject*); - virtual ~SPEngine (); - int currentTime () const; - int totalTime () const; - void setVolume(int); - int volume () const; - - private: - class SPEnginePvt* pvt; -}; -#endif diff --git a/examples/mediaplayer/spharvester.cpp b/examples/mediaplayer/spharvester.cpp deleted file mode 100644 index 4b31712..0000000 --- a/examples/mediaplayer/spharvester.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "spharvester.h" -#include -#include -#include -#include -#include - -using namespace Phonon; - -struct SPHarvesterPvt -{ - MediaObject* mediaObject; - QQueue pathQueue; -}; - -SPHarvester::SPHarvester(QObject* o) : QObject(o) -{ - pvt = new SPHarvesterPvt; - pvt->mediaObject = new MediaObject(this); - connect (pvt->mediaObject, SIGNAL(metaDataChanged()), this, SLOT(readMetaData ())); -} - -SPHarvester::~SPHarvester() -{ - delete pvt; -} - -void SPHarvester::harvest (const QString & directory, bool recurse) -{ - QDir d (directory); - QFileInfoList l = d.entryInfoList(QStringList() << "*.mp3",recurse ? QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Files : QDir::Files); - foreach (QFileInfo fi, l) { - if (fi.isDir()) { - harvest (fi.absoluteFilePath(), recurse); - } else { - pvt->pathQueue.enqueue(fi.absoluteFilePath()); - } - } - harvestNext (); -} - -void SPHarvester::harvestNext () -{ - if (pvt->pathQueue.empty()) - emit done(); - else { - QString s = pvt->pathQueue.dequeue(); - pvt->mediaObject->setCurrentSource(MediaSource(s)); - } -} - -void SPHarvester::readMetaData () -{ - QStringList albums = pvt->mediaObject->metaData("ALBUM"); - QStringList titles = pvt->mediaObject->metaData("TITLE"); - QStringList artists = pvt->mediaObject->metaData("ARTIST"); - QStringList trackNums = pvt->mediaObject->metaData("TRACKNUMBER"); - SongData sd; - sd.url = pvt->mediaObject->currentSource().url().toString(); - sd.album = albums.count() ? albums[0] : "Unknown Album"; - sd.artist = artists.count() ? artists[0] : "Unknown Artist"; - sd.trackNumber = trackNums.count() ? trackNums[0].toInt() : 0; - sd.genres = pvt->mediaObject->metaData("GENRE"); - sd.title = titles.count() ? titles[0] : QFileInfo(sd.url).baseName(); - - emit foundTrack(sd); - harvestNext (); -} diff --git a/examples/mediaplayer/spharvester.h b/examples/mediaplayer/spharvester.h deleted file mode 100644 index 61de45d..0000000 --- a/examples/mediaplayer/spharvester.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef SPHARVESTER_H -#define SPHARVESTER_H - -#include "songdata.h" -class SPHarvester : public QObject -{ - Q_OBJECT -public: - SPHarvester(QObject* o = NULL); - virtual ~SPHarvester (); -public slots: - void harvest (const QString & directory, bool recurse = true); - -private slots: - void harvestNext (); - void readMetaData(); -signals: - void foundTrack (const SongData & d); - void done (); - -private: - class SPHarvesterPvt* pvt; -}; - -#endif // _H diff --git a/examples/mediaplayer/spmodel.cpp b/examples/mediaplayer/spmodel.cpp deleted file mode 100644 index afaf730..0000000 --- a/examples/mediaplayer/spmodel.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "spmodel.h" -#include -#include -#include -#include -// an SQL query model that always as column (0) as uid and column (1) as display -class SPSqlQueryModel : public QSqlQueryModel -{ - Q_OBJECT - public: - SPSqlQueryModel (QObject* o = NULL): QSqlQueryModel (o) {} - virtual QVariant data(const QModelIndex & index, int role) const - { - QModelIndex idx(index); - if (role == Qt::DisplayRole && query().record().count() > 1) { - idx = idx.sibling(idx.row(),1); - } else if (role == Qt::UserRole) - role = Qt::DisplayRole; - return QSqlQueryModel::data(idx,role); - } -}; - - -class SPModelPvt -{ - public: - SPSqlQueryModel - artistModel, - albumModel, - songModel, - playlistModel, genreModel; - - QSqlQuery artistQuery, albumQuery, songQuery, playlistQuery, genreQuery, playingQuery; - -}; - -SPModel::SPModel(QObject* o) - :QObject(o) -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); - db.setDatabaseName("sqlite.db"); - if (!db.open()) { - QMessageBox::critical(0, qApp->tr("Cannot open database"), - qApp->tr("Unable to establish a database connection.\n" - "This example needs SQLite support. Please read " - "the Qt SQL driver documentation for information how " - "to build it.\n\n" - "Click Cancel to exit."), QMessageBox::Cancel); - } - - db.exec("CREATE TABLE IF NOT EXISTS songs (song_url VARCHAR(1024) PRIMARY KEY, song_title VARCHAR(1024), song_artist VARCHAR(1024), song_album VARCHAR(1024), song_track_index SMALLINT)"); - db.exec("DROP TABLE genres"); - db.exec("CREATE TABLE IF NOT EXISTS genres (genre_title VARCHAR(64), genre_song_url VARCHAR(1024))"); -// db.exec("CREATE TABLE IF NOT EXISTS playlists (playlist_id VARACHAR(256) PRIMARY KEY, playlist_title VARCHAR(1024))"); -// db.exec("CREATE TABLE IF NOT EXISTS playlist_songs (playlist_song_id BIGINT PRIMARY KEY, playlist_song_playlist - - pvt = new SPModelPvt; - pvt->artistQuery = QSqlQuery("SELECT DISTINCT song_artist FROM songs"); - pvt->albumQuery = QSqlQuery("SELECT DISTINCT song_album FROM songs"); - pvt->playlistQuery = QSqlQuery("SELECT playlist_url, playlist_title FROM playlists"); - pvt->songQuery = QSqlQuery("SELECT song_url, song_title from songs"); - pvt->genreQuery = QSqlQuery("SELECT DISTINCT genre_title from genres"); - QSqlQuery q; -// q.exec("SELECT DISTINCT song_url,song_title FROM songs, genres WHERE genre_song_url=song_url AND genre_title='All'"); - q.exec("SELECT * from genres"); - while (q.next()) { - qDebug () << q.value(0); - } -} - -void SPModel::addSong ( const SongData & data) -{ - - QSqlQuery q; - q.prepare("SELECT count(*) FROM songs WHERE song_url=:url"); - q.bindValue(":url",data.url); - bool inserting = true; - if (q.exec()) { - q.next(); - inserting = q.value(0).toInt() == 0; - } - if (inserting) { - q.prepare ("INSERT INTO songs (song_url, song_title, song_artist, song_album, song_track_index) VALUES (:url, :title, :artist, :album, :track)"); - } else { - q.prepare("UPDATE songs SET song_title=:title, song_album=:album, song_track_index=:track WHERE song_url=:url "); - } - q.bindValue(":url",data.url); - q.bindValue(":title",data.title); - q.bindValue(":artist",data.artist); - q.bindValue(":album",data.album); - q.bindValue(":track",data.trackNumber); - q.exec(); - - q.prepare ("DELETE FROM genres WHERE genre_song_url=:url"); - q.bindValue(":url",data.url); - q.exec(); - - q.prepare ("INSERT INTO genres (genre_song_url, genre_title) VALUES(:url, :genre)"); - q.bindValue(":url",data.url); - QStringList gn = data.genres; - gn << "All"; - foreach (QString g, gn) { - q.bindValue(":genre",g); - q.exec (); - } - - if (inserting) { - emit albumChanged(data.album); - emit songListChanged(); - emit artistChanged(data.artist); - foreach (QString g, data.genres) { - emit genreChanged(g); - } - } - - -} - - -SPModel::~SPModel() -{ - delete pvt; -} - -int SPModel::albumCount() const -{ - return pvt->albumModel.rowCount(); -} - -void SPModel::clearAlbumFilter () -{ - pvt->albumQuery = QSqlQuery ("SELECT DISTINCT song_album FROM songs "); -} -void SPModel::clearSongFilter () -{ - pvt->songQuery = QSqlQuery ("SELECT song_url, song_title FROM songs"); -} -void SPModel::loadArtists () -{ - pvt->artistQuery.exec (); - pvt->artistModel.setQuery(pvt->artistQuery); -} -void SPModel::filterAlbumsByArtist(const QString & artist) -{ - pvt->albumQuery.prepare("SELECT DISTINCT song_album FROM songs WHERE song_artist=:artist"); - pvt->albumQuery.bindValue(":artist",artist); -} -void SPModel::filterSongsByAlbum(const QString & album) -{ - pvt->albumQuery.prepare("SELECT song_url,song_title, song_track_index FROM songs WHERE song_album=:album ORDER BY song_track_index"); - pvt->albumQuery.bindValue(":album",album); -} -void SPModel::loadGenres () -{ - pvt->genreQuery.exec(); - pvt->genreModel.setQuery(pvt->genreQuery); -} - -void SPModel::filterSongsByGenre(const QString & genre) -{ - pvt->songQuery.prepare ("SELECT DISTINCT song_url,song_title FROM songs, genres WHERE genre_song_url=song_url AND genre_title=:genre"); - pvt->songQuery.bindValue(":genre",genre); -} -void SPModel::loadPlaylists() -{ - pvt->playlistQuery.exec (); - pvt->playlistModel.setQuery(pvt->playlistQuery); -} -void SPModel::loadAlbums() -{ - pvt->albumQuery.exec (); - pvt->albumModel.setQuery(pvt->albumQuery); -} -void SPModel::filterSongsByPlaylist(const QString & uid) -{ - pvt->songQuery.prepare("SELECT DISTINCT song_url, song_title, playlist_song_index FROM playlist_songs INNER JOIN songs ON playlist_song_url=song_url WHERE playlist_id=:playlist ORDER BY playlist_song_index"); - pvt->songQuery.bindValue(":playlist",uid); -} -void SPModel::loadSongs () -{ - pvt->songQuery.exec (); - pvt->songModel.setQuery(pvt->songQuery); -} -QUrl SPModel::currentSong() -{ - if (pvt->playingQuery.isValid()) - return QUrl(pvt->playingQuery.value(0).toString()); - else - return QUrl(); -} -QString SPModel::currentSongTitle() -{ - if (pvt->playingQuery.isValid()) - return pvt->playingQuery.value(1).toString(); - else - return QString(); -} -QString SPModel::currentSongArtist() -{ - QSqlQuery q; - q.prepare("SELECT song_artist FROM songs WHERE song_url=:url"); - q.bindValue(":url",currentSong().toString()); - q.exec(); - q.next(); - return q.value(0).toString(); -} -QString SPModel::currentSongAlbum() -{ - QSqlQuery q; - q.prepare("SELECT song_album FROM songs WHERE song_url=:url"); - q.bindValue(":url",currentSong().toString()); - q.exec(); - q.next(); - return q.value(0).toString(); -} - -void SPModel::selectSong (const QString & s) -{ - pvt->playingQuery = QSqlQuery(pvt->songQuery.executedQuery ()); - - while (pvt->playingQuery.next()) { - if (pvt->playingQuery.value(0).toString() == s) { - emit songChanged (); - return; - } - } - emit endOfList (); -} - -void SPModel::reset () -{ - pvt->playingQuery = QSqlQuery(pvt->songQuery.executedQuery ()); - pvt->playingQuery.exec(); -} - -void SPModel::gotoNext() -{ - if (pvt->playingQuery.next()) { - emit songChanged (); - }else - emit endOfList (); -} -void SPModel::gotoPrev() -{ - if (pvt->playingQuery.previous()) - emit songChanged (); - else - emit endOfList (); -} - - - -QAbstractItemModel* SPModel::albumsItemModel() const -{ - return &pvt->albumModel; -} -QAbstractItemModel* SPModel::genresItemModel() const -{ - return &pvt->genreModel; -} -QAbstractItemModel* SPModel::songsItemModel() const -{ - return &pvt->songModel; -} -QAbstractItemModel* SPModel::playlistsItemModel() const -{ - return &pvt->playlistModel; -} -QAbstractItemModel* SPModel::artistsItemModel() const -{ - return &pvt->artistModel; -} - -#include diff --git a/examples/mediaplayer/spmodel.h b/examples/mediaplayer/spmodel.h deleted file mode 100644 index 80430dd..0000000 --- a/examples/mediaplayer/spmodel.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef SPMODEL_H -#define SPMODEL_H -#include -#include -#include -#include "songdata.h" - -class SPModel : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QUrl currentSong READ currentSong) - Q_PROPERTY(QString currentSongTitle READ currentSongTitle) - Q_PROPERTY(QString currentSongArtist READ currentSongArtist) - Q_PROPERTY(QString currentSongAlbum READ currentSongAlbum) - Q_PROPERTY(int albumCount READ albumCount) - - - public slots: - void clearAlbumFilter (); - void clearSongFilter (); - void loadArtists (); - void filterAlbumsByArtist(const QString & name); - void loadGenres (); - void filterSongsByGenre(const QString & genre); - void loadPlaylists(); - void loadAlbums(); - void filterSongsByPlaylist(const QString & uid); - void filterSongsByAlbum(const QString & name); - void loadSongs (); - void selectSong (const QString &); - void gotoNext(); - void gotoPrev(); - void addSong (const SongData &); - void reset (); - - signals: - void albumChanged(const QString &); - void artistChanged(const QString &); - void genreChanged(const QString &); - void songListChanged(); - void songChanged (); - void endOfList (); - - public: - SPModel(QObject*); - virtual ~SPModel (); - - QUrl currentSong(); - QString currentSongTitle (); - QString currentSongArtist(); - QString currentSongAlbum(); - QAbstractItemModel* albumsItemModel() const; - QAbstractItemModel* genresItemModel() const; - QAbstractItemModel* songsItemModel() const; - QAbstractItemModel* playlistsItemModel() const; - QAbstractItemModel* artistsItemModel() const; - int albumCount() const; - - private: - class SPModelPvt* pvt; -}; - -#endif diff --git a/examples/mediaplayer/spview.cpp b/examples/mediaplayer/spview.cpp deleted file mode 100644 index 36d5326..0000000 --- a/examples/mediaplayer/spview.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "spview.h" -#include "spmodel.h" -#include -#include - -class SPViewPvt -{ - public: - SPModel* model; -}; - - -class SPItemDelegate : public QItemDelegate -{ - Q_OBJECT - -public: - SPItemDelegate(QObject* o) : QItemDelegate(o) {} - - virtual void paint (QPainter* p, QStyleOptionViewItem & option, const QModelIndex & index) const - { - QString disp = index.data(Qt::DisplayRole).toString(); - drawBackground(p,option,index); - drawDisplay(p,option,option.rect,disp); - } -}; - -void SPView::setModel (SPModel* m) -{ - pvt->model = m; -} - -void SPView::showAlbums () -{ - listView->setModel (pvt->model->albumsItemModel()); -} - -void SPView::showArtists () -{ - listView->setModel (pvt->model->artistsItemModel()); -} - -void SPView::showGenres () -{ - QAbstractItemModel* model = pvt->model->genresItemModel(); - listView->setModel (model); -} - -void SPView::showSongs () -{ - listView->setModel (pvt->model->songsItemModel()); -} - -void SPView::showPlaylists() -{ - listView->setModel (pvt->model->playlistsItemModel()); -} - - -SPView::SPView(QWidget* w) : QWidget (w) -{ - pvt = new SPViewPvt; - setupUi(this); - listView->setItemDelegate(new SPItemDelegate(this)); -} - -QString SPView::currentItem() const -{ - QVariant v = listView->model()->data(listView->currentIndex(),Qt::UserRole); - if (v.isNull()) - v = listView->currentIndex().data(Qt::DisplayRole); - return v.toString (); -} - -int SPView::itemCount () const -{ - return listView->model()->rowCount (); -} -int SPView::currentIndex() const -{ - return listView->currentIndex().row(); -} - -void SPView::setTotalTime (int t) -{ - posSlider->setMaximum(t); -} -void SPView::setCurrentTime (int t) -{ - posSlider->setValue (t); -} - -SPView::~SPView () -{ - delete pvt; -} -#include "spview.moc" diff --git a/examples/mediaplayer/spview.h b/examples/mediaplayer/spview.h deleted file mode 100644 index 45716fe..0000000 --- a/examples/mediaplayer/spview.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of SCXML on Qt labs -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SPVIEW_H -#define SPVIEW_H -#include -#include -#include "spmodel.h" -#include "ui_mediaplayer.h" - -class SPView : public QWidget, public virtual Ui::mediaPlayerWidget -{ - Q_OBJECT - Q_PROPERTY(QString currentItem READ currentItem) - Q_PROPERTY(int itemCount READ itemCount) - Q_PROPERTY(int currentIndex READ currentIndex) - public slots: - void setModel (SPModel*); - void showAlbums (); - void showArtists (); - void showGenres (); - void showSongs (); - void showPlaylists(); - void setTotalTime (int); - void setCurrentTime (int); - - - public: - SPView(QWidget*); - virtual ~SPView (); - QString currentItem () const; - int itemCount () const; - int currentIndex() const; - - private: - class SPViewPvt* pvt; -}; - -#endif -- cgit v1.2.3