From 1bb458198cd40d29b8515ae769e23310ab88c6d7 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Mon, 26 Aug 2024 14:22:15 +0000 Subject: [PATCH] Add private modules build and add Applcation ref to MainWindow --- CMakeLists.txt | 9 ++++++++- src/application.cpp | 23 ++++++----------------- src/application_impl.cpp | 16 ++++++++++++++++ {lib/src => src/lib}/library.cpp | 0 src/main_window.cpp | 16 +++++++++------- 5 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 src/application_impl.cpp rename {lib/src => src/lib}/library.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ddc7d49..7fe178b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,12 @@ set(CXX_EXTENSIONS NO) set(BOOST_INCLUDE_LIBRARIES "pfr") option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON) -file(GLOB_RECURSE LIB_SOURCES "lib/src/*.cpp") +file(GLOB_RECURSE LIB_SOURCES "src/lib/*.cpp") file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE IMPL_SOURCES "src/*_impl.cpp") +file(GLOB_RECURSE LIB_IMPL_SOURCES "src/lib/*_impl.cpp") +list(REMOVE_ITEM LIB_SOURCES ${LIB_IMPL_SOURCES}) +list(REMOVE_ITEM SOURCES ${IMPL_SOURCES} ${LIB_SOURCES}) set(CMAKE_CXX_MODULE_STD 1) set_target_properties(__cmake_cxx23 PROPERTIES CXX_EXTENSIONS OFF) @@ -85,6 +89,8 @@ target_compile_features(larra_xmpp INTERFACE cxx_std_23) target_sources(larra_xmpp PUBLIC FILE_SET larraXMPPSet TYPE CXX_MODULES FILES ${LIB_SOURCES}) +target_sources(larra_xmpp PUBLIC ${LIB_IMPL_SOURCES}) + install(TARGETS larra_xmpp EXPORT larraXMPPTargets @@ -115,6 +121,7 @@ target_link_libraries(larra larra_xmpp) target_sources(larra PUBLIC FILE_SET larraSet TYPE CXX_MODULES FILES ${SOURCES}) +target_sources(larra PUBLIC ${IMPL_SOURCES}) install(TARGETS larra RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/src/application.cpp b/src/application.cpp index 4d79a74..6a57c41 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -3,17 +3,16 @@ module; #include export module larra.application; -import larra.main_window; namespace larra { export struct Application : Gtk::Application { Application() : Gtk::Application("org.larra.larra") { Glib::set_application_name("Larra"); - }; + } static auto create() -> Glib::RefPtr { return Glib::make_refptr_for_instance(new Application{}); // NOLINT - }; + } auto on_startup() -> void final { this->Gtk::Application::on_startup(); this->add_action("preferences", sigc::mem_fun(*this, &Application::OnClickPreferences)); @@ -32,25 +31,15 @@ export struct Application : Gtk::Application { gmenu->append_submenu("Accounts", accountsMenu); gmenu->append_submenu("Help", helpMenu); this->set_menubar(gmenu); - }; + } - auto on_activate() -> void final { - auto win = new MainWindow{}; // NOLINT - this->add_window(*win); - win->signal_hide().connect([win] { - delete win; // NOLINT - }); - win->set_show_menubar(); - win->set_visible(true); - }; + auto on_activate() -> void final; auto OnClickPreferences() -> void { - - }; + } auto OnClickManageAccounts() -> void { - - }; + } auto OnClickAbout() -> void {}; }; diff --git a/src/application_impl.cpp b/src/application_impl.cpp new file mode 100644 index 0000000..0d8cf16 --- /dev/null +++ b/src/application_impl.cpp @@ -0,0 +1,16 @@ +module larra.application; +import larra.main_window; + +namespace larra { + +auto Application::on_activate() -> void { + auto win = new MainWindow{*this}; // NOLINT + this->add_window(*win); + win->signal_hide().connect([win] { + delete win; // NOLINT + }); + win->set_show_menubar(); + win->set_visible(true); +} + +} // namespace larra diff --git a/lib/src/library.cpp b/src/lib/library.cpp similarity index 100% rename from lib/src/library.cpp rename to src/lib/library.cpp diff --git a/src/main_window.cpp b/src/main_window.cpp index b194dac..546b289 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -1,19 +1,21 @@ module; #include export module larra.main_window; +import larra.application; namespace larra { export struct MainWindow : Gtk::ApplicationWindow { Gtk::Box main; - - Gtk::Box leftPanel{Gtk::Orientation::VERTICAL}; - Gtk::Box accounts{Gtk::Orientation::VERTICAL}; - - MainWindow() { + Application& app; + MainWindow(Application& app) : app(app) { this->set_title("Larra"); - auto settings = Gtk::Settings::get_default(); - this->main.append(this->leftPanel); + Gtk::Box leftPanel{Gtk::Orientation::VERTICAL}; + leftPanel.set_halign(Gtk::Align::START); + leftPanel.set_expand(true); + Gtk::Box accounts{Gtk::Orientation::VERTICAL}; + leftPanel.append(accounts); + this->main.append(leftPanel); this->set_child(this->main); } };