-
Notifications
You must be signed in to change notification settings - Fork 2
/
dreditconnectionwindow.cpp
143 lines (101 loc) · 4.15 KB
/
dreditconnectionwindow.cpp
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
/*
Deriv is a cross-platform client for th Wired 2.0 protocol
Copyright (C) 2014 Rafael Warnault, rw@read-write.fr
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 3 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dreditconnectionwindow.h"
#include "ui_dreditconnectionwindow.h"
#include "drmainwindow.h"
#include "dr.h"
#pragma mark -
DREditConnectionWindow::DREditConnectionWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::DREditConnectionWindow)
{
ui->setupUi(this);
this->connection = NULL;
}
DREditConnectionWindow::~DREditConnectionWindow()
{
delete ui;
}
#pragma mark -
void DREditConnectionWindow::setConnection(DRServerConnection *connection) {
this->connection = connection;
if(this->connection != NULL) {
ui->addressTextField->setEnabled(!this->connection->connected);
ui->loginTextField->setEnabled(!this->connection->connected);
ui->passwordTextField->setEnabled(!this->connection->connected);
QString addressString = QString(wi_string_cstring(wi_url_host(connection->url)));
int port = wi_url_port(connection->url);
if(port > 0 && port != 4871)
addressString += ":" + QString::number(port);
ui->addressTextField->setText(addressString);
QString login = QString(wi_string_cstring(wi_url_user(connection->url)));
ui->loginTextField->setText(login);
QString password = DR::loadPasswordForULRIdentifier(this->connection->URLIdentifier());
ui->passwordTextField->setText(password);
ui->autoConnectCheckBox->setChecked(this->connection->autoConnect);
ui->autoReconnectCheckBox->setChecked(this->connection->autoReconnect);
}
}
void DREditConnectionWindow::on_buttonBox_accepted()
{
if(this->isFormValid()) {
wi_url_t *url;
wi_string_t *url_string;
QString address, login, password;
address = ui->addressTextField->text();
if(address == NULL || address.length() <= 0) {
QApplication::beep();
return;
}
if(!address.contains(":"))
address = QString("%1:%2").arg(address).arg(4871);
login = ui->loginTextField->text();
if(login == NULL || login.length() <= 0)
login = "guest";
password = ui->passwordTextField->text();
if(password == NULL) {
url_string = wi_string_with_format(
WI_STR("wiredp7://%s@%s"),
login.toStdString().c_str(),
address.toStdString().c_str());
} else {
url_string = wi_string_with_format(
WI_STR("wiredp7://%s:%s@%s"),
login.toStdString().c_str(),
password.toStdString().c_str(),
address.toStdString().c_str());
}
url = wi_url_with_string(url_string);
this->connection->setURL(url);
this->connection->autoConnect = ui->autoConnectCheckBox->isChecked();
this->connection->autoReconnect = ui->autoReconnectCheckBox->isChecked();
if(password != NULL) {
DR::savePasswordForULRIdentifier(password, this->connection->URLIdentifier());
}
DRMainWindow::instance()->saveConnections();
this->close();
} else {
QApplication::beep();
}
}
bool DREditConnectionWindow::isFormValid() {
if(!ui->addressTextField->text().isEmpty() && !ui->loginTextField->text().isEmpty())
return true;
return false;
}
void DREditConnectionWindow::on_buttonBox_rejected()
{
this->close();
}