[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 01/01: Use correct player names and icons in the preferences dialog

noreply at xfce.org noreply at xfce.org
Tue Mar 20 01:49:37 CET 2018


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-pulseaudio-plugin.

commit 1e1166edc34b4e070d4022761a905e4159cba6b8
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Mon Mar 19 20:49:31 2018 -0400

    Use correct player names and icons in the preferences dialog
---
 panel-plugin/mprismenuitem.c         | 79 ++++-----------------------------
 panel-plugin/pulseaudio-dialog.c     | 20 ++++++---
 panel-plugin/pulseaudio-dialog.glade |  8 ++--
 panel-plugin/pulseaudio-mpris.c      | 86 ++++++++++++++++++++++++++++++++++++
 panel-plugin/pulseaudio-mpris.h      |  5 +++
 5 files changed, 119 insertions(+), 79 deletions(-)

diff --git a/panel-plugin/mprismenuitem.c b/panel-plugin/mprismenuitem.c
index 9e42450..e193f67 100644
--- a/panel-plugin/mprismenuitem.c
+++ b/panel-plugin/mprismenuitem.c
@@ -29,6 +29,7 @@
 #endif
 
 #include "mprismenuitem.h"
+#include "pulseaudio-mpris.h"
 
 #include <gdk/gdk.h>
 #include <gdk/gdkkeysyms.h>
@@ -114,7 +115,6 @@ static void         gtk_label_set_markup_printf_escaped     (GtkLabel       *lab
                                                              const gchar    *format,
                                                                              ...);
 static void         update_packing                          (MprisMenuItem  *item);
-static gchar *      find_desktop_entry                      (const gchar    *player_name);
 
 
 
@@ -156,34 +156,16 @@ GtkWidget*
 mpris_menu_item_new_from_player_name (const gchar *player)
 {
   GtkWidget *widget = NULL;
-  GKeyFile  *key_file;
-  gchar     *file;
-  gchar     *filename;
+  gchar     *name;
+  gchar     *icon_name;
   gchar     *full_path;
 
-  filename = find_desktop_entry (player);
-  if (filename == NULL)
-    {
-      return NULL;
-    }
-
-  file = g_strconcat("applications/", filename, NULL);
-  g_free (filename);
-
-  key_file = g_key_file_new();
-  if (g_key_file_load_from_data_dirs (key_file, file, &full_path, G_KEY_FILE_NONE, NULL))
-    {
-      gchar *name = g_key_file_get_string (key_file, "Desktop Entry", "Name", NULL);
-      gchar *icon_name = g_key_file_get_string (key_file, "Desktop Entry", "Icon", NULL);
-
-      widget = mpris_menu_item_new_with_player (player, name, icon_name, full_path);
-
-      g_free (name);
-      g_free (icon_name);
-    }
-
-  g_key_file_free (key_file);
-  g_free (file);
+  if (pulseaudio_mpris_get_player_summary (player, &name, &icon_name, &full_path)) {
+    widget = mpris_menu_item_new_with_player (player, name, icon_name, full_path);
+    g_free (name);
+    g_free (icon_name);
+    g_free (full_path);
+  }
 
   return widget;
 }
@@ -844,46 +826,3 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 
   gtk_container_add (GTK_CONTAINER (item), priv->hbox);
 }
-
-
-
-static gchar *
-find_desktop_entry (const gchar *player_name)
-{
-  GKeyFile  *key_file;
-  gchar     *file;
-  gchar     *filename = NULL;
-  gchar     *full_path;
-
-  file = g_strconcat ("applications/", player_name, ".desktop", NULL);
-
-  key_file = g_key_file_new();
-  if (g_key_file_load_from_data_dirs (key_file, file, &full_path, G_KEY_FILE_NONE, NULL))
-    {
-      filename = g_strconcat (player_name, ".desktop", NULL);
-    }
-  else
-    {
-      /* Support reverse domain name (RDN) formatted launchers. */
-      gchar ***results = g_desktop_app_info_search (player_name);
-      gint i, j;
-
-      for (i = 0; results[i]; i++)
-        {
-          for (j = 0; results[i][j]; j++)
-            {
-              if (filename == NULL)
-                {
-                  filename = g_strdup (results[i][j]);
-                }
-            }
-          g_strfreev (results[i]);
-      }
-      g_free (results);
-    }
-
-  g_key_file_free (key_file);
-  g_free (file);
-
-  return filename;
-}
diff --git a/panel-plugin/pulseaudio-dialog.c b/panel-plugin/pulseaudio-dialog.c
index 2c37f12..8e2fe37 100644
--- a/panel-plugin/pulseaudio-dialog.c
+++ b/panel-plugin/pulseaudio-dialog.c
@@ -42,6 +42,7 @@
 
 #include "pulseaudio-dialog.h"
 #include "pulseaudio-dialog_ui.h"
