#include "addsource.hpp"

using ftl::gui2::AddCtrl;

void AddCtrl::init() {
	button = screen->addButton(ENTYPO_ICON_PLUS);
	button->setCallback([this](){
		button->setPushed(false);
		show();
	});
	button->setVisible(true);
}

void AddCtrl::show() {
	if (screen->childIndex(window) == -1) {
		window = new ftl::gui2::AddSourceWindow(screen, this);
	}
	window->requestFocus();
	window->setVisible(true);
	screen->performLayout();
}

ftl::Configurable *AddCtrl::add(const std::string &uri) {
	io->feed()->add(uri);
	return nullptr;
}

std::vector<std::string> AddCtrl::getNetSources() {
	return std::move(io->feed()->availableNetworkSources());
}

std::vector<std::string> AddCtrl::getFileSources() {
	return std::move(io->feed()->availableFileSources());
}

std::string AddCtrl::getSourceName(const std::string &uri) {
	return io->feed()->getName(uri);
}

bool AddCtrl::isSourceActive(const std::string &uri) {
	return io->feed()->sourceActive(uri);
}

AddCtrl::~AddCtrl() {
	// remove window?
}