X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=remote%2Fsource%2Fxinemacontrol.cpp;h=f793e3bb0f1a271fcb69e119fc4692d29ae75b1c;hb=5bb8258cd0c2a5600bc90ac9f7dc06b4746a16f9;hp=76108b98f815425b32946dda8d8dec7b97990b19;hpb=1abfbdd94fa45883f6d742df00508715f79c9954;p=xinema.git diff --git a/remote/source/xinemacontrol.cpp b/remote/source/xinemacontrol.cpp index 76108b9..f793e3b 100644 --- a/remote/source/xinemacontrol.cpp +++ b/remote/source/xinemacontrol.cpp @@ -1,6 +1,9 @@ #include "xinemacontrol.h" -XinemaControl::XinemaControl() +XinemaControl::XinemaControl(): + playback_state(STOPPED), + duration(0.0f), + position(0.0f) { QObject::connect(&socket, &QAbstractSocket::connected, this, &XinemaControl::connected); QObject::connect(&socket, &QAbstractSocket::disconnected, this, &XinemaControl::disconnected); @@ -33,6 +36,26 @@ void XinemaControl::play_file(const QString &fn) send_request("play_file "+fn); } +void XinemaControl::play() +{ + send_request("play"); +} + +void XinemaControl::seek(float time) +{ + send_request(QString("seek %1").arg(time)); +} + +void XinemaControl::pause() +{ + send_request("pause"); +} + +void XinemaControl::stop() +{ + send_request("stop"); +} + void XinemaControl::send_request(const QString &req) { socket.write(req.toUtf8()); @@ -41,12 +64,16 @@ void XinemaControl::send_request(const QString &req) void XinemaControl::data_available() { - char rbuf[1024]; - int len = socket.read(rbuf, sizeof(rbuf)); - if(len<0) - return; + while(socket.bytesAvailable()) + { + char rbuf[1024]; + int len = socket.read(rbuf, sizeof(rbuf)); + if(len<0) + break; + + buffer.append(rbuf, len); + } - buffer.append(rbuf, len); unsigned start = 0; while(1) { @@ -77,4 +104,29 @@ void XinemaControl::process_reply(const QString &reply) emit subdirectory_added(args); else if(keyword=="file") emit file_added(args); + else if(keyword=="state") + { + if(args=="STOPPED") + playback_state = STOPPED; + else if(args=="PAUSED") + playback_state = PAUSED; + else if(args=="PLAYING") + playback_state = PLAYING; + emit playback_state_changed(playback_state); + } + else if(keyword=="title") + { + title = args; + emit title_changed(title); + } + else if(keyword=="duration") + { + duration = args.toFloat(); + emit duration_changed(duration); + } + else if(keyword=="position") + { + position = args.toFloat(); + emit position_changed(position); + } }