pgLab/pglab/SslModeModel.cpp

71 lines
1.6 KiB
C++

#include "SslModeModel.h"
#include <QStringList>
namespace {
const QStringList sslModes = {QString(), "disable", "allow", "prefer", "require", "verify-ca", "verify-full"};
}
SslModeModel::SslModeModel(QObject *parent)
: QAbstractListModel(parent)
{}
int SslModeModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : static_cast<int>(sslModes.size());
}
int SslModeModel::columnCount(const QModelIndex &) const
{
return ColCount;
}
QVariant SslModeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= rowCount()
|| index.column() < 0 || index.column() >= ColCount)
return {};
if (index.column() == Name) {
const auto &mode = sslModes.at(index.row());
if (role == Qt::UserRole)
return mode;
if (role == Qt::DisplayRole || role == Qt::EditRole)
return index.row() == 0 ? tr("Default") : mode;
return {};
}
QVariant v;
if (role == Qt::DisplayRole) {
switch (index.column()) {
case Description:
switch(index.row()) {
case 0:
v = tr("use the PostgreSQL default SSL mode");
break;
case 1:
v = tr("try a non encrypted connection only");
break;
case 2:
v = tr("try no encryption first then try encrypted");
break;
case 3:
v = tr("try encrypted first then not encrypted");
break;
case 4:
v = tr("require an encrypted connection");
break;
case 5:
v = tr("verify encryption certificate has a valid signature");
break;
case 6:
v = tr("verify encryption certificate has a valid signature and matches the host");
break;
}
break;
}
}
return v;
}