5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #include "main_window.h"
35 #include "ui_main_window.h"
39 #include <epan/filesystem.h>
40 #include <epan/prefs.h>
49 #include "capture-pcap-util.h"
50 #include "capture_ui_utils.h"
53 #include "wsutil/file_util.h"
55 #include "ui/alert_box.h"
56 #include "ui/capture_globals.h"
57 #include "ui/help_url.h"
58 #include "ui/main_statusbar.h"
59 #include "ui/ssl_key_export.h"
61 #include "wireshark_application.h"
62 #include "capture_file_dialog.h"
63 #include "export_object_dialog.h"
64 #include "print_dialog.h"
66 #include <QMessageBox>
75 void MainWindow::openCaptureFile(QString &cf_path, QString &display_filter)
77 QString file_name = "";
78 dfilter_t *rfcode = NULL;
81 testCaptureFileClose(false);
85 if (cf_path.isEmpty()) {
86 CaptureFileDialog open_dlg(this, cap_file_, display_filter);
88 switch (prefs.gui_fileopen_style) {
90 case FO_STYLE_LAST_OPENED:
91 /* The user has specified that we should start out in the last directory
92 we looked in. If we've already opened a file, use its containing
93 directory, if we could determine it, as the directory, otherwise
94 use the "last opened" directory saved in the preferences file if
96 /* This is now the default behaviour in file_selection_new() */
99 case FO_STYLE_SPECIFIED:
100 /* The user has specified that we should always start out in a
101 specified directory; if they've specified that directory,
102 start out by showing the files in that dir. */
103 if (prefs.gui_fileopen_dir[0] != '\0')
104 open_dlg.setDirectory(prefs.gui_fileopen_dir);
108 if (open_dlg.open(file_name)) {
109 if (dfilter_compile(display_filter.toUtf8().constData(), &rfcode)) {
110 cf_set_rfcode(&cfile, rfcode);
112 /* Not valid. Tell the user, and go back and run the file
113 selection box again once they dismiss the alert. */
114 //bad_dfilter_alert_box(top_level, display_filter->str);
115 QMessageBox::warning(this, tr("Invalid Display Filter"),
116 QString("The filter expression ") +
118 QString(" isn't a valid display filter. (") +
119 dfilter_error_msg + QString(")."),
129 /* Try to open the capture file. */
131 if (cf_open(&cfile, cf_path.toUtf8().constData(), FALSE, &err) != CF_OK) {
132 /* We couldn't open it; don't dismiss the open dialog box,
133 just leave it around so that the user can, after they
134 dismiss the alert box popped up for the open error,
138 dfilter_free(rfcode);
143 switch (cf_read(&cfile, FALSE)) {
147 /* Just because we got an error, that doesn't mean we were unable
148 to read any of the file; we handle what we could get from the
152 case CF_READ_ABORTED:
153 /* The user bailed out of re-reading the capture file; the
154 capture file has been closed - just free the capture file name
155 string and return (without changing the last containing
162 // get_dirname overwrites its path. Hopefully this isn't a problem.
163 wsApp->setLastOpenDir(get_dirname(cf_path.toUtf8().data()));
164 df_combo_box_->setEditText(display_filter);
166 main_ui_->statusBar->showExpert();
169 void MainWindow::filterPackets(QString& new_filter, bool force)
171 cf_status_t cf_status;
173 cf_status = cf_filter_packets(&cfile, new_filter.toUtf8().data(), force);
175 if (cf_status == CF_OK) {
176 emit displayFilterSuccess(true);
177 if (new_filter.length() > 0) {
178 if (df_combo_box_->findText(new_filter) < 0) {
179 df_combo_box_->insertItem(0, new_filter);
183 emit displayFilterSuccess(false);
190 void MainWindow::captureCapturePrepared(capture_options *capture_opts) {
191 qDebug() << "FIX captureCapturePrepared";
192 // main_capture_set_main_window_title(capture_opts);
194 // if(icon_list == NULL) {
195 // icon_list = icon_list_create(wsiconcap16_xpm, wsiconcap32_xpm, wsiconcap48_xpm, NULL);
197 // gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
199 /* Disable menu items that make no sense if you're currently running
201 setForCaptureInProgress(true);
202 // set_capture_if_dialog_for_capture_in_progress(TRUE);
204 // /* Don't set up main window for a capture file. */
205 // main_set_for_capture_file(FALSE);
206 main_ui_->mainStack->setCurrentWidget(packet_splitter_);
207 cap_file_ = (capture_file *) capture_opts->cf;
209 void MainWindow::captureCaptureUpdateStarted(capture_options *capture_opts) {
210 Q_UNUSED(capture_opts);
212 setForCaptureInProgress(true);
213 setForCapturedPackets(true);
215 void MainWindow::captureCaptureUpdateFinished(capture_options *capture_opts) {
216 Q_UNUSED(capture_opts);
218 /* The capture isn't stopping any more - it's stopped. */
219 capture_stopping_ = false;
221 /* Update the main window as appropriate */
222 updateForUnsavedChanges();
224 /* Enable menu items that make sense if you're not currently running
226 setForCaptureInProgress(false);
229 void MainWindow::captureCaptureFixedStarted(capture_options *capture_opts) {
230 Q_UNUSED(capture_opts);
231 qDebug() << "captureCaptureFixedStarted";
233 void MainWindow::captureCaptureFixedFinished(capture_options *capture_opts) {
234 Q_UNUSED(capture_opts);
235 qDebug() << "captureCaptureFixedFinished";
237 /* The capture isn't stopping any more - it's stopped. */
238 capture_stopping_ = false;
240 /* Enable menu items that make sense if you're not currently running
242 setForCaptureInProgress(false);
245 void MainWindow::captureCaptureStopping(capture_options *capture_opts) {
246 Q_UNUSED(capture_opts);
248 capture_stopping_ = true;
249 setMenusForCaptureStopping();
251 void MainWindow::captureCaptureFailed(capture_options *capture_opts) {
252 Q_UNUSED(capture_opts);
253 qDebug() << "captureCaptureFailed";
254 /* Capture isn't stopping any more. */
255 capture_stopping_ = false;
257 setForCaptureInProgress(false);
259 #endif // HAVE_LIBPCAP
262 // Callbacks from cfile.c via WiresharkApplication::captureFileCallback
264 void MainWindow::captureFileOpened(const capture_file *cf) {
265 if (cf->window != this) return;
266 cap_file_ = (capture_file *) cf;
268 file_set_dialog_.fileOpened(cf);
269 setMenusForFileSet(true);
270 emit setCaptureFile(cap_file_);
273 void MainWindow::captureFileReadStarted(const capture_file *cf) {
274 if (cf != cap_file_) return;
275 // tap_param_dlg_update();
277 /* Set up main window for a capture file. */
278 // main_set_for_capture_file(TRUE);
280 main_ui_->statusBar->popFileStatus();
281 QString msg = QString(tr("Loading: %1")).arg(get_basename(cf->filename));
282 main_ui_->statusBar->pushFileStatus(msg);
283 main_ui_->mainStack->setCurrentWidget(packet_splitter_);
284 WiresharkApplication::processEvents();
287 void MainWindow::captureFileReadFinished(const capture_file *cf) {
288 if (cf != cap_file_) return;
292 // if (!cf->is_tempfile && cf->filename) {
293 // /* Add this filename to the list of recent files in the "Recent Files" submenu */
294 // add_menu_recent_capture_file(cf->filename);
296 // /* Remember folder for next Open dialog and save it in recent */
297 // dir_path = get_dirname(g_strdup(cf->filename));
298 // wsApp->setLastOpenDir(dir_path);
301 // set_display_filename(cf);
303 /* Update the appropriate parts of the main window. */
304 updateForUnsavedChanges();
306 // /* Enable menu items that make sense if you have some captured packets. */
307 setForCapturedPackets(true);
309 main_ui_->statusBar->popFileStatus();
310 QString msg = QString().sprintf("%s", get_basename(cf->filename));
311 main_ui_->statusBar->pushFileStatus(msg);
314 void MainWindow::captureFileClosing(const capture_file *cf) {
315 if (cf != cap_file_) return;
317 setMenusForCaptureFile(true);
318 setForCapturedPackets(false);
319 setForCaptureInProgress(false);
321 // Reset expert info indicator
322 main_ui_->statusBar->hideExpert();
323 // gtk_widget_show(expert_info_none);
324 emit setCaptureFile(NULL);
327 void MainWindow::captureFileClosed(const capture_file *cf) {
328 if (cf != cap_file_) return;
329 packets_bar_update();
331 file_set_dialog_.fileClosed();
332 setMenusForFileSet(false);
334 // Reset expert info indicator
335 main_ui_->statusBar->hideExpert();
337 main_ui_->statusBar->popFileStatus();
340 setMenusForSelectedTreeRow();
347 // ui/gtk/capture_dlg.c:start_capture_confirmed
349 void MainWindow::startCapture() {
350 interface_options interface_opts;
353 /* did the user ever select a capture interface before? */
354 if(global_capture_opts.num_selected == 0) {
355 QString msg = QString("No interface selected");
356 main_ui_->statusBar->pushTemporaryStatus(msg);
360 /* XXX - we might need to init other pref data as well... */
361 // main_auto_scroll_live_changed(auto_scroll_live);
363 /* XXX - can this ever happen? */
364 if (global_capture_opts.state != CAPTURE_STOPPED)
367 /* close the currently loaded capture file */
368 cf_close((capture_file *) global_capture_opts.cf);
370 /* Copy the selected interfaces to the set of interfaces to use for
372 collect_ifaces(&global_capture_opts);
375 if (capture_start(&global_capture_opts)) {
376 /* The capture succeeded, which means the capture filter syntax is
377 valid; add this capture filter to the recent capture filter list. */
378 for (i = 0; i < global_capture_opts.ifaces->len; i++) {
379 interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
380 if (interface_opts.cfilter) {
381 // cfilter_combo_add_recent(interface_opts.cfilter);
389 // Copied from ui/gtk/gui_utils.c
390 void MainWindow::pipeTimeout() {
394 gboolean result, result1;
399 /* try to read data from the pipe only 5 times, to avoid blocking */
400 while(iterations < 5) {
401 /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
403 /* Oddly enough although Named pipes don't work on win9x,
404 PeekNamedPipe does !!! */
405 handle = (HANDLE) _get_osfhandle (pipe_source_);
406 result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
408 /* Get the child process exit status */
409 result1 = GetExitCodeProcess((HANDLE)*(pipe_child_process_),
412 /* If the Peek returned an error, or there are bytes to be read
413 or the childwatcher thread has terminated then call the normal
415 if (!result || avail > 0 || childstatus != STILL_ACTIVE) {
417 /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
419 /* And call the real handler */
420 if (!pipe_input_cb_(pipe_source_, pipe_user_data_)) {
421 g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: input pipe closed, iterations: %u", iterations);
422 /* pipe closed, return false so that the old timer is not run again */
428 /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
429 /* No data, stop now */
438 void MainWindow::pipeActivated(int source) {
442 g_assert(source == pipe_source_);
444 pipe_notifier_->setEnabled(false);
445 if (pipe_input_cb_(pipe_source_, pipe_user_data_)) {
446 pipe_notifier_->setEnabled(true);
448 delete pipe_notifier_;
453 void MainWindow::pipeNotifierDestroyed() {
457 pipe_notifier_ = NULL;
461 void MainWindow::stopCapture() {
462 //#ifdef HAVE_AIRPCAP
463 // if (airpcap_if_active)
464 // airpcap_set_toolbar_stop_capture(airpcap_if_active);
467 capture_stop(&global_capture_opts);
470 // XXX - Copied from ui/gtk/menus.c
473 * Add the capture filename (with an absolute path) to the "Recent Files" menu.
475 * @param cf_name Absolute path to the file.
476 * @param first Prepend the filename if true, otherwise append it. Default is false (append).
478 // XXX - We should probably create a RecentFile class.
479 void MainWindow::updateRecentFiles() {
481 QMenu *recentMenu = main_ui_->menuOpenRecentCaptureFile;
482 QString action_cf_name;
490 /* Iterate through the actions in menuOpenRecentCaptureFile,
491 * removing special items, a maybe duplicate entry and every item above count_max */
492 int shortcut = Qt::Key_0;
493 foreach (recent_item_status *ri, wsApp->recentItems()) {
495 ra = new QAction(recentMenu);
496 ra->setData(ri->filename);
497 // XXX - Needs get_recent_item_status or equivalent
498 ra->setEnabled(ri->accessible);
499 recentMenu->insertAction(NULL, ra);
500 action_cf_name = ra->data().toString();
501 if (shortcut <= Qt::Key_9) {
502 ra->setShortcut(Qt::META | shortcut);
505 ra->setText(action_cf_name);
506 connect(ra, SIGNAL(triggered()), this, SLOT(recentActionTriggered()));
509 if (recentMenu->actions().count() > 0) {
510 // Separator + "Clear"
511 // XXX - Do we really need this?
512 ra = new QAction(recentMenu);
513 ra->setSeparator(true);
514 recentMenu->insertAction(NULL, ra);
516 ra = new QAction(recentMenu);
517 ra->setText(tr("Clear Menu"));
518 recentMenu->insertAction(NULL, ra);
519 connect(ra, SIGNAL(triggered()), wsApp, SLOT(clearRecentItems()));
521 if (main_ui_->actionDummyNoFilesFound) {
522 recentMenu->addAction(main_ui_->actionDummyNoFilesFound);
527 void MainWindow::recentActionTriggered() {
528 QAction *ra = qobject_cast<QAction*>(sender());
531 QString cfPath = ra->data().toString();
532 openCaptureFile(cfPath);
536 void MainWindow::setMenusForSelectedTreeRow(field_info *fi) {
537 //gboolean properties;
540 // XXX Add commented items below
543 cap_file_->finfo_selected = fi;
546 if (cap_file_ != NULL && fi != NULL) {
548 header_field_info *hfinfo = fi->hfinfo;
552 if (hfinfo->parent == -1) {
553 abbrev = hfinfo->abbrev;
554 id = (hfinfo->type == FT_PROTOCOL) ? proto_get_id((protocol_t *)hfinfo->strings) : -1;
556 abbrev = proto_registrar_get_abbrev(hfinfo->parent);
559 properties = prefs_is_registered_protocol(abbrev);
561 bool can_match_selected = proto_can_match_selected(cap_file_->finfo_selected, cap_file_->edt);
562 // set_menu_sensitivity(ui_manager_tree_view_menu,
563 // "/TreeViewPopup/GotoCorrespondingPacket", hfinfo->type == FT_FRAMENUM);
564 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/Copy",
567 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ApplyasColumn",
568 // hfinfo->type != FT_NONE);
569 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ColorizewithFilter",
570 // proto_can_match_selected(cf->finfo_selected, cf->edt));
571 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ProtocolPreferences",
573 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/DisableProtocol",
574 // (id == -1) ? FALSE : proto_can_toggle_protocol(id));
575 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandSubtrees",
576 // cf->finfo_selected->tree_type != -1);
577 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/WikiProtocolPage",
578 // (id == -1) ? FALSE : TRUE);
579 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FilterFieldReference",
580 // (id == -1) ? FALSE : TRUE);
581 // set_menu_sensitivity(ui_manager_main_menubar,
582 main_ui_->actionFileExportPacketBytes->setEnabled(true);
584 // set_menu_sensitivity(ui_manager_main_menubar,
585 // "/Menubar/GoMenu/GotoCorrespondingPacket", hfinfo->type == FT_FRAMENUM);
587 main_ui_->actionEditCopyDescription->setEnabled(can_match_selected);
588 main_ui_->actionEditCopyFieldName->setEnabled(can_match_selected);
589 main_ui_->actionEditCopyValue->setEnabled(can_match_selected);
590 main_ui_->actionEditCopyAsFilter->setEnabled(can_match_selected);
591 // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Description",
592 // proto_can_match_selected(cf->finfo_selected, cf->edt));
593 // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Fieldname",
594 // proto_can_match_selected(cf->finfo_selected, cf->edt));
595 // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Value",
596 // proto_can_match_selected(cf->finfo_selected, cf->edt));
597 // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/AsFilter",
598 // proto_can_match_selected(cf->finfo_selected, cf->edt));
600 // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/ApplyasColumn",
601 // hfinfo->type != FT_NONE);
602 main_ui_->actionAnalyzeAAFSelected->setEnabled(can_match_selected);
603 main_ui_->actionAnalyzeAAFNotSelected->setEnabled(can_match_selected);
604 main_ui_->actionAnalyzeAAFAndSelected->setEnabled(can_match_selected);
605 main_ui_->actionAnalyzeAAFOrSelected->setEnabled(can_match_selected);
606 main_ui_->actionAnalyzeAAFAndNotSelected->setEnabled(can_match_selected);
607 main_ui_->actionAnalyzeAAFOrNotSelected->setEnabled(can_match_selected);
609 main_ui_->actionAnalyzePAFSelected->setEnabled(can_match_selected);
610 main_ui_->actionAnalyzePAFNotSelected->setEnabled(can_match_selected);
611 main_ui_->actionAnalyzePAFAndSelected->setEnabled(can_match_selected);
612 main_ui_->actionAnalyzePAFOrSelected->setEnabled(can_match_selected);
613 main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(can_match_selected);
614 main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(can_match_selected);
616 main_ui_->actionViewExpandSubtrees->setEnabled(cap_file_->finfo_selected->tree_type != -1);
617 // prev_abbrev = g_object_get_data(G_OBJECT(ui_manager_tree_view_menu), "menu_abbrev");
618 // if (!prev_abbrev || (strcmp (prev_abbrev, abbrev) != 0)) {
619 // /* No previous protocol or protocol changed - update Protocol Preferences menu */
620 // module_t *prefs_module_p = prefs_find_module(abbrev);
621 // rebuild_protocol_prefs_menu (prefs_module_p, properties);
623 // g_object_set_data(G_OBJECT(ui_manager_tree_view_menu), "menu_abbrev", g_strdup(abbrev));
624 // g_free (prev_abbrev);
627 // set_menu_sensitivity(ui_manager_tree_view_menu,
628 // "/TreeViewPopup/GotoCorrespondingPacket", FALSE);
629 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/Copy", FALSE);
630 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ApplyasColumn", FALSE);
631 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ApplyAsFilter", FALSE);
632 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/PrepareaFilter", FALSE);
633 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ColorizewithFilter", FALSE);
634 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ProtocolPreferences",
636 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/DisableProtocol", FALSE);
637 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandSubtrees", FALSE);
638 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/WikiProtocolPage",
640 // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FilterFieldReference",
642 main_ui_->actionFileExportPacketBytes->setEnabled(false);
643 // set_menu_sensitivity(ui_manager_main_menubar,
644 // "/Menubar/GoMenu/GotoCorrespondingPacket", FALSE);
645 main_ui_->actionEditCopyDescription->setEnabled(false);
646 main_ui_->actionEditCopyFieldName->setEnabled(false);
647 main_ui_->actionEditCopyValue->setEnabled(false);
648 main_ui_->actionEditCopyAsFilter->setEnabled(false);
649 // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/ApplyasColumn", FALSE);
651 main_ui_->actionAnalyzeAAFSelected->setEnabled(false);
652 main_ui_->actionAnalyzeAAFNotSelected->setEnabled(false);
653 main_ui_->actionAnalyzeAAFAndSelected->setEnabled(false);
654 main_ui_->actionAnalyzeAAFOrSelected->setEnabled(false);
655 main_ui_->actionAnalyzeAAFAndNotSelected->setEnabled(false);
656 main_ui_->actionAnalyzeAAFOrNotSelected->setEnabled(false);
658 main_ui_->actionAnalyzePAFSelected->setEnabled(false);
659 main_ui_->actionAnalyzePAFNotSelected->setEnabled(false);
660 main_ui_->actionAnalyzePAFAndSelected->setEnabled(false);
661 main_ui_->actionAnalyzePAFOrSelected->setEnabled(false);
662 main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(false);
663 main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(false);
665 main_ui_->actionViewExpandSubtrees->setEnabled(false);
669 void MainWindow::interfaceSelectionChanged()
671 if (global_capture_opts.num_selected > 0) {
672 main_ui_->actionStartCapture->setEnabled(true);
674 main_ui_->actionStartCapture->setEnabled(false);
681 void MainWindow::on_actionFileOpen_triggered()
686 void MainWindow::on_actionFileMerge_triggered()
691 void MainWindow::on_actionFileImport_triggered()
696 void MainWindow::on_actionFileClose_triggered() {
697 if (testCaptureFileClose())
698 main_ui_->mainStack->setCurrentWidget(main_welcome_);
701 void MainWindow::on_actionFileSave_triggered()
703 saveCaptureFile(cap_file_, FALSE);
706 void MainWindow::on_actionFileSaveAs_triggered()
708 saveAsCaptureFile(cap_file_, FALSE, TRUE);
711 void MainWindow::on_actionFileSetListFiles_triggered()
713 file_set_dialog_.exec();
716 void MainWindow::on_actionFileSetNextFile_triggered()
718 fileset_entry *entry = fileset_get_next();
721 QString new_cf_path = entry->fullname;
722 openCaptureFile(new_cf_path);
726 void MainWindow::on_actionFileSetPreviousFile_triggered()
728 fileset_entry *entry = fileset_get_previous();
731 QString new_cf_path = entry->fullname;
732 openCaptureFile(new_cf_path);
736 void MainWindow::on_actionFileExportPackets_triggered()
738 exportSelectedPackets();
741 void MainWindow::on_actionFileExportAsPlainText_triggered()
743 exportDissections(export_type_text);
746 void MainWindow::on_actionFileExportAsCSV_triggered()
748 exportDissections(export_type_csv);
751 void MainWindow::on_actionFileExportAsCArrays_triggered()
753 exportDissections(export_type_carrays);
756 void MainWindow::on_actionFileExportAsPSML_triggered()
758 exportDissections(export_type_psml);
761 void MainWindow::on_actionFileExportAsPDML_triggered()
763 exportDissections(export_type_pdml);
766 void MainWindow::on_actionFileExportPacketBytes_triggered()
770 if (!cap_file_ || !cap_file_->finfo_selected) return;
772 file_name = QFileDialog::getSaveFileName(this,
773 tr("Wireshark: Export Selected Packet Bytes"),
774 wsApp->lastOpenDir().canonicalPath(),
775 tr("Raw data (*.bin *.dat *.raw);;Any File (*.*)")
778 if (file_name.length() > 0) {
779 const guint8 *data_p;
782 data_p = tvb_get_ptr(cap_file_->finfo_selected->ds_tvb, 0, -1) +
783 cap_file_->finfo_selected->start;
784 fd = ws_open(file_name.toUtf8().constData(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
786 open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE);
789 if (write(fd, data_p, cfile.finfo_selected->length) < 0) {
790 write_failure_alert_box(file_name.toUtf8().constData(), errno);
794 if (::close(fd) < 0) {
795 write_failure_alert_box(file_name.toUtf8().constData(), errno);
799 /* Save the directory name for future file dialogs. */
800 wsApp->setLastOpenDir(&file_name);
804 void MainWindow::on_actionFileExportSSLSessionKeys_triggered()
810 keylist_len = ssl_session_key_count();
811 /* don't show up the dialog, if no data has to be saved */
812 if (keylist_len < 1) {
813 /* shouldn't happen as the menu item should have been greyed out */
814 QMessageBox::warning(
817 tr("There are no SSL Session Keys to save."),
823 save_title.append("Wireshark: Export SSL Session Keys (%1 key%2").
824 arg(keylist_len).arg(plurality(keylist_len, "", "s"));
825 file_name = QFileDialog::getSaveFileName(this,
827 wsApp->lastOpenDir().canonicalPath(),
828 tr("SSL Session Keys (*.keys *.txt);;Any File (*.*)")
830 if (file_name.length() > 0) {
834 keylist = ssl_export_sessions();
835 fd = ws_open(file_name.toUtf8().constData(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
837 open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE);
842 * Thanks, Microsoft, for not using size_t for the third argument to
843 * _write(). Presumably this string will be <= 4GiB long....
845 if (ws_write(fd, keylist, (unsigned int)strlen(keylist)) < 0) {
846 write_failure_alert_box(file_name.toUtf8().constData(), errno);
851 if (::close(fd) < 0) {
852 write_failure_alert_box(file_name.toUtf8().constData(), errno);
857 /* Save the directory name for future file dialogs. */
858 wsApp->setLastOpenDir(&file_name);
863 void MainWindow::on_actionFileExportObjectsDICOM_triggered()
865 new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Dicom);
868 void MainWindow::on_actionFileExportObjectsHTTP_triggered()
870 new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Http);
873 void MainWindow::on_actionFileExportObjectsSMB_triggered()
875 new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Smb);
878 void MainWindow::on_actionFilePrint_triggered()
880 PrintDialog pdlg(this, cap_file_);
887 // XXX This should probably be somewhere else.
888 void MainWindow::actionEditCopyTriggered(MainWindow::CopySelected selection_type)
890 char label_str[ITEM_LABEL_LENGTH];
893 if (!cap_file_) return;
895 switch(selection_type) {
896 case CopySelectedDescription:
897 if (cap_file_->finfo_selected->rep &&
898 strlen (cap_file_->finfo_selected->rep->representation) > 0) {
899 clip.append(cap_file_->finfo_selected->rep->representation);
902 case CopySelectedFieldName:
903 if (cap_file_->finfo_selected->hfinfo->abbrev != 0) {
904 clip.append(cap_file_->finfo_selected->hfinfo->abbrev);
907 case CopySelectedValue:
908 if (cap_file_->edt != 0) {
909 clip.append(get_node_field_value(cap_file_->finfo_selected, cap_file_->edt));
914 if (clip.length() == 0) {
915 /* If no representation then... Try to read the value */
916 proto_item_fill_label(cap_file_->finfo_selected, label_str);
917 clip.append(label_str);
921 wsApp->clipboard()->setText(clip);
923 QString err = tr("Couldn't copy text. Try another item.");
924 main_ui_->statusBar->pushTemporaryStatus(err);
928 void MainWindow::on_actionEditCopyDescription_triggered()
930 actionEditCopyTriggered(CopySelectedDescription);
933 void MainWindow::on_actionEditCopyFieldName_triggered()
935 actionEditCopyTriggered(CopySelectedFieldName);
938 void MainWindow::on_actionEditCopyValue_triggered()
940 actionEditCopyTriggered(CopySelectedValue);
943 void MainWindow::on_actionEditCopyAsFilter_triggered()
945 matchSelectedFilter(MatchSelectedReplace, false, true);
950 // Expand / collapse slots in proto_tree
956 // XXX This should probably be somewhere else.
957 void MainWindow::matchSelectedFilter(MainWindow::MatchSelected filter_type, bool apply, bool copy_only)
959 QString field_filter;
963 if (packet_list_->contextMenuActive()) {
964 field_filter = packet_list_->getFilterFromRowAndColumn();
965 } else if (cap_file_ && cap_file_->finfo_selected) {
966 field_filter = proto_construct_match_selected_string(cap_file_->finfo_selected,
972 if (field_filter.isEmpty()) {
973 QString err = tr("No filter available. Try another ");
974 err.append(packet_list_->contextMenuActive() ? "column" : "item");
976 main_ui_->statusBar->pushTemporaryStatus(err);
980 if (!df_combo_box_) return;
982 cur_filter = df_combo_box_->lineEdit()->text();
984 switch (filter_type) {
985 case MatchSelectedReplace:
986 new_filter = field_filter;
988 case MatchSelectedAnd:
989 if (cur_filter.length()) {
990 new_filter = "(" + cur_filter + ") && (" + field_filter + ")";
992 new_filter = field_filter;
995 case MatchSelectedOr:
996 if (cur_filter.length()) {
997 new_filter = "(" + cur_filter + ") || (" + field_filter + ")";
999 new_filter = field_filter;
1002 case MatchSelectedNot:
1003 new_filter = "!(" + field_filter + ")";
1005 case MatchSelectedAndNot:
1006 if (cur_filter.length()) {
1007 new_filter = "(" + cur_filter + ") && !(" + field_filter + ")";
1009 new_filter = "!(" + field_filter + ")";
1012 case MatchSelectedOrNot:
1013 if (cur_filter.length()) {
1014 new_filter = "(" + cur_filter + ") || !(" + field_filter + ")";
1016 new_filter = "!(" + field_filter + ")";
1020 g_assert_not_reached();
1025 wsApp->clipboard()->setText(new_filter);
1027 df_combo_box_->lineEdit()->setText(new_filter);
1029 df_combo_box_->applyDisplayFilter();
1031 df_combo_box_->lineEdit()->setFocus();
1037 void MainWindow::on_actionAnalyzeAAFSelected_triggered()
1039 matchSelectedFilter(MatchSelectedReplace, true, false);
1042 void MainWindow::on_actionAnalyzeAAFNotSelected_triggered()
1044 matchSelectedFilter(MatchSelectedNot, true, false);
1047 void MainWindow::on_actionAnalyzeAAFAndSelected_triggered()
1049 matchSelectedFilter(MatchSelectedAnd, true, false);
1052 void MainWindow::on_actionAnalyzeAAFOrSelected_triggered()
1054 matchSelectedFilter(MatchSelectedOr, true, false);
1057 void MainWindow::on_actionAnalyzeAAFAndNotSelected_triggered()
1059 matchSelectedFilter(MatchSelectedAndNot, true, false);
1062 void MainWindow::on_actionAnalyzeAAFOrNotSelected_triggered()
1064 matchSelectedFilter(MatchSelectedOrNot, true, false);
1067 void MainWindow::on_actionAnalyzePAFSelected_triggered()
1069 matchSelectedFilter(MatchSelectedReplace, false, false);
1072 void MainWindow::on_actionAnalyzePAFNotSelected_triggered()
1074 matchSelectedFilter(MatchSelectedNot, false, false);
1077 void MainWindow::on_actionAnalyzePAFAndSelected_triggered()
1079 matchSelectedFilter(MatchSelectedAnd, false, false);
1082 void MainWindow::on_actionAnalyzePAFOrSelected_triggered()
1084 matchSelectedFilter(MatchSelectedOr, false, false);
1087 void MainWindow::on_actionAnalyzePAFAndNotSelected_triggered()
1089 matchSelectedFilter(MatchSelectedAndNot, false, false);
1092 void MainWindow::on_actionAnalyzePAFOrNotSelected_triggered()
1094 matchSelectedFilter(MatchSelectedOrNot, false, false);
1098 // Next / previous / first / last slots in packet_list
1101 void MainWindow::on_actionHelpContents_triggered() {
1103 wsApp->helpTopicAction(HELP_CONTENT);
1106 void MainWindow::on_actionHelpMPWireshark_triggered() {
1108 wsApp->helpTopicAction(LOCALPAGE_MAN_WIRESHARK);
1110 void MainWindow::on_actionHelpMPWireshark_Filter_triggered() {
1112 wsApp->helpTopicAction(LOCALPAGE_MAN_WIRESHARK_FILTER);
1114 void MainWindow::on_actionHelpMPTShark_triggered() {
1116 wsApp->helpTopicAction(LOCALPAGE_MAN_TSHARK);
1118 void MainWindow::on_actionHelpMPRawShark_triggered() {
1120 wsApp->helpTopicAction(LOCALPAGE_MAN_RAWSHARK);
1122 void MainWindow::on_actionHelpMPDumpcap_triggered() {
1124 wsApp->helpTopicAction(LOCALPAGE_MAN_DUMPCAP);
1126 void MainWindow::on_actionHelpMPMergecap_triggered() {
1128 wsApp->helpTopicAction(LOCALPAGE_MAN_MERGECAP);
1130 void MainWindow::on_actionHelpMPEditcap_triggered() {
1132 wsApp->helpTopicAction(LOCALPAGE_MAN_EDITCAP);
1134 void MainWindow::on_actionHelpMPText2cap_triggered() {
1136 wsApp->helpTopicAction(LOCALPAGE_MAN_TEXT2PCAP);
1139 void MainWindow::on_actionHelpWebsite_triggered() {
1141 wsApp->helpTopicAction(ONLINEPAGE_HOME);
1144 void MainWindow::on_actionHelpFAQ_triggered() {
1146 wsApp->helpTopicAction(ONLINEPAGE_FAQ);
1149 void MainWindow::on_actionHelpAsk_triggered() {
1151 wsApp->helpTopicAction(ONLINEPAGE_ASK);
1154 void MainWindow::on_actionHelpDownloads_triggered() {
1156 wsApp->helpTopicAction(ONLINEPAGE_DOWNLOAD);
1159 void MainWindow::on_actionHelpWiki_triggered() {
1161 wsApp->helpTopicAction(ONLINEPAGE_WIKI);
1164 void MainWindow::on_actionHelpSampleCaptures_triggered() {
1166 wsApp->helpTopicAction(ONLINEPAGE_SAMPLE_FILES);
1169 void MainWindow::on_actionGoGoToPacket_triggered() {
1170 if (packet_list_->model()->rowCount() < 1) {
1173 previous_focus_ = wsApp->focusWidget();
1174 connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus()));
1175 main_ui_->goToFrame->show();
1176 main_ui_->goToLineEdit->setFocus();
1179 void MainWindow::resetPreviousFocus() {
1180 previous_focus_ = NULL;
1183 void MainWindow::on_goToCancel_clicked()
1185 main_ui_->goToFrame->hide();
1186 if (previous_focus_) {
1187 disconnect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus()));
1188 previous_focus_->setFocus();
1189 resetPreviousFocus();
1193 void MainWindow::on_goToGo_clicked()
1195 int packet_num = main_ui_->goToLineEdit->text().toInt();
1197 if (packet_num > 0) {
1198 packet_list_->goToPacket(packet_num);
1200 on_goToCancel_clicked();
1203 void MainWindow::on_goToLineEdit_returnPressed()
1205 on_goToGo_clicked();
1208 void MainWindow::on_actionStartCapture_triggered()
1210 //#ifdef HAVE_AIRPCAP
1211 // airpcap_if_active = airpcap_if_selected;
1212 // if (airpcap_if_active)
1213 // airpcap_set_toolbar_start_capture(airpcap_if_active);
1216 // if (cap_open_w) {
1218 // * There's an options dialog; get the values from it and close it.
1220 // gboolean success;
1222 // /* Determine if "capture start" while building of the "capture options" window */
1223 // /* is in progress. If so, ignore the "capture start. */
1224 // /* XXX: Would it be better/cleaner for the "capture options" window code to */
1225 // /* disable the capture start button temporarily ? */
1226 // if (cap_open_complete == FALSE) {
1227 // return; /* Building options window: ignore "capture start" */
1229 // success = capture_dlg_prep(cap_open_w);
1230 // window_destroy(GTK_WIDGET(cap_open_w));
1232 // return; /* error in options dialog */
1235 main_ui_->mainStack->setCurrentWidget(packet_splitter_);
1237 if (global_capture_opts.num_selected == 0) {
1238 QString err_msg = tr("No Interface Selected");
1239 main_ui_->statusBar->pushTemporaryStatus(err_msg);
1243 /* XXX - will closing this remove a temporary file? */
1244 if (testCaptureFileClose(FALSE, *new QString(" before starting a new capture")))
1248 void MainWindow::on_actionStopCapture_triggered()
1259 * indent-tabs-mode: nil
1262 * ex: set shiftwidth=4 tabstop=8 expandtab:
1263 * :indentSize=4:tabSize=8:noTabs=true: