summaryrefslogtreecommitdiff
path: root/gui/qml/logic.js
blob: 470900891676107789963b1b75a7a7fe5a6a1b62 (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
75
76
77
var status = 'off';
var needsReconnect = false;

function setNeedsReconnect(val) {
    needsReconnect = val;
}

function getNeedsReconnect() {
    return needsReconnect;
}

function setStatus(st) {
    status = st;
}

function getStatus() { 
    return status;
}

function setNeedsDonate(val) {
    needsDonate = val;
}

function toHuman(st) {
    switch (st) {
    case "off":
        //: %1 -> application name
        return qsTr("%1 off").arg(ctx.appName)
    case "on":
        //: %1 -> application name
        return qsTr("%1 on").arg(ctx.appName)
    case "connecting":
        //: %1 -> application name
        return qsTr("Connecting to %1").arg(ctx.appName)
    case "stopping":
        //: %1 -> application name
        return qsTr("Stopping %1").arg(ctx.appName)
    case "failed":
        //: %1 -> application name
        return qsTr("%1 blocking internet").arg(
                    ctx.appName) // TODO failed is not handled yet
    }
}

// Helper to show notification messages
function showNotification(ctx, msg) {
    console.log("Going to show notification message: ", msg)
    if (supportsMessages) {
        let appname = ctx ? ctx.appName : "VPN"
        showMessage(appname, msg, null, 15000)
    } else {
        console.log("System doesn't support systray notifications")
    }
}

function shouldAllowEmptyPass(providers) {
    let obj = JSON.parse(providers.getJson())
    let active = obj['default']
    let allProviders = obj['providers']
    for (var i = 0; i < allProviders.length; i++) {
        if (allProviders[i]['name'] === active) {
            return (allProviders[i]['authEmptyPass'] === 'true')
        }
    }
    return false
}

function getSelectedProvider(providers) {
    let obj = JSON.parse(providers.getJson())
    return obj['default']
}

function debugInit() {
    console.debug("Platform:", Qt.platform.os)
    console.debug("DEBUG: Pre-seeded providers:")
    console.debug(providers.getJson())
}