-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProxyCredentialsHandler.cpp
More file actions
43 lines (40 loc) · 1.47 KB
/
ProxyCredentialsHandler.cpp
File metadata and controls
43 lines (40 loc) · 1.47 KB
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
#include "ProxyCredentialsHandler.h"
#include "Settings.h"
#include <QInputDialog>
#include "Helper.h"
ProxyCredentialsHandler::ProxyCredentialsHandler()
: QObject()
, credentials_()
, enable_credentials_dialog_(false)
{
}
void ProxyCredentialsHandler::proxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* authenticator)
{
QString host = proxy.hostName().toLower().trimmed();
if (credentials_.contains(host))
{
//qDebug() << "ProxyCredentialsHandler::proxyAuthenticationRequired - CACHED";
const QPair<QString, QString>& credentials = credentials_[host];
authenticator->setUser(credentials.first);
authenticator->setPassword(credentials.second);
}
else
{
QString user = Settings::string("proxy_user", true);
QString password = Settings::string("proxy_password", true);
if (!user.isEmpty() && !password.isEmpty())
{
//qDebug() << "ProxyCredentialsHandler::proxyAuthenticationRequired - FROM SETTINGS" << user << password;
authenticator->setUser(user);
authenticator->setPassword(password);
}
else if (enable_credentials_dialog_)
{
//qDebug() << "ProxyCredentialsHandler::proxyAuthenticationRequired - ASKING USER";
QString user = QInputDialog::getText(nullptr, "Proxy user required", "Proxy user", QLineEdit::Normal, Helper::userName());
QString password = QInputDialog::getText(nullptr, "Proxy password required", "Proxy password", QLineEdit::Password);
authenticator->setUser(user);
authenticator->setPassword(password);
}
}
}