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