]> saetta.ns0.it Git - libzakgtkdecoder/commitdiff
Added signal decode.
authorAndrea Zagli <azagli@libero.it>
Sat, 19 Dec 2015 14:22:08 +0000 (15:22 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 19 Dec 2015 14:22:08 +0000 (15:22 +0100)
.gitignore
configure.ac
src/Makefile.am
src/decoder_marshal.list [new file with mode: 0644]
src/zakgtkdecoder.c
src/zakgtkdecoder.h
tests/decoder.c

index 5cfc0a4b50dc72040207f0d8022869e1f05acbdd..ce195c97c135808f92c6190ece74420a61243dc4 100644 (file)
@@ -50,3 +50,4 @@ intltool-*
 Rules-quot
 *.exe
 *.csv
+decodermarshal.[ch]
\ No newline at end of file
index 48dee930cca2b23bc798c9dc57aea989f1d40a2f..dd5511b8874a96654b182ab4280834a3c259708c 100644 (file)
@@ -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 ******************************
index 494bd048ffaf4edefa738af61821b5eb58b6210f..29dace394633e6d79c752fae108e4aedaa7d90cb 100644 (file)
@@ -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 (file)
index 0000000..3766655
--- /dev/null
@@ -0,0 +1 @@
+STRING:STRING
index 0e6f7a0ebbf13545c28a99568b911103825e36c8..883b2ec7f66897013724ef379ebd3521a363d098 100644 (file)
@@ -29,6 +29,8 @@
        #include <windows.h>
 #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
index 3636d9f22548ea568545d22e25c74b549b0d7972..a3faa2ed9eeaad21f969498adad7482144ac5cf2 100644 (file)
@@ -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;
 };
 
 
index b510e2d232cce41b869fd39ad163f40614d67708..c3563da561fde8eee358162a3de3b5769a13348e 100644 (file)
 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 ();