diff options
author | 2012-10-24 00:01:06 +0200 | |
---|---|---|
committer | 2012-10-24 00:01:06 +0200 | |
commit | 15c7c143680175d37419d36b271b17d49a0991e3 (patch) | |
tree | a0b70f86176aee67784a7ec73476a2724899052a /src/eom-new-item-dialog.c | |
parent | fd7f0ec9a302a8e9060af9aa8fbdf7a031c93760 (diff) | |
download | eye-on-manga-15c7c143680175d37419d36b271b17d49a0991e3.tar.gz eye-on-manga-15c7c143680175d37419d36b271b17d49a0991e3.zip |
Add updating of data for manga
The title and total numbers can now be changed.
* src/data.c (data_add_manga): Change `name' to `const gchar*', we're
not changing it.
(data_update_manga): New function, updates a manga's information.
* src/eom-detail-window.c (eom_detail_window_load): New function,
prepares the tables to show the right data.
(add_menu): New function, adds a menu to the window.
(eom_detail_window_init): Call `add_menu' and prepare the other
widgets for showing.
(on_edit): New function, opens an edit dialog and reloads the screen
afterwards.
(set_manga_id): Move data filling to `eom_detail_window_load' and
widget preparation to `eom_detail_window_init' and call
`eom_detail_window_load'.
* src/eom-detail-window.h (EomDetailWindow): Add `ctable' and `rtable'
members, these are the tables that show the data.
* src/eom-main-window.c (on_new): No need to save and copy the name of
a manga, just destroy the widget later and destroy it always.
* src/eom-new-item-dialog.c (eom_new_item_dialog_class_init): Add
write-only `manga-id' property.
(EOM_NEW_PROP_MID): New enum.
(finalize): New function. Free the associated manga.
(get_property): New function. Get a property, has no properties to
get for now.
(set_manga_id): New function. Show a manga's information in the
entries.
(set_property): New function. Set a property. Calls `set_manga_id'
for the `manga-id' property.
* src/eom-new-item-dialog.h (EomNewItemDialog): Add a `Manga' as
member.
Diffstat (limited to 'src/eom-new-item-dialog.c')
-rw-r--r-- | src/eom-new-item-dialog.c | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/src/eom-new-item-dialog.c b/src/eom-new-item-dialog.c index e7d5052..1f53513 100644 --- a/src/eom-new-item-dialog.c +++ b/src/eom-new-item-dialog.c @@ -4,8 +4,18 @@ #include <hildon/hildon-entry.h> #include <stdlib.h> +#include "data.h" + +enum { + EOM_NEW_PROP_MID = 1 +}; + static void eom_new_item_dialog_class_init(EomNewItemDialogClass*); static void eom_new_item_dialog_init(EomNewItemDialog*); +static void finalize(GObject*); +static void get_property(GObject*, guint, GValue*, GParamSpec*); +static void set_manga_id(EomNewItemDialog*, gint); +static void set_property(GObject*, guint, const GValue*, GParamSpec*); G_DEFINE_TYPE(EomNewItemDialog, eom_new_item_dialog, GTK_TYPE_DIALOG) @@ -28,8 +38,21 @@ eom_new_item_dialog_new(void) } static void -eom_new_item_dialog_class_init(EomNewItemDialogClass *class) -{} +eom_new_item_dialog_class_init(EomNewItemDialogClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GParamSpec *pspec; + + gobject_class->set_property = set_property; + gobject_class->get_property = get_property; + gobject_class->finalize = finalize; + pspec = g_param_spec_int("manga-id", "ID of the manga", + "Set the manga-id", 0, INT_MAX, 0, + G_PARAM_WRITABLE); + + g_object_class_install_property(gobject_class, EOM_NEW_PROP_MID, + pspec); +} static void eom_new_item_dialog_init(EomNewItemDialog *dialog) @@ -58,3 +81,55 @@ eom_new_item_dialog_init(EomNewItemDialog *dialog) GTK_RESPONSE_OK, NULL); } + +static void +finalize(GObject *object) +{ + EomNewItemDialog *self = EOM_NEW_ITEM_DIALOG(object); + + g_free(self->manga); + + G_OBJECT_CLASS(eom_new_item_dialog_parent_class)->finalize(object); +} + +static void +get_property(GObject *object, guint property_id, GValue *value, + GParamSpec *pspec) +{ + EomNewItemDialog *self = EOM_NEW_ITEM_DIALOG(object); + + switch(property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); + } +} + +static void +set_manga_id(EomNewItemDialog *self, gint manga_id) +{ + Manga *manga = data_get_manga_by_id(manga_id); + gchar *txt; + self->manga = manga; + txt = g_strdup_printf("%d", manga->total_qty); + + gtk_entry_set_text(GTK_ENTRY(self->name_entry), manga->name); + gtk_entry_set_text(GTK_ENTRY(self->qty_entry), txt); + + g_free(txt); +} + +static void +set_property(GObject *object, guint property_id, const GValue *value, + GParamSpec *pspec) +{ + EomNewItemDialog *self = EOM_NEW_ITEM_DIALOG(object); + gint manga_id = g_value_get_int(value); + + switch (property_id) { + case EOM_NEW_PROP_MID: + set_manga_id(self, manga_id); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); + } +} |