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>
This commit is contained in:
Stig Bjørlykke 2016-01-25 22:11:55 +01:00
parent 06e5197867
commit a7d07e9edc
3 changed files with 27 additions and 5 deletions

View File

@ -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());
}

View File

@ -124,7 +124,8 @@ private:
enum FileCloseContext {
Default,
Quit,
Restart
Restart,
Reload
};
Ui::MainWindow *main_ui_;

View File

@ -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 */