Qt: Add a CaptureFile class.
[metze/wireshark/wip.git] / ui / qt / main_window_slots.cpp
1 /* main_window_slots.cpp
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <config.h>
23
24 #ifdef HAVE_FCNTL_H
25 #include <fcntl.h>
26 #endif
27
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31
32 #include "main_window.h"
33 #include "ui_main_window.h"
34
35 #ifdef _WIN32
36 #include <windows.h>
37 #include <io.h>
38 #endif
39
40 #ifdef HAVE_LIBPCAP
41 #include "ui/capture.h"
42 #endif
43
44 #include "color_filters.h"
45
46 #include "wsutil/file_util.h"
47 #include "wsutil/filesystem.h"
48
49 #include "epan/addr_resolv.h"
50 #include "epan/column.h"
51 #include "epan/epan_dissect.h"
52 #include "epan/filter_expressions.h"
53 #include "epan/prefs.h"
54 #include "epan/value_string.h"
55
56 #include "ui/alert_box.h"
57 #ifdef HAVE_LIBPCAP
58 #include "ui/capture_ui_utils.h"
59 #endif
60
61 #include "ui/capture_globals.h"
62 #include "ui/help_url.h"
63 #include "ui/main_statusbar.h"
64 #include "ui/preference_utils.h"
65 #include "ui/recent.h"
66 #include "ui/recent_utils.h"
67 #include "ui/ssl_key_export.h"
68 #include "ui/ui_util.h"
69
70 #ifdef HAVE_SOFTWARE_UPDATE
71 #include "ui/software_update.h"
72 #endif
73
74 #include "capture_file_dialog.h"
75 #include "capture_file_properties_dialog.h"
76 #include "conversation_dialog.h"
77 #include "decode_as_dialog.h"
78 #include "endpoint_dialog.h"
79 #include "export_object_dialog.h"
80 #include "export_pdu_dialog.h"
81 #include "io_graph_dialog.h"
82 #include "lbm_stream_dialog.h"
83 #include "lbm_uimflow_dialog.h"
84 #include "lbm_lbtrm_transport_dialog.h"
85 #include "lbm_lbtru_transport_dialog.h"
86 #include "packet_comment_dialog.h"
87 #include "preferences_dialog.h"
88 #include "print_dialog.h"
89 #include "profile_dialog.h"
90 #include "qt_ui_utils.h"
91 #include "sctp_all_assocs_dialog.h"
92 #include "sctp_assoc_analyse_dialog.h"
93 #include "sctp_graph_dialog.h"
94 #include "sequence_dialog.h"
95 #include "stats_tree_dialog.h"
96 #include "tcp_stream_dialog.h"
97 #include "time_shift_dialog.h"
98 #include "voip_calls_dialog.h"
99 #include "wireshark_application.h"
100
101 #include <QClipboard>
102 #include <QMessageBox>
103 #include <QMetaObject>
104 #include <QToolBar>
105
106 #include <QDebug>
107
108 //
109 // Public slots
110 //
111
112 const char *dfe_property_ = "display filter expression"; //TODO : Fix Translate
113
114 void MainWindow::openCaptureFile(QString& cf_path, QString& read_filter, unsigned int type)
115 {
116     QString file_name = "";
117     dfilter_t *rfcode = NULL;
118     int err;
119     gboolean name_param;
120
121     // was a file name given as function parameter?
122     name_param = !cf_path.isEmpty();
123
124     testCaptureFileClose(false);
125
126     for (;;) {
127
128         if (cf_path.isEmpty()) {
129             CaptureFileDialog open_dlg(this, capture_file_.capFile(), read_filter);
130
131             switch (prefs.gui_fileopen_style) {
132
133             case FO_STYLE_LAST_OPENED:
134                 /* The user has specified that we should start out in the last directory
135                    we looked in.  If we've already opened a file, use its containing
136                    directory, if we could determine it, as the directory, otherwise
137                    use the "last opened" directory saved in the preferences file if
138                    there was one. */
139                 /* This is now the default behaviour in file_selection_new() */
140                 break;
141
142             case FO_STYLE_SPECIFIED:
143                 /* The user has specified that we should always start out in a
144                    specified directory; if they've specified that directory,
145                    start out by showing the files in that dir. */
146                 if (prefs.gui_fileopen_dir[0] != '\0')
147                     open_dlg.setDirectory(prefs.gui_fileopen_dir);
148                 break;
149             }
150
151             if (open_dlg.open(file_name, type)) {
152                 cf_path = file_name;
153             } else {
154                 return;
155             }
156         }
157
158         if (dfilter_compile(read_filter.toUtf8().constData(), &rfcode)) {
159             cf_set_rfcode(CaptureFile::globalCapFile(), rfcode);
160         } else {
161             /* Not valid.  Tell the user, and go back and run the file
162                selection box again once they dismiss the alert. */
163             //bad_dfilter_alert_box(top_level, read_filter->str);
164             QMessageBox::warning(this, tr("Invalid Display Filter"),
165                     QString("The filter expression ") +
166                     read_filter +
167                     QString(" isn't a valid display filter. (") +
168                     dfilter_error_msg + QString(")."),
169                     QMessageBox::Ok);
170
171             if (!name_param) {
172                 // go back to the selection dialogue only if the file
173                 // was selected from this dialogue
174                 cf_path.clear();
175                 continue;
176             }
177         }
178
179         /* Try to open the capture file. This closes the current file if it succeeds. */
180         CaptureFile::globalCapFile()->window = this;
181         if (cf_open(CaptureFile::globalCapFile(), cf_path.toUtf8().constData(), type, FALSE, &err) != CF_OK) {
182             /* We couldn't open it; don't dismiss the open dialog box,
183                just leave it around so that the user can, after they
184                dismiss the alert box popped up for the open error,
185                try again. */
186             CaptureFile::globalCapFile()->window = NULL;
187             if (rfcode != NULL)
188                 dfilter_free(rfcode);
189             cf_path.clear();
190             continue;
191         }
192
193         switch (cf_read(CaptureFile::globalCapFile(), FALSE)) {
194
195         case CF_READ_OK:
196         case CF_READ_ERROR:
197             /* Just because we got an error, that doesn't mean we were unable
198                to read any of the file; we handle what we could get from the
199                file. */
200             break;
201
202         case CF_READ_ABORTED:
203             /* The user bailed out of re-reading the capture file; the
204                capture file has been closed - just free the capture file name
205                string and return (without changing the last containing
206                directory). */
207             capture_file_.setCapFile(NULL);
208             return;
209         }
210         break;
211     }
212     // get_dirname overwrites its path. Hopefully this isn't a problem.
213     wsApp->setLastOpenDir(get_dirname(cf_path.toUtf8().data()));
214
215     main_ui_->statusBar->showExpert();
216 }
217
218 void MainWindow::filterPackets(QString& new_filter, bool force)
219 {
220     cf_status_t cf_status;
221
222     cf_status = cf_filter_packets(CaptureFile::globalCapFile(), new_filter.toUtf8().data(), force);
223
224     if (cf_status == CF_OK) {
225         emit displayFilterSuccess(true);
226         if (new_filter.length() > 0) {
227             int index = df_combo_box_->findText(new_filter);
228             if (index == -1) {
229                 df_combo_box_->insertItem(0, new_filter);
230                 df_combo_box_->setCurrentIndex(0);
231             }
232             else {
233                 df_combo_box_->setCurrentIndex(index);
234             }
235         }
236     } else {
237         emit displayFilterSuccess(false);
238     }
239 }
240
241 void MainWindow::layoutPanes()
242 {
243     QSplitter *parents[3];
244
245     // Reparent all widgets and add them back in the proper order below.
246     // This hides each widget as well.
247     packet_list_->setParent(main_ui_->mainStack);
248     proto_tree_->setParent(main_ui_->mainStack);
249     byte_view_tab_->setParent(main_ui_->mainStack);
250     empty_pane_.setParent(main_ui_->mainStack);
251     extra_split_.setParent(main_ui_->mainStack);
252
253     switch(prefs.gui_layout_type) {
254     case(layout_type_2):
255     case(layout_type_1):
256         extra_split_.setOrientation(Qt::Horizontal);
257     case(layout_type_5):
258         master_split_.setOrientation(Qt::Vertical);
259         break;
260
261     case(layout_type_4):
262     case(layout_type_3):
263         extra_split_.setOrientation(Qt::Vertical);
264     case(layout_type_6):
265         master_split_.setOrientation(Qt::Horizontal);
266         break;
267
268     default:
269         g_assert_not_reached();
270     }
271
272     switch(prefs.gui_layout_type) {
273     case(layout_type_5):
274     case(layout_type_6):
275         parents[0] = &master_split_;
276         parents[1] = &master_split_;
277         parents[2] = &master_split_;
278         break;
279     case(layout_type_2):
280     case(layout_type_4):
281         parents[0] = &master_split_;
282         parents[1] = &extra_split_;
283         parents[2] = &extra_split_;
284         break;
285     case(layout_type_1):
286     case(layout_type_3):
287         parents[0] = &extra_split_;
288         parents[1] = &extra_split_;
289         parents[2] = &master_split_;
290         break;
291     default:
292         g_assert_not_reached();
293     }
294
295     if (parents[0] == &extra_split_) {
296         master_split_.addWidget(&extra_split_);
297     }
298
299     parents[0]->addWidget(getLayoutWidget(prefs.gui_layout_content_1));
300
301     if (parents[2] == &extra_split_) {
302         master_split_.addWidget(&extra_split_);
303     }
304
305     parents[1]->addWidget(getLayoutWidget(prefs.gui_layout_content_2));
306     parents[2]->addWidget(getLayoutWidget(prefs.gui_layout_content_3));
307
308     QList<QWidget *>split_widgets;
309     for (int i = 0; i < master_split_.count(); i++) {
310         split_widgets << master_split_.widget(i);
311     }
312     for (int i = 0; i < extra_split_.count(); i++) {
313         split_widgets << master_split_.widget(i);
314     }
315     foreach (QWidget *widget, split_widgets) {
316         bool show = true;
317         if (widget == packet_list_ && !recent.packet_list_show) {
318             show = false;
319         } else if (widget == proto_tree_ && !recent.tree_view_show) {
320             show = false;
321         } else if (widget == byte_view_tab_ && !recent.byte_view_show) {
322             show = false;
323         }
324         widget->setVisible(show);
325     }
326 }
327
328 void MainWindow::layoutToolbars()
329 {
330     Qt::ToolButtonStyle tbstyle = Qt::ToolButtonIconOnly;
331     switch (prefs.gui_toolbar_main_style) {
332     case TB_STYLE_TEXT:
333         tbstyle = Qt::ToolButtonTextOnly;
334         break;
335     case TB_STYLE_BOTH:
336         tbstyle = Qt::ToolButtonTextUnderIcon;
337     }
338
339     main_ui_->mainToolBar->setToolButtonStyle(tbstyle);
340 }
341
342 void MainWindow::updateNameResolutionActions()
343 {
344     main_ui_->actionViewNameResolutionPhysical->setChecked(gbl_resolv_flags.mac_name);
345     main_ui_->actionViewNameResolutionNetwork->setChecked(gbl_resolv_flags.network_name);
346     main_ui_->actionViewNameResolutionTransport->setChecked(gbl_resolv_flags.transport_name);
347 }
348
349 void MainWindow::filterAction(QString &action_filter, FilterAction::Action action, FilterAction::ActionType type)
350 {
351     QString cur_filter, new_filter;
352
353     if (!df_combo_box_) return;
354     cur_filter = df_combo_box_->lineEdit()->text();
355
356     switch (type) {
357     case FilterAction::ActionTypePlain:
358         new_filter = action_filter;
359         break;
360     case FilterAction::ActionTypeAnd:
361         if (cur_filter.length()) {
362             new_filter = "(" + cur_filter + ") && (" + action_filter + ")";
363         } else {
364             new_filter = action_filter;
365         }
366         break;
367     case FilterAction::ActionTypeOr:
368         if (cur_filter.length()) {
369             new_filter = "(" + cur_filter + ") || (" + action_filter + ")";
370         } else {
371             new_filter = action_filter;
372         }
373         break;
374     case FilterAction::ActionTypeNot:
375         new_filter = "!(" + action_filter + ")";
376         break;
377     case FilterAction::ActionTypeAndNot:
378         if (cur_filter.length()) {
379             new_filter = "(" + cur_filter + ") && !(" + action_filter + ")";
380         } else {
381             new_filter = "!(" + action_filter + ")";
382         }
383         break;
384     case FilterAction::ActionTypeOrNot:
385         if (cur_filter.length()) {
386             new_filter = "(" + cur_filter + ") || !(" + action_filter + ")";
387         } else {
388             new_filter = "!(" + action_filter + ")";
389         }
390         break;
391     default:
392         g_assert_not_reached();
393         break;
394     }
395
396     switch(action) {
397     case FilterAction::ActionApply:
398         df_combo_box_->lineEdit()->setText(new_filter);
399         df_combo_box_->applyDisplayFilter();
400         break;
401     case FilterAction::ActionPrepare:
402         df_combo_box_->lineEdit()->setText(new_filter);
403         df_combo_box_->lineEdit()->setFocus();
404         break;
405     case FilterAction::ActionCopy:
406         wsApp->clipboard()->setText(new_filter);
407         break;
408     default:
409         qDebug() << "FIX FilterAction::Action" << action << "not implemented";
410         break;
411     }
412 }
413
414 // Capture callbacks
415
416 void MainWindow::captureCapturePrepared(capture_session *) {
417 #ifdef HAVE_LIBPCAP
418     setTitlebarForCaptureInProgress();
419
420     setWindowIcon(wsApp->captureIcon());
421
422     /* Disable menu items that make no sense if you're currently running
423        a capture. */
424     setForCaptureInProgress(true);
425 //    set_capture_if_dialog_for_capture_in_progress(TRUE);
426
427 //    /* Don't set up main window for a capture file. */
428 //    main_set_for_capture_file(FALSE);
429     main_ui_->mainStack->setCurrentWidget(&master_split_);
430 #endif // HAVE_LIBPCAP
431 }
432
433 void MainWindow::captureCaptureUpdateStarted(capture_session *cap_session) {
434     Q_UNUSED(cap_session);
435 #ifdef HAVE_LIBPCAP
436
437     /* We've done this in "prepared" above, but it will be cleared while
438        switching to the next multiple file. */
439     setTitlebarForCaptureInProgress();
440
441     setForCaptureInProgress(true);
442
443     setForCapturedPackets(true);
444 #endif // HAVE_LIBPCAP
445 }
446 void MainWindow::captureCaptureUpdateFinished(capture_session *cap_session) {
447     Q_UNUSED(cap_session);
448 #ifdef HAVE_LIBPCAP
449
450     /* The capture isn't stopping any more - it's stopped. */
451     capture_stopping_ = false;
452
453     /* Update the main window as appropriate */
454     updateForUnsavedChanges();
455
456     /* Enable menu items that make sense if you're not currently running
457      a capture. */
458     setForCaptureInProgress(false);
459
460     setWindowIcon(wsApp->normalIcon());
461
462     if (global_capture_opts.quit_after_cap) {
463         // Command line asked us to quit after capturing.
464         // Don't pop up a dialog to ask for unsaved files etc.
465         exit(0);
466     }
467 #endif // HAVE_LIBPCAP
468 }
469 void MainWindow::captureCaptureFixedStarted(capture_session *cap_session) {
470     Q_UNUSED(cap_session);
471 #ifdef HAVE_LIBPCAP
472 #endif // HAVE_LIBPCAP
473 }
474 void MainWindow::captureCaptureFixedFinished(capture_session *cap_session) {
475     Q_UNUSED(cap_session);
476 #ifdef HAVE_LIBPCAP
477
478     /* The capture isn't stopping any more - it's stopped. */
479     capture_stopping_ = false;
480
481     /* Enable menu items that make sense if you're not currently running
482      a capture. */
483     setForCaptureInProgress(false);
484
485     setWindowIcon(wsApp->normalIcon());
486
487     if (global_capture_opts.quit_after_cap) {
488         // Command line asked us to quit after capturing.
489         // Don't pop up a dialog to ask for unsaved files etc.
490         exit(0);
491     }
492 #endif // HAVE_LIBPCAP
493 }
494 void MainWindow::captureCaptureStopping(capture_session *cap_session) {
495     Q_UNUSED(cap_session);
496 #ifdef HAVE_LIBPCAP
497
498     capture_stopping_ = true;
499     setMenusForCaptureStopping();
500 #endif // HAVE_LIBPCAP
501 }
502 void MainWindow::captureCaptureFailed(capture_session *cap_session) {
503     Q_UNUSED(cap_session);
504 #ifdef HAVE_LIBPCAP
505     /* Capture isn't stopping any more. */
506     capture_stopping_ = false;
507
508     setForCaptureInProgress(false);
509     main_ui_->mainStack->setCurrentWidget(main_welcome_);
510
511     setWindowIcon(wsApp->normalIcon());
512
513     if (global_capture_opts.quit_after_cap) {
514         // Command line asked us to quit after capturing.
515         // Don't pop up a dialog to ask for unsaved files etc.
516         exit(0);
517     }
518 #endif // HAVE_LIBPCAP
519 }
520
521
522 // Callbacks from cfile.c and file.c via CaptureFile::captureFileCallback
523
524 void MainWindow::captureFileOpened() {
525     if (capture_file_.window() != this) return;
526
527     file_set_dialog_.fileOpened(capture_file_.capFile());
528     setMenusForFileSet(true);
529     emit setCaptureFile(capture_file_.capFile());
530 }
531
532 void MainWindow::captureFileReadStarted() {
533 //    tap_param_dlg_update();
534
535     /* Set up main window for a capture file. */
536 //    main_set_for_capture_file(TRUE);
537
538     main_ui_->statusBar->popFileStatus();
539     QString msg = QString(tr("Loading: %1")).arg(get_basename(capture_file_.capFile()->filename));
540     main_ui_->statusBar->pushFileStatus(msg);
541     main_ui_->mainStack->setCurrentWidget(&master_split_);
542     WiresharkApplication::processEvents();
543 }
544
545 void MainWindow::captureFileReadFinished() {
546     gchar *dir_path;
547
548     if (!capture_file_.capFile()->is_tempfile && capture_file_.capFile()->filename) {
549         /* Add this filename to the list of recent files in the "Recent Files" submenu */
550         add_menu_recent_capture_file(capture_file_.capFile()->filename);
551
552         /* Remember folder for next Open dialog and save it in recent */
553         dir_path = get_dirname(g_strdup(capture_file_.capFile()->filename));
554         wsApp->setLastOpenDir(dir_path);
555         g_free(dir_path);
556     }
557
558     /* Update the appropriate parts of the main window. */
559     updateForUnsavedChanges();
560
561     /* Enable menu items that make sense if you have some captured packets. */
562     setForCapturedPackets(true);
563
564     main_ui_->statusBar->popFileStatus();
565     QString msg = QString().sprintf("%s", get_basename(capture_file_.capFile()->filename));
566     main_ui_->statusBar->pushFileStatus(msg);
567     emit setDissectedCaptureFile(capture_file_.capFile());
568 }
569
570 void MainWindow::captureFileClosing() {
571     setMenusForCaptureFile(true);
572     setForCapturedPackets(false);
573     setMenusForSelectedPacket();
574     setForCaptureInProgress(false);
575
576     // Reset expert info indicator
577     main_ui_->statusBar->hideExpert();
578     main_ui_->searchFrame->animatedHide();
579 //    gtk_widget_show(expert_info_none);
580     emit setCaptureFile(NULL);
581     emit setDissectedCaptureFile(NULL);
582 }
583
584 void MainWindow::captureFileClosed() {
585     packets_bar_update();
586
587     file_set_dialog_.fileClosed();
588     setMenusForFileSet(false);
589
590     // Reset expert info indicator
591     main_ui_->statusBar->hideExpert();
592
593     main_ui_->statusBar->popFileStatus();
594
595     if (df_combo_box_)
596     {
597         df_combo_box_->lineEdit()->setText("");
598         df_combo_box_->applyDisplayFilter();
599     }
600
601     setTitlebarForSelectedTreeRow();
602     setMenusForSelectedTreeRow();
603 }
604
605 void MainWindow::configurationProfileChanged(const gchar *profile_name) {
606     Q_UNUSED(profile_name);
607     /* Update window view and redraw the toolbar */
608 //    main_titlebar_update();
609     filterExpressionsChanged();
610 //    toolbar_redraw_all();
611
612     /* Reload list of interfaces on welcome page */
613 //    welcome_if_panel_reload();
614
615     /* Recreate the packet list according to new preferences */
616     recreatePacketList();
617
618     /* Reload pane geometry, must be done after recreating the list */
619     //    main_pane_load_window_geometry();
620 }
621
622 void MainWindow::filterExpressionsChanged()
623 {
624     // Recreate filter buttons
625     foreach (QAction *act, main_ui_->displayFilterToolBar->actions()) {
626         // Permanent actions shouldn't have data
627         if (act->property(dfe_property_).isValid()) {
628             main_ui_->displayFilterToolBar->removeAction(act);
629             delete act;
630         }
631     }
632
633     for (struct filter_expression *fe = *pfilter_expression_head; fe != NULL; fe = fe->next) {
634         if (!fe->enabled) continue;
635         QAction *dfb_action = new QAction(fe->label, main_ui_->displayFilterToolBar);
636         dfb_action->setToolTip(fe->expression);
637         dfb_action->setData(fe->expression);
638         dfb_action->setProperty(dfe_property_, true);
639         main_ui_->displayFilterToolBar->addAction(dfb_action);
640         connect(dfb_action, SIGNAL(triggered()), this, SLOT(displayFilterButtonClicked()));
641     }
642 }
643
644 //
645 // Private slots
646 //
647
648 // ui/gtk/capture_dlg.c:start_capture_confirmed
649
650 void MainWindow::startCapture() {
651 #ifdef HAVE_LIBPCAP
652     interface_options interface_opts;
653     guint i;
654
655     /* did the user ever select a capture interface before? */
656     if(global_capture_opts.num_selected == 0) {
657         QString msg = QString(tr("No interface selected"));
658         main_ui_->statusBar->pushTemporaryStatus(msg);
659         return;
660     }
661
662     // Ideally we should have disabled the start capture
663     // toolbar buttons and menu items. This may not be the
664     // case, e.g. with QtMacExtras.
665     if(!capture_filter_valid_) {
666         QString msg = QString(tr("Invalid capture filter"));
667         main_ui_->statusBar->pushTemporaryStatus(msg);
668         return;
669     }
670
671     /* XXX - we might need to init other pref data as well... */
672 //    main_auto_scroll_live_changed(auto_scroll_live);
673
674     /* XXX - can this ever happen? */
675     if (cap_session_.state != CAPTURE_STOPPED)
676       return;
677
678     /* close the currently loaded capture file */
679     cf_close((capture_file *) cap_session_.cf);
680
681     /* Copy the selected interfaces to the set of interfaces to use for
682        this capture. */
683     collect_ifaces(&global_capture_opts);
684
685     CaptureFile::globalCapFile()->window = this;
686     if (capture_start(&global_capture_opts, &cap_session_, main_window_update)) {
687         /* The capture succeeded, which means the capture filter syntax is
688          valid; add this capture filter to the recent capture filter list. */
689         for (i = 0; i < global_capture_opts.ifaces->len; i++) {
690             interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
691             if (interface_opts.cfilter) {
692 //              cfilter_combo_add_recent(interface_opts.cfilter);
693             }
694         }
695     } else {
696         CaptureFile::globalCapFile()->window = NULL;
697     }
698 #endif // HAVE_LIBPCAP
699 }
700
701 // Copied from ui/gtk/gui_utils.c
702 void MainWindow::pipeTimeout() {
703 #ifdef _WIN32
704     HANDLE handle;
705     DWORD avail = 0;
706     gboolean result, result1;
707     DWORD childstatus;
708     gint iterations = 0;
709
710
711     /* try to read data from the pipe only 5 times, to avoid blocking */
712     while(iterations < 5) {
713         /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
714
715         /* Oddly enough although Named pipes don't work on win9x,
716            PeekNamedPipe does !!! */
717         handle = (HANDLE) _get_osfhandle (pipe_source_);
718         result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
719
720         /* Get the child process exit status */
721         result1 = GetExitCodeProcess((HANDLE)*(pipe_child_process_),
722                                      &childstatus);
723
724         /* If the Peek returned an error, or there are bytes to be read
725            or the childwatcher thread has terminated then call the normal
726            callback */
727         if (!result || avail > 0 || childstatus != STILL_ACTIVE) {
728
729             /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
730
731             /* And call the real handler */
732             if (!pipe_input_cb_(pipe_source_, pipe_user_data_)) {
733                 g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: input pipe closed, iterations: %u", iterations);
734                 /* pipe closed, return false so that the old timer is not run again */
735                 delete pipe_timer_;
736                 return;
737             }
738         }
739         else {
740             /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
741             /* No data, stop now */
742             break;
743         }
744
745         iterations++;
746     }
747 #endif // _WIN32
748 }
749
750 void MainWindow::pipeActivated(int source) {
751 #ifdef _WIN32
752     Q_UNUSED(source);
753 #else
754     g_assert(source == pipe_source_);
755
756     pipe_notifier_->setEnabled(false);
757     if (pipe_input_cb_(pipe_source_, pipe_user_data_)) {
758         pipe_notifier_->setEnabled(true);
759     } else {
760         delete pipe_notifier_;
761     }
762 #endif // _WIN32
763 }
764
765 void MainWindow::pipeNotifierDestroyed() {
766 #ifdef _WIN32
767     pipe_timer_ = NULL;
768 #else
769     pipe_notifier_ = NULL;
770 #endif // _WIN32
771 }
772
773 void MainWindow::stopCapture() {
774 //#ifdef HAVE_AIRPCAP
775 //  if (airpcap_if_active)
776 //    airpcap_set_toolbar_stop_capture(airpcap_if_active);
777 //#endif
778
779 #ifdef HAVE_LIBPCAP
780     capture_stop(&cap_session_);
781 #endif // HAVE_LIBPCAP
782 }
783
784 // XXX - Copied from ui/gtk/menus.c
785
786 /**
787  * Add the capture filename (with an absolute path) to the "Recent Files" menu.
788  */
789 // XXX - We should probably create a RecentFile class.
790 void MainWindow::updateRecentFiles() {
791     QAction *ra;
792     QMenu *recentMenu = main_ui_->menuOpenRecentCaptureFile;
793     QString action_cf_name;
794
795     if (!recentMenu) {
796         return;
797     }
798
799     recentMenu->clear();
800
801     /* Iterate through the actions in menuOpenRecentCaptureFile,
802      * removing special items, a maybe duplicate entry and every item above count_max */
803     int shortcut = Qt::Key_0;
804     foreach (recent_item_status *ri, wsApp->recentItems()) {
805         // Add the new item
806         ra = new QAction(recentMenu);
807         ra->setData(ri->filename);
808         // XXX - Needs get_recent_item_status or equivalent
809         ra->setEnabled(ri->accessible);
810         recentMenu->insertAction(NULL, ra);
811         action_cf_name = ra->data().toString();
812         if (shortcut <= Qt::Key_9) {
813             ra->setShortcut(Qt::META | shortcut);
814             shortcut++;
815         }
816         ra->setText(action_cf_name);
817         connect(ra, SIGNAL(triggered()), this, SLOT(recentActionTriggered()));
818     }
819
820     if (recentMenu->actions().count() > 0) {
821         // Separator + "Clear"
822         // XXX - Do we really need this?
823         ra = new QAction(recentMenu);
824         ra->setSeparator(true);
825         recentMenu->insertAction(NULL, ra);
826
827         ra = new QAction(recentMenu);
828         ra->setText(tr("Clear Menu"));
829         recentMenu->insertAction(NULL, ra);
830         connect(ra, SIGNAL(triggered()), wsApp, SLOT(clearRecentItems()));
831     } else {
832         if (main_ui_->actionDummyNoFilesFound) {
833             recentMenu->addAction(main_ui_->actionDummyNoFilesFound);
834         }
835     }
836 }
837
838 void MainWindow::recentActionTriggered() {
839     QAction *ra = qobject_cast<QAction*>(sender());
840
841     if (ra) {
842         QString cfPath = ra->data().toString();
843         openCaptureFile(cfPath);
844     }
845 }
846
847 void MainWindow::setMenusForSelectedPacket()
848 {
849 //    GList      *list_entry = dissector_filter_list;
850 //    guint       i          = 0;
851 //    gboolean    properties = FALSE;
852 //    const char *abbrev     = NULL;
853 //    char       *prev_abbrev;
854 #if 0
855     gboolean is_ip = FALSE, is_tcp = FALSE, is_udp = FALSE, is_sctp = FALSE;
856 #else
857     gboolean is_tcp = FALSE, is_sctp = FALSE;
858 #endif
859
860 //    /* Making the menu context-sensitive allows for easier selection of the
861 //       desired item and has the added benefit, with large captures, of
862 //       avoiding needless looping through huge lists for marked, ignored,
863 //       or time-referenced packets. */
864 //    gboolean is_ssl = epan_dissect_packet_contains_field(cf->edt, "ssl");
865
866     /* We have one or more items in the packet list */
867     gboolean have_frames = FALSE;
868     /* A frame is selected */
869     gboolean frame_selected = FALSE;
870     /* We have marked frames.  (XXX - why check frame_selected?) */
871     gboolean have_marked = FALSE;
872     /* We have a marked frame other than the current frame (i.e.,
873        we have at least one marked frame, and either there's more
874        than one marked frame or the current frame isn't marked). */
875     gboolean another_is_marked = FALSE;
876     /* One or more frames are hidden by a display filter */
877     gboolean have_filtered = FALSE;
878     /* One or more frames have been ignored */
879     gboolean have_ignored = FALSE;
880     gboolean have_time_ref = FALSE;
881     /* We have a time reference frame other than the current frame (i.e.,
882        we have at least one time reference frame, and either there's more
883        than one time reference frame or the current frame isn't a
884        time reference frame). (XXX - why check frame_selected?) */
885     gboolean another_is_time_ref = FALSE;
886
887     if (capture_file_.capFile()) {
888         frame_selected = capture_file_.capFile()->current_frame != NULL;
889         have_frames = capture_file_.capFile()->count > 0;
890         have_marked = frame_selected && capture_file_.capFile()->marked_count > 0;
891         another_is_marked = have_marked &&
892                 !(capture_file_.capFile()->marked_count == 1 && capture_file_.capFile()->current_frame->flags.marked);
893         have_filtered = capture_file_.capFile()->displayed_count > 0 && capture_file_.capFile()->displayed_count != capture_file_.capFile()->count;
894         have_ignored = capture_file_.capFile()->ignored_count > 0;
895         have_time_ref = capture_file_.capFile()->ref_time_count > 0;
896         another_is_time_ref = frame_selected && have_time_ref &&
897                 !(capture_file_.capFile()->ref_time_count == 1 && capture_file_.capFile()->current_frame->flags.ref_time);
898
899         if (capture_file_.capFile()->edt)
900         {
901             proto_get_frame_protocols(capture_file_.capFile()->edt->pi.layers, NULL, &is_tcp, NULL, &is_sctp, NULL);
902         }
903     }
904 //    if (cfile.edt && cfile.edt->tree) {
905 //        GPtrArray          *ga;
906 //        header_field_info  *hfinfo;
907 //        field_info         *v;
908 //        guint              ii;
909
910 //        ga = proto_all_finfos(cfile.edt->tree);
911
912 //        for (ii = ga->len - 1; ii > 0 ; ii -= 1) {
913
914 //            v = g_ptr_array_index (ga, ii);
915 //            hfinfo =  v->hfinfo;
916
917 //            if (!g_str_has_prefix(hfinfo->abbrev, "text") &&
918 //                !g_str_has_prefix(hfinfo->abbrev, "_ws.expert") &&
919 //                !g_str_has_prefix(hfinfo->abbrev, "_ws.malformed")) {
920
921 //                if (hfinfo->parent == -1) {
922 //                    abbrev = hfinfo->abbrev;
923 //                } else {
924 //                    abbrev = proto_registrar_get_abbrev(hfinfo->parent);
925 //                }
926 //                properties = prefs_is_registered_protocol(abbrev);
927 //                break;
928 //            }
929 //        }
930 //    }
931
932     main_ui_->actionEditMarkPacket->setEnabled(frame_selected);
933     main_ui_->actionEditMarkAllDisplayed->setEnabled(have_frames);
934     /* Unlike un-ignore, do not allow unmark of all frames when no frames are displayed  */
935     main_ui_->actionEditUnmarkAllDisplayed->setEnabled(have_marked);
936     main_ui_->actionEditNextMark->setEnabled(another_is_marked);
937     main_ui_->actionEditPreviousMark->setEnabled(another_is_marked);
938
939 //#ifdef WANT_PACKET_EDITOR
940 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/EditPacket",
941 //                         frame_selected);
942 //#endif /* WANT_PACKET_EDITOR */
943     main_ui_->actionEditPacketComment->setEnabled(frame_selected && wtap_dump_can_write(capture_file_.capFile()->linktypes, WTAP_COMMENT_PER_PACKET));
944
945     main_ui_->actionEditIgnorePacket->setEnabled(frame_selected);
946     main_ui_->actionEditIgnoreAllDisplayed->setEnabled(have_filtered);
947     /* Allow un-ignore of all frames even with no frames currently displayed */
948     main_ui_->actionEditUnignoreAllDisplayed->setEnabled(have_ignored);
949
950     main_ui_->actionEditSetTimeReference->setEnabled(frame_selected);
951     main_ui_->actionEditUnsetAllTimeReferences->setEnabled(have_time_ref);
952     main_ui_->actionEditNextTimeReference->setEnabled(another_is_time_ref);
953     main_ui_->actionEditPreviousTimeReference->setEnabled(another_is_time_ref);
954     main_ui_->actionEditTimeShift->setEnabled(have_frames);
955
956 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ResizeAllColumns",
957 //                         frame_selected);
958 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/CollapseAll",
959 //                         frame_selected);
960 //    set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/CollapseAll",
961 //                         frame_selected);
962 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ExpandAll",
963 //                         frame_selected);
964 //    set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandAll",
965 //                         frame_selected);
966 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ColorizeConversation",
967 //                         frame_selected);
968 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ResetColoring1-10",
969 //                         tmp_color_filters_used());
970 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ShowPacketinNewWindow",
971 //                         frame_selected);
972 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ShowPacketinNewWindow",
973 //                         frame_selected);
974 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ManuallyResolveAddress",
975 //                         frame_selected ? is_ip : FALSE);
976 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/SCTP",
977 //                         frame_selected ? is_sctp : FALSE);
978 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/FollowTCPStream",
979 //                         frame_selected ? is_tcp : FALSE);
980 //    set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FollowTCPStream",
981 //                         frame_selected ? is_tcp : FALSE);
982 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/FollowUDPStream",
983 //                         frame_selected ? is_udp : FALSE);
984 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/FollowSSLStream",
985 //                         frame_selected ? is_ssl : FALSE);
986 //    set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FollowSSLStream",
987 //                         frame_selected ? is_ssl : FALSE);
988 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter",
989 //                         frame_selected);
990 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/Ethernet",
991 //                         frame_selected ? (cf->edt->pi.dl_src.type == AT_ETHER) : FALSE);
992 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/IP",
993 //                         frame_selected ? is_ip : FALSE);
994 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/TCP",
995 //                         frame_selected ? is_tcp : FALSE);
996 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/UDP",
997 //                         frame_selected ? is_udp : FALSE);
998 //    set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FollowUDPStream",
999 //                         frame_selected ? is_udp : FALSE);
1000 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/PN-CBA",
1001 //                         frame_selected ? (cf->edt->pi.profinet_type != 0 && cf->edt->pi.profinet_type < 10) : FALSE);
1002 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation",
1003 //                         frame_selected);
1004 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/Ethernet",
1005 //                         frame_selected ? (cf->edt->pi.dl_src.type == AT_ETHER) : FALSE);
1006 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/IP",
1007 //                         frame_selected ? is_ip : FALSE);
1008 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/TCP",
1009 //                         frame_selected ? is_tcp : FALSE);
1010 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/UDP",
1011 //                         frame_selected ? is_udp : FALSE);
1012 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/PN-CBA",
1013 //                         frame_selected ? (cf->edt->pi.profinet_type != 0 && cf->edt->pi.profinet_type < 10) : FALSE);
1014
1015 //    if (properties) {
1016 //        prev_abbrev = g_object_get_data(G_OBJECT(ui_manager_packet_list_menu), "menu_abbrev");
1017 //        if (!prev_abbrev || (strcmp(prev_abbrev, abbrev) != 0)) {
1018 //          /*No previous protocol or protocol changed - update Protocol Preferences menu*/
1019 //            module_t *prefs_module_p = prefs_find_module(abbrev);
1020 //            rebuild_protocol_prefs_menu(prefs_module_p, properties, ui_manager_packet_list_menu, "/PacketListMenuPopup/ProtocolPreferences");
1021
1022 //            g_object_set_data(G_OBJECT(ui_manager_packet_list_menu), "menu_abbrev", g_strdup(abbrev));
1023 //            g_free (prev_abbrev);
1024 //        }
1025 //    }
1026
1027 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ProtocolPreferences",
1028 //                             properties);
1029 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/Copy",
1030 //                         frame_selected);
1031 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ApplyAsFilter",
1032 //                         frame_selected);
1033 //    set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/PrepareaFilter",
1034 //                         frame_selected);
1035 //    set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ResolveName",
1036 //                         frame_selected && (gbl_resolv_flags.mac_name || gbl_resolv_flags.network_name ||
1037 //                                            gbl_resolv_flags.transport_name || gbl_resolv_flags.concurrent_dns));
1038 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/FollowTCPStream",
1039 //                         frame_selected ? is_tcp : FALSE);
1040 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/FollowUDPStream",
1041 //                         frame_selected ? is_udp : FALSE);
1042 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/FollowSSLStream",
1043 //                         frame_selected ? is_ssl : FALSE);
1044 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/NameResolution/ResolveName",
1045 //                         frame_selected && (gbl_resolv_flags.mac_name || gbl_resolv_flags.network_name ||
1046 //                                            gbl_resolv_flags.transport_name || gbl_resolv_flags.concurrent_dns));
1047 //    set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ToolsMenu/FirewallACLRules",
1048 //                         frame_selected);
1049     main_ui_->menuTcpStreamGraphs->setEnabled(is_tcp);
1050     main_ui_->menuSCTP->setEnabled(is_sctp);
1051     main_ui_->actionSCTPAnalyseThisAssociation->setEnabled(is_sctp);
1052     main_ui_->actionSCTPShowAllAssociations->setEnabled(is_sctp);
1053     main_ui_->actionSCTPFilterThisAssociation->setEnabled(is_sctp);
1054
1055 //    while (list_entry != NULL) {
1056 //        dissector_filter_t *filter_entry;
1057 //        gchar *path;
1058
1059 //        filter_entry = list_entry->data;
1060 //        path = g_strdup_printf("/Menubar/AnalyzeMenu/ConversationFilterMenu/Filters/filter-%u", i);
1061
1062 //        set_menu_sensitivity(ui_manager_main_menubar, path,
1063 //            menu_dissector_filter_spe_cb(/* frame_data *fd _U_*/ NULL, cf->edt, filter_entry));
1064 //        g_free(path);
1065 //        i++;
1066 //        list_entry = g_list_next(list_entry);
1067 //    }
1068 }
1069
1070 void MainWindow::setMenusForSelectedTreeRow(field_info *fi) {
1071     //gboolean properties;
1072     //gint id;
1073
1074     // XXX Add commented items below
1075
1076     if (capture_file_.capFile()) {
1077         capture_file_.capFile()->finfo_selected = fi;
1078     }
1079
1080     if (capture_file_.capFile() != NULL && fi != NULL) {
1081         /*
1082         header_field_info *hfinfo = fi->hfinfo;
1083         const char *abbrev;
1084         char *prev_abbrev;
1085
1086         if (hfinfo->parent == -1) {
1087             abbrev = hfinfo->abbrev;
1088             id = (hfinfo->type == FT_PROTOCOL) ? proto_get_id((protocol_t *)hfinfo->strings) : -1;
1089         } else {
1090             abbrev = proto_registrar_get_abbrev(hfinfo->parent);
1091             id = hfinfo->parent;
1092         }
1093         properties = prefs_is_registered_protocol(abbrev);
1094         */
1095         bool can_match_selected = proto_can_match_selected(capture_file_.capFile()->finfo_selected, capture_file_.capFile()->edt);
1096 //        set_menu_sensitivity(ui_manager_tree_view_menu,
1097 //                             "/TreeViewPopup/GotoCorrespondingPacket", hfinfo->type == FT_FRAMENUM);
1098 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/Copy",
1099 //                             TRUE);
1100
1101 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/CreateAColumn",
1102 //                             hfinfo->type != FT_NONE);
1103 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ColorizewithFilter",
1104 //                             proto_can_match_selected(cf->finfo_selected, cf->edt));
1105 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ProtocolPreferences",
1106 //                             properties);
1107 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/DisableProtocol",
1108 //                             (id == -1) ? FALSE : proto_can_toggle_protocol(id));
1109 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandSubtrees",
1110 //                             cf->finfo_selected->tree_type != -1);
1111 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/WikiProtocolPage",
1112 //                             (id == -1) ? FALSE : TRUE);
1113 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FilterFieldReference",
1114 //                             (id == -1) ? FALSE : TRUE);
1115 //        set_menu_sensitivity(ui_manager_main_menubar,
1116         main_ui_->actionFileExportPacketBytes->setEnabled(true);
1117
1118 //        set_menu_sensitivity(ui_manager_main_menubar,
1119 //                             "/Menubar/GoMenu/GotoCorrespondingPacket", hfinfo->type == FT_FRAMENUM);
1120
1121         main_ui_->actionEditCopyDescription->setEnabled(can_match_selected);
1122         main_ui_->actionEditCopyFieldName->setEnabled(can_match_selected);
1123         main_ui_->actionEditCopyValue->setEnabled(can_match_selected);
1124         main_ui_->actionEditCopyAsFilter->setEnabled(can_match_selected);
1125 //        set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Description",
1126 //                             proto_can_match_selected(cf->finfo_selected, cf->edt));
1127 //        set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Fieldname",
1128 //                             proto_can_match_selected(cf->finfo_selected, cf->edt));
1129 //        set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Value",
1130 //                             proto_can_match_selected(cf->finfo_selected, cf->edt));
1131 //        set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/AsFilter",
1132 //                             proto_can_match_selected(cf->finfo_selected, cf->edt));
1133
1134 //        set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/CreateAColumn",
1135 //                             hfinfo->type != FT_NONE);
1136         main_ui_->actionAnalyzeAAFSelected->setEnabled(can_match_selected);
1137         main_ui_->actionAnalyzeAAFNotSelected->setEnabled(can_match_selected);
1138         main_ui_->actionAnalyzeAAFAndSelected->setEnabled(can_match_selected);
1139         main_ui_->actionAnalyzeAAFOrSelected->setEnabled(can_match_selected);
1140         main_ui_->actionAnalyzeAAFAndNotSelected->setEnabled(can_match_selected);
1141         main_ui_->actionAnalyzeAAFOrNotSelected->setEnabled(can_match_selected);
1142
1143         main_ui_->actionAnalyzePAFSelected->setEnabled(can_match_selected);
1144         main_ui_->actionAnalyzePAFNotSelected->setEnabled(can_match_selected);
1145         main_ui_->actionAnalyzePAFAndSelected->setEnabled(can_match_selected);
1146         main_ui_->actionAnalyzePAFOrSelected->setEnabled(can_match_selected);
1147         main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(can_match_selected);
1148         main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(can_match_selected);
1149
1150         main_ui_->actionViewExpandSubtrees->setEnabled(capture_file_.capFile()->finfo_selected->tree_type != -1);
1151 //        prev_abbrev = g_object_get_data(G_OBJECT(ui_manager_tree_view_menu), "menu_abbrev");
1152 //        if (!prev_abbrev || (strcmp (prev_abbrev, abbrev) != 0)) {
1153 //            /* No previous protocol or protocol changed - update Protocol Preferences menu */
1154 //            module_t *prefs_module_p = prefs_find_module(abbrev);
1155 //            rebuild_protocol_prefs_menu (prefs_module_p, properties);
1156
1157 //            g_object_set_data(G_OBJECT(ui_manager_tree_view_menu), "menu_abbrev", g_strdup(abbrev));
1158 //            g_free (prev_abbrev);
1159 //        }
1160     } else {
1161 //        set_menu_sensitivity(ui_manager_tree_view_menu,
1162 //                             "/TreeViewPopup/GotoCorrespondingPacket", FALSE);
1163 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/Copy", FALSE);
1164 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/CreateAColumn", FALSE);
1165 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ApplyAsFilter", FALSE);
1166 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/PrepareaFilter", FALSE);
1167 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ColorizewithFilter", FALSE);
1168 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ProtocolPreferences",
1169 //                             FALSE);
1170 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/DisableProtocol", FALSE);
1171 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandSubtrees", FALSE);
1172 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/WikiProtocolPage",
1173 //                             FALSE);
1174 //        set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FilterFieldReference",
1175 //                             FALSE);
1176         main_ui_->actionFileExportPacketBytes->setEnabled(false);
1177 //        set_menu_sensitivity(ui_manager_main_menubar,
1178 //                             "/Menubar/GoMenu/GotoCorrespondingPacket", FALSE);
1179         main_ui_->actionEditCopyDescription->setEnabled(false);
1180         main_ui_->actionEditCopyFieldName->setEnabled(false);
1181         main_ui_->actionEditCopyValue->setEnabled(false);
1182         main_ui_->actionEditCopyAsFilter->setEnabled(false);
1183 //        set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/CreateAColumn", FALSE);
1184
1185         main_ui_->actionAnalyzeAAFSelected->setEnabled(false);
1186         main_ui_->actionAnalyzeAAFNotSelected->setEnabled(false);
1187         main_ui_->actionAnalyzeAAFAndSelected->setEnabled(false);
1188         main_ui_->actionAnalyzeAAFOrSelected->setEnabled(false);
1189         main_ui_->actionAnalyzeAAFAndNotSelected->setEnabled(false);
1190         main_ui_->actionAnalyzeAAFOrNotSelected->setEnabled(false);
1191
1192         main_ui_->actionAnalyzePAFSelected->setEnabled(false);
1193         main_ui_->actionAnalyzePAFNotSelected->setEnabled(false);
1194         main_ui_->actionAnalyzePAFAndSelected->setEnabled(false);
1195         main_ui_->actionAnalyzePAFOrSelected->setEnabled(false);
1196         main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(false);
1197         main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(false);
1198
1199         main_ui_->actionViewExpandSubtrees->setEnabled(false);
1200     }
1201 }
1202
1203 void MainWindow::interfaceSelectionChanged()
1204 {
1205 #ifdef HAVE_LIBPCAP
1206     // XXX This doesn't disable the toolbar button when using
1207     // QtMacExtras.
1208     if (global_capture_opts.num_selected > 0 && capture_filter_valid_) {
1209         main_ui_->actionCaptureStart->setEnabled(true);
1210     } else {
1211         main_ui_->actionCaptureStart->setEnabled(false);
1212     }
1213 #endif // HAVE_LIBPCAP
1214 }
1215
1216 void MainWindow::captureFilterSyntaxChanged(bool valid)
1217 {
1218     capture_filter_valid_ = valid;
1219     interfaceSelectionChanged();
1220 }
1221
1222 void MainWindow::startInterfaceCapture(bool valid)
1223 {
1224     capture_filter_valid_ = valid;
1225     startCapture();
1226 }
1227
1228 void MainWindow::redissectPackets()
1229 {
1230     if (capture_file_.capFile())
1231         cf_redissect_packets(capture_file_.capFile());
1232     main_ui_->statusBar->expertUpdate();
1233 }
1234
1235 void MainWindow::recreatePacketList()
1236 {
1237     prefs.num_cols = g_list_length(prefs.col_list);
1238
1239     col_cleanup(&CaptureFile::globalCapFile()->cinfo);
1240     build_column_format_array(&CaptureFile::globalCapFile()->cinfo, prefs.num_cols, FALSE);
1241
1242     packet_list_->redrawVisiblePackets();
1243     packet_list_->hide();
1244     packet_list_->show();
1245
1246     CaptureFile::globalCapFile()->columns_changed = FALSE; /* Reset value */
1247 }
1248
1249 void MainWindow::fieldsChanged()
1250 {
1251     // Reload color filters
1252     color_filters_reload();
1253
1254     // Syntax check filter
1255     // TODO: Check if syntax filter is still valid after fields have changed
1256     //       and update background color.
1257     if (CaptureFile::globalCapFile()->dfilter) {
1258         // Check if filter is still valid
1259         dfilter_t *dfp = NULL;
1260         if (!dfilter_compile(CaptureFile::globalCapFile()->dfilter, &dfp)) {
1261             // TODO: Not valid, enable "Apply" button.
1262             g_free(CaptureFile::globalCapFile()->dfilter);
1263             CaptureFile::globalCapFile()->dfilter = NULL;
1264         }
1265         dfilter_free(dfp);
1266     }
1267
1268     if (have_custom_cols(&CaptureFile::globalCapFile()->cinfo)) {
1269         /* Recreate packet list according to new/changed/deleted fields */
1270         recreatePacketList();
1271     } else if (CaptureFile::globalCapFile()->state != FILE_CLOSED) {
1272         /* Redissect packets if we have any */
1273         redissectPackets();
1274     }
1275
1276     proto_free_deregistered_fields();
1277 }
1278
1279 void MainWindow::setFeaturesEnabled(bool enabled)
1280 {
1281     main_ui_->menuBar->setEnabled(enabled);
1282     main_ui_->mainToolBar->setEnabled(enabled);
1283     main_ui_->displayFilterToolBar->setEnabled(enabled);
1284     if(enabled)
1285     {
1286         main_ui_->statusBar->clearMessage();
1287     }
1288     else
1289     {
1290         main_ui_->statusBar->showMessage(tr("Please wait while Wireshark is initializing" UTF8_HORIZONTAL_ELLIPSIS));
1291     }
1292 }
1293
1294 // On Qt4 + OS X with unifiedTitleAndToolBarOnMac set it's possible to make
1295 // the main window obnoxiously wide.
1296
1297 // We might want to do something different here. We should probably merge
1298 // the dfilter and gui.filter_expressions code first.
1299 void MainWindow::addDisplayFilterButton(QString df_text)
1300 {
1301     struct filter_expression *cur_fe = *pfilter_expression_head;
1302     struct filter_expression *fe = g_new0(struct filter_expression, 1);
1303
1304     QFontMetrics fm = main_ui_->displayFilterToolBar->fontMetrics();
1305     QString label = fm.elidedText(df_text, Qt::ElideMiddle, fm.height() * 15);
1306
1307     fe->enabled = TRUE;
1308     fe->label = qstring_strdup(label);
1309     fe->expression = qstring_strdup(df_text);
1310
1311     if (!cur_fe) {
1312         *pfilter_expression_head = fe;
1313     } else {
1314         while (cur_fe->next) {
1315             cur_fe = cur_fe->next;
1316         }
1317         cur_fe->next = fe;
1318     }
1319
1320     prefs_main_write();
1321     filterExpressionsChanged();
1322 }
1323
1324 void MainWindow::displayFilterButtonClicked()
1325 {
1326     QAction *dfb_action = qobject_cast<QAction*>(sender());
1327
1328     if (dfb_action) {
1329         df_combo_box_->lineEdit()->setText(dfb_action->data().toString());
1330         df_combo_box_->applyDisplayFilter();
1331         df_combo_box_->lineEdit()->setFocus();
1332     }
1333 }
1334
1335 void MainWindow::openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata)
1336 {
1337     QString slot = QString("statCommand%1").arg(menu_path);
1338     QMetaObject::invokeMethod(this, slot.toLatin1().constData(), Q_ARG(const char *, arg), Q_ARG(void *, userdata));
1339 }
1340
1341 // File Menu
1342
1343 void MainWindow::on_actionFileOpen_triggered()
1344 {
1345     openCaptureFile();
1346 }
1347
1348 void MainWindow::on_actionFileMerge_triggered()
1349 {
1350     mergeCaptureFile();
1351 }
1352
1353 void MainWindow::on_actionFileImportFromHexDump_triggered()
1354 {
1355     importCaptureFile();
1356 }
1357
1358 void MainWindow::on_actionFileClose_triggered() {
1359     if (testCaptureFileClose())
1360         main_ui_->mainStack->setCurrentWidget(main_welcome_);
1361 }
1362
1363 void MainWindow::on_actionFileSave_triggered()
1364 {
1365     saveCaptureFile(capture_file_.capFile(), FALSE);
1366 }
1367
1368 void MainWindow::on_actionFileSaveAs_triggered()
1369 {
1370     saveAsCaptureFile(capture_file_.capFile(), FALSE, TRUE);
1371 }
1372
1373 void MainWindow::on_actionFileSetListFiles_triggered()
1374 {
1375     file_set_dialog_.exec();
1376 }
1377
1378 void MainWindow::on_actionFileSetNextFile_triggered()
1379 {
1380     fileset_entry *entry = fileset_get_next();
1381
1382     if (entry) {
1383         QString new_cf_path = entry->fullname;
1384         openCaptureFile(new_cf_path);
1385     }
1386 }
1387
1388 void MainWindow::on_actionFileSetPreviousFile_triggered()
1389 {
1390     fileset_entry *entry = fileset_get_previous();
1391
1392     if (entry) {
1393         QString new_cf_path = entry->fullname;
1394         openCaptureFile(new_cf_path);
1395     }
1396 }
1397
1398 void MainWindow::on_actionFileExportPackets_triggered()
1399 {
1400     exportSelectedPackets();
1401 }
1402
1403 void MainWindow::on_actionFileExportAsPlainText_triggered()
1404 {
1405     exportDissections(export_type_text);
1406 }
1407
1408 void MainWindow::on_actionFileExportAsCSV_triggered()
1409 {
1410     exportDissections(export_type_csv);
1411 }
1412
1413 void MainWindow::on_actionFileExportAsCArrays_triggered()
1414 {
1415     exportDissections(export_type_carrays);
1416 }
1417
1418 void MainWindow::on_actionFileExportAsPSML_triggered()
1419 {
1420     exportDissections(export_type_psml);
1421 }
1422
1423 void MainWindow::on_actionFileExportAsPDML_triggered()
1424 {
1425     exportDissections(export_type_pdml);
1426 }
1427
1428 void MainWindow::on_actionFileExportPacketBytes_triggered()
1429 {
1430     QString file_name;
1431
1432     if (!capture_file_.capFile() || !capture_file_.capFile()->finfo_selected) return;
1433
1434     file_name = QFileDialog::getSaveFileName(this,
1435                                              tr("Wireshark: Export Selected Packet Bytes"),
1436                                              wsApp->lastOpenDir().canonicalPath(),
1437                                              tr("Raw data (*.bin *.dat *.raw);;Any File (*.*)")
1438                                              );
1439
1440     if (file_name.length() > 0) {
1441         const guint8 *data_p;
1442         int fd;
1443
1444         data_p = tvb_get_ptr(capture_file_.capFile()->finfo_selected->ds_tvb, 0, -1) +
1445                 capture_file_.capFile()->finfo_selected->start;
1446         fd = ws_open(file_name.toUtf8().constData(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
1447         if (fd == -1) {
1448             open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE);
1449             return;
1450         }
1451         if (write(fd, data_p, capture_file_.capFile()->finfo_selected->length) < 0) {
1452             write_failure_alert_box(file_name.toUtf8().constData(), errno);
1453             ::close(fd);
1454             return;
1455         }
1456         if (::close(fd) < 0) {
1457             write_failure_alert_box(file_name.toUtf8().constData(), errno);
1458             return;
1459         }
1460
1461         /* Save the directory name for future file dialogs. */
1462         wsApp->setLastOpenDir(&file_name);
1463     }
1464 }
1465 void MainWindow::on_actionFileExportPDU_triggered()
1466 {
1467     ExportPDUDialog *exportpdu_dialog = new ExportPDUDialog(this);
1468
1469     if (exportpdu_dialog->isMinimized() == true)
1470     {
1471         exportpdu_dialog->showNormal();
1472     }
1473     else
1474     {
1475         exportpdu_dialog->show();
1476     }
1477
1478     exportpdu_dialog->raise();
1479     exportpdu_dialog->activateWindow();
1480 }
1481
1482 void MainWindow::on_actionFileExportSSLSessionKeys_triggered()
1483 {
1484     QString file_name;
1485     QString save_title;
1486     int keylist_len;
1487
1488     keylist_len = ssl_session_key_count();
1489     /* don't show up the dialog, if no data has to be saved */
1490     if (keylist_len < 1) {
1491         /* shouldn't happen as the menu item should have been greyed out */
1492         QMessageBox::warning(
1493                     this,
1494                     tr("No Keys"),
1495                     tr("There are no SSL Session Keys to save."),
1496                     QMessageBox::Ok
1497                     );
1498         return;
1499     }
1500
1501     save_title.append(QString("Wireshark: Export SSL Session Keys (%1 key%2").
1502             arg(keylist_len).arg(plurality(keylist_len, "", "s")));
1503     file_name = QFileDialog::getSaveFileName(this,
1504                                              save_title,
1505                                              wsApp->lastOpenDir().canonicalPath(),
1506                                              tr("SSL Session Keys (*.keys *.txt);;Any File (*.*)")
1507                                              );
1508     if (file_name.length() > 0) {
1509         gchar *keylist;
1510         int fd;
1511
1512         keylist = ssl_export_sessions();
1513         fd = ws_open(file_name.toUtf8().constData(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
1514         if (fd == -1) {
1515             open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE);
1516             g_free(keylist);
1517             return;
1518         }
1519         /*
1520          * Thanks, Microsoft, for not using size_t for the third argument to
1521          * _write().  Presumably this string will be <= 4GiB long....
1522          */
1523         if (ws_write(fd, keylist, (unsigned int)strlen(keylist)) < 0) {
1524             write_failure_alert_box(file_name.toUtf8().constData(), errno);
1525             ::close(fd);
1526             g_free(keylist);
1527             return;
1528         }
1529         if (::close(fd) < 0) {
1530             write_failure_alert_box(file_name.toUtf8().constData(), errno);
1531             g_free(keylist);
1532             return;
1533         }
1534
1535         /* Save the directory name for future file dialogs. */
1536         wsApp->setLastOpenDir(&file_name);
1537         g_free(keylist);
1538     }
1539 }
1540
1541 void MainWindow::on_actionFileExportObjectsDICOM_triggered()
1542 {
1543     new ExportObjectDialog(this, capture_file_.capFile(), ExportObjectDialog::Dicom);
1544 }
1545
1546 void MainWindow::on_actionFileExportObjectsHTTP_triggered()
1547 {
1548     new ExportObjectDialog(this, capture_file_.capFile(), ExportObjectDialog::Http);
1549 }
1550
1551 void MainWindow::on_actionFileExportObjectsSMB_triggered()
1552 {
1553     new ExportObjectDialog(this, capture_file_.capFile(), ExportObjectDialog::Smb);
1554 }
1555
1556 void MainWindow::on_actionFileExportObjectsTFTP_triggered()
1557 {
1558     new ExportObjectDialog(this, capture_file_.capFile(), ExportObjectDialog::Tftp);
1559 }
1560
1561 void MainWindow::on_actionFilePrint_triggered()
1562 {
1563     PrintDialog pdlg(this, capture_file_.capFile());
1564
1565     pdlg.exec();
1566 }
1567
1568 // Edit Menu
1569
1570 // XXX This should probably be somewhere else.
1571 void MainWindow::actionEditCopyTriggered(MainWindow::CopySelected selection_type)
1572 {
1573     char label_str[ITEM_LABEL_LENGTH];
1574     QString clip;
1575
1576     if (!capture_file_.capFile()) return;
1577
1578     switch(selection_type) {
1579     case CopySelectedDescription:
1580         if (capture_file_.capFile()->finfo_selected->rep &&
1581                 strlen (capture_file_.capFile()->finfo_selected->rep->representation) > 0) {
1582             clip.append(capture_file_.capFile()->finfo_selected->rep->representation);
1583         }
1584         break;
1585     case CopySelectedFieldName:
1586         if (capture_file_.capFile()->finfo_selected->hfinfo->abbrev != 0) {
1587             clip.append(capture_file_.capFile()->finfo_selected->hfinfo->abbrev);
1588         }
1589         break;
1590     case CopySelectedValue:
1591         if (capture_file_.capFile()->edt != 0) {
1592             gchar* field_str = get_node_field_value(capture_file_.capFile()->finfo_selected, capture_file_.capFile()->edt);
1593             clip.append(field_str);
1594             g_free(field_str);
1595         }
1596         break;
1597     }
1598
1599     if (clip.length() == 0) {
1600         /* If no representation then... Try to read the value */
1601         proto_item_fill_label(capture_file_.capFile()->finfo_selected, label_str);
1602         clip.append(label_str);
1603     }
1604
1605     if (clip.length()) {
1606         wsApp->clipboard()->setText(clip);
1607     } else {
1608         QString err = tr("Couldn't copy text. Try another item.");
1609         main_ui_->statusBar->pushTemporaryStatus(err);
1610     }
1611 }
1612
1613 void MainWindow::on_actionEditCopyDescription_triggered()
1614 {
1615     actionEditCopyTriggered(CopySelectedDescription);
1616 }
1617
1618 void MainWindow::on_actionEditCopyFieldName_triggered()
1619 {
1620     actionEditCopyTriggered(CopySelectedFieldName);
1621 }
1622
1623 void MainWindow::on_actionEditCopyValue_triggered()
1624 {
1625     actionEditCopyTriggered(CopySelectedValue);
1626 }
1627
1628 void MainWindow::on_actionEditCopyAsFilter_triggered()
1629 {
1630     matchFieldFilter(FilterAction::ActionCopy, FilterAction::ActionTypePlain);
1631 }
1632
1633 void MainWindow::on_actionEditFindPacket_triggered()
1634 {
1635     if (packet_list_->model()->rowCount() < 1) {
1636         return;
1637     }
1638     previous_focus_ = wsApp->focusWidget();
1639     connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus()));
1640     main_ui_->goToFrame->animatedHide();
1641     if (main_ui_->searchFrame->isVisible()) {
1642         main_ui_->searchFrame->animatedHide();
1643     } else {
1644         main_ui_->searchFrame->animatedShow();
1645     }
1646 }
1647
1648 void MainWindow::on_actionEditFindNext_triggered()
1649 {
1650     main_ui_->searchFrame->findNext();
1651 }
1652
1653 void MainWindow::on_actionEditFindPrevious_triggered()
1654 {
1655     main_ui_->searchFrame->findPrevious();
1656 }
1657
1658 void MainWindow::on_actionEditMarkPacket_triggered()
1659 {
1660     packet_list_->markFrame();
1661 }
1662
1663 void MainWindow::on_actionEditMarkAllDisplayed_triggered()
1664 {
1665     packet_list_->markAllDisplayedFrames(true);
1666 }
1667
1668 void MainWindow::on_actionEditUnmarkAllDisplayed_triggered()
1669 {
1670     packet_list_->markAllDisplayedFrames(false);
1671 }
1672
1673 void MainWindow::on_actionEditNextMark_triggered()
1674 {
1675     if (capture_file_.capFile())
1676         cf_find_packet_marked(capture_file_.capFile(), SD_FORWARD);
1677 }
1678
1679 void MainWindow::on_actionEditPreviousMark_triggered()
1680 {
1681     if (capture_file_.capFile())
1682         cf_find_packet_marked(capture_file_.capFile(), SD_BACKWARD);
1683 }
1684
1685 void MainWindow::on_actionEditIgnorePacket_triggered()
1686 {
1687     packet_list_->ignoreFrame();
1688 }
1689
1690 void MainWindow::on_actionEditIgnoreAllDisplayed_triggered()
1691 {
1692     packet_list_->ignoreAllDisplayedFrames(true);
1693 }
1694
1695 void MainWindow::on_actionEditUnignoreAllDisplayed_triggered()
1696 {
1697     packet_list_->ignoreAllDisplayedFrames(false);
1698 }
1699
1700 void MainWindow::on_actionEditSetTimeReference_triggered()
1701 {
1702     packet_list_->setTimeReference();
1703 }
1704
1705 void MainWindow::on_actionEditUnsetAllTimeReferences_triggered()
1706 {
1707     packet_list_->unsetAllTimeReferences();
1708 }
1709
1710 void MainWindow::on_actionEditNextTimeReference_triggered()
1711 {
1712     if (!capture_file_.capFile()) return;
1713     cf_find_packet_time_reference(capture_file_.capFile(), SD_FORWARD);
1714 }
1715
1716 void MainWindow::on_actionEditPreviousTimeReference_triggered()
1717 {
1718     if (!capture_file_.capFile()) return;
1719     cf_find_packet_time_reference(capture_file_.capFile(), SD_BACKWARD);
1720 }
1721
1722 void MainWindow::on_actionEditTimeShift_triggered()
1723 {
1724     TimeShiftDialog ts_dialog(this, capture_file_.capFile());
1725     connect(this, SIGNAL(setCaptureFile(capture_file*)),
1726             &ts_dialog, SLOT(setCaptureFile(capture_file*)));
1727     ts_dialog.exec();
1728 }
1729
1730 void MainWindow::on_actionEditPacketComment_triggered()
1731 {
1732     PacketCommentDialog pc_dialog(this, packet_list_->packetComment());
1733     if (pc_dialog.exec() == QDialog::Accepted) {
1734         packet_list_->setPacketComment(pc_dialog.text());
1735         updateForUnsavedChanges();
1736     }
1737 }
1738
1739 void MainWindow::on_actionEditConfigurationProfiles_triggered()
1740 {
1741     ProfileDialog cp_dialog;
1742
1743     cp_dialog.exec();
1744 }
1745
1746 void MainWindow::on_actionEditPreferences_triggered()
1747 {
1748     PreferencesDialog pref_dialog;
1749
1750     pref_dialog.exec();
1751
1752     // Emitting PacketDissectionChanged directly from PreferencesDialog
1753     // can cause problems. Queue them up and emit them here.
1754     foreach (WiresharkApplication::AppSignal app_signal, pref_dialog.appSignals()) {
1755         wsApp->emitAppSignal(app_signal);
1756     }
1757 }
1758
1759 // View Menu
1760
1761 void MainWindow::showHideMainWidgets(QAction *action)
1762 {
1763     if (!action) {
1764         return;
1765     }
1766     bool show = action->isChecked();
1767     QWidget *widget = action->data().value<QWidget*>();
1768
1769     if (widget == main_ui_->mainToolBar) {
1770         recent.main_toolbar_show = show;
1771     } else if (widget == main_ui_->displayFilterToolBar) {
1772         recent.filter_toolbar_show = show;
1773     // } else if (widget == main_ui_->wirelessToolbar) {
1774     //    recent.wireless_toolbar_show = show;
1775     } else if (widget == main_ui_->statusBar) {
1776         recent.statusbar_show = show;
1777     } else if (widget == packet_list_) {
1778         recent.packet_list_show = show;
1779     } else if (widget == proto_tree_) {
1780         recent.tree_view_show = show;
1781     } else if (widget == byte_view_tab_) {
1782         recent.byte_view_show = show;
1783     }
1784
1785     if (widget) {
1786         widget->setVisible(show);
1787     }
1788 }
1789
1790 Q_DECLARE_METATYPE(ts_type)
1791
1792 void MainWindow::setTimestampFormat(QAction *action)
1793 {
1794     if (!action) {
1795         return;
1796     }
1797     ts_type tsf = action->data().value<ts_type>();
1798     if (recent.gui_time_format != tsf) {
1799         timestamp_set_type(tsf);
1800         recent.gui_time_format = tsf;
1801         if (capture_file_.capFile()) {
1802             /* This call adjusts column width */
1803             cf_timestamp_auto_precision(capture_file_.capFile());
1804         }
1805         if (packet_list_) {
1806             packet_list_->redrawVisiblePackets();
1807         }
1808     }
1809 }
1810
1811 Q_DECLARE_METATYPE(ts_precision)
1812
1813 void MainWindow::setTimestampPrecision(QAction *action)
1814 {
1815     if (!action) {
1816         return;
1817     }
1818     ts_precision tsp = action->data().value<ts_precision>();
1819     if (recent.gui_time_precision != tsp) {
1820         /* the actual precision will be set in packet_list_queue_draw() below */
1821         timestamp_set_precision(tsp);
1822         recent.gui_time_precision = tsp;
1823         if (capture_file_.capFile()) {
1824             /* This call adjusts column width */
1825             cf_timestamp_auto_precision(capture_file_.capFile());
1826         }
1827         if (packet_list_) {
1828             packet_list_->redrawVisiblePackets();
1829         }
1830     }
1831 }
1832
1833 void MainWindow::on_actionViewTimeDisplaySecondsWithHoursAndMinutes_triggered(bool checked)
1834 {
1835     if (checked) {
1836         recent.gui_seconds_format = TS_SECONDS_HOUR_MIN_SEC;
1837     } else {
1838         recent.gui_seconds_format = TS_SECONDS_DEFAULT;
1839     }
1840     timestamp_set_seconds_type(recent.gui_seconds_format);
1841
1842     if (capture_file_.capFile()) {
1843         /* This call adjusts column width */
1844         cf_timestamp_auto_precision(capture_file_.capFile());
1845     }
1846     if (packet_list_) {
1847         packet_list_->redrawVisiblePackets();
1848     }
1849 }
1850
1851 void MainWindow::setNameResolution()
1852 {
1853     gbl_resolv_flags.mac_name = main_ui_->actionViewNameResolutionPhysical->isChecked() ? TRUE : FALSE;
1854     gbl_resolv_flags.network_name = main_ui_->actionViewNameResolutionNetwork->isChecked() ? TRUE : FALSE;
1855     gbl_resolv_flags.transport_name = main_ui_->actionViewNameResolutionTransport->isChecked() ? TRUE : FALSE;
1856
1857     if (packet_list_) {
1858         packet_list_->redrawVisiblePackets();
1859     }
1860 }
1861
1862 void MainWindow::on_actionViewNameResolutionPhysical_triggered()
1863 {
1864     setNameResolution();
1865 }
1866
1867 void MainWindow::on_actionViewNameResolutionNetwork_triggered()
1868 {
1869     setNameResolution();
1870 }
1871
1872 void MainWindow::on_actionViewNameResolutionTransport_triggered()
1873 {
1874     setNameResolution();
1875 }
1876
1877 void MainWindow::zoomText()
1878 {
1879     // Scale by 10%, rounding to nearest half point, minimum 1 point.
1880     // XXX Small sizes repeat. It might just be easier to create a map of multipliers.
1881     mono_font_ = QFont(wsApp->monospaceFont());
1882     qreal zoom_size = wsApp->monospaceFont().pointSize() * 2 * qPow(1.1, recent.gui_zoom_level);
1883     zoom_size = qRound(zoom_size) / 2.0;
1884     zoom_size = qMax(zoom_size, 1.0);
1885     mono_font_.setPointSizeF(zoom_size);
1886     emit monospaceFontChanged(mono_font_);
1887 }
1888
1889 void MainWindow::on_actionViewZoomIn_triggered()
1890 {
1891     recent.gui_zoom_level++;
1892     zoomText();
1893 }
1894
1895 void MainWindow::on_actionViewZoomOut_triggered()
1896 {
1897     recent.gui_zoom_level--;
1898     zoomText();
1899 }
1900
1901 void MainWindow::on_actionViewNormalSize_triggered()
1902 {
1903     recent.gui_zoom_level = 0;
1904     zoomText();
1905 }
1906
1907 void MainWindow::on_actionViewColorizePacketList_triggered(bool checked) {
1908     recent.packet_list_colorize = checked;
1909     color_filters_enable(checked);
1910     packet_list_->packetListModel()->resetColorized();
1911     packet_list_->update();
1912 }
1913
1914 void MainWindow::on_actionViewResizeColumns_triggered()
1915 {
1916     for (int col = 0; col < packet_list_->packetListModel()->columnCount(); col++) {
1917         packet_list_->resizeColumnToContents(col);
1918     }
1919 }
1920
1921 void MainWindow::on_actionViewReload_triggered()
1922 {
1923     cf_reload(CaptureFile::globalCapFile());
1924 }
1925
1926 // Expand / collapse slots in proto_tree
1927
1928 // Go Menu
1929
1930 // Analyze Menu
1931
1932 // XXX This should probably be somewhere else.
1933 void MainWindow::matchFieldFilter(FilterAction::Action action, FilterAction::ActionType filter_type)
1934 {
1935     QString field_filter;
1936
1937     if (packet_list_->contextMenuActive()) {
1938         field_filter = packet_list_->getFilterFromRowAndColumn();
1939     } else if (capture_file_.capFile() && capture_file_.capFile()->finfo_selected) {
1940         field_filter = proto_construct_match_selected_string(capture_file_.capFile()->finfo_selected,
1941                                                        capture_file_.capFile()->edt);
1942     } else {
1943         return;
1944     }
1945
1946     if (field_filter.isEmpty()) {
1947         QString err = tr("No filter available. Try another ");
1948         err.append(packet_list_->contextMenuActive() ? "column" : "item");
1949         err.append(".");
1950         main_ui_->statusBar->pushTemporaryStatus(err);
1951         return;
1952     }
1953
1954     filterAction(field_filter, action, filter_type);
1955 }
1956
1957 // XXX We could probably create the analyze and prepare actions
1958 // dynamically using FilterActions and consolidate the methods
1959 // below into one callback.
1960 void MainWindow::on_actionAnalyzeAAFSelected_triggered()
1961 {
1962     matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypePlain);
1963 }
1964
1965 void MainWindow::on_actionAnalyzeAAFNotSelected_triggered()
1966 {
1967     matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeNot);
1968 }
1969
1970 void MainWindow::on_actionAnalyzeAAFAndSelected_triggered()
1971 {
1972     matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeAnd);
1973 }
1974
1975 void MainWindow::on_actionAnalyzeAAFOrSelected_triggered()
1976 {
1977     matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeOr);
1978 }
1979
1980 void MainWindow::on_actionAnalyzeAAFAndNotSelected_triggered()
1981 {
1982     matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeAndNot);
1983 }
1984
1985 void MainWindow::on_actionAnalyzeAAFOrNotSelected_triggered()
1986 {
1987     matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeOrNot);
1988 }
1989
1990 void MainWindow::on_actionAnalyzePAFSelected_triggered()
1991 {
1992     matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypePlain);
1993 }
1994
1995 void MainWindow::on_actionAnalyzePAFNotSelected_triggered()
1996 {
1997     matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeNot);
1998 }
1999
2000 void MainWindow::on_actionAnalyzePAFAndSelected_triggered()
2001 {
2002     matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeAnd);
2003 }
2004
2005 void MainWindow::on_actionAnalyzePAFOrSelected_triggered()
2006 {
2007     matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeOr);
2008 }
2009
2010 void MainWindow::on_actionAnalyzePAFAndNotSelected_triggered()
2011 {
2012     matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeAndNot);
2013 }
2014
2015 void MainWindow::on_actionAnalyzePAFOrNotSelected_triggered()
2016 {
2017     matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeOrNot);
2018 }
2019
2020 void MainWindow::on_actionAnalyzeDecodeAs_triggered()
2021 {
2022     QAction *da_action = qobject_cast<QAction*>(sender());
2023     bool create_new = false;
2024     if (da_action && da_action->data().toBool() == true) {
2025         create_new = true;
2026     }
2027
2028     DecodeAsDialog da_dialog(this, capture_file_.capFile(), create_new);
2029     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2030             &da_dialog, SLOT(setCaptureFile(capture_file*)));
2031     da_dialog.exec();
2032 }
2033
2034 void MainWindow::openFollowStreamDialog(follow_type_t type) {
2035     FollowStreamDialog *fsd = new FollowStreamDialog(this, type, capture_file_.capFile());
2036     connect(fsd, SIGNAL(updateFilter(QString&, bool)), this, SLOT(filterPackets(QString&, bool)));
2037     connect(fsd, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int)));
2038
2039     fsd->follow(getFilter());
2040     fsd->show();
2041 }
2042
2043 void MainWindow::on_actionAnalyzeFollowTCPStream_triggered()
2044 {
2045     openFollowStreamDialog(FOLLOW_TCP);
2046 }
2047
2048 void MainWindow::on_actionAnalyzeFollowUDPStream_triggered()
2049 {
2050     openFollowStreamDialog(FOLLOW_UDP);
2051 }
2052
2053 void MainWindow::on_actionAnalyzeFollowSSLStream_triggered()
2054 {
2055     openFollowStreamDialog(FOLLOW_SSL);
2056 }
2057
2058 void MainWindow::openSCTPAllAssocsDialog()
2059 {
2060     SCTPAllAssocsDialog *sctp_dialog = new SCTPAllAssocsDialog(this, capture_file_.capFile());
2061     connect(sctp_dialog, SIGNAL(filterPackets(QString&,bool)),
2062             this, SLOT(filterPackets(QString&,bool)));
2063     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2064             sctp_dialog, SLOT(setCaptureFile(capture_file*)));
2065     sctp_dialog->fillTable();
2066
2067     if (sctp_dialog->isMinimized() == true)
2068     {
2069         sctp_dialog->showNormal();
2070     }
2071     else
2072     {
2073         sctp_dialog->show();
2074     }
2075
2076     sctp_dialog->raise();
2077     sctp_dialog->activateWindow();
2078 }
2079
2080 void MainWindow::on_actionSCTPShowAllAssociations_triggered()
2081 {
2082     openSCTPAllAssocsDialog();
2083 }
2084
2085 void MainWindow::on_actionSCTPAnalyseThisAssociation_triggered()
2086 {
2087     SCTPAssocAnalyseDialog *sctp_analyse = new SCTPAssocAnalyseDialog(this, NULL, capture_file_.capFile());
2088     connect(sctp_analyse, SIGNAL(filterPackets(QString&,bool)),
2089             this, SLOT(filterPackets(QString&,bool)));
2090
2091     if (sctp_analyse->isMinimized() == true)
2092     {
2093         sctp_analyse->showNormal();
2094     }
2095     else
2096     {
2097         sctp_analyse->show();
2098     }
2099
2100     sctp_analyse->raise();
2101     sctp_analyse->activateWindow();
2102 }
2103
2104 void MainWindow::on_actionSCTPFilterThisAssociation_triggered()
2105 {
2106     sctp_assoc_info_t* assoc = SCTPAssocAnalyseDialog::findAssocForPacket(capture_file_.capFile());
2107     if (assoc) {
2108         QString newFilter = QString("sctp.assoc_index==%1").arg(assoc->assoc_id);
2109         assoc = NULL;
2110         emit filterPackets(newFilter, false);
2111     }
2112 }
2113
2114
2115 // Next / previous / first / last slots in packet_list
2116
2117 // Statistics Menu
2118
2119 void MainWindow::on_actionStatisticsFlowGraph_triggered()
2120 {
2121     SequenceDialog *sequence_dialog = new SequenceDialog(this, capture_file_.capFile());
2122     connect(sequence_dialog, SIGNAL(goToPacket(int)),
2123             packet_list_, SLOT(goToPacket(int)));
2124     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2125             sequence_dialog, SLOT(setCaptureFile(capture_file*)));
2126     sequence_dialog->show();
2127 }
2128
2129 void MainWindow::openTcpStreamDialog(int graph_type)
2130 {
2131     TCPStreamDialog *stream_dialog = new TCPStreamDialog(this, capture_file_.capFile(), (tcp_graph_type)graph_type);
2132     connect(stream_dialog, SIGNAL(goToPacket(int)),
2133             packet_list_, SLOT(goToPacket(int)));
2134     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2135             stream_dialog, SLOT(setCaptureFile(capture_file*)));
2136     stream_dialog->show();
2137 }
2138
2139 void MainWindow::on_actionStatisticsTcpStreamStevens_triggered()
2140 {
2141     openTcpStreamDialog(GRAPH_TSEQ_STEVENS);
2142 }
2143
2144 void MainWindow::on_actionStatisticsTcpStreamTcptrace_triggered()
2145 {
2146     openTcpStreamDialog(GRAPH_TSEQ_TCPTRACE);
2147 }
2148
2149 void MainWindow::on_actionStatisticsTcpStreamThroughput_triggered()
2150 {
2151     openTcpStreamDialog(GRAPH_THROUGHPUT);
2152 }
2153
2154 void MainWindow::on_actionStatisticsTcpStreamRoundTripTime_triggered()
2155 {
2156     openTcpStreamDialog(GRAPH_RTT);
2157 }
2158
2159 void MainWindow::on_actionStatisticsTcpStreamWindowScaling_triggered()
2160 {
2161     openTcpStreamDialog(GRAPH_WSCALE);
2162 }
2163
2164 void MainWindow::openStatisticsTreeDialog(const gchar *abbr)
2165 {
2166     StatsTreeDialog *st_dialog = new StatsTreeDialog(this, capture_file_.capFile(), abbr);
2167 //    connect(st_dialog, SIGNAL(goToPacket(int)),
2168 //            packet_list_, SLOT(goToPacket(int)));
2169     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2170             st_dialog, SLOT(setCaptureFile(capture_file*)));
2171     st_dialog->show();
2172 }
2173
2174 void MainWindow::on_actionStatistics29WestTopics_Advertisements_by_Topic_triggered()
2175 {
2176     openStatisticsTreeDialog("lbmr_topic_ads_topic");
2177 }
2178
2179 void MainWindow::on_actionStatistics29WestTopics_Advertisements_by_Source_triggered()
2180 {
2181     openStatisticsTreeDialog("lbmr_topic_ads_source");
2182 }
2183
2184 void MainWindow::on_actionStatistics29WestTopics_Advertisements_by_Transport_triggered()
2185 {
2186     openStatisticsTreeDialog("lbmr_topic_ads_transport");
2187 }
2188
2189 void MainWindow::on_actionStatistics29WestTopics_Queries_by_Topic_triggered()
2190 {
2191     openStatisticsTreeDialog("lbmr_topic_queries_topic");
2192 }
2193
2194 void MainWindow::on_actionStatistics29WestTopics_Queries_by_Receiver_triggered()
2195 {
2196     openStatisticsTreeDialog("lbmr_topic_queries_receiver");
2197 }
2198
2199 void MainWindow::on_actionStatistics29WestTopics_Wildcard_Queries_by_Pattern_triggered()
2200 {
2201     openStatisticsTreeDialog("lbmr_topic_queries_pattern");
2202 }
2203
2204 void MainWindow::on_actionStatistics29WestTopics_Wildcard_Queries_by_Receiver_triggered()
2205 {
2206     openStatisticsTreeDialog("lbmr_topic_queries_pattern_receiver");
2207 }
2208
2209 void MainWindow::on_actionStatistics29WestQueues_Advertisements_by_Queue_triggered()
2210 {
2211     openStatisticsTreeDialog("lbmr_queue_ads_queue");
2212 }
2213
2214 void MainWindow::on_actionStatistics29WestQueues_Advertisements_by_Source_triggered()
2215 {
2216     openStatisticsTreeDialog("lbmr_queue_ads_source");
2217 }
2218
2219 void MainWindow::on_actionStatistics29WestQueues_Queries_by_Queue_triggered()
2220 {
2221     openStatisticsTreeDialog("lbmr_queue_queries_queue");
2222 }
2223
2224 void MainWindow::on_actionStatistics29WestQueues_Queries_by_Receiver_triggered()
2225 {
2226     openStatisticsTreeDialog("lbmr_queue_queries_receiver");
2227 }
2228
2229 void MainWindow::on_actionStatistics29WestUIM_Streams_triggered()
2230 {
2231     LBMStreamDialog *stream_dialog = new LBMStreamDialog(this, capture_file_.capFile());
2232 //    connect(stream_dialog, SIGNAL(goToPacket(int)),
2233 //            packet_list_, SLOT(goToPacket(int)));
2234     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2235             stream_dialog, SLOT(setCaptureFile(capture_file*)));
2236     stream_dialog->show();
2237 }
2238
2239 void MainWindow::on_actionStatistics29WestUIM_Stream_Flow_Graph_triggered()
2240 {
2241     LBMUIMFlowDialog * uimflow_dialog = new LBMUIMFlowDialog(this, capture_file_.capFile());
2242     connect(uimflow_dialog, SIGNAL(goToPacket(int)),
2243             packet_list_, SLOT(goToPacket(int)));
2244     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2245             uimflow_dialog, SLOT(setCaptureFile(capture_file*)));
2246     uimflow_dialog->show();
2247 }
2248
2249 void MainWindow::on_actionStatistics29WestLBTRM_triggered()
2250 {
2251     LBMLBTRMTransportDialog * lbtrm_dialog = new LBMLBTRMTransportDialog(this, capture_file_.capFile());
2252     connect(lbtrm_dialog, SIGNAL(goToPacket(int)),
2253             packet_list_, SLOT(goToPacket(int)));
2254     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2255             lbtrm_dialog, SLOT(setCaptureFile(capture_file*)));
2256     lbtrm_dialog->show();
2257 }
2258 void MainWindow::on_actionStatistics29WestLBTRU_triggered()
2259 {
2260     LBMLBTRUTransportDialog * lbtru_dialog = new LBMLBTRUTransportDialog(this, capture_file_.capFile());
2261     connect(lbtru_dialog, SIGNAL(goToPacket(int)),
2262             packet_list_, SLOT(goToPacket(int)));
2263     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2264             lbtru_dialog, SLOT(setCaptureFile(capture_file*)));
2265     lbtru_dialog->show();
2266 }
2267
2268 void MainWindow::on_actionStatisticsANCP_triggered()
2269 {
2270     openStatisticsTreeDialog("ancp");
2271 }
2272
2273 void MainWindow::on_actionStatisticsBACappInstanceId_triggered()
2274 {
2275     openStatisticsTreeDialog("bacapp_instanceid");
2276 }
2277
2278 void MainWindow::on_actionStatisticsBACappIP_triggered()
2279 {
2280     openStatisticsTreeDialog("bacapp_ip");
2281 }
2282
2283 void MainWindow::on_actionStatisticsBACappObjectId_triggered()
2284 {
2285     openStatisticsTreeDialog("bacapp_objectid");
2286 }
2287
2288 void MainWindow::on_actionStatisticsBACappService_triggered()
2289 {
2290     openStatisticsTreeDialog("bacapp_service");
2291 }
2292
2293 void MainWindow::on_actionStatisticsCollectd_triggered()
2294 {
2295     openStatisticsTreeDialog("collectd");
2296 }
2297
2298 void MainWindow::statCommandConversations(const char *arg, void *userdata)
2299 {
2300     ConversationDialog *conv_dialog = new ConversationDialog(this, capture_file_.capFile(), GPOINTER_TO_INT(userdata), arg);
2301     connect(conv_dialog, SIGNAL(filterAction(QString&,FilterAction::Action,FilterAction::ActionType)),
2302             this, SLOT(filterAction(QString&,FilterAction::Action,FilterAction::ActionType)));
2303     connect(conv_dialog, SIGNAL(openFollowStreamDialog(follow_type_t)),
2304             this, SLOT(openFollowStreamDialog(follow_type_t)));
2305     connect(conv_dialog, SIGNAL(openTcpStreamGraph(int)),
2306             this, SLOT(openTcpStreamDialog(int)));
2307     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2308             conv_dialog, SLOT(setCaptureFile(capture_file*)));
2309     conv_dialog->show();
2310 }
2311
2312 void MainWindow::on_actionStatisticsConversations_triggered()
2313 {
2314     statCommandConversations(NULL, NULL);
2315 }
2316
2317 void MainWindow::statCommandEndpoints(const char *arg, void *userdata)
2318 {
2319     EndpointDialog *endp_dialog = new EndpointDialog(this, capture_file_.capFile(), GPOINTER_TO_INT(userdata), arg);
2320     connect(endp_dialog, SIGNAL(filterAction(QString&,FilterAction::Action,FilterAction::ActionType)),
2321             this, SLOT(filterAction(QString&,FilterAction::Action,FilterAction::ActionType)));
2322     connect(endp_dialog, SIGNAL(openFollowStreamDialog(follow_type_t)),
2323             this, SLOT(openFollowStreamDialog(follow_type_t)));
2324     connect(endp_dialog, SIGNAL(openTcpStreamGraph(int)),
2325             this, SLOT(openTcpStreamDialog(int)));
2326     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2327             endp_dialog, SLOT(setCaptureFile(capture_file*)));
2328     endp_dialog->show();
2329 }
2330
2331 void MainWindow::on_actionStatisticsEndpoints_triggered()
2332 {
2333     statCommandEndpoints(NULL, NULL);
2334 }
2335
2336 void MainWindow::on_actionStatisticsHART_IP_triggered()
2337 {
2338     openStatisticsTreeDialog("hart_ip");
2339 }
2340
2341 void MainWindow::on_actionStatisticsHTTPPacketCounter_triggered()
2342 {
2343     openStatisticsTreeDialog("http");
2344 }
2345
2346 void MainWindow::on_actionStatisticsHTTPRequests_triggered()
2347 {
2348     openStatisticsTreeDialog("http_req");
2349 }
2350
2351 void MainWindow::on_actionStatisticsHTTPLoadDistribution_triggered()
2352 {
2353     openStatisticsTreeDialog("http_srv");
2354 }
2355
2356 void MainWindow::on_actionStatisticsPacketLen_triggered()
2357 {
2358     openStatisticsTreeDialog("plen");
2359 }
2360
2361 void MainWindow::statCommandIOGraph(const char *arg, void *userdata)
2362 {
2363     Q_UNUSED(arg);
2364     Q_UNUSED(userdata);
2365     IOGraphDialog *iog_dialog = new IOGraphDialog(this, capture_file_.capFile());
2366     connect(iog_dialog, SIGNAL(goToPacket(int)), packet_list_, SLOT(goToPacket(int)));
2367     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2368             iog_dialog, SLOT(setCaptureFile(capture_file*)));
2369     iog_dialog->show();
2370 }
2371
2372 void MainWindow::on_actionStatisticsIOGraph_triggered()
2373 {
2374     statCommandIOGraph(NULL, NULL);
2375 }
2376 void MainWindow::on_actionStatisticsSametime_triggered()
2377 {
2378     openStatisticsTreeDialog("sametime");
2379 }
2380
2381 // Telephony Menu
2382
2383 void MainWindow::openVoipCallsDialog(bool all_flows)
2384 {
2385     VoipCallsDialog *voip_calls_dialog = new VoipCallsDialog(this, capture_file_.capFile(), all_flows);
2386     connect(voip_calls_dialog, SIGNAL(goToPacket(int)),
2387             packet_list_, SLOT(goToPacket(int)));
2388     connect(voip_calls_dialog, SIGNAL(updateFilter(QString&, bool)),
2389             this, SLOT(filterPackets(QString&, bool)));
2390     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2391             voip_calls_dialog, SLOT(setCaptureFile(capture_file*)));
2392     voip_calls_dialog->show();
2393 }
2394
2395 void MainWindow::on_actionTelephonyVoipCalls_triggered()
2396 {
2397     openVoipCallsDialog();
2398 }
2399
2400 void MainWindow::on_actionTelephonyISUPMessages_triggered()
2401 {
2402     openStatisticsTreeDialog("isup_msg");
2403 }
2404
2405 void MainWindow::on_actionTelephonyRTSPPacketCounter_triggered()
2406 {
2407     openStatisticsTreeDialog("rtsp");
2408 }
2409
2410 void MainWindow::on_actionTelephonySMPPOperations_triggered()
2411 {
2412     openStatisticsTreeDialog("smpp_commands");
2413 }
2414
2415 void MainWindow::on_actionTelephonyUCPMessages_triggered()
2416 {
2417     openStatisticsTreeDialog("ucp_messages");
2418 }
2419
2420 void MainWindow::on_actionTelephonySipFlows_triggered()
2421 {
2422     openVoipCallsDialog(true);
2423 }
2424
2425 // Help Menu
2426 void MainWindow::on_actionHelpContents_triggered() {
2427
2428     wsApp->helpTopicAction(HELP_CONTENT);
2429 }
2430
2431 void MainWindow::on_actionHelpMPWireshark_triggered() {
2432
2433     wsApp->helpTopicAction(LOCALPAGE_MAN_WIRESHARK);
2434 }
2435
2436 void MainWindow::on_actionHelpMPWireshark_Filter_triggered() {
2437     wsApp->helpTopicAction(LOCALPAGE_MAN_WIRESHARK_FILTER);
2438 }
2439
2440 void MainWindow::on_actionHelpMPCapinfos_triggered() {
2441     wsApp->helpTopicAction(LOCALPAGE_MAN_CAPINFOS);
2442 }
2443
2444 void MainWindow::on_actionHelpMPDumpcap_triggered() {
2445     wsApp->helpTopicAction(LOCALPAGE_MAN_DUMPCAP);
2446 }
2447
2448 void MainWindow::on_actionHelpMPEditcap_triggered() {
2449     wsApp->helpTopicAction(LOCALPAGE_MAN_EDITCAP);
2450 }
2451
2452 void MainWindow::on_actionHelpMPMergecap_triggered() {
2453     wsApp->helpTopicAction(LOCALPAGE_MAN_MERGECAP);
2454 }
2455
2456 void MainWindow::on_actionHelpMPRawShark_triggered() {
2457     wsApp->helpTopicAction(LOCALPAGE_MAN_RAWSHARK);
2458 }
2459
2460 void MainWindow::on_actionHelpMPReordercap_triggered() {
2461     wsApp->helpTopicAction(LOCALPAGE_MAN_REORDERCAP);
2462 }
2463
2464  void MainWindow::on_actionHelpMPText2cap_triggered() {
2465     wsApp->helpTopicAction(LOCALPAGE_MAN_TEXT2PCAP);
2466 }
2467
2468 void MainWindow::on_actionHelpMPTShark_triggered() {
2469     wsApp->helpTopicAction(LOCALPAGE_MAN_TSHARK);
2470 }
2471
2472 void MainWindow::on_actionHelpWebsite_triggered() {
2473
2474     wsApp->helpTopicAction(ONLINEPAGE_HOME);
2475 }
2476
2477 void MainWindow::on_actionHelpFAQ_triggered() {
2478
2479     wsApp->helpTopicAction(ONLINEPAGE_FAQ);
2480 }
2481
2482 void MainWindow::on_actionHelpAsk_triggered() {
2483
2484     wsApp->helpTopicAction(ONLINEPAGE_ASK);
2485 }
2486
2487 void MainWindow::on_actionHelpDownloads_triggered() {
2488
2489     wsApp->helpTopicAction(ONLINEPAGE_DOWNLOAD);
2490 }
2491
2492 void MainWindow::on_actionHelpWiki_triggered() {
2493
2494     wsApp->helpTopicAction(ONLINEPAGE_WIKI);
2495 }
2496
2497 void MainWindow::on_actionHelpSampleCaptures_triggered() {
2498
2499     wsApp->helpTopicAction(ONLINEPAGE_SAMPLE_FILES);
2500 }
2501
2502 #ifdef HAVE_SOFTWARE_UPDATE
2503 void MainWindow::checkForUpdates()
2504 {
2505     software_update_check();
2506 }
2507 #endif
2508
2509 void MainWindow::on_actionHelpAbout_triggered()
2510 {
2511     AboutDialog *about_dialog = new AboutDialog(this);
2512
2513     if (about_dialog->isMinimized() == true)
2514     {
2515         about_dialog->showNormal();
2516     }
2517     else
2518     {
2519         about_dialog->show();
2520     }
2521
2522     about_dialog->raise();
2523     about_dialog->activateWindow();
2524 }
2525
2526 void MainWindow::on_actionGoGoToPacket_triggered() {
2527     if (packet_list_->model()->rowCount() < 1) {
2528         return;
2529     }
2530     previous_focus_ = wsApp->focusWidget();
2531     connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus()));
2532
2533     main_ui_->searchFrame->animatedHide();
2534     if (main_ui_->goToFrame->isVisible()) {
2535         main_ui_->goToFrame->animatedHide();
2536     } else {
2537         main_ui_->goToFrame->animatedShow();
2538     }
2539     main_ui_->goToLineEdit->setFocus();
2540 }
2541
2542 void MainWindow::resetPreviousFocus() {
2543     previous_focus_ = NULL;
2544 }
2545
2546 void MainWindow::on_goToCancel_clicked()
2547 {
2548     main_ui_->goToFrame->animatedHide();
2549     if (previous_focus_) {
2550         disconnect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus()));
2551         previous_focus_->setFocus();
2552         resetPreviousFocus();
2553     }
2554 }
2555
2556 void MainWindow::on_goToGo_clicked()
2557 {
2558     int packet_num = main_ui_->goToLineEdit->text().toInt();
2559
2560     if (packet_num > 0) {
2561         packet_list_->goToPacket(packet_num);
2562     }
2563     on_goToCancel_clicked();
2564 }
2565
2566 void MainWindow::on_goToLineEdit_returnPressed()
2567 {
2568     on_goToGo_clicked();
2569 }
2570
2571 void MainWindow::on_actionCaptureStart_triggered()
2572 {
2573 //#ifdef HAVE_AIRPCAP
2574 //  airpcap_if_active = airpcap_if_selected;
2575 //  if (airpcap_if_active)
2576 //    airpcap_set_toolbar_start_capture(airpcap_if_active);
2577 //#endif
2578
2579 //  if (cap_open_w) {
2580 //    /*
2581 //     * There's an options dialog; get the values from it and close it.
2582 //     */
2583 //    gboolean success;
2584
2585 //    /* Determine if "capture start" while building of the "capture options" window */
2586 //    /*  is in progress. If so, ignore the "capture start.                          */
2587 //    /* XXX: Would it be better/cleaner for the "capture options" window code to    */
2588 //    /*      disable the capture start button temporarily ?                         */
2589 //    if (cap_open_complete == FALSE) {
2590 //      return;  /* Building options window: ignore "capture start" */
2591 //    }
2592 //    success = capture_dlg_prep(cap_open_w);
2593 //    window_destroy(GTK_WIDGET(cap_open_w));
2594 //    if (!success)
2595 //      return;   /* error in options dialog */
2596 //  }
2597
2598     main_ui_->mainStack->setCurrentWidget(&master_split_);
2599
2600 #ifdef HAVE_LIBPCAP
2601     if (global_capture_opts.num_selected == 0) {
2602         QString err_msg = tr("No Interface Selected");
2603         main_ui_->statusBar->pushTemporaryStatus(err_msg);
2604         return;
2605     }
2606
2607     /* XXX - will closing this remove a temporary file? */
2608     if (testCaptureFileClose(FALSE, *new QString(" before starting a new capture")))
2609         startCapture();
2610 #endif // HAVE_LIBPCAP
2611 }
2612
2613 void MainWindow::on_actionCaptureStop_triggered()
2614 {
2615     stopCapture();
2616 }
2617
2618 void MainWindow::on_actionStatisticsCaptureFileProperties_triggered()
2619 {
2620     CaptureFilePropertiesDialog *capture_file_properties_dialog = new CaptureFilePropertiesDialog(this, capture_file_.capFile());
2621     connect(capture_file_properties_dialog, SIGNAL(captureCommentChanged()),
2622             this, SLOT(updateForUnsavedChanges()));
2623     connect(this, SIGNAL(setCaptureFile(capture_file*)),
2624             capture_file_properties_dialog, SLOT(setCaptureFile(capture_file*)));
2625     capture_file_properties_dialog->show();
2626 }
2627
2628 #ifdef HAVE_LIBPCAP
2629 void MainWindow::on_actionCaptureOptions_triggered()
2630 {
2631     connect(&capture_interfaces_dialog_, SIGNAL(setFilterValid(bool)), this, SLOT(startInterfaceCapture(bool)));
2632     capture_interfaces_dialog_.SetTab(0);
2633     capture_interfaces_dialog_.updateInterfaces();
2634
2635     if (capture_interfaces_dialog_.isMinimized() == true)
2636     {
2637         capture_interfaces_dialog_.showNormal();
2638     }
2639     else
2640     {
2641         capture_interfaces_dialog_.show();
2642     }
2643
2644     capture_interfaces_dialog_.raise();
2645     capture_interfaces_dialog_.activateWindow();
2646 }
2647
2648 void MainWindow::on_actionCaptureRefreshInterfaces_triggered()
2649 {
2650     wsApp->refreshLocalInterfaces();
2651 }
2652 #endif
2653
2654
2655 /*
2656  * Editor modelines
2657  *
2658  * Local Variables:
2659  * c-basic-offset: 4
2660  * tab-width: 8
2661  * indent-tabs-mode: nil
2662  * End:
2663  *
2664  * ex: set shiftwidth=4 tabstop=8 expandtab:
2665  * :indentSize=4:tabSize=8:noTabs=true:
2666  */