fix start/stop/pause
[Sak.git] / main.cpp
blob478b7b150c2479cbb882c646dd0c92c75c1bd788
1 #include <QtGui>
2 #include <signal.h>
3 #include "sak.h"
5 void sighandler(int signum) {
6 static bool quitting = false;
7 qDebug() << "SAK: caught signal " << signum;
8 signal(signum, SIG_IGN);
9 if (!quitting) {
10 quitting = true;
11 qApp->quit();
16 class MySplashScreen : public QSplashScreen
18 public:
19 MySplashScreen(const QPixmap & px) : QSplashScreen(px) {}
20 protected:
21 void timerEvent(QTimerEvent*) { hide(); deleteLater(); }
25 int main(int argc, char** argv)
27 QApplication app (argc, argv);
29 #ifdef Q_OS_LINUX
30 app.setGraphicsSystem("raster");
31 #endif
33 if (!QSystemTrayIcon::isSystemTrayAvailable()) {
34 QMessageBox::critical(0, QObject::tr("Systray"),
35 QObject::tr("I couldn't detect any system tray "
36 "on this system."));
37 return 1;
40 signal(SIGINT, sighandler);
41 #ifdef Q_OS_LINUX
42 signal(SIGQUIT, sighandler);
43 #endif
44 signal(SIGILL, sighandler);
45 signal(SIGABRT, sighandler);
46 signal(SIGFPE, sighandler);
47 signal(SIGSEGV, sighandler);
48 signal(SIGTERM, sighandler);
50 QFile lockFile(QDir::homePath() + QDir::separator() + ".sak.run");
51 if (lockFile.exists()) {
52 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)
53 return -1;
54 else {
55 QFile::remove(lockFile.fileName());
58 lockFile.open(QIODevice::ReadWrite);
60 #ifdef CENSORED
61 QPixmap px(":/images/active.png");
62 #else
63 QPixmap px(":/images/splash.png");
64 #endif
65 MySplashScreen* splash = new MySplashScreen(px);
66 splash->setMask(px.createMaskFromColor(QColor(0,0,0,0), Qt::MaskInColor));
67 splash->show();
68 splash->startTimer(2000);
69 app.processEvents();
70 Sak sak;
71 bool rc = app.exec();
73 lockFile.close();
74 QFile::remove(lockFile.fileName());
75 return rc;