change main project into DLL
authorKonrad Rosenbaum <konrad@silmor.de>
Sun, 10 Mar 2013 13:50:25 +0000 (14:50 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Sun, 10 Mar 2013 13:50:25 +0000 (14:50 +0100)
14 files changed:
Makefile
mainapp/icon.ico [moved from src/images/icon.ico with 100% similarity]
mainapp/main.cpp [new file with mode: 0644]
mainapp/mainapp.pro [new file with mode: 0644]
pack
src/dialogs/configdialog.cpp
src/dialogs/orderauditdlg.cpp
src/iface/msinterface.cpp
src/libs.pri
src/main.cpp
src/main.h
src/misc/debug.cpp
src/script/jsengine.cpp
src/smoke.pro

index e750ddf..0b03180 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -103,6 +103,7 @@ server: wob
 
 client: wob zip tzone elam
        cd src && $(QMAKE) $(QMAKEFLAGS) && $(MAKE)
+       cd mainapp && $(QMAKE) $(QMAKEFLAGS) && $(MAKE)
 
 zip:
        cd zip && $(QMAKE) $(QMCFG) $(QMAKEFLAGS) && $(MAKE)
similarity index 100%
rename from src/images/icon.ico
rename to mainapp/icon.ico
diff --git a/mainapp/main.cpp b/mainapp/main.cpp
new file mode 100644 (file)
index 0000000..e0642ac
--- /dev/null
@@ -0,0 +1,6 @@
+#include "main.h"
+
+int main(int ac,char**av)
+{
+        return MApplication::main(ac,av);
+}
\ No newline at end of file
diff --git a/mainapp/mainapp.pro b/mainapp/mainapp.pro
new file mode 100644 (file)
index 0000000..19b543d
--- /dev/null
@@ -0,0 +1,41 @@
+#Project File for MagicSmoke
+# (c) Konrad Rosenbaum, 2007-2011
+
+TEMPLATE = app
+TARGET = magicsmoke
+DESTDIR = $$PWD/../bin
+
+#make sure the correct Qt DLLs are used
+CONFIG += qt thread link_prl separate_debug_info
+QT += xml network script scripttools
+QT += widgets printsupport
+
+#add the icon for windoze
+win32-* {
+ #RC-File containing the icon:
+ RC_FILE += win.rc
+}
+
+#compilation output:
+OBJECTS_DIR = .ctmp
+MOC_DIR = .ctmp
+RCC_DIR = .ctmp
+
+#main source files
+SOURCES = main.cpp
+INCLUDEPATH += . ../src
+
+#make sure dependencies are found
+DEPENDPATH += $$INCLUDEPATH
+LIBS += -L$$PWD/../bin -lmagicsmoke
+include (../src/libs.pri)
+
+#security features
+linux-g++* {
+  message("activating ASLR and friends")
+  QMAKE_CFLAGS += -fPIE
+  QMAKE_CXXFLAGS += -fPIE
+  QMAKE_LFLAGS += -pie
+  #make sure we find our libs
+  QMAKE_LFLAGS += -Wl,-rpath,\'\$$ORIGIN\'
+}
diff --git a/pack b/pack
index 01e3256..4ccb7a2 160000 (submodule)
--- a/pack
+++ b/pack
@@ -1 +1 @@
-Subproject commit 01e32564337c5a177110bef33032b5b498375eda
+Subproject commit 4ccb7a2b5d235d5dadf502a82990fb77a467db78
index afecf02..896bad9 100644 (file)
@@ -224,6 +224,7 @@ void MConfigDialog::loadProfile()
        if(!idx.isValid())return;
        oldrow=idx.row();
        QString key=profilemodel->data(idx,Qt::UserRole).toString();
+        const QString&dataDir=MApplication::dataDir();
        QSettings set;
        set.beginGroup("profiles/"+key);
        hostname->setText(set.value("hostname").toString());
@@ -239,7 +240,7 @@ void MConfigDialog::loadProfile()
        proxyuser->setEnabled(useproxy->isChecked());
        proxypass->setEnabled(useproxy->isChecked());
        username->setText(set.value("username").toString());
-       sslexcept=new MSslExceptions(::dataDir+"/profile."+key+"/sslexceptions.xml");
+       sslexcept=new MSslExceptions(dataDir+"/profile."+key+"/sslexceptions.xml");
        sslFillModel();
        abiscript->setChecked(set.value("script/allowbuiltin",true).toBool());
        ausscript->setChecked(set.value("script/allowuser",false).toBool());
@@ -265,7 +266,7 @@ void MConfigDialog::saveProfile()
        set.setValue("proxyuser",proxyuser->text());
        set.setValue("proxypass",proxypass->text());
        set.setValue("username",username->text());
-       QDir(::dataDir).mkdir("profile."+key);
+       QDir(MApplication::dataDir()).mkdir("profile."+key);
        if(sslexcept)sslexcept->savesslexcept();
        set.setValue("script/allowbuiltin",abiscript->isChecked());
        set.setValue("script/allowuser",ausscript->isChecked());
index 88c575f..96a5b55 100644 (file)
@@ -263,7 +263,7 @@ void MOrderAuditDialog::calcPrices()
 
 void MOrderAuditDialog::getProfiles()
 {
-       QFile fd(dataDir+"/orderaudit.xml");
+       QFile fd(MApplication::dataDir()+"/orderaudit.xml");
        if(fd.exists() && fd.open(QIODevice::ReadOnly)){
                qDebug()<<"loading main config"<<fd.fileName();
                if(d->mprofiledoc.setContent(&fd))
index 5df2fc1..6d1e0af 100644 (file)
@@ -147,11 +147,11 @@ QMap<QString,QString> MSInterface::headers(QString s)const
 QString MSInterface::dataDir()const
 {
        QString dd="profile."+profileid;
-       QDir dir(::dataDir);
+       QDir dir(MApplication::dataDir());
        if(!dir.exists(dd))
                if(!dir.mkpath(dd))
                        qDebug("Warning: oh dir! Can't create my data directory!");
-       return ::dataDir+"/"+dd;
+       return MApplication::dataDir()+"/"+dd;
 }
 
 QString MSInterface::settingsGroup()const
index 41b1518..242e829 100644 (file)
@@ -1,19 +1,19 @@
-# Libraries for Magic Smoke by (c) Konrad Rosenbaum, 2007-2010
+# Libraries for Magic Smoke by (c) Konrad Rosenbaum, 2007-2013
 
 # ZIP library
-LIBS += -L../zip -lQtZipHelper
+LIBS += -lQtZipHelper
 INCLUDEPATH += ../zip/include
 
 # PACK library
-LIBS += -L../pack/qtbase -lqwbase
+LIBS += -lqwbase
 INCLUDEPATH += ../pack/qtbase/include
 
 # Time Zone DB library
-LIBS += -L../tzone -lQtTzData
+LIBS += -lQtTzData
 INCLUDEPATH += ../tzone/include
 
 # ELAM library
-LIBS += -L../elam -lelam
+LIBS += -lelam
 INCLUDEPATH += ../elam/include
 
 # Chester DPtr library
index 3798b72..5d87374 100644 (file)
@@ -67,11 +67,11 @@ QString choseLanguage(bool warn)
        return lang;
 }
 
-QString dataDir;
+static QString dataDir;
 
 #include <stdlib.h>
 
-static void initDataDir()
+static inline void initDataDir()
 {
 #ifdef Q_OS_WIN32
        dataDir=getenv("APPDATA");
@@ -224,6 +224,22 @@ void MApplication::help(int idx)
 MApplication::MApplication(int&ac,char**av)
 :QApplication(ac,av)
 {
+        //locate settings
+        setOrganizationName("MagicSmoke");
+        setApplicationName("MagicSmoke2");
+        
+        //set icon
+        setWindowIcon(QIcon(":/icon.png"));
+
+        //install event filter for random generator
+        installEventFilter(ef=new EFilter);
+        
+        //data directory
+        initDataDir();
+        //initialize log file
+        initDebug();
+        //init help menu layout
+        initHelpUrl();
 }
 
 void MApplication::setMyStyle()
@@ -240,12 +256,12 @@ void MApplication::setMyStyle()
        }
 }
 
-static inline void loadTranslation(QTranslator&trans,const QString&lang,const QString&prog)
+static inline void loadTranslation(QTranslator*trans,const QString&lang,const QString&prog)
 {
        QStringList lpath;
        lpath <<QApplication::applicationDirPath() <<QLibraryInfo::location(QLibraryInfo::TranslationsPath);
        for(int i=0;i<lpath.size();i++){
-               bool ok=trans.load(prog+"_"+lang,lpath[i]);
+               bool ok=trans->load(prog+"_"+lang,lpath[i]);
                QString msg=QString("...loading %1_%2 from %3 ...%4")
                         .arg(prog).arg(lang)
                         .arg(lpath[i])
@@ -255,57 +271,61 @@ static inline void loadTranslation(QTranslator&trans,const QString&lang,const QS
        }
 }
 
-int main(int argc,char**argv)
+void MApplication::initLanguage()
+{
+        //try to find appropriate locale
+        QString lang=QSettings().value("lang","--").toString();
+        if(lang=="--"){
+                lang=choseLanguage(false);
+        }
+        qDebug("Loading language %s",lang.toLatin1().data());
+        //load Qt translation
+        loadTranslation(qttrans=new QTranslator(this),lang,"qt");
+        installTranslator(qttrans);
+        //load magicSmoke translation
+        loadTranslation(mstrans=new QTranslator(this),lang,"smoke");
+        installTranslator(mstrans);
+        //defaults
+        if(lang!="--"&&lang!=""){
+                QLocale::setDefault(lang);
+                setenv("LANG",lang.toLatin1().data(),1);
+        }else{
+                setenv("LANG","C",1);
+        }
+}
+
+void MApplication::initialize()
+{
+        setMyStyle();
+        initLanguage();
+        initProfile();
+}
+
+QString MApplication::dataDir()
+{
+        return ::dataDir;
+}
+
+void MApplication::initProfile()
+{
+        //check/generate profile
+        if(!QSettings().childGroups().contains("profiles")){
+                QMessageBox::warning(0,translate("initprofile","Initial Profile Warning"), translate("initprofile","You need a profile to work with Magic Smoke. Please create one now."));
+                MConfigDialog().exec();
+        }
+}
+
+
+
+int MApplication::main(int argc,char**argv)
 {
        //create global app
        MApplication app(argc,argv);
        
-       //locate settings
-       app.setOrganizationName("MagicSmoke");
-       app.setApplicationName("MagicSmoke2");
-       
-       //set icon
-       app.setWindowIcon(QIcon(":/icon.png"));
-       
-       //set styling
-       app.setMyStyle();
-       
-       //install event filter for random generator
-       EFilter ef;
-       app.installEventFilter(&ef);
-       
-       //try to find appropriate locale
-       QString lang=QSettings().value("lang","--").toString();
-       if(lang=="--"){
-               lang=choseLanguage(false);
-       }
-       QLocale::setDefault(QLocale(lang));
-       qDebug("Loading language %s",lang.toLatin1().data());
-       QTranslator qttrans;
-       loadTranslation(qttrans,lang,"qt");
-       app.installTranslator(&qttrans);
-       QTranslator mstrans;
-       loadTranslation(mstrans,lang,"smoke");
-       app.installTranslator(&mstrans);
-       if(lang!="--"&&lang!="")
-               QLocale::setDefault(lang);
-       
-       //try to find data dir
-       initDataDir();
-       
-       //initialize log file
-       initDebug();
-       
-       //init help menu layout
-       initHelpUrl();
-       
-       //check/generate profile
-       if(!QSettings().childGroups().contains("profiles")){
-               QMessageBox::warning(0,app.translate("initprofile","Initial Profile Warning"), app.translate("initprofile","You need a profile to work with Magic Smoke. Please create one now."));
-               MConfigDialog().exec();
-       }
-       
-       //open main window
+       //init
+       app.initialize();
+
+        //open main window
        MLogin mmw;
        mmw.show();
        
index 6b61c0d..b03a1f0 100644 (file)
 /**show a dialog to change the language*/
 QString choseLanguage(bool warn=true);
 
-/**contains the directory that is used for external data storage*/
-extern QString dataDir;
 
 
 #include <QApplication>
 class QMenu;
+class EFilter;
+///Main application object of MagicSmoke
 class MApplication:public QApplication
 {
        Q_OBJECT
        public:
+                ///create MagicSmoke application
                MApplication(int&ac,char**av);
                
-               void setMyStyle();
-               
+                ///return the standard help menu
                static QMenu*helpMenu();
+                
+                ///shortcut: the main function
+                static int main(int,char**);
+                /**contains the directory that is used for external data storage*/
+                static QString dataDir();
        public slots:
-               //help menu
+                ///complete initialization: style, language, data dir
+                void initialize();
+                ///set the configured application style
+                void setMyStyle();
+                ///initialize the localization
+                void initLanguage();
+                ///initialize the profiles
+                void initProfile();
+                
+               ///show about dialog
                void aboutMS();
+                ///show version info
                void versionDlg();
+                ///start a browser with the help page
                void help();
+        private slots:
+                ///jump to a specific help page
                void help(int);
+                
+        private:
+                EFilter *ef;
+                QTranslator*qttrans,*mstrans;
 };
 
+#define mApp (qobject_cast<MApplication*>(qApp))
+
 #endif
index 6d1aa49..f2f92a8 100644 (file)
@@ -39,6 +39,7 @@ void initDebug()
         qDebug()<<"-nolog argument was given, will not create a log file";
     }
        //create new log file
+       const QString&dataDir=MApplication::dataDir();
        QDir(dataDir).mkpath("debuglog");
         mylogFile=new QFile(dataDir+"/debuglog/log-"+QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss.zzz")+".txt");
         //...open it
index 8bacc8e..c482c2b 100644 (file)
@@ -194,7 +194,7 @@ void MScriptEngine::initScriptPath()
        if(set.value("allowbuiltin",true).toBool())
                paths.insert(set.value("priobuiltin",10).toInt(),":/scripts");
        if(set.value("allowuser",false).toBool())
-               paths.insert(set.value("priouser",0).toInt(), set.value("userpath",dataDir+"/userscripts").toString());
+               paths.insert(set.value("priouser",0).toInt(), set.value("userpath",MApplication::dataDir()+"/userscripts").toString());
        bool allowserver=set.value("allowserver",false).toBool();
        QString mydir=req->dataDir()+"/scripts";
        if(allowserver)
index 5607d58..bdf69f3 100644 (file)
@@ -1,14 +1,10 @@
 #Project File for MagicSmoke
-# (c) Konrad Rosenbaum, 2007-2011
+# (c) Konrad Rosenbaum, 2007-2013
 
-TEMPLATE = app
+TEMPLATE = lib
 TARGET = magicsmoke
 DESTDIR = $$PWD/../bin
 
-#build for debug or release?
-#CONFIG += release
-CONFIG += debug
-
 #Localization
 TRANSLATIONS = \
        smoke_de.ts \
@@ -20,12 +16,6 @@ CONFIG += qt thread link_prl separate_debug_info
 QT += xml network script scripttools
 QT += widgets printsupport
 
-#add the icon for windoze
-win32-* {
- #RC-File containing the icon:
- RC_FILE += win.rc
-}
-
 #compilation output:
 OBJECTS_DIR = .ctmp
 MOC_DIR = .ctmp
@@ -58,16 +48,6 @@ include(wob/wob.pri)
 DEPENDPATH += $$INCLUDEPATH
 LIBS += -L$$PWD/../bin
 
-#security features
-linux-g++* {
-  message("activating ASLR and friends")
-  QMAKE_CFLAGS += -fPIE
-  QMAKE_CXXFLAGS += -fPIE
-  QMAKE_LFLAGS += -pie
-  #make sure we find our libs
-  QMAKE_LFLAGS += -Wl,-rpath,\'\$$ORIGIN\'
-}
-
 #activate C++11 for g++
 gcc {
   message("detected GCC, activating C++11 with GNU extensions")