main.cpp
author insilmaril
Tue, 19 Jun 2007 14:20:29 +0000
changeset 511 7debc44bf95e
parent 491 c58b3973337c
child 514 497fab7d1404
permissions -rw-r--r--
Exports can (partly) be scripted
     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 QString clipboardFile;			// Clipboard used in all mapEditors
    21 QDir vymBaseDir;				// Containing all styles, scripts, images, ...
    22 QDir lastImageDir;
    23 QDir lastFileDir;
    24 QString iconPath;				// Pointing to icons used for toolbars
    25 QString flagsPath;				// Pointing to flags
    26 bool clipboardEmpty;			
    27 bool debug;						// global debugging flag
    28 FlagRowObj *systemFlagsDefault;	// used to copy from in LinkableMapObj
    29 FlagRowObj *standardFlagsDefault;
    30 
    31 
    32 Settings settings ("InSilmaril","vym"); // Organization, Application name
    33 
    34 Options options;
    35 ImageIO imageIO;
    36 
    37 int statusbarTime=3500;
    38 
    39 int main(int argc, char* argv[])
    40 {
    41 	//Q_INIT_RESOURCE (application);
    42 
    43     QApplication app(argc,argv);
    44 
    45 	vymName=__VYM_NAME;
    46 	vymVersion=__VYM_VERSION;
    47 	vymBuildDate=__VYM_BUILD_DATE;
    48 	vymCodeName=__VYM_CODENAME;
    49 
    50 
    51 	// Reading and initializing options commandline options
    52 	options.add ("debug", Option::Switch, "d", "debug");
    53 	options.add ("version", Option::Switch, "v","version");
    54 	options.add ("local", Option::Switch, "l", "local");
    55 	options.add ("help", Option::Switch, "h", "help");
    56 	options.add ("quit", Option::Switch, "q", "quit");
    57 	options.add ("run", Option::String, "r", "run");
    58 	options.add ("test", Option::String, "t", "test");
    59 	options.setHelpText (
    60 		"VYM - View Your Mind\n"
    61 		"--------------------\n\n"
    62 		"Information about vym can be found in vym.pdf,\n"
    63 		"which should be part of the vym package.\n"
    64 		"It is also available at the project homepage:\n\n"
    65 		"http://www.InSilmaril.de/vym\n");
    66 	if (options.parse())
    67 	{
    68 		cout << endl << options.getHelpText().ascii()<<endl;
    69 		return 1;
    70 	}
    71 
    72 	debug=options.isOn ("debug");
    73 
    74 	if (options.isOn ("version"))
    75 	{
    76 		cout << "vym version "<<__VYM_VERSION 
    77 			<<"  (c) 2004-2007 Uwe Drechsel - "
    78 			<<__VYM_BUILD_DATE 
    79 			<<"  "<<__VYM_CODENAME<<endl;
    80 			
    81 		return 0;	
    82 	}		
    83 	
    84 	// Use /usr/share/vym or /usr/local/share/vym or . ?
    85 	// First try options
    86 	if (options.isOn ("local"))
    87 	{
    88 		vymBaseDir.setPath (vymBaseDir.currentDirPath());
    89 	} else
    90 	// then look for environment variable
    91 	if (getenv("VYMHOME")!=0)
    92 	{
    93 		vymBaseDir.setPath (getenv("VYMHOME"));
    94 	} else
    95 	// ok, let's find my way on my own
    96 	{
    97 		#if defined (Q_OS_MACX)
    98 			vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
    99 
   100 		#else
   101 			vymBaseDir.setPath ("/usr/share/vym");
   102 			if (!vymBaseDir.exists())
   103 			{
   104 				vymBaseDir.setPath ("/usr/local/share/vym");
   105 				if (!vymBaseDir.exists())
   106 					vymBaseDir.setPath(vymBaseDir.currentDirPath() );
   107 			}		
   108 		#endif
   109 	}
   110 
   111 	iconPath=vymBaseDir.path()+"/icons/";
   112 	flagsPath=vymBaseDir.path()+"/flags/";
   113 
   114 	// Some directories
   115 	lastImageDir=QDir().current();
   116 	lastFileDir=QDir().current();
   117 
   118 	if (options.isOn ("help"))
   119 	{
   120 		cout << options.getHelpText().ascii()<<endl;
   121 		return 0;	
   122 	}	
   123 
   124 	// Initialize translations
   125 	QTranslator translator (0);
   126 	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
   127     app.installTranslator( &translator );
   128 
   129 	// Initializing the row of system flags
   130 	// is done in first call to MapEditor(),
   131 	// because we need at least one canvas first
   132 	systemFlagsDefault=NULL;
   133 	standardFlagsDefault=NULL;
   134 
   135 	// Initialize window of TextEditor
   136 	textEditor = new TextEditor();
   137 	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
   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