Sandboxie/SandboxiePlus/SandMan/Models/MonitorModel.cpp

154 lines
3.8 KiB
C++
Raw Normal View History

2022-03-26 09:09:24 +00:00
#include "stdafx.h"
#include "MonitorModel.h"
#include "../MiscHelpers/Common/Common.h"
#include "../SbiePlusAPI.h"
CMonitorModel::CMonitorModel(QObject* parent)
:CTreeItemModel(parent)
{
2023-01-07 15:57:55 +00:00
m_bObjTree = false;
2022-03-26 09:09:24 +00:00
m_Root = MkNode(QVariant());
}
CMonitorModel::~CMonitorModel()
{
2023-01-07 15:57:55 +00:00
FreeNode(m_Root);
m_Root = NULL;
2022-03-26 09:09:24 +00:00
}
2023-01-07 15:57:55 +00:00
QList<QModelIndex> CMonitorModel::Sync(const QMap<QString, CMonitorEntryPtr>& EntryMap, void* params)
2022-03-26 09:09:24 +00:00
{
2023-01-07 15:57:55 +00:00
QList<QModelIndex> NewBranches;
2022-03-26 09:09:24 +00:00
QMap<QList<QVariant>, QList<STreeNode*> > New;
QHash<QVariant, STreeNode*> Old = m_Map;
foreach(const CMonitorEntryPtr pEntry, EntryMap)
{
2023-01-07 15:57:55 +00:00
QVariant ID = (quint64)pEntry.data();
QList<QVariant> Path;
QString ObjName;
if (m_bObjTree) {
QString Name = pEntry->GetName();
if (Name.left(1) != "\\")
continue; // skip debug messages and sys calls, only list nt object namespace
QStringList NtPath = Name.split("\\");
for(int i=1; i < NtPath.size() - 1; i++)
Path.append(NtPath.mid(0, i+1).join("\\").toLower());
ID = NtPath.mid(0, NtPath.size()).join("\\").toLower();
ObjName = NtPath.last();
}
2022-03-26 09:09:24 +00:00
QModelIndex Index;
QHash<QVariant, STreeNode*>::iterator I = Old.find(ID);
STraceNode* pNode = I != Old.end() ? static_cast<STraceNode*>(I.value()) : NULL;
if (!pNode)
{
pNode = static_cast<STraceNode*>(MkNode(ID));
pNode->Values.resize(columnCount());
2023-01-07 15:57:55 +00:00
pNode->Path = Path;
2022-03-26 09:09:24 +00:00
pNode->pEntry = pEntry;
New[pNode->Path].append(pNode);
}
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;
for (int section = 0; section < columnCount(); section++)
{
2023-05-27 15:14:29 +01:00
if (!IsColumnEnabled(section))
2022-03-26 09:09:24 +00:00
continue; // ignore columns which are hidden
QVariant Value;
switch (section)
{
2023-01-07 15:57:55 +00:00
case eType: Value = ObjName.isEmpty() ? pEntry->GetTypeStr() : ObjName; break;
case eStatus: Value = ObjName.isEmpty() ? pEntry->GetStautsStr() : (pEntry->GetTypeStr() + " " + pEntry->GetStautsStr()); break;
2022-03-26 09:09:24 +00:00
case eValue: Value = pEntry->GetName(); break;
case eCounter: Value = pEntry->GetCount(); break;
}
STraceNode::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 eType: ColValue.Formatted = ; break;
//case eValue: ColValue.Formatted = ; break;
2022-03-26 09:09:24 +00: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));
}
2023-01-07 15:57:55 +00:00
CTreeItemModel::Sync(New, Old, &NewBranches);
return NewBranches;
}
CMonitorModel::STreeNode* CMonitorModel::MkVirtualNode(const QVariant& Id, STreeNode* pParent)
{
STreeNode* pNode = CTreeItemModel::MkVirtualNode(Id, pParent);
if (!pNode->Values[0].Raw.isValid()) {
QStringList Paths = Id.toString().split("\\");
pNode->Values[0].Raw = Paths.last();
}
2022-03-26 09:09:24 +00:00
2023-01-07 15:57:55 +00:00
return pNode;
2022-03-26 09:09:24 +00:00
}
void CMonitorModel::Clear()
{
CTreeItemModel::Clear();
}
int CMonitorModel::columnCount(const QModelIndex& parent) const
{
return eCount;
}
QVariant CMonitorModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
switch (section)
{
case eType: return tr("Type");
case eStatus: return tr("Status");
case eValue: return tr("Value");
case eCounter: return tr("Count");
}
}
return QVariant();
}