Añadido un nuevo modulo de ejemplo.

GvnValue:
	- Bugs solucionados.
This commit is contained in:
Juan Ferrer Toribio 2014-09-17 00:42:05 +02:00
parent 3770dec9b5
commit d47b62e1aa
10 changed files with 884 additions and 9 deletions

View File

@ -615,6 +615,8 @@ GValue * gvn_value_new_null ()
gboolean gvn_value_get_boolean (const GValue * value)
{
g_return_val_if_fail (G_IS_VALUE (value), FALSE);
if (!gvn_value_is_null (value))
return g_value_get_boolean (value);
@ -630,6 +632,8 @@ GValue * gvn_value_new_boolean (gboolean value)
gint gvn_value_get_int (const GValue * value)
{
g_return_val_if_fail (G_IS_VALUE (value), 0);
if (!gvn_value_is_null (value))
return g_value_get_int (value);
@ -645,6 +649,8 @@ GValue * gvn_value_new_int (gint value)
glong gvn_value_get_long (const GValue * value)
{
g_return_val_if_fail (G_IS_VALUE (value), 0L);
if (!gvn_value_is_null (value))
return g_value_get_long (value);
@ -660,6 +666,8 @@ GValue * gvn_value_new_long (glong value)
gdouble gvn_value_get_double (const GValue * value)
{
g_return_val_if_fail (G_IS_VALUE (value), 0.0);
if (!gvn_value_is_null (value))
return g_value_get_double (value);
@ -675,6 +683,8 @@ GValue * gvn_value_new_double (gdouble value)
const gchar * gvn_value_get_string (const GValue * value)
{
g_return_val_if_fail (G_IS_VALUE (value), NULL);
if (!gvn_value_is_null (value))
return g_value_get_string (value);
@ -690,6 +700,8 @@ GValue * gvn_value_new_string (const gchar * value)
gpointer gvn_value_get_boxed (const GValue * value)
{
g_return_val_if_fail (G_IS_VALUE (value), NULL);
if (!gvn_value_is_null (value))
return g_value_get_boxed (value);
@ -699,7 +711,7 @@ gpointer gvn_value_get_boxed (const GValue * value)
GValue * gvn_value_new_boxed (gpointer value)
{
GValue * gvalue = g_new0 (GValue, 1);
g_value_set_string (g_value_init (gvalue, G_TYPE_BOXED), value);
g_value_set_boxed (g_value_init (gvalue, G_TYPE_BOXED), value);
return gvalue;
}

View File

@ -6,8 +6,8 @@ example_DATA = \
example.xml \
example-menu.xml \
consulter.glade \
consulter-menu.xml
shelfs.glade \
consulter-menu.xml \
customer.glade
# signer.glade
EXTRA_DIST = $(example_DATA)

View File

@ -8,11 +8,17 @@
<attribute name="target">consulter</attribute>
<attribute name="accel">F12</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Shelfs</attribute>
<attribute name="action">win.open-form</attribute>
<attribute name="target">shelfs</attribute>
<attribute name="accel">F11</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Customer</attribute>
<attribute name="action">win.open-form</attribute>
<attribute name="target">customer</attribute>
<attribute name="accel">F11</attribute>
<attribute name="accel">F10</attribute>
</item>
</section>
</menu>

View File

@ -8,6 +8,12 @@
icon="system-run">
Consulter
</form>
<form
translatable="yes"
name="shelfs"
icon="system-run">
Shelfs
</form>
<form
translatable="yes"
name="customer"

203
module/data/shelfs.glade Normal file
View File

@ -0,0 +1,203 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<requires lib="vn" version="1.0"/>
<object class="VnBatch" id="batch-items">
<items>
<item id="wh" param="wh"/>
<item id="date" param="date"/>
<item id="filter" param="filter"/>
</items>
</object>
<object class="VnSet" id="models">
<child>
<object class="VnModel" id="model-items">
<property name="sql">CALL vn2008.ubicator_beta (#wh, #date, #filter);</property>
<property name="batch">batch-items</property>
</object>
</child>
</object>
<object class="VnIterator" id="items">
<property name="model">model-items</property>
<property name="remember_selection">False</property>
<signal name="status-changed" handler="vn_shelfs_on_items_ready" swapped="no"/>
</object>
<object class="GtkBox" id="main">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">8</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="row_spacing">4</property>
<property name="column_spacing">5</property>
<property name="row_homogeneous">True</property>
<child>
<object class="GtkLabel" id="label-title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Title:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="VnEntry" id="title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child internal-child="widget">
<object class="GtkEntry" id="title-child">
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="VnDateChooser" id="date">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child internal-child="widget">
<object class="GtkToggleButton" id="date-child">
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">half</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-date">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Date:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-wh">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Warehouse:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="VnSpin" id="wh">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child internal-child="widget">
<object class="GtkSpinButton" id="wh-child">
<property name="can_focus">True</property>
<property name="climb_rate">1</property>
<property name="numeric">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-filter">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Filter:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="VnEntry" id="filter">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child internal-child="widget">
<object class="GtkEntry" id="filter-child">
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="buttonbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="homogeneous">True</property>
<property name="layout_style">expand</property>
<child>
<object class="GtkButton" id="button-print">
<property name="label" translatable="yes">Print</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="vn_shelfs_print_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button-preview">
<property name="label" translatable="yes">Preview</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="vn_shelfs_preview_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</interface>

View File

@ -12,6 +12,8 @@ libexample_la_LIBADD = $(top_builddir)/vn/libvn.la
libexample_la_SOURCES = \
vn-consulter.h \
vn-consulter.c \
vn-shelfs.h \
vn-shelfs.c \
vn-customer.h \
vn-customer.c

165
module/src/vn-allocator.c Normal file
View File

@ -0,0 +1,165 @@
#include <math.h>
#include <gtk/gtk.h>
typedef struct _VnAllocator VnAllocator;
typedef void (*VnAllocatorShelfFunc) (VnAllocator * self, gpointer user_data);
typedef void (*VnAllocatorBoxFunc) (VnAllocator * self, gpointer user_data);
typedef struct
{
int height;
int width;
int max_height;
int tray_spacing;
int first_tray_y;
int tray_x;
int vspace;
int hspace;
}
Shelf;
typedef struct
{
char * name;
int box_height;
int box_width;
int amount;
}
Item;
struct _VnAllocator
{
Shelf shelf;
Item * items;
int nboxes;
int item;
int amount;
int current_shelf;
int current_tray;
int tray_height;
int tray_width;
int tray_y;
int tray_x;
int column_width;
int ntrays;
int first_shelf_box;
int first_tray_box;
VnAllocatorShelfFunc shelf_func;
VnAllocatorBoxFunc box_func;
gpointer user_data;
};
VnAllocator *
vn_allocator_new (const Shelf shelf, Item * items,
VnAllocatorShelfFunc shelf_func, VnAllocatorBoxFunc box_func, gpointer user_data)
{
VnAllocator * self = g_new (VnAllocator, 1);
self->shelf = shelf;
self->items = items;
self->nboxes = 0;
self->item = 0;
self->amount = 0;
self->current_shelf = -1;
self->current_tray = -1;
self->column_width = 0;
self->ntrays = ceil (
(double) (self->shelf.height - self->shelf.first_tray_y) /
(self->shelf.tray_spacing + self->shelf.tray_x)
);
self->shelf_func = shelf_func;
self->box_func = box_func;
self->user_data = user_data;
return self;
}
gboolean
vn_allocator_step (VnAllocator * self)
{
Shelf shelf = self->shelf;
// Adding a new shelf
self->current_shelf++;
self->first_shelf_box = TRUE;
self->current_tray = self->ntrays - 1;
self->tray_width = shelf.hspace / 2;
self->tray_height = shelf.first_tray_y +
(self->ntrays - 1) * shelf.tray_spacing + self->ntrays * shelf.tray_x;
self->tray_x = 0;
self->tray_y = 0;
self->first_tray_box = TRUE;
if (self->shelf_func)
self->shelf_func (self, self->user_data);
// Allocating boxes
for (; self->items[self->item].name; self->item++)
{
Item i = self->items[self->item];
for (; self->amount < i.amount; self->amount++)
{
if (self->first_shelf_box)
{
self->column_width = i.box_width;
}
else if ((self->current_tray < self->ntrays - 1
&& self->tray_y + i.box_height > shelf.tray_spacing - shelf.vspace)
|| self->tray_height + self->tray_y + i.box_height > shelf.max_height - shelf.vspace
|| i.box_width > self->column_width)
{
if (self->tray_x + self->column_width + i.box_width > shelf.width - shelf.hspace)
{
if (self->current_tray > 0)
{
self->tray_height -= shelf.tray_spacing + shelf.tray_x;
self->tray_x = 0;
self->current_tray--;
}
else
return TRUE;
}
else
self->tray_x += self->column_width;
self->tray_y = 0;
self->first_tray_box = TRUE;
self->column_width = i.box_width;
}
if (self->box_func)
self->box_func (self, self->user_data);
self->first_shelf_box = FALSE;
self->first_tray_box = FALSE;
self->tray_y += i.box_height;
self->nboxes++;
}
self->amount = 0;
}
return FALSE;
}
void
vn_allocator_run (VnAllocator * self)
{
gboolean more_items = TRUE;
while (more_items)
more_items = vn_allocator_step (self);
}
void
vn_allocator_free (VnAllocator * self)
{
g_free (self);
}

427
module/src/vn-shelfs.c Normal file
View File

@ -0,0 +1,427 @@
/*
* Copyright (C) 2012 - Juan Ferrer Toribio
*
* 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 "vn-shelfs.h"
#include "vn-allocator.c"
#define $(self, id) (vn_form_get (VN_FORM (self), id))
G_DEFINE_TYPE (VnShelfs, vn_shelfs, VN_TYPE_FORM);
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
#define LINE_WIDTH 10
#define WIDGET_MARGIN 0
#define PAGE_MARGIN 40
#define HEADER_HEIGHT 80
#define TITLE_SIZE 40
#define BOX_TEXT_SIZE 35
#define BOX_MARGIN 6
static GdkRGBA colors[] = {
{0.96, 0.86, 0.86, 1} // Red
,{0.86, 0.96, 0.86, 1} // Green
,{0.86, 0.86, 0.96, 1} // Blue
,{0.96, 0.96, 0.76, 1} // Yellow
};
static Shelf shelf = {
1700 // Height
,1250 // Width
,2000 // Max. height
,620 // Tray spacing
,150 // First tray height
,15 // Tray X
,50 // V. space
,50 // H. space
};
//-------------------------- Drawing methods
void vn_shelfs_draw_box (VnAllocator * allocator, VnShelfs * self)
{
cairo_t * cr = self->cr;
Item i = allocator->items[allocator->item];
int x = self->shelf_x + allocator->tray_width + allocator->tray_x;
int y = self->shelf_y - (allocator->tray_height + allocator->tray_y);
cairo_rectangle (cr, x, y, i.box_width, -i.box_height);
cairo_save (cr);
gint n_color = allocator->item % G_N_ELEMENTS (colors);
gdk_cairo_set_source_rgba (cr, &colors[n_color]);
cairo_fill_preserve (cr);
cairo_restore (cr);
cairo_stroke (cr);
if (allocator->amount == 0 || allocator->first_shelf_box)
{
PangoRectangle extents;
PangoFontDescription * font = pango_font_description_new ();
pango_font_description_set_family (font, "Sans");
pango_font_description_set_absolute_size (font, BOX_TEXT_SIZE * PANGO_SCALE);
PangoLayout * layout = pango_cairo_create_layout (cr);
pango_layout_set_font_description (layout, font);
pango_layout_set_width (layout, (i.box_width - BOX_MARGIN * 2) * PANGO_SCALE);
pango_layout_set_height (layout, (i.box_height - BOX_MARGIN * 2) * PANGO_SCALE);
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_START);
pango_layout_set_text (layout, i.name, -1);
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
pango_layout_get_extents (layout, NULL, &extents);
cairo_move_to (cr
,x + BOX_MARGIN
,y - BOX_MARGIN - i.box_height / 2 - (extents.height / PANGO_SCALE) / 2
);
pango_cairo_show_layout (cr, layout);
g_object_unref (layout);
pango_font_description_free (font);
}
cairo_stroke (cr);
}
void
vn_shelfs_draw_shelf (VnAllocator * allocator, VnShelfs * self)
{
int y;
cairo_t * cr = self->cr;
// Drawing page
int page_x = 0;
int page_y = 0;
cairo_save (cr);
cairo_scale (cr, self->scale / self->shelf_scale, self->scale / self->shelf_scale);
/*
page_x = width / self->scale / 2 - self->page_width / 2;
page_y = (self->widget_margin + self->page_height) * current_shelf + self->widget_margin;
cairo_rectangle (cr, page_x, page_y, self->page_width, self->page_height);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_fill (cr);
cairo_rectangle (cr, page_x, page_y, self->page_width, self->page_height);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_set_line_width (cr, 0.1);
*/
// Drawing the title
cairo_text_extents_t extents;
const gchar * title = gvn_param_get_string ($(self, "title"));
cairo_set_font_size (cr, TITLE_SIZE);
cairo_text_extents (cr, title, &extents);
y = page_y + PAGE_MARGIN + extents.height;
cairo_move_to (cr, page_x + PAGE_MARGIN, y);
cairo_show_text (cr, title);
char * shelf_number = g_strdup_printf ("%d", allocator->current_shelf + 1);
cairo_text_extents (cr, shelf_number, &extents);
cairo_move_to (cr, page_x + self->page_width - PAGE_MARGIN - extents.width, y);
cairo_show_text (cr, shelf_number);
g_free (shelf_number);
cairo_restore (cr);
// Calculating the shelf bottom left coordinates
Shelf shelf = allocator->shelf;
int shelf_x = page_x + self->page_width / 2;
int shelf_y = page_y + PAGE_MARGIN + HEADER_HEIGHT +
(self->page_height - PAGE_MARGIN * 2 - HEADER_HEIGHT) / 2;
shelf_x = shelf_x / self->shelf_scale * self->scale;
shelf_y = shelf_y / self->shelf_scale * self->scale;
shelf_x -= shelf.width / 2;
shelf_y += shelf.max_height / 2;
// Drawing the shelf
cairo_move_to (cr, shelf_x, shelf_y);
cairo_line_to (cr, shelf_x, shelf_y - shelf.height);
cairo_move_to (cr, shelf_x + shelf.width, shelf_y);
cairo_line_to (cr, shelf_x + shelf.width, shelf_y - shelf.height);
// Drawing trays
int last_tray_y = shelf.first_tray_y;
if (shelf.tray_spacing > 0)
while (last_tray_y + shelf.tray_x < shelf.height)
{
y = shelf_y - last_tray_y;
cairo_move_to (cr, shelf_x, y);
cairo_line_to (cr, shelf_x + shelf.width, y);
cairo_move_to (cr, shelf_x, y - shelf.tray_x);
cairo_line_to (cr, shelf_x + shelf.width, y - shelf.tray_x);
last_tray_y += shelf.tray_spacing + shelf.tray_x;
}
self->page_x = page_x;
self->page_y = page_y;
self->shelf_x = shelf_x;
self->shelf_y = shelf_y;
cairo_stroke (cr);
}
void
vn_shelfs_on_begin_print (GtkPrintOperation * op, GtkPrintContext * context, VnShelfs * self)
{
// XXX
gint i;
DbIterator * iter = $(self, "items");
gint nitems = db_iterator_get_nrows (iter);
if (!db_iterator_is_ready (iter) || nitems == 0)
{
gtk_print_operation_cancel (op);
return;
}
Item * items = g_new (Item, nitems + 1);
db_iterator_move_iter (iter, NULL);
for (i = 0; db_iterator_move_next (iter); i++)
{
// int id = gvn_value_get_int (db_iterator_get_value (iter, "Id_Article"));
const gchar * name = gvn_value_get_string (db_iterator_get_value (iter, "Article"));
int size = gvn_value_get_int (db_iterator_get_value (iter, "Medida"));
int width = (int) gvn_value_get_double (db_iterator_get_value (iter, "x"));
int height = (int) gvn_value_get_double (db_iterator_get_value (iter, "z"));
int amount = (int) 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;
}
items[nitems].name = NULL;
// End
VnAllocator * allocator = vn_allocator_new (shelf, items
,(VnAllocatorShelfFunc) vn_shelfs_draw_shelf
,(VnAllocatorBoxFunc) vn_shelfs_draw_box
,self
);
int width = gtk_print_context_get_width (context);
int height = gtk_print_context_get_height (context);
self->page_width = gtk_print_context_get_width (context) /* 210 */;
self->page_height = gtk_print_context_get_height (context) /* 297 */;
self->scale = 0.0;
self->shelf_scale = 0.0;
// Calculating the page scale
{
int w = width - WIDGET_MARGIN * 2;
int h = height - WIDGET_MARGIN * 2;
if (h <= 0 || w <= 0)
return;
self->scale = (double) h / self->page_height;
if (self->page_width * self->scale > w)
self->scale = (double) w / self->page_width;
if (self->scale == 0.0)
return;
self->widget_margin = WIDGET_MARGIN / self->scale;
}
// Calculating the shelf scale
{
int w = self->page_width - PAGE_MARGIN * 2 - HEADER_HEIGHT;
int h = self->page_height - PAGE_MARGIN * 2;
if (h <= 0.0 || w <= 0.0)
return;
self->shelf_scale = (double) h / allocator->shelf.max_height;
if (allocator->shelf.width * self->shelf_scale > w)
self->shelf_scale = (double) w / allocator->shelf.width;
if (self->shelf_scale == 0.0)
return;
self->shelf_scale = self->shelf_scale * self->scale;
}
// Generating the pages
gboolean more_items = TRUE;
self->pages = NULL;
while (more_items)
{
cairo_surface_t * surface = cairo_surface_create_similar (
cairo_get_target (gtk_print_context_get_cairo_context (context)),
CAIRO_CONTENT_COLOR_ALPHA,
width,
height
);
cairo_t * cr = self->cr = cairo_create (surface);
cairo_select_font_face (cr, "Sans"
,CAIRO_FONT_SLANT_NORMAL
,CAIRO_FONT_WEIGHT_NORMAL
);
/*
GdkRGBA color;
gtk_style_context_get_color (gtk_widget_get_style_context (GTK_WIDGET (self->window)), 0, &color);
gdk_cairo_set_source_rgba (cr, &color);
*/
cairo_scale (cr, self->shelf_scale, self->shelf_scale);
cairo_set_line_width (cr, LINE_WIDTH);
// Getting the number of pages
more_items = vn_allocator_step (allocator);
self->pages = g_list_append (self->pages, surface);
cairo_destroy (cr);
}
gtk_print_operation_set_n_pages (op, allocator->current_shelf + 1);
vn_allocator_free (allocator);
}
void
vn_shelfs_on_end_print (GtkPrintOperation * op, GtkPrintContext * context, VnShelfs * self)
{
g_list_free_full (self->pages, (GDestroyNotify) cairo_surface_destroy);
g_message ("Print operation ended!");
}
void
vn_shelfs_on_draw_page (GtkPrintOperation * op, GtkPrintContext * context, gint page_num, VnShelfs * self)
{
cairo_t * cr = gtk_print_context_get_cairo_context (context);
cairo_surface_t * surface = g_list_nth_data (self->pages, page_num);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
}
void
vn_shelfs_print (VnShelfs * self, GtkPrintOperationAction action)
{
GtkPrintOperation * op = gtk_print_operation_new ();
if (self->print_settings)
gtk_print_operation_set_print_settings (op, self->print_settings);
gtk_print_operation_set_job_name (op, _("Shelfs"));
gtk_print_operation_set_embed_page_setup (op, TRUE);
g_object_connect (op
,"signal::begin-print", vn_shelfs_on_begin_print, self
,"signal::end-print", vn_shelfs_on_end_print, self
,"signal::draw-page", vn_shelfs_on_draw_page, self
,NULL
);
GError * err = NULL;
GtkWindow * parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
GtkPrintOperationResult result = gtk_print_operation_run (op, action, parent, &err);
if (result == GTK_PRINT_OPERATION_RESULT_APPLY)
{
self->print_settings = g_object_ref (gtk_print_operation_get_print_settings (op));
}
else if (result == GTK_PRINT_OPERATION_RESULT_ERROR && err)
{
g_warning (err->message);
g_error_free (err);
}
}
void
vn_shelfs_preview_clicked (GtkButton * button, VnShelfs * self)
{
vn_shelfs_print (self, GTK_PRINT_OPERATION_ACTION_PREVIEW);
}
void
vn_shelfs_print_clicked (GtkButton * button, VnShelfs * self)
{
vn_shelfs_print (self, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
}
//-------------------------- Form
void vn_shelfs_on_items_ready (DbIterator * iter, gboolean ready, VnShelfs * self)
{
if (!ready)
return;
g_message ("Ready!");
}
static void vn_shelfs_open (VnShelfs * self, gpointer user_data)
{
self->print_settings = NULL;
gvn_param_set_string ($(self, "title"), "Anthuriums");
gvn_param_set_string ($(self, "filter"), "a.Article LIKE \\'Ant %\\'");
gvn_param_set_int ($(self, "wh"), 1);
GValue date = G_VALUE_INIT;
g_value_init (&date, G_TYPE_DATE_TIME);
g_value_take_boxed (&date, g_date_time_new_now_local ());
gvn_param_set_value ($(self, "date"), &date);
g_value_unset (&date);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void vn_shelfs_init (VnShelfs * self) {}
static void vn_shelfs_finalize (VnShelfs * self)
{
g_clear_object (&self->print_settings);
G_OBJECT_CLASS (vn_shelfs_parent_class)->finalize (G_OBJECT (self));
}
static void vn_shelfs_class_init (VnShelfsClass * k)
{
G_OBJECT_CLASS (k)->finalize = (GObjectFinalizeFunc) vn_shelfs_finalize;
VN_FORM_CLASS (k)->open = (VnFormOpenFunc) vn_shelfs_open;
}

58
module/src/vn-shelfs.h Normal file
View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2012 - Juan Ferrer Toribio
*
* 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/>.
*/
#ifndef VN_SHELFS_H
#define VN_SHELFS_H
#include <vn/vn.h>
#define VN_TYPE_SHELFS (vn_shelfs_get_type ())
#define VN_SHELFS(self) (G_TYPE_CHECK_INSTANCE_CAST (self, VN_TYPE_SHELFS, VnShelfs))
#define VN_IS_ALLOCATOR(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, VN_TYPE_SHELFS))
typedef struct _VnShelfs VnShelfs;
typedef struct _VnShelfsClass VnShelfsClass;
struct _VnShelfs
{
VnForm parent;
GtkPrintSettings * print_settings;
// Cairo
cairo_t * cr;
GList * pages;
int page_width;
int page_height;
int widget_margin;
double scale;
double shelf_scale;
int page_x;
int page_y;
int shelf_x;
int shelf_y;
int draw_name;
};
struct _VnShelfsClass
{
VnFormClass parent;
};
GType vn_shelfs_get_type ();
#endif

View File

@ -165,11 +165,7 @@ static void vn_login_show (VnLogin * self)
*/
static void vn_login_set_loading (VnLogin * self, gboolean loading)
{
gtk_widget_set_sensitive (GTK_WIDGET (self->connect), !loading);
gtk_widget_set_sensitive (GTK_WIDGET (self->settings_button), !loading);
gtk_widget_set_sensitive (GTK_WIDGET (self->user), !loading);
gtk_widget_set_sensitive (GTK_WIDGET (self->pass), !loading);
gtk_widget_set_sensitive (GTK_WIDGET (self->remember), !loading);
gtk_widget_set_sensitive (GTK_WIDGET (self->window), !loading);
gtk_button_set_label (self->connect, NULL);
gtk_container_remove (GTK_CONTAINER (self->connect),