Guest User

ipaddresstest.c

a guest
Aug 30th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #include <gtk/gtk.h>
  2. #include "myipaddress.h"
  3.  
  4. static void ip_address_changed (MyIPAddress*);
  5.  
  6. int main (int argc,
  7.           char *argv[])
  8. {
  9.   GtkWidget *window, *ipaddress;
  10.   gint address[4] = { 1, 20, 35, 255 };
  11.  
  12.   gtk_init (&argc, &argv);
  13.  
  14.   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  15.   gtk_window_set_title (GTK_WINDOW (window), "GtkIPAddress");
  16.   gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  17.  
  18.   g_signal_connect (G_OBJECT (window), "destroy",
  19.                     G_CALLBACK (gtk_main_quit), NULL);
  20.  
  21.   ipaddress = my_ip_address_new ();
  22.   my_ip_address_set_address (MY_IP_ADDRESS (ipaddress), address);
  23.   g_signal_connect (G_OBJECT (ipaddress), "ip-changed",
  24.                     G_CALLBACK (ip_address_changed), NULL);
  25.  
  26.   gtk_container_add (GTK_CONTAINER (window), ipaddress);
  27.   gtk_widget_show_all (window);
  28.  
  29.   gtk_main ();
  30.   return 0;
  31. }
  32.  
  33. /* When the IP address is changed, print the new value to the screen. */
  34. static void
  35. ip_address_changed (MyIPAddress *ipaddress)
  36. {
  37.   gchar *address = my_ip_address_get_address (ipaddress);
  38.   g_print ("%s\n", address);
  39.   g_free (address);
  40. }
Add Comment
Please, Sign In to add comment