Sandboxie/SandboxiePlus/SandMan/Models/SbieModel.cpp

664 lines
19 KiB
C++
Raw Normal View History

2021-10-16 16:19:51 +01:00
#include "stdafx.h"
#include "SbieModel.h"
#include "../../MiscHelpers/Common/Common.h"
#include "../SandMan.h"
2022-12-16 12:08:49 +00:00
#include "../Helpers/WinHelper.h"
2021-10-16 16:19:51 +01:00
CSbieModel::CSbieModel(QObject *parent)
2022-07-09 10:46:07 +01:00
: CTreeItemModel(parent)
2021-10-16 16:19:51 +01:00
{
2022-09-29 17:28:48 +01:00
m_bTree = true;
2022-07-09 10:46:07 +01:00
m_LargeIcons = false;
2021-10-16 16:19:51 +01:00
//m_BoxEmpty = QIcon(":/BoxEmpty");
//m_BoxInUse = QIcon(":/BoxInUse");
m_ExeIcon = QIcon(":/exeIcon32");
2022-04-16 14:01:01 +01:00
m_SbieModelMimeType = "application/x-sbie-data";
2021-10-16 16:19:51 +01:00
m_Root = MkNode(QVariant());
}
CSbieModel::~CSbieModel()
{
2023-01-07 15:57:55 +00:00
FreeNode(m_Root);
m_Root = NULL;
2021-10-16 16:19:51 +01:00
}
QList<QVariant> CSbieModel::MakeProcPath(const QString& BoxName, const CBoxedProcessPtr& pProcess, const QMap<quint32, CBoxedProcessPtr>& ProcessList)
{
2022-01-06 17:36:09 +00:00
QList<QVariant> Path;
MakeProcPath(pProcess, ProcessList, Path);
2021-10-16 16:19:51 +01:00
Path.prepend(BoxName);
return Path;
}
2022-01-06 17:36:09 +00:00
void CSbieModel::MakeProcPath(const CBoxedProcessPtr& pProcess, const QMap<quint32, CBoxedProcessPtr>& ProcessList, QList<QVariant>& Path)
2021-10-16 16:19:51 +01:00
{
quint32 ParentID = pProcess->GetParendPID();
CBoxedProcessPtr pParent = ProcessList.value(ParentID);
2022-01-06 17:36:09 +00:00
if (!pParent.isNull() && ParentID != pProcess->GetProcessId() && !Path.contains(ParentID))
2021-10-16 16:19:51 +01:00
{
2022-01-06 17:36:09 +00:00
Path.prepend(ParentID);
MakeProcPath(pParent, ProcessList, Path);
2021-10-16 16:19:51 +01:00
}
}
bool CSbieModel::TestProcPath(const QList<QVariant>& Path, const QString& BoxName, const CBoxedProcessPtr& pProcess, const QMap<quint32, CBoxedProcessPtr>& ProcessList, int Index)
{
if (Index == 0)
{
if (Path.isEmpty() || BoxName != Path[0])
return false;
return TestProcPath(Path, BoxName, pProcess, ProcessList, 1);
}
quint32 ParentID = pProcess->GetParendPID();
CBoxedProcessPtr pParent = ProcessList.value(ParentID);
if (!pParent.isNull() && ParentID != pProcess->GetProcessId())
{
if(Index >= Path.size() || Path[Path.size() - Index] != ParentID)
return false;
return TestProcPath(Path, BoxName, pParent, ProcessList, Index + 1);
}
return Path.size() == Index;
}
QString CSbieModel__AddGroupMark(const QString& Name)
{
return Name.isEmpty() ? "" : ("!" + Name);
}
2022-04-16 14:01:01 +01:00
bool CSbieModel__HasGroupMark(const QString& Name)
{
return Name.left(1) == "!";
}
2021-10-16 16:19:51 +01:00
QString CSbieModel__RemoveGroupMark(const QString& Name)
{
return Name.left(1) == "!" ? Name.mid(1) : Name;
}
QString CSbieModel::FindParent(const QVariant& Name, const QMap<QString, QStringList>& Groups)
{
for(auto I = Groups.begin(); I != Groups.end(); ++I)
{
if (I.value().contains(CSbieModel__RemoveGroupMark(Name.toString()), Qt::CaseInsensitive))
return CSbieModel__AddGroupMark(I.key());
}
return QString();
}
void CSbieModel::MakeBoxPath(const QVariant& Name, const QMap<QString, QStringList>& Groups, QList<QVariant>& Path)
{
QString ParentID = FindParent(Name, Groups);
if (!ParentID.isEmpty() && ParentID != Name && !Path.contains(ParentID))
{
Path.prepend(ParentID);
MakeBoxPath(ParentID, Groups, Path);
}
}
QList<QVariant> CSbieModel::MakeBoxPath(const QVariant& Name, const QMap<QString, QStringList>& Groups)
{
QList<QVariant> Path;
MakeBoxPath(Name, Groups, Path);
return Path;
}
QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList, const QMap<QString, QStringList>& Groups, bool ShowHidden)
{
QList<QVariant> Added;
QMap<QList<QVariant>, QList<STreeNode*> > New;
QHash<QVariant, STreeNode*> Old = m_Map;
2022-06-16 17:35:26 +01:00
bool bGroupsFirst = theConf->GetBool("Options/SortGroupsFirst", false);
2022-05-16 20:30:40 +01:00
bool bWatchSize = theConf->GetBool("Options/WatchBoxSize", false);
2022-07-10 17:28:10 +01:00
bool ColorIcons = theConf->GetBool("Options/ColorBoxIcons", false);
2023-04-29 10:55:43 +01:00
bool OverlayIcons = theConf->GetBool("Options/UseOverlayIcons", true);
2022-07-10 17:28:10 +01:00
bool bPlus = (theAPI->GetFeatureFlags() & CSbieAPI::eSbieFeatureCert) != 0;
2022-11-07 11:06:15 +00:00
bool bVintage = theConf->GetInt("Options/ViewMode", 1) == 2;
if (bVintage)
2022-07-10 17:28:10 +01:00
bPlus = false;
2023-07-06 20:12:22 +01:00
bool bHideCore = theConf->GetBool("Options/HideSbieProcesses", false);
2022-05-16 20:30:40 +01:00
2021-10-16 16:19:51 +01:00
foreach(const QString& Group, Groups.keys())
{
if (Group.isEmpty())
continue;
QVariant ID = CSbieModel__AddGroupMark(Group);
QModelIndex Index;
QHash<QVariant, STreeNode*>::iterator I = Old.find(ID);
SSandBoxNode* pNode = I != Old.end() ? static_cast<SSandBoxNode*>(I.value()) : NULL;
if (!pNode)
{
pNode = static_cast<SSandBoxNode*>(MkNode(ID));
pNode->Values.resize(columnCount());
if (m_bTree)
pNode->Path = MakeBoxPath(ID, Groups);
pNode->pBox = NULL;
New[pNode->Path].append(pNode);
Added.append(ID);
2022-07-10 17:28:10 +01:00
QIcon Icon = QIcon(bPlus ? ":/Boxes/Group2" : ":/Boxes/Group"); // theGUI->GetBoxIcon(CSandBoxPlus::eDefault, false);
2022-07-09 10:46:07 +01:00
if (m_LargeIcons) // but not for boxes
Icon = QIcon(Icon.pixmap(QSize(32,32)).scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
pNode->Icon = Icon;
2021-10-16 16:19:51 +01:00
pNode->IsBold = true;
pNode->Values[eName].Raw = Group;
2022-06-16 17:35:26 +01:00
if(bGroupsFirst)
pNode->Values[eName].SortKey = ID;
2021-10-16 16:19:51 +01:00
pNode->Values[eStatus].Raw = tr("Box Group");
}
else
{
I.value() = NULL;
Index = Find(m_Root, pNode);
}
int Changed = 0;
QString ParentGroup = pNode->Path.isEmpty() ? "" : CSbieModel__RemoveGroupMark(pNode->Path.last().toString());
int OrderNumber = Groups[ParentGroup].indexOf(Group);
if (pNode->OrderNumber != OrderNumber) {
2022-11-23 17:14:26 +00:00
pNode->OrderNumber = (OrderNumber == -1) ? Groups[ParentGroup].size() : OrderNumber;
2021-10-16 16:19:51 +01:00
Changed = 1;
}
if (Changed && Index.isValid())
emit dataChanged(createIndex(Index.row(), 0, pNode), createIndex(Index.row(), columnCount()-1, pNode));
}
foreach (const CSandBoxPtr& pBox, BoxList)
{
2023-07-01 17:54:53 +01:00
if (!ShowHidden && (!pBox->IsEnabled() /*|| pBox->GetBool("IsShadow")*/))
2021-10-16 16:19:51 +01:00
continue;
QVariant ID = pBox->GetName();
QModelIndex Index;
QHash<QVariant, STreeNode*>::iterator I = Old.find(ID);
SSandBoxNode* pNode = I != Old.end() ? static_cast<SSandBoxNode*>(I.value()) : NULL;
if(!pNode)
{
pNode = static_cast<SSandBoxNode*>(MkNode(ID));
pNode->Values.resize(columnCount());
if (m_bTree)
pNode->Path = MakeBoxPath(ID, Groups);
pNode->pBox = pBox;
New[pNode->Path].append(pNode);
Added.append(ID);
}
else
{
I.value() = NULL;
Index = Find(m_Root, pNode);
}
CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(pBox.data());
int Col = 0;
bool State = false;
int Changed = 0;
QString Group = pNode->Path.isEmpty() ? "" : CSbieModel__RemoveGroupMark(pNode->Path.last().toString());
int OrderNumber = Groups[Group].indexOf(pBox->GetName());
if (pNode->OrderNumber != OrderNumber) {
2022-11-23 17:14:26 +00:00
pNode->OrderNumber = (OrderNumber == -1) ? Groups[Group].size() : OrderNumber;
2021-10-16 16:19:51 +01:00
Changed = 1;
}
QMap<quint32, CBoxedProcessPtr> ProcessList = pBox->GetProcessList();
2023-07-06 20:12:22 +01:00
if (bHideCore) {
for (auto I = ProcessList.begin(); I != ProcessList.end();) {
if (I.value()->GetFileName().indexOf(theAPI->GetSbiePath() + "\\Sandboxie", Qt::CaseInsensitive) == 0)
I = ProcessList.erase(I);
else
++I;
}
}
2021-10-16 16:19:51 +01:00
bool inUse = Sync(pBox, pNode->Path, ProcessList, New, Old, Added);
2023-07-01 17:54:53 +01:00
bool Busy = pBoxEx->IsBoxBusy();
2021-10-16 16:19:51 +01:00
int boxType = pBoxEx->GetType();
2022-11-07 11:06:15 +00:00
bool boxDel = pBoxEx->IsAutoDelete();
2023-04-29 10:55:43 +01:00
bool boxNoForce = pBoxEx->IsForceDisabled();
2022-07-10 17:28:10 +01:00
int boxColor = pBoxEx->GetColor();
2023-08-24 17:39:00 +01:00
SSandBoxNode::EMountState mountState = SSandBoxNode::eNone;
if (pBoxEx->UseRamDisk())
mountState = SSandBoxNode::eRamDisk;
else if (pBoxEx->UseImageFile()) {
if(pBoxEx->GetMountRoot().isEmpty())
mountState = SSandBoxNode::eUnmounted;
else
mountState = SSandBoxNode::eMounted;
}
2021-10-16 16:19:51 +01:00
2022-07-09 10:46:07 +01:00
QIcon Icon;
2022-12-16 12:08:49 +00:00
QString BoxIcon = pBox->GetText("BoxIcon");
if (!BoxIcon.isEmpty())
2022-09-29 17:28:48 +01:00
{
2023-04-29 10:55:43 +01:00
if (pNode->BoxIcon != BoxIcon || (pNode->busyState || Busy) || pNode->boxDel != boxDel || pNode->boxNoForce != boxNoForce)
2022-12-16 12:08:49 +00:00
{
StrPair PathIndex = Split2(BoxIcon, ",");
if (!PathIndex.second.isEmpty() && !PathIndex.second.contains("."))
2022-12-21 09:14:31 +00:00
Icon = QIcon(LoadWindowsIcon(PathIndex.first, PathIndex.second.toInt()));
2022-12-16 12:08:49 +00:00
else
Icon = QIcon(QPixmap(BoxIcon));
pNode->BoxIcon = BoxIcon;
2022-09-29 17:28:48 +01:00
}
}
2023-07-01 17:54:53 +01:00
else if (pNode->inUse != inUse ||
(pNode->busyState || Busy) ||
pNode->boxType != boxType ||
pNode->boxColor != boxColor ||
pNode->boxDel != boxDel ||
pNode->boxNoForce != boxNoForce ||
2023-08-24 17:39:00 +01:00
!pNode->BoxIcon.isEmpty() ||
pNode->MountState != mountState
2023-07-01 17:54:53 +01:00
)
2021-10-16 16:19:51 +01:00
{
pNode->inUse = inUse;
pNode->boxType = boxType;
2022-07-10 17:28:10 +01:00
pNode->boxColor = boxColor;
2022-11-18 14:11:46 +00:00
pNode->boxDel = boxDel;
2023-04-29 10:55:43 +01:00
pNode->boxNoForce = boxNoForce;
2021-10-16 16:19:51 +01:00
//pNode->Icon = pNode->inUse ? m_BoxInUse : m_BoxEmpty;
2022-07-10 17:28:10 +01:00
if(ColorIcons)
Icon = theGUI->GetColorIcon(boxColor, inUse);
else
Icon = theGUI->GetBoxIcon(boxType, inUse);
2022-12-16 12:08:49 +00:00
pNode->BoxIcon.clear();
2023-08-24 17:39:00 +01:00
pNode->MountState = mountState;
2022-07-09 10:46:07 +01:00
}
2022-11-07 12:05:19 +00:00
if (!Icon.isNull())
{
if (Busy)
Icon = theGUI->MakeIconBusy(Icon, pNode->busyState++);
else {
pNode->busyState = 0;
2023-04-29 10:55:43 +01:00
if (OverlayIcons)
{
if(boxNoForce)
Icon = theGUI->IconAddOverlay(Icon, ":/IconDFP");
2023-08-24 17:39:00 +01:00
else if(mountState == SSandBoxNode::eRamDisk)
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/RamDisk.png");
else if(mountState == SSandBoxNode::eMounted)
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/LockOpen.png");
else if(mountState == SSandBoxNode::eUnmounted)
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/LockClosed.png");
2023-04-29 10:55:43 +01:00
else if (boxDel && !bVintage)
Icon = theGUI->IconAddOverlay(Icon, ":/Boxes/AutoDel");
}
2022-11-07 12:05:19 +00:00
}
2022-07-09 10:46:07 +01:00
if (m_LargeIcons) // but not for boxes
Icon = QIcon(Icon.pixmap(QSize(32,32)).scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
2022-11-07 12:05:19 +00:00
2022-07-09 10:46:07 +01:00
pNode->Icon = Icon;
2021-10-16 16:19:51 +01:00
Changed = 1; // set change for first column
}
2022-07-09 10:46:07 +01:00
2021-10-16 16:19:51 +01:00
if (pNode->IsGray != !pBoxEx->IsEnabled())
{
pNode->IsGray = !pBoxEx->IsEnabled();
Changed = 2; // set change for all columns
}
for(int section = 0; section < columnCount(); section++)
{
2023-05-27 15:14:29 +01:00
if (!IsColumnEnabled(section))
2021-10-16 16:19:51 +01:00
continue; // ignore columns which are hidden
QVariant Value;
switch(section)
{
case eName: Value = pBox->GetName(); break;
case eStatus: Value = pBox.objectCast<CSandBoxPlus>()->GetStatusStr(); break;
2022-06-13 19:12:53 +01:00
case eInfo: Value = pBox.objectCast<CSandBoxPlus>()->IsEmptyCached() ? -2 : (bWatchSize ? pBox.objectCast<CSandBoxPlus>()->GetSize() : 0); break;
2021-10-16 16:19:51 +01:00
case ePath: Value = pBox->GetFileRoot(); break;
}
SSandBoxNode::SValue& ColValue = pNode->Values[section];
if (ColValue.Raw != Value)
{
if(Changed == 0)
Changed = 1;
ColValue.Raw = Value;
switch (section)
{
2022-05-16 20:30:40 +01:00
case eName: ColValue.Formatted = Value.toString().replace("_", " "); break;
2022-06-13 19:12:53 +01:00
case eInfo: ColValue.Formatted = Value.toULongLong() == -2 ? tr("Empty") : (Value.toULongLong() > 0 ? FormatSize(Value.toULongLong()) : ""); break;
2021-10-16 16:19:51 +01:00
}
}
if(State != (Changed != 0))
{
if(State && Index.isValid())
emit dataChanged(createIndex(Index.row(), Col, pNode), createIndex(Index.row(), section-1, pNode));
State = (Changed != 0);
Col = section;
}
if(Changed == 1)
Changed = 0;
}
if(State && Index.isValid())
emit dataChanged(createIndex(Index.row(), Col, pNode), createIndex(Index.row(), columnCount()-1, pNode));
}
CTreeItemModel::Sync(New, Old);
return Added;
}
bool CSbieModel::Sync(const CSandBoxPtr& pBox, const QList<QVariant>& Path, const QMap<quint32, CBoxedProcessPtr>& ProcessList, QMap<QList<QVariant>, QList<STreeNode*> >& New, QHash<QVariant, STreeNode*>& Old, QList<QVariant>& Added)
{
QString BoxName = pBox->GetName();
int ActiveCount = 0;
2023-04-29 10:55:43 +01:00
bool OverlayIcons = theConf->GetBool("Options/UseOverlayIcons", true);
2021-10-16 16:19:51 +01:00
foreach(const CBoxedProcessPtr& pProc, ProcessList)
{
QSharedPointer<CSbieProcess> pProcess = pProc.objectCast<CSbieProcess>();
QVariant ID = pProcess->GetProcessId();
QModelIndex Index;
QHash<QVariant, STreeNode*>::iterator I = Old.find(ID);
SSandBoxNode* pNode = I != Old.end() ? static_cast<SSandBoxNode*>(I.value()) : NULL;
if (!pNode || (m_bTree ? !TestProcPath(pNode->Path.mid(Path.length()), BoxName, pProcess, ProcessList) : !pNode->Path.isEmpty())) // todo: improve that
{
pNode = static_cast<SSandBoxNode*>(MkNode(ID));
pNode->Values.resize(columnCount());
if (m_bTree)
pNode->Path = Path + MakeProcPath(BoxName, pProcess, ProcessList);
pNode->pBox = pBox;
pNode->pProcess = pProcess;
New[pNode->Path].append(pNode);
Added.append(ID);
}
else
{
I.value() = NULL;
Index = Find(m_Root, pNode);
}
//if(Index.isValid()) // this is to slow, be more precise
// emit dataChanged(createIndex(Index.row(), 0, pNode), createIndex(Index.row(), columnCount()-1, pNode));
int Col = 0;
bool State = false;
int Changed = 0;
bool bIsTerminated = pProcess->IsTerminated();
if (pNode->IsGray != bIsTerminated)
{
pNode->IsGray = bIsTerminated;
Changed = 2; // update all columns for this item
}
if (!bIsTerminated)
ActiveCount++;
2021-10-19 23:07:47 +01:00
if (pNode->Icon.isNull() && !pProcess->GetFileName().isEmpty())
2021-10-16 16:19:51 +01:00
{
//PixmapEntryList icons = extractIcons(pProcess->GetFileName(), false);
//if (icons.isEmpty())
// pNode->Icon = m_ExeIcon;
//else
// pNode->Icon = icons.first().pixmap;
2023-01-28 20:49:24 +00:00
QIcon Icon = m_IconProvider.icon(QFileInfo(pProcess->GetFileName()));
if (Icon.isNull())
Icon = m_ExeIcon;
2023-04-29 10:55:43 +01:00
if (OverlayIcons) {
if (pProcess->HasSystemToken())
2023-07-01 17:54:53 +01:00
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/SystemShield.png");
2023-04-29 10:55:43 +01:00
else if (pProcess->HasElevatedToken())
2023-07-01 17:54:53 +01:00
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/AdminShield.png");
2023-04-29 10:55:43 +01:00
else if (pProcess->HasAppContainerToken())
2023-07-01 17:54:53 +01:00
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/AppContainer.png"); // AppContainer is also Restricted
2023-04-29 10:55:43 +01:00
else if (pProcess->HasRestrictedToken())
2023-07-01 17:54:53 +01:00
Icon = theGUI->IconAddOverlay(Icon, ":/Actions/Restricted.png");
2023-04-29 10:55:43 +01:00
}
2023-01-28 20:49:24 +00:00
pNode->Icon = Icon;
2021-10-24 20:07:20 +01:00
Changed = 1;
2021-10-16 16:19:51 +01:00
}
for (int section = 0; section < columnCount(); section++)
{
2023-05-27 15:14:29 +01:00
if (!IsColumnEnabled(section))
2021-10-16 16:19:51 +01:00
continue; // ignore columns which are hidden
QVariant Value;
switch (section)
{
2023-03-13 19:49:27 +00:00
case eName: {
QString Name = pProcess->GetProcessName();
if (pProcess->IsWoW64())
Name += " *32";
Value = Name;
break;
}
2021-10-16 16:19:51 +01:00
case eProcessId: Value = pProcess->GetProcessId(); break;
case eStatus: Value = pProcess->GetStatusStr(); break;
case eTitle: Value = theAPI->GetProcessTitle(pProcess->GetProcessId()); break;
//case eLogCount: break; // todo Value = pProcess->GetResourceLog().count(); break;
2022-05-16 20:30:40 +01:00
case eInfo: Value = pProcess->GetTimeStamp(); break;
2021-10-16 16:19:51 +01:00
//case ePath: Value = pProcess->GetFileName(); break;
case ePath: {
QString CmdLine = pProcess->GetCommandLine();
Value = CmdLine.isEmpty() ? pProcess->GetFileName() : CmdLine;
break;
}
}
SSandBoxNode::SValue& ColValue = pNode->Values[section];
if (ColValue.Raw != Value)
{
if (Changed == 0)
Changed = 1;
ColValue.Raw = Value;
switch (section)
{
2022-05-16 20:30:40 +01:00
case eProcessId: ColValue.Formatted = QString::number(pProcess->GetProcessId()); break;
//case eLogCount: ColValue.Formatted = QString::number(Value.toInt()); break;
case eInfo: ColValue.Formatted = pProcess->GetTimeStamp().toString("hh:mm:ss"); break;
2021-10-16 16:19:51 +01:00
}
}
if (State != (Changed != 0))
{
if (State && Index.isValid())
emit dataChanged(createIndex(Index.row(), Col, pNode), createIndex(Index.row(), section - 1, pNode));
State = (Changed != 0);
Col = section;
}
if (Changed == 1)
Changed = 0;
}
if (State && Index.isValid())
emit dataChanged(createIndex(Index.row(), Col, pNode), createIndex(Index.row(), columnCount() - 1, pNode));
}
return ActiveCount != 0;
}
QVariant CSbieModel::NodeData(STreeNode* pNode, int role, int section) const
{
if (section == 0 && role == Qt::InitialSortOrderRole) {
return ((SSandBoxNode*)pNode)->OrderNumber;
}
return CTreeItemModel::NodeData(pNode, role, section);
}
CSandBoxPtr CSbieModel::GetSandBox(const QModelIndex &index) const
{
if (!index.isValid())
return CSandBoxPtr();
SSandBoxNode* pNode = static_cast<SSandBoxNode*>(index.internalPointer());
ASSERT(pNode);
return pNode->pBox;
}
CBoxedProcessPtr CSbieModel::GetProcess(const QModelIndex &index) const
{
if (!index.isValid())
return CBoxedProcessPtr();
SSandBoxNode* pNode = static_cast<SSandBoxNode*>(index.internalPointer());
ASSERT(pNode);
return pNode->pProcess;
}
2022-04-16 14:01:01 +01:00
QString CSbieModel::GetGroup(const QModelIndex& index) const
{
if (!index.isValid())
return QString();
SSandBoxNode* pNode = static_cast<SSandBoxNode*>(index.internalPointer());
ASSERT(pNode);
if(!CSbieModel__HasGroupMark(pNode->ID.toString()))
return QString();
return pNode->ID.toString();
}
2021-10-16 16:19:51 +01:00
QVariant CSbieModel::GetID(const QModelIndex &index) const
{
if (!index.isValid())
return QVariant();
SSandBoxNode* pNode = static_cast<SSandBoxNode*>(index.internalPointer());
ASSERT(pNode);
if (!pNode->pProcess && !pNode->pBox)
return CSbieModel__RemoveGroupMark(pNode->ID.toString());
return pNode->ID;
}
CSbieModel::ETypes CSbieModel::GetType(const QModelIndex &index) const
{
if (!index.isValid())
return eNone;
SSandBoxNode* pNode = static_cast<SSandBoxNode*>(index.internalPointer());
ASSERT(pNode);
if (pNode->pProcess)
return eProcess;
if (pNode->pBox)
return eBox;
return eGroup;
}
int CSbieModel::columnCount(const QModelIndex &parent) const
{
return eCount;
}
QVariant CSbieModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
switch(section)
{
case eName: return tr("Name");
case eProcessId: return tr("Process ID");
case eStatus: return tr("Status");
case eTitle: return tr("Title");
2022-05-16 20:30:40 +01:00
case eInfo: return tr("Info");
//case eSize: return tr("Size");
2021-10-16 16:19:51 +01:00
//case eLogCount: return tr("Log Count");
2022-05-16 20:30:40 +01:00
//case eTimeStamp: return tr("Start Time");
2021-10-16 16:19:51 +01:00
case ePath: return tr("Path / Command Line");
}
}
return QVariant();
}
/*QVariant CSbieModel::GetDefaultIcon() const
{
return g_ExeIcon;
}*/
2022-04-16 14:01:01 +01:00
2022-07-09 10:46:07 +01:00
QVariant CSbieModel::data(const QModelIndex &index, int role) const
{
2022-08-08 09:07:38 +01:00
//if(m_LargeIcons && role == Qt::SizeHintRole)
// return QSize(32,32);
2022-07-09 10:46:07 +01:00
return CTreeItemModel::data(index, role);
}
2022-04-16 14:01:01 +01:00
Qt::ItemFlags CSbieModel::flags(const QModelIndex& index) const
{
Qt::ItemFlags Flags = CTreeItemModel::flags(index);
Flags |= Qt::ItemIsDragEnabled;
SSandBoxNode* pNode = static_cast<SSandBoxNode*>(index.internalPointer());
if (!pNode || (pNode && CSbieModel__HasGroupMark(pNode->ID.toString())) || pNode == m_Root)
Flags |= Qt::ItemIsDropEnabled;
return Flags;
}
QMimeData* CSbieModel::mimeData(const QModelIndexList &indexes) const
{
QStringList Boxes;
for (int i = 0; i < indexes.count(); i++) {
if (indexes[i].column() != 0)
continue;
SSandBoxNode* pNode = static_cast<SSandBoxNode*>(indexes[i].internalPointer());
Boxes.append(pNode->ID.toString());
}
QMimeData *data = new QMimeData();
data->setData(m_SbieModelMimeType, Boxes.join(",").toLatin1());
return data;
}
bool CSbieModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) {
QStringList Boxes = QString::fromLatin1(data->data(m_SbieModelMimeType)).split(",");
QString To = ""; // root
SSandBoxNode* pNode = static_cast<SSandBoxNode*>(parent.internalPointer());
if (pNode)
To = CSbieModel__RemoveGroupMark(pNode->ID.toString());
foreach(const QString & Name, Boxes) {
if(CSbieModel__HasGroupMark(Name))
2022-06-04 20:07:04 +01:00
MoveGroup(CSbieModel__RemoveGroupMark(Name), To, row);
2022-04-16 14:01:01 +01:00
else
2022-06-04 20:07:04 +01:00
MoveBox(Name, To, row);
2022-04-16 14:01:01 +01:00
}
return true;
2022-11-18 14:11:46 +00:00
}