[gupnp-tools/wip/search: 8/12] av-cp: Initial search dialog



commit 54b83dec52ebe871f8a627e1b28028c86d08daa9
Author: Jens Georg <mail jensge org>
Date:   Sun Jun 5 22:30:41 2016 +0200

    av-cp: Initial search dialog
    
    Provide basic dialog and hook it up with the TreeView's context menu

 data/Makefile.am              |    2 +-
 data/gupnp-av-cp.ui.in        |    9 +++
 data/search-dialog.ui         |  125 +++++++++++++++++++++++++++++++++++++++++
 src/av-cp/Makefile.am         |    4 +-
 src/av-cp/playlist-treeview.c |   41 +++++++++++++-
 src/av-cp/search-dialog.c     |   92 ++++++++++++++++++++++++++++++
 src/av-cp/search-dialog.h     |   44 ++++++++++++++
 7 files changed, 314 insertions(+), 3 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 7d40833..dfe289d 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -10,7 +10,7 @@ desktop_in_files = gupnp-universal-cp.desktop.in \
                   gupnp-network-light.desktop.in
 
 if BUILD_AV
-dist_shared_DATA += gupnp-av-cp.ui
+dist_shared_DATA += gupnp-av-cp.ui search-dialog.ui
 desktop_in_files += gupnp-av-cp.desktop.in
 endif
 
diff --git a/data/gupnp-av-cp.ui.in b/data/gupnp-av-cp.ui.in
index 2f55363..b405224 100644
--- a/data/gupnp-av-cp.ui.in
+++ b/data/gupnp-av-cp.ui.in
@@ -35,6 +35,15 @@
         <signal name="activate" handler="on_didl_menuitem_activate" swapped="no"/>
       </object>
     </child>
+    <child>
+      <object class="GtkMenuItem" id="search-menuitem">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Search…</property>
+        <property name="use_underline">True</property>
+        <signal name="activate" handler="on_search_menu_item_activated" swapped="no"/>
+      </object>
+    </child>
   </object>
   <object class="GtkTreeStore" id="playlist-tree-store">
     <columns>
diff --git a/data/search-dialog.ui b/data/search-dialog.ui
new file mode 100644
index 0000000..12b1415
--- /dev/null
+++ b/data/search-dialog.ui
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkListStore" id="search-dialog-listview">
+    <columns>
+      <!-- column-name icon -->
+      <column type="GdkPixbuf"/>
+      <!-- column-name title -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <template class="SearchDialog" parent="GtkDialog">
+    <property name="width_request">-1</property>
+    <property name="height_request">-1</property>
+    <property name="can_focus">False</property>
+    <property name="border_width">6</property>
+    <property name="default_width">400</property>
+    <property name="default_height">300</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton">
+                <property name="label" translatable="yes">_Close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_underline">True</property>
+                <signal name="clicked" handler="gtk_widget_hide" object="SearchDialog" swapped="yes"/>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">4</property>
+            <child>
+              <object class="GtkEntry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="primary_icon_name">edit-find</property>
+                <property name="secondary_icon_name">edit-clear</property>
+                <property name="placeholder_text" translatable="yes">UPnP search expression</property>
+                <signal name="activate" handler="search_dialog_on_search_activate" object="SearchDialog" 
swapped="yes"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScrolledWindow">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="shadow_type">in</property>
+                <child>
+                  <object class="GtkTreeView" id="search-dialog-treeview">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="model">search-dialog-listview</property>
+                    <property name="headers_visible">False</property>
+                    <child internal-child="selection">
+                      <object class="GtkTreeSelection"/>
+                    </child>
+                    <child>
+                      <object class="GtkTreeViewColumn">
+                        <property name="title" translatable="yes">column</property>
+                        <child>
+                          <object class="GtkCellRendererPixbuf"/>
+                          <attributes>
+                            <attribute name="pixbuf">0</attribute>
+                          </attributes>
+                        </child>
+                        <child>
+                          <object class="GtkCellRendererText">
+                            <property name="xpad">6</property>
+                          </object>
+                          <attributes>
+                            <attribute name="text">1</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/av-cp/Makefile.am b/src/av-cp/Makefile.am
index b1f8db6..621b655 100644
--- a/src/av-cp/Makefile.am
+++ b/src/av-cp/Makefile.am
@@ -26,7 +26,9 @@ gupnp_av_cp_SOURCES = main.c \
                      renderer-combo.h \
                      renderer-controls.h \
                          server-device.c \
-                         server-device.h
+                         server-device.h \
+                         search-dialog.c \
+                         search-dialog.h
 
 gupnp_av_cp_LDADD = ../common/libutil.a \
                    $(LIBGSSDP_LIBS) \
diff --git a/src/av-cp/playlist-treeview.c b/src/av-cp/playlist-treeview.c
index f198e37..76dc9fa 100644
--- a/src/av-cp/playlist-treeview.c
+++ b/src/av-cp/playlist-treeview.c
@@ -34,6 +34,7 @@
 #include "pretty-print.h"
 #include "gui.h"
 #include "server-device.h"
+#include "search-dialog.h"
 
 #define CONTENT_DIR "urn:schemas-upnp-org:service:ContentDirectory"
 
@@ -54,6 +55,7 @@ static GtkWidget *didl_dialog;
 static GtkWidget *didl_textview;
 static gboolean   expanded;
 static GHashTable *initial_notify;
