main.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           main.cpp  -  description
00003                              -------------------
00004     begin                : Tue Jan 13 2004
00005     copyright            : (C) 2004-2006 by Ben Swerts
00006     email                : bswerts@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00020 
00022 
00023 // Qt header files
00024 #include <qapplication.h>
00025 #include <qfont.h>
00026 #include <qstring.h>
00027 #include <qtextcodec.h>
00028 #include <qtranslator.h>
00029 
00030 // CrdView header files
00031 #include "crdfactory.h"
00032 #include "crdview.h"
00033 
00035 static void debugHandler(QtMsgType type, const char* message)
00039 {
00040   switch (type) 
00041   {
00042 #ifndef QT_NO_DEBUG // only print out debug and warning messages in debug builds
00043     case QtDebugMsg:   fprintf(stdout, "%s\n", message);
00044                        break;
00045     case QtWarningMsg: fprintf(stderr, "Warning: %s\n", message);
00046                        break;
00047 #endif
00048     case QtFatalMsg:   fprintf(stderr, "FATAL: %s\n", message);
00049                        fprintf(stderr, "Please note the exact message when reporting this.\n");
00050                        fprintf(stderr, "The application will now shut down.\n");
00051                        abort();
00052     default: break;
00053   }
00054 }
00055 
00057 int main(int argc, char *argv[])
00058 {
00059   // Initialize the Qt application object.
00060   qInstallMsgHandler(debugHandler); // enables to inhibit all debug messages by a single ifdef
00061   QApplication a(argc, argv);
00062 
00066 
00067 
00068   // read the rest of the command line into a QStringList
00069   QStringList argList;
00070   bool extendedFormat = true;
00071   for(int i = 1; i <= argc; i++)
00072   {
00073     QString argument = argv[i];
00074     if(argument.isEmpty())
00075       break;
00076     if(argument.left(1) != "-")
00077       argList += argument;
00078     else if(argument.lower() = "-bnf") // brabo normal format (extended is the default for writing)
00079       extendedFormat = false;
00080   }
00081   // check whether a conversion is needed
00082   if(argList.count() >= 2)
00083   {
00084     QString inputFileName = *(argList.begin());
00085     QString outputFileName = *(++argList.begin());
00086     qDebug("input & out filenames for conversion: |"+inputFileName+"|"+outputFileName+"|");
00087     int result = CrdFactory::convert(inputFileName, outputFileName, extendedFormat);
00088     switch(result)
00089     {
00090       case 1: break;
00091     }
00092     exit(0); // only conversion, no GUI
00093   }
00094 
00095   // check for OpenGL support after any conversion has finished
00096   if (!QGLFormat::hasOpenGL())
00097   {
00098     qWarning("This system has no working OpenGL support. Exiting...");
00099     return -1;
00100   }
00101 
00102 
00103   //QTranslator tor( 0 );
00104   // set the location where your .qm files are in load() below as the last parameter instead of "."
00105   // for development, use "/" to use the english original as
00106   // .qm files are stored in the base project directory.
00107   //tor.load( QString("crdview.") + QTextCodec::locale(), "." );
00108   //a.installTranslator( &tor );
00109 
00110   CrdView* crdview = new CrdView();
00111   a.setMainWidget(crdview);
00112 
00113   // preload coordinates if a filename was given on the command line
00114   if(argList.count() == 1)
00115   {
00116     qDebug("preloading: " + QString(*(argList.begin())));
00117     crdview->readCoordinates(*(argList.begin()));
00118   }
00119 
00120   // Let the show begin!
00121   crdview->show();
00122   return a.exec();
00123 }
00124 

Generated on Fri May 19 14:31:55 2006 for Brabosphere by  doxygen 1.4.6-NO