]> Some of my projects - aniplayer.git/commitdiff
UNFINISHED redo feature plugins
authorAPTX <marek321@gmail.com>
Mon, 24 Apr 2017 10:24:46 +0000 (12:24 +0200)
committerAPTX <marek321@gmail.com>
Mon, 24 Apr 2017 10:24:46 +0000 (12:24 +0200)
core/core.pro
core/include/aniplayer/featurepluginbase.h
core/include/aniplayer/playerfeatureplugininterface.h [new file with mode: 0644]
core/instancemanager.cpp
core/player.cpp
core/player.h
featureplugins/feature_localmylist/featurelocalmylist.cpp
featureplugins/feature_localmylist/featurelocalmylist.h
uiplugins/ui_desktop_qml_default/qml.qrc
uiplugins/ui_desktop_qml_default/qml/TextWithBackground.qml [new file with mode: 0644]
uiplugins/ui_desktop_qml_default/qml/main.qml

index d5f851590f9d6590e17f9004bcee008ca890ef1d..4cfe5dc3231125f1af80b9a5c7f415f494020cd1 100644 (file)
@@ -26,7 +26,8 @@ HEADERS += \
     instancemanager.h \
     settings.h \
     trackmodel.h \
-    chaptermodel.h
+    chaptermodel.h \
+    include/aniplayer/playerfeatureplugininterface.h
 
 include(qtsingleapplication/qtsingleapplication.pri)
 
index ff08d62007a36769f87bf442d66e048dfc00701f..b20b3b3e9dcacffd2f70da74776c74a6938fa86c 100644 (file)
@@ -3,15 +3,30 @@
 
 #include <QObject>
 
+#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 (file)
index 0000000..243a169
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef PLAYERFEATUREPLUGININTERFACE_H
+#define PLAYERFEATUREPLUGININTERFACE_H
+
+#include <QString>
+
+class PlayerFeaturePlauginInterface {
+public:
+  virtual ~PlayerFeaturePlauginInterface() = default;
+
+  virtual void featureShowStatusMessage(const QString &message) = 0;
+};
+
+#endif // PLAYERFEATUREPLUGININTERFACE_H
index 0a035749750f6b8e3d0f412ea8373ec2da01cdb1..c07647d8c0e5c1219e6fd739db1ced1074c40d95 100644 (file)
@@ -150,7 +150,7 @@ Player *InstanceManager::createPlayerInstance() {
   auto player = new Player{instance, this};
   Q_CHECK_PTR(player);
 
-  m_featurePluginManager->forEach<FeaturePluginBase>(
-      [player](FeaturePluginBase *plugin) { plugin->instanceCreated(player); });
+  m_featurePluginManager->forEach<FeaturePluginBase>([player](
+      FeaturePluginBase *plugin) { plugin->createInstance(player, player); });
   return player;
 }
index 8ff8a1c4e0617fe31a49995588dc8e4671400e81..ac5bfc49c3c4016aa88c41673ed13b410840cb66 100644 (file)
@@ -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>("TimeStamp");
   qRegisterMetaType<TrackIndex>("StreamIndex");
index ae61346bfa40d47268f2455868436110b27e098d..08248417974cd22867bd8145974a74b79e9aee4f 100644 (file)
@@ -7,12 +7,14 @@
 #include <QUrl>
 
 #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();
 
index 99f2d50597c5f7dcbccbce6525deec9fdaf0b490..2f76de60ee77cb4adfa9fa64a821294c8de22354 100644 (file)
@@ -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)));
+}
index b93043f42fa0eac3eb7bae108c19fb6ed7137800..6bc4957f8c24abd1d876af0f6954c14c37a57f3e 100644 (file)
@@ -7,6 +7,7 @@
 #include <QtPlugin>
 
 #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<QObject *, FileData> m_instanceMap;
+  QObject m_player;
+  PlayerFeaturePlauginInterface *m_playerInterface;
+  int m_fid;
+  QString m_path;
+  double m_duration;
 };
 
 #endif // FEATURELOCALMYLIST_H
index 4ba679cb04b901b41d85a50ee7d68c99185e2e76..eaf22ec6c65ce18395cdda681b8d25a35da55cf7 100644 (file)
@@ -6,5 +6,6 @@
         <file>qml/SeekSlider.qml</file>
         <file>qml/PlaybackPosition.qml</file>
         <file>qml/VolumeSlider.qml</file>
+        <file>qml/TextWithBackground.qml</file>
     </qresource>
 </RCC>
diff --git a/uiplugins/ui_desktop_qml_default/qml/TextWithBackground.qml b/uiplugins/ui_desktop_qml_default/qml/TextWithBackground.qml
new file mode 100644 (file)
index 0000000..917a1c5
--- /dev/null
@@ -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
+    }
+}
index 973e198a439ff3e8894f15cdc660ec4b07f33e95..d1bb4c672c123320b7d99b197096bae17f13773f 100644 (file)
@@ -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
+        }
+    }
 }