Allow "capture info data" to not be a singleton.
[metze/wireshark/wip.git] / ui / qt / main_window_slots.cpp
index 419b46829a1f7874e41da5d314af6cfdc77cbf8e..cb6f8eff0f9787b818b6fe94b8dc3fbc9502d769 100644 (file)
@@ -42,7 +42,7 @@
 
 #include "wsutil/file_util.h"
 #include "wsutil/filesystem.h"
-#include <wsutil/str_util.h>
+#include "wsutil/str_util.h"
 
 #include "epan/addr_resolv.h"
 #include "epan/dissector_filters.h"
@@ -290,6 +290,9 @@ void MainWindow::filterPackets(QString new_filter, bool force)
     } else {
         emit displayFilterSuccess(false);
     }
+    if (packet_list_) {
+        packet_list_->resetColumns();
+    }
 }
 
 // A new layout should be applied when it differs from the old layout AND
@@ -302,7 +305,11 @@ void MainWindow::layoutPanes()
     QVector<unsigned> new_layout = QVector<unsigned>() << prefs.gui_layout_type
                                                        << prefs.gui_layout_content_1
                                                        << prefs.gui_layout_content_2
-                                                       << prefs.gui_layout_content_3;
+                                                       << prefs.gui_layout_content_3
+                                                       << recent.packet_list_show
+                                                       << recent.tree_view_show
+                                                       << recent.byte_view_show;
+
     if (cur_layout_ == new_layout) return;
 
     QSplitter *parents[3];
@@ -449,6 +456,11 @@ void MainWindow::layoutToolbars()
     }
 
     main_ui_->mainToolBar->setToolButtonStyle(tbstyle);
+
+    main_ui_->mainToolBar->setVisible(recent.main_toolbar_show);
+    main_ui_->displayFilterToolBar->setVisible(recent.filter_toolbar_show);
+    main_ui_->wirelessToolBar->setVisible(recent.wireless_toolbar_show);
+    main_ui_->statusBar->setVisible(recent.statusbar_show);
 }
 
 void MainWindow::updatePreferenceActions()
@@ -461,6 +473,31 @@ void MainWindow::updatePreferenceActions()
     main_ui_->actionGoAutoScroll->setChecked(prefs.capture_auto_scroll);
 }
 
