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