Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ MultiApp/ // Core application files
- 🎉 Simple internet browser
- 🎉 Fractal creator
- 🎉 Local chat app
- ❌ Maze generator/player/solver
- ❌ Game of life
- ❌ Maze generator/player/solver
- ❌ Music player
- ❌ Local AI chat with ollama
- 🔬 Other goodies in the future

Expand Down
36 changes: 0 additions & 36 deletions res/gtk/main_app.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,6 @@
<object class="GtkNotebook" id="main_notebook">
<property name="page">0</property>
<property name="vexpand">True</property>
<child>
<object class="GtkBox" id="Chat">
<property name="orientation">vertical</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
</object>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="label">Chat</property>
</object>
</child>
<child>
<object class="GtkBox" id="Fractal">
<property name="orientation">vertical</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
</object>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="label">Fractal</property>
</object>
</child>
<child>
<object class="GtkBox" id="Browser">
<property name="orientation">vertical</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
</object>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="label">Browser</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
12 changes: 6 additions & 6 deletions src/browser_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ Browser::Browser() : Gtk::Box(Gtk::Orientation::VERTICAL) {
if(back_button) [[likely]]
back_button->signal_clicked().connect
(
[this](){ webkit_web_view_go_back(web_view);}
[this]{ webkit_web_view_go_back(web_view);}
);
if(forward_button) [[likely]]
forward_button->signal_clicked().connect
(
[this](){ webkit_web_view_go_forward(web_view);}
[this]{ webkit_web_view_go_forward(web_view);}
);
if(home_button) [[likely]]
home_button->signal_clicked().connect
(
[this](){ entry_uri_load(HOME_URL);}
[this]{ entry_uri_load(HOME_URL);}
);
if(reload_button) [[likely]]
reload_button->signal_clicked().connect
(
[this]() {
[this] {
webkit_web_view_is_loading(web_view) ?
webkit_web_view_stop_loading(web_view) :
webkit_web_view_reload(web_view);
}
);
if(uri_entry) [[likely]] {
uri_entry->signal_activate().connect([this](){ entry_uri_load();});
uri_entry->signal_activate().connect([this]{ entry_uri_load();});
if(enter_button) [[likely]]
enter_button->signal_clicked().connect([this](){ entry_uri_load();});
enter_button->signal_clicked().connect([this]{ entry_uri_load();});
}
// Menu button not visible as no usage needed for the moment
if(menu_button) [[likely]] menu_button->set_visible(false);
Expand Down
22 changes: 11 additions & 11 deletions src/chat_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ Chat::Chat() : Gtk::Box(Gtk::Orientation::VERTICAL) {
// Add Callbacks
if(home_button) [[likely]]
home_button->signal_clicked().connect
( [this](){ ip_entry->set_text(LOCALHOST); port_entry->set_text(DEFAULT_PORT); } );
( [this]{ ip_entry->set_text(LOCALHOST); port_entry->set_text(DEFAULT_PORT); } );
if(ip_entry) [[likely]]
ip_entry->signal_activate().connect([this](){ session_connection(); });
ip_entry->signal_activate().connect([this]{ session_connection(); });
if(port_entry) [[likely]]
port_entry->signal_activate().connect([this](){ session_connection(); });
port_entry->signal_activate().connect([this]{ session_connection(); });
if(connect_button) [[likely]]
connect_button->signal_clicked().connect([this](){ session_connection(); });
connect_button->signal_clicked().connect([this]{ session_connection(); });

if(message_entry) [[likely]]
message_entry->signal_activate().connect( [this] () { message_buffer(); });
message_entry->signal_activate().connect( [this] { message_buffer(); });
if(message_button) [[likely]]
message_button->signal_clicked().connect( [this] () { message_buffer(); });
message_button->signal_clicked().connect( [this] { message_buffer(); });

// Insert elements into Browser Box
insert_child_at_start(*header);
Expand Down Expand Up @@ -132,11 +132,11 @@ void Chat::session_connection() {
footer_box->set_visible(true);
message_entry->grab_focus();

session->set_disconnecter([this]() {
Glib::signal_idle().connect_once([this]() { session_connection(); });
session->set_disconnecter([this] {
Glib::signal_idle().connect_once([this] { session_connection(); });
});
dispatcher = std::make_unique<Glib::Dispatcher>();
dispatcher->connect([this]() {
dispatcher->connect([this] {
std::lock_guard<std::mutex> lock(session->receive_mutex);
while (!session->receive_queue.empty()) {
std::string message{std::move(session->receive_queue.front())};
Expand Down Expand Up @@ -165,13 +165,13 @@ void Chat::session_connection() {
bubble->set_wrap_mode(Pango::WrapMode::WORD_CHAR);
chat_box->append(*bubble);

Glib::signal_idle().connect_once([this]() {
Glib::signal_idle().connect_once([this] {
auto adj = chat_scrolled->get_vadjustment();
adj->set_value(adj->get_upper() - adj->get_page_size());
});
}
});
session->set_poster([this]() { dispatcher->emit(); });
session->set_poster([this] { dispatcher->emit(); });
}

void Chat::message_buffer () {
Expand Down
10 changes: 5 additions & 5 deletions src/fractal_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void FractalArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int w, int h)
}


FractalBox::FractalBox() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
Fractal::Fractal() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
// Load the GtkBuilder file and instantiate its widgets, check for errors
auto ref_builder {Gtk::Builder::create()};
try {
Expand Down Expand Up @@ -189,19 +189,19 @@ FractalBox::FractalBox() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
if(reset_button) [[likely]]
reset_button->signal_clicked().connect
(
[this](){ fractal_area->reset(); }
[this]{ fractal_area->reset(); }
);
if(save_button) [[likely]] {
save_button->signal_clicked().connect
(
[](){ std::cout << "Save button pressed!" << std::endl;}
[]{ std::cout << "Save button pressed!" << std::endl;}
);
save_button->set_visible(false); //Set visible false until new way of creating a dialog is available
}
if(fractal_dropdown) [[likely]]
fractal_dropdown->property_selected().signal_changed().connect
(
[this](){
[this]{
selection = std::dynamic_pointer_cast<Gtk::StringObject>(fractal_dropdown->get_selected_item())->get_string();
fractal_area->set_selection(selection);
if (selection != "Julia")
Expand Down Expand Up @@ -274,7 +274,7 @@ FractalBox::FractalBox() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
}


void FractalBox::on_realize() {
void Fractal::on_realize() {
Gtk::Box::on_realize();
selection = std::dynamic_pointer_cast<Gtk::StringObject>(fractal_dropdown->get_selected_item())->get_string();
status_label = dynamic_cast<Gtk::Label *>(get_parent()->get_parent()->get_parent()->get_parent()->get_last_child());
Expand Down
4 changes: 2 additions & 2 deletions src/include/fractal_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class FractalArea : public Gtk::DrawingArea {
* Gtk::Box implementing class that contains important Gtk Widgets
* for loading, displaying and saving fractals.
*/
class FractalBox : public Gtk::Box {
class Fractal : public Gtk::Box {
friend class FractalTest;
friend class FractalTest_FractalFunctionalTest_Test;

Expand All @@ -176,7 +176,7 @@ class FractalBox : public Gtk::Box {
* Creates FractalBox object using res/gtk/fractal_app.ui file,
* Checks for file issues, gets Widgets and connects needed signals.
*/
FractalBox();
Fractal();

private:
std::string selection{};
Expand Down
2 changes: 2 additions & 0 deletions src/include/main_application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MainApplication : public Gtk::Application {
Gtk::ApplicationWindow *main_window{};
Gtk::Box *selected_app{};

std::vector<std::pair<std::string, std::function<Gtk::Box*()>>> apps{};

/**
* @brief Creates ApplicationWindow to show.
*
Expand Down
38 changes: 17 additions & 21 deletions src/main_application.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "include/main_application.hpp"
#include "gtkmm/object.h"
#include "include/browser_app.hpp"
#include "include/fractal_app.hpp"
#include "include/chat_app.hpp"
Expand All @@ -8,7 +9,12 @@
#include <gtkmm.h>

MainApplication::MainApplication() :
Gtk::Application("org.xchel.multiapp", Gio::Application::Flags::HANDLES_OPEN | Gio::Application::Flags::NON_UNIQUE) {}
Gtk::Application("org.xchel.multiapp", Gio::Application::Flags::HANDLES_OPEN | Gio::Application::Flags::NON_UNIQUE),
apps ({
{"Chat", [] { return new Chat(); }},
{"Fractal", [] { return new Fractal(); }},
{"Browser", [] { return new Browser(); }}
}) {}

Glib::RefPtr<MainApplication> MainApplication::create() {
return Glib::make_refptr_for_instance<MainApplication>(new MainApplication());
Expand Down Expand Up @@ -39,32 +45,22 @@ Gtk::ApplicationWindow* MainApplication::create_window() {
main_window = Gtk::manage(ref_builder->get_widget<Gtk::ApplicationWindow>("main_window"));

auto main_notebook {Gtk::manage(ref_builder->get_widget<Gtk::Notebook>("main_notebook"))};
auto main_box {Gtk::manage(ref_builder->get_widget<Gtk::Box>("Chat"))};
for ( auto app : apps ) {
main_notebook->append_page(
*Gtk::manage(new Gtk::Box()),
*Gtk::manage(new Gtk::Label(app.first))
);
}
auto main_box {Gtk::manage(dynamic_cast<Gtk::Box*>(main_notebook->get_nth_page(0)))};

selected_app = Gtk::manage(new Chat());
main_box->append(*selected_app);

main_notebook->signal_switch_page().connect([this](Gtk::Widget* page, guint page_number) {
if (selected_app) selected_app->unparent();
selected_app = Gtk::manage(apps[page_number].second());
auto app {dynamic_cast<Gtk::Box *>(page)};
if (selected_app) {
selected_app->unparent();
selected_app = nullptr;
}

switch(page_number) {
case 0:
selected_app = Gtk::manage(new Chat());
app->append(*selected_app);
break;
case 1:
selected_app = Gtk::manage(new FractalBox());
app->append(*selected_app);
break;
case 2:
selected_app = Gtk::manage(new Browser());
app->append(*selected_app);
break;
}
app->append(*selected_app);
});

add_window(*main_window);
Expand Down
4 changes: 2 additions & 2 deletions src/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Client::Client(const std::string &host, unsigned port) :
asio::co_spawn(ioc, sender(connection), asio::detached);

// Run the event loop in separate thread until ioc.stop() is called
ioc_thread = std::thread([this](){ ioc.run(); });
ioc_thread = std::thread([this]{ ioc.run(); });
std::cout << "[Client] connected to " << host << ":" << port << "\n";
}

Expand Down Expand Up @@ -145,7 +145,7 @@ Server::Server(unsigned port) : Session::Session(),
acceptor (tcp::acceptor(ioc, tcp::endpoint(tcp::v4(), static_cast<asio::ip::port_type>(port)))) {
type = "Server";
asio::co_spawn(ioc, accept_loop(), asio::detached);
ioc_thread = std::thread([this](){ ioc.run(); });
ioc_thread = std::thread([this]{ ioc.run(); });
std::cout << "[" + type + "] listening on port " << port << "\n";
}

Expand Down
8 changes: 4 additions & 4 deletions tests/chat_app_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ TEST_F(ChatTest, ChatFunctionalTest) {
ASSERT_THAT(std::regex_search(server->session->receive_queue.front(), std::regex("User\\d says Hi!!!")), ::testing::Eq(true));

// Check poster and disconnecter setters
server->session->set_poster([this](){ std::cout << "Posting message from Server..." << std::endl; });
server->session->set_disconnecter([this](){ std::cout << "Disconnecting from Server..." << std::endl; });
server->session->set_poster([this]{ std::cout << "Posting message from Server..." << std::endl; });
server->session->set_disconnecter([this]{ std::cout << "Disconnecting from Server..." << std::endl; });
ASSERT_THAT(server->session->poster, ::testing::NotNull());
ASSERT_THAT(server->session->disconnecter, ::testing::NotNull());
server->session->poster();
server->session->disconnecter();
client_1->session->set_poster([this](){ std::cout << "Posting message from Client..." << std::endl; });
client_1->session->set_disconnecter([this](){ std::cout << "Disconnecting from Client..." << std::endl; });
client_1->session->set_poster([this]{ std::cout << "Posting message from Client..." << std::endl; });
client_1->session->set_disconnecter([this]{ std::cout << "Disconnecting from Client..." << std::endl; });
ASSERT_THAT(client_1->session->poster, ::testing::NotNull());
ASSERT_THAT(client_1->session->disconnecter, ::testing::NotNull());
client_1->session->poster();
Expand Down
3 changes: 2 additions & 1 deletion tests/fractal_app_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include <gmock/gmock.h>


FractalTest::FractalTest() : fractal (Gtk::manage(new FractalBox())),
FractalTest::FractalTest() :
fractal (Gtk::manage(new Fractal())),
menu (fractal->menu),
consts_box (fractal->consts_box),
reset_button (fractal->reset_button),
Expand Down
2 changes: 1 addition & 1 deletion tests/include/tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class FractalTest : public testing::Test {
* */
FractalTest();

FractalBox *fractal{};
Fractal *fractal{};
Gtk::Box *menu{};
Gtk::Box *consts_box{};
Gtk::Button *reset_button{};
Expand Down