]> Some of my projects - aniplayer.git/commitdiff
Add displayTitle
authorAPTX <marek321@gmail.com>
Mon, 21 Feb 2022 13:19:45 +0000 (22:19 +0900)
committerAPTX <marek321@gmail.com>
Mon, 21 Feb 2022 13:19:45 +0000 (22:19 +0900)
core/player.cpp
core/player.h

index 73654fe3be53ad019fd47c15c441439739876edd..559c7743cad7f56efae3e9931149c8ad525fee3b 100644 (file)
@@ -50,6 +50,9 @@ Player::Player(BackendPluginBase *backendPlugin, QObject *parent)
   Q_CHECK_PTR(m_playlist);
   connect(m_playlist, SIGNAL(currentChanged(PlaylistEntry)), this,
           SLOT(playPlaylistEntry(PlaylistEntry)));
+
+  connect(this, SIGNAL(currentSourceChanged(QUrl)), this,
+          SLOT(notifyDisplayTitleChanged()));
 }
 
 Player::~Player() {
@@ -67,6 +70,10 @@ QUrl Player::currentSource() const { return m_currentSource; }
 
 QUrl Player::nextSource() const { return m_nextSource; }
 
+QString Player::displayTitle() const {
+  return currentSource().isValid() ? currentSource().fileName() : tr("none");
+}
+
 Player::PlayState Player::state() const { return m_state; }
 
 Player::Volume Player::volume() const { return m_volume; }
@@ -376,6 +383,10 @@ void Player::playNextPlaylistEntryOnEndOfFile() {
   m_playlist->next();
 }
 
+void Player::notifyDisplayTitleChanged() {
+  emit displayTitleChanged(displayTitle());
+}
+
 bool Player::canLoadVideoNow() const {
   return m_backendInstanceReady && m_renderer && m_rendererReady;
 }
index b6d29185d5ef7afd6907daa437c00d1b1034cf0e..6d891cd9cf6c596e4418ea5037cd573815a807b5 100644 (file)
@@ -24,6 +24,9 @@ class Player : public QObject,
   Q_PROPERTY(QUrl nextSource READ nextSource WRITE setNextSource NOTIFY
                  nextSourceChanged)
 
+  Q_PROPERTY(QString displayTitle READ displayTitle NOTIFY displayTitleChanged
+                 STORED false)
+
   Q_PROPERTY(double duration READ duration NOTIFY durationChanged)
   Q_PROPERTY(double position READ position WRITE seek NOTIFY positionChanged)
 
@@ -84,6 +87,8 @@ public:
   QUrl currentSource() const;
   QUrl nextSource() const;
 
+  QString displayTitle() const;
+
   PlayState state() const;
   Volume volume() const;
   Volume maxVolume() const;
@@ -127,6 +132,8 @@ signals:
   void currentSourceChanged(QUrl currentSource);
   void nextSourceChanged(QUrl nextSource);
 
+  void displayTitleChanged(QString displayTitle);
+
   void durationChanged(double duration);
   void positionChanged(double position);
 
@@ -200,6 +207,7 @@ private slots:
   void onNewFrame();
   void playPlaylistEntry(const PlaylistEntry &entry);
   void playNextPlaylistEntryOnEndOfFile();
+  void notifyDisplayTitleChanged();
 
 private:
   bool canLoadVideoNow() const;