Implementation of a dBus management class for the GUI

This commit is contained in:
Sylvain Schneider
2026-03-12 18:57:35 +01:00
parent e64921702b
commit 16787ac642
4 changed files with 376 additions and 17 deletions

View File

@@ -4,7 +4,10 @@
#include "bars/statusBar.h"
#include "bars/toolBar.h"
#include <filesystem>
/* --- */
#include "api/project.h"
#include "api/requirement.h"
/* --- */
@@ -14,6 +17,7 @@ using namespace gui;
/* Constructor */
MainFrame::MainFrame(dBus::Bus &bus)
: wxFrame(nullptr, wxID_ANY, _("kwa.Fr"), wxDefaultPosition, wxDefaultSize)
, dBus::wxNode(this, bus)
, m_bus(bus)
{
// Initialization
@@ -27,9 +31,11 @@ MainFrame::MainFrame(dBus::Bus &bus)
createControls();
// Post-initialization
m_menuBar->Bind(wxEVT_MENU, &MainFrame::on_menubarItemClick, this);
m_menuBar->Bind(wxEVT_MENU, &MainFrame::on_menuBarItemClick, this);
CenterOnScreen();
subscribe(dBus::makeID("log.message"));
}
//--------------------------------------------------------------
/* Creating controls */
@@ -56,7 +62,7 @@ void MainFrame::createProject()
{
try
{
const auto ret = postFileOperationRequest(m_bus, api::requirement::FileOperation::Create);
const auto ret = api::project::postProjectOperationRequest(m_bus, api::project::OperationType::Create);
if (!ret)
{
wxMessageBox("No manager found for project creation request.\n\n"
@@ -80,30 +86,134 @@ void MainFrame::createProject()
/* Open an existing project */
void MainFrame::openProject()
{
try
{
wxFileDialog dlg(this,
_("Open Project"),
wxEmptyString,
wxEmptyString,
"Project Files (*.kwaProj)|*.kwaProj|All Files (*.*)|*.*",
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dlg.ShowModal() != wxID_OK)
return;
const auto filepath = filesystem::path(dlg.GetPath().ToStdString());
const auto ret = api::project::postProjectOperationRequest(m_bus, api::project::OperationType::Open, filepath);
if (!ret)
{
wxMessageBox("No manager found for project opening request.\n\n"
"The manager responsible for handling project opening "
"did not respond to the request. Please ensure that "
"the project management component is running and try again.",
"Failed...",
wxOK | wxICON_WARNING,
this);
}
}
catch (const std::exception &e)
{
wxMessageBox("An unexpected error occurred while opening a project\n\n" + wxString(e.what()),
"Critical Error",
wxOK | wxICON_ERROR,
this);
}
}
//--------------------------------------------------------------
/* Save the current project */
void MainFrame::saveProject()
{
try
{
const auto ret = api::project::postProjectOperationRequest(m_bus, api::project::OperationType::Save);
if (!ret)
{
wxMessageBox("No manager found for project saving request.\n\n"
"The manager responsible for handling project saving "
"did not respond to the request. Please ensure that "
"the project management component is running and try again.",
"Failed...",
wxOK | wxICON_WARNING,
this);
}
}
catch (const std::exception &e)
{
wxMessageBox("An unexpected error occurred while saving the project\n\n" + wxString(e.what()),
"Critical Error",
wxOK | wxICON_ERROR,
this);
}
}
//--------------------------------------------------------------
/* Save the current project as... */
void MainFrame::saveProjectAs()
{
try
{
wxFileDialog dlg(this,
_("Save Project"),
wxEmptyString,
wxEmptyString,
"Project Files (*.kwaProj)|*.kwaProj|All Files (*.*)|*.*",
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (dlg.ShowModal() != wxID_OK)
return;
const auto filepath = filesystem::path(dlg.GetPath().ToStdString());
const auto ret = api::project::postProjectOperationRequest(m_bus, api::project::OperationType::SaveAs, filepath);
if (!ret)
{
wxMessageBox("No manager found for project saving request.\n\n"
"The manager responsible for handling project saving "
"did not respond to the request. Please ensure that "
"the project management component is running and try again.",
"Failed...",
wxOK | wxICON_WARNING,
this);
}
}
catch (const std::exception &e)
{
wxMessageBox("An unexpected error occurred while saving the project\n\n" + wxString(e.what()),
"Critical Error",
wxOK | wxICON_ERROR,
this);
}
}
//--------------------------------------------------------------
/* Close the current project */
void MainFrame::closeProject() const
void MainFrame::closeProject()
{
try
{
const auto ret = api::project::postProjectOperationRequest(m_bus, api::project::OperationType::Close);
if (!ret)
{
wxMessageBox("No manager found for project closing request.\n\n"
"The manager responsible for handling project closing "
"did not respond to the request. Please ensure that "
"the project management component is running and try again.",
"Failed...",
wxOK | wxICON_WARNING,
this);
}
}
catch (const std::exception &e)
{
wxMessageBox("An unexpected error occurred while closing the project\n\n" + wxString(e.what()),
"Critical Error",
wxOK | wxICON_ERROR,
this);
}
}
//--------------------------------------------------------------
/* Menu bar item click event */
void MainFrame::on_menubarItemClick(wxCommandEvent &event)
void MainFrame::on_menuBarItemClick(wxCommandEvent &event)
{
switch (static_cast<MenuBar::IDs>(event.GetId()))
{
using enum MenuBar::IDs;
// File menu
// File menu
case ID_MENU_FILE_NEW:
{
createProject();
@@ -135,17 +245,22 @@ void MainFrame::on_menubarItemClick(wxCommandEvent &event)
break;
}
// Requirement menu
// Requirement menu
case ID_MENU_REQ_CREATE:
{
break;
}
// Help menu
// Help menu
default:
{
}
}
}
//--------------------------------------------------------------
/* dBus message reception handler */
void MainFrame::on_receiveMessageFromBus(const MessageID messageID, const MessagePtr message)
{
cout << "From MainFrame::on_receiveMessageFromBus: " << message->toString() << endl;
}
//--------------------------------------------------------------