-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
76 lines (65 loc) · 2.07 KB
/
main.cpp
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
#include <QtGui>
#include <signal.h>
#include "sak.h"
void sighandler(int signum) {
static bool quitting = false;
qDebug() << "SAK: caught signal " << signum;
signal(signum, SIG_IGN);
if (!quitting) {
quitting = true;
qApp->quit();
}
}
class MySplashScreen : public QSplashScreen
{
public:
MySplashScreen(const QPixmap & px) : QSplashScreen(px) {}
protected:
void timerEvent(QTimerEvent*) { hide(); deleteLater(); }
};
int main(int argc, char** argv)
{
QApplication app (argc, argv);
#ifdef Q_OS_LINUX
app.setGraphicsSystem("raster");
#endif
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("Systray"),
QObject::tr("I couldn't detect any system tray "
"on this system."));
return 1;
}
signal(SIGINT, sighandler);
#ifdef Q_OS_LINUX
signal(SIGQUIT, sighandler);
#endif
signal(SIGILL, sighandler);
signal(SIGABRT, sighandler);
signal(SIGFPE, sighandler);
signal(SIGSEGV, sighandler);
signal(SIGTERM, sighandler);
QFile lockFile(QDir::homePath() + QDir::separator() + ".sak.run");
if (lockFile.exists()) {
if ( QMessageBox::question(0, "Another instance of SAK is running ", "Another instance of SAK seems to be running right now. Proceeding with this new instance may results in data loss / corruptions. Do you want to proceed?", QMessageBox::Yes | QMessageBox::No , QMessageBox::No) == QMessageBox::No)
return -1;
else {
QFile::remove(lockFile.fileName());
}
}
lockFile.open(QIODevice::ReadWrite);
#ifdef CENSORED
QPixmap px(":/images/active.png");
#else
QPixmap px(":/images/splash.png");
#endif
MySplashScreen* splash = new MySplashScreen(px);
splash->setMask(px.createMaskFromColor(QColor(0,0,0,0), Qt::MaskInColor));
splash->show();
splash->startTimer(2000);
app.processEvents();
Sak sak;
bool rc = app.exec();
lockFile.close();
QFile::remove(lockFile.fileName());
return rc;
}