-
Notifications
You must be signed in to change notification settings - Fork 2
/
drconnectdialog.cpp
127 lines (83 loc) · 3.06 KB
/
drconnectdialog.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
/*
Deriv is a cross-platform client for th Wired 2.0 protocol
Copyright (C) 2014 Rafael Warnault, [email protected]
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 <QDebug>
#include <QMessageBox>
#include <QtCore>
#include <wired/wired.h>
#include "drconnectdialog.h"
#include "ui_drconnectdialog.h"
#include "drmainwindow.h"
#include "drconnectionscontroller.h"
#include "main.h"
#include "dr.h"
#pragma mark -
DRConnectDialog::DRConnectDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::DRConnectDialog)
{
ui->setupUi(this);
}
DRConnectDialog::~DRConnectDialog()
{
delete ui;
}
#pragma mark -
void DRConnectDialog::accept()
{
wi_url_t *url;
wi_p7_socket_t *socket;
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);
DRMainWindow *mainWindow = (DRMainWindow *)this->parent();
this->connection = DRConnectionsController::instance()->connectionForURL(url);
if(this->connection == NULL) {
this->connection = new DRServerConnection(url);
DRConnectionsController::instance()->addConnection(this->connection);
} else {
if(this->connection->connected) {
mainWindow->selectConnection(this->connection);
}
done(Accepted);
return;
}
DRMainWindow::startProgress(QString("Connecting to %1").arg(this->connection->URLIdentifier()));
DR::savePasswordForULRIdentifier(this->connection->URLPassword(), this->connection->URLIdentifier());
this->connection->connect(mainWindow);
done(Accepted);
}