changeset 61:a2871e6b8b15

drcc: automatic initialization of resources with program start (disabled with option -no-static-initialize) demos: resources fixes. examples: resources fixes.
author SokoL_SD
date Tue, 19 May 2009 10:48:30 +0000
parents fbf7881c8b0f
children 076691124a8b
files demos/interview/main.d examples/mainwindows/dockwidgets/CMakeLists.txt examples/mainwindows/dockwidgets/main.d examples/mainwindows/dockwidgets/mainwindow.d tools/drcc/main.cpp tools/drcc/rcc.cpp tools/drcc/rcc.h
diffstat 7 files changed, 37 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/demos/interview/main.d	Tue May 19 08:55:06 2009 +0000
+++ b/demos/interview/main.d	Tue May 19 10:48:30 2009 +0000
@@ -48,11 +48,6 @@
 import qt.gui.QIcon;
 import qt.gui.QPixmap;
 
-extern(C) int qtd_init_resources_interview();
-static this() {
-    qtd_init_resources_interview();
-}
-
 int main(char[][] args)
 {
     scope app = new QApplication(args);
--- a/examples/mainwindows/dockwidgets/CMakeLists.txt	Tue May 19 08:55:06 2009 +0000
+++ b/examples/mainwindows/dockwidgets/CMakeLists.txt	Tue May 19 10:48:30 2009 +0000
@@ -1,1 +1,1 @@
-build_example(dockwidgets main.d mainwindow.d)
\ No newline at end of file
+build_example(dockwidgets main.d mainwindow.d RESOURCES dockwidgets.qrc)
\ No newline at end of file
--- a/examples/mainwindows/dockwidgets/main.d	Tue May 19 08:55:06 2009 +0000
+++ b/examples/mainwindows/dockwidgets/main.d	Tue May 19 10:48:30 2009 +0000
@@ -42,7 +42,6 @@
 int main(char[][] args)
 {
     scope app = new QApplication(args);
-    //    Q_INIT_RESOURCE(dockwidgets);
     scope mainWin = new MainWindow;
     mainWin.show();
     return app.exec();
--- a/examples/mainwindows/dockwidgets/mainwindow.d	Tue May 19 08:55:06 2009 +0000
+++ b/examples/mainwindows/dockwidgets/mainwindow.d	Tue May 19 10:48:30 2009 +0000
@@ -215,22 +215,22 @@
     private:
         void createActions()
         {
-            newLetterAct = new QAction(new QIcon("images/new.png"), tr("&New Letter"), this);
+            newLetterAct = new QAction(new QIcon(":images/new.png"), tr("&New Letter"), this);
             newLetterAct.setShortcut(tr("Ctrl+N"));
             newLetterAct.setStatusTip(tr("Create a new form letter"));
             newLetterAct.triggered.connect(&this.newLetter);
 
-            saveAct = new QAction(new QIcon("images/save.png"), tr("&Save..."), this);
+            saveAct = new QAction(new QIcon(":images/save.png"), tr("&Save..."), this);
             saveAct.setShortcut(tr("Ctrl+S"));
             saveAct.setStatusTip(tr("Save the current form letter"));
             // saveAct.triggered.connect(&save);
 
-            printAct = new QAction(new QIcon("images/print.png"), tr("&Print..."), this);
+            printAct = new QAction(new QIcon(":images/print.png"), tr("&Print..."), this);
             printAct.setShortcut(tr("Ctrl+P"));
             printAct.setStatusTip(tr("Print the current form letter"));
             // printAct.triggered.connect(&print);
 
-            undoAct = new QAction(new QIcon("images/undo.png"), tr("&Undo"), this);
+            undoAct = new QAction(new QIcon(":images/undo.png"), tr("&Undo"), this);
             undoAct.setShortcut(tr("Ctrl+Z"));
             undoAct.setStatusTip(tr("Undo the last editing action"));
             undoAct.triggered.connect(&undo);
--- a/tools/drcc/main.cpp	Tue May 19 08:55:06 2009 +0000
+++ b/tools/drcc/main.cpp	Tue May 19 10:48:30 2009 +0000
@@ -57,18 +57,19 @@
         fprintf(stderr, "%s: %s\n", qPrintable(argv0), qPrintable(error));
     fprintf(stderr, "Usage: %s  [options] <inputs>\n\n"
         "Options:\n"
-        "  -o file              write output to file rather than stdout\n"
-        "  -name name           create an external initialization function with name\n"
-        "  -threshold level     threshold to consider compressing files\n"
-        "  -compress level      compress input files by level\n"
-        "  -root path           prefix resource access path with root path\n"
-        "  -no-compress         disable all compression\n"
-        "  -binary              output a binary file for use as a dynamic resource\n"
-        "  -namespace           turn off namespace macros\n"
-        "  -project             Output a resource file containing all\n"
-        "                       files from the current directory\n"
-        "  -version             display version\n"
-        "  -help                display this information\n",
+        "  -o file                write output to file rather than stdout\n"
+        "  -name name             create an external initialization function with name\n"
+        "  -threshold level       threshold to consider compressing files\n"
+        "  -compress level        compress input files by level\n"
+        "  -root path             prefix resource access path with root path\n"
+        "  -no-compress           disable all compression\n"
+	"  -no-static-initialize  disable automatic initialization of resources with program start\n"
+        "  -binary                output a binary file for use as a dynamic resource\n"
+        "  -namespace             turn off namespace macros\n"
+        "  -project               Output a resource file containing all\n"
+        "                         files from the current directory\n"
+        "  -version               display version\n"
+        "  -help                  display this information\n",
         qPrintable(argv0));
 }
 
@@ -190,6 +191,8 @@
                 helpRequested = true;
             } else if (opt == QLatin1String("-no-compress")) {
                 library.setCompressLevel(-2);
+            } else if (opt == QLatin1String("-no-static-initialize")) {
+                library.setStaticInitialize(false);
             } else if (opt == QLatin1String("-project")) {
                 projectRequested = true;
             } else {
--- a/tools/drcc/rcc.cpp	Tue May 19 08:55:06 2009 +0000
+++ b/tools/drcc/rcc.cpp	Tue May 19 10:48:30 2009 +0000
@@ -346,7 +346,8 @@
     m_namesOffset(0),
     m_dataOffset(0),
     m_useNameSpace(CONSTANT_USENAMESPACE),
-    m_errorDevice(0)
+    m_errorDevice(0),
+    m_staticInitialize(true)
 {
     m_out.reserve(30 * 1000 * 1000);
 }
@@ -925,6 +926,17 @@
         }
         writeString("    return 1;\n");
         writeString("}\n\n");
+	
+        if(staticInitialize())
+        {
+            writeString("static this() \n{\n    ");
+            writeMangleNamespaceFunction(initResources.toLatin1());
+            writeString("();\n}\n\n");
+
+            writeString("static ~this() \n{\n    ");
+            writeMangleNamespaceFunction(cleanResources.toLatin1());
+            writeString("();\n}\n\n");
+        }
     } else if (m_format == Binary) {
         int i = 4;
         char *p = m_out.data();
--- a/tools/drcc/rcc.h	Tue May 19 08:55:06 2009 +0000
+++ b/tools/drcc/rcc.h	Tue May 19 10:48:30 2009 +0000
@@ -97,6 +97,9 @@
     void setUseNameSpace(bool v) { m_useNameSpace = v; }
     bool useNameSpace() const { return m_useNameSpace; }
     
+    void setStaticInitialize(bool v) { m_staticInitialize = v; }
+    bool staticInitialize() const { return m_staticInitialize; }
+
     QStringList failedResources() const { return m_failedResources; }
 
 private:
@@ -143,6 +146,7 @@
     int m_namesOffset;
     int m_dataOffset;
     bool m_useNameSpace;
+    bool m_staticInitialize;
     QStringList m_failedResources;
     QIODevice *m_errorDevice;
     QByteArray m_out;