diff --git a/app/controller.cpp b/app/controller.cpp index dfb1c33a5ac62a43c370cd6ab0e30e247ee64a7e..80714abaea3b4fce08bcdaf320249be19d7e0b91 100644 --- a/app/controller.cpp +++ b/app/controller.cpp @@ -1,8 +1,9 @@ #include "controller.h" #include <QDebug> -Controller::Controller() : eltCollection() +Controller::Controller(MainWindow *window) : eltCollection(), genStatus(), main(window) { + QTimer *timer = new QTimer(); timer->connect(timer, SIGNAL(timeout()), this , SLOT(update())); timer->start(1000); @@ -10,6 +11,8 @@ Controller::Controller() : eltCollection() } void Controller::update(){ - qDebug() << "timer lancé"; + //qDebug() << "timer lancé"; //eltCollection.update(); + genStatus.update(); + main->update_status(genStatus); } diff --git a/app/controller.h b/app/controller.h index e5ee7bd2d64e70287b7372443fc22dfe2c366cfd..6b6aa6118d75b4103ff716e004502f6fc61677e5 100644 --- a/app/controller.h +++ b/app/controller.h @@ -2,7 +2,11 @@ #define CONTROLLER_H #include "elements.h" +#include "generalstatus.h" +#include "mainwindow.h" #include <QTimer> +#include <QApplication> + class Controller : public QObject { @@ -10,13 +14,15 @@ class Controller : public QObject public: - Controller(); + Controller(MainWindow*); public slots : void update(); private : + MainWindow *main; Elements eltCollection; + GeneralStatus genStatus; }; #endif // CONTROLLER_H diff --git a/app/generalstatus.cpp b/app/generalstatus.cpp index 8186d6167fa627ebb9ce6f12e7399d91baadfe90..429056b954a44a792061185b741c70ffe6a75e9e 100644 --- a/app/generalstatus.cpp +++ b/app/generalstatus.cpp @@ -1,4 +1,5 @@ #include "generalstatus.h" +#include <QDebug> GeneralStatus::GeneralStatus() : user_time(0), uptime("/proc/uptime"), meminfo("/proc/meminfo"), stat("/proc/stat"), nbT(".nbT") { @@ -9,7 +10,7 @@ GeneralStatus::GeneralStatus() : user_time(0), uptime("/proc/uptime"), meminfo(" QString line0 = in.readLine(); QStringList fields0 = line0.split(" "); - memTotal = fields0.at(1).toInt(); + memTotal = fields0.at(fields0.length()-2).toInt(); meminfo.close(); @@ -27,8 +28,8 @@ void GeneralStatus::update() QString line = in_s.readLine(); QStringList fields = line.split(" "); - CPU = static_cast<double>(fields.at(1).toInt()-user_time)/100.0; - user_time = fields.at(1).toInt(); + CPU = static_cast<double>(fields.at(2).toInt()-user_time); + user_time = fields.at(2).toInt(); stat.close(); @@ -41,7 +42,7 @@ void GeneralStatus::update() line = in_t.readLine(); fields = line.split(" "); - time = fields.at(0).toDouble(); + time = static_cast<int>(fields.at(0).toDouble()); uptime.close(); @@ -56,7 +57,9 @@ void GeneralStatus::update() line = in_m.readLine(); fields = line.split(" "); - mem = static_cast<double>(memTotal-fields.at(1).toInt())/static_cast<double>(memTotal); + mem = static_cast<int>((static_cast<double>(memTotal-fields.at(fields.length()-2).toInt())/static_cast<double>(memTotal))*100*100.0)/100.0; + + meminfo.close(); // nb task : system("ls /proc | grep '[0-9]' | wc -l > .nbT"); // ecrit le nb de processus dans le fichier .nbT @@ -72,7 +75,7 @@ void GeneralStatus::update() } -double GeneralStatus::getTime() +int GeneralStatus::getTime() { return time; } diff --git a/app/generalstatus.h b/app/generalstatus.h index b89fdce5a51dff5270d0a63fce4aec718de1264b..cfa60a33ff8acbc0ba4c4842d3c6a8b5589b2fe1 100644 --- a/app/generalstatus.h +++ b/app/generalstatus.h @@ -7,14 +7,14 @@ class GeneralStatus : public Updatable { public: GeneralStatus(); - double getTime(); + int getTime(); double getMem(); int getMemTotal(); double getCPU(); int getNbTask(); void update(); private: - double time; + int time; double mem; int memTotal; double CPU; diff --git a/app/main.cpp b/app/main.cpp index 4778870982d20f994beaaf8bd60ea097fd102675..59761060ec941999d9fb4a83aad9001e9e297ac3 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) w.show(); // lance le controller qui gère le timer pour l'update régulier - Controller * _controller = new Controller(); + Controller * _controller = new Controller(&w); return a.exec(); } diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 7011b537322a6037109bc4c7713a1aefb9100f15..8246b46aa1a6ead70eb5b9e2e4b88320bd89b747 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -18,6 +18,22 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::update_status(GeneralStatus &genStatus) +{ + int time = genStatus.getTime(); + int j = time/86400; + time-=j*86400; + int h = time/3600; + time-=h*3600; + int m = time/60; + int s = time - m*60; + + ui->statusBar->clearMessage(); + QString message = "uptime: " + QString::number(j)+ ":" + QString::number(h)+ ":" + QString::number(m)+ ":" + QString::number(s) + " tasks running: " + QString::number(genStatus.getNbTask()) + " CPU: " + QString::number(genStatus.getCPU()) + "% memory: " + QString::number(genStatus.getMem()) + "%"; + ui->statusBar->showMessage(message); + +} + void MainWindow::on_comboBox_currentTextChanged(const QString &arg1) { diff --git a/app/mainwindow.h b/app/mainwindow.h index ede189b6928ff07389a2c2c7a5f102d4176f5037..d94286866db047aed1921a737121549a0e114baa 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -3,7 +3,7 @@ #include <QMainWindow> #include <QMessageBox> -#include "controller.h" +#include "generalstatus.h" namespace Ui { class MainWindow; @@ -16,6 +16,7 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + void update_status(GeneralStatus &genStatus); private slots: void on_comboBox_currentTextChanged(const QString &arg1);