From: APTX Date: Mon, 24 Apr 2017 10:24:46 +0000 (+0200) Subject: UNFINISHED redo feature plugins X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=56236e3a4bd7ec991e4b42ee5d99f75bd75a0d16;p=aniplayer.git UNFINISHED redo feature plugins --- diff --git a/core/core.pro b/core/core.pro index d5f8515..4cfe5dc 100644 --- a/core/core.pro +++ b/core/core.pro @@ -26,7 +26,8 @@ HEADERS += \ instancemanager.h \ settings.h \ trackmodel.h \ - chaptermodel.h + chaptermodel.h \ + include/aniplayer/playerfeatureplugininterface.h include(qtsingleapplication/qtsingleapplication.pri) diff --git a/core/include/aniplayer/featurepluginbase.h b/core/include/aniplayer/featurepluginbase.h index ff08d62..b20b3b3 100644 --- a/core/include/aniplayer/featurepluginbase.h +++ b/core/include/aniplayer/featurepluginbase.h @@ -3,15 +3,30 @@ #include +#include "aniplayer/playerfeatureplugininterface.h" + +class FeaturePluginInstance { +public: + virtual ~FeaturePluginInstance() = default; + + FeaturePluginInstance(QObject *player, + PlayerFeaturePlauginInterface *interface) + : m_player{player}, m_playerInterface{interface} {} + +protected: + QObject *m_player; + PlayerFeaturePlauginInterface *m_playerInterface; +}; + class FeaturePluginBase { public: virtual ~FeaturePluginBase() = default; - virtual void instanceCreated(QObject *instance) = 0; - virtual void instanceDestroyed(QObject *instance) = 0; + virtual FeaturePluginInstance * + createInstance(QObject *instance, PlayerFeaturePlauginInterface *) = 0; }; -#define ANIPLAYER_FEATURE_PLUGIN_INTERFACE_IID \ +#define ANIPLAYER_FEATURE_PLUGIN_INTERFACE_IID \ "org.aptx.aniplayer.FeaturePluginInterface" Q_DECLARE_INTERFACE(FeaturePluginBase, ANIPLAYER_FEATURE_PLUGIN_INTERFACE_IID) diff --git a/core/include/aniplayer/playerfeatureplugininterface.h b/core/include/aniplayer/playerfeatureplugininterface.h new file mode 100644 index 0000000..243a169 --- /dev/null +++ b/core/include/aniplayer/playerfeatureplugininterface.h @@ -0,0 +1,13 @@ +#ifndef PLAYERFEATUREPLUGININTERFACE_H +#define PLAYERFEATUREPLUGININTERFACE_H + +#include + +class PlayerFeaturePlauginInterface { +public: + virtual ~PlayerFeaturePlauginInterface() = default; + + virtual void featureShowStatusMessage(const QString &message) = 0; +}; + +#endif // PLAYERFEATUREPLUGININTERFACE_H diff --git a/core/instancemanager.cpp b/core/instancemanager.cpp index 0a03574..c07647d 100644 --- a/core/instancemanager.cpp +++ b/core/instancemanager.cpp @@ -150,7 +150,7 @@ Player *InstanceManager::createPlayerInstance() { auto player = new Player{instance, this}; Q_CHECK_PTR(player); - m_featurePluginManager->forEach( - [player](FeaturePluginBase *plugin) { plugin->instanceCreated(player); }); + m_featurePluginManager->forEach([player]( + FeaturePluginBase *plugin) { plugin->createInstance(player, player); }); return player; } diff --git a/core/player.cpp b/core/player.cpp index 8ff8a1c..ac5bfc4 100644 --- a/core/player.cpp +++ b/core/player.cpp @@ -304,6 +304,11 @@ void Player::backendCurrentSubtitleTrackChanged(Player::TrackIndex track) { emit currentSubtitleTrackChanged(track); } +void Player::featureShowStatusMessage(const QString &message) +{ + emit statusMessageRequested(message); +} + void Player::reqisterQmlTypes() { qRegisterMetaType("TimeStamp"); qRegisterMetaType("StreamIndex"); diff --git a/core/player.h b/core/player.h index ae61346..0824841 100644 --- a/core/player.h +++ b/core/player.h @@ -7,12 +7,14 @@ #include #include "aniplayer/backendpluginbase.h" +#include "aniplayer/playerfeatureplugininterface.h" #include "chaptermodel.h" #include "trackmodel.h" class Player : public QObject, public PlayerPluginInterface, - public PlayerRendererInterface { + public PlayerRendererInterface, + public PlayerFeaturePlauginInterface { Q_OBJECT Q_PROPERTY(QUrl currentSource READ currentSource WRITE load NOTIFY currentSourceChanged) @@ -124,6 +126,8 @@ signals: void subtitleTrackModelChanged(QAbstractItemModel *subtitleTrackModel); void chapterModelChanged(QAbstractItemModel *chapterModel); + void statusMessageRequested(const QString &message); + public slots: // Basic Play state void load(const QUrl &resource); @@ -170,6 +174,8 @@ protected: void backendCurrentAudioTrackChanged(TrackIndex) override; void backendCurrentSubtitleTrackChanged(TrackIndex) override; + void featureShowStatusMessage(const QString &message) override; + public: static void reqisterQmlTypes(); diff --git a/featureplugins/feature_localmylist/featurelocalmylist.cpp b/featureplugins/feature_localmylist/featurelocalmylist.cpp index 99f2d50..2f76de6 100644 --- a/featureplugins/feature_localmylist/featurelocalmylist.cpp +++ b/featureplugins/feature_localmylist/featurelocalmylist.cpp @@ -20,22 +20,13 @@ FeatureLocalMyList::FeatureLocalMyList(QObject *parent) : QObject{parent} { qCWarning(lmlCategory) << "Init failed"; } -void FeatureLocalMyList::instanceCreated(QObject *instance) { - qCDebug(lmlCategory) << "Registering with instance" << instance; - connect(instance, SIGNAL(currentSourceChanged(QUrl)), this, - SLOT(sourceChanged(QUrl))); - connect(instance, SIGNAL(positionChanged(double)), this, - SLOT(positionChanged(double))); - connect(instance, SIGNAL(durationChanged(double)), this, - SLOT(durationChanged(double))); +FeaturePluginInstance * +FeatureLocalMyList::createInstance(QObject *instance, + PlayerFeaturePlauginInterface *interface) { + return new FeatureLocalMyListInstance(instance, interface); } -void FeatureLocalMyList::instanceDestroyed(QObject *instance) { - qCDebug(lmlCategory) << "Unregistering from instance" << instance; - m_instanceMap.remove(instance); -} - -void FeatureLocalMyList::sourceChanged(const QUrl &source) { +void FeatureLocalMyListInstance::sourceChanged(const QUrl &source) { if (!source.isLocalFile()) return; const auto path = source.toLocalFile(); @@ -55,49 +46,32 @@ void FeatureLocalMyList::sourceChanged(const QUrl &source) { qCInfo(lmlCategory) << "File" << path << "found in LocalMyList, fid =" << file.fid; - auto &data = m_instanceMap[sender()]; - data.duration = readDuration(sender()); - data.fid = file.fid; - data.path = path; + m_duration = readDuration(sender()); + m_fid = file.fid; + m_path = path; } -void FeatureLocalMyList::durationChanged(double duration) -{ +void FeatureLocalMyListInstance::durationChanged(double duration) { qCDebug(lmlCategory) << "Duration changed for " << sender(); - const auto it = m_instanceMap.find(sender()); - if (it == m_instanceMap.cend()) - return; - auto &data = it.value(); - - data.duration = duration; + m_duration = duration; } -void FeatureLocalMyList::positionChanged(double position) { - { - const auto it = m_instanceMap.find(sender()); - if (it == m_instanceMap.cend()) - return; - - const auto &data = it.value(); - - if (data.duration < 1.0) - return; +void FeatureLocalMyListInstance::positionChanged(double position) { + if (m_duration < 1.0) + return; - if (!data.fid) - return; + if (!m_fid) + return; - if (position / data.duration * 100.0 < PERCENT) - return; + if (position / m_duration * 100.0 < PERCENT) + return; - qCInfo(lmlCategory) << "Marking file" << data.path << "watched"; - LocalMyList::instance()->markWatchedIfUnwatched(data.fid); - } - m_instanceMap.remove(sender()); + qCInfo(lmlCategory) << "Marking file" << m_path << "watched"; + LocalMyList::instance()->markWatchedIfUnwatched(m_fid); } -double FeatureLocalMyList::readDuration(QObject *obj) -{ +double FeatureLocalMyListInstance::readDuration(QObject *obj) { const auto mo = obj->metaObject(); const auto durationIdx = mo->indexOfProperty("duration"); qCDebug(lmlCategory) << "duration propert index" << durationIdx; @@ -109,3 +83,15 @@ double FeatureLocalMyList::readDuration(QObject *obj) qCDebug(lmlCategory) << "File duration read" << duration; return duration; } + +FeatureLocalMyListInstance::FeatureLocalMyListInstance( + QObject *instance, PlayerFeaturePlauginInterface *player, QObject *parent) + : FeaturePluginInstance{instance, player} { + qCDebug(lmlCategory) << "Registering with instance" << instance; + connect(instance, SIGNAL(currentSourceChanged(QUrl)), this, + SLOT(sourceChanged(QUrl))); + connect(instance, SIGNAL(positionChanged(double)), this, + SLOT(positionChanged(double))); + connect(instance, SIGNAL(durationChanged(double)), this, + SLOT(durationChanged(double))); +} diff --git a/featureplugins/feature_localmylist/featurelocalmylist.h b/featureplugins/feature_localmylist/featurelocalmylist.h index b93043f..6bc4957 100644 --- a/featureplugins/feature_localmylist/featurelocalmylist.h +++ b/featureplugins/feature_localmylist/featurelocalmylist.h @@ -7,6 +7,7 @@ #include #include "aniplayer/featurepluginbase.h" +#include "aniplayer/playerfeatureplugininterface.h" #include "feature_localmylist_global.h" class FEATURE_LOCALMYLISTSHARED_EXPORT FeatureLocalMyList @@ -19,8 +20,14 @@ class FEATURE_LOCALMYLISTSHARED_EXPORT FeatureLocalMyList public: FeatureLocalMyList(QObject *parent = nullptr); - void instanceCreated(QObject *instance) override; - void instanceDestroyed(QObject *instance) override; + FeaturePluginInstance * + createInstance(QObject *instance, PlayerFeaturePlauginInterface *) override; +}; + +class FeatureLocalMyListInstance : public QObject, public FeaturePluginInstance { + Q_OBJECT +public: + FeatureLocalMyListInstance(QObject *instance, PlayerFeaturePlauginInterface *, QObject *parent = nullptr); private slots: void sourceChanged(const QUrl &source); @@ -30,12 +37,11 @@ private slots: private: static double readDuration(QObject *obj); - struct FileData { - int fid; - QString path; - double duration; - }; - QHash m_instanceMap; + QObject m_player; + PlayerFeaturePlauginInterface *m_playerInterface; + int m_fid; + QString m_path; + double m_duration; }; #endif // FEATURELOCALMYLIST_H diff --git a/uiplugins/ui_desktop_qml_default/qml.qrc b/uiplugins/ui_desktop_qml_default/qml.qrc index 4ba679c..eaf22ec 100644 --- a/uiplugins/ui_desktop_qml_default/qml.qrc +++ b/uiplugins/ui_desktop_qml_default/qml.qrc @@ -6,5 +6,6 @@ qml/SeekSlider.qml qml/PlaybackPosition.qml qml/VolumeSlider.qml + qml/TextWithBackground.qml diff --git a/uiplugins/ui_desktop_qml_default/qml/TextWithBackground.qml b/uiplugins/ui_desktop_qml_default/qml/TextWithBackground.qml new file mode 100644 index 0000000..917a1c5 --- /dev/null +++ b/uiplugins/ui_desktop_qml_default/qml/TextWithBackground.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Rectangle { + property alias text: message.text + + color: "#000000" + width: childrenRect.width + 5 + height: childrenRect.height + 5 + Text { + id: message + color: "red" + x: 0 + y: 0 + width: contentWidth + height: contentHeight + } +} diff --git a/uiplugins/ui_desktop_qml_default/qml/main.qml b/uiplugins/ui_desktop_qml_default/qml/main.qml index 973e198..d1bb4c6 100644 --- a/uiplugins/ui_desktop_qml_default/qml/main.qml +++ b/uiplugins/ui_desktop_qml_default/qml/main.qml @@ -139,4 +139,18 @@ Window { controlsVisible = !controlsVisible; } } + + TextWithBackground { + anchors.top: parent.top + anchors.left: parent.left + + text: "This is a text message" + + visible: controls.visible + + Connections { + target: player + onStatusMessageRequested: text = message + } + } }