summaryrefslogtreecommitdiff
path: root/src/pmchart/hostdialog.cpp
blob: e46635e5d72ca0005a24ae62a8198495749c3483 (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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Copyright (c) 2013-2014, Red Hat.
 * Copyright (c) 2007, Aconex.  All Rights Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */
#include <QtCore/QDir>
#include <QtGui/QMessageBox>
#include "hostdialog.h"
#include "main.h"

HostDialog::HostDialog(QWidget *parent) : QDialog(parent)
{
    setupUi(this);
    my.nssGuiStarted = false;
}

void
HostDialog::quit()
{
    if (my.nssGuiStarted) {
	my.nssGuiProc->terminate();
	my.nssGuiStarted = false;
    }
}

void
HostDialog::languageChange()
{
    retranslateUi(this);
}

void
HostDialog::secureCheckBox_toggled(bool enableSecure)
{
    certificatesPushButton->setEnabled(enableSecure);
}

void
HostDialog::proxyCheckBox_toggled(bool enableProxy)
{
    proxyLineEdit->setEnabled(enableProxy);
}

void
HostDialog::authenticateCheckBox_toggled(bool enableAuthenticate)
{
    usernameLabel->setEnabled(enableAuthenticate);
    usernameLineEdit->setEnabled(enableAuthenticate);
    passwordLabel->setEnabled(enableAuthenticate);
    passwordLineEdit->setEnabled(enableAuthenticate);
    realmLabel->setEnabled(enableAuthenticate);
    realmLineEdit->setEnabled(enableAuthenticate);
}

QString
HostDialog::getHostName(void) const
{
    QString host;

    if (hostLineEdit->isModified())
        host = hostLineEdit->text().trimmed();
    if (host.length() == 0)
        return QString::null;
    return host;
}

QString
HostDialog::getHostSpecification(void) const
{
    QString host = getHostName();

    if (hostLineEdit->isModified())
        host = hostLineEdit->text().trimmed();
    if (host.length() == 0)
        return QString::null;

    if (proxyLineEdit->isModified()) {
        QString proxy = proxyLineEdit->text().trimmed();
        if (proxy.length() > 0)
            host.prepend("@").prepend(proxy);
    }

    if (authenticateCheckBox->isChecked()) {
	QString username = usernameLineEdit->text().trimmed();
	QString password = passwordLineEdit->text().trimmed();
	QString realm = realmLineEdit->text().trimmed();

	host.append("?username=").append(username);
	host.append("&password=").append(password);
	host.append("&realm=").append(realm);
    }

    return host;
}

int
HostDialog::getContextFlags(void) const
{
    int flags = 0;

    if (secureCheckBox->isChecked())
        flags |= PM_CTXFLAG_SECURE;
    if (compressCheckBox->isChecked())
        flags |= PM_CTXFLAG_COMPRESS;
    if (authenticateCheckBox->isChecked())
        flags |= PM_CTXFLAG_AUTH;
    return flags;
}

void
HostDialog::certificatesPushButton_clicked()
{
    if (!my.nssGuiStarted) {
	my.nssGuiStarted = true;
	nssGuiStart();
    }
}

void
HostDialog::nssGuiStart()
{
    QString	dbpath = QDir::toNativeSeparators(QDir::homePath());
    int		sep = __pmPathSeparator();

    dbpath.append(sep).append(".pki").append(sep).append("nssdb");
    dbpath.prepend("sql:");	// only use sqlite NSS databases

    QStringList	arguments;
    arguments << "--dbdir";
    arguments << dbpath;

    my.nssGuiProc = new QProcess(this);
    connect(my.nssGuiProc, SIGNAL(finished(int, QProcess::ExitStatus)),
                 this, SLOT(nssGuiFinished(int, QProcess::ExitStatus)));
    my.nssGuiProc->start("nss-gui", arguments);
}

void
HostDialog::nssGuiFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
    (void)exitStatus;

    if (exitCode) {
	QString message(tr("nss-gui helper process failed\nExit status was:"));
	message.append(exitCode).append("\n");
	QMessageBox::warning(this, pmProgname, message,
		QMessageBox::Ok|QMessageBox::Default|QMessageBox::Escape,
		Qt::NoButton, Qt::NoButton);
    }
    my.nssGuiStarted = false;
}