QTfrontend/main.cpp
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8278 9cdfcb5b7ddd
parent 8355 df0ea4323295
--- a/QTfrontend/main.cpp	Tue Dec 18 20:48:37 2012 +0400
+++ b/QTfrontend/main.cpp	Fri Jan 04 21:44:40 2013 +0400
@@ -27,6 +27,8 @@
 #include <QSettings>
 #include <QStringListModel>
 #include <QDate>
+#include <QDesktopWidget>
+#include <QLabel>
 
 #include "hwform.h"
 #include "hwconsts.h"
@@ -39,9 +41,11 @@
 
 #ifdef _WIN32
 #include <Shlobj.h>
+#elif defined __APPLE__
+#include "CocoaInitializer.h"
 #endif
-#ifdef __APPLE__
-#include "CocoaInitializer.h"
+#ifndef _WIN32
+#include <signal.h>
 #endif
 
 
@@ -87,6 +91,12 @@
     else
         season = SEASON_NONE;
 }
+#ifndef _WIN32
+void terminateFrontend(int signal)
+{
+    QCoreApplication::exit(0);
+}
+#endif
 
 bool checkForDir(const QString & dir)
 {
@@ -136,8 +146,25 @@
     atexit(releaseCocoaPool);
 #endif
 
+#ifndef _WIN32
+    signal(SIGINT, &terminateFrontend);
+#endif
+
     HWApplication app(argc, argv);
 
+    QLabel *splash = NULL;
+#if defined Q_WS_WIN
+    QPixmap pixmap(":res/splash.png");
+    splash = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
+    splash->setAttribute(Qt::WA_TranslucentBackground);
+    const QRect deskSize = QApplication::desktop()->screenGeometry(-1);
+    QPoint splashCenter = QPoint( (deskSize.width() - pixmap.width())/2,
+                                  (deskSize.height() - pixmap.height())/2 );
+    splash->move(splashCenter);
+    splash->setPixmap(pixmap);
+    splash->show();
+#endif
+
     FileEngineHandler engine(argv[0]);
 
     flib_init();
@@ -179,9 +206,14 @@
     if(parsedArgs.contains("config-dir"))
     {
         QFileInfo f(parsedArgs["config-dir"]);
-        *cConfigDir = f.absoluteFilePath();
+        cfgdir->setPath(f.absoluteFilePath());
         custom_config = true;
     }
+    else
+    {
+        cfgdir->setPath(QDir::homePath());
+        custom_config = false;
+    }
 
     app.setStyle(new QPlastiqueStyle());
 
@@ -193,14 +225,9 @@
 
     qRegisterMetaType<HWTeam>("HWTeam");
 
-    bindir->cd("bin"); // workaround over NSIS installer
+    bindir->cd(QCoreApplication::applicationDirPath());
 
-    if(cConfigDir->length() == 0)
-        cfgdir->setPath(cfgdir->homePath());
-    else
-        cfgdir->setPath(*cConfigDir);
-
-    if(cConfigDir->length() == 0)
+    if(custom_config == false)
     {
 #ifdef __APPLE__
         checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars");
@@ -241,14 +268,14 @@
 
     datadir->cd(bindir->absolutePath());
     datadir->cd(*cDataDir);
-    if(!datadir->cd("hedgewars/Data"))
+    if(!datadir->cd("Data"))
     {
         QMessageBox missingMsg(QApplication::activeWindow());
         missingMsg.setIcon(QMessageBox::Critical);
         missingMsg.setWindowTitle(QMessageBox::tr("Main - Error"));
         missingMsg.setText(QMessageBox::tr("Failed to open data directory:\n%1\n\n"
                                            "Please check your installation!").
-                                            arg(datadir->absolutePath()+"/hedgewars/Data"));
+                                            arg(datadir->absolutePath()+"/Data"));
         missingMsg.setWindowModality(Qt::WindowModal);
         missingMsg.exec();
         return 1;
@@ -307,6 +334,7 @@
             break;
         default :
             fname = "qt.css";
+            break;
     }
 
     // load external stylesheet if there is any
@@ -321,6 +349,10 @@
 
     app.form = new HWForm(NULL, style);
     app.form->show();
+
+    if(splash)
+        splash->close();
+
     int r = app.exec();
 
     flib_quit();