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

Add groups to UI

parent 4238118b
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
...@@ -22,11 +22,15 @@ void AddCtrl::show() { ...@@ -22,11 +22,15 @@ void AddCtrl::show() {
} }
ftl::Configurable *AddCtrl::add(const std::string &uri) { ftl::Configurable *AddCtrl::add(const std::string &uri) {
try {
if (io->feed()->sourceActive(uri)) { if (io->feed()->sourceActive(uri)) {
io->feed()->remove(uri); io->feed()->remove(uri);
} else { } else {
io->feed()->add(uri); io->feed()->add(uri);
} }
} catch (const ftl::exception &e) {
screen->showError("Exception", e.what());
}
return nullptr; return nullptr;
} }
...@@ -35,7 +39,7 @@ std::vector<std::string> AddCtrl::getHosts() { ...@@ -35,7 +39,7 @@ std::vector<std::string> AddCtrl::getHosts() {
} }
std::vector<std::string> AddCtrl::getGroups() { std::vector<std::string> AddCtrl::getGroups() {
return {}; return std::move(io->feed()->availableGroups());
} }
std::set<ftl::stream::SourceInfo> AddCtrl::getRecent() { std::set<ftl::stream::SourceInfo> AddCtrl::getRecent() {
......
...@@ -59,6 +59,7 @@ nanogui::Button *AddSourceWindow::_addButton(const std::string &s, nanogui::Widg ...@@ -59,6 +59,7 @@ nanogui::Button *AddSourceWindow::_addButton(const std::string &s, nanogui::Widg
case ftl::URI::SCHEME_FTL : icon = ENTYPO_ICON_CLOUD; break; case ftl::URI::SCHEME_FTL : icon = ENTYPO_ICON_CLOUD; break;
case ftl::URI::SCHEME_WS : case ftl::URI::SCHEME_WS :
case ftl::URI::SCHEME_TCP : icon = ENTYPO_ICON_CLASSIC_COMPUTER; break; case ftl::URI::SCHEME_TCP : icon = ENTYPO_ICON_CLASSIC_COMPUTER; break;
case ftl::URI::SCHEME_GROUP : icon = ENTYPO_ICON_MERGE; break;
default: break; default: break;
} }
...@@ -101,6 +102,7 @@ void AddSourceWindow::rebuild() { ...@@ -101,6 +102,7 @@ void AddSourceWindow::rebuild() {
auto srcs = ctrl_->getRecent(); auto srcs = ctrl_->getRecent();
for (auto &s : srcs) { for (auto &s : srcs) {
LOG(INFO) << "ADD RECENT: " << s.uri;
_addButton(s.uri, recentscroll); _addButton(s.uri, recentscroll);
} }
......
...@@ -25,7 +25,7 @@ struct SourceInfo { ...@@ -25,7 +25,7 @@ struct SourceInfo {
std::string uri; std::string uri;
int64_t last_used; int64_t last_used;
inline bool operator<(const SourceInfo &o) const { return last_used > o.last_used; } inline bool operator<(const SourceInfo &o) const { return last_used >= o.last_used; }
}; };
class Feed : public ftl::Configurable { class Feed : public ftl::Configurable {
...@@ -107,6 +107,7 @@ public: ...@@ -107,6 +107,7 @@ public:
std::vector<std::string> availableNetworkSources(); std::vector<std::string> availableNetworkSources();
std::vector<std::string> availableFileSources(); std::vector<std::string> availableFileSources();
std::vector<std::string> availableDeviceSources(); std::vector<std::string> availableDeviceSources();
std::vector<std::string> availableGroups();
bool sourceAvailable(const std::string &uri); bool sourceAvailable(const std::string &uri);
bool sourceActive(const std::string &uri); bool sourceActive(const std::string &uri);
......
...@@ -95,6 +95,7 @@ Feed::Feed(nlohmann::json &config, ftl::net::Universe*net) : ...@@ -95,6 +95,7 @@ Feed::Feed(nlohmann::json &config, ftl::net::Universe*net) :
"recent_files", "recent_files",
"recent_sources", "recent_sources",
"known_hosts", "known_hosts",
"known_groups",
"auto_host_connect", "auto_host_connect",
"auto_host_sources", "auto_host_sources",
"uri", "uri",
...@@ -540,6 +541,17 @@ std::vector<std::string> Feed::availableNetworkSources() { ...@@ -540,6 +541,17 @@ std::vector<std::string> Feed::availableNetworkSources() {
return netcams_; return netcams_;
} }
std::vector<std::string> Feed::availableGroups() {
std::vector<std::string> groups;
auto &known = getConfig()["known_groups"];
for (auto &f : known.items()) {
groups.push_back(f.key());
}
return groups;
}
std::vector<std::string> Feed::availableFileSources() { std::vector<std::string> Feed::availableFileSources() {
std::vector<std::string> files; std::vector<std::string> files;
auto &recent_files = getConfig()["recent_files"]; auto &recent_files = getConfig()["recent_files"];
...@@ -611,6 +623,17 @@ bool Feed::sourceActive(const std::string &suri) { ...@@ -611,6 +623,17 @@ bool Feed::sourceActive(const std::string &suri) {
if (uri.getScheme() == ftl::URI::SCHEME_TCP || uri.getScheme() == ftl::URI::SCHEME_WS) { if (uri.getScheme() == ftl::URI::SCHEME_TCP || uri.getScheme() == ftl::URI::SCHEME_WS) {
return net_->isConnected(uri); return net_->isConnected(uri);
} else if (uri.getScheme() == ftl::URI::SCHEME_GROUP) {
// Check that every constituent source is active
auto &known = getConfig()["known_groups"];
if (known.contains(uri.getBaseURI())) {
auto &sources = known[uri.getBaseURI()]["sources"];
for (auto i=sources.begin(); i!=sources.end(); ++i) {
if (!sourceActive(i.key())) return false;
}
}
return true;
} else { } else {
SHARED_LOCK(mtx_, lk); SHARED_LOCK(mtx_, lk);
return fsid_lookup_.count(uri.getBaseURI()) > 0; return fsid_lookup_.count(uri.getBaseURI()) > 0;
...@@ -655,6 +678,13 @@ std::string Feed::getName(const std::string &puri) { ...@@ -655,6 +678,13 @@ std::string Feed::getName(const std::string &puri) {
return getConfig()["recent_files"][uri.getBaseURI()].value("name", "FTLFile"); return getConfig()["recent_files"][uri.getBaseURI()].value("name", "FTLFile");
} else if (uri.getScheme() == ftl::URI::SCHEME_TCP || uri.getScheme() == ftl::URI::SCHEME_WS) { } else if (uri.getScheme() == ftl::URI::SCHEME_TCP || uri.getScheme() == ftl::URI::SCHEME_WS) {
return uri.getBaseURI(); return uri.getBaseURI();
} else if (uri.getScheme() == ftl::URI::SCHEME_GROUP) {
auto &groups = getConfig()["known_groups"];
if (groups.contains(uri.getBaseURI())) {
return uri.getPathSegment(0) + std::string(" (") + std::to_string(groups[uri.getBaseURI()]["sources"].size()) + std::string(")");
} else {
return uri.getPathSegment(0);
}
} }
return uri.getPathSegment(-1); return uri.getPathSegment(-1);
...@@ -674,6 +704,14 @@ nlohmann::json &Feed::_add_recent_source(const ftl::URI &uri) { ...@@ -674,6 +704,14 @@ nlohmann::json &Feed::_add_recent_source(const ftl::URI &uri) {
details["uri"] = uri.to_string(); details["uri"] = uri.to_string();
details["name"] = name; details["name"] = name;
details["last_open"] = ftl::timer::get_time(); details["last_open"] = ftl::timer::get_time();
if (uri.hasAttribute("group")) {
std::string grpname = uri.getAttribute<std::string>("group");
auto &groups = getConfig()["known_groups"];
auto &grpdetail = groups[std::string("group:")+grpname];
grpdetail["sources"][uri.getBaseURI()] = true;
}
return details; return details;
} }
...@@ -816,7 +854,11 @@ uint32_t Feed::add(const std::string &path) { ...@@ -816,7 +854,11 @@ uint32_t Feed::add(const std::string &path) {
auto &known = getConfig()["recent_sources"]; auto &known = getConfig()["recent_sources"];
auto &details = known[uri.getBaseURI()]; auto &details = known[uri.getBaseURI()];
if (details.contains("host")) { if (details.contains("host")) {
net_->connect(details["host"].get<std::string>())->waitConnection(); auto *p = net_->connect(details["host"].get<std::string>());
p->noReconnect();
if (!p->waitConnection()) {
throw FTL_Error("Could not connect to host " << details["host"].get<std::string>() << " for stream " << path);
}
} else { } else {
// See if it can otherwise be found? // See if it can otherwise be found?
} }
...@@ -836,6 +878,19 @@ uint32_t Feed::add(const std::string &path) { ...@@ -836,6 +878,19 @@ uint32_t Feed::add(const std::string &path) {
add_src_cb_.trigger(fsid); add_src_cb_.trigger(fsid);
return fsid; return fsid;
} else if (scheme == ftl::URI::SCHEME_GROUP) {
auto &known = getConfig()["known_groups"];
if (known.contains(uri.getBaseURI())) {
auto &sources = known[uri.getBaseURI()]["sources"];
lk.unlock();
for (auto i=sources.begin(); i!=sources.end(); ++i) {
add(i.key());
}
lk.lock();
_add_recent_source(uri);
}
} }
else{ else{
throw ftl::exception("bad uri"); throw ftl::exception("bad uri");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment