Subversion Repositories OpenInventory

Rev

Rev 14 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 pingvin 1
#include "src/form.h"
2
#include "ui_form.h"
3
 
4
Form::Form(QWidget *parent) :
5
    QWidget(parent),
6
    m_ui(new Ui::Form)
7
{
8
    m_ui->setupUi(this);
9
    connect(&wmiProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
10
}
11
 
12
Form::~Form()
13
{
14
    delete m_ui;
15
}
16
 
17
void Form::changeEvent(QEvent *e)
18
{
19
    QWidget::changeEvent(e);
20
    switch (e->type()) {
21
    case QEvent::LanguageChange:
22
        m_ui->retranslateUi(this);
23
        break;
24
    default:
25
        break;
26
    }
27
}
28
 
29
 
30
 
31
 
32
void Form::on_wmiButton_clicked(){
33
 
34
//      QString program = tr(" wmic -U %Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"");
35
        QString program = tr("wmic");
36
        QStringList arguments;
16 pingvin 37
        int index;
14 pingvin 38
 
39
//      arguments << tr(" -U %Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"");    
16 pingvin 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\""));
14 pingvin 47
        int i;
48
        i++;
49
        wmiProcess.start(program);
50
 
51
}
52
 
53
 
54
void Form::readStandartProcessOutput(){
55
        QByteArray arr;
16 pingvin 56
        QStringList result, list_tmp, list_tmp_value;
57
        QString str1, str2, str_tmp, str_buf;
14 pingvin 58
        int i;
59
        arr = wmiProcess.readAllStandardOutput();
60
        QTextCodec *codecUTF = QTextCodec::codecForName("utf8");
61
        QTextCodec *codec = QTextCodec::codecForName("cp1251");
62
        QTextCodec::setCodecForTr(codecUTF);
63
        str1 = QString(tr(arr));
16 pingvin 64
        result.clear();
65
//        result << QStringList(tr(arr));
14 pingvin 66
        QTextCodec::setCodecForTr(codec);
16 pingvin 67
 
14 pingvin 68
//      str2 << arr;
69
        i = result.size();
70
//      str1 = result.at(0);
71
        i++;
72
        i = str1.indexOf("\r");
73
        i = str1.indexOf("\n");
74
        str_tmp = str1.left(i);
75
        m_ui->lineEdit->insert(str1);
76
 
77
        while (i != -1){
78
        i = str1.indexOf("\n");
79
        if (i != -1) {
80
                str_tmp = str1.left(i);
81
                result << str_tmp;
82
                str1.remove(0, i+1);}
83
 
84
        }
85
        document = m_ui->textEdit->document();
86
                cursor = new QTextCursor(document);
87
                cursor->movePosition(QTextCursor::Start);
88
     QTextCharFormat format(cursor->charFormat());
89
     //format.setFontFamily("Courier");
90
     format.setFontFamily("Arial");
91
     //format.setFontItalic(false);
92
 
93
     format.setFontWeight(QFont::Normal);
94
     QTextCharFormat boldFormat = format;
95
     boldFormat.setFontWeight(QFont::Bold);
96
 
97
        QTextCharFormat italicFormat = format;
98
     //format.setFontFamily("Courier");
99
//     format.setFontFamily("Arial");
100
     italicFormat.setFontItalic(true);
101
 
102
for (int m = 0; m < result.size(); ++m){
103
         cursor->insertText(result.at(m), format);
104
     cursor->insertBlock();
105
     cursor->insertText(tr("--------------------------"), format);
106
     cursor->insertBlock();
107
}
108
 
16 pingvin 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
 
14 pingvin 145
/*    
146
     cursor->insertText(result.at(2), format);
147
     cursor->insertBlock();
148
     cursor->insertText(tr("--------------------------"), format);
149
     cursor->insertBlock();
150
     cursor->insertText(result.at(3), format);
151
 
152
*/
153
 
154
}
155
 
156
void Form::readStandartProcessError(){
157
        QByteArray arr;
158
        arr = wmiProcess.readAllStandardError();
159
 
16 pingvin 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
}