Permalink
Browse files

remoteIOdevice <- QIODevice

  • Loading branch information...
1 parent ee46fa1 commit c733733e5c03fc92bb2227d48f023e6d546d072c @RJ committed Feb 8, 2010
@@ -76,6 +76,20 @@ void Library::addDir( const QString& url, int mtime)
query.exec();
}
+QVariantMap Library::file(int fid)
+{
+ QVariantMap m;
+ query.exec(QString("SELECT url, size FROM file WHERE id = ?").arg(fid));
+ if(query.next())
+ {
+ QString url = query.value(0).toString();
+ int size= query.value(2).toInt();
+ m["url"] = url;
+ m["size"] = size;
+ }
+ return m;
+}
+
int Library::addFile( QVariantMap m )
{
@@ -41,6 +41,7 @@ class Library : public QObject
QVariantMap artist(int id);
QVariantMap album(int id);
QVariantMap track(int id);
+ QVariantMap file(int fid);
public slots:
int addFile( QVariantMap m );
@@ -1,5 +1,5 @@
#include "remotecollection.h"
-//#include "httpd.h"
+#include "remoteioconnection.h"
RemoteCollection::RemoteCollection(Servent * s, RemoteCollectionConnection * conn) :
QDaap::Collection(conn->name(), conn), m_servent(s), m_rcconn(conn)
@@ -43,3 +43,16 @@ QList<QDaap::Track> RemoteCollection::loadTracks()
qDebug() << "all tracks received";
return m_tmp_tracks;
}
+
+QIODevice * RemoteCollection::getTrack(quint32 id)
+{
+ if(!m_tracks.contains(id))
+ {
+ return 0;
+ //Q_ASSERT(false);
+ }
+ QDaap::Track t = m_tracks[id];
+ RemoteIOConnection * ioc = new RemoteIOConnection(t.id, m_servent);
+ m_servent->createParallelConnection(m_rcconn->cc(), ioc, QString("FILE_REQUEST_KEY:%1").arg(id));
+ return ioc->iodevice();
+};
@@ -10,7 +10,11 @@
#include "library/library.h"
#include "conjist.h"
#include "httpd.h"
+
+#include "remotecollectionconnection.h"
+
class RemoteCollectionConnection;
+
class RemoteCollection : public QDaap::Collection
{
Q_OBJECT
@@ -35,6 +39,9 @@ public slots:
int port() const { return m_port; };
+ QIODevice * getTrack(quint32 id);
+
+
private:
Servent * m_servent;
RemoteCollectionConnection * m_rcconn;
@@ -51,93 +58,6 @@ public slots:
-class RemoteCollectionConnection : public Connection
-{
- Q_OBJECT
-public:
- RemoteCollectionConnection(Library * lib, Servent * s = 0 )
- : Connection(s), m_library(lib)
- {
- qDebug() << "CTOR " << id();
- };
-
- ~RemoteCollectionConnection()
- {
- qDebug() << "DTOR " << id();
- };
-
- QString id() const { return "RemoteCollectionConnection::" + name(); };
-
- Connection * clone() { Q_ASSERT(false); return 0; };
-
- void setup()
- {
- m_rc = new RemoteCollection(m_servent, this);
- };
-
- RemoteCollection * remoteCollection() const { return m_rc; };
-
- void handleMsg(QByteArray msg)
- {
- if(msg == "ALLTRACKSREQUEST")
- {
- // send all tracks
- QVariantList /*QList<QVariantMap>*/ all = m_library->allTracks();
- qDebug() << "Sending our library of " << all.length() << " tracks...";
-
- QVariantMap response;
- response["method"] = "alltracks";
- response["tracks"] = all;
-
- QJson::Serializer serializer;
- const QByteArray serialized = serializer.serialize( response );
- sendMsg(serialized);
- return;
- }
-
- bool ok;
- QVariantMap m = parser.parse(msg, &ok).toMap();
- if(ok)
- {
- if(m.value("method").toString() == "alltracks")
- {
- QList<QDaap::Track> tracks;
-
- QList<QVariant> all = m.value("tracks").toList();
- foreach(QVariant v, all)
- {
- QVariantMap m = v.toMap();
- QDaap::Track t;
- t.perid = t.id = m.value("id").toInt();
- t.genre = m.value("genre").toString();
- t.artist = m.value("artist").toString();
- t.album = m.value("album").toString();
- t.track = m.value("track").toString();
- t.comment = m.value("comment").toString();
- t.extension = m.value("extension").toString();
- t.bitrate = m.value("bitrate").toInt();
- t.duration = m.value("duration").toInt() * 1000;
- t.filesize = m.value("filesize").toInt();
- t.year = m.value("year").toInt();
- t.albumdiscnumber = m.value("albumdiscnumber").toInt();
- t.albumposition = m.value("albumposition").toInt();
- tracks.append(t);
- }
- emit allTracks(tracks);
- return;
- }
- }
-
- qDebug() << "UNHANDLED msg in rcc: " << QString::fromAscii(msg);
- };
-
-signals:
- void allTracks(QList<QDaap::Track>);
-private:
- Library * m_library;
- QJson::Parser parser;
- RemoteCollection * m_rc;
-};
@@ -0,0 +1,7 @@
+#include "remotecollectionconnection.h"
+
+
+void RemoteCollectionConnection::setup()
+{
+ m_rc = new RemoteCollection(m_servent, this);
+}
@@ -0,0 +1,98 @@
+#ifndef REMOTECOLLECTIONCONNECTION_H
+#define REMOTECOLLECTIONCONNECTION_H
+#include "connection.h"
+#include "remotecollection.h"
+#include "library/library.h"
+#include "remotecollection.h"
+
+class RemoteCollection;
+
+class RemoteCollectionConnection : public Connection
+{
+ Q_OBJECT
+public:
+ RemoteCollectionConnection(Library * lib, ControlConnection * cc, Servent * s = 0 )
+ : Connection(s), m_library(lib), m_cc(cc)
+ {
+ qDebug() << "CTOR " << id();
+ };
+
+ ~RemoteCollectionConnection()
+ {
+ qDebug() << "DTOR " << id();
+ };
+
+ QString id() const { return "RemoteCollectionConnection::" + name(); };
+
+ Connection * clone() { Q_ASSERT(false); return 0; };
+
+ void setup();
+
+ RemoteCollection * remoteCollection() const { return m_rc; };
+
+ void handleMsg(QByteArray msg)
+ {
+ if(msg == "ALLTRACKSREQUEST")
+ {
+ // send all tracks
+ QVariantList /*QList<QVariantMap>*/ all = m_library->allTracks();
+ qDebug() << "Sending our library of " << all.length() << " tracks...";
+
+ QVariantMap response;
+ response["method"] = "alltracks";
+ response["tracks"] = all;
+
+ QJson::Serializer serializer;
+ const QByteArray serialized = serializer.serialize( response );
+ sendMsg(serialized);
+ return;
+ }
+
+ bool ok;
+ QVariantMap m = parser.parse(msg, &ok).toMap();
+ if(ok)
+ {
+ if(m.value("method").toString() == "alltracks")
+ {
+ QList<QDaap::Track> tracks;
+
+ QList<QVariant> all = m.value("tracks").toList();
+ foreach(QVariant v, all)
+ {
+ QVariantMap m = v.toMap();
+ QDaap::Track t;
+ t.perid = t.id = m.value("id").toInt();
+ t.genre = m.value("genre").toString();
+ t.artist = m.value("artist").toString();
+ t.album = m.value("album").toString();
+ t.track = m.value("track").toString();
+ t.comment = m.value("comment").toString();
+ t.extension = m.value("extension").toString();
+ t.bitrate = m.value("bitrate").toInt();
+ t.duration = m.value("duration").toInt() * 1000;
+ t.filesize = m.value("filesize").toInt();
+ t.year = m.value("year").toInt();
+ t.albumdiscnumber = m.value("albumdiscnumber").toInt();
+ t.albumposition = m.value("albumposition").toInt();
+ tracks.append(t);
+ }
+ emit allTracks(tracks);
+ return;
+ }
+ }
+
+ qDebug() << "UNHANDLED msg in rcc: " << QString::fromAscii(msg);
+ };
+
+ ControlConnection * cc() const { return m_cc; };
+
+signals:
+ void allTracks(QList<QDaap::Track>);
+private:
+ Library * m_library;
+ QJson::Parser parser;
+ RemoteCollection * m_rc;
+ ControlConnection * m_cc;
+};
+
+#endif // REMOTECOLLECTIONCONNECTION_H
@@ -0,0 +1,3 @@
+#include "remoteioconnection.h"
+
+
Oops, something went wrong.

0 comments on commit c733733

Please sign in to comment.