-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
88 lines (72 loc) · 2.91 KB
/
main.cpp
File metadata and controls
88 lines (72 loc) · 2.91 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
#include "mainwindow.h"
#include "DatabaseManager.h" // Singleton database connection
#include "DatabaseSchema.h" // Database schema management
#include <QApplication>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QDebug>
#include <QStandardPaths>
#include <QDir>
#include <QDebug>
#include <QSplashScreen>
#include <QThread>
#include <QPixmap>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// Create and show the splash screen
QPixmap pixmap(":/resources/splash_screen_images/splash_image.png"); // image path
// Scale the image to a smaller size (for example, 50% of its original size)
QSize newSize(pixmap.width() / 1.1, pixmap.height() / 1.1); // Resize to 50% of original size
QPixmap scaledPixmap = pixmap.scaled(newSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QSplashScreen *splash = new QSplashScreen(scaledPixmap);
splash->setWindowFlags(Qt::SplashScreen | Qt::WindowStaysOnTopHint);
splash->show();
splash->showMessage("Preparing System...");
//Create a IMS Folder
QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
// Get the parent directory (e.g., AppData/Roaming)
QDir dir(appDataPath);
dir.cdUp(); // Go up from /Roaming/YourAppName to /Roaming
QString imsPath = dir.absolutePath() + "/IMS";
QDir imsDir(imsPath);
if (!imsDir.exists()) {
if (imsDir.mkpath(".")) {
qDebug() << "IMS folder created at:" << imsPath;
} else {
qDebug() << "Failed to create IMS folder!";
}
} else {
qDebug() << "IMS folder already exists at:" << imsPath;
}
splash->showMessage("Preparing Database...");
// Initialize the database connection
DatabaseManager &dbManager = DatabaseManager::instance();
if (!dbManager.getDatabase().isOpen()) {
QMessageBox::critical(nullptr, "Database Error", "Failed to connect to the database!");
splash->close(); // Close splash screen before exiting
return 1; // Exit the application
}
// Initialize database schema (create tables if needed)
DatabaseSchema::initializeDatabase();
// Check if the 'users' table exists (optional validation)
QSqlQuery query;
if (!query.exec("SELECT name FROM sqlite_master WHERE type='table' AND name='users';")) {
qDebug() << "Error checking for table existence:" << query.lastError().text();
splash->close(); // Close splash screen before exiting
return 1;
}
query.next();
if (query.size() == 0) {
qDebug() << "'users' table does not exist!";
splash->close(); // Close splash screen before exiting
return 1;
}
QThread::sleep(2); // Simulate some initialization delay (e.g., 2 seconds)
// Now that everything is ready, close the splash screen
splash->close();
// Show the main window
MainWindow w;
w.show();
return a.exec();
}