]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/app.cpp
Preliminary support for passing in filenames from the command line.
[virtualjaguar] / src / gui / app.cpp
1 //
2 // app.cpp - Qt-based GUI for Virtual Jaguar
3 //
4 // by James Hammons
5 // (C) 2010 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  12/23/2009  Created this file
12 // JLH  01/21/2011  Added SDL initialization
13 // JLH  06/26/2011  Added fix to keep SDL from hijacking main() on win32
14 //
15
16 #include "app.h"
17
18 #include <SDL.h>
19 #include <QApplication>
20 #include "log.h"
21 #include "mainwin.h"
22 #include "settings.h"
23 #include "types.h"
24
25 #ifdef __GCCWIN32__
26 // Apparently on win32, SDL is hijacking main from Qt. So let's do this:
27 #undef main
28 #endif
29
30 //hm. :-/
31 // This is stuff we pass into the mainWindow...
32 bool noUntunedTankPlease = false;
33 bool loadAndGo = false;
34 QString filename;
35
36 // Here's the main application loop--short and simple...
37 int main(int argc, char * argv[])
38 {
39         // Normally, this would be read in from the settings module... :-P
40         vjs.hardwareTypeAlpine = false;
41         // This is stuff we pass into the mainWindow...
42 //      noUntunedTankPlease = false;
43
44         if (argc > 1)
45         {
46                 if ((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0)
47                         || (strcmp(argv[1], "-?") == 0))
48                 {
49                         printf("Virtual Jaguar 2.0.0 help\n");
50                         printf("\n");
51                         printf("Command line interface is mostly non-functional ATM, but may return if\n"
52                                 "there is enough demand for it. :-)\n");
53                         return 0;
54                 }
55
56                 if (strcmp(argv[1], "--yarrr") == 0)
57                 {
58                         printf("\n");
59                         printf("Shiver me timbers!\n");
60                         printf("\n");
61                         return 0;
62                 }
63
64                 if ((strcmp(argv[1], "--alpine") == 0) || (strcmp(argv[1], "-a") == 0))
65                 {
66                         printf("Alpine Mode enabled.\n");
67                         vjs.hardwareTypeAlpine = true;
68                 }
69
70                 if (strcmp(argv[1], "--please-dont-kill-my-computer") == 0)
71                 {
72                         noUntunedTankPlease = true;
73                 }
74
75                 // Check for filename
76                 if (argv[1][0] != '-')
77                 {
78                         loadAndGo = true;
79                         filename = argv[1];
80                 }
81         }
82
83         Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
84 //or is it the .qrc filename???
85         // This is so we can pass this stuff using signal/slot mechanism...
86 //ick   int id = qRegisterMetaType<uint32>();
87
88         bool success = (bool)LogInit("virtualjaguar.log");      // Init logfile
89         int retVal = -1;                                                        // Default is failure
90
91         if (!success)
92                 printf("Failed to open virtualjaguar.log for writing!\n");
93
94         // Set up SDL library
95         if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
96         {
97                 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
98         }
99         else
100         {
101                 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
102                 App app(argc, argv);                                    // Declare an instance of the application
103                 retVal = app.exec();                                    // And run it!
104
105                 // Free SDL components last...!
106                 SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
107                 SDL_Quit();
108         }
109
110         LogDone();                                                                      // Close logfile
111         return retVal;
112 }
113
114 // Main app constructor--we stick globally accessible stuff here...
115
116 App::App(int argc, char * argv[]): QApplication(argc, argv)
117 {
118         mainWindow = new MainWin(filename);
119         mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
120         mainWindow->show();
121 }