diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2016-01-25 22:11:55 +0100 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2016-01-26 18:14:17 +0000 |
commit | a7d07e9edcf6643c098347470123605e378eda68 (patch) | |
tree | 801f4ecd4211de9e6668ceccefdfaec8f75f6b43 /ui | |
parent | 06e519786731a962403710d6cf30e8d4dabd42b2 (diff) | |
download | wireshark-a7d07e9edcf6643c098347470123605e378eda68.tar.gz |
Qt: Check for file changes on Reload
Check if having unsaved changes and offer a save before reload
and reload as file format/capture.
Bug: 12003
Change-Id: Ic4282e0a17a4ec745e729eb93863fc15e7ec611b
Reviewed-on: https://code.wireshark.org/review/13535
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/main_window.cpp | 13 | ||||
-rw-r--r-- | ui/qt/main_window.h | 3 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 16 |
3 files changed, 27 insertions, 5 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index f7777663f5..2dbcd25074 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -1592,8 +1592,14 @@ bool MainWindow::testCaptureFileClose(QString before_what, FileCloseContext cont question = tr("Do you want to stop the capture and save the captured packets%1?").arg(before_what); infotext = tr("Your captured packets will be lost if you don't save them."); } else if (capture_file_.capFile()->is_tempfile) { - question = tr("Do you want to save the captured packets%1?").arg(before_what); - infotext = tr("Your captured packets will be lost if you don't save them."); + if (context == Reload) { + // Reloading a tempfile will keep the packets, so this is not unsaved packets + question = tr("Do you want to save the changes you've made%1?").arg(before_what); + infotext = tr("Your changes will be lost if you don't save them."); + } else { + question = tr("Do you want to save the captured packets%1?").arg(before_what); + infotext = tr("Your captured packets will be lost if you don't save them."); + } } else { // No capture in progress and not a tempfile, so this is not unsaved packets gchar *display_basename = g_filename_display_basename(capture_file_.capFile()->filename); @@ -1691,7 +1697,8 @@ bool MainWindow::testCaptureFileClose(QString before_what, FileCloseContext cont captureStop(); #endif /* captureStop() will close the file if not having any packets */ - if (capture_file_.capFile()) + if (capture_file_.capFile() && context != Restart && context != Reload) + // Don't really close if Restart or Reload cf_close(capture_file_.capFile()); } diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 311005c8f0..20c7233f32 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -124,7 +124,8 @@ private: enum FileCloseContext { Default, Quit, - Restart + Restart, + Reload }; Ui::MainWindow *main_ui_; diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 574c522545..56bbec4c30 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -2506,13 +2506,27 @@ void MainWindow::on_actionContextShowLinkedPacketInNewWindow_triggered() void MainWindow::on_actionViewReload_triggered() { - cf_reload(CaptureFile::globalCapFile()); + capture_file *cf = CaptureFile::globalCapFile(); + + if (cf->unsaved_changes) { + QString before_what(tr(" before reloading the file")); + if (!testCaptureFileClose(before_what, Reload)) + return; + } + + cf_reload(cf); } void MainWindow::on_actionViewReload_as_File_Format_or_Capture_triggered() { capture_file *cf = CaptureFile::globalCapFile(); + if (cf->unsaved_changes) { + QString before_what(tr(" before reloading the file")); + if (!testCaptureFileClose(before_what, Reload)) + return; + } + if (cf->open_type == WTAP_TYPE_AUTO) cf->open_type = open_info_name_to_type("MIME Files Format"); else /* TODO: This should be latest format chosen by user */ |