+#include "pulseaudio-mpris.h"
 
 #define PLUGIN_WEBSITE  "https://docs.xfce.org/apps/pulseaudio-plugin/start"
 
@@ -164,11 +165,11 @@ pulseaudio_dialog_player_toggled_cb (GtkCellRendererToggle *toggle, gchar *path,
   gtk_tree_model_get_iter (model, &iter, treepath);
 
   gtk_tree_model_get_value (model, &iter, 1, &player_val);
-  gtk_tree_model_get_value (model, &iter, 2, &hidden_val);
+  gtk_tree_model_get_value (model, &iter, 3, &hidden_val);
   hidden = !g_value_get_boolean(&hidden_val);
   player = g_value_get_string(&player_val);
 
-  gtk_list_store_set(GTK_LIST_STORE(model), &iter, 2, hidden, -1);
+  gtk_list_store_set(GTK_LIST_STORE(model), &iter, 3, hidden, -1);
 
   if (hidden)
     pulseaudio_config_player_blacklist_add (dialog->config, player);
@@ -294,12 +295,19 @@ pulseaudio_dialog_build (PulseaudioDialog *dialog)
         {
           for (i = 0; i < g_strv_length (players); i++)
             {
-              gtk_list_store_append(liststore, &iter);
-              gtk_list_store_set(liststore, &iter,
-                                 0, players[i],
+              gchar *name = NULL;
+              gchar *icon_name = NULL;
+              gchar *full_path = NULL;
+
+              if (pulseaudio_mpris_get_player_summary (players[i], &name, &icon_name, &full_path)) {
+                gtk_list_store_append(liststore, &iter);
+                gtk_list_store_set(liststore, &iter,
+                                 0, icon_name,
                                  1, players[i],
-                                 2, pulseaudio_config_player_blacklist_lookup(dialog->config, players[i]),
+                                 2, name,
+                                 3, pulseaudio_config_player_blacklist_lookup(dialog->config, players[i]),
                                  -1);
+              }
             }
         }
       g_strfreev (players);
diff --git a/panel-plugin/pulseaudio-dialog.glade b/panel-plugin/pulseaudio-dialog.glade
index 1a6d33d..4f61bb9 100644
--- a/panel-plugin/pulseaudio-dialog.glade
+++ b/panel-plugin/pulseaudio-dialog.glade
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.2 -->
+<!-- Generated with glade 3.22.0 -->
 <interface>
   <requires lib="gtk+" version="3.20"/>
   <requires lib="libxfce4ui-2" version="4.11"/>
@@ -17,6 +17,8 @@
     <columns>
       <!-- column-name icon_name -->
       <column type="gchararray"/>
+      <!-- column-name player -->
+      <column type="gchararray"/>
       <!-- column-name label -->
       <column type="gchararray"/>
       <!-- column-name hidden -->
@@ -425,7 +427,7 @@
                                         <child>
                                           <object class="GtkCellRendererText" id="col_label_renderer"/>
                                           <attributes>
-                                            <attribute name="text">1</attribute>
+                                            <attribute name="text">2</attribute>
                                           </attributes>
                                         </child>
                                       </object>
@@ -436,7 +438,7 @@
                                         <child>
                                           <object class="GtkCellRendererToggle" id="col_hidden_renderer"/>
                                           <attributes>
-                                            <attribute name="active">2</attribute>
+                                            <attribute name="active">3</attribute>
                                           </attributes>
                                         </child>
                                       </object>
diff --git a/panel-plugin/pulseaudio-mpris.c b/panel-plugin/pulseaudio-mpris.c
index eb20044..7413b95 100644
--- a/panel-plugin/pulseaudio-mpris.c
+++ b/panel-plugin/pulseaudio-mpris.c
@@ -24,6 +24,7 @@
 #include <gio/gio.h>
 #include <glib.h>
 #include <gtk/gtk.h>
+#include <gio/gdesktopappinfo.h>
 
 #include "pulseaudio-mpris.h"
 #include "pulseaudio-mpris-player.h"
@@ -66,6 +67,54 @@ G_DEFINE_TYPE (PulseaudioMpris, pulseaudio_mpris, G_TYPE_OBJECT)
 
 
 
+static gchar *
+find_desktop_entry (const gchar *player_name)
+{
+  GKeyFile  *key_file;
+  gchar     *file = NULL;
+  gchar     *filename = NULL;
+  gchar     *full_path = NULL;
+
+  file = g_strconcat ("applications/", player_name, ".desktop", NULL);
+
+  key_file = g_key_file_new();
+  if (g_key_file_load_from_data_dirs (key_file, file, &full_path, G_KEY_FILE_NONE, NULL))
+    {
+      filename = g_strconcat (player_name, ".desktop", NULL);
+    }
+  else
+    {
+      /* Support reverse domain name (RDN) formatted launchers. */
+      gchar ***results = g_desktop_app_info_search (player_name);
+      gint i, j;
+
+      for (i = 0; results[i]; i++)
+        {
+          for (j = 0; results[i][j]; j++)
+            {
+              if (filename == NULL)
+                {
+                  filename = g_strdup (results[i][j]);
+                }
+            }
+          g_strfreev (results[i]);
+      }
+      g_free (results);
+    }
+
+  g_key_file_free (key_file);
+
+  if (file)
+    g_free (file);
+
+  if (full_path)
+    g_free (full_path);
+
+  return filename;
+}
+
+
+
 static void
 pulseaudio_mpris_class_init (PulseaudioMprisClass *klass)
 {
@@ -265,6 +314,43 @@ pulseaudio_mpris_get_player_snapshot (PulseaudioMpris  *mpris,
 
 
 gboolean
+pulseaudio_mpris_get_player_summary (const gchar  *player,
+                                     gchar       **name,
+                                     gchar       **icon_name,
+                                     gchar       **full_path)
+{
+  GKeyFile  *key_file;
+  gchar     *file;
+  gchar     *filename;
+  gchar     *path;
+
+  filename = find_desktop_entry (player);
+  if (filename == NULL)
+    {
+      return FALSE;
+    }
+
+  file = g_strconcat("applications/", filename, NULL);
+  g_free (filename);
+
+  key_file = g_key_file_new();
+  if (g_key_file_load_from_data_dirs (key_file, file, &path, G_KEY_FILE_NONE, NULL))
+    {
+      *name = g_key_file_get_string (key_file, "Desktop Entry", "Name", NULL);
+      *icon_name = g_key_file_get_string (key_file, "Desktop Entry", "Icon", NULL);
+      *full_path = g_strdup (path);
+      g_free (path);
+    }
+
+  g_key_file_free (key_file);
+  g_free (file);
+
+  return TRUE;
+}
+
+
+
+gboolean
 pulseaudio_mpris_notify_player (PulseaudioMpris  *mpris,
                                 const gchar      *name,
                                 const gchar      *message)
diff --git a/panel-plugin/pulseaudio-mpris.h b/panel-plugin/pulseaudio-mpris.h
index 6ba6c17..e681627 100644
--- a/panel-plugin/pulseaudio-mpris.h
+++ b/panel-plugin/pulseaudio-mpris.h
@@ -55,6 +55,11 @@ gboolean                pulseaudio_mpris_get_player_snapshot   (PulseaudioMpris
                                                                 gboolean         *can_raise,
                                                                 GList           **playlists);
 
+gboolean                pulseaudio_mpris_get_player_summary    (const gchar      *player,
+                                                                gchar           **name,
+                                                                gchar           **icon_name,
+                                                                gchar           **full_path);
+
 gboolean                pulseaudio_mpris_notify_player         (PulseaudioMpris  *mpris,
                                                                 const gchar      *name,
                                                                 const gchar      *message);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list