+void MainWindow::updateRecentActions()
+{
+    main_ui_->actionViewMainToolbar->setChecked(recent.main_toolbar_show);
+    main_ui_->actionViewFilterToolbar->setChecked(recent.filter_toolbar_show);
+    main_ui_->actionViewWirelessToolbar->setChecked(recent.wireless_toolbar_show);
+    main_ui_->actionViewStatusBar->setChecked(recent.statusbar_show);
+    main_ui_->actionViewPacketList->setChecked(recent.packet_list_show);
+    main_ui_->actionViewPacketDetails->setChecked(recent.tree_view_show);
+    main_ui_->actionViewPacketBytes->setChecked(recent.byte_view_show);
+
+    foreach (QAction* tda, td_actions.keys()) {
+        if (recent.gui_time_format == td_actions[tda]) {
+            tda->setChecked(true);
+        }
+    }
+    foreach (QAction* tpa, tp_actions.keys()) {
+        if (recent.gui_time_precision == tp_actions[tpa]) {
+            tpa->setChecked(true);
+        }
+    }
+    main_ui_->actionViewTimeDisplaySecondsWithHoursAndMinutes->setChecked(recent.gui_seconds_format == TS_SECONDS_HOUR_MIN_SEC);
+
+    main_ui_->actionViewColorizePacketList->setChecked(recent.packet_list_colorize);
+}
+
 void MainWindow::filterAction(QString &action_filter, FilterAction::Action action, FilterAction::ActionType type)
 {
     QString cur_filter, new_filter;
@@ -655,6 +692,8 @@ void MainWindow::captureFileReadStarted(const QString &action) {
     QString msgtip = QString();
     main_ui_->statusBar->pushFileStatus(msg, msgtip);
     main_ui_->mainStack->setCurrentWidget(&master_split_);
+    main_ui_->actionAnalyzeReloadLuaPlugins->setEnabled(false);
+
     WiresharkApplication::processEvents();
 }
 
@@ -678,6 +717,7 @@ void MainWindow::captureFileReadFinished() {
     setForCapturedPackets(true);
 
     main_ui_->statusBar->setFileName(capture_file_);
+    main_ui_->actionAnalyzeReloadLuaPlugins->setEnabled(true);
 
     packet_list_->captureFileReadFinished();
 
@@ -695,10 +735,14 @@ void MainWindow::captureFileRetapFinished()
     thaw();
 }
 
+void MainWindow::captureFileFlushTapsData()
+{
+    draw_tap_listeners(FALSE);
+}
+
 void MainWindow::captureFileClosing() {
     setMenusForCaptureFile(true);
     setForCapturedPackets(false);
-    setMenusForSelectedPacket();
     setForCaptureInProgress(false);
 
     // Reset expert information indicator
@@ -721,7 +765,9 @@ void MainWindow::captureFileClosed() {
 
     main_ui_->statusBar->popFileStatus();
 
-    setTitlebarForSelectedTreeRow();
+    setDefaultWindowTitle();
+    setWindowIcon(wsApp->normalIcon());
+    setMenusForSelectedPacket();
     setMenusForSelectedTreeRow();
 
     if (!global_capture_opts.multi_files_on)
@@ -777,8 +823,6 @@ void MainWindow::startCapture() {
         return;
     }
 
-    main_ui_->mainStack->setCurrentWidget(&master_split_);
-
     // Ideally we should have disabled the start capture
     // toolbar buttons and menu items. This may not be the
     // case, e.g. with QtMacExtras.
@@ -789,6 +833,8 @@ void MainWindow::startCapture() {
         return;
     }
 
+    main_ui_->mainStack->setCurrentWidget(&master_split_);
+
     /* XXX - we might need to init other pref data as well... */
 
     /* XXX - can this ever happen? */
@@ -803,12 +849,12 @@ void MainWindow::startCapture() {
     collect_ifaces(&global_capture_opts);
 
     CaptureFile::globalCapFile()->window = this;
-    if (capture_start(&global_capture_opts, &cap_session_, main_window_update)) {
+    if (capture_start(&global_capture_opts, &cap_session_, &info_data_, main_window_update)) {
         capture_options *capture_opts = cap_session_.capture_opts;
         GString *interface_names;
 
         /* enable autoscroll timer as needed. */
-        packet_list_->setAutoScroll(main_ui_->actionGoAutoScroll->isChecked());
+        packet_list_->setVerticalAutoScroll(main_ui_->actionGoAutoScroll->isChecked());
 
         /* Add "interface name<live capture in progress>" on main status bar */
         interface_names = get_iface_list_string(capture_opts, 0);
@@ -923,7 +969,7 @@ void MainWindow::stopCapture() {
     main_ui_->statusBar->setFileName(capture_file_);
 
     /* disable autoscroll timer if any. */
-    packet_list_->setAutoScroll(false);
+    packet_list_->setVerticalAutoScroll(false);
 }
 
 // Keep focus rects from showing through the welcome screen. Primarily for
@@ -1127,7 +1173,7 @@ void MainWindow::setMenusForSelectedPacket()
 
         bool enable = false;
         QString filter;
-        if (capture_file_.capFile()->edt) {
+        if (capture_file_.capFile() && capture_file_.capFile()->edt) {
             enable = conv_filter->is_filter_valid(&capture_file_.capFile()->edt->pi);
             filter = gchar_free_to_qstring(conv_filter->build_filter_string(&capture_file_.capFile()->edt->pi));
         }
@@ -1262,7 +1308,7 @@ void MainWindow::setMenusForSelectedTreeRow(field_info *fi) {
 
         bool enable = false;
         QString filter;
-        if (capture_file_.capFile() && capture_file_.capFile()->edt) {
+        if (fi && capture_file_.capFile() && capture_file_.capFile()->edt) {
             enable = conv_filter->is_filter_valid(&capture_file_.capFile()->edt->pi);
             filter = conv_filter->build_filter_string(&capture_file_.capFile()->edt->pi);
         }
@@ -1333,22 +1379,28 @@ void MainWindow::startInterfaceCapture(bool valid)
 
 void MainWindow::redissectPackets()
 {
-    if (capture_file_.capFile())
+    if (capture_file_.capFile()) {
         cf_redissect_packets(capture_file_.capFile());
-    main_ui_->statusBar->expertUpdate();
+        main_ui_->statusBar->expertUpdate();
+    }
 
     proto_free_deregistered_fields();
 }
 
-void MainWindow::fieldsChanged()
+void MainWindow::checkDisplayFilter()
 {
-    color_filters_reload();
-    tap_listeners_dfilter_recompile();
-
     if (!df_combo_box_->checkDisplayFilter()) {
         g_free(CaptureFile::globalCapFile()->dfilter);
         CaptureFile::globalCapFile()->dfilter = NULL;
     }
+}
+
+void MainWindow::fieldsChanged()
+{
+    color_filters_reload();
+    tap_listeners_dfilter_recompile();
+
+    emit checkDisplayFilter();
 
     if (have_custom_cols(&CaptureFile::globalCapFile()->cinfo)) {
         // Recreate packet list columns according to new/changed/deleted fields
@@ -1564,7 +1616,7 @@ void MainWindow::on_actionFileSaveAs_triggered()
 
 void MainWindow::on_actionFileSetListFiles_triggered()
 {
-    file_set_dialog_.exec();
+    file_set_dialog_.show();
 }
 
 void MainWindow::on_actionFileSetNextFile_triggered()
@@ -1876,6 +1928,9 @@ void MainWindow::on_actionEditFindPacket_triggered()
     previous_focus_ = wsApp->focusWidget();
     connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus()));
     showAccordionFrame(main_ui_->searchFrame, true);
+    if (main_ui_->searchFrame->isVisible()) {
+        main_ui_->searchFrame->setFocus();
+    }
 }
 
 void MainWindow::on_actionEditFindNext_triggered()
@@ -2074,7 +2129,7 @@ void MainWindow::setTimestampFormat(QAction *action)
             cf_timestamp_auto_precision(capture_file_.capFile());
         }
         if (packet_list_) {
-            packet_list_->columnsChanged();
+            packet_list_->resetColumns();
         }
     }
 }
@@ -2096,7 +2151,7 @@ void MainWindow::setTimestampPrecision(QAction *action)
             cf_timestamp_auto_precision(capture_file_.capFile());
         }
         if (packet_list_) {
-            packet_list_->columnsChanged();
+            packet_list_->resetColumns();
         }
     }
 }
@@ -2115,7 +2170,7 @@ void MainWindow::on_actionViewTimeDisplaySecondsWithHoursAndMinutes_triggered(bo
         cf_timestamp_auto_precision(capture_file_.capFile());
     }
     if (packet_list_) {
-        packet_list_->columnsChanged();
+        packet_list_->resetColumns();
     }
 }
 
@@ -2139,7 +2194,7 @@ void MainWindow::setNameResolution()
     gbl_resolv_flags.transport_name = main_ui_->actionViewNameResolutionTransport->isChecked() ? TRUE : FALSE;
 
     if (packet_list_) {
-        packet_list_->columnsChanged();
+        packet_list_->resetColumns();
     }
 }
 
