Permalink
Browse files

working lib with an example app

  • Loading branch information...
0 parents commit e4795763c0f83ca5ff806f57b0d85d8845e06ad3 @RJ committed Feb 11, 2010
@@ -0,0 +1,9 @@
+example/example-qdaapd
+build/*
+*.swp
+*.a
+*.user
+Makefile*
+makefile*
+*.o
+moc_*
@@ -0,0 +1,26 @@
+An embeddable C++/Qt DAAP server library.
+
+How to build
+------------
+
+$ qmake && make
+
+now you have libqdaapd.a
+
+How to use
+----------
+
+Include "qdaapd/qdaapd.h" and link to the static library.
+Extend QDaap::Collection and pass it to QDAAPd().
+See example:
+
+$ cd example/ && qmake && make
+
+Then run: ./example-qdaadp
+
+Make sure /tmp/test.mp3 exists, or edit example/fakecollection.h accordingly.
+
+Notes
+-----
+So far only tested with amarok and rhythmbox (not itunes, but should work)
+
@@ -0,0 +1,14 @@
+# -------------------------------------------------
+# Project created by QtCreator 2010-02-07T18:35:48
+# -------------------------------------------------
+QT -= gui
+TARGET = example-qdaapd
+CONFIG -= app_bundle
+TEMPLATE = app
+
+SOURCES += main.cpp
+HEADERS += fakecollection.h
+
+INCLUDEPATH += ../include
+LIBPATH += ..
+LIBS += -lqdaapd
@@ -0,0 +1,73 @@
+#ifndef FAKE_COLLECTION_H
+#define FAKE_COLLECTION_H
+
+#include "qdaapd/collection.h"
+
+class FakeCollection : public QDaap::Collection
+{
+Q_OBJECT
+public:
+ explicit FakeCollection(QString name, QObject *parent = 0)
+ : QDaap::Collection(name, parent)
+ {};
+
+ // called when we should load/prepare the tracklist for this collection:
+ virtual void loadTracks()
+ {
+ qDebug() << "LoadTracks()";
+ // fetch from database, read over network etc:
+
+ QDaap::Track t;
+ t.id = t.perid = 1;
+ t.artist = "Test artist name 1";
+ t.album = "Test album name 1";
+ t.track = "Test track title 1";
+ t.duration = 300000;
+ t.filesize = 1024*1024*5;
+ t.albumposition = 1;
+ t.genre = "Rock";
+ t.comment = "no comment";
+ t.year = 1982;
+ t.albumdiscnumber = 1;
+ t.bitrate = 128;
+
+
+ m_tracks[t.id] = t;
+
+ QDaap::Track t2;
+ t2.id = t2.perid = 2;
+ t2.artist = "Test artist name 2";
+ t2.album = "Test album name 2";
+ t2.track = "Test track title 2";
+ t2.duration = 200000;
+ t2.filesize = 1024*1024*3;
+ t2.albumposition = 7;
+ t2.genre = "Rock";
+ t2.comment = "no comment";
+ t2.year = 1982;
+ t2.albumdiscnumber = 1;
+ t2.bitrate = 128;
+
+ m_tracks[t2.id] = t2;
+
+ emit finishedLoading();
+ };
+
+ virtual QIODevice * getTrack(quint32 id)
+ {
+ if(!m_tracks.contains(id))
+ {
+ qDebug() << "no track id in collection : " << id;
+ return 0;
+ }
+ //QDaap::Track t = m_tracks[id];
+ // lookup file path/url from track id... (hardcoded here)
+ QFile * f = new QFile("/tmp/test.mp3");
+ f->open(QIODevice::ReadOnly);
+ return f;
+ };
+
+};
+
+
+#endif
@@ -0,0 +1,15 @@
+#include <QtCore/QCoreApplication>
+#include "qdaapd/qdaapd.h"
+#include "fakecollection.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+ FakeCollection coll("Stub/fake collection");
+ printf("Starting on port 8080\n");
+ printf("FYI, Rhythmbox can manually connect to specific daap shares\n");
+ printf("or you can advertise it using: avahi-publish-service Example _daap._tcp 8080\n");
+ QDAAPd server(&coll, 8080);
+ coll.loadTracks();
+ return a.exec();
+}
@@ -0,0 +1,112 @@
+#ifndef __BASIC_DAAP__
+ #define __BASIC_DAAP__
+
+ /*
+ lean and mean DAAP-lib
+ basic data types
+
+ Copyright (c) deleet 2003, Alexander Oberdoerster & Johannes Zander
+ http://deleet.de/projekte/daap/
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+ #ifdef _MSC_VER // MS's for-scope is plain wrong - fix it!
+ #define for if( false ){}else for
+ #endif
+
+
+ //////
+ // unified signed/unsigned 8/16/32/64 bit types
+
+ #if( defined( WIN32 ) || defined( _WIN32 ))
+ typedef unsigned __int64 u64;
+ typedef unsigned __int32 u32;
+ typedef unsigned __int16 u16;
+ typedef unsigned __int8 u8;
+
+ typedef signed __int64 s64;
+ typedef signed __int32 s32;
+ typedef signed __int16 s16;
+ typedef signed __int8 s8;
+ #elif( defined( __GNUC__ ) || defined( __MACOSX__ ))
+ #include <inttypes.h>
+ typedef uint64_t u64;
+ typedef uint32_t u32;
+ typedef uint16_t u16;
+ typedef uint8_t u8;
+
+ typedef int64_t s64;
+ typedef int32_t s32;
+ typedef int16_t s16;
+ typedef int8_t s8;
+ //#elif
+ #else
+ #error "uh - no idea what the int types could be!"
+ #endif
+
+
+ //////
+ // memory chunk
+
+ class Chunk {
+ public:
+ Chunk( const u8* _ptr=0, u32 _size=0 )
+ : ptr( _ptr )
+ , memSize( _size ) {}
+
+ inline u8 operator[] ( u32 pos ) const { return( ptr[pos]); }
+ inline const u8* begin() const { return( ptr ); }
+ inline const u8* end() const { return( ptr+memSize ); }
+ inline u32 size() const { return( memSize ); }
+
+ protected:
+ const u8* ptr;
+ u32 memSize;
+ };
+
+
+ //////
+ // daap tag
+
+ struct Tag {
+ typedef u32 TagType;
+
+ TagType type;
+
+ Tag( TagType _type=0 )
+ : type( _type ) {}
+ };
+
+
+ //////
+ // version
+
+ struct Version {
+ u16 hi, lo;
+
+ Version( u16 _hi=0, u16 _lo=0 )
+ : hi( _hi )
+ , lo( _lo ) {}
+ };
+
+
+ //////
+ // time
+
+ typedef u32 Time;
+
+#endif
@@ -0,0 +1,98 @@
+#ifndef COLLECTION_H
+#define COLLECTION_H
+
+#include <QObject>
+#include <QList>
+#include <QMap>
+#include <QFile>
+#include <QMutex>
+#include <QWaitCondition>
+#include <QDebug>
+
+namespace QDaap
+{
+
+
+class Track
+{
+public:
+ Track() : extension("mp3"), disabled(false), trackcount(1), albumdiscnumber(1)
+ {};
+
+ quint32 id;
+ quint64 perid;
+ QString genre;
+ QString artist;
+ QString album;
+ QString track;
+ QString comment;
+ QString extension;
+ bool disabled;
+ quint16 bitrate;
+ quint32 duration; // ms
+ quint32 filesize;
+ quint16 trackcount;
+ quint16 albumposition;
+ quint16 year;
+ quint16 albumdiscnumber;
+};
+
+
+
+/* TODO playlists
+class Playlist
+{
+public:
+ quint32 id;
+ quint64 perid;
+ QString title;
+ quint32 length; // num tracks in playlist
+
+ virtual QList<Track> getTracks()
+ {
+ return QList<Track>();
+ };
+};
+*/
+
+class Collection : public QObject
+{
+Q_OBJECT
+public:
+ explicit Collection(QString name, QObject *parent = 0)
+ : QObject(parent), m_tracksloaded(false), m_name(name)
+ {
+ connect(this, SIGNAL(finishedLoading()), this, SLOT(loaded()));
+ };
+
+ QString name() const { return m_name; };
+ int numTracks() { return tracks().size(); };
+ QMap<quint32,Track> & tracks() { return m_tracks; };
+ bool isLoaded() const { return m_tracksloaded; };
+
+ // this should hit DB/peer get full current list of all tracks:
+ virtual void loadTracks() = 0;
+ virtual QIODevice * getTrack(quint32 id) = 0;
+
+ // Playlists are not implemented yet
+ virtual int numPlaylists() const { return 0 ; };
+ //QList<Playlist> playlists() const = 0;
+
+signals:
+ void finishedLoading();
+
+private slots:
+ void loaded()
+ {
+ m_tracksloaded = true;
+ };
+
+protected:
+ QString m_name;
+ QMap<quint32,Track> m_tracks;
+ bool m_tracksloaded;
+};
+
+} // ns
+
+#endif // COLLECTION_H
Oops, something went wrong.

0 comments on commit e479576

Please sign in to comment.