forked from Schedulify-org/Schedulify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
103 lines (80 loc) · 3.43 KB
/
main.cpp
File metadata and controls
103 lines (80 loc) · 3.43 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
#include "model_db_integration.h"
#include <QQmlApplicationEngine>
#include "main_controller.h"
#include "cleanup_manager.h"
#include <QApplication>
#include "db_manager.h"
#include <QQmlContext>
#include "logger.h"
#include <QUrl>
// !!only add to code when need to reset db!!
void forceCleanDatabaseStart() {
Logger::get().logInfo("=== FORCING CLEAN DATABASE START ===");
// Find database file location
QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QString dbPath = QDir(appDataPath).filePath("schedulify.db");
// Delete existing database file
if (QFile::exists(dbPath)) {
if (QFile::remove(dbPath)) {
Logger::get().logInfo("Existing database file deleted: " + dbPath.toStdString());
} else {
Logger::get().logWarning("Failed to delete existing database file");
}
} else {
Logger::get().logInfo("No existing database file found");
}
// Also remove any journal/wal files
QFile::remove(dbPath + "-wal");
QFile::remove(dbPath + "-shm");
QFile::remove(dbPath + "-journal");
Logger::get().logInfo("Database reset complete - will create fresh v1 schema");
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Logger::get().logInitiate();
Logger::get().logInfo("Application started");
try {
auto& dbIntegration = ModelDatabaseIntegration::getInstance();
// insert forceCleanDatabaseStart here when need to reset db
if (!dbIntegration.initializeDatabase()) {
Logger::get().logWarning("Database initialization failed - continuing without persistence");
} else {
Logger::get().logInfo("Database initialized successfully");
auto& db = DatabaseManager::getInstance();
if (db.isConnected() && db.schedules()) {
Logger::get().logInfo("Schedule database ready for use");
} else {
Logger::get().logError("Schedule database not properly initialized");
}
}
} catch (const std::exception& e) {
Logger::get().logWarning("Database initialization exception: " + std::string(e.what()));
}
// Create the QQmlApplicationEngine
QQmlApplicationEngine engine;
// Create the ButtonController instance and pass the engine
MainController controller(&engine);
// Set the static reference to the main controller for all ControllerManager instances
ControllerManager::setMainController(&controller);
// Register the ButtonController with QML
engine.rootContext()->setContextProperty("controller", &controller);
engine.rootContext()->setContextProperty("Logger", &Logger::get());
// Load the QML file from resources
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
// Check for errors
if (engine.rootObjects().isEmpty()) {
Logger::get().logError("Error loading main qml (view) file");
return -1;
}
// Setup cleanup on application exit - use aboutToQuit for earlier cleanup
QObject::connect(&app, &QApplication::aboutToQuit, []() {
Logger::get().logInfo("Application about to quit - starting cleanup");
CleanupManager::performCleanup();
// Process any remaining events to ensure cleanup completes
QCoreApplication::processEvents();
Logger::get().logInfo("Cleanup signal processing completed");
});
int result = QApplication::exec();
return result;
}