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