main.cpp
author insilmaril
Thu, 16 Nov 2006 10:07:11 +0000
changeset 399 190b3a70fabc
parent 398 d42881c25fb6
child 404 53efc2562a7d
permissions -rw-r--r--
Version 1.8.59: More fixes in undo/redo area
     1 #include <QApplication>
     2 #include <q3network.h>
     3 
     4 #include "settings.h"
     5 #include "options.h"
     6 #include "mainwindow.h"
     7 #include "flagrowobj.h"
     8 
     9 // Global variables
    10 TextEditor *textEditor;			// used in Constr. of LinkableMapObj
    11 								// initialized in mainwindow
    12 
    13 Main *mainWindow;				// used in BranchObj::select()								
    14 QString tmpVymDir;				// All temp files go there, created in mainwindow
    15 QString clipboardDir;			// Clipboard used in all mapEditors
    16 QDir vymBaseDir;				// Containing all styles, scripts, images, ...
    17 QDir lastImageDir;
    18 QDir lastFileDir;
    19 QString iconPath;				// Pointing to icons used for toolbars
    20 QString flagsPath;				// Pointing to flags
    21 bool clipboardEmpty;			
    22 FlagRowObj *systemFlagsDefault;	// used to copy from in LinkableMapObj
    23 FlagRowObj *standardFlagsDefault;
    24 
    25 
    26 Settings settings ("InSilmaril","vym"); // Organization, Application name
    27 
    28 Options options;
    29 ImageIO imageIO;
    30 
    31 int statusbarTime=3500;
    32 
    33 int main(int argc, char* argv[])
    34 {
    35 	//Q_INIT_RESOURCE (application);
    36 
    37     QApplication app(argc,argv);
    38 
    39 
    40 	// Reading and initializing options commandline options
    41 	options.add ("version", SwitchOption, "v","version");
    42 	options.add ("local", SwitchOption, "l", "local");
    43 	options.add ("help", SwitchOption, "h", "help");
    44 	options.add ("quit", SwitchOption, "q", "quit");
    45 	options.add ("test", StringOption, "t", "test");
    46 	options.setHelpText (
    47 		"VYM - View Your Mind\n"
    48 		"--------------------\n\n"
    49 		"Information about vym can be found in vym.pdf,\n"
    50 		"which should be part of the vym package.\n"
    51 		"It is also available at the project homepage:\n\n"
    52 		"http://www.InSilmaril.de/vym\n");
    53 	if (options.parse())
    54 	{
    55 		cout << endl << options.getHelpText().ascii()<<endl;
    56 		return 1;
    57 	}
    58 
    59 	if (options.isOn ("version"))
    60 	{
    61 		cout << "vym version "<<__VYM_VERSION
    62 			<<"  (c) 2004-2006 Uwe Drechsel - "
    63 			<<__BUILD_DATE<<endl;
    64 			
    65 		return 0;	
    66 	}		
    67 	
    68 	// Use /usr/share/vym or /usr/local/share/vym or . ?
    69 	// First try options
    70 	if (options.isOn ("local"))
    71 	{
    72 		vymBaseDir.setPath (vymBaseDir.currentDirPath());
    73 	} else
    74 	// then look for environment variable
    75 	if (getenv("VYMHOME")!=0)
    76 	{
    77 		vymBaseDir.setPath (getenv("VYMHOME"));
    78 	} else
    79 	// ok, let's find my way on my own
    80 	{
    81 		#if defined (Q_OS_MACX)
    82 			vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
    83 
    84 		#else
    85 			vymBaseDir.setPath ("/usr/share/vym");
    86 			if (!vymBaseDir.exists())
    87 			{
    88 				vymBaseDir.setPath ("/usr/local/share/vym");
    89 				if (!vymBaseDir.exists())
    90 					vymBaseDir.setPath(vymBaseDir.currentDirPath() );
    91 			}		
    92 		#endif
    93 	}
    94 
    95 	iconPath=vymBaseDir.path()+"/icons/";
    96 	flagsPath=vymBaseDir.path()+"/flags/";
    97 
    98 	// Some directories
    99 	lastImageDir=QDir().current();
   100 	lastFileDir=QDir().current();
   101 
   102 	if (options.isOn ("help"))
   103 	{
   104 		cout << options.getHelpText().ascii()<<endl;
   105 		return 0;	
   106 	}	
   107 
   108     q3InitNetworkProtocols();
   109 
   110 
   111 	// Initialize translations
   112 	QTranslator translator (0);
   113 	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
   114     app.installTranslator( &translator );
   115 
   116 	// Initializing the row of system flags
   117 	// is done in first call to MapEditor(),
   118 	// because we need at least one canvas first
   119 	systemFlagsDefault=NULL;
   120 	standardFlagsDefault=NULL;
   121 
   122 	// Initialize window of TextEditor
   123 	textEditor = new TextEditor();
   124 	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
   125 	if (textEditor->showWithMain()) textEditor->show();
   126 
   127 	// Initialize mainwindow 
   128     Main m;
   129 	//m.resize(m.sizeHint());
   130 	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
   131 	m.show();
   132 	m.fileNew();
   133 	m.loadCmdLine();
   134 
   135 	// For benchmarking we may want to quit immediatly after drawing
   136 	if (options.isOn ("quit"))
   137 	{
   138 		return 0;
   139 	}	
   140 
   141     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   142 
   143     return app.exec();
   144 }
   145