Fix some edge cases when handling unsaved captures. Closes #2554

* The 'no to all' option should always be present if there are multiple unsaved
  captures across the connections, even if the current connection only has one
  capture and so otherwise wouldn't have a 'no to all' option.
* The 'no to all' option will always discard all unsaved captures in all
  connections when closing the window, if the user clicks no on the confirmation
  of this, abort the close operation entirely and let them decide how to handle
  it (e.g. discarding/saving captures in connections individually).
This commit is contained in:
baldurk
2022-04-18 17:06:44 +01:00
parent 26585e9a1b
commit dee3c37d90
3 changed files with 74 additions and 46 deletions
+36 -9
View File
@@ -690,7 +690,7 @@ QString LiveCapture::MakeText(Capture *cap)
return text;
}
bool LiveCapture::checkAllowClose(bool multipleClosures, bool &noToAll)
bool LiveCapture::checkAllowClose(int totalUnsavedCaptures, bool &noToAll)
{
m_IgnoreThreadClosed = true;
@@ -698,7 +698,10 @@ bool LiveCapture::checkAllowClose(bool multipleClosures, bool &noToAll)
QMessageBox::StandardButtons msgFlags = RDDialog::YesNoCancel;
if(ui->captures->count() > 1)
const int unsavedCaptures = unsavedCaptureCount();
const bool multipleClosures = totalUnsavedCaptures > unsavedCaptures;
if(unsavedCaptures > 1 || multipleClosures)
msgFlags |= QMessageBox::NoToAll;
for(int i = 0; i < ui->captures->count(); i++)
@@ -734,16 +737,25 @@ bool LiveCapture::checkAllowClose(bool multipleClosures, bool &noToAll)
// if we're closing multiple connections make sure the user is sure of what they're doing
if(multipleClosures)
{
QMessageBox::StandardButton res2 =
RDDialog::question(this, tr("Discarding all captures"),
tr("Multiple connections open have potentially unsaved captures, "
"are you sure you wish to discard them all?"));
QMessageBox::StandardButton res2 = RDDialog::question(
this, tr("Discarding all captures"),
tr("Multiple connections open have potentially unsaved captures, "
"this will discard all captures in all connections, are you sure?"));
// if the user is sure, apply the no to all
if(res2 == QMessageBox::Yes)
{
noToAll = true;
// otherwise we'll treat this as a simple 'no' in case they changed their mind.
}
else
{
// otherwise if the user changed their mind at this stage, cancel everything rather than
// trying to continue, to keep the flow simple and ensure the user is clear what is
// happening at all points. We do not support discarding all captures in one connection
// then individually filtering another.
m_IgnoreThreadClosed = false;
return false;
}
}
else
{
@@ -808,7 +820,7 @@ bool LiveCapture::checkAllowClose(bool multipleClosures, bool &noToAll)
bool LiveCapture::checkAllowClose()
{
bool dummy = false;
return checkAllowClose(false, dummy);
return checkAllowClose(unsavedCaptureCount(), dummy);
}
void LiveCapture::openCapture(Capture *cap)
@@ -980,6 +992,21 @@ void LiveCapture::fileSaved(QString from, QString to)
}
}
int LiveCapture::unsavedCaptureCount()
{
int ret = 0;
for(int i = 0; i < ui->captures->count(); i++)
{
Capture *cap = GetCapture(ui->captures->item(i));
if(!cap->saved)
ret++;
}
return ret;
}
void LiveCapture::previewToggle_toggled(bool checked)
{
if(m_IgnorePreviewToggle)