Sandboxie/SandboxiePlus/SandMan/Views/SbieView.cpp

975 lines
36 KiB
C++
Raw Normal View History

2020-06-01 17:11:56 +01:00
#include "stdafx.h"
#include "SbieView.h"
#include "..\SandMan.h"
#include "../QSbieAPI/SbieAPI.h"
2020-11-28 16:20:56 +00:00
#include "../QSbieAPI/SbieUtils.h"
2020-06-01 17:11:56 +01:00
#include "../../MiscHelpers/Common/SortFilterProxyModel.h"
#include "../../MiscHelpers/Common/Settings.h"
2020-11-28 16:20:56 +00:00
#include "../../MiscHelpers/Common/Common.h"
2020-07-19 21:09:02 +01:00
#include "../Windows/OptionsWindow.h"
2020-09-05 16:45:39 +01:00
#include "../Windows/SnapshotsWindow.h"
2020-12-22 14:50:58 +00:00
#include <QFileIconProvider>
2021-01-18 12:04:14 +00:00
#include "../../MiscHelpers/Common/CheckableMessageBox.h"
#include "../Windows/RecoveryWindow.h"
2021-02-01 19:13:09 +00:00
#include "../Windows/NewBoxWindow.h"
2020-06-01 17:11:56 +01:00
2020-10-10 17:18:01 +01:00
#include "qt_windows.h"
#include "qwindowdefs_win.h"
#include <shellapi.h>
2020-06-01 17:11:56 +01:00
CSbieView::CSbieView(QWidget* parent) : CPanelView(parent)
{
m_pMainLayout = new QVBoxLayout();
m_pMainLayout->setMargin(0);
this->setLayout(m_pMainLayout);
m_pSbieModel = new CSbieModel();
m_pSbieModel->SetTree(true);
m_pSbieModel->SetUseIcons(true);
m_pSortProxy = new CSortFilterProxyModel(false, this);
m_pSortProxy->setSortRole(Qt::EditRole);
m_pSortProxy->setSourceModel(m_pSbieModel);
m_pSortProxy->setDynamicSortFilter(true);
// SbieTree
m_pSbieTree = new QTreeViewEx();
2021-01-18 12:04:14 +00:00
m_pSbieTree->setExpandsOnDoubleClick(false);
2020-06-01 17:11:56 +01:00
//m_pSbieTree->setItemDelegate(theGUI->GetItemDelegate());
m_pSbieTree->setModel(m_pSortProxy);
2021-02-14 19:18:29 +00:00
((CSortFilterProxyModel*)m_pSortProxy)->setView(m_pSbieTree);
2020-06-01 17:11:56 +01:00
m_pSbieTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_pSbieTree->setSortingEnabled(true);
m_pSbieTree->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_pSbieTree, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnMenu(const QPoint &)));
2020-07-19 21:09:02 +01:00
connect(m_pSbieTree, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(OnDoubleClicked(const QModelIndex&)));
2020-06-01 17:11:56 +01:00
connect(m_pSbieTree->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(ProcessSelection(QItemSelection, QItemSelection)));
//connect(theGUI, SIGNAL(ReloadPanels()), m_pSbieModel, SLOT(Clear()));
m_pMainLayout->addWidget(m_pSbieTree);
//
m_pMainLayout->addWidget(new CFinder(m_pSortProxy, this));
2020-07-04 11:07:36 +01:00
connect(m_pSbieModel, SIGNAL(ToolTipCallback(const QVariant&, QString&)), this, SLOT(OnToolTipCallback(const QVariant&, QString&)), Qt::DirectConnection);
2021-02-01 19:13:09 +00:00
m_pNewBox = m_pMenu->addAction(CSandMan::GetIcon("NewBox"), tr("Create New Box"), this, SLOT(OnGroupAction()));
2020-12-22 14:50:58 +00:00
m_pAddGroupe = m_pMenu->addAction(CSandMan::GetIcon("Group"), tr("Add Group"), this, SLOT(OnGroupAction()));
m_pDelGroupe = m_pMenu->addAction(CSandMan::GetIcon("Remove"), tr("Remove Group"), this, SLOT(OnGroupAction()));
2020-12-07 16:34:20 +00:00
m_iMenuTop = m_pMenu->actions().count();
//m_pMenu->addSeparator();
2020-12-22 14:50:58 +00:00
m_pMenuRun = m_pMenu->addMenu(CSandMan::GetIcon("Start"), tr("Run"));
m_pMenuRunAny = m_pMenuRun->addAction(CSandMan::GetIcon("Run"), tr("Run Program"), this, SLOT(OnSandBoxAction()));
m_pMenuRunMenu = m_pMenuRun->addAction(CSandMan::GetIcon("StartMenu"), tr("Run from Start Menu"), this, SLOT(OnSandBoxAction()));
2021-07-05 12:37:28 +01:00
m_pMenuRunBrowser = m_pMenuRun->addAction(CSandMan::GetIcon("Internet"), tr("Default Web Browser"), this, SLOT(OnSandBoxAction()));
m_pMenuRunMailer = m_pMenuRun->addAction(CSandMan::GetIcon("Email"), tr("Default eMail Client"), this, SLOT(OnSandBoxAction()));
m_pMenuRunExplorer = m_pMenuRun->addAction(CSandMan::GetIcon("Explore"), tr("Windows Explorer"), this, SLOT(OnSandBoxAction()));
m_pMenuRunRegEdit = m_pMenuRun->addAction(CSandMan::GetIcon("RegEdit"), tr("Registry Editor"), this, SLOT(OnSandBoxAction()));
m_pMenuRunAppWiz = m_pMenuRun->addAction(CSandMan::GetIcon("Software"), tr("Programs and Features"), this, SLOT(OnSandBoxAction()));
m_pMenuRunCmd = m_pMenuRun->addAction(CSandMan::GetIcon("Cmd"), tr("Terminal"), this, SLOT(OnSandBoxAction()));
m_pMenuRunCmdAdmin = m_pMenuRun->addAction(CSandMan::GetIcon("Cmd"), tr("Terminal (as Admin)"), this, SLOT(OnSandBoxAction()));
2020-11-28 16:20:56 +00:00
m_pMenuRun->addSeparator();
m_iMenuRun = m_pMenuRun->actions().count();
2020-12-22 14:50:58 +00:00
m_pMenuEmptyBox = m_pMenu->addAction(CSandMan::GetIcon("EmptyAll"), tr("Terminate All Programs"), this, SLOT(OnSandBoxAction()));
2020-06-01 17:11:56 +01:00
m_pMenu->addSeparator();
2020-12-29 08:54:59 +00:00
m_pMenuMkLink = m_pMenu->addAction(CSandMan::GetIcon("MkLink"), tr("Create Shortcut"), this, SLOT(OnSandBoxAction()));
2020-10-10 17:18:01 +01:00
m_pMenu->addSeparator();
2020-12-22 14:50:58 +00:00
m_pMenuExplore = m_pMenu->addAction(CSandMan::GetIcon("Explore"), tr("Explore Content"), this, SLOT(OnSandBoxAction()));
m_pMenuSnapshots = m_pMenu->addAction(CSandMan::GetIcon("Snapshots"), tr("Snapshots Manager"), this, SLOT(OnSandBoxAction()));
m_pMenuRecover = m_pMenu->addAction(CSandMan::GetIcon("Recover"), tr("Recover Files"), this, SLOT(OnSandBoxAction()));
m_pMenuCleanUp = m_pMenu->addAction(CSandMan::GetIcon("Erase"), tr("Delete Content"), this, SLOT(OnSandBoxAction()));
2020-06-01 17:11:56 +01:00
m_pMenu->addSeparator();
2020-12-22 14:50:58 +00:00
m_pMenuPresets = m_pMenu->addMenu(CSandMan::GetIcon("Presets"), tr("Sandbox Presets"));
2021-02-21 14:32:20 +00:00
m_pMenuPresetsAdmin = new QActionGroup(m_pMenuPresets);
m_pMenuPresetsShowUAC = MakeAction(m_pMenuPresetsAdmin, m_pMenuPresets, tr("Ask for UAC Elevation"), 0);
m_pMenuPresetsNoAdmin = MakeAction(m_pMenuPresetsAdmin, m_pMenuPresets, tr("Drop Admin Rights"), 1);
m_pMenuPresetsFakeAdmin = MakeAction(m_pMenuPresetsAdmin, m_pMenuPresets, tr("Emulate Admin Rights"), 1 | 2);
2021-06-13 17:11:04 +01:00
if (theAPI->IsRunningAsAdmin()) {
m_pMenuPresetsNoAdmin->setEnabled(false);
m_pMenuPresetsFakeAdmin->setEnabled(false);
}
2021-02-21 14:32:20 +00:00
connect(m_pMenuPresetsAdmin, SIGNAL(triggered(QAction*)), this, SLOT(OnSandBoxAction(QAction*)));
m_pMenuPresets->addSeparator();
2020-07-04 11:07:36 +01:00
m_pMenuPresetsINet = m_pMenuPresets->addAction(tr("Block Internet Access"), this, SLOT(OnSandBoxAction()));
m_pMenuPresetsINet->setCheckable(true);
m_pMenuPresetsShares = m_pMenuPresets->addAction(tr("Allow Network Shares"), this, SLOT(OnSandBoxAction()));
m_pMenuPresetsShares->setCheckable(true);
2020-12-22 14:50:58 +00:00
m_pMenuOptions = m_pMenu->addAction(CSandMan::GetIcon("Options"), tr("Sandbox Options"), this, SLOT(OnSandBoxAction()));
m_pMenuRename = m_pMenu->addAction(CSandMan::GetIcon("Rename"), tr("Rename Sandbox"), this, SLOT(OnSandBoxAction()));
2020-12-07 16:34:20 +00:00
m_iMoveTo = m_pMenu->actions().count();
2020-12-22 14:50:58 +00:00
m_pMenuMoveTo = m_pMenu->addMenu(CSandMan::GetIcon("Group"), tr("Move to Group"));
m_pMenuRemove = m_pMenu->addAction(CSandMan::GetIcon("Remove"), tr("Remove Sandbox"), this, SLOT(OnSandBoxAction()));
2020-06-01 17:11:56 +01:00
m_iMenuBox = m_pMenu->actions().count();
2020-11-28 16:20:56 +00:00
//UpdateRunMenu();
2020-12-22 14:50:58 +00:00
m_pMenuTerminate = m_pMenu->addAction(CSandMan::GetIcon("Remove"), tr("Terminate"), this, SLOT(OnProcessAction()));
2020-07-04 11:07:36 +01:00
m_pMenuTerminate->setShortcut(QKeySequence::Delete);
2020-12-29 08:54:59 +00:00
m_pMenuLinkTo = m_pMenu->addAction(CSandMan::GetIcon("MkLink"), tr("Create Shortcut"), this, SLOT(OnProcessAction()));
2020-07-04 11:07:36 +01:00
this->addAction(m_pMenuTerminate);
2020-11-16 16:15:03 +00:00
m_pMenuTerminate->setShortcutContext(Qt::WidgetWithChildrenShortcut);
2020-12-22 14:50:58 +00:00
m_pMenuPreset = m_pMenu->addMenu(CSandMan::GetIcon("Presets"), tr("Preset"));
2020-11-28 16:20:56 +00:00
m_pMenuPinToRun = m_pMenuPreset->addAction(tr("Pin to Run Menu"), this, SLOT(OnProcessAction()));
m_pMenuPinToRun->setCheckable(true);
2020-11-16 16:15:03 +00:00
m_pMenuBlackList = m_pMenuPreset->addAction(tr("Block and Terminate"), this, SLOT(OnProcessAction()));
m_pMenuBlackList->setShortcut(QKeySequence("Shift+Del"));
m_pMenuBlackList->setShortcutContext(Qt::WidgetWithChildrenShortcut);
this->addAction(m_pMenuBlackList);
2020-12-29 08:54:59 +00:00
m_pMenuAllowInternet = m_pMenuPreset->addAction(tr("Allow internet access"), this, SLOT(OnProcessAction()));
m_pMenuAllowInternet->setCheckable(true);
m_pMenuMarkForced = m_pMenuPreset->addAction(tr("Force into this sandbox"), this, SLOT(OnProcessAction()));
m_pMenuMarkForced->setCheckable(true);
2020-11-28 16:20:56 +00:00
m_pMenuMarkLinger = m_pMenuPreset->addAction(tr("Set Linger Process"), this, SLOT(OnProcessAction()));
2020-11-16 16:15:03 +00:00
m_pMenuMarkLinger->setCheckable(true);
2020-11-28 16:20:56 +00:00
m_pMenuMarkLeader = m_pMenuPreset->addAction(tr("Set Leader Process"), this, SLOT(OnProcessAction()));
2020-11-16 16:15:03 +00:00
m_pMenuMarkLeader->setCheckable(true);
2020-12-29 08:54:59 +00:00
//m_pMenuSuspend = m_pMenu->addAction(tr("Suspend"), this, SLOT(OnProcessAction()));
//m_pMenuResume = m_pMenu->addAction(tr("Resume"), this, SLOT(OnProcessAction()));
2020-06-01 17:11:56 +01:00
m_iMenuProc = m_pMenu->actions().count();
2020-11-28 16:20:56 +00:00
QByteArray Columns = theConf->GetBlob("MainWindow/BoxTree_Columns");
2020-06-01 17:11:56 +01:00
if (Columns.isEmpty())
2021-01-18 12:04:14 +00:00
{
2020-06-01 17:11:56 +01:00
m_pSbieTree->OnResetColumns();
2021-01-18 12:04:14 +00:00
m_pSbieTree->setColumnWidth(0, 300);
m_pSbieTree->setColumnWidth(1, 70);
m_pSbieTree->setColumnWidth(2, 70);
m_pSbieTree->setColumnWidth(3, 70);
}
2020-06-01 17:11:56 +01:00
else
m_pSbieTree->restoreState(Columns);
//m_pMenu = new QMenu();
AddPanelItemsToMenu();
}
CSbieView::~CSbieView()
{
2020-11-28 16:20:56 +00:00
theConf->SetBlob("MainWindow/BoxTree_Columns", m_pSbieTree->saveState());
2020-06-01 17:11:56 +01:00
}
2021-01-02 08:03:16 +00:00
void CSbieView::Clear()
{
m_Groups.clear();
m_pSbieModel->Clear();
}
2020-06-01 17:11:56 +01:00
void CSbieView::Refresh()
{
2021-01-26 20:58:43 +00:00
QList<QVariant> Added = m_pSbieModel->Sync(theAPI->GetAllBoxes(), m_Groups, theGUI->IsShowHidden());
2020-06-01 17:11:56 +01:00
if (m_pSbieModel->IsTree())
{
QTimer::singleShot(100, this, [this, Added]() {
foreach(const QVariant ID, Added) {
m_pSbieTree->expand(m_pSortProxy->mapFromSource(m_pSbieModel->FindIndex(ID)));
}
});
}
}
2020-07-04 11:07:36 +01:00
void CSbieView::OnToolTipCallback(const QVariant& ID, QString& ToolTip)
{
if (ID.type() == QVariant::String)
{
QString BoxName = ID.toString();
CSandBoxPtr pBox = theAPI->GetBoxByName(BoxName);
CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(pBox.data());
if (!pBoxEx)
return;
// todo more info
ToolTip = BoxName + "\n";
ToolTip += tr(" File root: %1\n").arg(pBoxEx->GetFileRoot());
ToolTip += tr(" Registry root: %1\n").arg(pBoxEx->GetRegRoot());
ToolTip += tr(" IPC root: %1\n").arg(pBoxEx->GetIpcRoot());
ToolTip += tr("Options:\n ");
ToolTip += pBoxEx->GetStatusStr().replace(", ", "\n ");
}
2020-11-28 16:20:56 +00:00
else if (quint32 ProcessId = ID.toUInt())
2020-07-04 11:07:36 +01:00
{
// todo proc info
}
}
2020-06-01 17:11:56 +01:00
void CSbieView::OnMenu(const QPoint& Point)
{
2021-01-06 12:19:13 +00:00
QList<QAction*> MenuActions = m_pMenu->actions();
bool isConnected = theAPI->IsConnected();
if (isConnected) {
foreach(QAction * pAction, MenuActions)
pAction->setEnabled(true);
}
2020-07-04 11:07:36 +01:00
CSandBoxPtr pBox;
CBoxedProcessPtr pProcess;
2020-06-01 17:11:56 +01:00
int iProcessCount = 0;
int iSandBoxeCount = 0;
2020-12-29 08:54:59 +00:00
//int iSuspendedCount = 0;
2020-12-07 16:34:20 +00:00
QModelIndexList Rows = m_pSbieTree->selectedRows();
foreach(const QModelIndex& Index, Rows)
2020-06-01 17:11:56 +01:00
{
QModelIndex ModelIndex = m_pSortProxy->mapToSource(Index);
2021-01-30 18:10:49 +00:00
2020-07-04 11:07:36 +01:00
pProcess = m_pSbieModel->GetProcess(ModelIndex);
2020-06-01 17:11:56 +01:00
if (pProcess)
{
iProcessCount++;
2020-12-29 08:54:59 +00:00
//if (pProcess->IsSuspended())
// iSuspendedCount++;
2020-06-01 17:11:56 +01:00
}
else
{
2020-07-04 11:07:36 +01:00
pBox = m_pSbieModel->GetSandBox(ModelIndex);
2021-01-30 18:10:49 +00:00
if (pBox)
{
if (!pBox->IsEnabled())
iSandBoxeCount = -1;
else if (iSandBoxeCount != -1)
iSandBoxeCount++;
}
2020-06-01 17:11:56 +01:00
}
}
2020-12-07 16:34:20 +00:00
for (int i = 0; i < m_iMenuTop; i++)
MenuActions[i]->setVisible(iSandBoxeCount == 0 && iProcessCount == 0);
m_pDelGroupe->setVisible(!Rows.isEmpty() && iSandBoxeCount == 0 && iProcessCount == 0);
for (int i = m_iMenuTop; i < m_iMenuBox; i++)
2021-01-26 20:58:43 +00:00
MenuActions[i]->setVisible(iSandBoxeCount != 0 && iProcessCount == 0);
2020-06-01 17:11:56 +01:00
m_pMenuRun->setEnabled(iSandBoxeCount == 1);
2020-11-28 16:20:56 +00:00
2020-12-07 16:34:20 +00:00
MenuActions[m_iMoveTo]->setVisible(!Rows.isEmpty() && iProcessCount == 0);
2020-11-28 16:20:56 +00:00
if(iSandBoxeCount == 1)
UpdateRunMenu(pBox);
m_pMenuMkLink->setEnabled(iSandBoxeCount == 1);
2020-06-01 17:11:56 +01:00
m_pMenuRename->setEnabled(iSandBoxeCount == 1);
2020-11-28 16:20:56 +00:00
m_pMenuRecover->setEnabled(iSandBoxeCount == 1);
2020-06-01 17:11:56 +01:00
2020-07-04 11:07:36 +01:00
m_pMenuPresets->setEnabled(iSandBoxeCount == 1);
2021-02-21 14:32:20 +00:00
m_pMenuPresetsShowUAC->setChecked(pBox && !pBox->GetBool("DropAdminRights", false) && !pBox->GetBool("FakeAdminRights", false));
m_pMenuPresetsNoAdmin->setChecked(pBox && pBox->GetBool("DropAdminRights", false) && !pBox->GetBool("FakeAdminRights", false));
m_pMenuPresetsFakeAdmin->setChecked(pBox && pBox->GetBool("DropAdminRights", false) && pBox->GetBool("FakeAdminRights", false));
2020-07-04 11:07:36 +01:00
m_pMenuPresetsINet->setChecked(pBox && pBox.objectCast<CSandBoxPlus>()->IsINetBlocked());
m_pMenuPresetsShares->setChecked(pBox && pBox.objectCast<CSandBoxPlus>()->HasSharesAccess());
2021-01-26 20:58:43 +00:00
m_pMenuExplore->setEnabled(iSandBoxeCount == 1);
2020-07-19 21:09:02 +01:00
m_pMenuOptions->setEnabled(iSandBoxeCount == 1);
2020-09-05 16:45:39 +01:00
m_pMenuSnapshots->setEnabled(iSandBoxeCount == 1);
2020-07-04 11:07:36 +01:00
2020-06-01 17:11:56 +01:00
for (int i = m_iMenuBox; i < m_iMenuProc; i++)
2021-01-26 20:58:43 +00:00
MenuActions[i]->setVisible(iProcessCount != 0 && iSandBoxeCount == 0);
2020-11-16 16:15:03 +00:00
2020-12-29 08:54:59 +00:00
m_pMenuLinkTo->setEnabled(iProcessCount == 1);
2020-11-16 16:15:03 +00:00
if (!pProcess.isNull()) {
2020-11-28 16:20:56 +00:00
CSandBoxPlus* pBoxPlus = pProcess.objectCast<CSbieProcess>()->GetBox();
QStringList RunOptions = pBoxPlus->GetTextList("RunCommand", true);
QString FoundPin;
QString FileName = pProcess->GetFileName();
foreach(const QString& RunOption, RunOptions) {
if (Split2(RunOption, "|").second.indexOf(FileName) == 0) {
FoundPin = RunOption;
break;
}
}
if (FoundPin.isEmpty() && FileName.indexOf(pBoxPlus->GetFileRoot(), Qt::CaseInsensitive) == 0) {
FileName.remove(0, pBoxPlus->GetFileRoot().length());
foreach(const QString& RunOption, RunOptions) {
if (Split2(RunOption, "|").second.indexOf(FileName) == 0) {
FoundPin = RunOption;
break;
}
}
}
m_pMenuPinToRun->setChecked(!FoundPin.isEmpty());
m_pMenuPinToRun->setData(FoundPin);
2020-12-29 08:54:59 +00:00
m_pMenuAllowInternet->setChecked(pProcess.objectCast<CSbieProcess>()->HasInternetAccess());
m_pMenuMarkForced->setChecked(pProcess.objectCast<CSbieProcess>()->IsForcedProgram());
2020-11-16 16:15:03 +00:00
int isLingering = pProcess.objectCast<CSbieProcess>()->IsLingeringProgram();
m_pMenuMarkLinger->setChecked(isLingering != 0);
m_pMenuMarkLinger->setEnabled(isLingering != 2);
m_pMenuMarkLeader->setChecked(pProcess.objectCast<CSbieProcess>()->IsLeaderProgram());
}
2020-12-29 08:54:59 +00:00
//m_pMenuSuspend->setEnabled(iProcessCount > iSuspendedCount);
//m_pMenuResume->setEnabled(iSuspendedCount > 0);
2020-06-01 17:11:56 +01:00
2021-01-06 12:19:13 +00:00
if (!isConnected) {
foreach(QAction * pAction, MenuActions)
pAction->setEnabled(false);
}
2020-06-01 17:11:56 +01:00
CPanelView::OnMenu(Point);
}
2020-12-07 16:34:20 +00:00
int CSbieView__ParseGroup(const QString& Grouping, QMap<QString, QStringList>& m_Groups, const QString& Parent = "", int Index = 0)
{
QRegExp RegExp("[,()]", Qt::CaseInsensitive, QRegExp::RegExp);
for (; ; )
{
int pos = Grouping.indexOf(RegExp, Index);
QString Name;
if (pos == -1) {
Name = Grouping.mid(Index);
Index = Grouping.length();
}
else {
Name = Grouping.mid(Index, pos - Index);
Index = pos + 1;
}
if (!Name.isEmpty())
m_Groups[Parent].append(Name);
if (pos == -1)
break;
if (Grouping.at(pos) == "(")
2021-01-02 08:03:16 +00:00
{
m_Groups[Name] = QStringList();
2020-12-07 16:34:20 +00:00
Index = CSbieView__ParseGroup(Grouping, m_Groups, Name, Index);
2021-01-02 08:03:16 +00:00
}
2020-12-07 16:34:20 +00:00
else if (Grouping.at(pos) == ")")
break;
}
return Index;
}
void CSbieView::ReloadGroups()
{
m_Groups.clear();
QString Grouping = theAPI->GetUserSettings()->GetText("BoxDisplayOrder");
CSbieView__ParseGroup(Grouping, m_Groups);
2020-12-29 08:54:59 +00:00
UpdateGroupMenu();
}
void CSbieView::UpdateGroupMenu()
{
2020-12-07 16:34:20 +00:00
// update move to menu
foreach(QAction* pAction, m_pMenuMoveTo->actions())
m_pMenuMoveTo->removeAction(pAction);
foreach(const QString& Group, m_Groups.keys())
{
QAction* pAction = m_pMenuMoveTo->addAction(Group.isEmpty() ? tr("[None]") : Group, this, SLOT(OnGroupAction()));
pAction->setData(Group);
}
2021-01-26 20:58:43 +00:00
m_pMenuMoveTo->setEnabled(m_Groups.keys().count() > 1);
2020-12-07 16:34:20 +00:00
}
QString CSbieView__SerializeGroup(QMap<QString, QStringList>& m_Groups, const QString& Parent = "")
{
QStringList Grouping;
foreach(const QString& Name, m_Groups[Parent])
{
if (m_Groups.contains(Name))
Grouping.append(Name + "(" + CSbieView__SerializeGroup(m_Groups, Name) + ")");
else
Grouping.append(Name);
}
return Grouping.join(",");
}
2021-02-14 19:18:29 +00:00
QString CSbieView::FindParent(const QString& Name)
{
for (auto I = m_Groups.begin(); I != m_Groups.end(); ++I)
{
if (I.value().contains(Name, Qt::CaseInsensitive))
return I.key();
}
return QString();
}
bool CSbieView::IsParentOf(const QString& Name, const QString& Group)
{
QString Parent = FindParent(Group);
if (Parent == Name)
return true;
if (Parent.isEmpty())
return false;
return IsParentOf(Name, Parent);
}
2020-12-07 16:34:20 +00:00
void CSbieView::OnGroupAction()
{
QAction* Action = qobject_cast<QAction*>(sender());
2021-02-01 19:13:09 +00:00
if (Action == m_pNewBox)
{
QString Name = AddNewBox();
if (Name.isEmpty())
return;
QModelIndex ModelIndex = m_pSortProxy->mapToSource(m_pSbieTree->currentIndex());
QString Parent;
if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eGroup)
Parent = m_pSbieModel->GetID(ModelIndex).toString();
m_Groups[Parent].append(Name);
m_pSbieModel->Clear(); //todo improve that
}
else if (Action == m_pAddGroupe)
2020-12-07 16:34:20 +00:00
{
QString Name = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a new group name"), QLineEdit::Normal);
if (Name.isEmpty() || m_Groups.contains(Name))
return;
m_Groups[Name] = QStringList();
QModelIndex ModelIndex = m_pSortProxy->mapToSource(m_pSbieTree->currentIndex());
QString Parent;
if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eGroup)
Parent = m_pSbieModel->GetID(ModelIndex).toString();
2021-01-02 08:03:16 +00:00
m_Groups[Parent].append(Name);
2020-12-07 16:34:20 +00:00
}
else if (Action == m_pDelGroupe)
{
2021-01-26 20:58:43 +00:00
if (QMessageBox("Sandboxie-Plus", tr("Do you really want to remove the selected group(s)?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
2020-12-07 16:34:20 +00:00
return;
foreach(const QModelIndex& Index, m_pSbieTree->selectedRows())
{
QModelIndex ModelIndex = m_pSortProxy->mapToSource(Index);
if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eGroup)
{
QString Group = m_pSbieModel->GetID(ModelIndex).toString();
2021-01-08 17:27:00 +00:00
QStringList Items = m_Groups.take(Group); // remove groupe
2020-12-07 16:34:20 +00:00
// remove from parents
2021-01-08 17:27:00 +00:00
for (auto I = m_Groups.begin(); I != m_Groups.end(); ++I) {
if (I.value().removeOne(Group)) {
// move items to grand parent
I.value().append(Items);
break;
}
}
2020-12-07 16:34:20 +00:00
}
}
m_pSbieModel->Clear(); //todo improve that, also move boxes to grant parent?
}
else // move to groupe
{
QString Group = Action->data().toString();
foreach(const QModelIndex& Index, m_pSbieTree->selectedRows())
{
QModelIndex ModelIndex = m_pSortProxy->mapToSource(Index);
QString Name;
if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eGroup)
Name = m_pSbieModel->GetID(ModelIndex).toString();
else if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eBox)
Name = m_pSbieModel->GetSandBox(ModelIndex)->GetName();
2021-02-01 19:13:09 +00:00
if (Name.isEmpty())
2020-12-07 16:34:20 +00:00
continue;
2021-02-14 19:18:29 +00:00
if (Name == Group || IsParentOf(Name, Group)) {
2021-02-01 19:13:09 +00:00
QMessageBox("Sandboxie-Plus", tr("A group can not be its own parent."), QMessageBox::Critical, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this).exec();
continue;
}
2020-12-07 16:34:20 +00:00
// remove from old
for (auto I = m_Groups.begin(); I != m_Groups.end(); ++I)
I.value().removeAll(Name);
// add to new
m_Groups[Group].append(Name);
}
m_pSbieModel->Clear(); //todo improve that
}
QString Grouping = CSbieView__SerializeGroup(m_Groups);
theAPI->GetUserSettings()->SetText("BoxDisplayOrder", Grouping);
2021-07-05 12:37:28 +01:00
UpdateGroupMenu();
2020-12-07 16:34:20 +00:00
}
2021-02-01 19:13:09 +00:00
QString CSbieView::AddNewBox()
{
CNewBoxWindow NewBoxWindow(this);
bool bAlwaysOnTop = theConf->GetBool("Options/AlwaysOnTop", false);
NewBoxWindow.setWindowFlag(Qt::WindowStaysOnTopHint, bAlwaysOnTop);
if (NewBoxWindow.exec() == 1)
{
theAPI->ReloadBoxes();
Refresh();
SelectBox(NewBoxWindow.m_Name);
return NewBoxWindow.m_Name;
}
return QString();
}
2020-06-01 17:11:56 +01:00
void CSbieView::OnSandBoxAction()
2021-02-21 14:32:20 +00:00
{
OnSandBoxAction(qobject_cast<QAction*>(sender()));
}
void CSbieView::OnSandBoxAction(QAction* Action)
2020-06-01 17:11:56 +01:00
{
QList<SB_STATUS> Results;
QList<CSandBoxPtr> SandBoxes = CSbieView::GetSelectedBoxes();
if (SandBoxes.isEmpty())
return;
if (Action == m_pMenuRunAny)
{
/*QString Command = ShowRunDialog(SandBoxes.first()->GetName());
if(!Command.isEmpty())
SandBoxes.first()->RunCommand(Command);*/
Results.append(SandBoxes.first()->RunStart("run_dialog"));
}
2020-11-28 16:20:56 +00:00
else if (Action == m_pMenuRunMenu)
Results.append(SandBoxes.first()->RunStart("start_menu"));
2020-06-01 17:11:56 +01:00
else if (Action == m_pMenuRunBrowser)
Results.append(SandBoxes.first()->RunStart("default_browser"));
2020-11-28 16:20:56 +00:00
else if (Action == m_pMenuRunMailer)
Results.append(SandBoxes.first()->RunStart("mail_agent"));
2020-06-01 17:11:56 +01:00
else if (Action == m_pMenuRunExplorer)
2021-01-18 12:04:14 +00:00
{
if (theConf->GetBool("Options/AdvancedView", true) == false && theConf->GetBool("Options/BoxedExplorerInfo", true))
{
bool State = false;
CCheckableMessageBox::question(this, "Sandboxie-Plus",
theAPI->GetSbieMsgStr(0x00000DCDL, theGUI->m_LanguageId) // MSG_3533
, tr("Don't show this message again."), &State, QDialogButtonBox::Ok, QDialogButtonBox::Ok, QMessageBox::Information);
if (State)
theConf->SetValue("Options/BoxedExplorerInfo", false);
}
2020-12-22 14:50:58 +00:00
Results.append(SandBoxes.first()->RunStart("explorer.exe /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"));
2021-01-18 12:04:14 +00:00
}
2021-07-05 12:37:28 +01:00
else if (Action == m_pMenuRunRegEdit)
Results.append(SandBoxes.first()->RunStart("regedit.exe"));
else if (Action == m_pMenuRunAppWiz)
Results.append(SandBoxes.first()->RunStart("\"C:\\WINDOWS\\System32\\control.exe\" \"C:\\Windows\\System32\\appwiz.cpl\""));
2020-06-01 17:11:56 +01:00
else if (Action == m_pMenuRunCmd)
2020-12-22 14:50:58 +00:00
Results.append(SandBoxes.first()->RunStart("cmd.exe"));
2021-02-14 19:18:29 +00:00
else if (Action == m_pMenuRunCmdAdmin)
Results.append(SandBoxes.first()->RunStart("cmd.exe", true));
2021-02-21 14:32:20 +00:00
else if (Action == m_pMenuPresetsShowUAC)
{
SandBoxes.first()->SetBool("DropAdminRights", false);
SandBoxes.first()->SetBool("FakeAdminRights", false);
}
else if (Action == m_pMenuPresetsNoAdmin)
{
SandBoxes.first()->SetBool("DropAdminRights", true);
SandBoxes.first()->SetBool("FakeAdminRights", false);
}
else if (Action == m_pMenuPresetsFakeAdmin)
{
SandBoxes.first()->SetBool("DropAdminRights", true);
SandBoxes.first()->SetBool("FakeAdminRights", true);
}
2020-07-04 11:07:36 +01:00
else if (Action == m_pMenuPresetsINet)
SandBoxes.first().objectCast<CSandBoxPlus>()->SetINetBlock(m_pMenuPresetsINet->isChecked());
else if (Action == m_pMenuPresetsShares)
SandBoxes.first().objectCast<CSandBoxPlus>()->SetAllowShares(m_pMenuPresetsShares->isChecked());
2020-07-19 21:09:02 +01:00
else if (Action == m_pMenuOptions)
{
2021-01-18 12:04:14 +00:00
OnDoubleClicked(m_pSbieTree->selectedRows().first());
2020-07-19 21:09:02 +01:00
}
2020-10-10 17:18:01 +01:00
else if (Action == m_pMenuExplore)
{
2021-01-30 18:10:49 +00:00
if (SandBoxes.first()->IsEmpty()) {
QMessageBox("Sandboxie-Plus", tr("This Sandbox is empty."), QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this).exec();
return;
}
2021-01-18 12:04:14 +00:00
if (theConf->GetBool("Options/AdvancedView", true) == false && theConf->GetBool("Options/ExplorerInfo", true))
{
bool State = false;
CCheckableMessageBox::question(this, "Sandboxie-Plus",
theAPI->GetSbieMsgStr(0x00000DCEL, theGUI->m_LanguageId) // MSG_3534
, tr("Don't show this message again."), &State, QDialogButtonBox::Ok, QDialogButtonBox::Ok, QMessageBox::Information);
if (State)
theConf->SetValue("Options/ExplorerInfo", false);
}
2020-10-10 17:18:01 +01:00
::ShellExecute(NULL, NULL, SandBoxes.first()->GetFileRoot().toStdWString().c_str(), NULL, NULL, SW_SHOWNORMAL);
}
2020-09-05 16:45:39 +01:00
else if (Action == m_pMenuSnapshots)
{
2021-01-26 20:58:43 +00:00
CSandBoxPtr pBox = SandBoxes.first();
static QMap<void*, CSnapshotsWindow*> SnapshotWindows;
if (!SnapshotWindows.contains(pBox.data()))
{
CSnapshotsWindow* pSnapshotsWindow = new CSnapshotsWindow(SandBoxes.first(), this);
SnapshotWindows.insert(pBox.data(), pSnapshotsWindow);
connect(pSnapshotsWindow, &CSnapshotsWindow::Closed, [this, pBox]() {
SnapshotWindows.remove(pBox.data());
});
pSnapshotsWindow->show();
}
2020-09-05 16:45:39 +01:00
}
2020-06-01 17:11:56 +01:00
else if (Action == m_pMenuRename)
{
2021-07-05 12:37:28 +01:00
QString OldValue = SandBoxes.first()->GetName().replace("_", " ");
2020-07-19 21:09:02 +01:00
QString Value = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a new name for the Sandbox."), QLineEdit::Normal, OldValue);
2020-07-04 11:07:36 +01:00
if (Value.isEmpty() || Value == OldValue)
2020-06-01 17:11:56 +01:00
return;
2021-07-05 12:37:28 +01:00
Results.append((SandBoxes.first()->RenameBox(Value.replace(" ", "_"))));
2020-06-01 17:11:56 +01:00
}
else if (Action == m_pMenuRemove)
{
2021-01-26 20:58:43 +00:00
if (QMessageBox("Sandboxie-Plus", tr("Do you really want to remove the selected sandbox(es)?"), QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
2020-06-01 17:11:56 +01:00
return;
2021-07-05 12:37:28 +01:00
foreach(const CSandBoxPtr& pBox, SandBoxes)
Results.append(pBox->RemoveBox());
2020-06-01 17:11:56 +01:00
}
2020-11-28 16:20:56 +00:00
else if (Action == m_pMenuRecover)
{
emit RecoveryRequested(SandBoxes.first()->GetName());
}
2020-06-01 17:11:56 +01:00
else if (Action == m_pMenuCleanUp)
{
2021-01-18 12:04:14 +00:00
if (SandBoxes.count() == 1)
{
if (SandBoxes.first()->IsEmpty()) {
2021-01-26 20:58:43 +00:00
QMessageBox("Sandboxie-Plus", tr("This Sandbox is already empty."), QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this).exec();
2021-01-18 12:04:14 +00:00
return;
}
if (theConf->GetBool("Options/ShowRecovery", false))
{
2021-07-05 12:37:28 +01:00
CRecoveryWindow* pRecoveryWindow = new CRecoveryWindow(SandBoxes.first(), this);
2021-01-18 12:04:14 +00:00
pRecoveryWindow->FindFiles();
if (pRecoveryWindow->exec() != 1)
return;
}
2021-01-26 20:58:43 +00:00
else if(QMessageBox("Sandboxie-Plus", tr("Do you want to delete the content of the selected sandbox?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
2021-01-18 12:04:14 +00:00
return;
}
2021-01-26 20:58:43 +00:00
else if (QMessageBox("Sandboxie-Plus", tr("Do you really want to delete the content of multiple sandboxes?"), QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
2020-06-01 17:11:56 +01:00
return;
2021-01-18 12:04:14 +00:00
foreach(const CSandBoxPtr & pBox, SandBoxes)
2020-06-18 16:44:29 +01:00
{
2020-09-05 16:45:39 +01:00
SB_PROGRESS Status = pBox->CleanBox();
if (Status.GetStatus() == OP_ASYNC)
theGUI->AddAsyncOp(Status.GetValue());
2021-01-18 12:04:14 +00:00
else if (Status.IsError())
2020-09-05 16:45:39 +01:00
Results.append(Status);
2021-01-18 12:04:14 +00:00
}
2020-06-01 17:11:56 +01:00
}
else if (Action == m_pMenuEmptyBox)
{
2021-01-26 20:58:43 +00:00
if (QMessageBox("Sandboxie-Plus", tr("Do you want to terminate all processes in the selected sandbox(es)?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
return;
2020-06-01 17:11:56 +01:00
foreach(const CSandBoxPtr& pBox, SandBoxes)
Results.append(pBox->TerminateAll());
}
2020-11-28 16:20:56 +00:00
else if (Action == m_pMenuMkLink)
{
2020-12-07 16:34:20 +00:00
QString BoxName = SandBoxes.first()->GetName();
QString LinkPath, IconPath, WorkDir;
quint32 IconIndex;
if (!CSbieUtils::GetStartMenuShortcut(theAPI, BoxName, LinkPath, IconPath, IconIndex, WorkDir))
return;
QString LinkName;
int pos = LinkPath.lastIndexOf(L'\\');
if (pos == -1)
return;
if (pos == 2 && LinkPath.length() == 3)
LinkName = QObject::tr("Drive %1").arg(LinkPath.left(1));
else {
LinkName = LinkPath.mid(pos + 1);
pos = LinkName.indexOf(QRegExp("[" + QRegExp::escape("\":;,*?.") + "]"));
if (pos != -1)
LinkName = LinkName.left(pos);
}
QString Path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).replace("/", "\\");
//Path = QFileDialog::getExistingDirectory(this, tr("Select Directory to create Shorcut in"), Path).replace("/", "\\");
//if (Path.isEmpty())
// return;
if (Path.right(1) != "\\")
Path.append("\\");
Path += "[" + BoxName + "] " + LinkName;
Path = QFileDialog::getSaveFileName(this, tr("Create Shortcut to sandbox %1").arg(BoxName), Path, QString("Shortcut files (*.lnk)")).replace("/", "\\");
if (Path.isEmpty())
return;
CSbieUtils::CreateShortcut(theAPI, Path, LinkName, BoxName, LinkPath, IconPath, IconIndex, WorkDir);
2020-11-28 16:20:56 +00:00
}
else // custom run menu command
{
QString Command = Action->data().toString();
if (!Command.isEmpty())
{
if (Command.left(1) == "\\" && !SandBoxes.isEmpty())
Command.prepend(SandBoxes.first()->GetFileRoot());
2020-12-22 14:50:58 +00:00
Results.append(SandBoxes.first()->RunStart(Command));
2020-11-28 16:20:56 +00:00
}
}
2020-06-01 17:11:56 +01:00
CSandMan::CheckResults(Results);
}
2020-06-18 16:44:29 +01:00
2020-06-01 17:11:56 +01:00
void CSbieView::OnProcessAction()
{
2020-06-08 16:17:37 +01:00
QList<SB_STATUS> Results;
2020-06-01 17:11:56 +01:00
QAction* Action = qobject_cast<QAction*>(sender());
2020-11-16 16:15:03 +00:00
if (Action == m_pMenuTerminate || Action == m_pMenuBlackList)
2020-07-04 11:07:36 +01:00
{
if (QMessageBox("Sandboxie-Plus", tr("Do you want to %1 the selected process(es)?").arg(((QAction*)sender())->text().toLower())
2021-01-26 20:58:43 +00:00
, QMessageBox::Question, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
2020-07-04 11:07:36 +01:00
return;
}
2020-06-01 17:11:56 +01:00
foreach(const CBoxedProcessPtr& pProcess, CSbieView::GetSelectedProcesses())
{
if (Action == m_pMenuTerminate)
2020-06-08 16:17:37 +01:00
Results.append(pProcess->Terminate());
2020-12-29 08:54:59 +00:00
else if (Action == m_pMenuLinkTo)
{
QString BoxName = pProcess->GetBoxName();
QString LinkName = pProcess->GetProcessName();
QString LinkPath = pProcess->GetFileName();
QString Path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).replace("/", "\\");
//Path = QFileDialog::getExistingDirectory(this, tr("Select Directory to create Shorcut in"), Path).replace("/", "\\");
//if (Path.isEmpty())
// return;
if (Path.right(1) != "\\")
Path.append("\\");
Path += "[" + BoxName + "] " + LinkName;
Path = QFileDialog::getSaveFileName(this, tr("Create Shortcut to sandbox %1").arg(BoxName), Path, QString("Shortcut files (*.lnk)")).replace("/", "\\");
if (Path.isEmpty())
return;
CSbieUtils::CreateShortcut(theAPI, Path, LinkName, BoxName, LinkPath, LinkPath);
}
2020-11-28 16:20:56 +00:00
else if (Action == m_pMenuPinToRun)
{
CSandBoxPlus* pBoxPlus = pProcess.objectCast<CSbieProcess>()->GetBox();
if (m_pMenuPinToRun->isChecked())
{
QString FileName = pProcess->GetFileName();
if (FileName.indexOf(pBoxPlus->GetFileRoot(), Qt::CaseInsensitive) == 0) {
FileName.remove(0, pBoxPlus->GetFileRoot().length());
if (FileName.at(0) != "\\")
FileName.prepend("\\");
}
pBoxPlus->InsertText("RunCommand", pProcess->GetProcessName() + "|" + pProcess->GetFileName());
}
else if(!m_pMenuPinToRun->data().toString().isEmpty())
pBoxPlus->DelValue("RunCommand", m_pMenuPinToRun->data().toString());
}
2020-11-16 16:15:03 +00:00
else if (Action == m_pMenuBlackList)
{
Results.append(pProcess->Terminate());
pProcess.objectCast<CSbieProcess>()->BlockProgram();
}
2020-12-29 08:54:59 +00:00
else if (Action == m_pMenuAllowInternet)
{
if (!pProcess.objectCast<CSbieProcess>()->GetBox()->IsINetBlocked())
{
2021-01-26 20:58:43 +00:00
if (QMessageBox("Sandboxie-Plus", tr("This box does not have Internet restrictions in place, do you want to enable them?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
2020-12-29 08:54:59 +00:00
return;
pProcess.objectCast<CSbieProcess>()->GetBox()->SetINetBlock(true);
}
pProcess.objectCast<CSbieProcess>()->SetInternetAccess(m_pMenuAllowInternet->isChecked());
}
else if (Action == m_pMenuMarkForced)
pProcess.objectCast<CSbieProcess>()->SetForcedProgram(m_pMenuMarkForced->isChecked());
2020-11-16 16:15:03 +00:00
else if (Action == m_pMenuMarkLinger)
pProcess.objectCast<CSbieProcess>()->SetLingeringProgram(m_pMenuMarkLinger->isChecked());
else if (Action == m_pMenuMarkLeader)
pProcess.objectCast<CSbieProcess>()->SetLeaderProgram(m_pMenuMarkLeader->isChecked());
2020-12-29 08:54:59 +00:00
/*else if (Action == m_pMenuSuspend)
2020-06-08 16:17:37 +01:00
Results.append(pProcess->SetSuspend(true));
2020-06-01 17:11:56 +01:00
else if (Action == m_pMenuResume)
2020-12-29 08:54:59 +00:00
Results.append(pProcess->SetSuspend(false));*/
2020-06-01 17:11:56 +01:00
}
2020-06-08 16:17:37 +01:00
CSandMan::CheckResults(Results);
2020-06-01 17:11:56 +01:00
}
2020-07-19 21:09:02 +01:00
void CSbieView::OnDoubleClicked(const QModelIndex& index)
{
QModelIndex ModelIndex = m_pSortProxy->mapToSource(index);
CSandBoxPtr pBox = m_pSbieModel->GetSandBox(ModelIndex);
if (pBox.isNull())
return;
2021-01-26 20:58:43 +00:00
if (!pBox->IsEnabled())
{
if (QMessageBox("Sandboxie-Plus", tr("This sandbox is disabled, do you want to enable it?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
return;
pBox->SetText("Enabled", "y");
}
2021-01-18 12:04:14 +00:00
static QMap<void*, COptionsWindow*> OptionsWindows;
if (!OptionsWindows.contains(pBox.data()))
{
2021-01-26 20:58:43 +00:00
COptionsWindow* pOptionsWindow = new COptionsWindow(pBox, pBox->GetName());
2021-01-18 12:04:14 +00:00
OptionsWindows.insert(pBox.data(), pOptionsWindow);
connect(pOptionsWindow, &COptionsWindow::Closed, [this, pBox]() {
OptionsWindows.remove(pBox.data());
});
pOptionsWindow->show();
}
2020-07-19 21:09:02 +01:00
}
2020-06-01 17:11:56 +01:00
void CSbieView::ProcessSelection(const QItemSelection& selected, const QItemSelection& deselected)
{
if (selected.empty())
return;
QItemSelectionModel* selectionModel = m_pSbieTree->selectionModel();
QItemSelection selection = selectionModel->selection();
2020-12-07 16:34:20 +00:00
QItemSelection invalid;
/*
2020-06-01 17:11:56 +01:00
QModelIndex root_parent = m_pSbieTree->currentIndex().parent();
while (root_parent.isValid() && root_parent.parent().isValid())
root_parent = root_parent.parent();
foreach(const QModelIndex& index, selection.indexes())
{
QModelIndex parent = index.parent();
while (parent.isValid() && parent.parent().isValid())
parent = parent.parent();
if (parent != root_parent)
invalid.select(index, index);
2020-12-07 16:34:20 +00:00
}*/
int Type = m_pSbieModel->GetType(m_pSortProxy->mapToSource(m_pSbieTree->currentIndex()));
foreach(const QModelIndex& index, selection.indexes())
{
if (m_pSbieModel->GetType(m_pSortProxy->mapToSource(index)) != Type)
invalid.select(index, index);
2020-06-01 17:11:56 +01:00
}
2020-12-07 16:34:20 +00:00
2020-06-01 17:11:56 +01:00
selectionModel->select(invalid, QItemSelectionModel::Deselect);
}
QList<CSandBoxPtr> CSbieView::GetSelectedBoxes()
{
QList<CSandBoxPtr> List;
foreach(const QModelIndex& Index, m_pSbieTree->selectedRows())
{
QModelIndex ModelIndex = m_pSortProxy->mapToSource(Index);
CSandBoxPtr pBox = m_pSbieModel->GetSandBox(ModelIndex);
if (!pBox)
continue;
List.append(pBox);
}
return List;
}
QList<CBoxedProcessPtr> CSbieView::GetSelectedProcesses()
{
QList<CBoxedProcessPtr> List;
foreach(const QModelIndex& Index, m_pSbieTree->selectedRows())
{
QModelIndex ModelIndex = m_pSortProxy->mapToSource(Index);
CBoxedProcessPtr pProcess = m_pSbieModel->GetProcess(ModelIndex);
if (!pProcess)
return QList < CBoxedProcessPtr>();
List.append(pProcess);
}
return List;
2020-11-28 16:20:56 +00:00
}
/*void CSbieView::UpdateRunMenu()
{
while (m_iMenuRun < m_pMenuRun->actions().count())
m_pMenuRun->removeAction(m_pMenuRun->actions().at(m_iMenuRun));
QStringList RunOptions = theConf->ListKeys("RunOptions");
foreach(const QString& RunOption, RunOptions)
{
StrPair NameCmd = Split2(theConf->GetString("RunOptions/" + RunOption), "|");
QAction* pAction = m_pMenuRun->addAction(NameCmd.first, this, SLOT(OnSandBoxAction()));
pAction->setData(NameCmd.second);
}
}*/
void CSbieView::UpdateRunMenu(const CSandBoxPtr& pBox)
{
while (m_iMenuRun < m_pMenuRun->actions().count())
m_pMenuRun->removeAction(m_pMenuRun->actions().at(m_iMenuRun));
2020-12-22 14:50:58 +00:00
QFileIconProvider IconProvider;
2020-11-28 16:20:56 +00:00
QStringList RunOptions = pBox->GetTextList("RunCommand", true);
foreach(const QString& RunOption, RunOptions)
{
StrPair NameCmd = Split2(RunOption, "|");
QAction* pAction = m_pMenuRun->addAction(NameCmd.first, this, SLOT(OnSandBoxAction()));
2020-12-22 14:50:58 +00:00
QString Path = NameCmd.second;
if (Path.left(1) == "\"") {
int End = Path.indexOf("\"", 1);
if (End != -1) Path = Path.mid(1, End - 1);
}
else {
int End = Path.indexOf(" ");
if (End != -1) Path.truncate(End);
}
if (Path.left(1) == "\\")
Path.prepend(pBox->GetFileRoot());
pAction->setIcon(IconProvider.icon(QFileInfo(Path)));
2020-11-28 16:20:56 +00:00
pAction->setData(NameCmd.second);
}
2020-12-22 17:49:58 +00:00
}
2021-01-26 20:58:43 +00:00
void CSbieView::SelectBox(const QString& Name)
{
QModelIndex Index = m_pSbieModel->FindIndex(Name);
QModelIndex ModelIndex = m_pSortProxy->mapFromSource(Index);
QModelIndex ModelL = m_pSortProxy->index(ModelIndex.row(), 0, ModelIndex.parent());
QModelIndex ModelR = m_pSortProxy->index(ModelIndex.row(), m_pSortProxy->columnCount() - 1, ModelIndex.parent());
QItemSelection SelectedItems;
SelectedItems.append(QItemSelectionRange(ModelL, ModelR));
m_pSbieTree->scrollTo(ModelL);
m_pSbieTree->selectionModel()->select(SelectedItems, QItemSelectionModel::ClearAndSelect);
}