Sandboxie/SandboxiePlus/SandMan/Windows/OptionsStop.cpp

179 lines
5.1 KiB
C++
Raw Normal View History

2021-10-16 16:19:51 +01:00
#include "stdafx.h"
#include "OptionsWindow.h"
#include "SandMan.h"
#include "SettingsWindow.h"
#include "../MiscHelpers/Common/Settings.h"
#include "../MiscHelpers/Common/Common.h"
#include "../MiscHelpers/Common/ComboInputDialog.h"
#include "../MiscHelpers/Common/SettingsWidgets.h"
#include "Helpers/WinAdmin.h"
void COptionsWindow::LoadStop()
{
ui.treeStop->clear();
foreach(const QString& Value, m_pBox->GetTextList("LingerProcess", m_Template))
2022-09-29 17:28:48 +01:00
AddStopEntry(Value);
2021-12-03 19:26:09 +00:00
foreach(const QString& Value, m_pBox->GetTextList("LingerProcessDisabled", m_Template))
2022-09-29 17:28:48 +01:00
AddStopEntry(Value, true);
LoadStopTmpl();
2021-12-03 19:26:09 +00:00
2022-09-29 17:28:48 +01:00
ui.treeLeader->clear();
2021-10-16 16:19:51 +01:00
foreach(const QString& Value, m_pBox->GetTextList("LeaderProcess", m_Template))
2022-09-29 17:28:48 +01:00
AddLeaderEntry(Value);
2021-12-03 19:26:09 +00:00
foreach(const QString& Value, m_pBox->GetTextList("LeaderProcessDisabled", m_Template))
2022-09-29 17:28:48 +01:00
AddLeaderEntry(Value, true);
LoadLeaderTmpl();
2021-10-16 16:19:51 +01:00
2024-03-23 11:14:25 +00:00
ui.chkNoStopWnd->setChecked(m_pBox->GetBool("LingerExemptWnds", true));
ui.chkLingerLeniency->setChecked(m_pBox->GetBool("LingerLeniency", true));
2021-10-16 16:19:51 +01:00
m_StopChanged = false;
}
void COptionsWindow::LoadStopTmpl(bool bUpdate)
{
if (ui.chkShowStopTmpl->isChecked())
{
foreach(const QString & Template, m_pBox->GetTemplates())
{
foreach(const QString & Value, m_pBox->GetTextListTmpl("LingerProcess", Template))
2022-09-29 17:28:48 +01:00
AddStopEntry(Value, false, Template);
2021-10-16 16:19:51 +01:00
}
}
else if (bUpdate)
{
for (int i = 0; i < ui.treeStop->topLevelItemCount(); )
{
QTreeWidgetItem* pItem = ui.treeStop->topLevelItem(i);
2022-09-29 17:28:48 +01:00
int Type = pItem->data(1, Qt::UserRole).toInt();
2021-10-16 16:19:51 +01:00
if (Type == -1) {
delete pItem;
continue; // entry from template
}
i++;
}
}
}
2022-09-29 17:28:48 +01:00
void COptionsWindow::LoadLeaderTmpl(bool bUpdate)
{
if (ui.chkShowLeaderTmpl->isChecked())
{
foreach(const QString & Template, m_pBox->GetTemplates())
{
foreach(const QString & Value, m_pBox->GetTextListTmpl("LeaderProcess", Template))
AddLeaderEntry(Value, false, Template);
}
}
else if (bUpdate)
{
for (int i = 0; i < ui.treeLeader->topLevelItemCount(); )
{
QTreeWidgetItem* pItem = ui.treeLeader->topLevelItem(i);
int Type = pItem->data(1, Qt::UserRole).toInt();
if (Type == -1) {
delete pItem;
continue; // entry from template
}
i++;
}
}
}
void COptionsWindow::AddStopEntry(const QString& Name, bool disabled, const QString& Template)
2021-10-16 16:19:51 +01:00
{
QTreeWidgetItem* pItem = new QTreeWidgetItem();
2021-12-03 19:26:09 +00:00
pItem->setCheckState(0, disabled ? Qt::Unchecked : Qt::Checked);
2022-09-29 17:28:48 +01:00
pItem->setData(1, Qt::UserRole, Template.isEmpty() ? 0 : -1);
SetProgramItem(Name, pItem, 0, (Template.isEmpty() ? "" : " (" + Template + ")"));
2021-12-03 19:26:09 +00:00
if(Template.isEmpty())
pItem->setFlags(pItem->flags() | Qt::ItemIsEditable);
2021-10-16 16:19:51 +01:00
ui.treeStop->addTopLevelItem(pItem);
}
2022-09-29 17:28:48 +01:00
void COptionsWindow::AddLeaderEntry(const QString& Name, bool disabled, const QString& Template)
{
QTreeWidgetItem* pItem = new QTreeWidgetItem();
pItem->setCheckState(0, disabled ? Qt::Unchecked : Qt::Checked);
pItem->setData(1, Qt::UserRole, Template.isEmpty() ? 0 : -1);
SetProgramItem(Name, pItem, 0, (Template.isEmpty() ? "" : " (" + Template + ")"));
if(Template.isEmpty())
pItem->setFlags(pItem->flags() | Qt::ItemIsEditable);
ui.treeLeader->addTopLevelItem(pItem);
}
2021-10-16 16:19:51 +01:00
void COptionsWindow::SaveStop()
{
QStringList LingerProcess;
2022-09-29 17:28:48 +01:00
QStringList LingerProcessDisabled;
2021-10-16 16:19:51 +01:00
for (int i = 0; i < ui.treeStop->topLevelItemCount(); i++)
{
QTreeWidgetItem* pItem = ui.treeStop->topLevelItem(i);
2022-09-29 17:28:48 +01:00
int Type = pItem->data(1, Qt::UserRole).toInt();
2021-10-16 16:19:51 +01:00
if (Type == -1)
continue; // entry from template
2022-09-29 17:28:48 +01:00
if (pItem->checkState(0) == Qt::Checked)
LingerProcess.append(pItem->data(0, Qt::UserRole).toString());
else
LingerProcessDisabled.append(pItem->data(0, Qt::UserRole).toString());
2021-10-16 16:19:51 +01:00
}
WriteTextList("LingerProcess", LingerProcess);
2022-09-29 17:28:48 +01:00
WriteTextList("LingerProcessDisabled", LingerProcessDisabled);
QStringList LeaderProcess;
QStringList LeaderProcessDisabled;
for (int i = 0; i < ui.treeLeader->topLevelItemCount(); i++)
{
QTreeWidgetItem* pItem = ui.treeLeader->topLevelItem(i);
int Type = pItem->data(1, Qt::UserRole).toInt();
if (Type == -1)
continue; // entry from template
if (pItem->checkState(0) == Qt::Checked)
LeaderProcess.append(pItem->data(0, Qt::UserRole).toString());
else
LeaderProcessDisabled.append(pItem->data(0, Qt::UserRole).toString());
}
2021-10-16 16:19:51 +01:00
WriteTextList("LeaderProcess", LeaderProcess);
2022-09-29 17:28:48 +01:00
WriteTextList("LeaderProcessDisabled", LeaderProcessDisabled);
2021-10-16 16:19:51 +01:00
2024-03-23 11:14:25 +00:00
WriteAdvancedCheck(ui.chkNoStopWnd, "LingerExemptWnds", "", "n");
WriteAdvancedCheck(ui.chkLingerLeniency, "LingerLeniency", "", "n");
2021-10-16 16:19:51 +01:00
m_StopChanged = false;
}
void COptionsWindow::OnAddLingering()
{
QString Value = SelectProgram();
if (Value.isEmpty())
return;
2022-09-29 17:28:48 +01:00
AddStopEntry(Value);
2021-10-16 16:19:51 +01:00
m_StopChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::OnAddLeader()
{
QString Value = SelectProgram();
if (Value.isEmpty())
return;
2022-09-29 17:28:48 +01:00
AddLeaderEntry(Value);
2021-10-16 16:19:51 +01:00
m_StopChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::OnDelStopProg()
{
2022-09-29 17:28:48 +01:00
DeleteAccessEntry(ui.treeStop->currentItem(), 1);
m_StopChanged = true;
OnOptChanged();
}
void COptionsWindow::OnDelLeader()
{
DeleteAccessEntry(ui.treeLeader->currentItem(), 1);
2021-10-16 16:19:51 +01:00
m_StopChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}