[libgd/wip/rishi/main-box: 3/8] Add GdMainBoxGeneric



commit a1bdda6e7a528cf763cd00e4f582434cc09b0378
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Dec 1 15:51:11 2016 +0100

    Add GdMainBoxGeneric
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774914

 libgd/gd-main-box-generic.c |  157 +++++++++++++++++++++++++++++++++++++++++++
 libgd/gd-main-box-generic.h |   49 +++++++++++++
 2 files changed, 206 insertions(+), 0 deletions(-)
---
diff --git a/libgd/gd-main-box-generic.c b/libgd/gd-main-box-generic.c
new file mode 100644
index 0000000..e8f2e5d
--- /dev/null
+++ b/libgd/gd-main-box-generic.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser 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 Lesser General Public 
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License 
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ *
+ */
+
+#include "gd-main-box-generic.h"
+
+enum
+{
+  VIEW_SELECTION_CHANGED,
+  NUM_SIGNALS
+};
+
+static guint signals[NUM_SIGNALS] = { 0, };
+
+G_DEFINE_INTERFACE (GdMainBoxGeneric, gd_main_box_generic, GTK_TYPE_WIDGET)
+
+static void
+gd_main_box_generic_default_init (GdMainBoxGenericInterface *iface)
+{
+  GParamSpec *pspec;
+
+  /**
+   * GdMainBoxGeneric:model:
+   *
+   * A #GListModel that is rendered by the #GdMainBoxGeneric widget.
+   */
+  pspec = g_param_spec_object ("model",
+                               "Model",
+                               "A model that is rendered by the widget",
+                               G_TYPE_LIST_MODEL,
+                               G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_interface_install_property (iface, pspec);
+
+  /**
+   * GdMainBoxGeneric:selection-mode:
+   *
+   * Whether the #GdMainBoxGeneric widget is in selection mode.
+   */
+  pspec = g_param_spec_object ("selection-mode",
+                               "Selection Mode",
+                               "Whether the widget is in selection mode",
+                               FALSE,
+                               G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_interface_install_property (iface, pspec);
+
+  signals[VIEW_SELECTION_CHANGED] = g_signal_new ("view-selection-changed",
+                                                  GD_TYPE_MAIN_BOX_GENERIC,
+                                                  G_SIGNAL_RUN_LAST,
+                                                  0,
+                                                  NULL,
+                                                  NULL,
+                                                  g_cclosure_marshal_VOID__VOID,
+                                                  G_TYPE_NONE,
+                                                  0);
+}
+
+/**
+ * gd_main_box_generic_get_child_at_index:
+ * @self:
+ * @index:
+ *
+ * Returns: (transfer none): The child at @index.
+ */
+GtkWidget *
+gd_main_box_generic_get_child_at_index (GdMainBoxGeneric *self, gint index)
+{
+  GdMainBoxGenericInterface *iface;
+
+  g_return_val_if_fail (GD_IS_MAIN_BOX_GENERIC (self), NULL);
+
+  iface = GD_MAIN_BOX_GENERIC_GET_IFACE (self);
+
+  return (* iface->get_child_at_index) (self, index);
+}
+
+/**
+ * gd_main_box_generic_get_model:
+ * @self:
+ *
+ * Returns: (transfer none): The associated model
+ */
+GListModel *
+gd_main_box_generic_get_model (GdMainBoxGeneric *self)
+{
+  GListModel *model;
+
+  g_return_val_if_fail (GD_IS_MAIN_BOX_GENERIC (self), NULL);
+
+  g_object_get (self, "model", &model, NULL);
+
+  if (model != NULL)
+    g_object_unref (model);
+
+  return model;
+}
+
+/**
+ * gd_main_box_generic_get_selection_mode:
+ * @self:
+ *
+ * Returns: (transfer none): Whether @self is in selection mode
+ */
+gboolean
+gd_main_box_generic_get_selection_mode (GdMainBoxGeneric *self)
+{
+  gboolean selection_mode;
+
+  g_return_val_if_fail (GD_IS_MAIN_BOX_GENERIC (self), FALSE);
+
+  g_object_get (self, "selection-mode", &selection_mode, NULL);
+  return selection_mode;
+}
+
+/**
+ * gd_main_box_generic_set_model:
+ * @self:
+ * @model: (allow-none):
+ *
+ */
+void
+gd_main_box_generic_set_model (GdMainBoxGeneric *self, GListModel *model)
+{
+  g_return_if_fail (GD_IS_MAIN_BOX_GENERIC (self));
+  g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
+
+  g_object_set (self, "model", model, NULL);
+}
+
+/**
+ * gd_main_box_generic_set_selection_mode:
+ * @self:
+ * @selection_mode:
+ *
+ */
+void
+gd_main_box_generic_set_selection_mode (GdMainBoxGeneric *self, gboolean selection_mode)
+{
+  g_return_if_fail (GD_IS_MAIN_BOX_GENERIC (self));
+  g_object_set (self, "selection-mode", selection_mode, NULL);
+}
diff --git a/libgd/gd-main-box-generic.h b/libgd/gd-main-box-generic.h
new file mode 100644
index 0000000..9a5f35c
--- /dev/null
+++ b/libgd/gd-main-box-generic.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser 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 Lesser General Public 
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License 
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ *
+ */
+
+#ifndef __GD_MAIN_BOX_GENERIC_H__
+#define __GD_MAIN_BOX_GENERIC_H__
+
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GD_TYPE_MAIN_BOX_GENERIC gd_main_box_generic_get_type()
+G_DECLARE_INTERFACE (GdMainBoxGeneric, gd_main_box_generic, GD, MAIN_BOX_GENERIC, GtkWidget)
+
+struct _GdMainBoxGenericInterface
+{
+  GTypeInterface base_iface;
+
+  /* vtable */
+  GtkWidget   * (* get_child_at_index)  (GdMainBoxGeneric *self, gint index);
+};
+
+GtkWidget   * gd_main_box_generic_get_child_at_index  (GdMainBoxGeneric *self, gint index);
+GListModel  * gd_main_box_generic_get_model           (GdMainBoxGeneric *self);
+gboolean      gd_main_box_generic_get_selection_mode  (GdMainBoxGeneric *self);
+void          gd_main_box_generic_set_model           (GdMainBoxGeneric *self, GListModel *model);
+void          gd_main_box_generic_set_selection_mode  (GdMainBoxGeneric *self, gboolean selection_mode);
+
+G_END_DECLS
+
+#endif /* __GD_MAIN_BOX_GENERIC_H__ */


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