-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
138 lines (114 loc) · 4.31 KB
/
Main.cpp
File metadata and controls
138 lines (114 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include <QtGlobal>
#include <QDebug>
#include "src/core/BaseRequest.h"
#include "src/core/BaseResponse.h"
#include "src/core/AppSettings.h"
#include "src/translation/TranslationManager.h"
#include "src/controller/MainController.h"
#include "src/model/FileListModel.h"
#include "src/util/SimpleLog.h"
// catch qml message function
static void qtMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QString level;
switch (type)
{
case QtDebugMsg:
level = "DEBUG";
break;
case QtInfoMsg:
level = "INFO";
break;
case QtWarningMsg:
level = "WARN";
break;
case QtCriticalMsg:
level = "ERROR";
break;
case QtFatalMsg:
level = "FATAL";
break;
}
QString line =
QString("[%1] [%2] %3").arg(QDateTime::currentDateTime().toString("HH:mm:ss.zzz")).arg(level).arg(msg);
SimpleLog::write("{}", line);
}
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
// Initialize qInstallMessageHandler
#ifdef QT_DEBUG
qInstallMessageHandler(qtMessageHandler);
#endif
// Set application metadata
app.setOrganizationName("EFileOps");
app.setOrganizationDomain("efileops.org");
app.setApplicationName("EFileOps");
app.setApplicationVersion("1.0.3");
// Set Qt UI style
QQuickStyle::setStyle("Basic");
// Initialize application settings (singleton)
AppSettings::instance();
// Register common data types to QML (shared across all modules)
qRegisterMetaType<BaseRequest>("BaseRequest");
qRegisterMetaType<BaseResponse>("BaseResponse");
// Register C++ types to QML
qmlRegisterType<MainController>("EFileOps", 1, 0, "MainController");
qmlRegisterType<FileListModel>("EFileOps", 1, 0, "FileListModel");
// Create QML engine
QQmlApplicationEngine engine;
// Create and register translation manager instance
TranslationManager translation_manager;
engine.rootContext()->setContextProperty("translationManager", &translation_manager);
QObject::connect(&translation_manager, &TranslationManager::languageChanged, [&engine]() { engine.retranslate(); });
// Create and register main controller instance
MainController main_controller;
engine.rootContext()->setContextProperty("mainController", &main_controller);
// Create and register file list model
FileListModel file_list_model(main_controller.fileService());
engine.rootContext()->setContextProperty("fileListModel", &file_list_model);
// Set file list model reference to main controller (for auto-selection after adding files)
main_controller.setFileListModel(&file_list_model);
// Auto-restore session if enabled
if (AppSettings::instance()->autoRestoreSession())
{
SimpleLog::write("[Main] Auto-restore enabled, loading previous session...");
main_controller.loadSession();
}
// Connect app aboutToQuit signal to save session
QObject::connect(&app, &QGuiApplication::aboutToQuit,
[&main_controller]()
{
SimpleLog::write("[Main] Application closing, saving session...");
main_controller.autoSaveSession();
});
// Add import path for EUI components (loaded at runtime from qml/EUI/)
QString qml_path = QCoreApplication::applicationDirPath() + "/qml";
engine.addImportPath(qml_path);
// Load main QML file
const QUrl main_qml_url(u"qrc:/EFileOps/qml/Main.qml"_qs);
// Connect loading failure signal
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &app,
[main_qml_url](QObject *obj, const QUrl &obj_url)
{
if (!obj && main_qml_url == obj_url)
{
SimpleLog::write("[Main] Failed to load main QML file, exiting application.");
QCoreApplication::exit(-1);
}
},
Qt::QueuedConnection);
engine.load(main_qml_url);
// Check if loading was successful
if (engine.rootObjects().isEmpty())
{
SimpleLog::write("[Main] No root objects found after loading QML, exiting application.");
return -1;
}
return app.exec();
}