[gupnp-tools/wip/search: 2/3] wip: Search dialog



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

    wip: Search dialog

 data/Makefile.am              |    2 +-
 data/search-dialog.ui         |  124 +++++++++++++++++++++++++++++++++++++++++
 src/av-cp/Makefile.am         |    4 +-
 src/av-cp/playlist-treeview.c |   41 +++++++++++++-
 src/av-cp/search-dialog.c     |   73 ++++++++++++++++++++++++
 src/av-cp/search-dialog.h     |   44 ++++++++++++++
 6 files changed, 285 insertions(+), 3 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index f682cd6..dc23a75 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/search-dialog.ui b/data/search-dialog.ui
new file mode 100644
index 0000000..83ec243
--- /dev/null
+++ b/data/search-dialog.ui
@@ -0,0 +1,124 @@
+<?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="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="search-dialog" 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>
+            <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>
+    <child>
+      <placeholder/>
+    </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..1bbedf1
--- /dev/null
+++ b/src/av-cp/search-dialog.c
@@ -0,0 +1,73 @@
+#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]