+static GtkDialog *search_dialog;
 
 gboolean
 on_playlist_treeview_button_release (GtkWidget      *widget,
@@ -78,6 +80,10 @@ void
 on_didl_menuitem_activate (GtkMenuItem *menuitem,
                            gpointer     user_data);
 
+void
+on_search_menu_item_activated (GtkMenuItem *menuitem,
+                               gpointer     user_data);
+
 static void
 on_proxy_ready (GObject *source_object,
                 GAsyncResult *res,
@@ -303,6 +309,40 @@ on_didl_menuitem_activate (GtkMenuItem *menuitem,
         get_selected_object (display_metadata, NULL);
 }
 
+G_MODULE_EXPORT
+void
+on_search_menu_item_activated (GtkMenuItem *menuitem,
+                               gpointer     user_data)
+{
+    AVCPMediaServer   *server;
+    GtkTreeSelection  *selection;
+    GtkTreeModel      *model;
+    GtkTreeIter        iter;
+    char              *id = NULL;
+
+    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+    g_assert (selection != NULL);
+
+    if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
+        return;
+    }
+
+    gtk_tree_model_get (model,
+                        &iter,
+                        2, &server,
+                        4, &id,
+                        -1);
+
+    if (search_dialog == NULL) {
+        search_dialog = GTK_DIALOG (g_object_new (SEARCH_DIALOG_TYPE, NULL));
+    }
+
+    search_dialog_set_server (SEARCH_DIALOG (search_dialog), server);
+    search_dialog_set_container_id (SEARCH_DIALOG (search_dialog), id);
+
+    gtk_dialog_run (search_dialog);
+}
+
 void
 setup_playlist_treeview (GtkBuilder *builder)
 {
@@ -344,7 +384,6 @@ setup_playlist_treeview (GtkBuilder *builder)
                                           GTK_TEXT_BUFFER (buffer));
         }
 #endif
-
         expanded = FALSE;
 }
 
diff --git a/src/av-cp/search-dialog.c b/src/av-cp/search-dialog.c
new file mode 100644
index 0000000..4a22c7e
--- /dev/null
+++ b/src/av-cp/search-dialog.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2016 Jens Georg <mail jensge org>
+ *
+ * Authors: Jens Georg <mail jensge org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "search-dialog.h"
+#include "server-device.h"
+
+struct _SearchDialog {
+        GtkDialog parent;
+};
+
+struct _SearchDialogClass {
+        GtkDialogClass parent_class;
+};
+
+struct _SearchDialogPrivate {
+        char *id;
+        AVCPMediaServer *server;
+};
+
+typedef struct _SearchDialogPrivate SearchDialogPrivate;
+G_DEFINE_TYPE_WITH_PRIVATE (SearchDialog, search_dialog, GTK_TYPE_DIALOG)
+
+void
+search_dialog_on_search_activate (SearchDialog *self, GtkEntry *entry);
+
+static void
+search_dialog_class_init (SearchDialogClass *klass)
+{
+        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+        GError *error = NULL;
+        gchar *data = NULL;
+        gsize size = -1;
+        GBytes *bytes;
+
+        g_file_get_contents (DATA_DIR "/search-dialog.ui", &data, &size, &error);
+        if (error != NULL) {
+                g_critical ("Failed to load ui file: %s", error->message);
+                g_error_free (error);
+
+                return;
+        }
+
+        bytes = g_bytes_new_take (data, size);
+        gtk_widget_class_set_template (widget_class, bytes);
+        g_bytes_unref (bytes);
+}
+
+static void
+search_dialog_init (SearchDialog *self)
+{
+        gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+void
+search_dialog_set_server (SearchDialog *self, AVCPMediaServer *server)
+{
+        SearchDialogPrivate *priv = search_dialog_get_instance_private (self);
+
+        priv->server = server;
+}
+
+void
+search_dialog_set_container_id (SearchDialog *self, char *id)
+{
+        SearchDialogPrivate *priv = search_dialog_get_instance_private (self);
+
+        priv->id = id;
+}
+
+G_MODULE_EXPORT
+void
+search_dialog_on_search_activate (SearchDialog *self, GtkEntry *entry)
+{
+        g_print ("==> %s\n", gtk_entry_get_text (entry));
+}
diff --git a/src/av-cp/search-dialog.h b/src/av-cp/search-dialog.h
new file mode 100644
index 0000000..ce009b1
--- /dev/null
+++ b/src/av-cp/search-dialog.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2016 Jens Georg <mail jensge org>
+ *
+ * Authors: Jens Georg <mail jensge org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SEARCH_DIALOG_H
+#define SEARCH_DIALOG_H
+
+#include <gtk/gtk.h>
+
+#include "server-device.h"
+
+#define SEARCH_DIALOG_TYPE (search_dialog_get_type ())
+#define SEARCH_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                            SEARCH_DIALOG_TYPE, \
+                            SearchDialog))
+
+typedef struct _SearchDialog SearchDialog;
+typedef struct _SearchDialogClass SearchDialogClass;
+
+GType search_dialog_get_type (void);
+
+void
+search_dialog_set_server (SearchDialog *self, AVCPMediaServer *server);
+
+void
+search_dialog_set_container_id (SearchDialog *self, char *id);
+
+#endif /* SEARCH_DIALOG_H */


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