Synchronize the selection of interfaces between the main welcome
authortuexen <tuexen@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 20 Jul 2011 12:51:57 +0000 (12:51 +0000)
committertuexen <tuexen@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 20 Jul 2011 12:51:57 +0000 (12:51 +0000)
window, the capture/interface dialog box and the capture / start
menu item.
Obtained from Irene Ruengeler.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@38133 f5534014-38df-0310-8fa8-9805f1628bb7

gtk/capture_dlg.c
gtk/capture_if_dlg.c
gtk/capture_if_dlg.h
gtk/main_welcome.c
gtk/main_welcome.h

index f57bc9834b0ed2ede13828901f28b157f2d78de5..bc679ec46b56cea19ebe17c635558042d3208f5c 100644 (file)
@@ -2689,7 +2689,7 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
 #endif
 
   if (get_interfaces_dialog_window()) {
-    window_destroy(get_interfaces_dialog_window());
+     window_destroy(GTK_WIDGET(get_interfaces_dialog_window()));
   }
   
   if (cap_open_w) {
index 68aff3513cff4b952e786565536ac4d49c76d930..067f27460d3f474b390d47c2a1f886d538d8f24f 100644 (file)
@@ -66,6 +66,7 @@
 #include "gtk/webbrowser.h"
 #include "gtk/capture_globals.h"
 #include "gtk/network_icons.h"
+#include "gtk/main_welcome.h"
 
 #ifdef HAVE_AIRPCAP
 #include "../image/toolbar/capture_airpcap_16.xpm"
@@ -136,8 +137,29 @@ typedef struct if_dlg_data_s {
 
 static gboolean gbl_capture_in_progress = FALSE;
 
+void
+update_selected_interface(gchar *name, gboolean activate)
+{
+  guint ifs;
+  GList *curr;
+  if_dlg_data_t *temp;
+
+  for (ifs = 0; ifs < g_list_length(if_data_list); ifs++) {
+    curr = g_list_nth(if_data_list, ifs);
+    temp = (if_dlg_data_t *)(curr->data);
+    if (strcmp(name, temp->if_info.name) == 0) {
+      if (activate) {
+        gtk_toggle_button_set_active((GtkToggleButton *)temp->choose_bt, TRUE);
+      } else {
+        gtk_toggle_button_set_active((GtkToggleButton *)temp->choose_bt, FALSE);
+      }
+      break;
+    }
+  }
+}
+
 static void
-store_selected(GtkWidget *choose_bt _U_, gpointer if_data)
+store_selected(GtkWidget *choose_bt, gpointer if_data)
 {
   if_dlg_data_t *if_dlg_data = if_data, *temp;
   GList *curr;
@@ -161,6 +183,9 @@ store_selected(GtkWidget *choose_bt _U_, gpointer if_data)
           if (!temp->selected) {
             interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
             global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i);
+            if (gtk_widget_is_focus(choose_bt) && get_welcome_window()) {
+              change_interface_selection(interface_opts.name, FALSE);
+            }
             g_free(interface_opts.name);
             g_free(interface_opts.descr);
             g_free(interface_opts.cfilter);
@@ -203,6 +228,9 @@ store_selected(GtkWidget *choose_bt _U_, gpointer if_data)
         interface_opts.sampling_param  = global_capture_opts.default_options.sampling_param;
 #endif
         g_array_append_val(global_capture_opts.ifaces, interface_opts);
+        if (gtk_widget_is_focus(choose_bt) && get_welcome_window() != NULL) {
+          change_interface_selection(g_strdup(temp->if_info.name), TRUE);
+        }
       }
       
       if (temp->selected)
index 12f5509eef8a4f5ea7b33851d360d2265cd9d6ef..5ffc747a2d99321460fb59c756e44617bbc4e101 100644 (file)
@@ -50,6 +50,9 @@ capture_if_cb(GtkWidget *widget, gpointer data);
 GtkWidget *
 capture_get_if_icon(const if_info_t* if_info);
 
+void
+update_selected_interface(gchar *name, gboolean activate);
+
 GtkWidget *
 get_interfaces_dialog_window(void);
 
index 7b181cecaa52f4609780d7ab1b91e88b54eee458..a47ae9e203f29e9758df877428702b216755cbea 100644 (file)
@@ -676,7 +676,7 @@ main_welcome_add_recent_capture_file(const char *widget_cf_name, GObject *menu_i
 
 #ifdef HAVE_LIBPCAP
 static gboolean select_current_ifaces(GtkTreeModel  *model,
-                                  GtkTreePath   *path _U_,
+                                  GtkTreePath   *path,
                                   GtkTreeIter   *iter,
                                   gpointer       userdata)
 {
@@ -688,7 +688,9 @@ static gboolean select_current_ifaces(GtkTreeModel  *model,
     gtk_tree_model_get (model, iter, IFACE_NAME, &if_name, -1);
     for (i = 0; i < global_capture_opts.ifaces->len; i++) {
         if (strcmp(g_array_index(global_capture_opts.ifaces, interface_options, i).name, if_name) == 0) {
-            gtk_tree_selection_select_iter(selection, iter);
+            if (!gtk_tree_selection_path_is_selected(selection, path)) {
+              gtk_tree_selection_select_iter(selection, iter);
+            }
             found = TRUE;
             break;
         }
@@ -711,7 +713,7 @@ gboolean on_selection_changed(GtkTreeSelection *selection _U_,
     guint i;
     cap_settings_t    cap_settings;
     gboolean found = FALSE;
-    
+
     gtk_tree_model_get_iter (model, &iter, path);
     gtk_tree_model_get (model, &iter, IFACE_NAME, &if_name, -1);
     for (i = 0; i < global_capture_opts.ifaces->len; i++) {
@@ -720,6 +722,9 @@ gboolean on_selection_changed(GtkTreeSelection *selection _U_,
             if (path_currently_selected) {
                 interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
                 global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i);
+                if (gtk_widget_is_focus(g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES)) && get_interfaces_dialog_window()) {
+                    update_selected_interface(strdup(interface_opts.name), FALSE);
+                }
                 g_free(interface_opts.name);
                 g_free(interface_opts.descr);
                 g_free(interface_opts.cfilter);
@@ -762,8 +767,48 @@ gboolean on_selection_changed(GtkTreeSelection *selection _U_,
         interface_opts.sampling_param  = global_capture_opts.default_options.sampling_param;
 #endif
         g_array_append_val(global_capture_opts.ifaces, interface_opts);
+        if (gtk_widget_is_focus(g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES)) && get_interfaces_dialog_window()) {
+           update_selected_interface(strdup(interface_opts.name), TRUE);
+        }
+    }
+    return TRUE;
+}
+
+static gboolean activate_ifaces(GtkTreeModel  *model,
+                                  GtkTreePath   *path _U_,
+                                  GtkTreeIter   *iter,
+                                  gpointer       userdata)
+{
+  gchar *if_name;
+  GtkWidget *view;
+  GtkTreeSelection *selection;
+  selected_name_t  *entry = (selected_name_t *)userdata;
+  
+  view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
+  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+  gtk_tree_model_get (model, iter, IFACE_NAME, &if_name, -1);
+  if (strcmp(if_name, entry->name) == 0) {
+    if (entry->activate) {
+      gtk_tree_selection_select_iter(selection, iter);
+    } else {
+      gtk_tree_selection_unselect_iter(selection, iter);
     }
     return TRUE;
+  }
+  return FALSE;
+}
+
+void change_interface_selection(gchar* name, gboolean activate)
+{
+    GtkWidget        *view;
+    GtkTreeModel     *model;
+    selected_name_t  entry;
+   
+    view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
+    model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
+    entry.name = strdup(name);
+    entry.activate = activate;
+    gtk_tree_model_foreach(GTK_TREE_MODEL(model), (GtkTreeModelForeachFunc)(activate_ifaces), (gpointer) &entry);
 }
 #endif
 
@@ -869,7 +914,6 @@ welcome_if_panel_reload(void)
     GList* child_list;
     GList* child_list_item;
 
-
     if(welcome_if_panel_vb) {
         child_box = scroll_box_dynamic_reset(welcome_if_panel_vb);
         child_list = gtk_container_get_children(GTK_CONTAINER(child_box));
@@ -1223,3 +1267,9 @@ welcome_new(void)
 
     return welcome_scrollw;
 }
+
+GtkWidget* get_welcome_window(void)
+{
+  return welcome_hb;
+}
+
index daec47cb300a00ca549f217a8e9d351bd4e06d35..b7da8adff4b479c1cc20b3e038f5a0192c12502b 100644 (file)
@@ -33,6 +33,10 @@ enum
   NUMCOLUMNS
 };
 
+typedef struct selected_name_s {
+  gchar *name;
+  gboolean activate;
+} selected_name_t;
 GtkWidget *welcome_new(void);
 
 /* reset the list of recently used files */
@@ -63,4 +67,8 @@ void welcome_header_pop_msg(void);
 
 void select_ifaces(void);
 
+GtkWidget* get_welcome_window(void);
+
+void change_interface_selection(gchar* name, gboolean activate);
+
 #endif /* __MAIN_WELCOME_H__ */