You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kaffeine/kaffeine/src/player-parts/libmpv-part/libmpv_event.h

97 lines
3.0 KiB

/*
* Kaffeine libmpv part
* Copyright (C) 2023 Mavridis Philippe <mavridisf@gmail.com>
*
* Based on Kaffeine dummy part
* Copyright (C) 2004-2005 Jürgen Kofler <kaffeine@gmx.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
// TQt
#include <tqthread.h>
#include <tqevent.h>
#include <tqdatetime.h>
// libmpv
#include <mpv/client.h>
#define MPVPART_EVENT_PROPERTY_CHANGE 65890
#define MPVPART_EVENT_EOF 65891
#define MPVPART_EVENT_ERROR 65892
class MpvPart;
class MpvPropertyChangeEvent : public TQCustomEvent {
public:
MpvPropertyChangeEvent(TQCString property, mpv_format format, void *data)
: TQCustomEvent(MPVPART_EVENT_PROPERTY_CHANGE),
_property(property), _format(format), _data(data)
{}
TQCString property() { return _property; }
mpv_format format() { return _format; }
void *data() { return _data; }
double toDouble() { return *(double *)_data; }
TQTime toTime() { return TQTime().addMSecs(toDouble() * 1000); }
private:
TQCString _property;
mpv_format _format;
void *_data;
};
class MpvEOFEvent : public TQCustomEvent {
public:
MpvEOFEvent(mpv_end_file_reason reason, TQString error = TQString::null)
: TQCustomEvent(MPVPART_EVENT_EOF), _reason(reason), _error(error)
{}
mpv_end_file_reason reason() { return _reason; }
TQString error() { return _error; }
private:
mpv_end_file_reason _reason;
TQString _error;
};
class MpvErrorEvent : public TQCustomEvent {
public:
MpvErrorEvent(TQString text, TQString caption, TQString details = TQString::null)
: TQCustomEvent(MPVPART_EVENT_ERROR), _text(text), _caption(caption), _details(details)
{}
TQString text() { return _text; }
TQString caption() { return _caption; }
TQString details() { return _details; }
private:
TQString _text, _caption, _details;
};
class MpvEventThread : public TQThread {
public:
MpvEventThread(MpvPart *part);
virtual void run();
private:
void initPropertyObservers();
void processEvent(mpv_event *event);
void processErrorMessage(TQString prefix, TQString level, TQString text);
private:
MpvPart *m_part;
};