Skip to content

Commit 5881ed4

Browse files
committed
Add "Encrypted session" checkbox for sslmode.
sslmode was already changeable through the parameters as a free text but it requires that the user knows the exact syntax. Now require/disable/whatever is available through a tri-state checkbox.
1 parent 7804642 commit 5881ed4

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/login.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2004-2016 Daniel Verite
1+
/* Copyright (C) 2004-2017 Daniel Verite
22
33
This file is part of Manitou-Mail (see http://www.manitou-mail.org)
44
@@ -24,6 +24,7 @@
2424
#include <QLineEdit>
2525
#include <QComboBox>
2626
#include <QPushButton>
27+
#include <QCheckBox>
2728
#include <QLabel>
2829
#include <QMessageBox>
2930
#include <QVBoxLayout>
@@ -69,6 +70,10 @@ login_dialog::login_dialog() : QDialog(0)
6970
grid->addWidget(m_params, row, 1);
7071
row++;
7172

73+
m_tls = new QCheckBox(tr("Encrypted session"));
74+
m_tls->setTristate();
75+
grid->addWidget(m_tls, row, 1);
76+
7277
QHBoxLayout* hbox = new QHBoxLayout();
7378
top_layout->addLayout(hbox);
7479

@@ -103,6 +108,11 @@ login_dialog::init_settings()
103108
set_dbname(settings.value("dbname").toString());
104109
set_host(settings.value("host").toString());
105110
set_params(settings.value("params").toString());
111+
bool ok=false;
112+
// serialized tri-state value corresponding to Qt::CheckState
113+
int tls_state = settings.value("tls").toInt(&ok);
114+
if (ok && tls_state>=0 && tls_state<=2)
115+
set_tls((Qt::CheckState)tls_state);
106116
}
107117

108118
void
@@ -137,6 +147,12 @@ login_dialog::connect_string()
137147
if (!m_params->text().isEmpty()) {
138148
res.append(" " + m_params->text());
139149
}
150+
if (m_tls->checkState()==Qt::Checked)
151+
res.append(" sslmode=require");
152+
else if (m_tls->checkState()==Qt::Unchecked)
153+
res.append(" sslmode=disable");
154+
/* if Qt::PartiallyChecked, do not specify sslmode. The user can
155+
direct it through m_params */
140156
return res.trimmed();
141157
}
142158

@@ -186,6 +202,12 @@ login_dialog::set_host(const QString host)
186202
m_host->setText(host);
187203
}
188204

205+
void
206+
login_dialog::set_tls(Qt::CheckState state)
207+
{
208+
m_tls->setCheckState(state);
209+
}
210+
189211
// focus on the password if login is set
190212
void
191213
login_dialog::set_focus()
@@ -244,6 +266,7 @@ login_dialog::db_connect()
244266
settings.setValue("dbname", dbnames()); // stringlist
245267
settings.setValue("host", host());
246268
settings.setValue("params", params());
269+
settings.setValue("tls", m_tls->checkState());
247270
accept();
248271
}
249272
}

src/login.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2004-2016 Daniel Verite
1+
/* Copyright (C) 2004-2017 Daniel Verite
22
33
This file is part of Manitou-Mail (see http://www.manitou-mail.org)
44
@@ -25,6 +25,7 @@
2525

2626
class QLineEdit;
2727
class QComboBox;
28+
class QCheckBox;
2829

2930
class login_dialog: public QDialog
3031
{
@@ -37,6 +38,7 @@ class login_dialog: public QDialog
3738
void set_dbname(const QString dbname); // list of values separated by ';'
3839
void set_params(const QString params);
3940
void set_host(const QString host);
41+
void set_tls(Qt::CheckState);
4042
void set_focus(); // focus on the password if login is set
4143
QString login() const;
4244
QString dbnames() const;
@@ -52,6 +54,7 @@ class login_dialog: public QDialog
5254
QLineEdit* m_password;
5355
QLineEdit* m_host;
5456
QLineEdit* m_params;
57+
QCheckBox* m_tls;
5558
private slots:
5659
void db_connect();
5760
void ok();

0 commit comments

Comments
 (0)