load ui template at runtime, configurable in ini file, load print offsets from ini
This commit is contained in:
parent
971acbbb83
commit
ae21398a5a
4 changed files with 44 additions and 10 deletions
|
@ -1,6 +1,8 @@
|
||||||
[general]
|
[general]
|
||||||
countdown = 5
|
countdown = 5
|
||||||
countdown_audio_file = beep.m4a
|
countdown_audio_file = beep.m4a
|
||||||
|
template = photobooth.ui
|
||||||
|
stylesheet = photobooth.css
|
||||||
overlay_image = overlay_print_rainbows.png
|
overlay_image = overlay_print_rainbows.png
|
||||||
|
|
||||||
[printer]
|
[printer]
|
||||||
|
@ -9,6 +11,8 @@ dpi = 346
|
||||||
width = 2076
|
width = 2076
|
||||||
height = 1384
|
height = 1384
|
||||||
icc_profile = CP955_F.icc
|
icc_profile = CP955_F.icc
|
||||||
|
offset_x = 12.0
|
||||||
|
offset_y = 16.0
|
||||||
|
|
||||||
[camera]
|
[camera]
|
||||||
preview_width = 640
|
preview_width = 640
|
||||||
|
|
15
photobooth.c
15
photobooth.c
|
@ -51,6 +51,7 @@ struct _PhotoBoothPrivate
|
||||||
|
|
||||||
gchar *printer_backend;
|
gchar *printer_backend;
|
||||||
gint print_dpi, print_width, print_height;
|
gint print_dpi, print_width, print_height;
|
||||||
|
gdouble print_x_offset, print_y_offset;
|
||||||
gchar *print_icc_profile;
|
gchar *print_icc_profile;
|
||||||
gint prints_remaining;
|
gint prints_remaining;
|
||||||
GstBuffer *print_buffer;
|
GstBuffer *print_buffer;
|
||||||
|
@ -195,12 +196,15 @@ static void photo_booth_init (PhotoBooth *pb)
|
||||||
priv->print_dpi = PRINT_DPI;
|
priv->print_dpi = PRINT_DPI;
|
||||||
priv->print_width = PRINT_WIDTH;
|
priv->print_width = PRINT_WIDTH;
|
||||||
priv->print_height = PRINT_HEIGHT;
|
priv->print_height = PRINT_HEIGHT;
|
||||||
|
priv->print_x_offset = priv->print_y_offset = 0;
|
||||||
priv->print_buffer = NULL;
|
priv->print_buffer = NULL;
|
||||||
priv->print_icc_profile = NULL;
|
priv->print_icc_profile = NULL;
|
||||||
priv->cam_icc_profile = NULL;
|
priv->cam_icc_profile = NULL;
|
||||||
priv->printer_backend = NULL;
|
priv->printer_backend = NULL;
|
||||||
priv->printer_settings = NULL;
|
priv->printer_settings = NULL;
|
||||||
priv->overlay_image = NULL;
|
priv->overlay_image = NULL;
|
||||||
|
G_stylesheet_filename = NULL;
|
||||||
|
G_template_filename = NULL;
|
||||||
|
|
||||||
G_strings_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
G_strings_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||||
g_mutex_init (&priv->processing_mutex);
|
g_mutex_init (&priv->processing_mutex);
|
||||||
|
@ -270,6 +274,8 @@ static void photo_booth_dispose (GObject *object)
|
||||||
g_hash_table_destroy (G_strings_table);
|
g_hash_table_destroy (G_strings_table);
|
||||||
g_mutex_clear (&priv->processing_mutex);
|
g_mutex_clear (&priv->processing_mutex);
|
||||||
G_OBJECT_CLASS (photo_booth_parent_class)->dispose (object);
|
G_OBJECT_CLASS (photo_booth_parent_class)->dispose (object);
|
||||||
|
g_free (G_stylesheet_filename);
|
||||||
|
g_free (G_template_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename)
|
void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename)
|
||||||
|
@ -308,6 +314,8 @@ void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename)
|
||||||
}
|
}
|
||||||
if (g_key_file_has_group (gkf, "general"))
|
if (g_key_file_has_group (gkf, "general"))
|
||||||
{
|
{
|
||||||
|
G_template_filename = g_key_file_get_string (gkf, "general", "template", NULL);
|
||||||
|
G_stylesheet_filename = g_key_file_get_string (gkf, "general", "stylesheet", NULL);
|
||||||
priv->countdown = g_key_file_get_integer (gkf, "general", "countdown", NULL);
|
priv->countdown = g_key_file_get_integer (gkf, "general", "countdown", NULL);
|
||||||
gchar *audiofile = g_key_file_get_string (gkf, "general", "countdown_audio_file", NULL);
|
gchar *audiofile = g_key_file_get_string (gkf, "general", "countdown_audio_file", NULL);
|
||||||
if (audiofile)
|
if (audiofile)
|
||||||
|
@ -325,7 +333,6 @@ void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename)
|
||||||
g_free (audioabsfilename);
|
g_free (audioabsfilename);
|
||||||
}
|
}
|
||||||
priv->overlay_image = g_key_file_get_string (gkf, "general", "overlay_image", NULL);
|
priv->overlay_image = g_key_file_get_string (gkf, "general", "overlay_image", NULL);
|
||||||
GST_INFO ( "overlay_image: %s", priv->overlay_image);
|
|
||||||
}
|
}
|
||||||
if (g_key_file_has_group (gkf, "printer"))
|
if (g_key_file_has_group (gkf, "printer"))
|
||||||
{
|
{
|
||||||
|
@ -334,6 +341,8 @@ void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename)
|
||||||
priv->print_width = g_key_file_get_integer (gkf, "printer", "width", NULL);
|
priv->print_width = g_key_file_get_integer (gkf, "printer", "width", NULL);
|
||||||
priv->print_height = g_key_file_get_integer (gkf, "printer", "height", NULL);
|
priv->print_height = g_key_file_get_integer (gkf, "printer", "height", NULL);
|
||||||
priv->print_icc_profile = g_key_file_get_string (gkf, "printer", "icc_profile", NULL);
|
priv->print_icc_profile = g_key_file_get_string (gkf, "printer", "icc_profile", NULL);
|
||||||
|
priv->print_x_offset = g_key_file_get_double (gkf, "printer", "offset_x", NULL);
|
||||||
|
priv->print_y_offset = g_key_file_get_double (gkf, "printer", "offset_y", NULL);
|
||||||
}
|
}
|
||||||
if (g_key_file_has_group (gkf, "camera"))
|
if (g_key_file_has_group (gkf, "camera"))
|
||||||
{
|
{
|
||||||
|
@ -1467,7 +1476,7 @@ static void photo_booth_draw_page (GtkPrintOperation *operation, GtkPrintContext
|
||||||
GST_ERROR_OBJECT (context, "can't draw because we have no photo buffer!");
|
GST_ERROR_OBJECT (context, "can't draw because we have no photo buffer!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GST_DEBUG_OBJECT (context, "draw_page no. %i . %" GST_PTR_FORMAT "", page_nr, priv->print_buffer);
|
GST_INFO_OBJECT (context, "draw_page no. %i . %" GST_PTR_FORMAT " size %dx%x, %i dpi, offsets (%.2f, %.2f)", page_nr, priv->print_buffer, priv->print_width, priv->print_height, priv->print_dpi, priv->print_x_offset, priv->print_y_offset);
|
||||||
|
|
||||||
gst_buffer_map(priv->print_buffer, &map, GST_MAP_READ);
|
gst_buffer_map(priv->print_buffer, &map, GST_MAP_READ);
|
||||||
guint8 *h = map.data;
|
guint8 *h = map.data;
|
||||||
|
@ -1481,7 +1490,7 @@ static void photo_booth_draw_page (GtkPrintOperation *operation, GtkPrintContext
|
||||||
|
|
||||||
float scale = (float) PT_PER_IN / (float) priv->print_dpi;
|
float scale = (float) PT_PER_IN / (float) priv->print_dpi;
|
||||||
cairo_scale(cr, scale, scale);
|
cairo_scale(cr, scale, scale);
|
||||||
cairo_set_source_surface(cr, cairosurface, 16.0, 16.0); // FIXME offsets?
|
cairo_set_source_surface(cr, cairosurface, priv->print_x_offset, priv->print_y_offset);
|
||||||
cairo_paint(cr);
|
cairo_paint(cr);
|
||||||
cairo_set_matrix(cr, &m);
|
cairo_set_matrix(cr, &m);
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,8 @@ typedef enum
|
||||||
PB_STATE_PRINTING
|
PB_STATE_PRINTING
|
||||||
} PhotoboothState;
|
} PhotoboothState;
|
||||||
|
|
||||||
|
gchar *G_template_filename;
|
||||||
|
gchar *G_stylesheet_filename;
|
||||||
GHashTable *G_strings_table;
|
GHashTable *G_strings_table;
|
||||||
#define _(key) (g_hash_table_contains (G_strings_table, key) ? g_hash_table_lookup (G_strings_table, key) : key)
|
#define _(key) (g_hash_table_contains (G_strings_table, key) ? g_hash_table_lookup (G_strings_table, key) : key)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <glib/gstdio.h>
|
||||||
#include "photobooth.h"
|
#include "photobooth.h"
|
||||||
#include "photoboothwin.h"
|
#include "photoboothwin.h"
|
||||||
|
|
||||||
|
@ -39,7 +40,21 @@ gboolean _pbw_clock_tick (GtkLabel *status_clock);
|
||||||
static void photo_booth_window_class_init (PhotoBoothWindowClass *klass)
|
static void photo_booth_window_class_init (PhotoBoothWindowClass *klass)
|
||||||
{
|
{
|
||||||
GST_DEBUG_CATEGORY_INIT (photo_booth_windows_debug, "photoboothwin", GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLUE, "PhotoBoothWindow");
|
GST_DEBUG_CATEGORY_INIT (photo_booth_windows_debug, "photoboothwin", GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLUE, "PhotoBoothWindow");
|
||||||
|
GError *error = NULL;
|
||||||
|
if (G_template_filename)
|
||||||
|
{
|
||||||
|
GST_DEBUG ("open template from file '%s'", G_template_filename);
|
||||||
|
GMappedFile *templatef = g_mapped_file_new (G_template_filename, FALSE, &error);
|
||||||
|
gtk_widget_class_set_template (GTK_WIDGET_CLASS (klass), g_mapped_file_get_bytes (templatef));
|
||||||
|
g_mapped_file_unref (templatef);
|
||||||
|
}
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
GST_INFO ( "can't use template from file '%s': %s. Falling back to default resource!", G_template_filename, error->message);
|
||||||
|
g_error_free (error);
|
||||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/schaffenburg/photobooth/photobooth.ui");
|
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/schaffenburg/photobooth/photobooth.ui");
|
||||||
|
}
|
||||||
|
GST_DEBUG ("done!");
|
||||||
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, overlay);
|
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, overlay);
|
||||||
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, spinner);
|
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, spinner);
|
||||||
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, countdown_label);
|
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, countdown_label);
|
||||||
|
@ -56,14 +71,18 @@ static void photo_booth_window_init (PhotoBoothWindow *win)
|
||||||
priv = photo_booth_window_get_instance_private (win);
|
priv = photo_booth_window_get_instance_private (win);
|
||||||
GdkScreen *screen = gdk_screen_get_default ();
|
GdkScreen *screen = gdk_screen_get_default ();
|
||||||
gtk_window_fullscreen_on_monitor (GTK_WINDOW (win), screen, 0);
|
gtk_window_fullscreen_on_monitor (GTK_WINDOW (win), screen, 0);
|
||||||
GFile *cssfile = g_file_new_for_path ("photobooth.css");
|
if (G_stylesheet_filename)
|
||||||
|
{
|
||||||
|
GFile *cssfile = g_file_new_for_path (G_stylesheet_filename);
|
||||||
if (cssfile)
|
if (cssfile)
|
||||||
{
|
{
|
||||||
|
GST_DEBUG ("open stylesheet from file '%s'", G_stylesheet_filename);
|
||||||
GtkCssProvider *cssprovider = gtk_css_provider_new ();
|
GtkCssProvider *cssprovider = gtk_css_provider_new ();
|
||||||
gtk_css_provider_load_from_file (cssprovider, cssfile, NULL);
|
gtk_css_provider_load_from_file (cssprovider, cssfile, NULL);
|
||||||
gtk_style_context_add_provider_for_screen (screen, (GtkStyleProvider *)cssprovider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
gtk_style_context_add_provider_for_screen (screen, (GtkStyleProvider *)cssprovider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
g_object_unref (cssfile);
|
g_object_unref (cssfile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g_timeout_add (1000, (GSourceFunc) _pbw_clock_tick, win->status_clock);
|
g_timeout_add (1000, (GSourceFunc) _pbw_clock_tick, win->status_clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue