From 3a68a7bed61f6564924bee2a3837e7879e0d5213 Mon Sep 17 00:00:00 2001 From: Marcos Bento Date: Fri, 18 Oct 2024 16:03:58 +0100 Subject: [PATCH] Use notion of selected Protocol - use Protocol value instead of flags isSsl, isHttp, isHttps in the ecFlowUI implementation Re ECFLOW-1957 --- Viewer/ecflowUI/src/OverviewProvider.cpp | 11 +- Viewer/ecflowUI/src/ServerAddDialog.ui | 70 ++++-------- Viewer/ecflowUI/src/ServerEditDialog.ui | 42 +++----- Viewer/ecflowUI/src/ServerHandler.cpp | 58 +++------- Viewer/ecflowUI/src/ServerHandler.hpp | 38 +++---- Viewer/ecflowUI/src/ServerItem.cpp | 58 +++------- Viewer/ecflowUI/src/ServerItem.hpp | 26 ++--- Viewer/ecflowUI/src/ServerList.cpp | 67 ++++++------ Viewer/ecflowUI/src/ServerList.hpp | 10 +- Viewer/ecflowUI/src/ServerListDialog.cpp | 130 ++++++++++++----------- Viewer/ecflowUI/src/ServerListDialog.hpp | 22 ++-- Viewer/ecflowUI/src/SessionHandler.cpp | 2 +- 12 files changed, 208 insertions(+), 326 deletions(-) diff --git a/Viewer/ecflowUI/src/OverviewProvider.cpp b/Viewer/ecflowUI/src/OverviewProvider.cpp index f4dde69c2..19a7a04a9 100644 --- a/Viewer/ecflowUI/src/OverviewProvider.cpp +++ b/Viewer/ecflowUI/src/OverviewProvider.cpp @@ -105,9 +105,18 @@ void OverviewProvider::serverInfo(VInfoServer* info, std::stringstream& f) { f << inc << "Host : " << server->host() << "\n"; f << inc << "Port : " << server->port() << "\n"; - if (server->isSsl()) { + if (server->isSsl()) { // Protocol::Ssl f << inc << "SSL : enabled\n"; } + else if (server->isHttp()) { // Protocol::Http + f << inc << "HTTP : enabled\n"; + } + else if (server->isHttps()) { // Protocol::Https + f << inc << "HTTPS : enabled\n"; + } + else { // Protocol::Plain + f << inc << "PLAIN : enabled\n"; + } if (!server->user().empty()) { f << inc << "Custom user : " << server->user() << "\n"; diff --git a/Viewer/ecflowUI/src/ServerAddDialog.ui b/Viewer/ecflowUI/src/ServerAddDialog.ui index 1a83d7097..0fa50714a 100644 --- a/Viewer/ecflowUI/src/ServerAddDialog.ui +++ b/Viewer/ecflowUI/src/ServerAddDialog.ui @@ -7,7 +7,7 @@ 0 0 294 - 315 + 358 @@ -20,7 +20,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -85,57 +85,41 @@ - + - Use &SSL: - - - sslCb + Protocol: - - - - - - - - + - Use &HTTP: - - - httpCb + TCP/IP - + - + TCP/IP with SSL - - + + - Use &HTTPS: - - - httpsCb + HTTP - - + + - + HTTPS - + @@ -145,22 +129,6 @@ - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 10 - - - - @@ -176,10 +144,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -192,10 +160,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok diff --git a/Viewer/ecflowUI/src/ServerEditDialog.ui b/Viewer/ecflowUI/src/ServerEditDialog.ui index d409d86e2..7a469e909 100644 --- a/Viewer/ecflowUI/src/ServerEditDialog.ui +++ b/Viewer/ecflowUI/src/ServerEditDialog.ui @@ -89,57 +89,41 @@ - + - Use &SSL: - - - sslCh + Protocol: - + - - - - - - - - Use &HTTP: - - - httpCh + TCP/IP - + - + TCP/IP with SSL - - + + - Use &HTTPS: - - - httpsCh + HTTP - - + + - + HTTPS - + diff --git a/Viewer/ecflowUI/src/ServerHandler.cpp b/Viewer/ecflowUI/src/ServerHandler.cpp index c6c2e740b..5eb52d0b7 100644 --- a/Viewer/ecflowUI/src/ServerHandler.cpp +++ b/Viewer/ecflowUI/src/ServerHandler.cpp @@ -56,16 +56,12 @@ ServerHandler::ServerHandler(const std::string& name, const std::string& host, const std::string& port, const std::string& user, - bool ssl, - bool http, - bool https) + Protocol protocol) : name_(name), host_(host), port_(port), user_(user), - ssl_(ssl), - http_(http), - https_(https), + protocol_(protocol), client_(nullptr), updating_(false), communicating_(false), @@ -188,12 +184,12 @@ void ServerHandler::createClient(bool init) { bool ssl_enabled = false; std::string ssl_error; -// bool http_enabled = false; + // bool http_enabled = false; std::string http_error; if (client_) { #ifdef ECF_OPENSSL - if (ssl_) { + if (isSsl()) { try { client_->enable_ssl(); ssl_enabled = true; @@ -209,20 +205,18 @@ void ServerHandler::createClient(bool init) { client_->disable_ssl(); } #endif - if (http_) { + if (isHttp()) { try { client_->enable_http(); -// http_enabled = true; } catch (std::exception& e) { http_error = std::string(e.what()); } } - if (https_) { + if (isHttps()) { try { client_->enable_https(); -// http_enabled = true; } catch (std::exception& e) { http_error = std::string(e.what()); @@ -274,7 +268,7 @@ void ServerHandler::createClient(bool init) { } #ifdef ECF_OPENSSL - if (ssl_ && !ssl_enabled) { + if (isSsl() && !ssl_enabled) { sslCertificateError(ssl_error); return; } @@ -329,31 +323,9 @@ void ServerHandler::recreateClient() { createClient(false); } -void ServerHandler::setSsl(bool ssl) { - if (ssl != ssl_) { - ssl_ = ssl; - - if (connectState_->state() != ConnectState::VersionIncompatible && - connectState_->state() != ConnectState::FailedClient) { - recreateClient(); - } - } -} - -void ServerHandler::setHttp(bool http) { - if (http != http_) { - http_ = http; - - if (connectState_->state() != ConnectState::VersionIncompatible && - connectState_->state() != ConnectState::FailedClient) { - recreateClient(); - } - } -} - -void ServerHandler::setHttps(bool https) { - if (https != https_) { - https_ = https; +void ServerHandler::setProtocol(Protocol protocol) { + if (protocol != protocol_) { + protocol_ = protocol; if (connectState_->state() != ConnectState::VersionIncompatible && connectState_->state() != ConnectState::FailedClient) { @@ -575,10 +547,8 @@ ServerHandler* ServerHandler::addServer(const std::string& name, const std::string& host, const std::string& port, const std::string& user, - bool ssl, - bool http, - bool https) { - auto* sh = new ServerHandler(name, host, port, user, ssl, http, https); + Protocol protocol) { + auto* sh = new ServerHandler(name, host, port, user, protocol); return sh; } @@ -1443,7 +1413,7 @@ void ServerHandler::sslIncompatibleServer(const std::string& msg) { connectState_->state(ConnectState::SslIncompatible); std::string errStr = "Cannot communicate to server."; #if ECF_OPENSSL - if (ssl_) { + if (isSsl()) { errStr += " Server is marked as SSL in the UI. Please check if the server is really SSL-enabled! Also check " "settings in Manage servers dialogue!"; } @@ -1461,7 +1431,7 @@ void ServerHandler::sslIncompatibleServer(const std::string& msg) { void ServerHandler::sslCertificateError(const std::string& msg) { #if ECF_OPENSSL - assert(ssl_); + assert(isSsl()); compatibility_ = Incompatible; stopRefreshTimer(); comQueue_->disable(); diff --git a/Viewer/ecflowUI/src/ServerHandler.hpp b/Viewer/ecflowUI/src/ServerHandler.hpp index b2129daf4..a6e6ab6fe 100644 --- a/Viewer/ecflowUI/src/ServerHandler.hpp +++ b/Viewer/ecflowUI/src/ServerHandler.hpp @@ -30,7 +30,6 @@ class ServerReply; class ConnectState; class NodeObserver; -class ServerHandler; class ServerComQueue; class ServerObserver; class ServerComObserver; @@ -42,6 +41,8 @@ class VServerChange; class VSettings; class VSuiteNode; +enum class Protocol { Plain = 0, Ssl = 1, Http = 2, Https = 3 }; + class ServerHandler : public QObject { Q_OBJECT // inherits from QObject in order to gain signal/slots @@ -58,12 +59,11 @@ class ServerHandler : public QObject { const std::string& longName() const { return longName_; } const std::string& fullLongName() const { return fullLongName_; } const std::string& port() const { return port_; } - bool isSsl() const { return ssl_; } - bool isHttp() const { return http_; } + bool isSsl() const { return protocol_ == Protocol::Ssl; } + bool isHttp() const { return protocol_ == Protocol::Http; } + bool isHttps() const { return protocol_ == Protocol::Https; } const std::string& user() { return user_; } - void setSsl(bool); - void setHttp(bool); - void setHttps(bool); + void setProtocol(Protocol protocol); void setUser(const std::string& user); Activity activity() const { return activity_; } @@ -121,9 +121,7 @@ class ServerHandler : public QObject { const std::string& host, const std::string& port, const std::string& user, - bool ssl, - bool http, - bool https); + Protocol protocol); static void removeServer(ServerHandler*); static ServerHandler* findServer(const std::string& alias); @@ -147,9 +145,7 @@ class ServerHandler : public QObject { const std::string& host, const std::string& port, const std::string& user, - bool ssl, - bool http, - bool https); + Protocol protocol); ~ServerHandler() override; void logoutAndDelete(); void queueLoggedOut(); @@ -173,9 +169,7 @@ class ServerHandler : public QObject { std::string host_; std::string port_; std::string user_; - bool ssl_; - bool http_; - bool https_; + Protocol protocol_; ClientInvoker* client_; std::string longName_; std::string fullLongName_; @@ -235,21 +229,21 @@ private Q_SLOTS: void setActivity(Activity activity); - typedef void (ServerObserver::*SoMethod)(ServerHandler*); - typedef void (ServerObserver::*SoMethodV1)(ServerHandler*, const VServerChange&); - typedef void (ServerObserver::*SoMethodV2)(ServerHandler*, const std::string&); + typedef void (ServerObserver::* SoMethod)(ServerHandler*); + typedef void (ServerObserver::* SoMethodV1)(ServerHandler*, const VServerChange&); + typedef void (ServerObserver::* SoMethodV2)(ServerHandler*, const std::string&); void broadcast(SoMethod); void broadcast(SoMethodV1, const VServerChange&); void broadcast(SoMethodV2, const std::string&); - typedef void (NodeObserver::*NoMethod)(const VNode*); - typedef void (NodeObserver::*NoMethodV1)(const VNode*, const std::vector&, const VNodeChange&); - typedef void (NodeObserver::*NoMethodV2)(const VNode*, const VNodeChange&); + typedef void (NodeObserver::* NoMethod)(const VNode*); + typedef void (NodeObserver::* NoMethodV1)(const VNode*, const std::vector&, const VNodeChange&); + typedef void (NodeObserver::* NoMethodV2)(const VNode*, const VNodeChange&); void broadcast(NoMethod, const VNode*); void broadcast(NoMethodV1, const VNode*, const std::vector&, const VNodeChange&); void broadcast(NoMethodV2, const VNode*, const VNodeChange&); - typedef void (ServerComObserver::*SocMethod)(ServerHandler*); + typedef void (ServerComObserver::* SocMethod)(ServerHandler*); void broadcast(SocMethod); void saveConf(); diff --git a/Viewer/ecflowUI/src/ServerItem.cpp b/Viewer/ecflowUI/src/ServerItem.cpp index fc642a1c4..b7863752b 100644 --- a/Viewer/ecflowUI/src/ServerItem.cpp +++ b/Viewer/ecflowUI/src/ServerItem.cpp @@ -26,17 +26,13 @@ ServerItem::ServerItem(const std::string& name, const std::string& port, const std::string& user, bool favourite, - bool ssl, - bool http, - bool https) + Protocol protocol) : name_(name), host_(host), port_(port), user_(user), favourite_(favourite), - ssl_(ssl), - http_(http), - https_(https) { + protocol_(protocol) { } ServerItem::~ServerItem() { @@ -54,9 +50,7 @@ void ServerItem::reset(const std::string& name, const std::string& host, const std::string& port, const std::string& user, - bool ssl, - bool http, - bool https) { + Protocol protocol) { if (name_ != name) { name_ = name; if (handler_) { @@ -64,18 +58,14 @@ void ServerItem::reset(const std::string& name, } } - if (host == host_ && port == port_ && ssl) { - // TODO: these should be called together - setSsl(ssl); - setUser(user); - } - - else if (host == host_ && port == port_ && http) { - setHttp(http); - } + if (host == host_ && port == port_) { - else if (host == host_ && port == port_ && https) { - setHttps(https); + setProtocol(protocol); + if (protocol == Protocol::Ssl) { + // TODO: these should be called together + setProtocol(protocol); + setUser(user); + } } // host or port changed: full reload needed and this situation cannot @@ -99,29 +89,11 @@ void ServerItem::setSystem(bool b) { // broadcastChanged(); } -void ServerItem::setSsl(bool b) { - if (ssl_ != b) { - ssl_ = b; - if (handler_) - handler_->setSsl(ssl_); - } - // broadcastChanged(); -} - -void ServerItem::setHttp(bool b) { - if (http_ != b) { - http_ = b; - if (handler_) - handler_->setHttp(http_); - } - // broadcastChanged(); -} - -void ServerItem::setHttps(bool b) { - if (https_ != b) { - https_ = b; +void ServerItem::setProtocol(Protocol protocol) { + if (protocol_ != protocol) { + protocol_ = protocol; if (handler_) - handler_->setHttps(https_); + handler_->setProtocol(protocol_); } // broadcastChanged(); } @@ -146,7 +118,7 @@ std::string ServerItem::longName() const { void ServerItem::registerUsageBegin() { if (!handler_) { - handler_ = ServerHandler::addServer(name_, host_, port_, user_, ssl_, http_, https_); + handler_ = ServerHandler::addServer(name_, host_, port_, user_, protocol_); } if (handler_) useCnt_++; diff --git a/Viewer/ecflowUI/src/ServerItem.hpp b/Viewer/ecflowUI/src/ServerItem.hpp index 8f650fadb..3fad0f73e 100644 --- a/Viewer/ecflowUI/src/ServerItem.hpp +++ b/Viewer/ecflowUI/src/ServerItem.hpp @@ -17,7 +17,8 @@ #include #include -class ServerHandler; +#include "ServerHandler.hpp" + class ServerItem; class ServerItemObserver { @@ -40,9 +41,10 @@ class ServerItem { std::string longName() const; bool isFavourite() const { return favourite_; } bool isSystem() const { return system_; } - bool isSsl() const { return ssl_; } - bool isHttp() const { return http_; } - bool isHttps() const { return https_; } + Protocol protocol() const { return protocol_; } + bool isSsl() const { return protocol_ == Protocol::Ssl; } + bool isHttp() const { return protocol_ == Protocol::Http; } + bool isHttps() const { return protocol_ == Protocol::Https; } bool isUsed() const; int useCnt() const { return useCnt_; } @@ -58,9 +60,7 @@ class ServerItem { const std::string& port, const std::string& user, bool favourite, - bool ssl, - bool http, - bool https); + Protocol protocol); ~ServerItem(); void name(const std::string& name) { name_ = name; } @@ -70,14 +70,10 @@ class ServerItem { const std::string& host, const std::string& port, const std::string& user, - bool ssl, - bool http, - bool https); + Protocol protocol); void setFavourite(bool b); void setSystem(bool b); - void setSsl(bool b); - void setHttp(bool b); - void setHttps(bool b); + void setProtocol(Protocol protocol); void setUser(const std::string&); void registerUsageBegin(); @@ -92,9 +88,7 @@ class ServerItem { std::string user_; bool favourite_{false}; bool system_{false}; - bool ssl_{false}; - bool http_{false}; - bool https_{false}; + Protocol protocol_{Protocol::Plain}; int useCnt_{0}; ServerHandler* handler_{nullptr}; diff --git a/Viewer/ecflowUI/src/ServerList.cpp b/Viewer/ecflowUI/src/ServerList.cpp index 86a393bdb..495510b9c 100644 --- a/Viewer/ecflowUI/src/ServerList.cpp +++ b/Viewer/ecflowUI/src/ServerList.cpp @@ -366,9 +366,7 @@ ServerItem* ServerList::add(const std::string& name, const std::string& port, const std::string& user, bool favourite, - bool ssl, - bool http, - bool https, + Protocol protocol, bool saveIt) { std::string errStr; if (!checkItemToAdd(name, host, port, true, errStr)) { @@ -376,7 +374,7 @@ ServerItem* ServerList::add(const std::string& name, return nullptr; } - auto* item = new ServerItem(name, host, port, user, favourite, ssl, http, https); + auto* item = new ServerItem(name, host, port, user, favourite, protocol); items_.push_back(item); @@ -405,9 +403,7 @@ ServerItem* ServerList::reset(ServerItem* item, const std::string& host, const std::string& port, const std::string& user, - bool ssl, - bool http, - bool https) { + Protocol protocol) { auto it = std::find(items_.begin(), items_.end(), item); if (it != items_.end()) { // Check if there is an item with the same name. Names have to be unique! @@ -418,14 +414,14 @@ ServerItem* ServerList::reset(ServerItem* item, items_.erase(it); broadcastChanged(); delete item; - item = add(name, host, port, user, false, ssl, http, https, true); + item = add(name, host, port, user, false, protocol, true); save(); broadcastChanged(); } else { assert(host == item->host()); assert(port == item->port()); - item->reset(name, host, port, user, ssl, http, https); + item->reset(name, host, port, user, protocol); save(); broadcastChanged(); } @@ -552,29 +548,28 @@ bool ServerList::load() { if (sv.size() >= 5) sys = (sv[4] == "1") ? true : false; - bool ssl = false; - if (sv.size() >= 6) - ssl = (sv[5] == "1") ? true : false; + Protocol protocol = Protocol::Plain; + if (sv.size() >= 6) { + if (sv[5] == "1") { + protocol = Protocol::Ssl; + } + else if (sv[5] == "2") { + protocol = Protocol::Http; + } + else if (sv[5] == "3") { + protocol = Protocol::Https; + } + } std::string user; if (sv.size() >= 7) user = sv[6]; - bool http = false; - if (sv.size() >= 8) { - http = (sv[7] == "1") ? true : false; - } - - bool https = false; - if (sv.size() >= 9) { - https = (sv[8] == "1") ? true : false; - } - if (sv.size() >= 3) { std::string name = sv[0], host = sv[1], port = sv[2]; ServerItem* item = nullptr; try { - item = add(name, host, port, user, favourite, ssl, http, https, false); + item = add(name, host, port, user, favourite, protocol, false); UI_ASSERT(item != nullptr, "name=" << name << " host=" << host << " port=" << port << " user=" << user); item->setSystem(sys); } @@ -613,16 +608,22 @@ void ServerList::save() { if (!out.good()) return; - out << "#Name Host Port Favourite System Ssl user Http Https" << std::endl; + out << "# Name, Host, Port, Favourite, System, Protocol, User" << std::endl; + out << "# " << std::endl; + out << "# Protocol:" << std::endl; + out << "# 0 == TCP/IP == 0" << std::endl; + out << "# 1 == TCP/IP with SSL == 1" << std::endl; + out << "# 2 == HTTP" << std::endl; + out << "# 3 == HTTPS" << std::endl; + out << "# " << std::endl; for (auto& item : items_) { - std::string fav = (item->isFavourite()) ? "1" : "0"; - std::string ssl = (item->isSsl()) ? "1" : "0"; - std::string http = (item->isHttp()) ? "1" : "0"; - std::string https = (item->isHttps()) ? "1" : "0"; - std::string sys = (item->isSystem()) ? "1" : "0"; - out << item->name() << "," << item->host() << "," << item->port() << "," << fav << "," << sys << "," << ssl - << "," << item->user() << "," << http << "," << https << std::endl; + std::string fav = (item->isFavourite()) ? "1" : "0"; + + auto protocol = static_cast>(item->protocol()); + std::string sys = (item->isSystem()) ? "1" : "0"; + out << item->name() << "," << item->host() << "," << item->port() << "," << fav << "," << sys << "," << protocol + << "," << item->user() << std::endl; } out.close(); } @@ -678,7 +679,7 @@ void ServerList::loadSystemItems(const std::vector& sysVec, changed = true; std::string name = sysItem.name(), host = sysItem.host(), port = sysItem.port(); try { - item = add(name, host, port, "", false, false, false, false, false); + item = add(name, host, port, "", false, Protocol::Plain, false); UI_ASSERT(item != nullptr, "name=" << name << " host=" << host << " port=" << port); item->setSystem(true); changeVec.push_back( @@ -704,7 +705,7 @@ void ServerList::loadSystemItems(const std::vector& sysVec, ServerListTmpItem localTmp(item); changeVec.push_back(new ServerListSyncChangeItem(sysItem, localTmp, ServerListSyncChangeItem::MatchChange)); - item = reset(item, sysItem.name(), sysItem.host(), sysItem.port(), "", false, false, false); + item = reset(item, sysItem.name(), sysItem.host(), sysItem.port(), "", Protocol::Plain); if (item) { item->setSystem(true); } diff --git a/Viewer/ecflowUI/src/ServerList.hpp b/Viewer/ecflowUI/src/ServerList.hpp index fdfbbf16a..307665ee3 100644 --- a/Viewer/ecflowUI/src/ServerList.hpp +++ b/Viewer/ecflowUI/src/ServerList.hpp @@ -18,9 +18,9 @@ #include "GenFileProvider.hpp" #include "PropertyMapper.hpp" +#include "ServerItem.hpp" #include "VProperty.hpp" -class ServerItem; class ServerList; class GenFileReceiver; @@ -131,9 +131,7 @@ class ServerList { const std::string& port, const std::string& user, bool favorite, - bool ssl, - bool http, - bool https, + Protocol protocol, bool saveIt); void remove(ServerItem*); ServerItem* reset(ServerItem*, @@ -141,9 +139,7 @@ class ServerList { const std::string& host, const std::string& port, const std::string& user, - bool ssl, - bool http, - bool https); + Protocol protocol); void setFavourite(ServerItem*, bool); std::string uniqueName(const std::string&); diff --git a/Viewer/ecflowUI/src/ServerListDialog.cpp b/Viewer/ecflowUI/src/ServerListDialog.cpp index 9b66d778c..055eb27d8 100644 --- a/Viewer/ecflowUI/src/ServerListDialog.cpp +++ b/Viewer/ecflowUI/src/ServerListDialog.cpp @@ -198,16 +198,23 @@ QString ServerAddDialog::user() const { return userEdit->text(); } -bool ServerAddDialog::isSsl() const { - return sslCb->isChecked(); -} - -bool ServerAddDialog::isHttp() const { - return httpCb->isChecked(); -} - -bool ServerAddDialog::isHttps() const { - return httpsCb->isChecked(); +Protocol ServerAddDialog::protocol() const { + if (protocolPlain->isChecked()) { + return Protocol::Plain; + } + else if (protocolSsl->isChecked()) { + return Protocol::Ssl; + } + else if (protocolHttp->isChecked()) { + return Protocol::Http; + } + else if (protocolHttps->isChecked()) { + return Protocol::Https; + } + else { + // Unknown protocol values are assumed to be Plain + return Protocol::Plain; + } } bool ServerAddDialog::addToView() const { @@ -225,9 +232,7 @@ ServerEditDialog::ServerEditDialog(QString name, QString port, QString user, bool favourite, - bool ssl, - bool http, - bool https, + Protocol protocol, QWidget* parent) : QDialog(parent), ServerDialogChecker(tr("Cannot modify server!")), @@ -238,10 +243,11 @@ ServerEditDialog::ServerEditDialog(QString name, hostEdit->setText(host); portEdit->setText(port); userEdit->setText(user); + protocolPlain->setChecked(protocol == Protocol::Plain); + protocolSsl->setChecked(protocol == Protocol::Ssl); + protocolHttp->setChecked(protocol == Protocol::Http); + protocolHttps->setChecked(protocol == Protocol::Https); favCh->setChecked(favourite); - sslCh->setChecked(ssl); - httpCh->setChecked(http); - httpsCh->setChecked(https); #ifndef ECF_OPENSSL sslMessageLabel->hide(); @@ -298,16 +304,23 @@ bool ServerEditDialog::isFavourite() const { return favCh->isChecked(); } -bool ServerEditDialog::isSsl() const { - return sslCh->isChecked(); -} - -bool ServerEditDialog::isHttp() const { - return httpCh->isChecked(); -} - -bool ServerEditDialog::isHttps() const { - return httpsCh->isChecked(); +Protocol ServerEditDialog::protocol() const { + if (protocolPlain->isChecked()) { + return Protocol::Plain; + } + else if (protocolSsl->isChecked()) { + return Protocol::Ssl; + } + else if (protocolHttp->isChecked()) { + return Protocol::Http; + } + else if (protocolHttps->isChecked()) { + return Protocol::Https; + } + else { + // Unknown protocol values are assumed to be Plain + return Protocol::Plain; + } } //====================================== @@ -457,9 +470,7 @@ void ServerListDialog::editItem(const QModelIndex& index) { QString::fromStdString(item->port()), QString::fromStdString(item->user()), item->isFavourite(), - item->isSsl(), - item->isHttp(), - item->isHttps(), + item->protocol(), this); // The dialog checks the name, host and port! @@ -472,9 +483,7 @@ void ServerListDialog::editItem(const QModelIndex& index) { d.host().toStdString(), d.port().toStdString(), d.user().toStdString(), - d.isSsl(), - d.isHttp(), - d.isHttps()); + d.protocol()); if (item) { if (item->isFavourite() != d.isFavourite()) { @@ -500,9 +509,7 @@ void ServerListDialog::duplicateItem(const QModelIndex& index) { QString::fromStdString(item->port()), QString::fromStdString(item->user()), item->isFavourite(), - item->isSsl(), - item->isHttp(), - item->isHttps(), + item->protocol(), this); // The dialog checks the name, host and port! @@ -513,9 +520,7 @@ void ServerListDialog::duplicateItem(const QModelIndex& index) { d.port().toStdString(), d.user().toStdString(), item->isFavourite(), - item->isSsl(), - item->isHttp(), - item->isHttps(), + item->protocol(), false); model_->dataChangeFinished(); } @@ -535,9 +540,7 @@ void ServerListDialog::addItem() { d.port().toStdString(), d.user().toStdString(), false, - d.isSsl(), - d.isHttp(), - d.isHttps(), + d.protocol(), false); } catch (std::exception& e) { @@ -616,7 +619,7 @@ void ServerListDialog::setSslItem(const QModelIndex& index,bool b) void ServerListDialog::on_serverView_doubleClicked(const QModelIndex& index) { int col = index.column(); if (col == ServerListModel::NameColumn || col == ServerListModel::HostColumn || - col == ServerListModel::PortColumn || col == ServerListModel::SslColumn || + col == ServerListModel::PortColumn || col == ServerListModel::ProtocolColumn || col == ServerListModel::FavouriteColumn) { editItem(index); } @@ -834,12 +837,19 @@ QVariant ServerListModel::data(const QModelIndex& index, int role) const { return QString::fromStdString(item->port()); case UserColumn: return QString::fromStdString(item->user()); - case SslColumn: - return (item->isSsl()) ? "ssl" : ""; - case HttpColumn: - return (item->isHttp()) ? "http" : ""; - case HttpsColumn: - return (item->isHttps()) ? "https" : ""; + case ProtocolColumn: + if (item->isSsl()) { + return "TCP/IP over SSL"; + } + else if (item->isHttp()) { + return "HTTP"; + } + else if (item->isHttps()) { + return "HTTPS"; + } + else { + return "TCP/IP"; + } case UseColumn: { int n = item->useCnt(); if (n > 0) @@ -924,12 +934,8 @@ QVariant ServerListModel::headerData(int section, Qt::Orientation ori, int role) return tr("Custom user"); case SystemColumn: return tr("S"); - case SslColumn: - return tr("SSL"); - case HttpColumn: - return tr("HTTP"); - case HttpsColumn: - return tr("HTTPS"); + case ProtocolColumn: + return tr("Protocol"); case FavouriteColumn: return tr("F"); case UseColumn: @@ -952,17 +958,13 @@ QVariant ServerListModel::headerData(int section, Qt::Orientation ori, int role) case UserColumn: return tr("Custom user name"); case SystemColumn: - return tr("Indicates if a server appears in the centrally maintained system server list. \ -
The name, host and port of these server entries cannot be edited."); - case SslColumn: - return tr("Indicates if a server uses SSL communication."); - case HttpColumn: - return tr("Indicates if a server uses HTTP communication."); - case HttpsColumn: - return tr("Indicates if a server uses HTTPS communication."); + return tr("Indicates if a server appears in the centrally maintained system server list." + "
The name, host and port of these server entries cannot be edited."); + case ProtocolColumn: + return tr("Indicates the protocol to use for communication with ecFlow server."); case FavouriteColumn: - return tr("Indicates if a server is a favourite. Only favourite and loaded servers \ - are appearing in the server list under the Servers menu in the menubar"); + return tr("Indicates if a server is a favourite. Only favourite and loaded servers" + "are appearing in the server list under the Servers menu in the menubar"); case UseColumn: return tr("Indicates the number of tabs where the server is loaded."); default: diff --git a/Viewer/ecflowUI/src/ServerListDialog.hpp b/Viewer/ecflowUI/src/ServerListDialog.hpp index 6a40dcf9b..d4437c56d 100644 --- a/Viewer/ecflowUI/src/ServerListDialog.hpp +++ b/Viewer/ecflowUI/src/ServerListDialog.hpp @@ -14,12 +14,12 @@ #include #include +#include "ServerItem.hpp" #include "ui_ServerAddDialog.h" #include "ui_ServerEditDialog.h" #include "ui_ServerListDialog.h" class ServerFilter; -class ServerItem; class ServerListModel; class ServerListFilterModel; @@ -45,18 +45,14 @@ class ServerEditDialog : public QDialog, private Ui::ServerEditDialog, public Se QString port, QString user, bool favourite, - bool ssl, - bool http, - bool https, + Protocol protocol, QWidget* parent = nullptr); QString name() const; QString host() const; QString port() const; QString user() const; - bool isSsl() const; - bool isHttp() const; - bool isHttps() const; + Protocol protocol() const; bool isFavourite() const; public Q_SLOTS: @@ -77,9 +73,7 @@ class ServerAddDialog : public QDialog, private Ui::ServerAddDialog, public Serv QString port() const; QString user() const; bool addToView() const; - bool isSsl() const; - bool isHttp() const; - bool isHttps() const; + Protocol protocol() const; public Q_SLOTS: void accept() override; @@ -162,11 +156,9 @@ class ServerListModel : public QAbstractItemModel { PortColumn = 3, UserColumn = 4, SystemColumn = 5, - SslColumn = 6, - HttpColumn = 7, - HttpsColumn = 8, - FavouriteColumn = 9, - UseColumn = 10 + ProtocolColumn = 6, + FavouriteColumn = 7, + UseColumn = 8 // when updating the columns list, ensure to update the columnCount() method to refer to last enum entry }; enum CustomItemRole { IconStatusRole = Qt::UserRole + 1 }; diff --git a/Viewer/ecflowUI/src/SessionHandler.cpp b/Viewer/ecflowUI/src/SessionHandler.cpp index ca52c4e31..df68d87bb 100644 --- a/Viewer/ecflowUI/src/SessionHandler.cpp +++ b/Viewer/ecflowUI/src/SessionHandler.cpp @@ -282,7 +282,7 @@ void SessionHandler::setTemporarySessionIfReqested() { if (ServerList::instance()->find(alias, host, port) == nullptr) { // no - add it, and make sure it's got a unique alias std::string uniqueName = ServerList::instance()->uniqueName(alias); - ServerList::instance()->add(uniqueName, host, port, "", false, false, false, false, true); + ServerList::instance()->add(uniqueName, host, port, "", false, Protocol::Plain, true); } } }