diff options
-rw-r--r-- | capture_opts.h | 12 | ||||
-rw-r--r-- | ui/iface_lists.c | 7 | ||||
-rw-r--r-- | ui/qt/interface_tree.cpp | 126 | ||||
-rw-r--r-- | ui/qt/interface_tree.h | 1 |
4 files changed, 61 insertions, 85 deletions
diff --git a/capture_opts.h b/capture_opts.h index a603a6e330..2097e2ab4d 100644 --- a/capture_opts.h +++ b/capture_opts.h @@ -236,10 +236,14 @@ typedef struct interface_options_tag { /** Capture options coming from user interface */ typedef struct capture_options_tag { /* general */ - GArray *ifaces; /* the interfaces to use for the next capture, - entries are of type interface_options */ - GArray *all_ifaces; /* all interfaces, - entries are of type interface_t */ + GArray *ifaces; /**< the interfaces to use for the + next capture, entries are of + type interface_options */ + GArray *all_ifaces; /**< all interfaces, entries are + of type interface_t */ + int ifaces_err; /**< if all_ifaces is null, the error + when it was fetched, if any */ + gchar *ifaces_err_info; /**< error string for that error */ guint num_selected; /* diff --git a/ui/iface_lists.c b/ui/iface_lists.c index a0b75af240..a9dd10c72b 100644 --- a/ui/iface_lists.c +++ b/ui/iface_lists.c @@ -70,7 +70,7 @@ scan_local_interfaces(void (*update_cb)(void)) gint linktype_count; gboolean monitor_mode; GSList *curr_addr; - int ips = 0, i, err; + int ips = 0, i; guint count = 0, j; if_addr_t *addr, *temp_addr; link_row *link = NULL; @@ -110,7 +110,10 @@ scan_local_interfaces(void (*update_cb)(void)) } /* Scan through the list and build a list of strings to display. */ - if_list = capture_interface_list(&err, NULL, update_cb); + g_free(global_capture_opts.ifaces_err_info); + if_list = capture_interface_list(&global_capture_opts.ifaces_err, + &global_capture_opts.ifaces_err_info, + update_cb); count = 0; for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) { if_info = (if_info_t *)if_entry->data; diff --git a/ui/qt/interface_tree.cpp b/ui/qt/interface_tree.cpp index 2d03390bf2..6512a960a1 100644 --- a/ui/qt/interface_tree.cpp +++ b/ui/qt/interface_tree.cpp @@ -121,26 +121,23 @@ void InterfaceTree::resizeEvent(QResizeEvent *evt) setUpdatesEnabled(true); } -void InterfaceTree::getInterfaceList() +void InterfaceTree::display() { #ifdef HAVE_LIBPCAP - GList *if_list; - int err; - gchar *err_str = NULL; + interface_t device; + setDisabled(false); clear(); - if_list = capture_interface_list(&err, &err_str,main_window_update); - if_list = g_list_sort(if_list, if_list_comparator_alph); - - if (if_list == NULL) { + if (global_capture_opts.all_ifaces->len == 0) { + // Error,or just no interfaces? QTreeWidgetItem *ti = new QTreeWidgetItem(); QLabel *err_label; - if (err == CANT_GET_INTERFACE_LIST || err == DONT_HAVE_PCAP) { - err_label = new QLabel(gchar_free_to_qstring(err_str)); - } else { + if (global_capture_opts.ifaces_err == 0) { err_label = new QLabel("No interfaces found"); + } else { + err_label = new QLabel(gchar_free_to_qstring(global_capture_opts.ifaces_err_info)); } err_label->setWordWrap(true); @@ -151,48 +148,33 @@ void InterfaceTree::getInterfaceList() return; } - // XXX Do we need to check for this? capture_interface_list returns an error if the length is 0. - if (g_list_length(if_list) > 0) { - interface_t device; - setDisabled(false); - - for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { - QList<int> *points; - - device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { + QList<int> *points; - /* Continue if capture device is hidden */ - if (device.hidden) { - continue; - } + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); - QTreeWidgetItem *ti = new QTreeWidgetItem(); - ti->setText(0, QString().fromUtf8(device.display_name)); - ti->setData(0, Qt::UserRole, QString(device.name)); - points = new QList<int>(); - ti->setData(1, Qt::UserRole, qVariantFromValue(points)); - addTopLevelItem(ti); - // XXX Add other device information - resizeColumnToContents(1); - if (strstr(prefs.capture_device, device.name) != NULL) { - device.selected = TRUE; - global_capture_opts.num_selected++; - global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); - g_array_insert_val(global_capture_opts.all_ifaces, i, device); - } - if (device.selected) { - ti->setSelected(true); - } + /* Continue if capture device is hidden */ + if (device.hidden) { + continue; } - } - free_interface_list(if_list); - resizeEvent(NULL); - if (!stat_timer_) { - updateStatistics(); - stat_timer_ = new QTimer(this); - connect(stat_timer_, SIGNAL(timeout()), this, SLOT(updateStatistics())); - stat_timer_->start(stat_update_interval_); + QTreeWidgetItem *ti = new QTreeWidgetItem(); + ti->setText(0, QString().fromUtf8(device.display_name)); + ti->setData(0, Qt::UserRole, QString(device.name)); + points = new QList<int>(); + ti->setData(1, Qt::UserRole, qVariantFromValue(points)); + addTopLevelItem(ti); + // XXX Add other device information + resizeColumnToContents(1); + if (strstr(prefs.capture_device, device.name) != NULL) { + device.selected = TRUE; + global_capture_opts.num_selected++; + global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); + g_array_insert_val(global_capture_opts.all_ifaces, i, device); + } + if (device.selected) { + ti->setSelected(true); + } } #else QTreeWidgetItem *ti = new QTreeWidgetItem(); @@ -205,6 +187,21 @@ void InterfaceTree::getInterfaceList() #endif // HAVE_LIBPCAP } +void InterfaceTree::getInterfaceList() +{ + display(); + resizeEvent(NULL); + +#ifdef HAVE_LIBPCAP + if (!stat_timer_) { + updateStatistics(); + stat_timer_ = new QTimer(this); + connect(stat_timer_, SIGNAL(timeout()), this, SLOT(updateStatistics())); + stat_timer_->start(stat_update_interval_); + } +#endif +} + void InterfaceTree::getPoints(int row, PointList *pts) { QTreeWidgetItemIterator iter(this); @@ -339,36 +336,7 @@ void InterfaceTree::setSelectedInterfaces() void InterfaceTree::interfaceListChanged() { #ifdef HAVE_LIBPCAP - interface_t device; - clear(); - for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { - QList<int> *points; - - device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); - - /* Continue if capture device is hidden */ - if (device.hidden) { - continue; - } - - QTreeWidgetItem *ti = new QTreeWidgetItem(); - ti->setText(0, QString().fromUtf8(device.display_name)); - ti->setData(0, Qt::UserRole, QString(device.name)); - points = new QList<int>(); - ti->setData(1, Qt::UserRole, qVariantFromValue(points)); - addTopLevelItem(ti); - // XXX Add other device information - resizeColumnToContents(1); - if (strstr(prefs.capture_device, device.name) != NULL) { - device.selected = TRUE; - global_capture_opts.num_selected++; - global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); - g_array_insert_val(global_capture_opts.all_ifaces, i, device); - } - if (device.selected) { - ti->setSelected(true); - } - } + display(); #endif } diff --git a/ui/qt/interface_tree.h b/ui/qt/interface_tree.h index eeab0eeacb..48b5b5acd9 100644 --- a/ui/qt/interface_tree.h +++ b/ui/qt/interface_tree.h @@ -48,6 +48,7 @@ protected: void hideEvent(QHideEvent *evt); void showEvent(QShowEvent *evt); void resizeEvent(QResizeEvent *evt); + void display(); private: #ifdef HAVE_LIBPCAP |