File fix-support-for-vlc-2.x.patch of Package kaffeine

From 402cbee5e675cf795b619b834f92aac086972afc Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Date: Fri, 3 May 2019 08:41:36 -0300
Subject: vlc: fix support for vlc 2.x

As reported by Wolfgang, the changes made on Kaffeine 2.0.16 to
solve issues with audio CDs broke Kaffeine when building it with
legacy vlc 2.2.x.

The fix here is simple: just place two libVlc 3.0 events at the
print logic inside the Vlc3 block is enough to make it build
again.

The libvlc_MediaMetaChanged is used to report when a new media is
playing.

With vlc 2.0, such event should be enabled only inside mediaPlay()
routine. Doing it early causes the play to not work.

So, re-add such logic, with got removed on changeset d03abc77ad40
("backend-vlc: simplify events handling logic").

BUG: 407153

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
---
 src/backend-vlc/vlcmediawidget.cpp | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/backend-vlc/vlcmediawidget.cpp b/src/backend-vlc/vlcmediawidget.cpp
index e47a44d..7917417 100644
--- a/src/backend-vlc/vlcmediawidget.cpp
+++ b/src/backend-vlc/vlcmediawidget.cpp
@@ -113,10 +113,6 @@ const char *vlcEventName(int event)
 		return "MediaListPlayerNextItemSet";
 	case libvlc_MediaListPlayerStopped:
 		return "MediaListPlayerStopped";
-	case libvlc_RendererDiscovererItemAdded:
-		return "RendererDiscovererItemAdded";
-	case libvlc_RendererDiscovererItemDeleted:
-		return "RendererDiscovererItemDeleted";
 	case libvlc_VlmMediaAdded:
 		return "VlmMediaAdded";
 	case libvlc_VlmMediaRemoved:
@@ -140,6 +136,10 @@ const char *vlcEventName(int event)
 	case libvlc_VlmMediaInstanceStatusError:
 		return "VlmMediaInstanceStatusError";
 #if LIBVLC_VERSION_MAJOR > 2
+	case libvlc_RendererDiscovererItemAdded:
+		return "RendererDiscovererItemAdded";
+	case libvlc_RendererDiscovererItemDeleted:
+		return "RendererDiscovererItemDeleted";
 	case libvlc_MediaPlayerAudioVolume:
 		return "MediaPlayerAudioVolume";
 	case libvlc_MediaPlayerAudioDevice:
@@ -171,17 +171,17 @@ VlcMediaWidget::VlcMediaWidget(QWidget *parent) : AbstractMediaWidget(parent),
     typeOfDevice(""), trackNumber(1), numTracks(1)
 {
 	libvlc_event_e events[] = {
-		libvlc_MediaMetaChanged,
 		libvlc_MediaPlayerEncounteredError,
 		libvlc_MediaPlayerEndReached,
 		libvlc_MediaPlayerLengthChanged,
 		libvlc_MediaPlayerSeekableChanged,
 		libvlc_MediaPlayerStopped,
+		libvlc_MediaPlayerTimeChanged,
 #if LIBVLC_VERSION_MAJOR > 2
+		libvlc_MediaMetaChanged,
 		libvlc_MediaPlayerESAdded,
 		libvlc_MediaPlayerESDeleted,
 #endif
-		libvlc_MediaPlayerTimeChanged,
 #if 0 // all other possible events
 		libvlc_MediaSubItemAdded,
 		libvlc_MediaDurationChanged,
@@ -558,6 +558,10 @@ void VlcMediaWidget::unregisterEvents()
 	for (int i = 0; i < eventType.size(); ++i)
 		libvlc_event_detach(eventManager, eventType.at(i),
 				    vlcEventHandler, this);
+#if LIBVLC_VERSION_MAJOR <= 2
+	libvlc_event_detach(eventManager, libvlc_MediaMetaChanged,
+			    vlcEventHandler, this);
+#endif
 }
 
 bool VlcMediaWidget::registerEvents()
@@ -578,6 +582,16 @@ int VlcMediaWidget::makePlay()
 		return -1;
 	}
 
+#if LIBVLC_VERSION_MAJOR <= 2
+	// For libVlc 2.x to work, we need to add the
+	// MediaMetaChanged event only here
+	if (libvlc_event_attach(eventManager, libvlc_MediaMetaChanged,
+				vlcEventHandler, this) != 0) {
+		qCWarning(logMediaWidget, "Cannot attach event handler %d",
+			  libvlc_MediaMetaChanged);
+	}
+#endif
+
 	libvlc_media_player_set_media(vlcMediaPlayer, vlcMedia);
 
 	/*
-- 
cgit v1.1

openSUSE Build Service is sponsored by