bar can now toggle bluetooth power and discovery
This commit is contained in:
79
src/widgets/todo.cpp
Normal file
79
src/widgets/todo.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "widgets/todo.hpp"
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/entry.h>
|
||||
#include <string>
|
||||
|
||||
TodoPopover::TodoPopover(std::string icon, std::string title) : Popover(icon, title) {
|
||||
this->name = title;
|
||||
this->popover->set_size_request(300, -1);
|
||||
|
||||
container.set_orientation(Gtk::Orientation::VERTICAL);
|
||||
container.set_spacing(10);
|
||||
container.add_css_class("todo-popover-container");
|
||||
|
||||
auto entry = Gtk::make_managed<Gtk::Entry>();
|
||||
entry->set_placeholder_text("Enter your to-do item...");
|
||||
entry->add_css_class("todo-input");
|
||||
entry->set_hexpand(true);
|
||||
entry->set_halign(Gtk::Align::FILL);
|
||||
entry->set_valign(Gtk::Align::START);
|
||||
|
||||
inputArea.append(*entry);
|
||||
inputArea.add_css_class("todo-input-area");
|
||||
inputArea.set_hexpand(true);
|
||||
inputArea.set_halign(Gtk::Align::FILL);
|
||||
|
||||
entry->signal_activate().connect([this, entry]() {
|
||||
std::string text = entry->get_text();
|
||||
if (!text.empty()) {
|
||||
this->todoService->addTodo(text);
|
||||
|
||||
entry->set_text("");
|
||||
}
|
||||
});
|
||||
|
||||
container.append(inputArea);
|
||||
|
||||
this->todoList = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
|
||||
container.append(*todoList);
|
||||
todoList->add_css_class("todo-list");
|
||||
|
||||
auto signal = sigc::signal<void()>();
|
||||
this->todoService = new TodoService(signal);
|
||||
|
||||
signal.connect(sigc::mem_fun(*this, &TodoPopover::update));
|
||||
|
||||
this->set_popover_child(this->container);
|
||||
this->update();
|
||||
}
|
||||
|
||||
void TodoPopover::update() {
|
||||
auto todos = this->todoService->getTodos();
|
||||
|
||||
Gtk::Widget *child = todoList->get_first_child();
|
||||
|
||||
while (child) {
|
||||
Gtk::Widget *next = child->get_next_sibling();
|
||||
|
||||
bool found = false;
|
||||
for (auto &[id, todo] : todos) {
|
||||
if (child == todo) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
todoList->remove(*child);
|
||||
}
|
||||
|
||||
child = next;
|
||||
}
|
||||
|
||||
for (auto &[id, todo] : todos) {
|
||||
if (todo->get_parent() == nullptr) {
|
||||
todoList->append(*todo);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user