Switch to side-by-side view

--- a/upqo/avtransport_qo.h
+++ b/upqo/avtransport_qo.h
@@ -4,45 +4,74 @@
 
 #include <QObject>
 #include <QThread>
+#include <QDebug>
 
 #include "libupnpp/control/avtransport.hxx"
+
+class AVTMetadata {
+public:
+    virtual std::string getDidl() const = 0;
+};
 
 class AVTransportQO : public QObject, public UPnPClient::VarEventReporter {
 Q_OBJECT
 
 public:
     AVTransportQO(UPnPClient::AVTH avt, QObject *parent = 0)
-        : QObject(parent), m_srv(avt)
-        {
-            m_srv->installReporter(this);
+        : QObject(parent), m_srv(avt), m_cursecs(-1)
+    {
+        m_srv->installReporter(this);
+    }
+
+    virtual void changed(const char *nm, int value)
+    {
+        if (!strcmp(nm, "CurrentTrackDuration")) {
+            m_cursecs = value;
         }
+            
+        qDebug() << "AVT: Changed: " << nm << " (int): " << value;
+    }
+    virtual void changed(const char *nm, const char *value)
+    {
+        qDebug() << "AVT: Changed: " << nm << " (char*): " << value;
+    }
 
-    void changed(const char *nm, int value)
-        {
-//            cout << "Changed: " << nm << " (int): " << value  << endl;
+    virtual void changed(const char *nm, UPnPDirObject meta)
+    {
+        string s = meta.dump();
+        if (!strcmp(nm, "AVTransportURIMetaData")) {
+            emit titleChanged(QString::fromUtf8(
+                                  meta.m_title.c_str()));
+            emit albumChanged(QString::fromUtf8(
+                                  meta.m_props["upnp:album"].c_str()));
+            emit artistChanged(QString::fromUtf8(
+                                   meta.m_props["upnp:artist"].c_str()));
+            //m_cursecs = meta.getDurationSeconds();
+            qDebug() << "AVT: duration now: " << m_cursecs << " S";
         }
-    void changed(const char *nm, const char *value)
-        {
-//            cout << "Changed: " << nm << " (char*): " << value << endl;
-        }
-
-    void changed(const char *nm, UPnPDirContent meta)
-        {
-            string s("NO CONTENT");
-            if (meta.m_items.size() > 0) {
-                s = meta.m_items[0].dump();
-                if (!strcmp(nm, "AVTransportURIMetaData"))
-                    emit titleChanged(QString::fromUtf8(
-                                          meta.m_items[0].m_title.c_str()));
-                    emit albumChanged(QString::fromUtf8(
-                                          meta.m_items[0].m_props["upnp:album"].c_str()));
-                    emit artistChanged(QString::fromUtf8(
-                                          meta.m_items[0].m_props["upnp:artist"].c_str()));
-            }
-//            cout << "Changed: " << nm << " (dirc): " << s << endl;
-        }
+        qDebug() << "AVT: Changed: " << nm << " (dirc): " << s.c_str();
+    }
 
 public slots:
+
+    virtual void play() {m_srv->play();}
+    virtual void stop() {m_srv->stop();}
+    virtual void pause() {m_srv->pause();}
+
+    virtual void changeTrack(const string& uri, const AVTMetadata* md)
+    {
+        m_srv->setAVTransportURI(uri, md->getDidl());
+    }
+
+    // Seek to point. Parameter in percent.
+    virtual void seekPC(int pc) 
+    {
+        qDebug() << "AVT: seekPC " << pc << " %";
+        if (m_cursecs > 0) {
+            m_srv->seek(UPnPClient::AVTransport::SEEK_ABS_TIME, 
+                        (float(pc)/100.0) * m_cursecs); 
+        }
+    }
 
 signals:
     void titleChanged(QString);
@@ -51,5 +80,6 @@
 
 private:
     UPnPClient::AVTH m_srv;
+    int m_cursecs;
 };