From ef7e652c707e2d65ef0aeb3770c9df59cb3e569d Mon Sep 17 00:00:00 2001 From: Marcos Bento Date: Thu, 20 Jun 2024 09:55:37 +0100 Subject: [PATCH] Update UI to allow for HTTP connection Re ECFLOW-1957 --- Viewer/ecflowUI/src/ServerAddDialog.ui | 21 +++++++++++-- Viewer/ecflowUI/src/ServerEditDialog.ui | 17 ++++++++++ Viewer/ecflowUI/src/ServerHandler.cpp | 31 +++++++++++++++++-- Viewer/ecflowUI/src/ServerHandler.hpp | 9 ++++-- Viewer/ecflowUI/src/ServerItem.cpp | 17 ++++++++-- Viewer/ecflowUI/src/ServerItem.hpp | 6 +++- Viewer/ecflowUI/src/ServerList.cpp | 24 +++++++++----- Viewer/ecflowUI/src/ServerList.hpp | 4 ++- Viewer/ecflowUI/src/ServerListDialog.cpp | 27 ++++++++++++++-- Viewer/ecflowUI/src/ServerListDialog.hpp | 8 +++-- Viewer/ecflowUI/src/ServerListDialog.ui | 2 +- Viewer/ecflowUI/src/SessionHandler.cpp | 2 +- .../src/ecflow/client/ClientEnvironment.hpp | 1 + .../src/ecflow/client/ClientInvoker.hpp | 3 ++ 14 files changed, 145 insertions(+), 27 deletions(-) diff --git a/Viewer/ecflowUI/src/ServerAddDialog.ui b/Viewer/ecflowUI/src/ServerAddDialog.ui index 6f8c95faf..486c48bbe 100644 --- a/Viewer/ecflowUI/src/ServerAddDialog.ui +++ b/Viewer/ecflowUI/src/ServerAddDialog.ui @@ -7,7 +7,7 @@ 0 0 294 - 225 + 315 @@ -101,7 +101,24 @@ + + + + Use &HTTP: + + + httpCb + + + + + + + + + + @@ -111,7 +128,7 @@ - + Qt::Vertical diff --git a/Viewer/ecflowUI/src/ServerEditDialog.ui b/Viewer/ecflowUI/src/ServerEditDialog.ui index b7faaa770..c5dfdac88 100644 --- a/Viewer/ecflowUI/src/ServerEditDialog.ui +++ b/Viewer/ecflowUI/src/ServerEditDialog.ui @@ -105,7 +105,24 @@ + + + + Use &HTTP: + + + httpCh + + + + + + + + + + diff --git a/Viewer/ecflowUI/src/ServerHandler.cpp b/Viewer/ecflowUI/src/ServerHandler.cpp index 373c65e28..8b4d7619d 100644 --- a/Viewer/ecflowUI/src/ServerHandler.cpp +++ b/Viewer/ecflowUI/src/ServerHandler.cpp @@ -56,12 +56,14 @@ ServerHandler::ServerHandler(const std::string& name, const std::string& host, const std::string& port, const std::string& user, - bool ssl) + bool ssl, + bool http) : name_(name), host_(host), port_(port), user_(user), ssl_(ssl), + http_(http), client_(nullptr), updating_(false), communicating_(false), @@ -184,6 +186,8 @@ void ServerHandler::createClient(bool init) { bool ssl_enabled = false; std::string ssl_error; + bool http_enabled = false; + std::string http_error; if (client_) { #ifdef ECF_OPENSSL @@ -203,6 +207,15 @@ void ServerHandler::createClient(bool init) { client_->disable_ssl(); } #endif + if (http_) { + try { + client_->enable_http(); + http_enabled = true; + } + catch (std::exception& e) { + http_error = std::string(e.what()); + } + } if (!init || !user_.empty()) { try { @@ -315,6 +328,17 @@ void ServerHandler::setSsl(bool ssl) { } } +void ServerHandler::setHttp(bool http) { + if (http != http_) { + http_ = http; + + if (connectState_->state() != ConnectState::VersionIncompatible && + connectState_->state() != ConnectState::FailedClient) { + recreateClient(); + } + } +} + void ServerHandler::setUser(const std::string& user) { if (user != user_) { user_ = user; @@ -528,8 +552,9 @@ ServerHandler* ServerHandler::addServer(const std::string& name, const std::string& host, const std::string& port, const std::string& user, - bool ssl) { - auto* sh = new ServerHandler(name, host, port, user, ssl); + bool ssl, + bool http) { + auto* sh = new ServerHandler(name, host, port, user, ssl, http); return sh; } diff --git a/Viewer/ecflowUI/src/ServerHandler.hpp b/Viewer/ecflowUI/src/ServerHandler.hpp index 4925189b2..7cc521724 100644 --- a/Viewer/ecflowUI/src/ServerHandler.hpp +++ b/Viewer/ecflowUI/src/ServerHandler.hpp @@ -59,8 +59,10 @@ class ServerHandler : public QObject { const std::string& fullLongName() const { return fullLongName_; } const std::string& port() const { return port_; } bool isSsl() const { return ssl_; } + bool isHttp() const { return http_; } const std::string& user() { return user_; } void setSsl(bool); + void setHttp(bool); void setUser(const std::string& user); Activity activity() const { return activity_; } @@ -118,7 +120,8 @@ class ServerHandler : public QObject { const std::string& host, const std::string& port, const std::string& user, - bool ssl); + bool ssl, + bool http); static void removeServer(ServerHandler*); static ServerHandler* findServer(const std::string& alias); @@ -142,7 +145,8 @@ class ServerHandler : public QObject { const std::string& host, const std::string& port, const std::string& user, - bool ssl); + bool ssl, + bool http); ~ServerHandler() override; void logoutAndDelete(); void queueLoggedOut(); @@ -167,6 +171,7 @@ class ServerHandler : public QObject { std::string port_; std::string user_; bool ssl_; + bool http_; ClientInvoker* client_; std::string longName_; std::string fullLongName_; diff --git a/Viewer/ecflowUI/src/ServerItem.cpp b/Viewer/ecflowUI/src/ServerItem.cpp index 917f7a12a..ee4ec19c8 100644 --- a/Viewer/ecflowUI/src/ServerItem.cpp +++ b/Viewer/ecflowUI/src/ServerItem.cpp @@ -26,13 +26,15 @@ ServerItem::ServerItem(const std::string& name, const std::string& port, const std::string& user, bool favourite, - bool ssl) + bool ssl, + bool http) : name_(name), host_(host), port_(port), user_(user), favourite_(favourite), - ssl_(ssl) { + ssl_(ssl), + http_(http) { } ServerItem::~ServerItem() { @@ -94,6 +96,15 @@ void ServerItem::setSsl(bool b) { // broadcastChanged(); } +void ServerItem::setHttp(bool b) { + if (http_ != b) { + http_ = b; + if (handler_) + handler_->setHttp(http_); + } + // broadcastChanged(); +} + void ServerItem::setUser(const std::string& user) { if (user_ != user) { user_ = user; @@ -114,7 +125,7 @@ std::string ServerItem::longName() const { void ServerItem::registerUsageBegin() { if (!handler_) { - handler_ = ServerHandler::addServer(name_, host_, port_, user_, ssl_); + handler_ = ServerHandler::addServer(name_, host_, port_, user_, ssl_, http_); } if (handler_) useCnt_++; diff --git a/Viewer/ecflowUI/src/ServerItem.hpp b/Viewer/ecflowUI/src/ServerItem.hpp index 183ca4741..a41b6ad46 100644 --- a/Viewer/ecflowUI/src/ServerItem.hpp +++ b/Viewer/ecflowUI/src/ServerItem.hpp @@ -41,6 +41,7 @@ class ServerItem { bool isFavourite() const { return favourite_; } bool isSystem() const { return system_; } bool isSsl() const { return ssl_; } + bool isHttp() const { return http_; } bool isUsed() const; int useCnt() const { return useCnt_; } @@ -56,7 +57,8 @@ class ServerItem { const std::string& port, const std::string& user, bool favourite, - bool ssl); + bool ssl, + bool http); ~ServerItem(); void name(const std::string& name) { name_ = name; } @@ -67,6 +69,7 @@ class ServerItem { void setFavourite(bool b); void setSystem(bool b); void setSsl(bool b); + void setHttp(bool b); void setUser(const std::string&); void registerUsageBegin(); @@ -82,6 +85,7 @@ class ServerItem { bool favourite_{false}; bool system_{false}; bool ssl_{false}; + bool http_{false}; int useCnt_{0}; ServerHandler* handler_{nullptr}; diff --git a/Viewer/ecflowUI/src/ServerList.cpp b/Viewer/ecflowUI/src/ServerList.cpp index 017d5b70e..5dfce1808 100644 --- a/Viewer/ecflowUI/src/ServerList.cpp +++ b/Viewer/ecflowUI/src/ServerList.cpp @@ -367,6 +367,7 @@ ServerItem* ServerList::add(const std::string& name, const std::string& user, bool favourite, bool ssl, + bool http, bool saveIt) { std::string errStr; if (!checkItemToAdd(name, host, port, true, errStr)) { @@ -374,7 +375,7 @@ ServerItem* ServerList::add(const std::string& name, return nullptr; } - auto* item = new ServerItem(name, host, port, user, favourite, ssl); + auto* item = new ServerItem(name, host, port, user, favourite, ssl, http); items_.push_back(item); @@ -403,7 +404,8 @@ ServerItem* ServerList::reset(ServerItem* item, const std::string& host, const std::string& port, const std::string& user, - bool ssl) { + bool ssl, + bool http) { 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! @@ -414,7 +416,7 @@ ServerItem* ServerList::reset(ServerItem* item, items_.erase(it); broadcastChanged(); delete item; - item = add(name, host, port, user, false, ssl, true); + item = add(name, host, port, user, false, ssl, http, true); save(); broadcastChanged(); } @@ -556,11 +558,16 @@ bool ServerList::load() { if (sv.size() >= 7) user = sv[6]; + bool http = false; + if (sv.size() >= 8) { + http = (sv[7] == "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, false); + item = add(name, host, port, user, favourite, ssl, http, false); UI_ASSERT(item != nullptr, "name=" << name << " host=" << host << " port=" << port << " user=" << user); item->setSystem(sys); } @@ -599,14 +606,15 @@ void ServerList::save() { if (!out.good()) return; - out << "#Name Host Port Favourite System Ssl user" << std::endl; + out << "#Name Host Port Favourite System Ssl user Http" << 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 sys = (item->isSystem()) ? "1" : "0"; out << item->name() << "," << item->host() << "," << item->port() << "," << fav << "," << sys << "," << ssl - << "," << item->user() << std::endl; + << "," << item->user() << "," << http << std::endl; } out.close(); } @@ -662,7 +670,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); + item = add(name, host, port, "", false, false, false, false); UI_ASSERT(item != nullptr, "name=" << name << " host=" << host << " port=" << port); item->setSystem(true); changeVec.push_back( @@ -688,7 +696,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); + item = reset(item, sysItem.name(), sysItem.host(), sysItem.port(), "", false, false); if (item) { item->setSystem(true); } diff --git a/Viewer/ecflowUI/src/ServerList.hpp b/Viewer/ecflowUI/src/ServerList.hpp index 511ca0a58..4a87c2dd7 100644 --- a/Viewer/ecflowUI/src/ServerList.hpp +++ b/Viewer/ecflowUI/src/ServerList.hpp @@ -132,6 +132,7 @@ class ServerList { const std::string& user, bool favorite, bool ssl, + bool http, bool saveIt); void remove(ServerItem*); ServerItem* reset(ServerItem*, @@ -139,7 +140,8 @@ class ServerList { const std::string& host, const std::string& port, const std::string& user, - bool ssl); + bool ssl, + bool http); 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 707e661c2..fe6cdddd3 100644 --- a/Viewer/ecflowUI/src/ServerListDialog.cpp +++ b/Viewer/ecflowUI/src/ServerListDialog.cpp @@ -202,6 +202,10 @@ bool ServerAddDialog::isSsl() const { return sslCb->isChecked(); } +bool ServerAddDialog::isHttp() const { + return httpCb->isChecked(); +} + bool ServerAddDialog::addToView() const { return addToCurrentCb->isChecked(); } @@ -218,6 +222,7 @@ ServerEditDialog::ServerEditDialog(QString name, QString user, bool favourite, bool ssl, + bool http, QWidget* parent) : QDialog(parent), ServerDialogChecker(tr("Cannot modify server!")), @@ -230,6 +235,7 @@ ServerEditDialog::ServerEditDialog(QString name, userEdit->setText(user); favCh->setChecked(favourite); sslCh->setChecked(ssl); + httpCh->setChecked(http); #ifndef ECF_OPENSSL sslMessageLabel->hide(); @@ -290,6 +296,10 @@ bool ServerEditDialog::isSsl() const { return sslCh->isChecked(); } +bool ServerEditDialog::isHttp() const { + return httpCh->isChecked(); +} + //====================================== // // ServerListDialog @@ -438,6 +448,7 @@ void ServerListDialog::editItem(const QModelIndex& index) { QString::fromStdString(item->user()), item->isFavourite(), item->isSsl(), + item->isHttp(), this); // The dialog checks the name, host and port! @@ -450,7 +461,8 @@ void ServerListDialog::editItem(const QModelIndex& index) { d.host().toStdString(), d.port().toStdString(), d.user().toStdString(), - d.isSsl()); + d.isSsl(), + d.isHttp()); if (item) { if (item->isFavourite() != d.isFavourite()) { @@ -477,6 +489,7 @@ void ServerListDialog::duplicateItem(const QModelIndex& index) { QString::fromStdString(item->user()), item->isFavourite(), item->isSsl(), + item->isHttp(), this); // The dialog checks the name, host and port! @@ -488,6 +501,7 @@ void ServerListDialog::duplicateItem(const QModelIndex& index) { d.user().toStdString(), item->isFavourite(), item->isSsl(), + item->isHttp(), false); model_->dataChangeFinished(); } @@ -508,6 +522,7 @@ void ServerListDialog::addItem() { d.user().toStdString(), false, d.isSsl(), + d.isHttp(), false); } catch (std::exception& e) { @@ -772,7 +787,7 @@ void ServerListModel::dataChangeFinished() { } int ServerListModel::columnCount(const QModelIndex& /*parent*/) const { - return 8; + return 9; } int ServerListModel::rowCount(const QModelIndex& parent) const { @@ -806,6 +821,8 @@ QVariant ServerListModel::data(const QModelIndex& index, int role) const { return QString::fromStdString(item->user()); case SslColumn: return (item->isSsl()) ? "ssl" : ""; + case HttpColumn: + return (item->isHttp()) ? "http" : ""; case UseColumn: { int n = item->useCnt(); if (n > 0) @@ -892,6 +909,8 @@ QVariant ServerListModel::headerData(int section, Qt::Orientation ori, int role) return tr("S"); case SslColumn: return tr("SSL"); + case HttpColumn: + return tr("HTTP"); case FavouriteColumn: return tr("F"); case UseColumn: @@ -918,9 +937,11 @@ QVariant ServerListModel::headerData(int section, Qt::Orientation ori, int role)
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 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"); + 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 4781e5e8e..e54ad66b1 100644 --- a/Viewer/ecflowUI/src/ServerListDialog.hpp +++ b/Viewer/ecflowUI/src/ServerListDialog.hpp @@ -46,6 +46,7 @@ class ServerEditDialog : public QDialog, private Ui::ServerEditDialog, public Se QString user, bool favourite, bool ssl, + bool http, QWidget* parent = nullptr); QString name() const; @@ -53,6 +54,7 @@ class ServerEditDialog : public QDialog, private Ui::ServerEditDialog, public Se QString port() const; QString user() const; bool isSsl() const; + bool isHttp() const; bool isFavourite() const; public Q_SLOTS: @@ -74,6 +76,7 @@ class ServerAddDialog : public QDialog, private Ui::ServerAddDialog, public Serv QString user() const; bool addToView() const; bool isSsl() const; + bool isHttp() const; public Q_SLOTS: void accept() override; @@ -157,8 +160,9 @@ class ServerListModel : public QAbstractItemModel { UserColumn = 4, SystemColumn = 5, SslColumn = 6, - FavouriteColumn = 7, - UseColumn = 8 + HttpColumn = 7, + FavouriteColumn = 8, + UseColumn = 9 }; enum CustomItemRole { IconStatusRole = Qt::UserRole + 1 }; diff --git a/Viewer/ecflowUI/src/ServerListDialog.ui b/Viewer/ecflowUI/src/ServerListDialog.ui index e99e2b2ff..178e9dd68 100644 --- a/Viewer/ecflowUI/src/ServerListDialog.ui +++ b/Viewer/ecflowUI/src/ServerListDialog.ui @@ -6,7 +6,7 @@ 0 0 - 599 + 699 661 diff --git a/Viewer/ecflowUI/src/SessionHandler.cpp b/Viewer/ecflowUI/src/SessionHandler.cpp index cd46cec57..69c243791 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, true); + ServerList::instance()->add(uniqueName, host, port, "", false, false, false, true); } } } diff --git a/libs/client/src/ecflow/client/ClientEnvironment.hpp b/libs/client/src/ecflow/client/ClientEnvironment.hpp index ba47d7760..a4597361e 100644 --- a/libs/client/src/ecflow/client/ClientEnvironment.hpp +++ b/libs/client/src/ecflow/client/ClientEnvironment.hpp @@ -92,6 +92,7 @@ class ClientEnvironment final : public AbstractClientEnv { bool http() const { return http_; } void enable_http() { http_ = true; } + void disable_http() { http_ = false; } #ifdef ECF_OPENSSL /// return true if this is a ssl enabled server diff --git a/libs/client/src/ecflow/client/ClientInvoker.hpp b/libs/client/src/ecflow/client/ClientInvoker.hpp index 515fe8acd..c424d27bb 100644 --- a/libs/client/src/ecflow/client/ClientInvoker.hpp +++ b/libs/client/src/ecflow/client/ClientInvoker.hpp @@ -73,6 +73,9 @@ class ClientInvoker { void disable_ssl() { clientEnv_.disable_ssl(); } // override environment setting for ECF_SSL #endif + void enable_http() { clientEnv_.enable_http(); } + void disable_http() { clientEnv_.disable_http(); } + /// This will override the environment setting. /// In particular setting host explicitly will avoid cycling through server list, /// if connection fails. hence will bomb out earlier