main.cpp
author insilmaril
Wed, 02 May 2007 15:31:17 +0000
changeset 483 01a0e82280f9
parent 473 8b9cfc26638c
child 486 9c86935835a4
permissions -rw-r--r--
Mainly documentation fixes
     1 #include <QApplication>
     2 
     3 #include "flagrowobj.h"
     4 #include "mainwindow.h"
     5 #include "options.h"
     6 #include "settings.h"
     7 #include "version.h"
     8 
     9 // Global variables
    10 TextEditor *textEditor;			// used in Constr. of LinkableMapObj
    11 								// initialized in mainwindow
    12 QString vymName;
    13 QString vymVersion;
    14 QString vymBuildDate;
    15 QString vymCodeName;
    16 
    17 Main *mainWindow;				// used in BranchObj::select()								
    18 QString tmpVymDir;				// All temp files go there, created in mainwindow
    19 QString clipboardDir;			// Clipboard used in all mapEditors
    20 QDir vymBaseDir;				// Containing all styles, scripts, images, ...
    21 QDir lastImageDir;
    22 QDir lastFileDir;
    23 QString iconPath;				// Pointing to icons used for toolbars
    24 QString flagsPath;				// Pointing to flags
    25 bool clipboardEmpty;			
    26 bool debug;						// global debugging flag
    27 FlagRowObj *systemFlagsDefault;	// used to copy from in LinkableMapObj
    28 FlagRowObj *standardFlagsDefault;
    29 
    30 
    31 Settings settings ("InSilmaril","vym"); // Organization, Application name
    32 
    33 Options options;
    34 ImageIO imageIO;
    35 
    36 int statusbarTime=3500;
    37 
    38 int main(int argc, char* argv[])
    39 {
    40 	//Q_INIT_RESOURCE (application);
    41 
    42     QApplication app(argc,argv);
    43 
    44 	vymName=__VYM_NAME;
    45 	vymVersion=__VYM_VERSION;
    46 	vymBuildDate=__VYM_BUILD_DATE;
    47 	vymCodeName=__VYM_CODENAME;
    48 
    49 
    50 	// Reading and initializing options commandline options
    51 	options.add ("debug", Option::Switch, "d", "debug");
    52 	options.add ("version", Option::Switch, "v","version");
    53 	options.add ("local", Option::Switch, "l", "local");
    54 	options.add ("help", Option::Switch, "h", "help");
    55 	options.add ("quit", Option::Switch, "q", "quit");
    56 	options.add ("run", Option::String, "r", "run");
    57 	options.add ("test", Option::String, "t", "test");
    58 	options.setHelpText (
    59 		"VYM - View Your Mind\n"
    60 		"--------------------\n\n"
    61 		"Information about vym can be found in vym.pdf,\n"
    62 		"which should be part of the vym package.\n"
    63 		"It is also available at the project homepage:\n\n"
    64 		"http://www.InSilmaril.de/vym\n");
    65 	if (options.parse())
    66 	{
    67 		cout << endl << options.getHelpText().ascii()<<endl;
    68 		return 1;
    69 	}
    70 
    71 	debug=options.isOn ("debug");
    72 
    73 	if (options.isOn ("version"))
    74 	{
    75 		cout << "vym version "<<__VYM_VERSION 
    76 			<<"  (c) 2004-2007 Uwe Drechsel - "
    77 			<<__VYM_BUILD_DATE 
    78 			<<"  "<<__VYM_CODENAME<<endl;
    79 			
    80 		return 0;	
    81 	}		
    82 	
    83 	// Use /usr/share/vym or /usr/local/share/vym or . ?
    84 	// First try options
    85 	if (options.isOn ("local"))
    86 	{
    87 		vymBaseDir.setPath (vymBaseDir.currentDirPath());
    88 	} else
    89 	// then look for environment variable
    90 	if (getenv("VYMHOME")!=0)
    91 	{
    92 		vymBaseDir.setPath (getenv("VYMHOME"));
    93 	} else
    94 	// ok, let's find my way on my own
    95 	{
    96 		#if defined (Q_OS_MACX)
    97 			vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
    98 
    99 		#else
   100 			vymBaseDir.setPath ("/usr/share/vym");
   101 			if (!vymBaseDir.exists())
   102 			{
   103 				vymBaseDir.setPath ("/usr/local/share/vym");
   104 				if (!vymBaseDir.exists())
   105 					vymBaseDir.setPath(vymBaseDir.currentDirPath() );
   106 			}		
   107 		#endif
   108 	}
   109 
   110 	iconPath=vymBaseDir.path()+"/icons/";
   111 	flagsPath=vymBaseDir.path()+"/flags/";
   112 
   113 	// Some directories
   114 	lastImageDir=QDir().current();
   115 	lastFileDir=QDir().current();
   116 
   117 	if (options.isOn ("help"))
   118 	{
   119 		cout << options.getHelpText().ascii()<<endl;
   120 		return 0;	
   121 	}	
   122 
   123 	// Initialize translations
   124 	QTranslator translator (0);
   125 	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
   126     app.installTranslator( &translator );
   127 
   128 	// Initializing the row of system flags
   129 	// is done in first call to MapEditor(),
   130 	// because we need at least one canvas first
   131 	systemFlagsDefault=NULL;
   132 	standardFlagsDefault=NULL;
   133 
   134 	// Initialize window of TextEditor
   135 	textEditor = new TextEditor();
   136 	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
   137 	if (textEditor->showWithMain()) textEditor->show();
   138 
   139 	// Initialize mainwindow 
   140     Main m;
   141 	//m.resize(m.sizeHint());
   142 	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
   143 	m.show();
   144 	m.fileNew();
   145 	m.loadCmdLine();
   146 
   147 	// Run script
   148 	if (options.isOn ("run"))
   149 	{
   150 		QString script;
   151 		QString fn=options.getArg ("run");
   152 		if ( !fn.isEmpty() )
   153 		{
   154 			QFile f( fn );
   155 			if ( !f.open( QIODevice::ReadOnly ) )
   156 			{
   157 				QMessageBox::warning(0, 
   158 					QObject::tr("Error"),
   159 					QObject::tr("Couldn't open %1.\n").arg(fn));
   160 				return 0;
   161 			}	
   162 
   163 			QTextStream ts( &f );
   164 			script= ts.read();
   165 			f.close();
   166 			m.setScript (script);
   167 			m.runScript (script);
   168 		}
   169 	}		
   170 	
   171 	// For benchmarking we may want to quit instead of entering event loop
   172 	if (options.isOn ("quit"))
   173 	{
   174 		return 0;
   175 	}	
   176 
   177     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   178 
   179     return app.exec();
   180 }
   181