Skip to content

Commit

Permalink
Add "Encrypted session" checkbox for sslmode.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
manitou-mail committed Jul 8, 2017
1 parent 7804642 commit 5881ed4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/login.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2004-2016 Daniel Verite
/* Copyright (C) 2004-2017 Daniel Verite
This file is part of Manitou-Mail (see http://www.manitou-mail.org)
Expand All @@ -24,6 +24,7 @@
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QCheckBox>
#include <QLabel>
#include <QMessageBox>
#include <QVBoxLayout>
Expand Down Expand Up @@ -69,6 +70,10 @@ login_dialog::login_dialog() : QDialog(0)
grid->addWidget(m_params, row, 1);
row++;

m_tls = new QCheckBox(tr("Encrypted session"));
m_tls->setTristate();
grid->addWidget(m_tls, row, 1);

QHBoxLayout* hbox = new QHBoxLayout();
top_layout->addLayout(hbox);

Expand Down Expand Up @@ -103,6 +108,11 @@ login_dialog::init_settings()
set_dbname(settings.value("dbname").toString());
set_host(settings.value("host").toString());
set_params(settings.value("params").toString());
bool ok=false;
// serialized tri-state value corresponding to Qt::CheckState
int tls_state = settings.value("tls").toInt(&ok);
if (ok && tls_state>=0 && tls_state<=2)
set_tls((Qt::CheckState)tls_state);
}

void
Expand Down Expand Up @@ -137,6 +147,12 @@ login_dialog::connect_string()
if (!m_params->text().isEmpty()) {
res.append(" " + m_params->text());
}
if (m_tls->checkState()==Qt::Checked)
res.append(" sslmode=require");
else if (m_tls->checkState()==Qt::Unchecked)
res.append(" sslmode=disable");
/* if Qt::PartiallyChecked, do not specify sslmode. The user can
direct it through m_params */
return res.trimmed();
}

Expand Down Expand Up @@ -186,6 +202,12 @@ login_dialog::set_host(const QString host)
m_host->setText(host);
}

void
login_dialog::set_tls(Qt::CheckState state)
{
m_tls->setCheckState(state);
}

// focus on the password if login is set
void
login_dialog::set_focus()
Expand Down Expand Up @@ -244,6 +266,7 @@ login_dialog::db_connect()
settings.setValue("dbname", dbnames()); // stringlist
settings.setValue("host", host());
settings.setValue("params", params());
settings.setValue("tls", m_tls->checkState());
accept();
}
}
5 changes: 4 additions & 1 deletion src/login.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2004-2016 Daniel Verite
/* Copyright (C) 2004-2017 Daniel Verite
This file is part of Manitou-Mail (see http://www.manitou-mail.org)
Expand All @@ -25,6 +25,7 @@

class QLineEdit;
class QComboBox;
class QCheckBox;

class login_dialog: public QDialog
{
Expand All @@ -37,6 +38,7 @@ class login_dialog: public QDialog
void set_dbname(const QString dbname); // list of values separated by ';'
void set_params(const QString params);
void set_host(const QString host);
void set_tls(Qt::CheckState);
void set_focus(); // focus on the password if login is set
QString login() const;
QString dbnames() const;
Expand All @@ -52,6 +54,7 @@ class login_dialog: public QDialog
QLineEdit* m_password;
QLineEdit* m_host;
QLineEdit* m_params;
QCheckBox* m_tls;
private slots:
void db_connect();
void ok();
Expand Down

0 comments on commit 5881ed4

Please sign in to comment.