|
1 | | -/* Copyright (C) 2004-2016 Daniel Verite |
| 1 | +/* Copyright (C) 2004-2017 Daniel Verite |
2 | 2 |
|
3 | 3 | This file is part of Manitou-Mail (see http://www.manitou-mail.org) |
4 | 4 |
|
|
24 | 24 | #include <QLineEdit> |
25 | 25 | #include <QComboBox> |
26 | 26 | #include <QPushButton> |
| 27 | +#include <QCheckBox> |
27 | 28 | #include <QLabel> |
28 | 29 | #include <QMessageBox> |
29 | 30 | #include <QVBoxLayout> |
@@ -69,6 +70,10 @@ login_dialog::login_dialog() : QDialog(0) |
69 | 70 | grid->addWidget(m_params, row, 1); |
70 | 71 | row++; |
71 | 72 |
|
| 73 | + m_tls = new QCheckBox(tr("Encrypted session")); |
| 74 | + m_tls->setTristate(); |
| 75 | + grid->addWidget(m_tls, row, 1); |
| 76 | + |
72 | 77 | QHBoxLayout* hbox = new QHBoxLayout(); |
73 | 78 | top_layout->addLayout(hbox); |
74 | 79 |
|
@@ -103,6 +108,11 @@ login_dialog::init_settings() |
103 | 108 | set_dbname(settings.value("dbname").toString()); |
104 | 109 | set_host(settings.value("host").toString()); |
105 | 110 | 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); |
106 | 116 | } |
107 | 117 |
|
108 | 118 | void |
@@ -137,6 +147,12 @@ login_dialog::connect_string() |
137 | 147 | if (!m_params->text().isEmpty()) { |
138 | 148 | res.append(" " + m_params->text()); |
139 | 149 | } |
| 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 */ |
140 | 156 | return res.trimmed(); |
141 | 157 | } |
142 | 158 |
|
@@ -186,6 +202,12 @@ login_dialog::set_host(const QString host) |
186 | 202 | m_host->setText(host); |
187 | 203 | } |
188 | 204 |
|
| 205 | +void |
| 206 | +login_dialog::set_tls(Qt::CheckState state) |
| 207 | +{ |
| 208 | + m_tls->setCheckState(state); |
| 209 | +} |
| 210 | + |
189 | 211 | // focus on the password if login is set |
190 | 212 | void |
191 | 213 | login_dialog::set_focus() |
@@ -244,6 +266,7 @@ login_dialog::db_connect() |
244 | 266 | settings.setValue("dbname", dbnames()); // stringlist |
245 | 267 | settings.setValue("host", host()); |
246 | 268 | settings.setValue("params", params()); |
| 269 | + settings.setValue("tls", m_tls->checkState()); |
247 | 270 | accept(); |
248 | 271 | } |
249 | 272 | } |
0 commit comments