Query window has now buttons with icons made in the designer for better looks. Depending on received responses from the database the tabcontrol with the message, data and explain tab now switches to the appropriate tab.
202 lines
3.7 KiB
C++
202 lines
3.7 KiB
C++
#include "connectionconfig.h"
|
|
#include <QCoreApplication>
|
|
|
|
namespace {
|
|
|
|
struct {
|
|
SslMode mode;
|
|
const char* string;
|
|
} SslModeStringTable[] = {
|
|
{ SslMode::disable, "disable" },
|
|
{ SslMode::allow, "allow" },
|
|
{ SslMode::prefer, "prefer" },
|
|
{ SslMode::require, "require" },
|
|
{ SslMode::verify_ca, "verify-ca" },
|
|
{ SslMode::verify_full, "verify-full" }
|
|
};
|
|
|
|
inline const char *valuePtr(const std::string &v)
|
|
{
|
|
return v.empty() ? nullptr : v.c_str();
|
|
}
|
|
|
|
} // end unnamed namespace
|
|
|
|
std::string SslModeToString(SslMode sm)
|
|
{
|
|
std::string result;
|
|
for (auto e : SslModeStringTable) {
|
|
if (e.mode == sm) {
|
|
result = e.string;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
SslMode StringToSslMode(std::string s)
|
|
{
|
|
SslMode result = SslMode::allow;
|
|
for (auto e : SslModeStringTable) {
|
|
if (e.string == s) {
|
|
result = e.mode;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
std::vector<const char*> ConnectionConfig::s_keywords = {
|
|
"host", "hostaddr", "port", "user", "password", "dbname",
|
|
"sslmode", "sslcert", "sslkey", "sslrootcrt", "sslcrl",
|
|
"client_encoding", "application_name", nullptr };
|
|
|
|
|
|
ConnectionConfig::ConnectionConfig()
|
|
: m_applicationName(QCoreApplication::applicationName().toUtf8().data())
|
|
{}
|
|
|
|
void ConnectionConfig::setName(std::string desc)
|
|
{
|
|
m_name = std::move(desc);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::name() const
|
|
{
|
|
return m_name;
|
|
}
|
|
|
|
void ConnectionConfig::setHost(std::string host)
|
|
{
|
|
m_host = std::move(host);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::host() const
|
|
{
|
|
return m_host;
|
|
}
|
|
|
|
void ConnectionConfig::setHostAddr(std::string v)
|
|
{
|
|
m_hostaddr = std::move(v);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::hostAddr() const
|
|
{
|
|
return m_hostaddr;
|
|
}
|
|
|
|
void ConnectionConfig::setPort(unsigned short port)
|
|
{
|
|
m_port = std::to_string(port);
|
|
}
|
|
|
|
unsigned short ConnectionConfig::port() const
|
|
{
|
|
return static_cast<unsigned short>(std::stoi(m_port));
|
|
}
|
|
|
|
void ConnectionConfig::setUser(std::string v)
|
|
{
|
|
m_user = std::move(v);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::user() const
|
|
{
|
|
return m_user;
|
|
}
|
|
|
|
void ConnectionConfig::setPassword(std::string v)
|
|
{
|
|
m_password = std::move(v);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::password() const
|
|
{
|
|
return m_password;
|
|
}
|
|
|
|
void ConnectionConfig::setDbname(std::string v)
|
|
{
|
|
m_dbname = std::move(v);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::dbname() const
|
|
{
|
|
return m_dbname;
|
|
}
|
|
|
|
void ConnectionConfig::setSslMode(SslMode m)
|
|
{
|
|
m_sslMode = SslModeToString(m);
|
|
}
|
|
|
|
SslMode ConnectionConfig::sslMode() const
|
|
{
|
|
return StringToSslMode(m_sslMode);
|
|
}
|
|
|
|
void ConnectionConfig::setSslCert(std::string v)
|
|
{
|
|
m_sslCert = std::move(v);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::sslCert() const
|
|
{
|
|
return m_sslCert;
|
|
}
|
|
|
|
void ConnectionConfig::setSslKey(std::string v)
|
|
{
|
|
m_sslKey = std::move(v);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::sslKey() const
|
|
{
|
|
return m_sslKey;
|
|
}
|
|
|
|
void ConnectionConfig::setSslRootCert(std::string v)
|
|
{
|
|
m_sslRootCert = std::move(v);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::sslRootCert() const
|
|
{
|
|
return m_sslRootCert;
|
|
}
|
|
|
|
void ConnectionConfig::setSslCrl(std::string v)
|
|
{
|
|
m_sslCrl = std::move(v);
|
|
}
|
|
|
|
const std::string& ConnectionConfig::sslCrl() const
|
|
{
|
|
return m_sslCrl;
|
|
}
|
|
|
|
|
|
const char * const * ConnectionConfig::getKeywords() const
|
|
{
|
|
return s_keywords.data();
|
|
}
|
|
|
|
const char * const * ConnectionConfig::getValues() const
|
|
{
|
|
m_values.resize(s_keywords.size(), nullptr);
|
|
m_values[0] = valuePtr(m_host);
|
|
m_values[1] = valuePtr(m_hostaddr);
|
|
m_values[2] = valuePtr(m_port);
|
|
m_values[3] = valuePtr(m_user);
|
|
m_values[4] = valuePtr(m_password);
|
|
m_values[5] = valuePtr(m_dbname);
|
|
m_values[6] = valuePtr(m_sslMode);
|
|
m_values[7] = valuePtr(m_sslCert);
|
|
m_values[8] = valuePtr(m_sslKey);
|
|
m_values[9] = valuePtr(m_sslRootCert);
|
|
m_values[10] = valuePtr(m_sslCrl);
|
|
m_values[11] = "utf8";
|
|
m_values[12] = valuePtr(m_applicationName);
|
|
|
|
return m_values.data();
|
|
}
|