Subversion Repositories OpenInventory

Rev

Rev 255 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 255 Rev 256
1
#ifndef WMITHREAD_H
1
#ifndef WMITHREAD_H
2
#define WMITHREAD_H
2
#define WMITHREAD_H
3
3
4
#include <QThread>
4
#include <QThread>
5
#include <QProcess>
5
#include <QProcess>
6
#include <QMutex>
6
#include <QMutex>
7
#include <QDebug>
7
#include <QDebug>
8
#include <QEventLoop>
8
#include <QEventLoop>
9
#include "woker.h"
9
#include "woker.h"
10
10
11
class WmiThread : public QThread
11
class WmiThread : public QThread
12
{
12
{
13
    Q_OBJECT
13
    Q_OBJECT
14
public:
14
public:
15
    explicit WmiThread(QObject *parent = 0);
15
    explicit WmiThread(QObject *parent = 0);
16
    void run();
16
    void run();
17
    void stop();
17
    void stop();
18
    void setHost(QString new_host){host = new_host;}
18
    void setHost(QString new_host){host = new_host;}
19
    void setUser(QString new_user){user_name = new_user;}
19
    void setUser(QString new_user){user_name = new_user;}
20
    void setPassword(QString new_password){password = new_password;}
20
    void setPassword(QString new_password){password = new_password;}
21
    QByteArray buffer(){return p_buffer;}
21
    QByteArray buffer(){return p_buffer;}
22
    void clearBuffer(){p_buffer.clear();}
22
    void clearBuffer(){p_buffer.clear();}
23
    bool isError(){return error;}
23
    bool isError(){return error;}
24
    bool isStopped(){
24
    bool isStopped(){
25
        mutex.lock();
25
        mutex.lock();
26
        return stopped;
26
        return stopped;
27
        mutex.unlock();
27
        mutex.unlock();
28
28
29
                        }
29
                        }
30
    void setWmiString(QString new_wmi_string){wmi_string = new_wmi_string;}
30
    void setWmiString(QString new_wmi_string){wmi_string = new_wmi_string;}
31
    QString resultString(){
31
    QString resultString(){
32
32
33
        QTextCodec *codec = QTextCodec::codecForName("cp1251");
33
        QTextCodec *codec = QTextCodec::codecForName("cp1251");
34
        QTextCodec *codecUTF = QTextCodec::codecForName("utf8");
34
        QTextCodec *codecUTF = QTextCodec::codecForName("utf8");
35
        QTextCodec::setCodecForTr(codecUTF);
35
        QTextCodec::setCodecForTr(codecUTF);
36
        QString tmp_str;
36
        QString tmp_str;
37
        tmp_str = tr(p_buffer);
37
        tmp_str = tr(p_buffer);
38
        QTextCodec::setCodecForTr(codec);
38
        QTextCodec::setCodecForTr(codec);
39
        //  return QString(tr(p_buffer));
39
        //  return QString(tr(p_buffer));
40
        return tmp_str;
40
        return tmp_str;
41
                            }
41
                            }
42
volatile bool stopped;
42
volatile bool stopped;
43
private:
43
private:
44
44
45
    volatile bool error;
45
    volatile bool error;
46
46
47
   QProcess process;
47
   QProcess process;
48
    QString host;
48
    QString host;
49
    QString user_name;
49
    QString user_name;
50
    QString password;
50
    QString password;
51
    QMutex mutex;
51
    QMutex mutex;
52
    QByteArray p_buffer; //çäåñü áóäåì õðàíèòü äàííûå, ñ÷èòàííûå èç ñòàíäàðòíîãî ïîòîêà äëÿ ÷òåíèÿ (ïðîöåññà)
52
    QByteArray p_buffer; //çäåñü áóäåì õðàíèòü äàííûå, ñ÷èòàííûå èç ñòàíäàðòíîãî ïîòîêà äëÿ ÷òåíèÿ (ïðîöåññà)
53
    QString wmi_string;  //çäåñü áóäåì õðàíèòü wmi-çàïðîñ
53
    QString wmi_string;  //çäåñü áóäåì õðàíèòü wmi-çàïðîñ
-
 
54
    QEventLoop *loop;
54
55
55
signals:
56
signals:
-
 
57
    void stop_now();
56
58
57
public slots:
59
public slots:
58
    void readStandartProcessOutput();
60
    void readStandartProcessOutput();
59
    void readStandartProcessError();
61
    void readStandartProcessError();
60
 //   void wokerIsStopped();
62
 //   void wokerIsStopped();
61
63
62
private slots:
64
private slots:
63
65
64
66
65
67
66
};
68
};
67
69
68
#endif // WMITHREAD_H
70
#endif // WMITHREAD_H
69
 
71