Added little bit of memory management, removed a lot of g_print
This commit is contained in:
parent
ffdaaa761d
commit
cb376d3ef4
3 changed files with 23 additions and 11 deletions
14
src/data.c
14
src/data.c
|
@ -45,6 +45,7 @@ GList *data_get_manga(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
g_print("error %d: %s\n", res, sqlite3_errmsg(database));
|
g_print("error %d: %s\n", res, sqlite3_errmsg(database));
|
||||||
|
|
||||||
/* Release the compiled statement from memory */
|
/* Release the compiled statement from memory */
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
|
@ -80,6 +81,7 @@ Manga *data_get_manga_by_id(gint manga_id)
|
||||||
manga = data_get_manga_from_statement(statement);
|
manga = data_get_manga_from_statement(statement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
sqlite3_close(database);
|
sqlite3_close(database);
|
||||||
|
@ -107,31 +109,31 @@ void data_get_volumes_by_manga_id(gint manga_id, gint *size, gint **vols)
|
||||||
" FROM volume "
|
" FROM volume "
|
||||||
" WHERE manga_id = %d ", manga_id);
|
" WHERE manga_id = %d ", manga_id);
|
||||||
|
|
||||||
g_print("%s\n", sql);
|
|
||||||
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
|
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
|
||||||
if (res == SQLITE_OK) {
|
if (res == SQLITE_OK) {
|
||||||
if (sqlite3_step(statement) == SQLITE_ROW) {
|
if (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
count = sqlite3_column_int(statement, 0);
|
count = sqlite3_column_int(statement, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
g_print("%d: %d\n", manga_id, count);
|
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
sql = g_strdup_printf(
|
sql = g_strdup_printf(
|
||||||
" SELECT id "
|
" SELECT id "
|
||||||
" FROM volume "
|
" FROM volume "
|
||||||
" WHERE manga_id = %d ", manga_id);
|
" WHERE manga_id = %d ", manga_id);
|
||||||
g_print("%s\n", sql);
|
|
||||||
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
|
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
|
||||||
if (res == SQLITE_OK) {
|
if (res == SQLITE_OK) {
|
||||||
gint i = 0;
|
gint i = 0;
|
||||||
while (sqlite3_step(statement) == SQLITE_ROW) {
|
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
gint volume = sqlite3_column_int(statement, 0);
|
gint volume = sqlite3_column_int(statement, 0);
|
||||||
g_print("volume: %d\n", volume);
|
|
||||||
volumes[i++] = volume;
|
volumes[i++] = volume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sqlite3_close(database);
|
sqlite3_close(database);
|
||||||
|
@ -166,6 +168,7 @@ gboolean data_add_manga(gchar *name, gint total_qty)
|
||||||
if (sqlite3_step(statement) == SQLITE_DONE)
|
if (sqlite3_step(statement) == SQLITE_DONE)
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
sqlite3_close(database);
|
sqlite3_close(database);
|
||||||
|
@ -200,6 +203,7 @@ gboolean data_add_to_manga(gint manga_id, gint count)
|
||||||
if (sqlite3_step(statement) == SQLITE_DONE)
|
if (sqlite3_step(statement) == SQLITE_DONE)
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
sqlite3_close(database);
|
sqlite3_close(database);
|
||||||
|
@ -238,6 +242,7 @@ gboolean data_add_volume_to_manga(gint manga_id, gint volume)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
g_print("res was not OK\n");
|
g_print("res was not OK\n");
|
||||||
|
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -279,6 +284,7 @@ gboolean data_remove_volume_from_manga(gint manga_id, gint volume)
|
||||||
g_print("step did not return DONE\n");
|
g_print("step did not return DONE\n");
|
||||||
else
|
else
|
||||||
g_print("result did not return OK\n");
|
g_print("result did not return OK\n");
|
||||||
|
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -58,6 +58,15 @@ static void eom_edit_window_get_property(GObject *object,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void eom_edit_window_finalize(GObject *object)
|
||||||
|
{
|
||||||
|
EomEditWindow *self = EOM_EDIT_WINDOW(object);
|
||||||
|
|
||||||
|
g_free(self->current_manga);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS(eom_edit_window_parent_class)->finalize(object);
|
||||||
|
}
|
||||||
|
|
||||||
static void eom_edit_window_class_init(EomEditWindowClass *klass)
|
static void eom_edit_window_class_init(EomEditWindowClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||||
|
@ -65,6 +74,7 @@ static void eom_edit_window_class_init(EomEditWindowClass *klass)
|
||||||
|
|
||||||
gobject_class->set_property = eom_edit_window_set_property;
|
gobject_class->set_property = eom_edit_window_set_property;
|
||||||
gobject_class->get_property = eom_edit_window_get_property;
|
gobject_class->get_property = eom_edit_window_get_property;
|
||||||
|
gobject_class->finalize = eom_edit_window_finalize;
|
||||||
|
|
||||||
pspec = g_param_spec_int("manga-id",
|
pspec = g_param_spec_int("manga-id",
|
||||||
"ID of the manga",
|
"ID of the manga",
|
||||||
|
@ -157,7 +167,6 @@ static void eom_edit_window_set_manga_id(EomEditWindow *self,
|
||||||
button = gtk_toggle_button_new_with_label(g_strdup_printf("%d", i + 1));
|
button = gtk_toggle_button_new_with_label(g_strdup_printf("%d", i + 1));
|
||||||
gtk_box_pack_start(GTK_BOX(self->volumes_box), button, TRUE, TRUE, 0);
|
gtk_box_pack_start(GTK_BOX(self->volumes_box), button, TRUE, TRUE, 0);
|
||||||
|
|
||||||
g_print("volume found: %d, i=%d\n", volumes[j], i);
|
|
||||||
if (j < num_vols && volumes[j] == i+1) {
|
if (j < num_vols && volumes[j] == i+1) {
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
|
||||||
j++;
|
j++;
|
||||||
|
@ -180,15 +189,11 @@ static void eom_edit_window_on_volume_toggled(GtkToggleButton *togglebutton,
|
||||||
active = gtk_toggle_button_get_active(togglebutton);
|
active = gtk_toggle_button_get_active(togglebutton);
|
||||||
volume = atoi(gtk_button_get_label(GTK_BUTTON(togglebutton)));
|
volume = atoi(gtk_button_get_label(GTK_BUTTON(togglebutton)));
|
||||||
|
|
||||||
g_print("toggled %d: %d\n", self->current_manga->id, volume);
|
|
||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
if (!data_add_to_manga(self->current_manga->id, 1)) {
|
if (!data_add_to_manga(self->current_manga->id, 1)) {
|
||||||
g_print("not added 1 volume to %d\n", self->current_manga->id);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!data_add_volume_to_manga(self->current_manga->id, volume)) {
|
if (!data_add_volume_to_manga(self->current_manga->id, volume)) {
|
||||||
g_print("not added volume %d to %d\n", volume, self->current_manga->id);
|
|
||||||
data_add_to_manga(self->current_manga->id, 1);
|
data_add_to_manga(self->current_manga->id, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -196,11 +201,9 @@ static void eom_edit_window_on_volume_toggled(GtkToggleButton *togglebutton,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!data_add_to_manga(self->current_manga->id, -1)) {
|
if (!data_add_to_manga(self->current_manga->id, -1)) {
|
||||||
g_print("not added -1 volumes to %d\n", self->current_manga->id);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!data_remove_volume_from_manga(self->current_manga->id, volume)) {
|
if (!data_remove_volume_from_manga(self->current_manga->id, volume)) {
|
||||||
g_print("not added volume %d to %d\n", volume, self->current_manga->id);
|
|
||||||
data_add_to_manga(self->current_manga->id, 1); /* Undo */
|
data_add_to_manga(self->current_manga->id, 1); /* Undo */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,9 @@ void eom_main_window_load(EomMainWindow *self)
|
||||||
Manga *manga = list->data;
|
Manga *manga = list->data;
|
||||||
eom_main_window_add_line(self, manga->id, manga->name,
|
eom_main_window_add_line(self, manga->id, manga->name,
|
||||||
manga->current_qty, manga->total_qty);
|
manga->current_qty, manga->total_qty);
|
||||||
|
|
||||||
|
free(manga->name);
|
||||||
|
free(manga);
|
||||||
list = g_list_next(list);
|
list = g_list_next(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue