Diff for /embedaddon/mtr/ui/gtk.c between versions 1.1.1.1 and 1.1.1.3

version 1.1.1.1, 2019/10/21 14:25:31 version 1.1.1.3, 2023/09/27 11:18:58
Line 4 Line 4
     Changes/additions Copyright (C) 1998 R.E.Wolff@BitWizard.nl      Changes/additions Copyright (C) 1998 R.E.Wolff@BitWizard.nl
   
     This program is free software; you can redistribute it and/or modify      This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2 as     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.      published by the Free Software Foundation.
   
     This program is distributed in the hope that it will be useful,      This program is distributed in the hope that it will be useful,
Line 12 Line 12
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.      GNU General Public License for more details.
   
    You should have received a copy of the GNU General Public License    You should have received a copy of the GNU General Public License along
    along with this program; if not, write to the Free Software    with this program; if not, write to the Free Software Foundation, Inc.,
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */  */
   
 #include "config.h"  #include "config.h"
Line 94  int gtk_detect( Line 94  int gtk_detect(
 {  {
     if (getenv("DISPLAY") != NULL) {      if (getenv("DISPLAY") != NULL) {
         /* If we do this here, gtk_init exits on an error. This happens          /* If we do this here, gtk_init exits on an error. This happens
           BEFORE the user has had a chance to tell us not to use the            BEFORE the user has had a chance to tell us not to use the
            display... */             display... */
         return TRUE;          return TRUE;
     } else {      } else {
Line 198  static gint About_clicked( Line 198  static gint About_clicked(
     gtk_show_about_dialog(GTK_WINDOW(main_window)      gtk_show_about_dialog(GTK_WINDOW(main_window)
                           , "version", PACKAGE_VERSION, "copyright",                            , "version", PACKAGE_VERSION, "copyright",
                           "Copyright \xc2\xa9 1997,1998  Matt Kimball",                            "Copyright \xc2\xa9 1997,1998  Matt Kimball",
                          "website", "http://www.bitwizard.nl/mtr/",                          "website", "https://www.bitwizard.nl/mtr/",
                           "authors", authors, "comments",                            "authors", authors, "comments",
                           "The 'traceroute' and 'ping' programs in a single network diagnostic tool.",                            "The 'traceroute' and 'ping' programs in a single network diagnostic tool.",
                           "license",                            "license",
Line 244  static gint Host_activate( Line 244  static gint Host_activate(
     gpointer data)      gpointer data)
 {  {
     struct mtr_ctl *ctl = (struct mtr_ctl *) data;      struct mtr_ctl *ctl = (struct mtr_ctl *) data;
    struct hostent *addr;    struct addrinfo *res = NULL;
   
    addr = dns_forward(gtk_entry_get_text(GTK_ENTRY(entry)));    ctl->af = DEFAULT_AF;  // should this obey the cmd line option?
    if (addr) {    ctl->Hostname = gtk_entry_get_text(GTK_ENTRY(entry));
        net_reopen(ctl, addr);    if (get_addrinfo_from_name(ctl, &res, ctl->Hostname) == 0) {
         net_reopen(ctl, res);
         freeaddrinfo(res);
         net_send_batch(ctl);
         /* If we are "Paused" at this point it is usually because someone          /* If we are "Paused" at this point it is usually because someone
            entered a non-existing host. Therefore do the go-ahead... */             entered a non-existing host. Therefore do the go-ahead... */
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(Pause_Button), 0);          gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(Pause_Button), 0);
Line 272  static void Toolbar_fill( Line 275  static void Toolbar_fill(
     GtkWidget *Label;      GtkWidget *Label;
     GtkAdjustment *Adjustment;      GtkAdjustment *Adjustment;
   
    Button = gtk_button_new_from_stock(GTK_STOCK_QUIT);    Button = gtk_button_new_with_label("Quit");
     gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);      gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
    g_signal_connect(GTK_OBJECT(Button), "clicked",    g_signal_connect(G_OBJECT(Button), "clicked",
                     GTK_SIGNAL_FUNC(Window_destroy), NULL);                     G_CALLBACK(Window_destroy), NULL);
   
    Button = gtk_button_new_from_stock(GTK_STOCK_ABOUT);    Button = gtk_button_new_with_label("About");
     gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);      gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
    g_signal_connect(GTK_OBJECT(Button), "clicked",    g_signal_connect(G_OBJECT(Button), "clicked",
                     GTK_SIGNAL_FUNC(About_clicked), NULL);                     G_CALLBACK(About_clicked), NULL);
   
     Button = gtk_button_new_with_mnemonic("_Restart");      Button = gtk_button_new_with_mnemonic("_Restart");
     gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);      gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
    g_signal_connect(GTK_OBJECT(Button), "clicked",    g_signal_connect(G_OBJECT(Button), "clicked",
                     GTK_SIGNAL_FUNC(Restart_clicked), ctl);                     G_CALLBACK(Restart_clicked), ctl);
   
     Pause_Button = gtk_toggle_button_new_with_mnemonic("_Pause");      Pause_Button = gtk_toggle_button_new_with_mnemonic("_Pause");
     gtk_box_pack_end(GTK_BOX(Toolbar), Pause_Button, FALSE, FALSE, 0);      gtk_box_pack_end(GTK_BOX(Toolbar), Pause_Button, FALSE, FALSE, 0);
    g_signal_connect(GTK_OBJECT(Pause_Button), "clicked",    g_signal_connect(G_OBJECT(Pause_Button), "clicked",
                     GTK_SIGNAL_FUNC(Pause_clicked), ctl);                     G_CALLBACK(Pause_clicked), ctl);
   
     /* allow root only to set zero delay */      /* allow root only to set zero delay */
     Adjustment = (GtkAdjustment *) gtk_adjustment_new(ctl->WaitTime,      Adjustment = (GtkAdjustment *) gtk_adjustment_new(ctl->WaitTime,
                                                      getuid() ==                                                      running_as_root() ? 0.01 : 1.00,
                                                      0 ? 0.01 : 1.00, 
                                                       999.99, 1.0, 10.0,                                                        999.99, 1.0, 10.0,
                                                       0.0);                                                        0.0);
     Button = gtk_spin_button_new(Adjustment, 0.5, 2);      Button = gtk_spin_button_new(Adjustment, 0.5, 2);
     gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(Button), TRUE);      gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(Button), TRUE);
     gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);      gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
     ctl->gtk_data = Button;      ctl->gtk_data = Button;
    g_signal_connect(GTK_OBJECT(Adjustment), "value_changed",    g_signal_connect(G_OBJECT(Adjustment), "value_changed",
                     GTK_SIGNAL_FUNC(WaitTime_changed), ctl);                     G_CALLBACK(WaitTime_changed), ctl);
   
     Label = gtk_label_new_with_mnemonic("_Hostname:");      Label = gtk_label_new_with_mnemonic("_Hostname:");
     gtk_box_pack_start(GTK_BOX(Toolbar), Label, FALSE, FALSE, 0);      gtk_box_pack_start(GTK_BOX(Toolbar), Label, FALSE, FALSE, 0);
   
     Entry = gtk_entry_new();      Entry = gtk_entry_new();
     gtk_entry_set_text(GTK_ENTRY(Entry), ctl->Hostname);      gtk_entry_set_text(GTK_ENTRY(Entry), ctl->Hostname);
    g_signal_connect(GTK_OBJECT(Entry), "activate",    g_signal_connect(G_OBJECT(Entry), "activate",
                     GTK_SIGNAL_FUNC(Host_activate), ctl);                     G_CALLBACK(Host_activate), ctl);
     gtk_box_pack_start(GTK_BOX(Toolbar), Entry, TRUE, TRUE, 0);      gtk_box_pack_start(GTK_BOX(Toolbar), Entry, TRUE, TRUE, 0);
   
     gtk_label_set_mnemonic_widget(GTK_LABEL(Label), Entry);      gtk_label_set_mnemonic_widget(GTK_LABEL(Label), Entry);
Line 395  static void TreeViewCreate( Line 397  static void TreeViewCreate(
     ReportTreeView =      ReportTreeView =
         gtk_tree_view_new_with_model(GTK_TREE_MODEL(ReportStore));          gtk_tree_view_new_with_model(GTK_TREE_MODEL(ReportStore));
   
    g_signal_connect(GTK_OBJECT(ReportTreeView), "button_press_event",    g_signal_connect(G_OBJECT(ReportTreeView), "button_press_event",
                      G_CALLBACK(ReportTreeView_clicked), ctl);                       G_CALLBACK(ReportTreeView_clicked), ctl);
   
 #ifdef HAVE_IPINFO  #ifdef HAVE_IPINFO
Line 508  static void update_tree_row( Line 510  static void update_tree_row(
     char str[256] = "???", *name = str;      char str[256] = "???", *name = str;
   
     addr = net_addr(row);      addr = net_addr(row);
    if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {    if (addrcmp(addr, &ctl->unspec_addr, ctl->af)) {
         if ((name = dns_lookup(ctl, addr))) {          if ((name = dns_lookup(ctl, addr))) {
             if (ctl->show_ips) {              if (ctl->show_ips) {
                 snprintf(str, sizeof(str), "%s (%s)", name,                  snprintf(str, sizeof(str), "%s (%s)", name,
                         strlongip(ctl, addr));                         strlongip(ctl->af, addr));
                 name = str;                  name = str;
             }              }
         } else          } else
            name = strlongip(ctl, addr);            name = strlongip(ctl->af, addr);
     }      }
   
     gtk_list_store_set(ReportStore, iter,      gtk_list_store_set(ReportStore, iter,
Line 565  void gtk_redraw( Line 567  void gtk_redraw(
     }      }
 }  }
   
   // GTK 3 has changed the interface a bit. Here a few defines so that we can
   // work with GTK2 or GTK3 as required.
   #ifdef HAVE_GTK3
   #define gtk_vbox_new_(orientation,sz) gtk_box_new(orientation, sz)
   #define gtk_hbox_new_(orientation,sz) gtk_box_new(orientation, sz)
   #else
   #define gtk_vbox_new_(orientation,sz) gtk_vbox_new(FALSE, sz)
   #define gtk_hbox_new_(orientation,sz) gtk_hbox_new(FALSE, sz)
   #endif
   
 static void Window_fill(  static void Window_fill(
     struct mtr_ctl *ctl,      struct mtr_ctl *ctl,
Line 577  static void Window_fill( Line 588  static void Window_fill(
     gtk_window_set_title(GTK_WINDOW(Window), "My traceroute");      gtk_window_set_title(GTK_WINDOW(Window), "My traceroute");
     gtk_window_set_default_size(GTK_WINDOW(Window), 650, 400);      gtk_window_set_default_size(GTK_WINDOW(Window), 650, 400);
     gtk_container_set_border_width(GTK_CONTAINER(Window), 10);      gtk_container_set_border_width(GTK_CONTAINER(Window), 10);
     VBox = gtk_vbox_new(FALSE, 10);  
   
    Toolbar = gtk_hbox_new(FALSE, 10);    VBox    = gtk_vbox_new_(GTK_ORIENTATION_VERTICAL,   10);
     Toolbar = gtk_hbox_new_(GTK_ORIENTATION_HORIZONTAL, 10);
 
     Toolbar_fill(ctl, Toolbar);      Toolbar_fill(ctl, Toolbar);
     gtk_box_pack_start(GTK_BOX(VBox), Toolbar, FALSE, FALSE, 0);      gtk_box_pack_start(GTK_BOX(VBox), Toolbar, FALSE, FALSE, 0);
   
Line 620  void gtk_open( Line 632  void gtk_open(
   
     Window_fill(ctl, main_window);      Window_fill(ctl, main_window);
   
    g_signal_connect(GTK_OBJECT(main_window), "delete_event",    g_signal_connect(G_OBJECT(main_window), "delete_event",
                     GTK_SIGNAL_FUNC(Window_destroy), NULL);                     G_CALLBACK(Window_destroy), NULL);
    g_signal_connect(GTK_OBJECT(main_window), "destroy",    g_signal_connect(G_OBJECT(main_window), "destroy",
                     GTK_SIGNAL_FUNC(Window_destroy), NULL);                     G_CALLBACK(Window_destroy), NULL);
   
     gtk_widget_show_all(main_window);      gtk_widget_show_all(main_window);
 }  }
Line 802  static gboolean ReportTreeView_clicked( Line 814  static gboolean ReportTreeView_clicked(
     newdestination_item =      newdestination_item =
         gtk_menu_item_new_with_label("Set as new destination");          gtk_menu_item_new_with_label("Set as new destination");
   
    gtk_menu_append(GTK_MENU(popup_menu), copy_item);    gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), copy_item);
    gtk_menu_append(GTK_MENU(popup_menu), newdestination_item);    gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), newdestination_item);
   
    g_signal_connect(GTK_OBJECT(copy_item), "activate",    g_signal_connect(G_OBJECT(copy_item), "activate",
                     GTK_SIGNAL_FUNC(Copy_activate), path);                     G_CALLBACK(Copy_activate), path);
   
     ctl->gtk_data = path;      ctl->gtk_data = path;
    g_signal_connect(GTK_OBJECT(newdestination_item), "activate",    g_signal_connect(G_OBJECT(newdestination_item), "activate",
                     GTK_SIGNAL_FUNC(NewDestination_activate), ctl);                     G_CALLBACK(NewDestination_activate), ctl);
   
     gtk_widget_show(copy_item);      gtk_widget_show(copy_item);
     gtk_widget_show(newdestination_item);      gtk_widget_show(newdestination_item);
   
   #ifdef HAVE_GTK3
       gtk_menu_popup_at_pointer(GTK_MENU(popup_menu), NULL);
   #else
     gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL,      gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL,
                    0, event->time);                     0, event->time);
   #endif
     return TRUE;      return TRUE;
 }  }

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>