@@ -2548,9 +2603,9 @@ void MainWindow::on_actionAnalyzeDecodeAs_triggered()
     wsApp->flushAppSignals();
 }
 
-#ifdef HAVE_LUA
 void MainWindow::on_actionAnalyzeReloadLuaPlugins_triggered()
 {
+#ifdef HAVE_LUA
     if (wsApp->isReloadingLua())
         return;
 
@@ -2566,15 +2621,15 @@ void MainWindow::on_actionAnalyzeReloadLuaPlugins_triggered()
     main_ui_->preferenceEditorFrame->animatedHide();
 
     char *gdp_path, *dp_path;
-    (void) wsApp->readConfigurationFiles(&gdp_path, &dp_path);
+    wsApp->readConfigurationFiles(&gdp_path, &dp_path, true);
 
     fieldsChanged();
     redissectPackets();
 
     wsApp->setReloadingLua(false);
     SimpleDialog::displayQueuedMessages();
-}
 #endif
+}
 
 void MainWindow::openFollowStreamDialog(follow_type_t type) {
     FollowStreamDialog *fsd = new FollowStreamDialog(*this, capture_file_, type);
@@ -3277,9 +3332,67 @@ void MainWindow::on_actionGoGoToLinkedPacket_triggered()
     packet_list_->goToPacket(packet_num);
 }
 
