From eee4aacfaa6b3c9d22345526826cb861ad6e70cd Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 9 Oct 2014 18:35:23 +0200 Subject: [PATCH] Merge --- module/src/vn-allocator.c | 10 ++- module/src/vn-shelves.c | 134 +++++++++++++++++++++----------------- module/src/vn-shelves.h | 14 ++++ vn/field/vn-combo.c | 5 ++ vn/vn-login.c | 20 +++--- 5 files changed, 111 insertions(+), 72 deletions(-) diff --git a/module/src/vn-allocator.c b/module/src/vn-allocator.c index d94e65e..6b2beb7 100644 --- a/module/src/vn-allocator.c +++ b/module/src/vn-allocator.c @@ -33,6 +33,7 @@ struct _VnAllocator gint current_shelf; gint current_tray; gint column_width; + gint last_box_width; gint tray_x; gint tray_y; }; @@ -72,6 +73,7 @@ vn_allocator_add_column (VnAllocator * self, gint width) self->tray_y = 0; self->column_width = width; + self->last_box_width = width; } void @@ -83,13 +85,16 @@ vn_allocator_add_box (VnAllocator * self, Item * i, gint amount) tray_height = self->top_tray_height; if (self->tray_y + i->box_height > tray_height - || i->box_width > self->column_width) + || i->box_width > self->last_box_width) vn_allocator_add_column (self, i->box_width); if (self->box_func) self->box_func (self, self->user_data, i, amount); self->tray_y += i->box_height; + + if (i->box_width < self->last_box_width) + self->last_box_width = i->box_width; } gint @@ -102,10 +107,11 @@ vn_allocator_run (VnAllocator * self) self->current_shelf = -1; self->current_tray = -1; self->column_width = 0; + self->last_box_width = 0; self->tray_x = 0; self->tray_y = 0; - for (i = &self->items[0]; i->name; i++) + for (i = self->items; i->name; i++) for (amount = 0; amount < i->amount; amount++) { if (amount == 0 diff --git a/module/src/vn-shelves.c b/module/src/vn-shelves.c index 6811180..5423171 100644 --- a/module/src/vn-shelves.c +++ b/module/src/vn-shelves.c @@ -22,24 +22,11 @@ G_DEFINE_TYPE (VnShelves, vn_shelves, VN_TYPE_FORM); -typedef struct -{ - gint width; - gint height; - gint max_height; - gint tray_height; - gint first_tray_elevation; - gint tray_density; - gint vspace; - gint hspace; -} -Shelf; - //+++++++++++++++++++++++++++++++++++++++++++++++++++ Private #define LINE_WIDTH 10 #define PAGE_MARGIN 40 -#define HEADER_HEIGHT 60 +#define HEADER_HEIGHT 80 #define TITLE_SIZE 40 #define BOX_TEXT_SIZE 35 #define BOX_MARGIN 6 @@ -52,18 +39,6 @@ GdkRGBA colors[] = { ,{0.96, 0.96, 0.76, 1} // Yellow }; -static -Shelf shelf = { - 1250 // Width - ,1700 // Height - ,2100 // Max. height - ,620 // Tray height - ,150 // First tray elevation - ,15 // Tray density - ,25 // V. space - ,25 // H. space -}; - //-------------------------- Drawing methods void @@ -72,9 +47,10 @@ vn_shelves_draw_box (VnAllocator * allocator, VnShelves * self, Item * i, gint a if (i->box_width == 0 || i->box_height == 0) return; + VnShelf shelf = self->shelf; cairo_t * cr = self->cr; - gint x = self->shelf_x + allocator->tray_x + shelf.hspace; + gint x = self->shelf_x + allocator->tray_x + shelf.hspacing; gint y = self->shelf_y - allocator->tray_y - shelf.first_tray_elevation - shelf.tray_density - allocator->current_tray * (shelf.tray_height + shelf.tray_density); @@ -128,6 +104,7 @@ void vn_shelves_draw_shelf (VnAllocator * allocator, VnShelves * self) { gint y; + VnShelf shelf = self->shelf; cairo_surface_t * surface = cairo_surface_create_similar ( cairo_get_target (self->context_cr), @@ -215,13 +192,30 @@ vn_shelves_draw_shelf (VnAllocator * allocator, VnShelves * self) void vn_shelves_on_begin_print (GtkPrintOperation * op, GtkPrintContext * context, VnShelves * self) { + DbIterator * iter; + self->pages = NULL; self->context_cr = gtk_print_context_get_cairo_context (context); + + // XXX: Shelf dimensions - // XXX + iter = $("iter-shelves"); + VnShelf shelf = { + db_iterator_get_int (iter, "width") + ,db_iterator_get_int (iter, "height") + ,db_iterator_get_int (iter, "max_height") + ,db_iterator_get_int (iter, "tray_height") + ,db_iterator_get_int (iter, "first_tray_elevation") + ,db_iterator_get_int (iter, "tray_density") + ,db_iterator_get_int (iter, "vspacing") + ,db_iterator_get_int (iter, "hspacing") + }; + self->shelf = shelf; + + // XXX: Items list - gint i; - DbIterator * iter = $("iter-items"); + Item * i; + iter = $("iter-items"); gint nitems = db_iterator_get_nrows (iter); Item * items = g_new (Item, nitems + 1); @@ -229,18 +223,15 @@ vn_shelves_on_begin_print (GtkPrintOperation * op, GtkPrintContext * context, Vn db_iterator_move_iter (iter, NULL); - for (i = 0; db_iterator_move_next (iter); i++) + for (i = items; db_iterator_move_next (iter); i++) { - const gchar * name = gvn_value_get_string (db_iterator_get_value (iter, "Article")); - gint size = gvn_value_get_int (db_iterator_get_value (iter, "Medida")); - gint width = gvn_value_get_double (db_iterator_get_value (iter, "x")); - gint height = gvn_value_get_double (db_iterator_get_value (iter, "z")); - gint amount = gvn_value_get_double (db_iterator_get_value (iter, "etiquetas")); - - items[i].name = g_strdup_printf ("%s x%d", name, size); - items[i].box_width = width * 10; - items[i].box_height = height * 10; - items[i].amount = amount; + i->name = g_strdup_printf ("%s x%d" + ,db_iterator_get_string (iter, "Article") + ,db_iterator_get_int (iter, "Medida") + ); + i->box_width = db_iterator_get_double (iter, "x") * 10; + i->box_height = db_iterator_get_double (iter, "z") * 10; + i->amount = db_iterator_get_double (iter, "etiquetas"); } // Initializing @@ -283,19 +274,19 @@ vn_shelves_on_begin_print (GtkPrintOperation * op, GtkPrintContext * context, Vn (gdouble) (shelf.height - shelf.first_tray_elevation) / (shelf.tray_height + shelf.tray_density) ); - alloc.tray_width = shelf.width - shelf.hspace * 2; - alloc.tray_height = shelf.tray_height - shelf.vspace; - alloc.top_tray_height = shelf.max_height - shelf.vspace + alloc.tray_width = shelf.width - shelf.hspacing * 2; + alloc.tray_height = shelf.tray_height - shelf.vspacing; + alloc.top_tray_height = shelf.max_height - shelf.vspacing - shelf.first_tray_elevation - (alloc.ntrays - 1) * shelf.tray_height; gint npages = vn_allocator_run (&alloc); gtk_print_operation_set_n_pages (op, npages); - // XXX + // XXX: Freeing items list - for (i = 0; i < nitems; i++) - g_free (items[i].name); + for (i = items; i->name; i++) + g_free (i->name); g_free (items); } @@ -317,6 +308,20 @@ vn_shelves_on_draw_page (GtkPrintOperation * op, GtkPrintContext * context, gint cairo_paint (cr); } +void +vn_shelves_show_message (VnShelves * self, const gchar * message) +{ + GtkWindow * parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))); + GtkWidget * dialog = gtk_message_dialog_new (parent + ,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT + ,GTK_MESSAGE_INFO + ,GTK_BUTTONS_CLOSE + ,message + ); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); +} + void vn_shelves_on_items_changed (DbModel * model, DbModelStatus status, VnShelves * self) { @@ -326,17 +331,9 @@ vn_shelves_on_items_changed (DbModel * model, DbModelStatus status, VnShelves * if (status != DB_MODEL_STATUS_READY || self->action == -1) return; - GtkWindow * parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))); - if (db_model_get_nrows (model) == 0) { - GtkWidget * dialog = gtk_message_dialog_new (parent - ,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT - ,GTK_MESSAGE_INFO - ,GTK_BUTTONS_OK - ,_("There are no items to allocate") - ); - gtk_dialog_run (GTK_DIALOG (dialog)); + vn_shelves_show_message (self, _("There are no items to allocate")); return; } @@ -345,7 +342,7 @@ vn_shelves_on_items_changed (DbModel * model, DbModelStatus status, VnShelves * if (self->print_settings) gtk_print_operation_set_print_settings (op, self->print_settings); - gtk_print_operation_set_job_name (op, _("Selves")); + gtk_print_operation_set_job_name (op, _("Shelves")); gtk_print_operation_set_embed_page_setup (op, TRUE); g_object_connect (op ,"signal::begin-print", vn_shelves_on_begin_print, self @@ -355,6 +352,7 @@ vn_shelves_on_items_changed (DbModel * model, DbModelStatus status, VnShelves * ); GError * err = NULL; + GtkWindow * parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))); GtkPrintOperationResult result = gtk_print_operation_run (op, self->action, parent, &err); @@ -365,7 +363,7 @@ vn_shelves_on_items_changed (DbModel * model, DbModelStatus status, VnShelves * } else if (result == GTK_PRINT_OPERATION_RESULT_ERROR && err) { - g_warning (err->message); + vn_shelves_show_message (self, err->message); g_error_free (err); } } @@ -386,16 +384,34 @@ vn_shelves_print_clicked (GtkButton * button, VnShelves * self) //-------------------------- Form +void +vn_shelves_on_edit_clicked (GtkButton * button, VnShelves * self) +{ + GtkWidget * dialog = $("shelves-dialog"); + gtk_window_set_transient_for (GTK_WINDOW (dialog), + GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); + gtk_widget_show_all (dialog); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_hide (dialog); +} + +void +vn_shelves_on_close_clicked (GtkButton * button, VnShelves * self) +{ + gtk_dialog_response ($("shelves-dialog"), 1); +} + static void vn_shelves_open (VnShelves * self, gpointer user_data) { - // XXX: Developer: Default field values + // XXX: Default field values self->action = -1; gvn_param_set_string ($("title"), "Anthuriums"); gvn_param_set_string ($("filter"), "a.Article LIKE \\'Ant %\\'"); gvn_param_set_int ($("wh"), 1); + gvn_param_set_int ($("shelf"), 1); GValue date = G_VALUE_INIT; g_value_init (&date, G_TYPE_DATE_TIME); diff --git a/module/src/vn-shelves.h b/module/src/vn-shelves.h index e019c70..52d1aec 100644 --- a/module/src/vn-shelves.h +++ b/module/src/vn-shelves.h @@ -26,12 +26,26 @@ typedef struct _VnShelves VnShelves; typedef struct _VnShelvesClass VnShelvesClass; +typedef struct _VnShelf VnShelf; + +struct _VnShelf +{ + gint width; + gint height; + gint max_height; + gint tray_height; + gint first_tray_elevation; + gint tray_density; + gint vspacing; + gint hspacing; +}; struct _VnShelves { VnForm parent; GtkPrintSettings * print_settings; GtkPrintOperationAction action; + VnShelf shelf; // Cairo diff --git a/vn/field/vn-combo.c b/vn/field/vn-combo.c index 8e443a8..65b5a52 100644 --- a/vn/field/vn-combo.c +++ b/vn/field/vn-combo.c @@ -270,6 +270,11 @@ static void vn_combo_init (VnCombo * self) gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->combo)); self->cell = gtk_cell_renderer_text_new (); + g_object_set (self->cell + ,"ellipsize", PANGO_ELLIPSIZE_END + ,"width", 0 + ,NULL + ); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self->combo), self->cell, TRUE); VN_FIELD_GET_CLASS (self)->set_widget (VN_FIELD (self), diff --git a/vn/vn-login.c b/vn/vn-login.c index 6e1846e..2ed2755 100644 --- a/vn/vn-login.c +++ b/vn/vn-login.c @@ -189,7 +189,7 @@ static void vn_login_set_loading (VnLogin * self, gboolean loading) gtk_widget_show_all (spinner); } else - gtk_button_set_label (self->connect, "gtk-connect"); + gtk_button_set_label (self->connect, "Connect"); gtk_widget_set_sensitive (GTK_WIDGET (self->connect), !loading); } @@ -252,7 +252,7 @@ void vn_login_on_server_changed (DbIterator * iterator, VnLogin * self) if (db_iterator_get_row (self->login_data) != -1) { - const gchar * pass = gvn_value_get_string (db_iterator_get_value (self->login_data, "password")); + const gchar * pass = db_iterator_get_string (self->login_data, "password"); gvn_param_set_value (self->user, db_iterator_get_value (self->login_data, "user")); @@ -367,11 +367,9 @@ static gboolean vn_login_done (ConnectData * connect_data) if (gvn_param_get_boolean (self->remember)) { - GValue encoded = G_VALUE_INIT; - g_value_init (&encoded, G_TYPE_STRING); - g_value_take_string (&encoded, gvn_encode (gvn_param_get_string (self->pass))); - db_iterator_set_value (self->login_data, "password", &encoded, NULL); - g_value_unset (&encoded); + gchar * encoded = gvn_encode (gvn_param_get_string (self->pass)); + db_iterator_set_string (self->login_data, "password", encoded); + g_free (encoded); } db_iterator_perform_operations (self->last_conn); @@ -430,10 +428,10 @@ static void vn_login_thread (ConnectData * connect_data) // FIXME: Thread unsafe functions const gchar * user = gvn_param_get_string (self->user); const gchar * pass = gvn_param_get_string (self->pass); - const gchar * plugin = gvn_value_get_string (db_iterator_get_value (self->login_data, "plugin")); - const gchar * host = gvn_value_get_string (db_iterator_get_value (self->login_data, "host")); - const gchar * schema = gvn_value_get_string (db_iterator_get_value (self->login_data, "schema")); - const gchar * ssl_ca = gvn_value_get_string (db_iterator_get_value (self->login_data, "ssl_ca")); + const gchar * plugin = db_iterator_get_string (self->login_data, "plugin"); + const gchar * host = db_iterator_get_string (self->login_data, "host"); + const gchar * schema = db_iterator_get_string (self->login_data, "schema"); + const gchar * ssl_ca = db_iterator_get_string (self->login_data, "ssl_ca"); if (IS_DEFINED (plugin) && IS_DEFINED (schema)) {