start trying to figure out where the documentation is
[mussa.git] / qui / mussagl.cpp
1 #include <boost/filesystem/operations.hpp>
2 using namespace boost::filesystem;
3
4 #include "py/python.hpp"
5 #include "qui/MussaWindow.hpp"
6 #include "alg/parse_options.hpp"
7 #include "mussa_exceptions.hpp"
8
9 #include <stdlib.h>
10 #include <iostream>
11 #include <QApplication>
12
13 #if defined(Q_WS_MAC)
14 #include <CoreFoundation/CoreFoundation.h>
15 #endif 
16
17 std::string get_doc_dir()
18 {
19 #if defined(Q_WS_MAC)
20   CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
21   CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
22                                          kCFURLPOSIXPathStyle);
23   const char *pathPtr = CFStringGetCStringPtr(macPath,
24                                          CFStringGetSystemEncoding());
25   std::string doc_dir(pathPtr);
26   qDebug("Path = %s", pathPtr);
27   CFRelease(pluginRef);
28   CFRelease(macPath);
29 #else
30   return string(".");
31 #endif
32 }
33
34 int main(int argc, char **argv)
35 {
36   MussaOptions opts;
37
38   // if we're under unix and don't have a display, see if we can still run
39 #ifdef Q_WS_X11
40   opts.useGUI = getenv("DISPLAY") != 0;
41   if (opts.useGUI == false) {
42     std::clog << "DISPLAY not set, running in console mode only" << std::endl;
43   }
44 #endif
45   //opts.doc_dir = get_doc_dir();
46
47   QApplication app(argc, argv, opts.useGUI);
48   Q_INIT_RESOURCE(icons);
49
50   initialize_mussa(opts, argc, argv);
51
52   if (opts.analysis == 0) {
53     return 1;
54   }
55
56   try {
57 #ifdef USE_PYTHON
58     if (opts.runAsPythonInterpeter) {
59       get_py().interpreter();
60     } else 
61 #endif /* USE_PYTHON */
62     if (opts.useGUI) { 
63       MussaWindow win(opts.analysis);
64       win.show();
65       app.exec();
66     }
67     return 0;
68   } catch (mussa_error e) {
69     qFatal(e.what());
70   } catch (boost::filesystem::filesystem_error e) {
71     qFatal(e.what());
72   } catch( boost::python::error_already_set ) {
73     PyErr_Print();
74   } catch (std::runtime_error e) {
75     qFatal(e.what());
76   } catch (...) {
77     qFatal("unrecognized exception");
78   }
79   return 1; 
80 }