mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-09-18 16:32:33 +02:00
Add basic sysinfo structure
This commit is contained in:
parent
69385d76a1
commit
972e7bcad5
@ -9,11 +9,15 @@ uri = net.aimber.sysinfo
|
||||
# Input
|
||||
SOURCES += \
|
||||
screenplaysysinfo_plugin.cpp \
|
||||
sysinfo.cpp
|
||||
sysinfo.cpp \
|
||||
cpu.cpp \
|
||||
ram.cpp
|
||||
|
||||
HEADERS += \
|
||||
screenplaysysinfo_plugin.h \
|
||||
sysinfo.h
|
||||
sysinfo.h \
|
||||
cpu.h \
|
||||
ram.h
|
||||
|
||||
DISTFILES = qmldir
|
||||
|
||||
|
33
ScreenPlaySysInfo/cpu.cpp
Normal file
33
ScreenPlaySysInfo/cpu.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "cpu.h"
|
||||
#include <QtQml/qqml.h>
|
||||
|
||||
#define STATUS_SUCCESS 0
|
||||
#define STATUS_INFO_LENGTH_MISMATCH 0xC0000004
|
||||
|
||||
CPU::CPU(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CPU::update()
|
||||
{
|
||||
// long status = 0;
|
||||
// unsigned long bufSize = c_BufferSize;
|
||||
// byte* buf = (bufSize > 0) ? new BYTE[bufSize] : nullptr;
|
||||
|
||||
|
||||
|
||||
// status = c_NtQuerySystemInformation(SystemProcessorPerformanceInformation, buf, bufSize, &size);
|
||||
|
||||
// switch (status) {
|
||||
// case STATUS_INFO_LENGTH_MISMATCH:
|
||||
// qWarning() << "Warning: Status info length mismatch!";
|
||||
// break;
|
||||
// case STATUS_SUCCESS:
|
||||
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
}
|
56
ScreenPlaySysInfo/cpu.h
Normal file
56
ScreenPlaySysInfo/cpu.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <qt_windows.h>
|
||||
#endif
|
||||
|
||||
// https://github.com/rainmeter/rainmeter/blob/master/Library/MeasureCPU.cpp
|
||||
|
||||
typedef LONG(WINAPI* FPNTQSI)(UINT, PVOID, ULONG, PULONG);
|
||||
|
||||
class CPU : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(float usage READ usage NOTIFY usageChanged)
|
||||
|
||||
public:
|
||||
explicit CPU(QObject* parent = nullptr);
|
||||
|
||||
|
||||
float usage() const
|
||||
{
|
||||
return m_usage;
|
||||
}
|
||||
|
||||
signals:
|
||||
|
||||
void usageChanged(float usage);
|
||||
|
||||
public slots:
|
||||
void update();
|
||||
|
||||
void setUsage(float usage)
|
||||
{
|
||||
qWarning("Floating point comparison needs context sanity check");
|
||||
if (qFuzzyCompare(m_usage, usage))
|
||||
return;
|
||||
|
||||
m_usage = usage;
|
||||
emit usageChanged(m_usage);
|
||||
}
|
||||
|
||||
private:
|
||||
float m_usage = 42.0f;
|
||||
|
||||
int m_Processor;
|
||||
|
||||
double m_OldTime[2];
|
||||
|
||||
static FPNTQSI c_NtQuerySystemInformation;
|
||||
|
||||
static int c_NumOfProcessors;
|
||||
static ULONG c_BufferSize;
|
||||
};
|
8
ScreenPlaySysInfo/ram.cpp
Normal file
8
ScreenPlaySysInfo/ram.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "ram.h"
|
||||
#include <QtQml/qqml.h>
|
||||
#include <qmetatype.h>
|
||||
RAM::RAM(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
||||
}
|
39
ScreenPlaySysInfo/ram.h
Normal file
39
ScreenPlaySysInfo/ram.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
|
||||
class RAM : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(float usage READ usage NOTIFY usageChanged)
|
||||
|
||||
public:
|
||||
explicit RAM(QObject* parent = nullptr);
|
||||
|
||||
float usage() const
|
||||
{
|
||||
return m_usage;
|
||||
}
|
||||
|
||||
signals:
|
||||
|
||||
void usageChanged(float usage);
|
||||
|
||||
public slots:
|
||||
void exe(){
|
||||
qDebug() << "aa";
|
||||
}
|
||||
void setUsage(float usage)
|
||||
{
|
||||
qWarning("Floating point comparison needs context sanity check");
|
||||
if (qFuzzyCompare(m_usage, usage))
|
||||
return;
|
||||
|
||||
m_usage = usage;
|
||||
emit usageChanged(m_usage);
|
||||
}
|
||||
|
||||
private:
|
||||
float m_usage = 42.0f;
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "screenplaysysinfo_plugin.h"
|
||||
#include "sysinfo.h"
|
||||
|
||||
#include <qmetatype.h>
|
||||
#include <qqml.h>
|
||||
|
||||
QObject* ScreenPlaySysInfoSingleton(QQmlEngine* engine, QJSEngine* scriptEngine)
|
||||
@ -15,5 +15,5 @@ void ScreenPlaySysInfoPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
// @uri net.aimber.sysinfo
|
||||
qmlRegisterSingletonType<SysInfo>(uri, 1, 0, "SysInfo", ScreenPlaySysInfoSingleton);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,13 +3,13 @@
|
||||
SysInfo::SysInfo(QQuickItem *parent):
|
||||
QQuickItem(parent)
|
||||
{
|
||||
// By default, QQuickItem does not draw anything. If you subclass
|
||||
// QQuickItem to create a visual item, you will need to uncomment the
|
||||
// following line and re-implement updatePaintNode()
|
||||
|
||||
// setFlag(ItemHasContents, true);
|
||||
// FIXME Elias 2018 QQmlEngine cannot handle smartpointers yet....
|
||||
m_ram = new RAM();
|
||||
m_cpu = new CPU();
|
||||
}
|
||||
|
||||
SysInfo::~SysInfo()
|
||||
{
|
||||
delete m_cpu;
|
||||
delete m_ram;
|
||||
}
|
||||
|
@ -1,16 +1,39 @@
|
||||
#ifndef SYSINFO_H
|
||||
#define SYSINFO_H
|
||||
#pragma once
|
||||
|
||||
#include "cpu.h"
|
||||
#include "ram.h"
|
||||
#include <QQuickItem>
|
||||
#include <QSharedPointer>
|
||||
#include <memory>
|
||||
|
||||
class SysInfo : public QQuickItem
|
||||
{
|
||||
class SysInfo : public QQuickItem {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(SysInfo)
|
||||
|
||||
Q_PROPERTY(RAM* ram READ ram NOTIFY ramChanged)
|
||||
Q_PROPERTY(CPU* cpu READ cpu NOTIFY cpuChanged)
|
||||
|
||||
public:
|
||||
SysInfo(QQuickItem* parent = nullptr);
|
||||
~SysInfo();
|
||||
};
|
||||
|
||||
#endif // SYSINFO_H
|
||||
RAM* ram() const
|
||||
{
|
||||
return m_ram;
|
||||
}
|
||||
|
||||
CPU* cpu() const
|
||||
{
|
||||
return m_cpu;
|
||||
}
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
void ramChanged(RAM* ram);
|
||||
void cpuChanged(CPU* cpu);
|
||||
|
||||
private:
|
||||
RAM* m_ram;
|
||||
CPU* m_cpu;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user