[gupnp-tools] Added command line argument for friendly name



commit 3a80440755e2a5166e58c9208562834b107beb66
Author: ljsachs <larry j sachs intel com>
Date:   Mon Feb 22 09:38:19 2016 -0800

    Added command line argument for friendly name
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761967

 src/network-light/gui.c  |    7 ++++++-
 src/network-light/gui.h  |    3 ++-
 src/network-light/main.c |    6 ++++--
 src/network-light/upnp.c |   32 +++++++++++++++++++++++++++++---
 src/network-light/upnp.h |    2 +-
 5 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/src/network-light/gui.c b/src/network-light/gui.c
index 74c3ee3..d02d70b 100644
--- a/src/network-light/gui.c
+++ b/src/network-light/gui.c
@@ -191,7 +191,8 @@ on_delete_event (GtkWidget *widget,
 
 gboolean
 init_ui (gint   *argc,
-         gchar **argv[])
+         gchar **argv[],
+         gchar *name)
 {
         GdkPixbuf *icon_pixbuf;
         GError *error = NULL;
@@ -215,6 +216,10 @@ init_ui (gint   *argc,
                                                           "main-window"));
         g_assert (main_window != NULL);
 
+        if (name && (strlen(name) > 0)) {
+            gtk_window_set_title (GTK_WINDOW (main_window), name);
+        }
+
         about_dialog = GTK_WIDGET (gtk_builder_get_object (builder,
                                                            "about-dialog"));
         g_assert (about_dialog != NULL);
diff --git a/src/network-light/gui.h b/src/network-light/gui.h
index fde0063..1ab2f0c 100644
--- a/src/network-light/gui.h
+++ b/src/network-light/gui.h
@@ -28,7 +28,8 @@ update_image       (void);
 
 gboolean
 init_ui            (gint             *argc,
-                    gchar           **argv[]);
+                    gchar           **argv[],
+                    gchar            *name);
 
 void
 deinit_ui          (void);
diff --git a/src/network-light/main.c b/src/network-light/main.c
index 43d6baa..b5b2f2e 100644
--- a/src/network-light/main.c
+++ b/src/network-light/main.c
@@ -40,11 +40,13 @@ static gint     light_load_level;
 
 static int      upnp_port = 0;
 static char   **interfaces = NULL;
+static char    *name = NULL;
 
 static GOptionEntry entries[] =
 {
         { "port", 'p', 0, G_OPTION_ARG_INT, &upnp_port, N_("Network PORT to use for UPnP"), "PORT" },
         { "interface", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &interfaces, N_("Network interfaces to use for 
UPnP communication"), "INTERFACE" },
+        { "name", 'n', 0, G_OPTION_ARG_STRING, &name, N_("Friendly name for this UPnP light"), "NAME" },
         { NULL }
 };
 
@@ -107,11 +109,11 @@ main (int argc, char **argv)
                 return -4;
         }
 
-        if (!init_ui (&argc, &argv)) {
+        if (!init_ui (&argc, &argv, name)) {
                 return -1;
         }
 
-        if (!init_upnp (interfaces, upnp_port)) {
+        if (!init_upnp (interfaces, upnp_port, name)) {
                 return -2;
         }
 
diff --git a/src/network-light/upnp.c b/src/network-light/upnp.c
index ca55de6..1cb6682 100644
--- a/src/network-light/upnp.c
+++ b/src/network-light/upnp.c
@@ -378,12 +378,33 @@ xml_util_get_element (xmlNode *node,
         return node;
 }
 
+static void init_friendly_name (gchar *name)
+{
+        xmlNode *fdn_node;
+
+        fdn_node = xml_util_get_element ((xmlNode *) doc->doc,
+                                          "root",
+                                          "device",
+                                          "friendlyName",
+                                          NULL);
+        if (fdn_node == NULL) {
+                g_warning ("Failed to find friendly name element"
+                            "in device description, "
+                            "using default value");
+
+                return;
+        }
+
+        xmlNodeSetContent (fdn_node, (unsigned char *) name);
+}
+
 static void init_uuid (void)
 {
         xmlNode *uuid_node;
         char *udn;
 
         uuid = gupnp_get_uuid ();
+
         uuid_node = xml_util_get_element ((xmlNode *) doc->doc,
                                           "root",
                                           "device",
@@ -609,7 +630,7 @@ init_server (GUPnPContext *context)
 }
 
 static gboolean
-prepare_desc (void)
+prepare_desc (gchar *name)
 {
         GError *error = NULL;
 
@@ -624,6 +645,11 @@ prepare_desc (void)
                 return FALSE;
         }
 
+        if (name && (strlen(name) > 0)) {
+                /* set the friendlyName in the xmlDoc */
+                init_friendly_name (name);
+        }
+
         /* create and set the UUID in the xmlDoc */
         init_uuid ();
 
@@ -705,7 +731,7 @@ context_equal (GUPnPContext *context1, GUPnPContext *context2)
 }
 
 gboolean
-init_upnp (gchar **interfaces, guint port)
+init_upnp (gchar **interfaces, guint port, gchar *name)
 {
         GUPnPWhiteList *white_list;
 
@@ -717,7 +743,7 @@ init_upnp (gchar **interfaces, guint port)
                                          g_object_unref,
                                          (GDestroyNotify) network_light_free);
 
-        if (!prepare_desc ()) {
+        if (!prepare_desc (name)) {
                 return FALSE;
         }
 
diff --git a/src/network-light/upnp.h b/src/network-light/upnp.h
index 0f05f9e..4b4100a 100644
--- a/src/network-light/upnp.h
+++ b/src/network-light/upnp.h
@@ -30,7 +30,7 @@ void
 notify_load_level_change        (gint           load_level);
 
 gboolean
-init_upnp                       (gchar **interfaces, guint port);
+init_upnp                       (gchar **interfaces, guint port, gchar *name);
 
 void
 deinit_upnp                     (void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]