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

« back to all changes in this revision

Viewing changes to info/memorywidget.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 "memorywidget.h"
21
 
#include "computerpage.h"
22
 
#include "../dbusproxy/youkersystemdbus.h"
23
 
#include <QDebug>
24
 
 
25
 
MemoryWidget::MemoryWidget(QWidget *parent, SystemDispatcher *proxy) :
26
 
    QWidget(parent),
27
 
    systemproxy(proxy)
28
 
{
29
 
    this->setStyleSheet("QWidget{border: none;background-color: #ffffff;}");
30
 
    setFixedSize(750, 403);
31
 
    scroll_widget = new ScrollWidget(this);
32
 
    scroll_widget->setGeometry(0, 0, 750, 403);
33
 
    dataOK = false;
34
 
}
35
 
 
36
 
MemoryWidget::~MemoryWidget()
37
 
{
38
 
    this->clear_page_list();
39
 
    if (scroll_widget != NULL) {
40
 
        delete scroll_widget;
41
 
        scroll_widget = NULL;
42
 
    }
43
 
}
44
 
 
45
 
void MemoryWidget::clear_page_list()
46
 
{
47
 
    for(int i=0; i<page_list.count(); i++)
48
 
    {
49
 
        ComputerPage *page = page_list.at(i);
50
 
        delete page;
51
 
        page = NULL;
52
 
    }
53
 
    page_list.clear();
54
 
    if (scroll_widget)
55
 
        scroll_widget->resetWidget();
56
 
}
57
 
 
58
 
bool MemoryWidget::displaySwitch()
59
 
{
60
 
    memory_info_map.clear();
61
 
    memory_info_map = systemproxy->get_memory_info_qt();
62
 
    if (memory_info_map.isEmpty() || memory_info_map.count() <= 0)
63
 
    {
64
 
        return false;
65
 
    }
66
 
    else
67
 
    {
68
 
        return true;
69
 
    }
70
 
}
71
 
 
72
 
bool MemoryWidget::getStatus()
73
 
{
74
 
    return this->dataOK;
75
 
}
76
 
 
77
 
void MemoryWidget::initData()
78
 
{
79
 
    this->clear_page_list();
80
 
    memory_info_map = systemproxy->get_memory_info_qt();//?硬盘,显卡,声卡,内存界面需要重新调用?为何其他界面不需要重新调用
81
 
    QMap<QString, QVariant>::iterator iter = memory_info_map.find("Memnum");
82
 
    int memoryNum = 0;
83
 
    if (iter == memory_info_map.end()) {
84
 
        memoryNum = 0;
85
 
    }
86
 
    else{
87
 
        memoryNum = iter.value().toInt();
88
 
    }
89
 
    if(memoryNum == 0) {
90
 
    }
91
 
    else {
92
 
        if(memoryNum == 1) {
93
 
            ComputerPage *page = new ComputerPage(scroll_widget->zone, tr("Memory Info"));
94
 
            page_list.append(page);
95
 
            memory_info_map.remove("Memnum");
96
 
            QMap<QString, QVariant> tmpMap;
97
 
            QMap<QString,QVariant>::iterator it;
98
 
            for ( it = memory_info_map.begin(); it != memory_info_map.end(); ++it ) {
99
 
                if (it.value().toString().length() > 0) {
100
 
                    tmpMap.insert(it.key(), it.value());
101
 
                }
102
 
            }
103
 
            page->setMap(tmpMap, "UBUNTUKYLIN");
104
 
            page->initUI(false);
105
 
            scroll_widget->addScrollWidget(page);
106
 
        }
107
 
        else if(memoryNum > 1) {
108
 
            for(int i=0;i<memoryNum;i++) {
109
 
                ComputerPage *page = new ComputerPage(scroll_widget->zone, tr("Memory Info %1").arg(i+1));
110
 
                page_list.append(page);
111
 
                tmp_info_map.clear();
112
 
                QMap<QString, QVariant>::iterator itbegin = memory_info_map.begin();
113
 
                QMap<QString, QVariant>::iterator  itend = memory_info_map.end();
114
 
                for (;itbegin != itend; ++itbegin) {
115
 
                    if(itbegin.key() != "Memnum" && itbegin.value().toString().contains("<1_1>")) {
116
 
                        QString result = itbegin.value().toString().split("<1_1>").at(i);
117
 
                        if (result.length() > 0) {
118
 
                            tmp_info_map.insert(itbegin.key(), result);
119
 
                        }
120
 
                    }
121
 
                }
122
 
                page->setMap(tmp_info_map, tmp_info_map.value("MemVendor").toString().toUpper());
123
 
                page->initUI(false);
124
 
                scroll_widget->addScrollWidget(page);
125
 
            }
126
 
        }
127
 
    }
128
 
 
129
 
    /*QMap<QString, QVariant>::iterator iter = memory_info_map.find("Memnum");
130
 
    int memoryNum = 0;
131
 
    if (iter == memory_info_map.end())
132
 
    {
133
 
        memoryNum = 0;
134
 
    }
135
 
    else{
136
 
        memoryNum = iter.value().toInt();
137
 
    }
138
 
    if(memory_info_map.count() == 1 && memory_info_map.contains("kylinkobe"))
139
 
    {
140
 
    }
141
 
    else {
142
 
        if(memoryNum == 1)
143
 
        {
144
 
            ComputerPage *page = new ComputerPage(scroll_widget->zone, tr("Memory Info"));
145
 
            memory_info_map.remove("Memnum");
146
 
            QMap<QString, QVariant> tmpMap;
147
 
            QMap<QString,QVariant>::iterator it;
148
 
            for ( it = memory_info_map.begin(); it != memory_info_map.end(); ++it ) {
149
 
                if (it.value().toString().length() > 0) {
150
 
                    tmpMap.insert(it.key(), it.value());
151
 
                }
152
 
            }
153
 
            page->setMap(tmpMap, "UBUNTUKYLIN");
154
 
            page->initUI();
155
 
            scroll_widget->addScrollWidget(page);
156
 
        }
157
 
        else if(memoryNum > 1)
158
 
        {
159
 
            for(int i=0;i<memoryNum;i++)
160
 
            {
161
 
                ComputerPage *page = new ComputerPage(scroll_widget->zone, tr("Memory Info %1").arg(i+1));
162
 
                tmp_info_map.clear();
163
 
                QMap<QString, QVariant>::iterator itbegin = memory_info_map.begin();
164
 
                QMap<QString, QVariant>::iterator  itend = memory_info_map.end();
165
 
                for (;itbegin != itend; ++itbegin)
166
 
                {
167
 
                    if(itbegin.key() != "Memnum" && itbegin.value().toString().contains("<1_1>")) {
168
 
                        QString result = itbegin.value().toString().split("<1_1>").at(i);
169
 
                        if (result.length() > 0) {
170
 
                            tmp_info_map.insert(itbegin.key(), result);
171
 
                        }
172
 
                    }
173
 
                }
174
 
                page->setMap(tmp_info_map, tmp_info_map.value("MemVendor").toString().toUpper());
175
 
                page->initUI();
176
 
                scroll_widget->addScrollWidget(page);
177
 
            }
178
 
        }
179
 
    }*/
180
 
//    dataOK = true;
181
 
}