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