Commit 9ecbf214 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko
Browse files

glade: Support HdySwipeGroup



Do the same thing as for HdyHeaderGroup.
Signed-off-by: Alexander Mikhaylenko's avatarAlexander Mikhaylenko <alexm@gnome.org>
parent b791251b
/*
* Copyright (C) 2019 Alexander Mikhaylenko <exalm7659@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*
* Based on
* hdy-header-group.c - GladeWidgetAdaptor for HdyHeaderGroup
* Copyright (C) 2018 Purism SPC
* Copyright (C) 2013 Tristan Van Berkom
*/
#include "glade-hdy-swipe-group.h"
#include <config.h>
#include <glib/gi18n-lib.h>
#include <gladeui/glade.h>
#define PROP_SWIPEABLES "swipeables"
#define GLADE_TAG_SWIPEGROUP_SWIPEABLES "swipeables"
#define GLADE_TAG_SWIPEGROUP_SWIPEABLE "swipeable"
static void
glade_hdy_swipe_group_read_widgets (GladeWidget *widget,
GladeXmlNode *node)
{
GladeXmlNode *widgets_node;
GladeProperty *property;
gchar *string = NULL;
if ((widgets_node =
glade_xml_search_child (node, GLADE_TAG_SWIPEGROUP_SWIPEABLES)) != NULL) {
GladeXmlNode *n;
for (n = glade_xml_node_get_children (widgets_node);
n; n = glade_xml_node_next (n)) {
gchar *widget_name, *tmp;
if (!glade_xml_node_verify (n, GLADE_TAG_SWIPEGROUP_SWIPEABLE))
continue;
widget_name = glade_xml_get_property_string_required
(n, GLADE_TAG_NAME, NULL);
if (string == NULL) {
string = widget_name;
} else if (widget_name != NULL) {
tmp =
g_strdup_printf ("%s%s%s", string, GPC_OBJECT_DELIMITER,
widget_name);
string = (g_free (string), tmp);
g_free (widget_name);
}
}
}
if (string) {
property = glade_widget_get_property (widget, PROP_SWIPEABLES);
g_assert (property);
/* we must synchronize this directly after loading this project
* (i.e. lookup the actual objects after they've been parsed and
* are present).
*/
g_object_set_data_full (G_OBJECT (property),
"glade-loaded-object", string, g_free);
}
}
void
glade_hdy_swipe_group_read_widget (GladeWidgetAdaptor *adaptor,
GladeWidget *widget,
GladeXmlNode *node)
{
if (!(glade_xml_node_verify_silent (node, GLADE_XML_TAG_WIDGET) ||
glade_xml_node_verify_silent (node, GLADE_XML_TAG_TEMPLATE)))
return;
/* First chain up and read in all the normal properties.. */
GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
glade_hdy_swipe_group_read_widgets (widget, node);
}
static void
glade_hdy_swipe_group_write_widgets (GladeWidget *widget,
GladeXmlContext *context,
GladeXmlNode *node)
{
GladeXmlNode *widgets_node, *widget_node;
GList *widgets = NULL, *list;
GladeWidget *awidget;
widgets_node = glade_xml_node_new (context, GLADE_TAG_SWIPEGROUP_SWIPEABLES);
if (glade_widget_property_get (widget, PROP_SWIPEABLES, &widgets)) {
for (list = widgets; list; list = list->next) {
awidget = glade_widget_get_from_gobject (list->data);
widget_node =
glade_xml_node_new (context, GLADE_TAG_SWIPEGROUP_SWIPEABLE);
glade_xml_node_append_child (widgets_node, widget_node);
glade_xml_node_set_property_string (widget_node, GLADE_TAG_NAME,
glade_widget_get_name (awidget));
}
}
if (!glade_xml_node_get_children (widgets_node))
glade_xml_node_delete (widgets_node);
else
glade_xml_node_append_child (node, widgets_node);
}
void
glade_hdy_swipe_group_write_widget (GladeWidgetAdaptor *adaptor,
GladeWidget *widget,
GladeXmlContext *context,
GladeXmlNode *node)
{
if (!(glade_xml_node_verify_silent (node, GLADE_XML_TAG_WIDGET) ||
glade_xml_node_verify_silent (node, GLADE_XML_TAG_TEMPLATE)))
return;
/* First chain up and read in all the normal properties.. */
GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
glade_hdy_swipe_group_write_widgets (widget, context, node);
}
void
glade_hdy_swipe_group_set_property (GladeWidgetAdaptor *adaptor,
GObject *object,
const gchar *property_name,
const GValue *value)
{
if (!strcmp (property_name, PROP_SWIPEABLES)) {
GSList *sg_widgets, *slist;
GList *widgets, *list;
/* remove old widgets */
if ((sg_widgets =
hdy_swipe_group_get_swipeables (HDY_SWIPE_GROUP (object))) != NULL) {
/* copy since we are modifying an internal list */
sg_widgets = g_slist_copy (sg_widgets);
for (slist = sg_widgets; slist; slist = slist->next)
hdy_swipe_group_remove_swipeable (HDY_SWIPE_GROUP (object),
HDY_SWIPEABLE (slist->data));
g_slist_free (sg_widgets);
}
/* add new widgets */
if ((widgets = g_value_get_boxed (value)) != NULL) {
for (list = widgets; list; list = list->next)
hdy_swipe_group_add_swipeable (HDY_SWIPE_GROUP (object),
HDY_SWIPEABLE (list->data));
}
} else {
GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object,
property_name, value);
}
}
/*
* Copyright (C) 2019 Alexander Mikhaylenko <exalm7659@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*
* Based on
* hdy-header-group.h - GladeWidgetAdaptor for HdyHeaderGroup
* Copyright (C) 2018 Purism SPC
*/
#pragma once
#include <gladeui/glade.h>
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
void glade_hdy_swipe_group_set_property (GladeWidgetAdaptor *adaptor,
GObject *object,
const gchar *property_name,
const GValue *value);
void glade_hdy_swipe_group_write_widget (GladeWidgetAdaptor *adaptor,
GladeWidget *widget,
GladeXmlContext *context,
GladeXmlNode *node);
void glade_hdy_swipe_group_read_widget (GladeWidgetAdaptor *adaptor,
GladeWidget *widget,
GladeXmlNode *node);
......@@ -84,6 +84,20 @@
<glade-widget-class name="HdyPreferencesWindow" generic-name="preferenceswindow" title="Preferences Window" since="0.0.10"/>
<glade-widget-class name="HdySearchBar" generic-name="searchbar" title="Search Bar" since="0.0.6"/>
<glade-widget-class name="HdySqueezer" generic-name="squeezer" title="Squeezer" since="0.0.10"/>
<glade-widget-class name="HdySwipeGroup" generic-name="swipegroup" title="Swipe Group" toplevel="True">
<read-widget-function>glade_hdy_swipe_group_read_widget</read-widget-function>
<write-widget-function>glade_hdy_swipe_group_write_widget</write-widget-function>
<set-property-function>glade_hdy_swipe_group_set_property</set-property-function>
<properties>
<property id="swipeables" name="Widgets" save="False">
<parameter-spec>
<type>GladeParamObjects</type>
<value-type>HdySwipeable</value-type>
</parameter-spec>
<tooltip>List of widgets in this group</tooltip>
</property>
</properties>
</glade-widget-class>
<glade-widget-class name="HdyTitleBar" generic-name="titlebar" title="Title Bar"/>
<glade-widget-class name="HdyViewSwitcher" generic-name="viewswitcher" title="View Switcher" since="0.0.10"/>
<glade-widget-class name="HdyViewSwitcherBar" generic-name="viewswitcherbar" title="View Switcher Bar" since="0.0.10"/>
......@@ -107,6 +121,7 @@
<glade-widget-class-ref name="HdyPreferencesWindow"/>
<glade-widget-class-ref name="HdySearchBar"/>
<glade-widget-class-ref name="HdySqueezer"/>
<glade-widget-class-ref name="HdySwipeGroup"/>
<glade-widget-class-ref name="HdyTitleBar"/>
<glade-widget-class-ref name="HdyViewSwitcher"/>
<glade-widget-class-ref name="HdyViewSwitcherBar"/>
......
......@@ -20,6 +20,7 @@ endif
libglade_hdy_sources = [
'glade-hdy-header-group.c',
'glade-hdy-paginator.c',
'glade-hdy-swipe-group.c',
]
libglade_hdy_deps = [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment