From: Andrea Zagli Date: Sat, 19 Dec 2015 14:22:08 +0000 (+0100) Subject: Added signal decode. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=d042ebeb38f86e1fa910fd8db4f9d9b371ce2580;p=libzakgtkdecoder Added signal decode. --- diff --git a/.gitignore b/.gitignore index 5cfc0a4..ce195c9 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ intltool-* Rules-quot *.exe *.csv +decodermarshal.[ch] \ No newline at end of file diff --git a/configure.ac b/configure.ac index 48dee93..dd5511b 100644 --- a/configure.ac +++ b/configure.ac @@ -29,6 +29,11 @@ AC_PROG_MAKE_SET AC_PROG_LIBTOOL AC_PROG_RANLIB +dnl ****************************** +dnl glib-genmarshal +dnl ****************************** +AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal) + dnl ****************************** dnl Translations dnl ****************************** diff --git a/src/Makefile.am b/src/Makefile.am index 494bd04..29dace3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,14 @@ AM_CPPFLAGS = $(ZAKGTKDECODER_CFLAGS) \ lib_LTLIBRARIES = libzakgtkdecoder.la +decodermarshal.c: decodermarshal.h decoder_marshal.list $(GLIB_GENMARSHAL) + $(GLIB_GENMARSHAL) $(srcdir)/decoder_marshal.list --body --prefix=_zak_gtk_decoder_marshal > $(srcdir)/$@ + +decodermarshal.h: decoder_marshal.list $(GLIB_GENMARSHAL) + $(GLIB_GENMARSHAL) $(srcdir)/decoder_marshal.list --header --prefix=_zak_gtk_decoder_marshal > $(srcdir)/$@ + libzakgtkdecoder_la_SOURCES = \ + decodermarshal.c \ zakgtkdecoder.c libzakgtkdecoder_la_LDFLAGS = -no-undefined @@ -24,3 +31,6 @@ libzakgtkdecoder_include_HEADERS = \ zakgtkdecoder.h libzakgtkdecoder_includedir = $(includedir)/libzakgtkdecoder + +noinst_HEADERS = \ + decodermarshal.h diff --git a/src/decoder_marshal.list b/src/decoder_marshal.list new file mode 100644 index 0000000..3766655 --- /dev/null +++ b/src/decoder_marshal.list @@ -0,0 +1 @@ +STRING:STRING diff --git a/src/zakgtkdecoder.c b/src/zakgtkdecoder.c index 0e6f7a0..883b2ec 100644 --- a/src/zakgtkdecoder.c +++ b/src/zakgtkdecoder.c @@ -29,6 +29,8 @@ #include #endif +#include "decodermarshal.h" + #include "zakgtkdecoder.h" enum @@ -220,6 +222,22 @@ zak_gtk_decoder_class_init (ZakGtkDecoderClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /** + * ZakGtkDecoder::decode: + * @zak_gtk_decoder: + * + */ + klass->decode_signal_id = g_signal_new ("decode", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + _zak_gtk_decoder_marshal_STRING__STRING, + G_TYPE_STRING, + 1, + G_TYPE_STRING); } static void @@ -372,11 +390,28 @@ static void zak_gtk_decoder_decode (ZakGtkDecoder *decoder) { ZakGtkDecoderPrivate *priv; + ZakGtkDecoderClass *klass; + + gchar *ret; g_return_if_fail (ZAK_GTK_IS_DECODER (decoder)); + klass = ZAK_GTK_DECODER_GET_CLASS (decoder); + priv = ZAK_GTK_DECODER_GET_PRIVATE (decoder); + ret = NULL; + g_signal_emit (decoder, klass->decode_signal_id, + 0, + gtk_label_get_text (GTK_LABEL (priv->lbl_key)), + &ret); + + if (ret == NULL) + { + ret = g_strdup (""); + } + + gtk_entry_set_text (GTK_ENTRY (priv->txt_decoded), ret); } void diff --git a/src/zakgtkdecoder.h b/src/zakgtkdecoder.h index 3636d9f..a3faa2e 100644 --- a/src/zakgtkdecoder.h +++ b/src/zakgtkdecoder.h @@ -38,6 +38,8 @@ struct _ZakGtkDecoderClass guint btn_new_clicked_signal_id; guint btn_open_clicked_signal_id; guint btn_browse_clicked_signal_id; + + guint decode_signal_id; }; diff --git a/tests/decoder.c b/tests/decoder.c index b510e2d..c3563da 100644 --- a/tests/decoder.c +++ b/tests/decoder.c @@ -23,29 +23,38 @@ GtkWidget *w; GtkWidget *decoder; +static gchar +*on_decode (gpointer instance, gchar *key, gpointer user_data) +{ + g_message ("Decoding."); + return g_strdup_printf ("Decode for key «%s»", key); +} + static gboolean -on_btn_clean_clicked (gpointer instance, gint arg1, gpointer user_data) +on_btn_clean_clicked (gpointer instance, gpointer user_data) { + g_message ("Clean clicked."); return FALSE; } static gboolean on_btn_new_clicked (gpointer instance, gpointer user_data) { - g_debug ("New clicked."); + g_message ("New clicked."); return FALSE; } static gboolean on_btn_open_clicked (gpointer instance, gpointer user_data) { - g_debug ("Open clicked."); + g_message ("Open clicked."); return FALSE; } static gboolean on_btn_browse_clicked (gpointer instance, gpointer user_data) { + g_message ("Browse clicked."); zak_gtk_decoder_set_key (ZAK_GTK_DECODER (decoder), "1"); return FALSE; } @@ -68,6 +77,9 @@ main (int argc, char **argv) g_signal_connect (w, "destroy", gtk_main_quit, NULL); decoder = zak_gtk_decoder_new (); + zak_gtk_decoder_show_btn_new (ZAK_GTK_DECODER (decoder), TRUE); + zak_gtk_decoder_show_btn_clean (ZAK_GTK_DECODER (decoder), TRUE); + zak_gtk_decoder_show_btn_open (ZAK_GTK_DECODER (decoder), TRUE); gtk_container_add (GTK_CONTAINER (w), decoder); g_signal_connect (G_OBJECT (decoder), "btn_clean_clicked", @@ -79,6 +91,9 @@ main (int argc, char **argv) g_signal_connect (G_OBJECT (decoder), "btn_browse_clicked", G_CALLBACK (on_btn_browse_clicked), NULL); + g_signal_connect (G_OBJECT (decoder), "decode", + G_CALLBACK (on_decode), NULL); + gtk_widget_show_all (w); gtk_main ();