PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ui/qt/main_window_slots.cpp

https://github.com/labx-technologies-llc/wireshark
C++ | 1801 lines | 1063 code | 298 blank | 440 comment | 149 complexity | 0ba6c9eb2a9d97a643e39a51562f93b8 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /* main_window_slots.cpp
  2. *
  3. * $Id$
  4. *
  5. * Wireshark - Network traffic analyzer
  6. * By Gerald Combs <gerald@wireshark.org>
  7. * Copyright 1998 Gerald Combs
  8. *
  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.
  13. *
  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.
  18. *
  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.
  22. */
  23. #include <config.h>
  24. #ifdef HAVE_FCNTL_H
  25. #include <fcntl.h>
  26. #endif
  27. #ifdef HAVE_UNISTD_H
  28. #include <unistd.h>
  29. #endif
  30. #include "main_window.h"
  31. #include "ui_main_window.h"
  32. #include "globals.h"
  33. #include <epan/filesystem.h>
  34. #include <epan/prefs.h>
  35. #ifdef _WIN32
  36. #include <windows.h>
  37. #include <io.h>
  38. #endif
  39. #ifdef HAVE_LIBPCAP
  40. #include "capture.h"
  41. #include "capture-pcap-util.h"
  42. #include "capture_ui_utils.h"
  43. #include "capture_session.h"
  44. #endif
  45. #include "wsutil/file_util.h"
  46. #include "epan/column.h"
  47. #include "epan/filter_expressions.h"
  48. #include "ui/alert_box.h"
  49. #include "ui/ui_util.h"
  50. #include "ui/capture_globals.h"
  51. #include "ui/help_url.h"
  52. #include "ui/main_statusbar.h"
  53. #include "ui/preference_utils.h"
  54. #include "ui/ssl_key_export.h"
  55. #ifdef HAVE_SOFTWARE_UPDATE
  56. #include "ui/software_update.h"
  57. #endif
  58. #include "capture_file_dialog.h"
  59. #include "export_object_dialog.h"
  60. #include "time_shift_dialog.h"
  61. #include "packet_comment_dialog.h"
  62. #include "preferences_dialog.h"
  63. #include "print_dialog.h"
  64. #include "profile_dialog.h"
  65. #include "qt_ui_utils.h"
  66. #include "wireshark_application.h"
  67. #include <QClipboard>
  68. #include <QMessageBox>
  69. #include <QDebug>
  70. //
  71. // Public slots
  72. //
  73. const char *dfe_property_ = "display filter expression"; //TODO : Fix Translate
  74. void MainWindow::openCaptureFile(QString &cf_path, QString &display_filter)
  75. {
  76. QString file_name = "";
  77. dfilter_t *rfcode = NULL;
  78. int err;
  79. testCaptureFileClose(false);
  80. for (;;) {
  81. if (cf_path.isEmpty()) {
  82. CaptureFileDialog open_dlg(this, cap_file_, display_filter);
  83. switch (prefs.gui_fileopen_style) {
  84. case FO_STYLE_LAST_OPENED:
  85. /* The user has specified that we should start out in the last directory
  86. we looked in. If we've already opened a file, use its containing
  87. directory, if we could determine it, as the directory, otherwise
  88. use the "last opened" directory saved in the preferences file if
  89. there was one. */
  90. /* This is now the default behaviour in file_selection_new() */
  91. break;
  92. case FO_STYLE_SPECIFIED:
  93. /* The user has specified that we should always start out in a
  94. specified directory; if they've specified that directory,
  95. start out by showing the files in that dir. */
  96. if (prefs.gui_fileopen_dir[0] != '\0')
  97. open_dlg.setDirectory(prefs.gui_fileopen_dir);
  98. break;
  99. }
  100. if (open_dlg.open(file_name)) {
  101. if (dfilter_compile(display_filter.toUtf8().constData(), &rfcode)) {
  102. cf_set_rfcode(&cfile, rfcode);
  103. } else {
  104. /* Not valid. Tell the user, and go back and run the file
  105. selection box again once they dismiss the alert. */
  106. //bad_dfilter_alert_box(top_level, display_filter->str);
  107. QMessageBox::warning(this, tr("Invalid Display Filter"),
  108. QString("The filter expression ") +
  109. display_filter +
  110. QString(" isn't a valid display filter. (") +
  111. dfilter_error_msg + QString(")."),
  112. QMessageBox::Ok);
  113. continue;
  114. }
  115. cf_path = file_name;
  116. } else {
  117. return;
  118. }
  119. }
  120. /* Try to open the capture file. */
  121. cfile.window = this;
  122. if (cf_open(&cfile, cf_path.toUtf8().constData(), FALSE, &err) != CF_OK) {
  123. /* We couldn't open it; don't dismiss the open dialog box,
  124. just leave it around so that the user can, after they
  125. dismiss the alert box popped up for the open error,
  126. try again. */
  127. cfile.window = NULL;
  128. if (rfcode != NULL)
  129. dfilter_free(rfcode);
  130. cf_path.clear();
  131. continue;
  132. }
  133. switch (cf_read(&cfile, FALSE)) {
  134. case CF_READ_OK:
  135. case CF_READ_ERROR:
  136. /* Just because we got an error, that doesn't mean we were unable
  137. to read any of the file; we handle what we could get from the
  138. file. */
  139. break;
  140. case CF_READ_ABORTED:
  141. /* The user bailed out of re-reading the capture file; the
  142. capture file has been closed - just free the capture file name
  143. string and return (without changing the last containing
  144. directory). */
  145. cap_file_ = NULL;
  146. return;
  147. }
  148. break;
  149. }
  150. // get_dirname overwrites its path. Hopefully this isn't a problem.
  151. wsApp->setLastOpenDir(get_dirname(cf_path.toUtf8().data()));
  152. df_combo_box_->setEditText(display_filter);
  153. main_ui_->statusBar->showExpert();
  154. }
  155. void MainWindow::filterPackets(QString& new_filter, bool force)
  156. {
  157. cf_status_t cf_status;
  158. cf_status = cf_filter_packets(&cfile, new_filter.toUtf8().data(), force);
  159. if (cf_status == CF_OK) {
  160. emit displayFilterSuccess(true);
  161. if (new_filter.length() > 0) {
  162. if (df_combo_box_->findText(new_filter) < 0) {
  163. df_combo_box_->insertItem(0, new_filter);
  164. }
  165. }
  166. } else {
  167. emit displayFilterSuccess(false);
  168. }
  169. }
  170. // Capture callbacks
  171. #ifdef HAVE_LIBPCAP
  172. void MainWindow::captureCapturePrepared(capture_session *cap_session) {
  173. qDebug() << "FIX captureCapturePrepared";
  174. setTitlebarForCaptureInProgress();
  175. // if(icon_list == NULL) {
  176. // icon_list = icon_list_create(wsiconcap16_xpm, wsiconcap32_xpm, wsiconcap48_xpm, NULL);
  177. // }
  178. // gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
  179. /* Disable menu items that make no sense if you're currently running
  180. a capture. */
  181. setForCaptureInProgress(true);
  182. // set_capture_if_dialog_for_capture_in_progress(TRUE);
  183. // /* Don't set up main window for a capture file. */
  184. // main_set_for_capture_file(FALSE);
  185. main_ui_->mainStack->setCurrentWidget(packet_splitter_);
  186. cap_file_ = (capture_file *) cap_session->cf;
  187. }
  188. void MainWindow::captureCaptureUpdateStarted(capture_session *cap_session) {
  189. Q_UNUSED(cap_session);
  190. /* We've done this in "prepared" above, but it will be cleared while
  191. switching to the next multiple file. */
  192. setTitlebarForCaptureInProgress();
  193. setForCaptureInProgress(true);
  194. setForCapturedPackets(true);
  195. }
  196. void MainWindow::captureCaptureUpdateFinished(capture_session *cap_session) {
  197. Q_UNUSED(cap_session);
  198. /* The capture isn't stopping any more - it's stopped. */
  199. capture_stopping_ = false;
  200. /* Update the main window as appropriate */
  201. updateForUnsavedChanges();
  202. /* Enable menu items that make sense if you're not currently running
  203. a capture. */
  204. setForCaptureInProgress(false);
  205. }
  206. void MainWindow::captureCaptureFixedStarted(capture_session *cap_session) {
  207. Q_UNUSED(cap_session);
  208. qDebug() << "captureCaptureFixedStarted";
  209. }
  210. void MainWindow::captureCaptureFixedFinished(capture_session *cap_session) {
  211. Q_UNUSED(cap_session);
  212. qDebug() << "captureCaptureFixedFinished";
  213. /* The capture isn't stopping any more - it's stopped. */
  214. capture_stopping_ = false;
  215. /* Enable menu items that make sense if you're not currently running
  216. a capture. */
  217. setForCaptureInProgress(false);
  218. }
  219. void MainWindow::captureCaptureStopping(capture_session *cap_session) {
  220. Q_UNUSED(cap_session);
  221. capture_stopping_ = true;
  222. setMenusForCaptureStopping();
  223. }
  224. void MainWindow::captureCaptureFailed(capture_session *cap_session) {
  225. Q_UNUSED(cap_session);
  226. qDebug() << "captureCaptureFailed";
  227. /* Capture isn't stopping any more. */
  228. capture_stopping_ = false;
  229. setForCaptureInProgress(false);
  230. }
  231. #endif // HAVE_LIBPCAP
  232. // Callbacks from cfile.c via WiresharkApplication::captureFileCallback
  233. void MainWindow::captureFileOpened(const capture_file *cf) {
  234. if (cf->window != this) return;
  235. cap_file_ = (capture_file *) cf;
  236. file_set_dialog_.fileOpened(cf);
  237. setMenusForFileSet(true);
  238. emit setCaptureFile(cap_file_);
  239. }
  240. void MainWindow::captureFileReadStarted(const capture_file *cf) {
  241. if (cf != cap_file_) return;
  242. // tap_param_dlg_update();
  243. /* Set up main window for a capture file. */
  244. // main_set_for_capture_file(TRUE);
  245. main_ui_->statusBar->popFileStatus();
  246. QString msg = QString(tr("Loading: %1")).arg(get_basename(cf->filename));
  247. main_ui_->statusBar->pushFileStatus(msg);
  248. main_ui_->mainStack->setCurrentWidget(packet_splitter_);
  249. WiresharkApplication::processEvents();
  250. }
  251. void MainWindow::captureFileReadFinished(const capture_file *cf) {
  252. if (cf != cap_file_) return;
  253. // gchar *dir_path;
  254. // if (!cf->is_tempfile && cf->filename) {
  255. // /* Add this filename to the list of recent files in the "Recent Files" submenu */
  256. // add_menu_recent_capture_file(cf->filename);
  257. // /* Remember folder for next Open dialog and save it in recent */
  258. // dir_path = get_dirname(g_strdup(cf->filename));
  259. // wsApp->setLastOpenDir(dir_path);
  260. // g_free(dir_path);
  261. // }
  262. /* Update the appropriate parts of the main window. */
  263. updateForUnsavedChanges();
  264. /* Enable menu items that make sense if you have some captured packets. */
  265. setForCapturedPackets(true);
  266. main_ui_->statusBar->popFileStatus();
  267. QString msg = QString().sprintf("%s", get_basename(cf->filename));
  268. main_ui_->statusBar->pushFileStatus(msg);
  269. }
  270. void MainWindow::captureFileClosing(const capture_file *cf) {
  271. if (cf != cap_file_) return;
  272. setMenusForCaptureFile(true);
  273. setForCapturedPackets(false);
  274. setMenusForSelectedPacket();
  275. setForCaptureInProgress(false);
  276. // Reset expert info indicator
  277. main_ui_->statusBar->hideExpert();
  278. main_ui_->searchFrame->animatedHide();
  279. // gtk_widget_show(expert_info_none);
  280. emit setCaptureFile(NULL);
  281. }
  282. void MainWindow::captureFileClosed(const capture_file *cf) {
  283. if (cf != cap_file_) return;
  284. packets_bar_update();
  285. file_set_dialog_.fileClosed();
  286. setMenusForFileSet(false);
  287. // Reset expert info indicator
  288. main_ui_->statusBar->hideExpert();
  289. main_ui_->statusBar->popFileStatus();
  290. cap_file_ = NULL;
  291. summary_dialog_.close();
  292. setTitlebarForSelectedTreeRow();
  293. setMenusForSelectedTreeRow();
  294. }
  295. void MainWindow::configurationProfileChanged(const gchar *profile_name) {
  296. Q_UNUSED(profile_name);
  297. /* Update window view and redraw the toolbar */
  298. // main_titlebar_update();
  299. filterExpressionsChanged();
  300. // toolbar_redraw_all();
  301. /* Reload list of interfaces on welcome page */
  302. // welcome_if_panel_reload();
  303. /* Recreate the packet list according to new preferences */
  304. recreatePacketList();
  305. /* Reload pane geometry, must be done after recreating the list */
  306. // main_pane_load_window_geometry();
  307. }
  308. void MainWindow::filterExpressionsChanged()
  309. {
  310. // Recreate filter buttons
  311. foreach (QAction *act, main_ui_->displayFilterToolBar->actions()) {
  312. // Permanent actions shouldn't have data
  313. if (act->property(dfe_property_).isValid()) {
  314. main_ui_->displayFilterToolBar->removeAction(act);
  315. delete act;
  316. }
  317. }
  318. for (struct filter_expression *fe = *pfilter_expression_head; fe != NULL; fe = fe->next) {
  319. if (!fe->enabled) continue;
  320. QAction *dfb_action = new QAction(fe->label, main_ui_->displayFilterToolBar);
  321. dfb_action->setToolTip(fe->expression);
  322. dfb_action->setData(fe->expression);
  323. dfb_action->setProperty(dfe_property_, true);
  324. main_ui_->displayFilterToolBar->addAction(dfb_action);
  325. connect(dfb_action, SIGNAL(triggered()), this, SLOT(displayFilterButtonClicked()));
  326. }
  327. }
  328. //
  329. // Private slots
  330. //
  331. // ui/gtk/capture_dlg.c:start_capture_confirmed
  332. void MainWindow::startCapture() {
  333. interface_options interface_opts;
  334. guint i;
  335. /* did the user ever select a capture interface before? */
  336. if(global_capture_opts.num_selected == 0) {
  337. QString msg = QString("No interface selected");
  338. main_ui_->statusBar->pushTemporaryStatus(msg);
  339. return;
  340. }
  341. // Ideally we should have disabled the start capture
  342. // toolbar buttons and menu items. This may not be the
  343. // case, e.g. with QtMacExtras.
  344. if(!capture_filter_valid_) {
  345. QString msg = QString("Invalid capture filter");
  346. main_ui_->statusBar->pushTemporaryStatus(msg);
  347. return;
  348. }
  349. /* XXX - we might need to init other pref data as well... */
  350. // main_auto_scroll_live_changed(auto_scroll_live);
  351. /* XXX - can this ever happen? */
  352. if (global_capture_session.state != CAPTURE_STOPPED)
  353. return;
  354. /* close the currently loaded capture file */
  355. cf_close((capture_file *) global_capture_session.cf);
  356. /* Copy the selected interfaces to the set of interfaces to use for
  357. this capture. */
  358. collect_ifaces(&global_capture_opts);
  359. cfile.window = this;
  360. if (capture_start(&global_capture_opts, &global_capture_session, main_window_update)) {
  361. /* The capture succeeded, which means the capture filter syntax is
  362. valid; add this capture filter to the recent capture filter list. */
  363. for (i = 0; i < global_capture_opts.ifaces->len; i++) {
  364. interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
  365. if (interface_opts.cfilter) {
  366. // cfilter_combo_add_recent(interface_opts.cfilter);
  367. }
  368. }
  369. } else {
  370. cfile.window = NULL;
  371. }
  372. }
  373. // Copied from ui/gtk/gui_utils.c
  374. void MainWindow::pipeTimeout() {
  375. #ifdef _WIN32
  376. HANDLE handle;
  377. DWORD avail = 0;
  378. gboolean result, result1;
  379. DWORD childstatus;
  380. gint iterations = 0;
  381. /* try to read data from the pipe only 5 times, to avoid blocking */
  382. while(iterations < 5) {
  383. /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
  384. /* Oddly enough although Named pipes don't work on win9x,
  385. PeekNamedPipe does !!! */
  386. handle = (HANDLE) _get_osfhandle (pipe_source_);
  387. result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
  388. /* Get the child process exit status */
  389. result1 = GetExitCodeProcess((HANDLE)*(pipe_child_process_),
  390. &childstatus);
  391. /* If the Peek returned an error, or there are bytes to be read
  392. or the childwatcher thread has terminated then call the normal
  393. callback */
  394. if (!result || avail > 0 || childstatus != STILL_ACTIVE) {
  395. /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
  396. /* And call the real handler */
  397. if (!pipe_input_cb_(pipe_source_, pipe_user_data_)) {
  398. g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: input pipe closed, iterations: %u", iterations);
  399. /* pipe closed, return false so that the old timer is not run again */
  400. delete pipe_timer_;
  401. return;
  402. }
  403. }
  404. else {
  405. /*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
  406. /* No data, stop now */
  407. break;
  408. }
  409. iterations++;
  410. }
  411. #endif // _WIN32
  412. }
  413. void MainWindow::pipeActivated(int source) {
  414. #ifdef _WIN32
  415. Q_UNUSED(source);
  416. #else
  417. g_assert(source == pipe_source_);
  418. pipe_notifier_->setEnabled(false);
  419. if (pipe_input_cb_(pipe_source_, pipe_user_data_)) {
  420. pipe_notifier_->setEnabled(true);
  421. } else {
  422. delete pipe_notifier_;
  423. }
  424. #endif // _WIN32
  425. }
  426. void MainWindow::pipeNotifierDestroyed() {
  427. #ifdef _WIN32
  428. pipe_timer_ = NULL;
  429. #else
  430. pipe_notifier_ = NULL;
  431. #endif // _WIN32
  432. }
  433. void MainWindow::stopCapture() {
  434. //#ifdef HAVE_AIRPCAP
  435. // if (airpcap_if_active)
  436. // airpcap_set_toolbar_stop_capture(airpcap_if_active);
  437. //#endif
  438. capture_stop(&global_capture_session);
  439. }
  440. // XXX - Copied from ui/gtk/menus.c
  441. /**
  442. * Add the capture filename (with an absolute path) to the "Recent Files" menu.
  443. *
  444. * @param cf_name Absolute path to the file.
  445. * @param first Prepend the filename if true, otherwise append it. Default is false (append).
  446. */
  447. // XXX - We should probably create a RecentFile class.
  448. void MainWindow::updateRecentFiles() {
  449. QAction *ra;
  450. QMenu *recentMenu = main_ui_->menuOpenRecentCaptureFile;
  451. QString action_cf_name;
  452. if (!recentMenu) {
  453. return;
  454. }
  455. recentMenu->clear();
  456. /* Iterate through the actions in menuOpenRecentCaptureFile,
  457. * removing special items, a maybe duplicate entry and every item above count_max */
  458. int shortcut = Qt::Key_0;
  459. foreach (recent_item_status *ri, wsApp->recentItems()) {
  460. // Add the new item
  461. ra = new QAction(recentMenu);
  462. ra->setData(ri->filename);
  463. // XXX - Needs get_recent_item_status or equivalent
  464. ra->setEnabled(ri->accessible);
  465. recentMenu->insertAction(NULL, ra);
  466. action_cf_name = ra->data().toString();
  467. if (shortcut <= Qt::Key_9) {
  468. ra->setShortcut(Qt::META | shortcut);
  469. shortcut++;
  470. }
  471. ra->setText(action_cf_name);
  472. connect(ra, SIGNAL(triggered()), this, SLOT(recentActionTriggered()));
  473. }
  474. if (recentMenu->actions().count() > 0) {
  475. // Separator + "Clear"
  476. // XXX - Do we really need this?
  477. ra = new QAction(recentMenu);
  478. ra->setSeparator(true);
  479. recentMenu->insertAction(NULL, ra);
  480. ra = new QAction(recentMenu);
  481. ra->setText(tr("Clear Menu"));
  482. recentMenu->insertAction(NULL, ra);
  483. connect(ra, SIGNAL(triggered()), wsApp, SLOT(clearRecentItems()));
  484. } else {
  485. if (main_ui_->actionDummyNoFilesFound) {
  486. recentMenu->addAction(main_ui_->actionDummyNoFilesFound);
  487. }
  488. }
  489. }
  490. void MainWindow::recentActionTriggered() {
  491. QAction *ra = qobject_cast<QAction*>(sender());
  492. if (ra) {
  493. QString cfPath = ra->data().toString();
  494. openCaptureFile(cfPath);
  495. }
  496. }
  497. void MainWindow::setMenusForSelectedPacket()
  498. {
  499. // GList *list_entry = dissector_filter_list;
  500. // guint i = 0;
  501. // gboolean properties = FALSE;
  502. // const char *abbrev = NULL;
  503. // char *prev_abbrev;
  504. // /* Making the menu context-sensitive allows for easier selection of the
  505. // desired item and has the added benefit, with large captures, of
  506. // avoiding needless looping through huge lists for marked, ignored,
  507. // or time-referenced packets. */
  508. // gboolean is_ssl = epan_dissect_packet_contains_field(cf->edt, "ssl");
  509. /* We have one or more items in the packet list */
  510. gboolean have_frames = FALSE;
  511. /* A frame is selected */
  512. gboolean frame_selected = FALSE;
  513. /* We have marked frames. (XXX - why check frame_selected?) */
  514. gboolean have_marked = FALSE;
  515. /* We have a marked frame other than the current frame (i.e.,
  516. we have at least one marked frame, and either there's more
  517. than one marked frame or the current frame isn't marked). */
  518. gboolean another_is_marked = FALSE;
  519. /* One or more frames are hidden by a display filter */
  520. gboolean have_filtered = FALSE;
  521. /* One or more frames have been ignored */
  522. gboolean have_ignored = FALSE;
  523. gboolean have_time_ref = FALSE;
  524. /* We have a time reference frame other than the current frame (i.e.,
  525. we have at least one time reference frame, and either there's more
  526. than one time reference frame or the current frame isn't a
  527. time reference frame). (XXX - why check frame_selected?) */
  528. gboolean another_is_time_ref = FALSE;
  529. if (cap_file_) {
  530. frame_selected = cap_file_->current_frame != NULL;
  531. have_frames = cap_file_->count > 0;
  532. have_marked = frame_selected && cap_file_->marked_count > 0;
  533. another_is_marked = have_marked &&
  534. !(cap_file_->marked_count == 1 && cap_file_->current_frame->flags.marked);
  535. have_filtered = cap_file_->displayed_count > 0 && cap_file_->displayed_count != cap_file_->count;
  536. have_ignored = cap_file_->ignored_count > 0;
  537. have_time_ref = cap_file_->ref_time_count > 0;
  538. another_is_time_ref = frame_selected && have_time_ref &&
  539. !(cap_file_->ref_time_count == 1 && cap_file_->current_frame->flags.ref_time);
  540. }
  541. // if (cfile.edt && cfile.edt->tree) {
  542. // GPtrArray *ga;
  543. // header_field_info *hfinfo;
  544. // field_info *v;
  545. // guint ii;
  546. // ga = proto_all_finfos(cfile.edt->tree);
  547. // for (ii = ga->len - 1; ii > 0 ; ii -= 1) {
  548. // v = g_ptr_array_index (ga, ii);
  549. // hfinfo = v->hfinfo;
  550. // if (!g_str_has_prefix(hfinfo->abbrev, "text") &&
  551. // !g_str_has_prefix(hfinfo->abbrev, "expert") &&
  552. // !g_str_has_prefix(hfinfo->abbrev, "malformed")) {
  553. // if (hfinfo->parent == -1) {
  554. // abbrev = hfinfo->abbrev;
  555. // } else {
  556. // abbrev = proto_registrar_get_abbrev(hfinfo->parent);
  557. // }
  558. // properties = prefs_is_registered_protocol(abbrev);
  559. // break;
  560. // }
  561. // }
  562. // }
  563. main_ui_->actionEditMarkPacket->setEnabled(frame_selected);
  564. main_ui_->actionEditMarkAllDisplayed->setEnabled(have_frames);
  565. /* Unlike un-ignore, do not allow unmark of all frames when no frames are displayed */
  566. main_ui_->actionEditUnmarkAllDisplayed->setEnabled(have_marked);
  567. main_ui_->actionEditNextMark->setEnabled(another_is_marked);
  568. main_ui_->actionEditPreviousMark->setEnabled(another_is_marked);
  569. //#ifdef WANT_PACKET_EDITOR
  570. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/EditPacket",
  571. // frame_selected);
  572. //#endif /* WANT_PACKET_EDITOR */
  573. main_ui_->actionEditPacketComment->setEnabled(frame_selected && wtap_dump_can_write(cap_file_->linktypes, WTAP_COMMENT_PER_PACKET));
  574. main_ui_->actionEditIgnorePacket->setEnabled(frame_selected);
  575. main_ui_->actionEditIgnoreAllDisplayed->setEnabled(have_filtered);
  576. /* Allow un-ignore of all frames even with no frames currently displayed */
  577. main_ui_->actionEditUnignoreAllDisplayed->setEnabled(have_ignored);
  578. main_ui_->actionEditSetTimeReference->setEnabled(frame_selected);
  579. main_ui_->actionEditUnsetAllTimeReferences->setEnabled(have_time_ref);
  580. main_ui_->actionEditNextTimeReference->setEnabled(another_is_time_ref);
  581. main_ui_->actionEditPreviousTimeReference->setEnabled(another_is_time_ref);
  582. main_ui_->actionEditTimeShift->setEnabled(have_frames);
  583. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ResizeAllColumns",
  584. // frame_selected);
  585. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/CollapseAll",
  586. // frame_selected);
  587. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/CollapseAll",
  588. // frame_selected);
  589. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ExpandAll",
  590. // frame_selected);
  591. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandAll",
  592. // frame_selected);
  593. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ColorizeConversation",
  594. // frame_selected);
  595. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ResetColoring1-10",
  596. // tmp_color_filters_used());
  597. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ShowPacketinNewWindow",
  598. // frame_selected);
  599. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ShowPacketinNewWindow",
  600. // frame_selected);
  601. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ManuallyResolveAddress",
  602. // frame_selected ? ((cf->edt->pi.ethertype == ETHERTYPE_IP)||(cf->edt->pi.ethertype == ETHERTYPE_IPv6)) : FALSE);
  603. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/SCTP",
  604. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_SCTP) : FALSE);
  605. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/FollowTCPStream",
  606. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
  607. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FollowTCPStream",
  608. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
  609. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/FollowUDPStream",
  610. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_UDP) : FALSE);
  611. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/FollowSSLStream",
  612. // frame_selected ? is_ssl : FALSE);
  613. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FollowSSLStream",
  614. // frame_selected ? is_ssl : FALSE);
  615. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter",
  616. // frame_selected);
  617. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/Ethernet",
  618. // frame_selected ? (cf->edt->pi.dl_src.type == AT_ETHER) : FALSE);
  619. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/IP",
  620. // frame_selected ? ((cf->edt->pi.ethertype == ETHERTYPE_IP)||(cf->edt->pi.ethertype == ETHERTYPE_IPv6)) : FALSE);
  621. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/TCP",
  622. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
  623. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/UDP",
  624. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_UDP) : FALSE);
  625. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FollowUDPStream",
  626. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_UDP) : FALSE);
  627. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ConversationFilter/PN-CBA",
  628. // frame_selected ? (cf->edt->pi.profinet_type != 0 && cf->edt->pi.profinet_type < 10) : FALSE);
  629. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation",
  630. // frame_selected);
  631. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/Ethernet",
  632. // frame_selected ? (cf->edt->pi.dl_src.type == AT_ETHER) : FALSE);
  633. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/IP",
  634. // frame_selected ? ((cf->edt->pi.ethertype == ETHERTYPE_IP)||(cf->edt->pi.ethertype == ETHERTYPE_IPv6)) : FALSE);
  635. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/TCP",
  636. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
  637. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/UDP",
  638. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_UDP) : FALSE);
  639. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ColorizeConversation/PN-CBA",
  640. // frame_selected ? (cf->edt->pi.profinet_type != 0 && cf->edt->pi.profinet_type < 10) : FALSE);
  641. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/DecodeAs",
  642. // frame_selected && decode_as_ok());
  643. // if (properties) {
  644. // prev_abbrev = g_object_get_data(G_OBJECT(ui_manager_packet_list_menu), "menu_abbrev");
  645. // if (!prev_abbrev || (strcmp(prev_abbrev, abbrev) != 0)) {
  646. // /*No previous protocol or protocol changed - update Protocol Preferences menu*/
  647. // module_t *prefs_module_p = prefs_find_module(abbrev);
  648. // rebuild_protocol_prefs_menu(prefs_module_p, properties, ui_manager_packet_list_menu, "/PacketListMenuPopup/ProtocolPreferences");
  649. // g_object_set_data(G_OBJECT(ui_manager_packet_list_menu), "menu_abbrev", g_strdup(abbrev));
  650. // g_free (prev_abbrev);
  651. // }
  652. // }
  653. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ProtocolPreferences",
  654. // properties);
  655. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/DecodeAs",
  656. // frame_selected && decode_as_ok());
  657. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/Copy",
  658. // frame_selected);
  659. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/ApplyAsFilter",
  660. // frame_selected);
  661. // set_menu_sensitivity(ui_manager_packet_list_menu, "/PacketListMenuPopup/PrepareaFilter",
  662. // frame_selected);
  663. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ResolveName",
  664. // frame_selected && (gbl_resolv_flags.mac_name || gbl_resolv_flags.network_name ||
  665. // gbl_resolv_flags.transport_name || gbl_resolv_flags.concurrent_dns));
  666. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/FollowTCPStream",
  667. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_TCP) : FALSE);
  668. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/FollowUDPStream",
  669. // frame_selected ? (cf->edt->pi.ipproto == IP_PROTO_UDP) : FALSE);
  670. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/FollowSSLStream",
  671. // frame_selected ? is_ssl : FALSE);
  672. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/DecodeAs",
  673. // frame_selected && decode_as_ok());
  674. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/NameResolution/ResolveName",
  675. // frame_selected && (gbl_resolv_flags.mac_name || gbl_resolv_flags.network_name ||
  676. // gbl_resolv_flags.transport_name || gbl_resolv_flags.concurrent_dns));
  677. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ToolsMenu/FirewallACLRules",
  678. // frame_selected);
  679. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/StatisticsMenu/TCPStreamGraphMenu",
  680. // tcp_graph_selected_packet_enabled(cf->current_frame,cf->edt, NULL));
  681. // while (list_entry != NULL) {
  682. // dissector_filter_t *filter_entry;
  683. // gchar *path;
  684. // filter_entry = list_entry->data;
  685. // path = g_strdup_printf("/Menubar/AnalyzeMenu/ConversationFilterMenu/Filters/filter-%u", i);
  686. // set_menu_sensitivity(ui_manager_main_menubar, path,
  687. // menu_dissector_filter_spe_cb(/* frame_data *fd _U_*/ NULL, cf->edt, filter_entry));
  688. // g_free(path);
  689. // i++;
  690. // list_entry = g_list_next(list_entry);
  691. // }
  692. }
  693. void MainWindow::setMenusForSelectedTreeRow(field_info *fi) {
  694. //gboolean properties;
  695. //gint id;
  696. // XXX Add commented items below
  697. if (cap_file_) {
  698. cap_file_->finfo_selected = fi;
  699. }
  700. if (cap_file_ != NULL && fi != NULL) {
  701. /*
  702. header_field_info *hfinfo = fi->hfinfo;
  703. const char *abbrev;
  704. char *prev_abbrev;
  705. if (hfinfo->parent == -1) {
  706. abbrev = hfinfo->abbrev;
  707. id = (hfinfo->type == FT_PROTOCOL) ? proto_get_id((protocol_t *)hfinfo->strings) : -1;
  708. } else {
  709. abbrev = proto_registrar_get_abbrev(hfinfo->parent);
  710. id = hfinfo->parent;
  711. }
  712. properties = prefs_is_registered_protocol(abbrev);
  713. */
  714. bool can_match_selected = proto_can_match_selected(cap_file_->finfo_selected, cap_file_->edt);
  715. // set_menu_sensitivity(ui_manager_tree_view_menu,
  716. // "/TreeViewPopup/GotoCorrespondingPacket", hfinfo->type == FT_FRAMENUM);
  717. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/Copy",
  718. // TRUE);
  719. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ApplyasColumn",
  720. // hfinfo->type != FT_NONE);
  721. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ColorizewithFilter",
  722. // proto_can_match_selected(cf->finfo_selected, cf->edt));
  723. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ProtocolPreferences",
  724. // properties);
  725. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/DisableProtocol",
  726. // (id == -1) ? FALSE : proto_can_toggle_protocol(id));
  727. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandSubtrees",
  728. // cf->finfo_selected->tree_type != -1);
  729. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/WikiProtocolPage",
  730. // (id == -1) ? FALSE : TRUE);
  731. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FilterFieldReference",
  732. // (id == -1) ? FALSE : TRUE);
  733. // set_menu_sensitivity(ui_manager_main_menubar,
  734. main_ui_->actionFileExportPacketBytes->setEnabled(true);
  735. // set_menu_sensitivity(ui_manager_main_menubar,
  736. // "/Menubar/GoMenu/GotoCorrespondingPacket", hfinfo->type == FT_FRAMENUM);
  737. main_ui_->actionEditCopyDescription->setEnabled(can_match_selected);
  738. main_ui_->actionEditCopyFieldName->setEnabled(can_match_selected);
  739. main_ui_->actionEditCopyValue->setEnabled(can_match_selected);
  740. main_ui_->actionEditCopyAsFilter->setEnabled(can_match_selected);
  741. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Description",
  742. // proto_can_match_selected(cf->finfo_selected, cf->edt));
  743. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Fieldname",
  744. // proto_can_match_selected(cf->finfo_selected, cf->edt));
  745. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/Value",
  746. // proto_can_match_selected(cf->finfo_selected, cf->edt));
  747. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/AsFilter",
  748. // proto_can_match_selected(cf->finfo_selected, cf->edt));
  749. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/ApplyasColumn",
  750. // hfinfo->type != FT_NONE);
  751. main_ui_->actionAnalyzeAAFSelected->setEnabled(can_match_selected);
  752. main_ui_->actionAnalyzeAAFNotSelected->setEnabled(can_match_selected);
  753. main_ui_->actionAnalyzeAAFAndSelected->setEnabled(can_match_selected);
  754. main_ui_->actionAnalyzeAAFOrSelected->setEnabled(can_match_selected);
  755. main_ui_->actionAnalyzeAAFAndNotSelected->setEnabled(can_match_selected);
  756. main_ui_->actionAnalyzeAAFOrNotSelected->setEnabled(can_match_selected);
  757. main_ui_->actionAnalyzePAFSelected->setEnabled(can_match_selected);
  758. main_ui_->actionAnalyzePAFNotSelected->setEnabled(can_match_selected);
  759. main_ui_->actionAnalyzePAFAndSelected->setEnabled(can_match_selected);
  760. main_ui_->actionAnalyzePAFOrSelected->setEnabled(can_match_selected);
  761. main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(can_match_selected);
  762. main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(can_match_selected);
  763. main_ui_->actionViewExpandSubtrees->setEnabled(cap_file_->finfo_selected->tree_type != -1);
  764. // prev_abbrev = g_object_get_data(G_OBJECT(ui_manager_tree_view_menu), "menu_abbrev");
  765. // if (!prev_abbrev || (strcmp (prev_abbrev, abbrev) != 0)) {
  766. // /* No previous protocol or protocol changed - update Protocol Preferences menu */
  767. // module_t *prefs_module_p = prefs_find_module(abbrev);
  768. // rebuild_protocol_prefs_menu (prefs_module_p, properties);
  769. // g_object_set_data(G_OBJECT(ui_manager_tree_view_menu), "menu_abbrev", g_strdup(abbrev));
  770. // g_free (prev_abbrev);
  771. // }
  772. } else {
  773. // set_menu_sensitivity(ui_manager_tree_view_menu,
  774. // "/TreeViewPopup/GotoCorrespondingPacket", FALSE);
  775. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/Copy", FALSE);
  776. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ApplyasColumn", FALSE);
  777. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ApplyAsFilter", FALSE);
  778. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/PrepareaFilter", FALSE);
  779. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ColorizewithFilter", FALSE);
  780. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ProtocolPreferences",
  781. // FALSE);
  782. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/DisableProtocol", FALSE);
  783. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandSubtrees", FALSE);
  784. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/WikiProtocolPage",
  785. // FALSE);
  786. // set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/FilterFieldReference",
  787. // FALSE);
  788. main_ui_->actionFileExportPacketBytes->setEnabled(false);
  789. // set_menu_sensitivity(ui_manager_main_menubar,
  790. // "/Menubar/GoMenu/GotoCorrespondingPacket", FALSE);
  791. main_ui_->actionEditCopyDescription->setEnabled(false);
  792. main_ui_->actionEditCopyFieldName->setEnabled(false);
  793. main_ui_->actionEditCopyValue->setEnabled(false);
  794. main_ui_->actionEditCopyAsFilter->setEnabled(false);
  795. // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/ApplyasColumn", FALSE);
  796. main_ui_->actionAnalyzeAAFSelected->setEnabled(false);
  797. main_ui_->actionAnalyzeAAFNotSelected->setEnabled(false);
  798. main_ui_->actionAnalyzeAAFAndSelected->setEnabled(false);
  799. main_ui_->actionAnalyzeAAFOrSelected->setEnabled(false);
  800. main_ui_->actionAnalyzeAAFAndNotSelected->setEnabled(false);
  801. main_ui_->actionAnalyzeAAFOrNotSelected->setEnabled(false);
  802. main_ui_->actionAnalyzePAFSelected->setEnabled(false);
  803. main_ui_->actionAnalyzePAFNotSelected->setEnabled(false);
  804. main_ui_->actionAnalyzePAFAndSelected->setEnabled(false);
  805. main_ui_->actionAnalyzePAFOrSelected->setEnabled(false);
  806. main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(false);
  807. main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(false);
  808. main_ui_->actionViewExpandSubtrees->setEnabled(false);
  809. }
  810. }
  811. void MainWindow::interfaceSelectionChanged()
  812. {
  813. // XXX This doesn't disable the toolbar button when using
  814. // QtMacExtras.
  815. if (global_capture_opts.num_selected > 0 && capture_filter_valid_) {
  816. main_ui_->actionStartCapture->setEnabled(true);
  817. } else {
  818. main_ui_->actionStartCapture->setEnabled(false);
  819. }
  820. }
  821. void MainWindow::captureFilterSyntaxChanged(bool valid)
  822. {
  823. capture_filter_valid_ = valid;
  824. interfaceSelectionChanged();
  825. }
  826. void MainWindow::redissectPackets()
  827. {
  828. if (cap_file_)
  829. cf_redissect_packets(cap_file_);
  830. main_ui_->statusBar->expertUpdate();
  831. }
  832. void MainWindow::recreatePacketList()
  833. {
  834. prefs.num_cols = g_list_length(prefs.col_list);
  835. col_cleanup(&cfile.cinfo);
  836. build_column_format_array(&cfile.cinfo, prefs.num_cols, FALSE);
  837. packet_list_->updateAll();
  838. packet_list_->hide();
  839. packet_list_->show();
  840. cfile.columns_changed = FALSE; /* Reset value */
  841. }
  842. void MainWindow::setFeaturesEnabled(bool enabled)
  843. {
  844. main_ui_->menuBar->setEnabled(enabled);
  845. main_ui_->mainToolBar->setEnabled(enabled);
  846. main_ui_->displayFilterToolBar->setEnabled(enabled);
  847. if(enabled)
  848. {
  849. main_ui_->statusBar->clearMessage();
  850. }
  851. else
  852. {
  853. main_ui_->statusBar->showMessage(tr("Please wait while Wireshark is initializing . . ."));
  854. }
  855. }
  856. // On Qt4 + OS X with unifiedTitleAndToolBarOnMac set it's possible to make
  857. // the main window obnoxiously wide.
  858. // We might want to do something different here. We should probably merge
  859. // the dfilter and gui.filter_expressions code first.
  860. void MainWindow::addDisplayFilterButton(QString df_text)
  861. {
  862. struct filter_expression *cur_fe = *pfilter_expression_head;
  863. struct filter_expression *fe = g_new0(struct filter_expression, 1);
  864. QFontMetrics fm = main_ui_->displayFilterToolBar->fontMetrics();
  865. QString label = fm.elidedText(df_text, Qt::ElideMiddle, fm.height() * 15);
  866. fe->enabled = TRUE;
  867. fe->label = qstring_strdup(label);
  868. fe->expression = qstring_strdup(df_text);
  869. if (!cur_fe) {
  870. *pfilter_expression_head = fe;
  871. } else {
  872. while (cur_fe->next) {
  873. cur_fe = cur_fe->next;
  874. }
  875. cur_fe->next = fe;
  876. }
  877. prefs_main_write();
  878. filterExpressionsChanged();
  879. }
  880. void MainWindow::displayFilterButtonClicked()
  881. {
  882. QAction *dfb_action = qobject_cast<QAction*>(sender());
  883. if (dfb_action) {
  884. df_combo_box_->lineEdit()->setText(dfb_action->data().toString());
  885. df_combo_box_->applyDisplayFilter();
  886. df_combo_box_->lineEdit()->setFocus();
  887. }
  888. }
  889. // File Menu
  890. void MainWindow::on_actionFileOpen_triggered()
  891. {
  892. openCaptureFile();
  893. }
  894. void MainWindow::on_actionFileMerge_triggered()
  895. {
  896. mergeCaptureFile();
  897. }
  898. void MainWindow::on_actionFileImportFromHexDump_triggered()
  899. {
  900. importCaptureFile();
  901. }
  902. void MainWindow::on_actionFileClose_triggered() {
  903. if (testCaptureFileClose())
  904. main_ui_->mainStack->setCurrentWidget(main_welcome_);
  905. }
  906. void MainWindow::on_actionFileSave_triggered()
  907. {
  908. saveCaptureFile(cap_file_, FALSE);
  909. }
  910. void MainWindow::on_actionFileSaveAs_triggered()
  911. {
  912. saveAsCaptureFile(cap_file_, FALSE, TRUE);
  913. }
  914. void MainWindow::on_actionFileSetListFiles_triggered()
  915. {
  916. file_set_dialog_.exec();
  917. }
  918. void MainWindow::on_actionFileSetNextFile_triggered()
  919. {
  920. fileset_entry *entry = fileset_get_next();
  921. if (entry) {
  922. QString new_cf_path = entry->fullname;
  923. openCaptureFile(new_cf_path);
  924. }
  925. }
  926. void MainWindow::on_actionFileSetPreviousFile_triggered()
  927. {
  928. fileset_entry *entry = fileset_get_previous();
  929. if (entry) {
  930. QString new_cf_path = entry->fullname;
  931. openCaptureFile(new_cf_path);
  932. }
  933. }
  934. void MainWindow::on_actionFileExportPackets_triggered()
  935. {
  936. exportSelectedPackets();
  937. }
  938. void MainWindow::on_actionFileExportAsPlainText_triggered()
  939. {
  940. exportDissections(export_type_text);
  941. }
  942. void MainWindow::on_actionFileExportAsCSV_triggered()
  943. {
  944. exportDissections(export_type_csv);
  945. }
  946. void MainWindow::on_actionFileExportAsCArrays_triggered()
  947. {
  948. exportDissections(export_type_carrays);
  949. }
  950. void MainWindow::on_actionFileExportAsPSML_triggered()
  951. {
  952. exportDissections(export_type_psml);
  953. }
  954. void MainWindow::on_actionFileExportAsPDML_triggered()
  955. {
  956. exportDissections(export_type_pdml);
  957. }
  958. void MainWindow::on_actionFileExportPacketBytes_triggered()
  959. {
  960. QString file_name;
  961. if (!cap_file_ || !cap_file_->finfo_selected) return;
  962. file_name = QFileDialog::getSaveFileName(this,
  963. tr("Wireshark: Export Selected Packet Bytes"),
  964. wsApp->lastOpenDir().canonicalPath(),
  965. tr("Raw data (*.bin *.dat *.raw);;Any File (*.*)")
  966. );
  967. if (file_name.length() > 0) {
  968. const guint8 *data_p;
  969. int fd;
  970. data_p = tvb_get_ptr(cap_file_->finfo_selected->ds_tvb, 0, -1) +
  971. cap_file_->finfo_selected->start;
  972. fd = ws_open(file_name.toUtf8().constData(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
  973. if (fd == -1) {
  974. open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE);
  975. return;
  976. }
  977. if (write(fd, data_p, cfile.finfo_selected->length) < 0) {
  978. write_failure_alert_box(file_name.toUtf8().constData(), errno);
  979. ::close(fd);
  980. return;
  981. }
  982. if (::close(fd) < 0) {
  983. write_failure_alert_box(file_name.toUtf8().constData(), errno);
  984. return;
  985. }
  986. /* Save the directory name for future file dialogs. */
  987. wsApp->setLastOpenDir(&file_name);
  988. }
  989. }
  990. void MainWindow::on_actionFileExportSSLSessionKeys_triggered()
  991. {
  992. QString file_name;
  993. QString save_title;
  994. int keylist_len;
  995. keylist_len = ssl_session_key_count();
  996. /* don't show up the dialog, if no data has to be saved */
  997. if (keylist_len < 1) {
  998. /* shouldn't happen as the menu item should have been greyed out */
  999. QMessageBox::warning(
  1000. this,
  1001. tr("No Keys"),
  1002. tr("There are no SSL Session Keys to save."),
  1003. QMessageBox::Ok
  1004. );
  1005. return;
  1006. }
  1007. save_title.append(QString("Wireshark: Export SSL Session Keys (%1 key%2").
  1008. arg(keylist_len).arg(plurality(keylist_len, "", "s")));
  1009. file_name = QFileDialog::getSaveFileName(this,
  1010. save_title,
  1011. wsApp->lastOpenDir().canonicalPath(),
  1012. tr("SSL Session Keys (*.keys *.txt);;Any File (*.*)")
  1013. );
  1014. if (file_name.length() > 0) {
  1015. gchar *keylist;
  1016. int fd;
  1017. keylist = ssl_export_sessions();
  1018. fd = ws_open(file_name.toUtf8().constData(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
  1019. if (fd == -1) {
  1020. open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE);
  1021. g_free(keylist);
  1022. return;
  1023. }
  1024. /*
  1025. * Thanks, Microsoft, for not using size_t for the third argument to
  1026. * _write(). Presumably this string will be <= 4GiB long....
  1027. */
  1028. if (ws_write(fd, keylist, (unsigned int)strlen(keylist)) < 0) {
  1029. write_failure_alert_box(file_name.toUtf8().constData(), errno);
  1030. ::close(fd);
  1031. g_free(keylist);
  1032. return;
  1033. }
  1034. if (::close(fd) < 0) {
  1035. write_failure_alert_box(file_name.toUtf8().constData(), errno);
  1036. g_free(keylist);
  1037. return;
  1038. }
  1039. /* Save the directory name for future file dialogs. */
  1040. wsApp->setLastOpenDir(&file_name);
  1041. g_free(keylist);
  1042. }
  1043. }
  1044. void MainWindow::on_actionFileExportObjectsDICOM_triggered()
  1045. {
  1046. new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Dicom);
  1047. }
  1048. void MainWindow::on_actionFileExportObjectsHTTP_triggered()
  1049. {
  1050. new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Http);
  1051. }
  1052. void MainWindow::on_actionFileExportObjectsSMB_triggered()
  1053. {
  1054. new ExportObjectDialog(this, cap_file_, ExportObjectDialog::Smb);
  1055. }
  1056. void MainWindow::on_actionFilePrint_triggered()
  1057. {
  1058. PrintDialog pdlg(this, cap_file_);
  1059. pdlg.exec();
  1060. }
  1061. // Edit Menu
  1062. // XXX This should probably be somewhere else.
  1063. void MainWindow::actionEditCopyTriggered(MainWindow::CopySelected selection_type)
  1064. {
  1065. char label_str[ITEM_LABEL_LENGTH];
  1066. QString clip;
  1067. if (!cap_file_) return;
  1068. switch(selection_type) {
  1069. case CopySelectedDescription:
  1070. if (cap_file_->finfo_selected->rep &&
  1071. strlen (cap_file_->finfo_selected->rep->representation) > 0) {
  1072. clip.append(cap_file_->finfo_selected->rep->representation);
  1073. }
  1074. break;
  1075. case CopySelectedFieldName:
  1076. if (cap_file_->finfo_selected->hfinfo->abbrev != 0) {
  1077. clip.append(cap_file_->finfo_selected->hfinfo->abbrev);
  1078. }
  1079. break;
  1080. case CopySelectedValue:
  1081. if (cap_file_->edt != 0) {
  1082. clip.append(get_node_field_value(cap_file_->finfo_selected, cap_file_->edt));
  1083. }
  1084. break;
  1085. }
  1086. if (clip.length() == 0) {
  1087. /* If no representation then... Try to read the value */
  1088. proto_item_fill_label(cap_file_->finfo_selected, label_str);
  1089. clip.append(label_str);
  1090. }
  1091. if (clip.length()) {
  1092. wsApp->clipboard()->se

Large files files are truncated, but you can click here to view the full file