run-time loaded user-customizable strings lookup
This commit is contained in:
parent
4443c43ad6
commit
02e0e536a2
4 changed files with 73 additions and 14 deletions
63
photobooth.c
63
photobooth.c
|
@ -77,6 +77,7 @@ void photo_booth_background_clicked (GtkWidget *widget, GdkEventButton *event, P
|
||||||
void photo_booth_button_yes_clicked (GtkButton *button, PhotoBoothWindow *win);
|
void photo_booth_button_yes_clicked (GtkButton *button, PhotoBoothWindow *win);
|
||||||
|
|
||||||
/* general private functions */
|
/* general private functions */
|
||||||
|
static void photo_booth_load_strings ();
|
||||||
static void photo_booth_quit_signal (PhotoBooth *pb);
|
static void photo_booth_quit_signal (PhotoBooth *pb);
|
||||||
static void photo_booth_window_destroyed_signal (PhotoBoothWindow *win, PhotoBooth *pb);
|
static void photo_booth_window_destroyed_signal (PhotoBoothWindow *win, PhotoBooth *pb);
|
||||||
static void photo_booth_setup_window (PhotoBooth *pb);
|
static void photo_booth_setup_window (PhotoBooth *pb);
|
||||||
|
@ -172,6 +173,7 @@ static void photo_booth_init (PhotoBooth *pb)
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->capture_thread = NULL;
|
priv->capture_thread = NULL;
|
||||||
|
photo_booth_load_strings();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void photo_booth_setup_window (PhotoBooth *pb)
|
static void photo_booth_setup_window (PhotoBooth *pb)
|
||||||
|
@ -224,6 +226,43 @@ static void photo_booth_dispose (GObject *object)
|
||||||
G_OBJECT_CLASS (photo_booth_parent_class)->dispose (object);
|
G_OBJECT_CLASS (photo_booth_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void photo_booth_load_strings ()
|
||||||
|
{
|
||||||
|
GKeyFile* gkf;
|
||||||
|
GError *error = NULL;
|
||||||
|
guint group, keyidx;
|
||||||
|
gsize num_groups, num_keys;
|
||||||
|
gchar **groups, **keys, *val;
|
||||||
|
gchar *key;
|
||||||
|
gchar *value;
|
||||||
|
|
||||||
|
G_strings_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||||
|
gkf = g_key_file_new();
|
||||||
|
|
||||||
|
if (g_key_file_load_from_file(gkf, STRINGS_FILE, G_KEY_FILE_NONE, &error))
|
||||||
|
{
|
||||||
|
groups = g_key_file_get_groups(gkf, &num_groups);
|
||||||
|
for (group = 0; group < num_groups; group++)
|
||||||
|
{
|
||||||
|
GST_INFO("group %u/%u: \t%s", group, num_groups - 1, groups[group]);
|
||||||
|
keys = g_key_file_get_keys (gkf, groups[group], &num_keys, &error);
|
||||||
|
for (keyidx = 0; keyidx < num_keys; keyidx++)
|
||||||
|
{
|
||||||
|
val = g_key_file_get_value(gkf, groups[group], keys[keyidx], &error);
|
||||||
|
key = g_strdup(keys[keyidx]);
|
||||||
|
value = g_strdup(val);
|
||||||
|
g_hash_table_insert (G_strings_table, key, value);
|
||||||
|
GST_LOG ("key %u/%u:\t'%s' => '%s'", keyidx, num_keys-1, key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
GST_INFO ( "can't read strings lookup file %s: %s", STRINGS_FILE, error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void _gphoto_err(GPLogLevel level, const char *domain, const char *str, void *data)
|
static void _gphoto_err(GPLogLevel level, const char *domain, const char *str, void *data)
|
||||||
{
|
{
|
||||||
GST_DEBUG ("GPhoto %d, %s:%s", (int) level, domain, str);
|
GST_DEBUG ("GPhoto %d, %s:%s", (int) level, domain, str);
|
||||||
|
@ -373,7 +412,7 @@ static void photo_booth_capture_thread_func (PhotoBooth *pb)
|
||||||
g_main_context_invoke (NULL, (GSourceFunc) photo_booth_preview, pb);
|
g_main_context_invoke (NULL, (GSourceFunc) photo_booth_preview, pb);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gtk_label_set_text (priv->win->status, "no camera connected!");
|
gtk_label_set_text (priv->win->status, _("No camera connected!"));
|
||||||
GST_INFO_OBJECT (pb, "no camera info.");
|
GST_INFO_OBJECT (pb, "no camera info.");
|
||||||
}
|
}
|
||||||
timeout = 5000;
|
timeout = 5000;
|
||||||
|
@ -425,7 +464,7 @@ static void photo_booth_capture_thread_func (PhotoBooth *pb)
|
||||||
{
|
{
|
||||||
if (pb->cam_info)
|
if (pb->cam_info)
|
||||||
{
|
{
|
||||||
gtk_label_set_text (priv->win->status, "taking photo...");
|
gtk_label_set_text (priv->win->status, _("Taking photo..."));
|
||||||
ret = photo_booth_take_photo (pb->cam_info);
|
ret = photo_booth_take_photo (pb->cam_info);
|
||||||
if (ret)
|
if (ret)
|
||||||
g_main_context_invoke (NULL, (GSourceFunc) photo_booth_snapshot_taken, pb);
|
g_main_context_invoke (NULL, (GSourceFunc) photo_booth_snapshot_taken, pb);
|
||||||
|
@ -771,7 +810,7 @@ static gboolean photo_booth_preview (PhotoBooth *pb)
|
||||||
gst_element_set_state (pb->video_bin, GST_STATE_PLAYING);
|
gst_element_set_state (pb->video_bin, GST_STATE_PLAYING);
|
||||||
GST_DEBUG_OBJECT (pb, "photo_booth_preview done");
|
GST_DEBUG_OBJECT (pb, "photo_booth_preview done");
|
||||||
pb->state = PB_STATE_PREVIEW;
|
pb->state = PB_STATE_PREVIEW;
|
||||||
gtk_label_set_text (priv->win->status, "camera ready, showing preview video");
|
gtk_label_set_text (priv->win->status, _("Touch screen to take a photo!"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,11 +868,11 @@ static void photo_booth_get_printer_status (PhotoBooth *pb)
|
||||||
gchar *size = g_match_info_fetch_named(match_info, "size");
|
gchar *size = g_match_info_fetch_named(match_info, "size");
|
||||||
remain = atoi(g_match_info_fetch_named(match_info, "remain"));
|
remain = atoi(g_match_info_fetch_named(match_info, "remain"));
|
||||||
guint total = atoi(g_match_info_fetch_named(match_info, "total"));
|
guint total = atoi(g_match_info_fetch_named(match_info, "total"));
|
||||||
label_string = g_strdup_printf("printer %s online. media (%s) %i prints remaining", priv->printer_backend, size, remain);
|
label_string = g_strdup_printf(_("Printer %s online. %i prints (%s) remaining"), priv->printer_backend, remain, size);
|
||||||
GST_INFO_OBJECT (pb, "printer %s status: media code %i (%s) prints remaining %i of %i", priv->printer_backend, code, size, remain, total);
|
GST_INFO_OBJECT (pb, "printer %s status: media code %i (%s) prints remaining %i of %i", priv->printer_backend, code, size, remain, total);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
label_string = g_strdup_printf("can't parse printer backend output");
|
label_string = g_strdup_printf(_("Can't parse printer backend output"));
|
||||||
GST_ERROR_OBJECT (pb, "%s: '%s'", label_string, output);
|
GST_ERROR_OBJECT (pb, "%s: '%s'", label_string, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -842,11 +881,11 @@ static void photo_booth_get_printer_status (PhotoBooth *pb)
|
||||||
regex = g_regex_new ("ERROR: Printer open failure", G_REGEX_MULTILINE|G_REGEX_DOTALL, 0, &error);
|
regex = g_regex_new ("ERROR: Printer open failure", G_REGEX_MULTILINE|G_REGEX_DOTALL, 0, &error);
|
||||||
if (g_regex_match (regex, output, 0, &match_info))
|
if (g_regex_match (regex, output, 0, &match_info))
|
||||||
{
|
{
|
||||||
label_string = g_strdup_printf("printer %s off-line", priv->printer_backend);
|
label_string = g_strdup_printf(_("Printer %s off-line"), priv->printer_backend);
|
||||||
GST_WARNING_OBJECT (pb, "%s", label_string);
|
GST_WARNING_OBJECT (pb, "%s", label_string);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
label_string = g_strdup_printf("can't parse printer backend output");
|
label_string = g_strdup_printf(_("can't parse printer backend output"));
|
||||||
GST_ERROR_OBJECT (pb, "%s: '%s'", label_string, output);
|
GST_ERROR_OBJECT (pb, "%s: '%s'", label_string, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -855,7 +894,7 @@ static void photo_booth_get_printer_status (PhotoBooth *pb)
|
||||||
g_regex_unref (regex);
|
g_regex_unref (regex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
label_string = g_strdup_printf("can't spawn %s", argv[0]);
|
label_string = g_strdup_printf(_("Can't spawn %s"), argv[0]);
|
||||||
GST_ERROR_OBJECT (pb, "%s %s %s (%s)", label_string, argv[1], envp[0], error->message);
|
GST_ERROR_OBJECT (pb, "%s %s %s (%s)", label_string, argv[1], envp[0], error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
}
|
}
|
||||||
|
@ -1010,7 +1049,7 @@ static gboolean photo_booth_snapshot_taken (PhotoBooth *pb)
|
||||||
GstPad *pad;
|
GstPad *pad;
|
||||||
|
|
||||||
GST_INFO_OBJECT (pb, "photo_booth_snapshot_taken size=%lu", pb->cam_info->size);
|
GST_INFO_OBJECT (pb, "photo_booth_snapshot_taken size=%lu", pb->cam_info->size);
|
||||||
gtk_label_set_text (priv->win->status, "processing photo...");
|
gtk_label_set_text (priv->win->status, _("Processing photo..."));
|
||||||
|
|
||||||
appsrc = gst_bin_get_by_name (GST_BIN (pb->photo_bin), "photo-appsrc");
|
appsrc = gst_bin_get_by_name (GST_BIN (pb->photo_bin), "photo-appsrc");
|
||||||
buffer = gst_buffer_new_wrapped (pb->cam_info->data, pb->cam_info->size);
|
buffer = gst_buffer_new_wrapped (pb->cam_info->data, pb->cam_info->size);
|
||||||
|
@ -1043,7 +1082,7 @@ static GstPadProbeReturn photo_booth_catch_photo_buffer (GstPad * pad, GstPadPro
|
||||||
photo_booth_window_set_spinner (priv->win, FALSE);
|
photo_booth_window_set_spinner (priv->win, FALSE);
|
||||||
GST_INFO_OBJECT (priv->win->button_yes, "PB_STATE_TAKING_PHOTO -> PB_STATE_PROCESS_PHOTO. hide spinner, show button");
|
GST_INFO_OBJECT (priv->win->button_yes, "PB_STATE_TAKING_PHOTO -> PB_STATE_PROCESS_PHOTO. hide spinner, show button");
|
||||||
gtk_widget_show (GTK_WIDGET (priv->win->button_yes));
|
gtk_widget_show (GTK_WIDGET (priv->win->button_yes));
|
||||||
gtk_label_set_text (priv->win->status, "Print Photo? Touch background to cancel!");
|
gtk_label_set_text (priv->win->status, _("Print Photo? Touch background to cancel!"));
|
||||||
return GST_PAD_PROBE_PASS;
|
return GST_PAD_PROBE_PASS;
|
||||||
}
|
}
|
||||||
if (pb->state == PB_STATE_PROCESS_PHOTO)
|
if (pb->state == PB_STATE_PROCESS_PHOTO)
|
||||||
|
@ -1116,10 +1155,10 @@ static void photo_booth_print (PhotoBooth *pb)
|
||||||
gtk_label_set_text (priv->win->status, "PRINTING................");
|
gtk_label_set_text (priv->win->status, "PRINTING................");
|
||||||
}
|
}
|
||||||
else if (priv->prints_remaining == -1) {
|
else if (priv->prints_remaining == -1) {
|
||||||
gtk_label_set_text (priv->win->status, "can't print... no printer connected!!!");
|
gtk_label_set_text (priv->win->status, _("Can't print, no printer connected!"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
gtk_label_set_text (priv->win->status, "can't print... out of paper!!!");
|
gtk_label_set_text (priv->win->status, _("Can't print, out of paper!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
PhotoBooth *photo_booth_new (void)
|
PhotoBooth *photo_booth_new (void)
|
||||||
|
|
|
@ -80,6 +80,9 @@ typedef enum
|
||||||
PB_STATE_PRINTING
|
PB_STATE_PRINTING
|
||||||
} PhotoboothState;
|
} PhotoboothState;
|
||||||
|
|
||||||
|
#define STRINGS_FILE "strings.ini"
|
||||||
|
GHashTable *G_strings_table;
|
||||||
|
#define _(key) (g_hash_table_contains (G_strings_table, key) ? g_hash_table_lookup (G_strings_table, key) : key)
|
||||||
|
|
||||||
#define PHOTO_BOOTH_TYPE (photo_booth_get_type ())
|
#define PHOTO_BOOTH_TYPE (photo_booth_get_type ())
|
||||||
#define PHOTO_BOOTH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),PHOTO_BOOTH_TYPE,PhotoBooth))
|
#define PHOTO_BOOTH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),PHOTO_BOOTH_TYPE,PhotoBooth))
|
||||||
|
|
|
@ -119,7 +119,7 @@ gboolean _pbw_tick_countdown (PhotoBoothWindow *win)
|
||||||
GST_DEBUG ("_pbw_tick_countdown %i", priv->countdown);
|
GST_DEBUG ("_pbw_tick_countdown %i", priv->countdown);
|
||||||
if (priv->countdown > 0)
|
if (priv->countdown > 0)
|
||||||
{
|
{
|
||||||
gchar *status_str = g_strdup_printf ("Taking photo in %d seconds...", priv->countdown);
|
gchar *status_str = g_strdup_printf (_("Taking photo in %d seconds..."), priv->countdown);
|
||||||
gtk_label_set_text (win->status, status_str);
|
gtk_label_set_text (win->status, status_str);
|
||||||
str = g_strdup_printf ("%d...", priv->countdown);
|
str = g_strdup_printf ("%d...", priv->countdown);
|
||||||
gtk_label_set_text (priv->countdown_label, str);
|
gtk_label_set_text (priv->countdown_label, str);
|
||||||
|
@ -127,7 +127,7 @@ gboolean _pbw_tick_countdown (PhotoBoothWindow *win)
|
||||||
}
|
}
|
||||||
else if (priv->countdown == 0)
|
else if (priv->countdown == 0)
|
||||||
{
|
{
|
||||||
gtk_label_set_text (priv->countdown_label, "SAY CHEESE!");
|
gtk_label_set_text (priv->countdown_label, _("SAY CHEESE!"));
|
||||||
}
|
}
|
||||||
else if (priv->countdown == -1)
|
else if (priv->countdown == -1)
|
||||||
{
|
{
|
||||||
|
|
17
strings.ini
Normal file
17
strings.ini
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[Status Strings]
|
||||||
|
No camera connected! = Keine Kamera verbunden!
|
||||||
|
Taking photo... = fotografiere...
|
||||||
|
Touch screen to take a photo! = Bildschirm berühren zum Fotografieren!
|
||||||
|
Processing photo... = verarbeite Foto...
|
||||||
|
Print Photo? Touch background to cancel! = Foto Drucken? Zum Abbrechen Hintergrund berühren
|
||||||
|
Taking photo in %d seconds... = Aufnahme in %d Sekunden...
|
||||||
|
SAY CHEESE! = BITTE LÄCHELN :)
|
||||||
|
|
||||||
|
[Printer String]
|
||||||
|
Printer %s online. %i prints (%s) remaining = Drucker %s bereit. %i Abzüge (%s) übrig
|
||||||
|
Can't parse printer backend output = Fehler beim Verarbeiten der Ausgabe vom Drucker-Backend
|
||||||
|
Printer %s off-line = Drucker %s ist nicht verfügbar
|
||||||
|
Can't spawn %s = Fehler beim Starten von %s
|
||||||
|
Can't print, no printer connected! = Kann nicht Drucken weil kein Drucker verbunden ist!
|
||||||
|
Can't print, out of paper! = Kann nicht Drucken weil kein Papier übrig ist!
|
||||||
|
|
Loading…
Add table
Reference in a new issue