Correctly show changes when total goes down

* src/data.c (data_update_manga): When updating, set `current_qty' to
  the lesser of `current_qty' and `total_qty' so that current will
  never exceed total.  If the update went well remove any volumes that
  have numbers greater than the `total_qty'.

* src/eom-detail-window.c (eom_detail_window_load): Get to upper bound
  of rows, if I need 1.5 rows I actually need 2 rows, what was I
  thinking?  Clear both tables of children before filling them up
  again.
  (cb_destroy): New function.  Just calls destroy in `widget', but
  `gtk_widget_destroy' doesn't seem like a valid `GtkCallback'.
  (on_volume_toggled): When adding a volume fails, revert one from
  `current_qty'.  Don't mess with `self->manga->current_qty', just
  reset the manga id, otherwise we will know that there should be one
  more or less volume, but won't show it in the manga's volumes
  collection.
This commit is contained in:
Tom Willemsen 2012-10-25 21:15:50 +02:00
parent 337a0ba2d2
commit 7ffc87d99d
2 changed files with 27 additions and 10 deletions

View file

@ -239,12 +239,24 @@ gboolean
data_update_manga(gint manga_id, const gchar *name, gint total_qty)
{
gchar *sql =
g_strdup_printf("UPDATE manga SET name = '%s', total_qty = %d "
"WHERE id = %d", name, total_qty, manga_id);
g_strdup_printf("UPDATE manga SET "
" name = '%s', "
" total_qty = %d, "
" current_qty = MIN(current_qty, %d) "
"WHERE id = %d", name, total_qty, total_qty,
manga_id);
gboolean ret = execute_non_query(sql);
g_free(sql);
if (ret) {
sql = g_strdup_printf("DELETE FROM volume "
"WHERE manga_id = %d "
"AND id > %d",
manga_id, total_qty);
ret = execute_non_query(sql);
}
return ret;
}

View file

@ -18,6 +18,7 @@ enum {
};
static void add_menu(EomDetailWindow*);
static void cb_destroy(GtkWidget*, gpointer);
static GtkWidget *create_volume_button(gchar*, GtkTable*, int, int);
static void eom_detail_window_class_init(EomDetailWindowClass*);
static void eom_detail_window_init(EomDetailWindow *self);
@ -42,10 +43,12 @@ eom_detail_window_load(EomDetailWindow *self)
if (!total_qty)
total_qty = self->manga->current_qty + 1;
rows = (int)floor(total_qty / COLUMNS);
rows = (int)ceil(total_qty / COLUMNS);
gtk_window_set_title(GTK_WINDOW(self), self->manga->name);
gtk_container_foreach(GTK_CONTAINER(self->ctable), cb_destroy, NULL);
gtk_table_resize(GTK_TABLE(self->ctable), rows, COLUMNS);
gtk_container_foreach(GTK_CONTAINER(self->rtable), cb_destroy, NULL);
gtk_table_resize(GTK_TABLE(self->rtable), rows, COLUMNS);
for (i = 0; i < total_qty; i++) {
@ -113,6 +116,12 @@ add_menu(EomDetailWindow *window)
HILDON_APP_MENU(appmenu));
}
static void
cb_destroy(GtkWidget *widget, gpointer user_data)
{
gtk_widget_destroy(widget);
}
static GtkWidget *
create_volume_button(gchar* text, GtkTable* table, int column, int row)
{
@ -264,26 +273,22 @@ on_volume_toggled(GtkToggleButton *togglebutton, gpointer user_data)
return;
}
if (!data_add_volume_to_manga(self->manga->id, volume)) {
data_add_to_manga(self->manga->id, 1);
data_add_to_manga(self->manga->id, -1);
return;
}
self->manga->current_qty++;
}
else {
/* Remove 1 from mangas collected */
if (!data_add_to_manga(self->manga->id, -1)) {
return;
}
if (!data_remove_volume_from_manga(self->manga->id,
volume)) {
if (!data_remove_volume_from_manga(self->manga->id, volume)) {
data_add_to_manga(self->manga->id, 1); /* Undo */
return;
}
self->manga->current_qty--;
}
if (!self->manga->total_qty)
eom_detail_window_load(self);
set_manga_id(self, self->manga->id);
}
static void