This repository has been archived on 2024-07-15. You can view files and clone it, but cannot push or open issues or pull requests.
hedera/glade/glade-db-model-editor.c

137 lines
4.3 KiB
C

/*
* Copyright (C) 2014 - Juan Ferrer Toribio
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "glade-db-model-editor.h"
//+++++++++++++++++++++++++++++++++++++++++++++++++++ GladeModelEditor
GtkWidget * glade_model_editor_new (GladeWidgetAdaptor * adaptor,
GladeEditable * editable)
{
GladeModelEditor * obj;
GladeEditorProperty * eprop;
GtkWidget * frame, * alignment, * vbox;
g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
g_return_val_if_fail (GLADE_IS_EDITABLE (editable), NULL);
obj = g_object_new (GLADE_TYPE_MODEL_EDITOR,
"orientation", GTK_ORIENTATION_VERTICAL, NULL);
obj->base = GTK_WIDGET (editable);
gtk_box_pack_start (GTK_BOX (obj), GTK_WIDGET (editable), FALSE, FALSE, 0);
eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "links", FALSE, TRUE);
obj->props = g_list_prepend (obj->props, eprop);
frame = gtk_frame_new (NULL);
gtk_frame_set_label_widget (GTK_FRAME (frame),
glade_editor_property_get_item_label (eprop));
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
gtk_box_pack_start (GTK_BOX (obj), frame, FALSE, FALSE, 12);
alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
gtk_container_add (GTK_CONTAINER (frame), alignment);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (alignment), vbox);
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4);
gtk_widget_set_tooltip_text (vbox, _("List of parameters linked to the model"));
gtk_widget_show_all (GTK_WIDGET (obj));
return GTK_WIDGET (obj);
}
static void glade_model_editor_load (GladeEditable * editable, GladeWidget * widget)
{
GList *l;
GladeModelEditor * obj = GLADE_MODEL_EDITOR (editable);
GladeEditableIface * iface = g_type_default_interface_peek (GLADE_TYPE_EDITABLE);
iface->load (editable, widget);
if (obj->base)
glade_editable_load (GLADE_EDITABLE (obj->base), widget);
for (l = obj->props; l; l = l->next)
glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget);
}
static void glade_model_editor_set_show_name (GladeEditable * editable, gboolean show_name)
{
GladeModelEditor * obj = GLADE_MODEL_EDITOR (editable);
glade_editable_set_show_name (GLADE_EDITABLE (obj->base), show_name);
}
static void glade_model_editor_finalize (GObject * object)
{
GladeModelEditor * obj = GLADE_MODEL_EDITOR (object);
GObjectClass * parent = g_type_class_peek_parent (GLADE_MODEL_EDITOR_GET_CLASS (obj));
if (obj->props)
g_list_free (obj->props);
obj->props = NULL;
obj->base = NULL;
glade_editable_load (GLADE_EDITABLE (obj), NULL);
parent->finalize (G_OBJECT (obj));
}
static void glade_model_editor_class_init (GladeModelEditorClass * k)
{
GObjectClass * klass = G_OBJECT_CLASS (k);
klass->finalize = glade_model_editor_finalize;
}
static void glade_model_editor_init (GladeModelEditor * obj)
{
}
static void glade_model_editor_editable_init (GladeEditableIface * iface)
{
iface->load = glade_model_editor_load;
iface->set_show_name = glade_model_editor_set_show_name;
}
G_DEFINE_TYPE_WITH_CODE (GladeModelEditor, glade_model_editor, GTK_TYPE_BOX,
G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, glade_model_editor_editable_init));
//+++++++++++++++++++++++++++++++++++++++++++++++++++ GladeDbList
G_DEFINE_BOXED_TYPE (GladeDbList, glade_db_list, glade_db_list_copy, glade_db_list_free);
void glade_db_list_free (GladeDbList * list)
{
if (!list)
return;
if (list->list)
g_object_unref (list->list);
g_free (list);
list = NULL;
}
GladeDbList * glade_db_list_copy (const GladeDbList * list)
{
GladeDbList * l = g_new (GladeDbList, 1);
l->list = list->list ? g_object_ref (list->list) : NULL;
return l;
}