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