~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to info/sensorwidget.cpp

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 ~ 2015 National University of Defense Technology(NUDT) & Kylin Ltd.
3
 
 *
4
 
 * Authors:
5
 
 *  Kobe Lee    xiangli@ubuntukylin.com/kobe24_lixiang@126.com
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; version 3.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include "sensorwidget.h"
21
 
#include "computerpage.h"
22
 
 
23
 
SensorWieget::SensorWieget(QWidget *parent, SystemDispatcher *proxy) :
24
 
    QWidget(parent),
25
 
    systemproxy(proxy)
26
 
{
27
 
    this->setStyleSheet("QWidget{border: none;background-color: #ffffff;}");
28
 
    setFixedSize(750, 403);
29
 
    page = NULL;
30
 
    timer = new QTimer(this);
31
 
    connect(timer, SIGNAL(timeout()), this, SLOT(updateTimeValue()));
32
 
    scroll_widget = new ScrollWidget(this);
33
 
    scroll_widget->setGeometry(0, 0, 750, 403);
34
 
    this->initData();
35
 
}
36
 
 
37
 
SensorWieget::~SensorWieget()
38
 
{
39
 
    if (timer != NULL) {
40
 
        disconnect(timer,SIGNAL(timeout()),this,SLOT(updateTimeValue()));
41
 
        if(timer->isActive()) {
42
 
            timer->stop();
43
 
        }
44
 
        delete timer;
45
 
        timer = NULL;
46
 
    }
47
 
    this->clear_page_list();
48
 
    if (scroll_widget != NULL) {
49
 
        delete scroll_widget;
50
 
        scroll_widget = NULL;
51
 
    }
52
 
}
53
 
 
54
 
 
55
 
void SensorWieget::clear_page_list()
56
 
{
57
 
    if (page != NULL) {
58
 
        delete page;
59
 
        page = NULL;
60
 
    }
61
 
    if (scroll_widget)
62
 
        scroll_widget->resetWidget();
63
 
}
64
 
 
65
 
void SensorWieget::updateTimeValue()
66
 
{
67
 
    QMap<QString, QVariant> tmpMap = systemproxy->get_sensor_info_qt();
68
 
    if (tmpMap.isEmpty() || tmpMap.count() <= 0) {
69
 
 
70
 
    }
71
 
    else {
72
 
        sensor_info_map.clear();
73
 
        QMap<QString,QVariant>::iterator it;
74
 
        for (it = tmpMap.begin(); it != tmpMap.end(); ++it) {
75
 
            if (it.value().toString().length() > 0) {
76
 
                sensor_info_map.insert(it.key(), it.value());
77
 
            }
78
 
        }
79
 
        if (!sensor_info_map.isEmpty() && sensor_info_map.count() > 0) {
80
 
            page->resetSensor(sensor_info_map);
81
 
        }
82
 
    }
83
 
}
84
 
 
85
 
void SensorWieget::initData()
86
 
{
87
 
    QMap<QString, QVariant> tmpMap = systemproxy->get_sensor_info_qt();
88
 
    if (tmpMap.isEmpty() || tmpMap.count() <= 0) {
89
 
        page = NULL;
90
 
    }
91
 
    else {
92
 
        QMap<QString,QVariant>::iterator it;
93
 
        for ( it = tmpMap.begin(); it != tmpMap.end(); ++it ) {
94
 
            if (it.value().toString().length() > 0) {
95
 
                sensor_info_map.insert(it.key(), it.value());
96
 
            }
97
 
        }
98
 
        if (sensor_info_map.isEmpty() || sensor_info_map.count() <= 0) {
99
 
            page = NULL;
100
 
        }
101
 
        else {
102
 
            page = new ComputerPage(scroll_widget->zone, tr("Hardware sensor information"));
103
 
            page->setMap(sensor_info_map, "");
104
 
            page->setsensor(true);
105
 
            page->initUI(false);
106
 
            scroll_widget->addScrollWidget(page);
107
 
            timer->start(1000*4);
108
 
        }
109
 
    }
110
 
    /*QMap<QString,QVariant>::iterator it;
111
 
    for ( it = tmpMap.begin(); it != tmpMap.end(); ++it ) {
112
 
        if (it.value().toString().length() > 0) {
113
 
            sensor_info_map.insert(it.key(), it.value());
114
 
        }
115
 
    }
116
 
    if(sensor_info_map.count() == 0)
117
 
    {
118
 
        page = NULL;
119
 
    }
120
 
    else {
121
 
        page = new ComputerPage(scroll_widget->zone, tr("Hardware sensor information"));
122
 
        page->setMap(sensor_info_map, "");
123
 
        page->setsensor(true);
124
 
        page->initUI();
125
 
        scroll_widget->addScrollWidget(page);
126
 
        timer->start(1000*4);
127
 
    }*/
128
 
}