add todo setup
This commit is contained in:
@@ -21,17 +21,23 @@ target_sources(bar_lib
|
||||
PUBLIC
|
||||
src/app.cpp
|
||||
src/bar/bar.cpp
|
||||
|
||||
src/widgets/clock.cpp
|
||||
src/widgets/date.cpp
|
||||
src/widgets/workspaceIndicator.cpp
|
||||
src/widgets/volumeWidget.cpp
|
||||
src/widgets/webWidget.cpp
|
||||
|
||||
src/services/todo.cpp
|
||||
src/services/hyprland.cpp
|
||||
src/services/tray.cpp
|
||||
src/services/notifications.cpp
|
||||
|
||||
src/widgets/tray.cpp
|
||||
src/widgets/todo.cpp
|
||||
src/widgets/todoPopover.cpp
|
||||
|
||||
src/components/popover.cpp
|
||||
src/components/todoEntry.cpp
|
||||
)
|
||||
include_directories(bar_lib PRIVATE
|
||||
include
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
#include "widgets/clock.hpp"
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/tray.hpp"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/webWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
|
||||
class Bar : public Gtk::Window {
|
||||
public:
|
||||
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
|
||||
TrayService &trayService, int monitorId);
|
||||
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, TrayService &trayService, int monitorId);
|
||||
|
||||
protected:
|
||||
Gtk::CenterBox main_box{};
|
||||
@@ -23,16 +23,18 @@ class Bar : public Gtk::Window {
|
||||
Gtk::Box right_box{Gtk::Orientation::HORIZONTAL};
|
||||
|
||||
private:
|
||||
int monitorId;
|
||||
|
||||
Clock clock;
|
||||
Date date;
|
||||
WebWidget homeAssistant{ICON_HOME, "Home Assistant",
|
||||
"https://home.rivercry.com"};
|
||||
TrayService &trayService;
|
||||
HyprlandService &hyprlandService;
|
||||
int monitorId;
|
||||
WebWidget homeAssistant{ICON_HOME, "Home Assistant", "https://home.rivercry.com"};
|
||||
|
||||
WorkspaceIndicator *workspaceIndicator = nullptr;
|
||||
TrayWidget *trayWidget = nullptr;
|
||||
class VolumeWidget *volumeWidget = nullptr;
|
||||
VolumeWidget *volumeWidget = nullptr;
|
||||
|
||||
TrayService &trayService;
|
||||
HyprlandService &hyprlandService;
|
||||
|
||||
void setup_ui();
|
||||
void setup_left_box();
|
||||
|
||||
18
include/components/todoEntry.hpp
Normal file
18
include/components/todoEntry.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "gtkmm/box.h"
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
class TodoEntry : public Gtk::Box {
|
||||
public:
|
||||
TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed);
|
||||
~TodoEntry() override;
|
||||
|
||||
int get_id() const { return id; }
|
||||
private:
|
||||
int id;
|
||||
sigc::signal<void(int)> signal_dismissed;
|
||||
|
||||
void on_dismiss_clicked();
|
||||
};
|
||||
22
include/services/todo.hpp
Normal file
22
include/services/todo.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/todoEntry.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TodoService {
|
||||
public:
|
||||
TodoService(sigc::signal<void()> refreshSignal);
|
||||
~TodoService();
|
||||
|
||||
std::map<int, TodoEntry *> getTodos();
|
||||
void init();
|
||||
void removeTodo(int id);
|
||||
TodoEntry *addTodo(std::string text, bool emitSignal = true);
|
||||
void updateTodo(int id, std::string text);
|
||||
|
||||
private:
|
||||
int nextId = 1;
|
||||
std::map<int, TodoEntry *> todos;
|
||||
sigc::signal<void()> refreshSignal;
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/popover.hpp"
|
||||
|
||||
class Todo : public Popover {
|
||||
public:
|
||||
Todo(std::string icon, std::string title);
|
||||
};
|
||||
19
include/widgets/todoPopover.hpp
Normal file
19
include/widgets/todoPopover.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/popover.hpp"
|
||||
#include "services/todo.hpp"
|
||||
#include <string>
|
||||
|
||||
class TodoPopover : public Popover {
|
||||
|
||||
public:
|
||||
TodoPopover(std::string icon, std::string title);
|
||||
|
||||
void update();
|
||||
private:
|
||||
std::string name;
|
||||
TodoService* todoService = nullptr;
|
||||
Gtk::Box container;
|
||||
Gtk::Box inputArea;
|
||||
Gtk::Box* todoList = nullptr;
|
||||
};
|
||||
@@ -109,3 +109,21 @@ tooltip {
|
||||
font-family: "Material Icons, Font Awesome 7 Brands, Hack Nerd Font Mono";
|
||||
font-size: 19px;
|
||||
}
|
||||
|
||||
.todo-popover-container {
|
||||
padding: 10px;
|
||||
background-color: #1e1e1e;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.todo-input-area {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.todo-input {
|
||||
padding: 5px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #555555;
|
||||
background-color: #222222;
|
||||
color: #ffffff;
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/spacer.hpp"
|
||||
#include "widgets/todo.hpp"
|
||||
#include "widgets/todoPopover.hpp"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
|
||||
@@ -40,8 +40,8 @@ Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
|
||||
set_child(main_box);
|
||||
|
||||
this->volumeWidget = Gtk::make_managed<VolumeWidget>();
|
||||
workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
|
||||
trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
||||
this->workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
|
||||
this->trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
||||
|
||||
load_css();
|
||||
setup_ui();
|
||||
@@ -73,7 +73,7 @@ void Bar::setup_left_box() {
|
||||
void Bar::setup_center_box() {
|
||||
center_box.set_hexpand(false);
|
||||
|
||||
center_box.append(*(new Todo("\uf23a", "To-Do")));
|
||||
center_box.append(*(new TodoPopover("\uf23a", "To-Do")));
|
||||
center_box.append(*(new Spacer()));
|
||||
center_box.append(this->date);
|
||||
center_box.append(*(new Spacer()));
|
||||
|
||||
45
src/components/todoEntry.cpp
Normal file
45
src/components/todoEntry.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "components/todoEntry.hpp"
|
||||
|
||||
#include <gtkmm/label.h>
|
||||
|
||||
#include "gtkmm/button.h"
|
||||
|
||||
TodoEntry::TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed)
|
||||
: Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
||||
this->id = id;
|
||||
this->signal_dismissed = signal_dismissed;
|
||||
|
||||
|
||||
auto box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||
box->set_hexpand(true);
|
||||
box->set_halign(Gtk::Align::START);
|
||||
box->set_valign(Gtk::Align::CENTER);
|
||||
box->set_name("todo-entry-box");
|
||||
box->add_css_class("todo-entry-box");
|
||||
append(*box);
|
||||
|
||||
auto label = Gtk::make_managed<Gtk::Label>(text);
|
||||
label->set_halign(Gtk::Align::START);
|
||||
label->set_valign(Gtk::Align::CENTER);
|
||||
box->append(*label);
|
||||
|
||||
auto buttonBox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||
buttonBox->set_halign(Gtk::Align::END);
|
||||
buttonBox->set_valign(Gtk::Align::CENTER);
|
||||
append(*buttonBox);
|
||||
|
||||
auto dismissButton = Gtk::make_managed<Gtk::Button>("\uf00d");
|
||||
dismissButton->set_valign(Gtk::Align::CENTER);
|
||||
dismissButton->set_tooltip_text("Dismiss");
|
||||
|
||||
dismissButton->signal_clicked().connect(sigc::mem_fun(*this, &TodoEntry::on_dismiss_clicked));
|
||||
|
||||
buttonBox->append(*dismissButton);
|
||||
}
|
||||
|
||||
TodoEntry::~TodoEntry() {
|
||||
}
|
||||
|
||||
void TodoEntry::on_dismiss_clicked() {
|
||||
this->signal_dismissed.emit(this->id);
|
||||
}
|
||||
56
src/services/todo.cpp
Normal file
56
src/services/todo.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "services/todo.hpp"
|
||||
#include "components/todoEntry.hpp"
|
||||
#include "gtkmm/object.h"
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
TodoService::TodoService(sigc::signal<void()> refreshSignal) {
|
||||
this->refreshSignal = refreshSignal;
|
||||
this->init();
|
||||
}
|
||||
|
||||
TodoService::~TodoService() {}
|
||||
|
||||
std::map<int, TodoEntry *> TodoService::getTodos() {
|
||||
return this->todos;
|
||||
}
|
||||
|
||||
void TodoService::init() {
|
||||
std::vector<std::string> items = {
|
||||
"Buy groceries",
|
||||
"Finish the report",
|
||||
"Call Alice",
|
||||
"Schedule dentist appointment"};
|
||||
|
||||
for (auto item : items) {
|
||||
this->addTodo(item, false);
|
||||
}
|
||||
}
|
||||
|
||||
void TodoService::removeTodo(int id) {
|
||||
if (todos.find(id) == todos.end()) {
|
||||
std::cerr << "Todo with id " << id << " not found!" << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
todos.erase(id);
|
||||
|
||||
this->refreshSignal.emit();
|
||||
}
|
||||
|
||||
TodoEntry *TodoService::addTodo(std::string text, bool emitSignal) {
|
||||
auto signal = sigc::signal<void(int)>();
|
||||
signal.connect(sigc::mem_fun(*this, &TodoService::removeTodo));
|
||||
TodoEntry *todo = Gtk::make_managed<TodoEntry>(nextId, text, signal);
|
||||
|
||||
todos[nextId] = todo;
|
||||
|
||||
nextId++;
|
||||
|
||||
if (emitSignal) {
|
||||
this->refreshSignal.emit();
|
||||
}
|
||||
return todo;
|
||||
}
|
||||
|
||||
void TodoService::updateTodo(int id, std::string text) {}
|
||||
@@ -1,9 +0,0 @@
|
||||
#include <gtkmm/label.h>
|
||||
|
||||
#include "widgets/todo.hpp"
|
||||
|
||||
Todo::Todo(std::string icon, std::string title) : Popover(icon, title) {
|
||||
auto label = Gtk::make_managed<Gtk::Label>(title);
|
||||
label->add_css_class("todo-label");
|
||||
this->set_popover_child(*label);
|
||||
}
|
||||
78
src/widgets/todoPopover.cpp
Normal file
78
src/widgets/todoPopover.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "widgets/todoPopover.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);
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "widgets/webWidget.hpp"
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <webkit/webkit.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user