Хранилища Subversion OpenInventory

Редакция

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

Редакция 16 Редакция 159
1
#include "src/form.h"
1
#include "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
        int index;
38
38
39
//      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\"");    
40
        program.append(tr(" -U Àäìèíèñòðàòîð%Patr10t //"));
40
        program.append(tr(" -U Àäìèíèñòðàòîð%Patr10t //"));
41
        program.append(tr(m_ui->lineEdit_2->text()));
41
        program.append(tr(m_ui->lineEdit_2->text()));
42
        program.append(tr(" \"select * from "));
42
        program.append(tr(" \"select * from "));
43
        index = m_ui->comboBox_2->currentIndex();
43
        index = m_ui->comboBox_2->currentIndex();
44
        program.append(m_ui->comboBox_2->itemText(index));
44
        program.append(m_ui->comboBox_2->itemText(index));
45
        program.append(tr("\""));
45
        program.append(tr("\""));
46
        //                  Win32_ComputerSystem\""));
46
        //                  Win32_ComputerSystem\""));
47
        int i;
47
        int i;
48
        i++;
48
        i++;
49
        wmiProcess.start(program);
49
        wmiProcess.start(program);
50
       
50
       
51
}
51
}
52
52
53
53
54
void Form::readStandartProcessOutput(){
54
void Form::readStandartProcessOutput(){
55
        QByteArray arr;
55
        QByteArray arr;
56
        QStringList result, list_tmp, list_tmp_value;
56
        QStringList result, list_tmp, list_tmp_value;
57
        QString str1, str2, str_tmp, str_buf;
57
        QString str1, str2, str_tmp, str_buf;
58
        int i;
58
        int i;
59
        arr = wmiProcess.readAllStandardOutput();
59
        arr = wmiProcess.readAllStandardOutput();
60
        QTextCodec *codecUTF = QTextCodec::codecForName("utf8");
60
        QTextCodec *codecUTF = QTextCodec::codecForName("utf8");
61
        QTextCodec *codec = QTextCodec::codecForName("cp1251");
61
        QTextCodec *codec = QTextCodec::codecForName("cp1251");
62
        QTextCodec::setCodecForTr(codecUTF);
62
        QTextCodec::setCodecForTr(codecUTF);
63
        str1 = QString(tr(arr));
63
        str1 = QString(tr(arr));
64
        result.clear();
64
        result.clear();
65
//        result << QStringList(tr(arr));
65
//        result << QStringList(tr(arr));
66
        QTextCodec::setCodecForTr(codec);
66
        QTextCodec::setCodecForTr(codec);
67
67
68
//      str2 << arr;
68
//      str2 << arr;
69
        i = result.size();
69
        i = result.size();
70
//      str1 = result.at(0);
70
//      str1 = result.at(0);
71
        i++;
71
        i++;
72
        i = str1.indexOf("\r");
72
        i = str1.indexOf("\r");
73
        i = str1.indexOf("\n");
73
        i = str1.indexOf("\n");
74
        str_tmp = str1.left(i);
74
        str_tmp = str1.left(i);
75
        m_ui->lineEdit->insert(str1);
75
        m_ui->lineEdit->insert(str1);
76
76
77
        while (i != -1){
77
        while (i != -1){
78
        i = str1.indexOf("\n");
78
        i = str1.indexOf("\n");
79
        if (i != -1) {
79
        if (i != -1) {
80
                str_tmp = str1.left(i);
80
                str_tmp = str1.left(i);
81
                result << str_tmp;
81
                result << str_tmp;
82
                str1.remove(0, i+1);}
82
                str1.remove(0, i+1);}
83
       
83
       
84
        }
84
        }
85
        document = m_ui->textEdit->document();
85
        document = m_ui->textEdit->document();
86
                cursor = new QTextCursor(document);
86
                cursor = new QTextCursor(document);
87
                cursor->movePosition(QTextCursor::Start);
87
                cursor->movePosition(QTextCursor::Start);
88
     QTextCharFormat format(cursor->charFormat());
88
     QTextCharFormat format(cursor->charFormat());
89
     //format.setFontFamily("Courier");
89
     //format.setFontFamily("Courier");
90
     format.setFontFamily("Arial");
90
     format.setFontFamily("Arial");
91
     //format.setFontItalic(false);
91
     //format.setFontItalic(false);
92
92
93
     format.setFontWeight(QFont::Normal);
93
     format.setFontWeight(QFont::Normal);
94
     QTextCharFormat boldFormat = format;
94
     QTextCharFormat boldFormat = format;
95
     boldFormat.setFontWeight(QFont::Bold);
95
     boldFormat.setFontWeight(QFont::Bold);
96
96
97
        QTextCharFormat italicFormat = format;
97
        QTextCharFormat italicFormat = format;
98
     //format.setFontFamily("Courier");
98
     //format.setFontFamily("Courier");
99
//     format.setFontFamily("Arial");
99
//     format.setFontFamily("Arial");
100
     italicFormat.setFontItalic(true);
100
     italicFormat.setFontItalic(true);
101
101
102
for (int m = 0; m < result.size(); ++m){
102
for (int m = 0; m < result.size(); ++m){
103
         cursor->insertText(result.at(m), format);
103
         cursor->insertText(result.at(m), format);
104
     cursor->insertBlock();
104
     cursor->insertBlock();
105
     cursor->insertText(tr("--------------------------"), format);
105
     cursor->insertText(tr("--------------------------"), format);
106
     cursor->insertBlock();
106
     cursor->insertBlock();
107
}
107
}
108
108
109
str_tmp = result.at(1);
109
str_tmp = result.at(1);
110
list_tmp = get_substr_arr(str_tmp, "|");
110
list_tmp = get_substr_arr(str_tmp, "|");
111
/*
111
/*
112
i=0;
112
i=0;
113
while (i != -1){
113
while (i != -1){
114
        i = str_tmp.indexOf("|");
114
        i = str_tmp.indexOf("|");
115
        if (i != -1) {
115
        if (i != -1) {
116
                str_buf = str_tmp.left(i);
116
                str_buf = str_tmp.left(i);
117
                list_tmp << str_buf;
117
                list_tmp << str_buf;
118
                str_tmp.remove(0, i+1);}
118
                str_tmp.remove(0, i+1);}
119

119

120
        }
120
        }
121

121

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