Хранилища Subversion OpenInventory

Редакция

Редакция 14 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 14 Редакция 16
1
#include "src/form.h"
1
#include "src/form.h"
2
#include "ui_form.h"
2
#include "ui_form.h"
3
3
4
Form::Form(QWidget *parent) :
4
Form::Form(QWidget *parent) :
5
    QWidget(parent),
5
    QWidget(parent),
6
    m_ui(new Ui::Form)
6
    m_ui(new Ui::Form)
7
{
7
{
8
    m_ui->setupUi(this);
8
    m_ui->setupUi(this);
9
    connect(&wmiProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
9
    connect(&wmiProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
10
}
10
}
11
11
12
Form::~Form()
12
Form::~Form()
13
{
13
{
14
    delete m_ui;
14
    delete m_ui;
15
}
15
}
16
16
17
void Form::changeEvent(QEvent *e)
17
void Form::changeEvent(QEvent *e)
18
{
18
{
19
    QWidget::changeEvent(e);
19
    QWidget::changeEvent(e);
20
    switch (e->type()) {
20
    switch (e->type()) {
21
    case QEvent::LanguageChange:
21
    case QEvent::LanguageChange:
22
        m_ui->retranslateUi(this);
22
        m_ui->retranslateUi(this);
23
        break;
23
        break;
24
    default:
24
    default:
25
        break;
25
        break;
26
    }
26
    }
27
}
27
}
28
28
29
29
30
30
31
31
32
void Form::on_wmiButton_clicked(){
32
void Form::on_wmiButton_clicked(){
33
       
33
       
34
//      QString program = tr(" wmic -U Àäìèíèñòðàòîð%Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"");
34
//      QString program = tr(" wmic -U Àäìèíèñòðàòîð%Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"");
35
        QString program = tr("wmic");
35
        QString program = tr("wmic");
36
        QStringList arguments;
36
        QStringList arguments;
-
 
37
        int index;
37
38
38
//      arguments << tr(" -U Àäìèíèñòðàòîð%Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"");    
39
//      arguments << tr(" -U Àäìèíèñòðàòîð%Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"");    
39
        program.append(tr(" -U Àäìèíèñòðàòîð%Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\""));
40
        program.append(tr(" -U Àäìèíèñòðàòîð%Patr10t //"));
-
 
41
        program.append(tr(m_ui->lineEdit_2->text()));
-
 
42
        program.append(tr(" \"select * from "));
-
 
43
        index = m_ui->comboBox_2->currentIndex();
-
 
44
        program.append(m_ui->comboBox_2->itemText(index));
-
 
45
        program.append(tr("\""));
-
 
46
        //                  Win32_ComputerSystem\""));
40
        int i;
47
        int i;
41
        i++;
48
        i++;
42
        wmiProcess.start(program);
49
        wmiProcess.start(program);
43
       
50
       
44
}
51
}
45
52
46
53
47
void Form::readStandartProcessOutput(){
54
void Form::readStandartProcessOutput(){
48
        QByteArray arr;
55
        QByteArray arr;
49
        QStringList result;
56
        QStringList result, list_tmp, list_tmp_value;
50
        QString str1, str2, str_tmp;
57
        QString str1, str2, str_tmp, str_buf;
51
        int i;
58
        int i;
52
        arr = wmiProcess.readAllStandardOutput();
59
        arr = wmiProcess.readAllStandardOutput();
53
        QTextCodec *codecUTF = QTextCodec::codecForName("utf8");
60
        QTextCodec *codecUTF = QTextCodec::codecForName("utf8");
54
        QTextCodec *codec = QTextCodec::codecForName("cp1251");
61
        QTextCodec *codec = QTextCodec::codecForName("cp1251");
55
        QTextCodec::setCodecForTr(codecUTF);
62
        QTextCodec::setCodecForTr(codecUTF);
56
        str1 = QString(tr(arr));
63
        str1 = QString(tr(arr));
-
 
64
        result.clear();
-
 
65
//        result << QStringList(tr(arr));
57
        QTextCodec::setCodecForTr(codec);
66
        QTextCodec::setCodecForTr(codec);
58
        result << QStringList(arr);
-
 
-
 
67
59
//      str2 << arr;
68
//      str2 << arr;
60
        i = result.size();
69
        i = result.size();
61
//      str1 = result.at(0);
70
//      str1 = result.at(0);
62
        i++;
71
        i++;
63
        i = str1.indexOf("\r");
72
        i = str1.indexOf("\r");
64
        i = str1.indexOf("\n");
73
        i = str1.indexOf("\n");
65
        str_tmp = str1.left(i);
74
        str_tmp = str1.left(i);
66
        m_ui->lineEdit->insert(str1);
75
        m_ui->lineEdit->insert(str1);
67
76
68
        while (i != -1){
77
        while (i != -1){
69
        i = str1.indexOf("\n");
78
        i = str1.indexOf("\n");
70
        if (i != -1) {
79
        if (i != -1) {
71
                str_tmp = str1.left(i);
80
                str_tmp = str1.left(i);
72
                result << str_tmp;
81
                result << str_tmp;
73
                str1.remove(0, i+1);}
82
                str1.remove(0, i+1);}
74
       
83
       
75
        }
84
        }
76
        document = m_ui->textEdit->document();
85
        document = m_ui->textEdit->document();
77
                cursor = new QTextCursor(document);
86
                cursor = new QTextCursor(document);
78
                cursor->movePosition(QTextCursor::Start);
87
                cursor->movePosition(QTextCursor::Start);
79
     QTextCharFormat format(cursor->charFormat());
88
     QTextCharFormat format(cursor->charFormat());
80
     //format.setFontFamily("Courier");
89
     //format.setFontFamily("Courier");
81
     format.setFontFamily("Arial");
90
     format.setFontFamily("Arial");
82
     //format.setFontItalic(false);
91
     //format.setFontItalic(false);
83
92
84
     format.setFontWeight(QFont::Normal);
93
     format.setFontWeight(QFont::Normal);
85
     QTextCharFormat boldFormat = format;
94
     QTextCharFormat boldFormat = format;
86
     boldFormat.setFontWeight(QFont::Bold);
95
     boldFormat.setFontWeight(QFont::Bold);
87
96
88
        QTextCharFormat italicFormat = format;
97
        QTextCharFormat italicFormat = format;
89
     //format.setFontFamily("Courier");
98
     //format.setFontFamily("Courier");
90
//     format.setFontFamily("Arial");
99
//     format.setFontFamily("Arial");
91
     italicFormat.setFontItalic(true);
100
     italicFormat.setFontItalic(true);
92
101
93
for (int m = 0; m < result.size(); ++m){
102
for (int m = 0; m < result.size(); ++m){
94
         cursor->insertText(result.at(m), format);
103
         cursor->insertText(result.at(m), format);
95
     cursor->insertBlock();
104
     cursor->insertBlock();
96
     cursor->insertText(tr("--------------------------"), format);
105
     cursor->insertText(tr("--------------------------"), format);
97
     cursor->insertBlock();
106
     cursor->insertBlock();
98
}
107
}
99
108
-
 
109
str_tmp = result.at(1);
-
 
110
list_tmp = get_substr_arr(str_tmp, "|");
-
 
111
/*
-
 
112
i=0;
-
 
113
while (i != -1){
-
 
114
        i = str_tmp.indexOf("|");
-
 
115
        if (i != -1) {
-
 
116
                str_buf = str_tmp.left(i);
-
 
117
                list_tmp << str_buf;
-
 
118
                str_tmp.remove(0, i+1);}
-
 
119

-
 
120
        }
-
 
121

-
 
122
*/
-
 
123
-
 
124
str_tmp = result.at(2);
-
 
125
i=0;
-
 
126
while (i != -1){
-
 
127
        i = str_tmp.indexOf("|");
-
 
128
        if (i != -1) {
-
 
129
                str_buf = str_tmp.left(i);
-
 
130
                list_tmp_value << str_buf;
-
 
131
                str_tmp.remove(0, i+1);}
-
 
132
-
 
133
        }
-
 
134
-
 
135
for (int m = 0; m < list_tmp.size(); ++m){
-
 
136
         cursor->insertText(list_tmp.at(m), format);
-
 
137
          cursor->insertText(" : ", format);
-
 
138
          cursor->insertText(list_tmp_value.at(m), format);
-
 
139
     cursor->insertBlock();
-
 
140
     cursor->insertText(tr("--------------------------"), format);
-
 
141
     cursor->insertBlock();
-
 
142
}
-
 
143
-
 
144
100
/*    
145
/*    
101
     cursor->insertText(result.at(2), format);
146
     cursor->insertText(result.at(2), format);
102
     cursor->insertBlock();
147
     cursor->insertBlock();
103
     cursor->insertText(tr("--------------------------"), format);
148
     cursor->insertText(tr("--------------------------"), format);
104
     cursor->insertBlock();
149
     cursor->insertBlock();
105
     cursor->insertText(result.at(3), format);
150
     cursor->insertText(result.at(3), format);
106
       
151
       
107
*/
152
*/
108
153
109
}
154
}
110
155
111
void Form::readStandartProcessError(){
156
void Form::readStandartProcessError(){
112
        QByteArray arr;
157
        QByteArray arr;
113
        arr = wmiProcess.readAllStandardError();
158
        arr = wmiProcess.readAllStandardError();
114
       
159
       
115
}
-
 
116
160
}
-
 
161
-
 
162
-
 
163
QStringList Form::get_substr_arr(QString stroka, QString razdelitel){
-
 
164
QStringList result;
-
 
165
QString str_tmp, str_buf;
-
 
166
int i = 0;
-
 
167
result.clear();
-
 
168
while (i != -1){
-
 
169
        i = stroka.indexOf(razdelitel);
-
 
170
        if (i != -1) {
-
 
171
                str_buf = stroka.left(i);
-
 
172
                result << str_buf;
-
 
173
                stroka.remove(0, i+1);}
-
 
174
-
 
175
        }
-
 
176
return result;
-
 
177
-
 
178
-
 
179
}
-
 
180