1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-25 20:22:39 +01:00

Add uptime to sysinfo

This commit is contained in:
Elias Steurer 2021-02-13 20:14:10 +01:00
parent 817734e6b6
commit 7e10ae47e2
6 changed files with 149 additions and 18 deletions

View File

@ -9,8 +9,22 @@ find_package(
COMPONENTS Quick Core
REQUIRED)
set(src screenplaysysinfo_plugin.cpp sysinfo.cpp cpu.cpp ram.cpp storage.cpp)
set(headers screenplaysysinfo_plugin.h sysinfo.h cpu.h ram.h mathhelper.h storage.h)
set(src
screenplaysysinfo_plugin.cpp
sysinfo.cpp
cpu.cpp
ram.cpp
storage.cpp
uptime.cpp)
set(headers
screenplaysysinfo_plugin.h
sysinfo.h
cpu.h
ram.h
mathhelper.h
storage.h
uptime.h)
add_library(${PROJECT_NAME} SHARED ${src} ${headers})

View File

@ -37,10 +37,10 @@
#include <QDebug>
#include <QObject>
#include <QTimer>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
//#include <sysinfoapi.h>
#define DWORDLONG unsigned long long

View File

@ -5,5 +5,6 @@ SysInfo::SysInfo(QQuickItem* parent)
, m_ram(std::make_unique<RAM>())
, m_cpu(std::make_unique<CPU>())
, m_storage(std::make_unique<Storage>())
, m_uptime(std::make_unique<Uptime>())
{
}

View File

@ -40,6 +40,7 @@
#include "cpu.h"
#include "ram.h"
#include "storage.h"
#include "uptime.h"
class SysInfo : public QQuickItem {
Q_OBJECT
@ -47,33 +48,25 @@ class SysInfo : public QQuickItem {
Q_PROPERTY(RAM* ram READ ram NOTIFY ramChanged)
Q_PROPERTY(CPU* cpu READ cpu NOTIFY cpuChanged)
Q_PROPERTY(Storage* storage READ storage NOTIFY storageChanged)
Q_PROPERTY(Uptime* uptime READ uptime NOTIFY uptimeChanged)
public:
SysInfo(QQuickItem* parent = nullptr);
~SysInfo() { }
RAM* ram() const
{
return m_ram.get();
}
CPU* cpu() const
{
return m_cpu.get();
}
Storage* storage() const
{
return m_storage.get();
}
RAM* ram() const { return m_ram.get(); }
CPU* cpu() const { return m_cpu.get(); }
Storage* storage() const { return m_storage.get(); }
Uptime* uptime() const { return m_uptime.get(); }
signals:
void ramChanged(RAM* ram);
void cpuChanged(CPU* cpu);
void storageChanged(Storage* storage);
void uptimeChanged(Uptime* uptime);
private:
std::unique_ptr<RAM> m_ram;
std::unique_ptr<CPU> m_cpu;
std::unique_ptr<Storage> m_storage;
std::unique_ptr<Uptime> m_uptime;
};

View File

@ -0,0 +1,37 @@
#include "uptime.h"
#ifdef Q_OS_WINDOWS
#include <Windows.h>
#include <sysinfoapi.h>
#endif
Uptime::Uptime(QObject* parent)
: QObject(parent)
{
QObject::connect(&m_updateTimer, &QTimer::timeout, this, &Uptime::update);
m_updateTimer.start(m_tickRate);
}
void Uptime::update()
{
#ifdef Q_OS_WINDOWS
auto ticks = GetTickCount64();
auto milliseconds = ticks % 1000;
ticks /= 1000;
auto seconds = ticks % 60;
ticks /= 60;
auto minutes = ticks % 60;
ticks /= 60;
auto hours = ticks;
ticks /= 24;
auto days = ticks;
ticks /= 365;
auto years = ticks;
setSeconds(seconds);
setMinutes(minutes);
setHours(hours);
setDays(days);
setYears(years);
#endif
}

View File

@ -0,0 +1,86 @@
#pragma once
#include <QObject>
#include <QTimer>
class Uptime : public QObject {
Q_OBJECT
Q_PROPERTY(int days READ days WRITE setDays NOTIFY daysChanged)
Q_PROPERTY(int years READ years WRITE setYears NOTIFY yearsChanged)
Q_PROPERTY(int hours READ hours WRITE setHours NOTIFY hoursChanged)
Q_PROPERTY(int minutes READ minutes WRITE setMinutes NOTIFY minutesChanged)
Q_PROPERTY(int seconds READ seconds WRITE setSeconds NOTIFY secondsChanged)
public:
Uptime(QObject* parent = nullptr);
int days() const { return m_days; }
int years() const { return m_years; }
int hours() const { return m_hours; }
int minutes() const { return m_minutes; }
int seconds() const { return m_seconds; }
public slots:
void update();
void setDays(int days)
{
if (m_days == days)
return;
m_days = days;
emit daysChanged(m_days);
}
void setYears(int years)
{
if (m_years == years)
return;
m_years = years;
emit yearsChanged(m_years);
}
void setHours(int hours)
{
if (m_hours == hours)
return;
m_hours = hours;
emit hoursChanged(m_hours);
}
void setMinutes(int minutes)
{
if (m_minutes == minutes)
return;
m_minutes = minutes;
emit minutesChanged(m_minutes);
}
void setSeconds(int seconds)
{
if (m_seconds == seconds)
return;
m_seconds = seconds;
emit secondsChanged(m_seconds);
}
signals:
void daysChanged(int days);
void yearsChanged(int years);
void hoursChanged(int hours);
void minutesChanged(int minutes);
void secondsChanged(int seconds);
private:
int m_days = 0;
int m_years = 0;
int m_hours = 0;
int m_minutes = 0;
int m_seconds = 0;
int m_tickRate = 1000;
QTimer m_updateTimer;
};