There’s only one problem are two different files
See this:
/*
* Copyright 2019 Danilo Fernandes Galete
*
* 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 "fnc-combo-box-category.h"
struct _FncComboBoxCategory{
GtkComboBox parent;
/* The Widgets */
GtkListStore *liststore;
/* The Parameters */
GtkMenuButton *button_add_subcategory;
FncComboBoxSubcategory *combo_box_subcategory;
FncPopoverSubcategory *popover_subcategory;
};
enum{
PROP_0,
PROP_BUTTON_ADD_SUBCATEGORY,
PROP_COMBO_BOX_SUBCATEGORY,
PROP_POPOVER_SUBCATEGORY,
N_PROPERTIES
};
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
G_DEFINE_TYPE (FncComboBoxCategory, fnc_combo_box_category, GTK_TYPE_COMBO_BOX);
static void
on_combo_box_category_changed (GtkComboBox *combo_box,
gpointer user_data)
{
FncComboBoxCategory *self;
GtkTreeModel *model;
GtkTreeIter iter;
gint col_id;
self = FNC_COMBO_BOX_CATEGORY (user_data);
col_id = gtk_combo_box_get_active (combo_box);
if (col_id != -1)
{
model = gtk_combo_box_get_model (combo_box);
gtk_combo_box_get_active_iter (combo_box, &iter);
gtk_tree_model_get (model, &iter,
0, &col_id, -1);
gtk_widget_set_visible (GTK_WIDGET (self->button_add_subcategory), TRUE);
fnc_combo_box_subcategory_update (FNC_COMBO_BOX_SUBCATEGORY (self->combo_box_subcategory), col_id);
g_object_set (G_OBJECT (self->popover_subcategory), "id_category", col_id, NULL);
}
else
{
gtk_widget_set_visible (GTK_WIDGET (self->button_add_subcategory), FALSE);
fnc_combo_box_subcategory_clean (FNC_COMBO_BOX_SUBCATEGORY (self->combo_box_subcategory));
}
}
static void
fnc_combo_box_category_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
FncComboBoxCategory *self = FNC_COMBO_BOX_CATEGORY (object);
switch (property_id)
{
case PROP_BUTTON_ADD_SUBCATEGORY:
g_assert (self->button_add_subcategory == NULL);
self->button_add_subcategory = g_value_get_object (value);
break;
case PROP_COMBO_BOX_SUBCATEGORY:
g_assert (self->combo_box_subcategory == NULL);
self->combo_box_subcategory = g_value_get_object (value);
break;
case PROP_POPOVER_SUBCATEGORY:
g_assert (self->popover_subcategory == NULL);
self->popover_subcategory = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
fnc_combo_box_category_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
FncComboBoxCategory *self = FNC_COMBO_BOX_CATEGORY (object);
switch (property_id)
{
case PROP_BUTTON_ADD_SUBCATEGORY:
g_value_set_object (value, self->button_add_subcategory);
break;
case PROP_COMBO_BOX_SUBCATEGORY:
g_value_set_object (value, self->combo_box_subcategory);
break;
case PROP_POPOVER_SUBCATEGORY:
g_value_set_object (value, self->popover_subcategory);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
fnc_combo_box_category_init (FncComboBoxCategory *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
/* Create Table */
fnc_model_category_create_table ();
}
static void
fnc_combo_box_category_class_init (FncComboBoxCategoryClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->set_property = fnc_combo_box_category_set_property;
object_class->get_property = fnc_combo_box_category_get_property;
obj_properties[PROP_BUTTON_ADD_SUBCATEGORY] = g_param_spec_object ("button_add_subcategory",
"ButtonAdd of the ComboBoxCategory",
"The Button Add of the ComboBoxCategory",
GTK_TYPE_MENU_BUTTON,
G_PARAM_READWRITE);
obj_properties[PROP_COMBO_BOX_SUBCATEGORY] = g_param_spec_object ("combo_box_subcategory",
"ComboBoxSubcategory of the ComboBoxCategory",
"The Combo Box Subcategory of the ComboBoxCategory",
FNC_TYPE_COMBO_BOX_SUBCATEGORY,
G_PARAM_READWRITE);
obj_properties[PROP_POPOVER_SUBCATEGORY] = g_param_spec_object ("popover_subcategory",
"PopoverSubcategory of the ComboBoxCategory",
"The Popover Subcategory of the ComboBoxCategory",
FNC_TYPE_POPOVER_SUBCATEGORY,
G_PARAM_READWRITE);
g_object_class_install_properties (object_class, N_PROPERTIES, obj_properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/finance/combo-box-category.ui");
gtk_widget_class_bind_template_child (widget_class, FncComboBoxCategory, liststore);
gtk_widget_class_bind_template_callback (widget_class, on_combo_box_category_changed);
}
FncComboBoxCategory*
fnc_combo_box_category_new (void)
{
return g_object_new (FNC_TYPE_COMBO_BOX_CATEGORY, NULL);
}
void
fnc_combo_box_category_update (FncComboBoxCategory *self)
{
fnc_model_category_list (self->liststore);
}
/*
* Copyright 2019 Danilo Fernandes Galete
*
* 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 "fnc-popover-category.h"
struct _FncPopoverCategory{
GtkPopover parent;
/* The Widgets */
GtkEntry *entry_name;
GtkButton *button_add;
GtkLabel *label_inf;
/* The Parameters */
FncComboBoxCategory *combo_box_category;
};
enum{
PROP_0,
PROP_COMBO_BOX_CATEGORY,
N_PROPERTIES
};
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
G_DEFINE_TYPE (FncPopoverCategory, fnc_popover_category, GTK_TYPE_POPOVER);
static void
on_popover_category_clean (FncPopoverCategory *self)
{
gtk_entry_set_text (GTK_ENTRY (self->entry_name), "");
gtk_widget_set_visible (GTK_WIDGET (self->label_inf), FALSE);
gtk_popover_popdown (GTK_POPOVER (self));
}
static void
on_button_add_clicked (GtkButton *button,
gpointer user_data)
{
FncPopoverCategory *self;
gchar *normalized_name;
self = FNC_POPOVER_CATEGORY (user_data);
normalized_name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_name))));
if (strlen (normalized_name) > 0)
{
if(!fnc_model_category_insert (normalized_name))
{
}
else
{
fnc_combo_box_category_update (FNC_COMBO_BOX_CATEGORY (self->combo_box_category));
on_popover_category_clean (self);
}
}
else
{
gtk_widget_set_visible (GTK_WIDGET (self->label_inf), TRUE);
gtk_entry_set_text (GTK_ENTRY (self->entry_name), "");
}
g_free (normalized_name);
}
static void
fnc_popover_category_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
FncPopoverCategory *self = FNC_POPOVER_CATEGORY (object);
switch (property_id)
{
case PROP_COMBO_BOX_CATEGORY:
g_assert (self->combo_box_category == NULL);
self->combo_box_category = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
fnc_popover_category_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
FncPopoverCategory *self = FNC_POPOVER_CATEGORY (object);
switch (property_id)
{
case PROP_COMBO_BOX_CATEGORY:
g_value_set_object (value, self->combo_box_category);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,pspec);
break;
}
}
static void
fnc_popover_category_init (FncPopoverCategory *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
static void
fnc_popover_category_class_init (FncPopoverCategoryClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->set_property = fnc_popover_category_set_property;
object_class->get_property = fnc_popover_category_get_property;
obj_properties[PROP_COMBO_BOX_CATEGORY] = g_param_spec_object ("combo_box_category",
"ComboBoxCategory of the PopoverCategory",
"The Combo Box Category of the PopoverCategory",
FNC_TYPE_COMBO_BOX_CATEGORY,
G_PARAM_READWRITE);
g_object_class_install_properties (object_class, N_PROPERTIES, obj_properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/finance/popover-category.ui");
gtk_widget_class_bind_template_child (widget_class, FncPopoverCategory, entry_name);
gtk_widget_class_bind_template_child (widget_class, FncPopoverCategory, button_add);
gtk_widget_class_bind_template_child (widget_class, FncPopoverCategory, label_inf);
gtk_widget_class_bind_template_callback (widget_class, on_button_add_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_format_text);
gtk_widget_class_bind_template_callback (widget_class, on_popover_category_clean);
}
FncPopoverCategory*
fnc_popover_category_new (void)
{
return g_object_new (FNC_TYPE_POPOVER_CATEGORY, NULL);
}