aboutsummaryrefslogtreecommitdiff
path: root/src/session.h
blob: 2b39a78c5822c1f54d8b723e38acb968f561e03a (plain)
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
#pragma once

#include <QObject>
#include <QQmlApplicationEngine>
#include <QQuickItem>
#include <QTimerEvent>
#include <QTranslator>
#include <QtDBus/QtDBus>

#include "RWADBusAdaptor.h"
#include "main_qmladaptor.h"
//#include "session.cpp"

class Session : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString status READ getStatus NOTIFY statusChanged) // this makes status available as a QML property
    Q_PROPERTY(int     id     READ getId     NOTIFY idChanged    ) // this makes id     available as a QML property
    Q_PROPERTY(QString url    READ getURL    NOTIFY urlChanged   ) // this makes url    available as a QML property
    Q_PROPERTY(QString pin    READ getPin    NOTIFY pinChanged   ) // this makes pin    available as a QML property
public:
    explicit Session(QObject *parent, MainQMLAdaptor *main_gui = nullptr);

    QString getStatus();
    QString getURL();
    int getId();
    QString getPin();

    void setStatus(QString status);
    void setURL(QString url);
    void setId(int id);
    void setPin(QString pin);

    // Starts a VNC Session
    void start_request_dbus();
    // Refreshes a VNC Session's status
    void refresh_status_request_dbus(int pid);
    // Stop the Session
    void stop_request_dbus(int pid);
    // Gets a VNC Session's status
    void status_request_dbus(int pid);
    // Returns true if Session is somewhat usable (Running, Alive, etc..)
    bool isSessionAliveOrRunning(QString status);

protected:
    QString _status;
    void statusTimerEvent();
    void init_vars();
private:
    MainQMLAdaptor* _main_gui;
    int _id;
    QString _url;
    QString _pin;
    OrgArcticaProjectRWAInterface* _dbus_rwa;
    void _initDBus();

    bool _minimizedBefore = false;

signals:
    void finished();
    void statusChanged(QString status);
    void idChanged(int id);
    void urlChanged(QString URL);
    void pinChanged(QString pin);

public slots:
    void handleConnectButtonClick(bool checked);

    void start_dbus_replied(QDBusPendingCallWatcher *call);
    void stop_dbus_replied(QDBusPendingCallWatcher *call);
    void status_dbus_replied(QDBusPendingCallWatcher *call);

    void onCloseHandler();
};