FOSSredder 0.5.0
Loading...
Searching...
No Matches
MainWindowContext.cpp
Go to the documentation of this file.
1
6
8
9#include <QAction>
10#include <QApplication>
11#include <QCoreApplication>
12#include <QQmlEngine>
13
14#include "MainWindow.h"
15#include "ui/i18n/Text.h"
20#include "ui/shell/AppActions.h"
21#include "ui/shell/Navigation.h"
22#include "ui/shell/Settings.h"
23#include "ui/shell/Status.h"
29
30namespace ui::window {
31
33 QObject* parent) {
34 MainWindowServices services;
35 services.actions = new ui::Actions(parent);
36 services.navigation = new ui::Navigation(parent);
37 services.workspaceStore = new ui::WorkspaceStore(parent);
38 services.workspaceSelectors =
39 new ui::WorkspaceSelectors(*services.workspaceStore, parent);
41 *services.workspaceStore, *services.workspaceSelectors, parent);
42 services.workspaceCommands =
43 new ui::WorkspaceCommands(*services.workspaceStore, parent);
44 services.fileSystemBrowser = new ui::FileSystemBrowser(parent);
45 auto* application = qobject_cast<QApplication*>(QCoreApplication::instance());
46 services.languageService =
47 new ui::LanguageService(application, qmlEngine, parent);
48 services.settings = new ui::Settings(parent);
49 services.status = new ui::Status(parent);
51
52 return services;
53}
54
56 MainWindow& window, const MainWindowServices& services,
57 const std::shared_ptr<core::ports::diagnostics::IErrorReporter>&
58 errorReporter,
59 const std::function<void()>& showAbout) {
60 if (!services.actions)
61 return;
62
63 auto* actions = services.actions;
64 QObject::connect(
65 actions->newFileAction(), &QAction::triggered, &window,
66 [&window, errorReporter](bool) {
67 const QString file = ui::dialogs::pickNewStorageFile(&window);
68 if (file.isEmpty())
69 return;
70 ui::window::reportMainWindowFlow(
71 errorReporter.get(),
72 ui::observability::origins::mainWindow::kActionRouting,
73 "UI requested new file", core::errors::ErrorSeverity::Info,
74 ui::window::makePathContext(file));
75 emit window.newFileRequested(file);
76 });
77 QObject::connect(
78 actions->openFileAction(), &QAction::triggered, &window,
79 [&window, workspaceStore = services.workspaceStore, errorReporter](bool) {
80 const QString file = ui::dialogs::pickOpenStorageFile(
81 &window,
82 workspaceStore ? workspaceStore->currentPath() : QString());
83 if (file.isEmpty())
84 return;
85 ui::window::reportMainWindowFlow(
86 errorReporter.get(),
87 ui::observability::origins::mainWindow::kActionRouting,
88 "UI requested open file", core::errors::ErrorSeverity::Info,
89 ui::window::makePathContext(file));
90 emit window.openFileRequested(file);
91 });
92 QObject::connect(actions->saveFileAction(), &QAction::triggered, &window,
93 [&window, errorReporter](bool) {
94 ui::window::reportMainWindowFlow(
95 errorReporter.get(),
96 ui::observability::origins::mainWindow::kActionRouting,
97 "UI requested save file");
98 emit window.saveFileRequested();
99 });
100 QObject::connect(
101 actions->saveFileAsAction(), &QAction::triggered, &window,
102 [&window, workspaceStore = services.workspaceStore, errorReporter](bool) {
103 const QString file = ui::dialogs::pickSaveStorageFileAs(
104 &window,
105 workspaceStore ? workspaceStore->currentPath() : QString());
106 if (file.isEmpty())
107 return;
108 ui::window::reportMainWindowFlow(
109 errorReporter.get(),
110 ui::observability::origins::mainWindow::kActionRouting,
111 "UI requested save file as", core::errors::ErrorSeverity::Info,
112 ui::window::makePathContext(file));
113 emit window.saveFileAsRequested(file);
114 });
115
116 QObject::connect(actions->quitAction(), &QAction::triggered, &window,
117 &QWidget::close);
118 QObject::connect(actions->aboutAction(), &QAction::triggered, &window,
119 [showAbout]() {
120 if (showAbout)
121 showAbout();
122 });
123
124 QObject::connect(
126 [&window, actions, status = services.status, settings = services.settings,
127 errorReporter](const QString& filter) {
128 const QStringList files = ui::dialogs::pickImportFiles(
129 &window, filter,
130 settings ? settings->importDefaultPath() : QString());
131 if (!files.isEmpty()) {
132 ui::window::reportMainWindowFlow(
133 errorReporter.get(),
134 ui::observability::origins::mainWindow::kActionRouting,
135 "UI selected import files", core::errors::ErrorSeverity::Info,
136 ui::window::makeFileListContext(files));
137 emit actions->importFilesSelected(files);
138 if (files.size() == 1)
139 emit actions->importFileSelected(files.first());
140 if (status)
141 status->setText(ui::text::mainWindow::selectedStatusPattern().arg(
142 files.front()));
143 }
144 });
145
146 QObject::connect(
148 [&window, actions, status = services.status, settings = services.settings,
149 errorReporter](const QString& filter) {
150 const QString file = ui::dialogs::pickExportFile(
151 &window, filter,
152 settings ? settings->exportDefaultDirectory() : QString());
153 if (!file.isEmpty()) {
154 ui::window::reportMainWindowFlow(
155 errorReporter.get(),
156 ui::observability::origins::mainWindow::kActionRouting,
157 "UI selected export path", core::errors::ErrorSeverity::Info,
158 ui::window::makePathContext(file));
159 emit actions->exportFileSelected(file);
160 if (status)
161 status->setText(
162 ui::text::mainWindow::exportPathStatusPattern().arg(file));
163 }
164 });
165
166 QObject::connect(
168 [&window, actions, status = services.status, settings = services.settings,
169 errorReporter](const QString& title) {
170 const QString directory = ui::dialogs::pickExportDirectory(
171 &window, title,
172 settings ? settings->exportDefaultDirectory() : QString());
173 if (!directory.isEmpty()) {
174 ui::window::reportMainWindowFlow(
175 errorReporter.get(),
176 ui::observability::origins::mainWindow::kActionRouting,
177 "UI selected export directory", core::errors::ErrorSeverity::Info,
178 ui::window::makePathContext(directory));
179 emit actions->exportDirectorySelected(directory);
180 if (status)
181 status->setText(
182 ui::text::mainWindow::exportPathStatusPattern().arg(directory));
183 }
184 });
185}
186
187} // namespace ui::window
Declares QAction wrappers exposed to the UI layer and QML.
Declares shared native file dialog helpers used by the desktop UI.
Declares the UI helper that exposes a minimal filesystem view to QML.
Declares the UI service responsible for runtime language switching.
Main window declaration for the UI application.
Declarations for the UI MainWindowContext component.
Declarations for the UI MainWindowTrace component.
Declarations for the UI Navigation component.
Declarations for the UI Origins component.
Declares the centralized UI settings view model exposed to QML.
Declarations for the UI Status component.
Provides translated C++ UI strings for shell, workflow, adapter and view model code.
Declares the workspace selection state synchronized with the store.
Declares read-only workspace selectors for QML payloads.
Declares the UI workspace snapshot store.
Owns the main window actions and exposes them to QML.
Definition AppActions.h:18
void importBrowseRequested(const QString &filter)
Emitted when QML requests an import file dialog.
void exportBrowseRequested(const QString &filter)
Emitted when QML requests an export file dialog.
void exportDirectoryBrowseRequested(const QString &title)
Emitted when QML requests an export directory dialog.
Exposes directory listing and application-directory lookup to QML.
Manages the active UI language and the available translation options.
Stores the active top-level shell section and settings sub-section.
Definition Navigation.h:15
Stores and exposes globally persisted UI settings for settings-related views.
Definition Settings.h:19
Exposes the shell status text shown by the main window.
Definition Status.h:16
void setText(const QString &value)
Updates the current status text.
Definition Status.h:39
Maps UI intent to core workspace writer commands.
Tracks the currently selected workspace entities.
Projects workspace store data into QML-facing read models.
Owns the current UI-side workspace snapshot and revision lifecycle.
QString ready()
Text for the idle application state.
Definition Text.h:41
MainWindowServices installMainWindowContext(QQmlEngine *qmlEngine, QObject *parent)
Creates shell services used by the main window and QML context.
void wireMainWindowActions(MainWindow &window, const MainWindowServices &services, const std::shared_ptr< core::ports::diagnostics::IErrorReporter > &errorReporter, const std::function< void()> &showAbout)
Wires main window actions to dialogs, status text and window signals.
Container for shell services owned by the main window context.
ui::WorkspaceSelection * workspaceSelection
ui::WorkspaceCommands * workspaceCommands
ui::WorkspaceSelectors * workspaceSelectors
ui::LanguageService * languageService
ui::WorkspaceStore * workspaceStore
ui::FileSystemBrowser * fileSystemBrowser
Declares UI-side workspace command submission.