gtk-interface.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <gtk/gtk.h>
  2. static GtkBuilder *builder;
  3. static GtkWidget *window;
  4. // static GtkSwitch * RegExpSwitch, * HighHeadSwitch;
  5. char PrefixPatern[321];
  6. #define COMANDBUF 100
  7. #define PROGRAMNAME "SimpleYggGen"
  8. static gboolean regexp, highmode;
  9. void on_window_main_destroy(void) { gtk_main_quit(); }
  10. void on_start_clicked(void) {
  11. if( strlen(PrefixPatern) < 1 && !highmode ) return;
  12. puts("Start search");
  13. puts(PrefixPatern);
  14. if (regexp)
  15. puts("regexp true");
  16. if (highmode)
  17. puts("highmode true");
  18. char command[sizeof(PrefixPatern) + COMANDBUF];
  19. sprintf(command, "./%s %s %s %s", PROGRAMNAME,
  20. regexp ? "-r" : "",PrefixPatern, highmode ? "-H" : "");
  21. system(command);
  22. }
  23. void on_high_mode_activated(GtkSwitch *data, gboolean state) {
  24. puts("High Mode changed");
  25. highmode = state;
  26. }
  27. void on_regexp_mode_changed(GtkSwitch *data, gboolean state) {
  28. puts("RegExp mode changed");
  29. regexp = state;
  30. }
  31. void on_ipv6_pater_changed(GtkWidget *data, gpointer p) {
  32. puts("IPv6 patter changed");
  33. // GtkEntry * ipv6_label=GTK_ENTRY(gtk_builder_get_object(builder,
  34. // "Ipv6Text"));
  35. GtkWidget *entry = (GtkWidget *)data;
  36. const gchar *ipv6 = gtk_entry_get_text(GTK_ENTRY(entry));
  37. puts(ipv6);
  38. memcpy(PrefixPatern, ipv6, strlen(ipv6));
  39. PrefixPatern[strlen(ipv6)] = '\0';
  40. }
  41. int main(int argc, char *argv[]) {
  42. memset((void *)PrefixPatern, '\0', sizeof(PrefixPatern));
  43. // bzero(PrefixPatern, sizeof(PrefixPatern));
  44. gtk_init(&argc, &argv);
  45. builder = gtk_builder_new();
  46. gtk_builder_add_from_file(builder, "GTK.glade", NULL);
  47. window = GTK_WIDGET(gtk_builder_get_object(builder, "MainWindow"));
  48. // RegExpSwitch = GTK_SWITCH(gtk_builder_get_object(builder, "highswitch"));
  49. // HighHeadSwitch = GTK_SWITCH(gtk_builder_get_object(builder,
  50. // "regexpswitch"));
  51. gtk_window_set_title(GTK_WINDOW(window), "Sys-Yggdrasil GTK interface");
  52. gtk_builder_connect_signals(builder, NULL);
  53. GtkWidget *paned = GTK_WIDGET(gtk_builder_get_object(builder, "Paned"));
  54. g_object_unref(builder);
  55. gtk_widget_show(window);
  56. gtk_main();
  57. return 0;
  58. }