create an options structure to indicate if we need a gui
[mussa.git] / qui / mussagl.cpp
index d7b685cac1738776f0231dfd2b43ce2e8821cc5d..bc6260f42813ac2df668728bad966642d2548768 100644 (file)
@@ -1,31 +1,35 @@
 #include <boost/filesystem/operations.hpp>
 using namespace boost::filesystem;
 
+#include <stdlib.h>
 #include <QApplication>
 
 #include "qui/MussaWindow.hpp"
 #include "alg/parse_options.hpp"
 
-int startgui(Mussa *analysis, int argc, char **argv)
+int main(int argc, char **argv)
 {
-  QApplication app(argc, argv);
-  Q_INIT_RESOURCE(icons);
-  MussaWindow win(analysis);
-  win.show();
-  app.exec();
+  MussaOptions opts;
 
-  return 0;
-}
+  // if we're under unix and don't have a display, see if we can still run
+#ifdef Q_WS_X11
+  opts.useGUI = getenv("DISPLAY") != 0;
+#endif
 
-int main(int argc, char **argv)
-{
-  // let boost::filesystem store the path we were initially launched in
-  initial_path();
+  QApplication app(argc, argv, opts.useGUI);
+  Q_INIT_RESOURCE(icons);
+
+  initialize_mussa(opts, argc, argv);
 
-  Mussa *analysis = initialize_mussa(argc, argv);
-  if (analysis == 0) {
+  if (opts.analysis == 0) {
     return 1;
   }
 
-  return startgui(analysis, argc, argv);
+  if (opts.useGUI) { 
+    MussaWindow win(opts.analysis);
+    win.show();
+    app.exec();
+  }
+
+  return 0;
 }