Skip to content
Snippets Groups Projects
Commit 12a0bac8 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add host add and clear

parent 0a71caf4
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
Pipeline #28562 passed
......@@ -8,6 +8,7 @@
#include <nanogui/button.h>
#include <nanogui/vscrollpanel.h>
#include <nanogui/tabwidget.h>
#include <nanogui/formhelper.h>
#include <loguru.hpp>
......@@ -168,13 +169,38 @@ void AddSourceWindow::rebuild() {
_addButton(s, tab_items_[2]);
}
button = new Button(tab_items_[3], "Add Host", ENTYPO_ICON_PLUS);
button->setIconPosition(Button::IconPosition::Left);
button->setIconExtraScale(1.2);
auto *host_menu = new Widget(tab_items_[3]);
host_menu->setLayout(new BoxLayout(nanogui::Orientation::Horizontal, nanogui::Alignment::Maximum, 5,4));
button = new Button(host_menu, "Add", ENTYPO_ICON_PLUS);
button->setFontSize(18);
button->setTooltip("Manually add a new connection URI");
button->setTooltip("Connect to a new machine");
button->setCallback([this]() {
FormHelper *fh = new FormHelper(screen());
auto *win = fh->addWindow(Vector2i(10,10), "Add Host");
win->center();
win->setTheme(dynamic_cast<ftl::gui2::Screen*>(win->screen())->getTheme("window_dark"));
//win->setWidth(200);
fh->addVariable<std::string>("URI", [this,win](const std::string &v) {
try {
ctrl_->add(v);
} catch (const ftl::exception &e) {
LOG(ERROR) << "Add failed: " << e.what();
}
win->dispose();
}, [this]() {
return "";
})->setFixedWidth(150);
win->screen()->performLayout();
delete fh;
});
button = new Button(host_menu, "Clear", ENTYPO_ICON_CYCLE);
button->setFontSize(18);
button->setTooltip("Clear host history");
button->setCallback([this]() {
ctrl_->feed()->clearHostHistory();
uptodate_.clear();
});
auto hostsrcs = ctrl_->getHosts();
......@@ -239,9 +265,7 @@ void AddSourceWindow::draw(NVGcontext *ctx) {
{
UNIQUE_LOCK(mutex_, lk);
if (!uptodate_.test_and_set()) {
tabs_->requestFocus();
// Note the 1, first widget is the title bar buttons
//while(childCount() > 1) { removeChild(childCount()-1); }
tabs_->requestFocus(); // Must ensure focus item not deleted
rebuild();
screen()->performLayout();
}
......
......@@ -112,6 +112,7 @@ public:
bool sourceActive(const std::string &uri);
void clearFileHistory();
void clearHostHistory();
/**
* Perform a render tick for all render sources. Note that this must be
......
......@@ -595,6 +595,22 @@ std::vector<std::string> Feed::knownHosts() {
return hosts;
}
void Feed::clearHostHistory() {
UNIQUE_LOCK(mtx_, lk);
auto &known = getConfig()["known_hosts"];
known.clear();
auto &recent = getConfig()["recent_sources"];
for (auto i=recent.begin(); i != recent.end();) {
ftl::URI uri(i.key());
if (uri.getScheme() == ftl::URI::SCHEME_TCP || uri.getScheme() == ftl::URI::SCHEME_WS) {
i = recent.erase(i);
} else {
++i;
}
}
}
std::set<ftl::stream::SourceInfo> Feed::recentSources() {
std::set<ftl::stream::SourceInfo> result;
......@@ -873,7 +889,7 @@ uint32_t Feed::add(const std::string &path) {
auto &host_details = known_hosts[uri.getBaseURIWithUser()];
host_details["last_open"] = ftl::timer::get_time();
ftl::pool.push([this,path](int id) { net_->connect(path); });
ftl::pool.push([this,path](int id) { net_->connect(path)->noReconnect(); });
}
else if (scheme == ftl::URI::SCHEME_FTL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment