When deleting temp files, remove from the recent file list. Closes #1540

* If the UI was launched with a filename as a parameter to open the capture, it
  will be added to the recent capture file list. Only later (relatively
  speaking) if we make a capture connection will we realise that it is temporary
  and potentially delete the file. If we do so, remove the capture from the
  recent file list.
This commit is contained in:
baldurk
2019-10-10 16:48:42 +01:00
parent 4a6235d9b7
commit e9dda8343f
9 changed files with 100 additions and 26 deletions
+10 -1
View File
@@ -809,7 +809,7 @@ void CaptureContext::LoadCaptureThreaded(const QString &captureFile, const Repla
if(!temporary)
{
AddRecentFile(Config().RecentCaptureFiles, origFilename, 10);
AddRecentFile(Config().RecentCaptureFiles, origFilename);
Config().Save();
}
@@ -1076,7 +1076,10 @@ void CaptureContext::RecompressCapture()
if(tempCap)
tempCap->Shutdown();
if(!tempFilename.isEmpty())
{
m_MainWindow->RemoveRecentCapture(tempFilename);
QFile::remove(tempFilename);
}
return;
}
@@ -1134,7 +1137,10 @@ void CaptureContext::RecompressCapture()
if(tempCap)
tempCap->Shutdown();
if(!tempFilename.isEmpty())
{
m_MainWindow->RemoveRecentCapture(tempFilename);
QFile::remove(tempFilename);
}
}
bool CaptureContext::SaveCaptureTo(const rdcstr &captureFile)
@@ -1195,7 +1201,10 @@ bool CaptureContext::SaveCaptureTo(const rdcstr &captureFile)
// if it was a temporary capture, remove the old instnace
if(m_CaptureTemporary)
{
m_MainWindow->RemoveRecentCapture(m_CaptureFile);
QFile::remove(m_CaptureFile);
}
// Update the filename, and mark that it's local and not temporary now.
m_CaptureFile = captureFile;
+26 -12
View File
@@ -502,7 +502,23 @@ bool PersistantConfig::Save()
LastFileBrowsePath = RDDialog::DefaultBrowsePath;
return Serialize(m_Filename);
// truncate the lists to a maximum of 9 items, allow more to exist in memory
rdcarray<rdcstr> capFiles = RecentCaptureFiles;
rdcarray<rdcstr> capSettings = RecentCaptureSettings;
// the oldest items are first, so remove from there
while(RecentCaptureFiles.count() >= 10)
RecentCaptureFiles.erase(0);
while(RecentCaptureSettings.count() >= 10)
RecentCaptureSettings.erase(0);
bool ret = Serialize(m_Filename);
// restore lists
RecentCaptureFiles = capFiles;
RecentCaptureSettings = capSettings;
return ret;
}
void PersistantConfig::Close()
@@ -515,7 +531,12 @@ void PersistantConfig::SetupFormatting()
Formatter::setParams(*this);
}
void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file, int maxItems)
void RemoveRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file)
{
recentList.removeOne(QDir::cleanPath(file));
}
void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file)
{
QDir dir(file);
QString path = dir.canonicalPath();
@@ -526,17 +547,10 @@ void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file, int maxItem
return;
}
if(!recentList.contains(path))
{
recentList.push_back(path);
if(recentList.count() >= maxItems)
recentList.erase(0);
}
else
{
if(recentList.contains(path))
recentList.removeOne(path);
recentList.push_back(path);
}
recentList.push_back(path);
}
void PersistantConfig::SetConfigSetting(const rdcstr &name, const rdcstr &value)
+12 -4
View File
@@ -435,16 +435,24 @@ inline rdcstr UnitSuffix(TimeUnit unit)
}
DOCUMENT(R"(Checks if a given file is in a list. If it is, then it's shuffled to the end. If it's
not then it's added to the end and an item is dropped from the front of the list if necessary to
stay within a given maximum
not then it's added to the end
As the name suggests, this is used for tracking a 'recent file' list.
:param list recentList: A ``list`` of ``str`` that is mutated by the function.
:param str file: The file to add to the list.
:param int maxItems: The maximum allowed length of the list.
)");
void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file, int maxItems);
void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file);
DOCUMENT(R"(Removes a given file from the list, after normalising the path. If the path isn't
present then the list is not modified.
As the name suggests, this is used for tracking a 'recent file' list.
:param list recentList: A ``list`` of ``str`` that is mutated by the function.
:param str file: The file to remove from the list.
)");
void RemoveRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file);
DOCUMENT2(R"(A persistant config file that is automatically loaded and saved, which contains any
settings and information that needs to be preserved from one run to the next.
+1 -1
View File
@@ -64,7 +64,7 @@ void ReplayManager::OpenCapture(const QString &capturefile, const ReplayOptions
void ReplayManager::DeleteCapture(const rdcstr &capture, bool local)
{
if(IsRunning())
if(IsRunning() && !m_Thread->isCurrentThread())
{
AsyncInvoke([this, capture, local](IReplayController *) { DeleteCapture(capture, local); });
return;
@@ -151,7 +151,11 @@ void PersistantConfig::SetupFormatting()
{
}
void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file, int maxItems)
void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file)
{
}
void RemoveRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file)
{
}
+2 -2
View File
@@ -873,7 +873,7 @@ void CaptureDialog::on_saveSettings_clicked()
if(dirinfo.exists())
{
SaveSettings(filename);
AddRecentFile(m_Ctx.Config().RecentCaptureSettings, filename, 10);
AddRecentFile(m_Ctx.Config().RecentCaptureSettings, filename);
m_Main->PopulateRecentCaptureSettings();
}
}
@@ -887,7 +887,7 @@ void CaptureDialog::on_loadSettings_clicked()
if(!filename.isEmpty() && QFileInfo::exists(filename))
{
LoadSettings(filename);
AddRecentFile(m_Ctx.Config().RecentCaptureSettings, filename, 10);
AddRecentFile(m_Ctx.Config().RecentCaptureSettings, filename);
}
}
+12 -1
View File
@@ -396,6 +396,11 @@ void LiveCapture::deleteCapture_triggered()
{
m_Ctx.Replay().DeleteCapture(cap->path, cap->local);
}
if(cap->saved || cap->local)
{
m_Main->RemoveRecentCapture(cap->path);
}
}
}
@@ -844,9 +849,10 @@ bool LiveCapture::saveCapture(Capture *cap, QString path)
if(!cap->saved)
m_Ctx.Replay().DeleteCapture(cap->path, cap->local);
m_Main->RemoveRecentCapture(cap->path);
cap->saved = true;
cap->path = path;
AddRecentFile(m_Ctx.Config().RecentCaptureFiles, path, 10);
AddRecentFile(m_Ctx.Config().RecentCaptureFiles, path);
m_Main->PopulateRecentCaptureFiles();
return true;
}
@@ -875,6 +881,11 @@ void LiveCapture::cleanItems()
{
m_Ctx.Replay().DeleteCapture(cap->path, cap->local);
}
if(cap->saved || cap->local)
{
m_Main->RemoveRecentCapture(cap->path);
}
}
}
+30 -4
View File
@@ -911,7 +911,7 @@ bool MainWindow::PromptSaveCaptureAs()
if(!success)
return false;
AddRecentFile(m_Ctx.Config().RecentCaptureFiles, saveFilename, 10);
AddRecentFile(m_Ctx.Config().RecentCaptureFiles, saveFilename);
PopulateRecentCaptureFiles();
SetTitle(saveFilename);
@@ -1025,15 +1025,28 @@ bool MainWindow::PromptCloseCapture()
CloseCapture();
if(!deletepath.isEmpty())
{
m_Ctx.Replay().DeleteCapture(deletepath, caplocal);
RemoveRecentCapture(deletepath);
}
return true;
}
void MainWindow::CloseCapture()
{
QString path = m_Ctx.GetCaptureFilename();
bool local = m_Ctx.IsCaptureLocal();
m_Ctx.CloseCapture();
if(m_OwnTempCapture)
{
m_Ctx.Replay().DeleteCapture(path, local);
RemoveRecentCapture(path);
m_OwnTempCapture = false;
}
ui->action_Save_Capture_Inplace->setEnabled(false);
ui->action_Save_Capture_As->setEnabled(false);
ui->menu_Export_As->setEnabled(false);
@@ -1141,6 +1154,10 @@ void MainWindow::PopulateRecentCaptureFiles()
idx++;
ui->menu_Recent_Capture_Files->setEnabled(true);
// only populate the 9 most recent, even if more exist in memory
if(idx == 10)
break;
}
ui->menu_Recent_Capture_Files->addSeparator();
@@ -1170,6 +1187,10 @@ void MainWindow::PopulateRecentCaptureSettings()
idx++;
ui->menu_Recent_Capture_Settings->setEnabled(true);
// only populate the 9 most recent, even if more exist in memory
if(idx == 10)
break;
}
ui->menu_Recent_Capture_Settings->addSeparator();
@@ -1545,6 +1566,13 @@ void MainWindow::show()
QMainWindow::show();
}
void MainWindow::RemoveRecentCapture(const QString &filename)
{
RemoveRecentFile(m_Ctx.Config().RecentCaptureFiles, filename);
PopulateRecentCaptureFiles();
}
void MainWindow::recentCaptureFile(const QString &filename)
{
if(QFileInfo::exists(filename))
@@ -1559,9 +1587,7 @@ void MainWindow::recentCaptureFile(const QString &filename)
if(res == QMessageBox::Yes)
{
m_Ctx.Config().RecentCaptureFiles.removeOne(filename);
PopulateRecentCaptureFiles();
RemoveRecentCapture(filename);
}
}
}
+2
View File
@@ -91,6 +91,8 @@ public:
void ShowLiveCapture(LiveCapture *live);
void LiveCaptureClosed(LiveCapture *live);
void RemoveRecentCapture(const QString &filename);
QMenu *GetBaseMenu(WindowMenu base, rdcstr name);
QList<QAction *> GetMenuActions();