main.cpp
author insilmaril
Fri, 05 Jan 2007 11:17:32 +0000
changeset 417 1cc7bbf75f0b
parent 406 1c8ff1928b97
child 434 c585be63ec69
permissions -rw-r--r--
1.8.64 various fixes
     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;
    14 QString vymVersion;
    15 QString vymBuildDate;
    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 	vymName=__VYM_NAME;
    44 	vymVersion=__VYM_VERSION;
    45 	vymBuildDate=__VYM_BUILD_DATE;
    46 
    47 
    48 	// Reading and initializing options commandline options
    49 	options.add ("version", SwitchOption, "v","version");
    50 	options.add ("local", SwitchOption, "l", "local");
    51 	options.add ("help", SwitchOption, "h", "help");
    52 	options.add ("quit", SwitchOption, "q", "quit");
    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     q3InitNetworkProtocols();
   117 
   118 
   119 	// Initialize translations
   120 	QTranslator translator (0);
   121 	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
   122     app.installTranslator( &translator );
   123 
   124 	// Initializing the row of system flags
   125 	// is done in first call to MapEditor(),
   126 	// because we need at least one canvas first
   127 	systemFlagsDefault=NULL;
   128 	standardFlagsDefault=NULL;
   129 
   130 	// Initialize window of TextEditor
   131 	textEditor = new TextEditor();
   132 	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
   133 	if (textEditor->showWithMain()) textEditor->show();
   134 
   135 	// Initialize mainwindow 
   136     Main m;
   137 	//m.resize(m.sizeHint());
   138 	m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
   139 	m.show();
   140 	m.fileNew();
   141 	m.loadCmdLine();
   142 
   143 	// For benchmarking we may want to quit immediatly after drawing
   144 	if (options.isOn ("quit"))
   145 	{
   146 		return 0;
   147 	}	
   148 
   149     QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
   150 
   151     return app.exec();
   152 }
   153