+// gtk/main_menubar.c:goto_conversation_frame
+void MainWindow::goToConversationFrame(bool go_next) {
+    gchar     *filter       = NULL;
+    dfilter_t *dfcode       = NULL;
+    gboolean   found_packet = FALSE;
+    packet_info *pi = &(capture_file_.capFile()->edt->pi);
+    conversation_filter_t* conv_filter;
+
+    /* Try to build a conversation
+     * filter in the order TCP, UDP, IP, Ethernet and apply the
+     * coloring */
+    conv_filter = find_conversation_filter("tcp");
+    if ((conv_filter != NULL) && (conv_filter->is_filter_valid(pi)))
+        filter = conv_filter->build_filter_string(pi);
+    conv_filter = find_conversation_filter("udp");
+    if ((conv_filter != NULL) && (conv_filter->is_filter_valid(pi)))
+        filter = conv_filter->build_filter_string(pi);
+    conv_filter = find_conversation_filter("ip");
+    if ((conv_filter != NULL) && (conv_filter->is_filter_valid(pi)))
+        filter = conv_filter->build_filter_string(pi);
+    conv_filter = find_conversation_filter("ipv6");
+    if ((conv_filter != NULL) && (conv_filter->is_filter_valid(pi)))
+        filter = conv_filter->build_filter_string(pi);
+
+    if( filter == NULL ) {
+        main_ui_->statusBar->pushTemporaryStatus(tr("Unable to build conversation filter."));
+        g_free(filter);
+        return;
+    }
+
+    if (!dfilter_compile(filter, &dfcode, NULL)) {
+        /* The attempt failed; report an error. */
+        main_ui_->statusBar->pushTemporaryStatus(tr("Error compiling filter for this conversation."));
+        g_free(filter);
+        return;
+    }
+
+    found_packet = cf_find_packet_dfilter(capture_file_.capFile(), dfcode, go_next ? SD_FORWARD : SD_BACKWARD);
+
+    if (!found_packet) {
+        /* We didn't find a packet */
+        main_ui_->statusBar->pushTemporaryStatus(tr("No previous/next packet in conversation."));
+    }
+
+    dfilter_free(dfcode);
+    g_free(filter);
+}
+
+void MainWindow::on_actionGoNextConversationPacket_triggered()
+{
+    goToConversationFrame(true);
+}
+
+void MainWindow::on_actionGoPreviousConversationPacket_triggered()
+{
+    goToConversationFrame(false);
+}
+
 void MainWindow::on_actionGoAutoScroll_toggled(bool checked)
 {
-    packet_list_->setAutoScroll(checked);
+    packet_list_->setVerticalAutoScroll(checked);
 }
 
 void MainWindow::resetPreviousFocus() {
@@ -3422,7 +3535,9 @@ void MainWindow::on_actionCaptureOptions_triggered()
 
 void MainWindow::on_actionCaptureRefreshInterfaces_triggered()
 {
+    main_ui_->actionCaptureRefreshInterfaces->setEnabled(false);
     wsApp->refreshLocalInterfaces();
+    main_ui_->actionCaptureRefreshInterfaces->setEnabled(true);
 }
 #endif