diff --git a/.gitignore b/.gitignore index 234639a..94777a1 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ moc* *Make* +make-release.sh src/sysmon-qt *.sav* notes diff --git a/src/sysmon-qt b/src/sysmon-qt deleted file mode 100755 index 8318736..0000000 Binary files a/src/sysmon-qt and /dev/null differ diff --git a/src/sysmon-qt.cpp b/src/sysmon-qt.cpp index 2ca27a6..308bff6 100644 --- a/src/sysmon-qt.cpp +++ b/src/sysmon-qt.cpp @@ -1,12 +1,10 @@ #include #include #include -#include #include #include #include #include -// #include #include "sysmon-qt.h" #include "sm_config.h" @@ -36,6 +34,19 @@ sysmon_qt::sysmon_qt() font_size = settings.value( "fontSize" , 12 ).toInt(); font_normal = QFont( font_family, font_size ); + // Files + fUptime = new QFile( "/proc/uptime" ); + fUptime ->open( QIODevice::ReadOnly | QIODevice::Text); + + fLoadAvg = new QFile( "/proc/loadavg" ); + fLoadAvg->open( QIODevice::ReadOnly | QIODevice::Text); + + fMemInfo = new QFile( "/proc/meminfo" ); + fMemInfo->open( QIODevice::ReadOnly | QIODevice::Text); + + fStat = new QFile( "/proc/stat" ); + fStat ->open( QIODevice::ReadOnly | QIODevice::Text); + // Set up palettes set_palettes(); @@ -98,6 +109,11 @@ sysmon_qt::~sysmon_qt() settings.setValue( "positionX", QString::number( position.x() ) ); settings.setValue( "positionY", QString::number( position.y() ) ); settings.sync(); + + if ( fUptime ->isOpen() ) fUptime ->close(); + if ( fLoadAvg->isOpen() ) fLoadAvg->close(); + if ( fMemInfo->isOpen() ) fMemInfo->close(); + if ( fStat ->isOpen() ) fStat ->close(); } void sysmon_qt::setup_all() @@ -178,12 +194,10 @@ void sysmon_qt::update_uptime( void ) if ( lbl_uptime == nullptr ) return; if ( tick % 60 != 0 ) return; // Update once a minute - QFile file( "/proc/uptime" ); - file.open( QIODevice::ReadOnly | QIODevice::Text); - QByteArray ba = file.readLine(); - file.close(); + fUptime->seek( 0 ); + QByteArray baUptime = fUptime->readLine(); - QString lineString = QString( ba ); + QString lineString = QString( baUptime ); QString upSecs = lineString.left( lineString.indexOf(".") ); uint secs = upSecs.toInt(); @@ -204,7 +218,8 @@ void sysmon_qt::setup_cpuLoad() bool useCPU = settings.value( "useCPU", true ).toBool(); bool useCPUbar = settings.value( "useCPUbar", true ).toBool(); - lbl_cpu = nullptr; + lbl_cpu = nullptr; + lbl_loads = nullptr; if ( ! useCPU && ! useCPUbar ) return; @@ -247,12 +262,10 @@ void sysmon_qt::update_cpu( void ) if ( lbl_loads != nullptr ) { - QFile file( "/proc/loadavg" ); - file.open( QIODevice::ReadOnly | QIODevice::Text); - QByteArray ba2 = file.readLine(); - file.close(); + fLoadAvg->seek( 0 ); + QByteArray ba = fLoadAvg->readLine(); - QString lineString = QString( ba2 ); + QString lineString = QString( ba ); QStringList loadList = lineString.split( QLatin1Char(' ') ); QString CPU_loads = loadList[0] + " " + loadList[1] + " " + @@ -297,9 +310,8 @@ void sysmon_qt::update_memory( void ) if ( lbl_memory == nullptr ) return; if ( tick % memory_refresh != 0 ) return; - QFile file( "/proc/meminfo" ); - file.open( QIODevice::ReadOnly | QIODevice::Text); - QTextStream textStream( &file ); + fMemInfo->seek( 0 ); + QTextStream textStream( fMemInfo ); QString MemTotal; QString MemAvailable; @@ -314,7 +326,6 @@ void sysmon_qt::update_memory( void ) break; } } - file.close(); QRegularExpression re( "\\d+" ); QRegularExpressionMatch match = re.match( MemTotal ); @@ -591,7 +602,6 @@ void sysmon_qt::update_cpu_percentage( void ) // Could possibly do it every cpu_refresh time (3 seconds for now) static qint64 previousJiffiesWork; static qint64 previousJiffiesTotal; - static QFile* file; QString cpu; // Not really used -- always "cpu" qint64 user, // jiffies @@ -602,16 +612,16 @@ void sysmon_qt::update_cpu_percentage( void ) // First time through only if ( previousJiffiesWork == 0 ) { - file = new QFile( "/proc/stat" ); - file->open( QIODevice::ReadOnly | QIODevice::Text); - QTextStream stream( file ); + fStat->seek( 0 ); + QTextStream stream( fStat ); stream >> cpu >> user >> nice >> system >> idle; + previousJiffiesWork = user + nice + system; previousJiffiesTotal = previousJiffiesWork + idle; return; } - QTextStream stream( file ); + QTextStream stream( fStat ); stream.seek( 0 ); // Just read the first line each time stream >> cpu >> user >> nice >> system >> idle; diff --git a/src/sysmon-qt.h b/src/sysmon-qt.h index 5b44e10..402e28d 100644 --- a/src/sysmon-qt.h +++ b/src/sysmon-qt.h @@ -2,6 +2,7 @@ #define SYSMONQT_H #include +#include #include #include #include @@ -29,25 +30,30 @@ public slots: QLabel* textlabel( const QString&, int = -1, int = QFont::Normal ); QLabel* banner ( const QString&, int = 0, int = QFont::Bold ); - int tick = 0; // tick every second - int cpu_refresh = 3; - int memory_refresh = 3; - int temp_refresh = 5; - int tempsCount; - int cpuPercentage; - bool pauseUpdate = false; - bool mFrame = false; // turn frame on and off - bool pauseTempUpdate = false; // turn temperature update on and off - QString TZ; // time zone - QPoint position; // location of widget - - QLabel* lbl_hostname; - QLabel* lbl_time; // time of day - QLabel* lbl_date; - QLabel* lbl_uptime; - QLabel* lbl_cpu; // title - QLabel* lbl_loads; // label for memory - QLabel* lbl_memory; // title + int tick = 0; // tick every second + int cpu_refresh = 3; + int memory_refresh = 3; + int temp_refresh = 5; + int tempsCount; + int cpuPercentage; + bool pauseUpdate = false; + bool mFrame = false; // turn frame on and off + bool pauseTempUpdate = false; // turn temperature update on and off + QString TZ; // time zone + QPoint position; // location of widget + + QLabel* lbl_hostname; + QLabel* lbl_time; // time of day + QLabel* lbl_date; + QLabel* lbl_uptime; + QLabel* lbl_cpu; // title + QLabel* lbl_loads; // label for memory + QLabel* lbl_memory; // title + + QFile* fUptime; + QFile* fLoadAvg; + QFile* fMemInfo; + QFile* fStat; QProgressBar* memory; QProgressBar* load;