summaryrefslogtreecommitdiffstats
path: root/src/VSession.h
blob: 8eb99cd2ecec691dc8715ca1bb64e77bb1d4b03d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (c) 2010,2011 - RZ Uni Freiburg
 * Copyright (c) 2010,2011 - OpenSLX Project
 *
 * This program/file is free software distributed under the GPL version 2.
 * See http://gpl.openslx.org/
 *
 * If you have any feedback please consult http://feedback.openslx.org/ and
 * send your feedback to feedback@openslx.org
 *
 * General information about OpenSLX - libChooser can be found under
 * http://openslx.org
 *
 */

#ifndef VMCHOOSER_VSESSION_H_
#define VMCHOOSER_VSESSION_H_

#include <QString>
#include <QList>
#include <QDomDocument>
#include <QDir>
#include <QProcess>
#include <QFSFileEngine>
#include <QDateTime>

#include "Session.h"
#include "VSessionHandler.h"

enum ImgType {
    VMWARE,
    VBOX,
    OTHER
};

class VSession : public Session {
  public:
	VSession(VSessionHandler *parent);
    bool init(const QString& xml, const QString& baseDirPath);

    ImgType imgtype() const;
    bool isActive() const;
    bool isLocked() const;
    bool isValid() const;
    int priority() const;

    QString shortDescription() const {
        return getAttribute("short_description");
    }

    QString description() const {
    	QString ret;
        ret = getNodeText("description_html");
        if (ret.size() > 0) return ret;
        return getAttribute("long_description");
    }

    QString icon() const;

    QString os() const {
        QString ret;
        ret = getAttribute("operating_system");
        if (ret.size() > 0) return ret;
        return getAttribute("os");
    }

    QString title() const {
    	QString tmp = getAttribute("title");
    	if (tmp.size() > 0) return tmp;
        return getAttribute("short_description");
    };

    QString screenshot() const;

    QString emulator() const {
    	return getAttribute("emulator");
    };

    QString author() const {
    	QString tmp;
    	tmp = getAttribute("creator") + "&lt;" + getAttribute("email") + "&gt;";
    	return tmp;
    };

    QString creationDate () const {
    	if (QFile::exists(QString(this->baseDirPath_).append("/").append(getAttribute("image_name")))) {
    		QFSFileEngine fe(QString(this->baseDirPath_).append("/").append(getAttribute("image_name"))); //QAbstractFileEngine::ModificationTime
    		return fe.fileTime(QAbstractFileEngine::CreationTime).toString(Qt::SystemLocaleLongDate);
    	}
    	return QString();
    };

    QString changeDate() const {
    	if (QFile::exists(QString(this->baseDirPath_).append("/").append(getAttribute("image_name")))) {
    		QFSFileEngine fe(QString(this->baseDirPath_).append("/").append(getAttribute("image_name"))); //QAbstractFileEngine::ModificationTime
    		return fe.fileTime(QAbstractFileEngine::AccessTime).toString(Qt::SystemLocaleLongDate);
    	}
    	return QString();
    };


    QString getAttribute(const QString& nodeName,
                             const QString& attribute = "param") const;
    QString getNodeText(const QString& nodeName) const;

    void addNodeWithAttribute(const QString& nodeName,
                              const QString& value,
                              const QString& attribute = "param",
                              bool replace = true);
    void addPrinters(const QString& script, const QString& type = "printer");
    void addScanners(const QString& script);
    void addUserAndHostname();
    void mergePoolXml();

    QString toXml() const;

    bool run() const;

    int type() const;

    bool operator<(const Session& other) const;

    static bool debugMode;



  private:
    QDomDocument doc_;
    QString baseDirPath_;
    VSessionHandler *sessionHandler;


    QProcess *_process;
};

#endif /*VMCHOOSER_VSESSION_H_*/