main.cpp
author insilmaril
Wed, 24 Oct 2007 12:21:24 +0000
changeset 613 8fb5b3956b3e
parent 550 55236fe5a630
child 625 22955004d512
permissions -rw-r--r--
Improved ascii export
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@491
    20
QString clipboardFile;			// Clipboard used in all mapEditors
insilmaril@215
    21
QDir vymBaseDir;				// Containing all styles, scripts, images, ...
insilmaril@366
    22
QDir lastImageDir;
insilmaril@366
    23
QDir lastFileDir;
insilmaril@269
    24
QString iconPath;				// Pointing to icons used for toolbars
insilmaril@269
    25
QString flagsPath;				// Pointing to flags
insilmaril@166
    26
bool clipboardEmpty;			
insilmaril@473
    27
bool debug;						// global debugging flag
insilmaril@0
    28
FlagRowObj *systemFlagsDefault;	// used to copy from in LinkableMapObj
insilmaril@0
    29
FlagRowObj *standardFlagsDefault;
insilmaril@0
    30
insilmaril@366
    31
insilmaril@366
    32
Settings settings ("InSilmaril","vym"); // Organization, Application name
insilmaril@366
    33
insilmaril@0
    34
Options options;
insilmaril@366
    35
ImageIO imageIO;
insilmaril@0
    36
insilmaril@0
    37
int statusbarTime=3500;
insilmaril@0
    38
insilmaril@394
    39
int main(int argc, char* argv[])
insilmaril@0
    40
{
insilmaril@394
    41
	//Q_INIT_RESOURCE (application);
insilmaril@366
    42
insilmaril@0
    43
    QApplication app(argc,argv);
insilmaril@0
    44
insilmaril@406
    45
	vymName=__VYM_NAME;
insilmaril@406
    46
	vymVersion=__VYM_VERSION;
insilmaril@406
    47
	vymBuildDate=__VYM_BUILD_DATE;
insilmaril@473
    48
	vymCodeName=__VYM_CODENAME;
insilmaril@406
    49
insilmaril@0
    50
insilmaril@0
    51
	// Reading and initializing options commandline options
insilmaril@473
    52
	options.add ("debug", Option::Switch, "d", "debug");
insilmaril@473
    53
	options.add ("version", Option::Switch, "v","version");
insilmaril@473
    54
	options.add ("local", Option::Switch, "l", "local");
insilmaril@473
    55
	options.add ("help", Option::Switch, "h", "help");
insilmaril@473
    56
	options.add ("quit", Option::Switch, "q", "quit");
insilmaril@473
    57
	options.add ("run", Option::String, "r", "run");
insilmaril@473
    58
	options.add ("test", Option::String, "t", "test");
insilmaril@0
    59
	options.setHelpText (
insilmaril@0
    60
		"VYM - View Your Mind\n"
insilmaril@0
    61
		"--------------------\n\n"
insilmaril@0
    62
		"Information about vym can be found in vym.pdf,\n"
insilmaril@0
    63
		"which should be part of the vym package.\n"
insilmaril@0
    64
		"It is also available at the project homepage:\n\n"
insilmaril@0
    65
		"http://www.InSilmaril.de/vym\n");
insilmaril@0
    66
	if (options.parse())
insilmaril@0
    67
	{
insilmaril@366
    68
		cout << endl << options.getHelpText().ascii()<<endl;
insilmaril@0
    69
		return 1;
insilmaril@0
    70
	}
insilmaril@0
    71
insilmaril@473
    72
	debug=options.isOn ("debug");
insilmaril@473
    73
insilmaril@0
    74
	if (options.isOn ("version"))
insilmaril@0
    75
	{
insilmaril@550
    76
		cout << "VYM - View Your Mind (c) 2004-2007 Uwe Drechsel "  << endl
insilmaril@550
    77
			<<"   Version: "<<__VYM_VERSION <<endl
insilmaril@550
    78
			<<"Build date: "<<__VYM_BUILD_DATE << endl
insilmaril@473
    79
			<<"  "<<__VYM_CODENAME<<endl;
insilmaril@0
    80
			
insilmaril@0
    81
		return 0;	
insilmaril@0
    82
	}		
insilmaril@0
    83
	
insilmaril@243
    84
	// Use /usr/share/vym or /usr/local/share/vym or . ?
insilmaril@269
    85
	// First try options
insilmaril@243
    86
	if (options.isOn ("local"))
insilmaril@243
    87
	{
insilmaril@243
    88
		vymBaseDir.setPath (vymBaseDir.currentDirPath());
insilmaril@269
    89
	} else
insilmaril@269
    90
	// then look for environment variable
insilmaril@269
    91
	if (getenv("VYMHOME")!=0)
insilmaril@269
    92
	{
insilmaril@269
    93
		vymBaseDir.setPath (getenv("VYMHOME"));
insilmaril@269
    94
	} else
insilmaril@269
    95
	// ok, let's find my way on my own
insilmaril@243
    96
	{
insilmaril@390
    97
		#if defined (Q_OS_MACX)
insilmaril@394
    98
			vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
insilmaril@390
    99
insilmaril@390
   100
		#else
insilmaril@390
   101
			vymBaseDir.setPath ("/usr/share/vym");
insilmaril@308
   102
			if (!vymBaseDir.exists())
insilmaril@390
   103
			{
insilmaril@390
   104
				vymBaseDir.setPath ("/usr/local/share/vym");
insilmaril@390
   105
				if (!vymBaseDir.exists())
insilmaril@390
   106
					vymBaseDir.setPath(vymBaseDir.currentDirPath() );
insilmaril@390
   107
			}		
insilmaril@390
   108
		#endif
insilmaril@243
   109
	}
insilmaril@243
   110
insilmaril@269
   111
	iconPath=vymBaseDir.path()+"/icons/";
insilmaril@269
   112
	flagsPath=vymBaseDir.path()+"/flags/";
insilmaril@269
   113
insilmaril@366
   114
	// Some directories
insilmaril@366
   115
	lastImageDir=QDir().current();
insilmaril@366
   116
	lastFileDir=QDir().current();
insilmaril@366
   117
insilmaril@0
   118
	if (options.isOn ("help"))
insilmaril@0
   119
	{
insilmaril@366
   120
		cout << options.getHelpText().ascii()<<endl;
insilmaril@0
   121
		return 0;	
insilmaril@0
   122
	}	
insilmaril@0
   123
insilmaril@243
   124
	// Initialize translations
insilmaril@243
   125
	QTranslator translator (0);
insilmaril@243
   126
	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
insilmaril@243
   127
    app.installTranslator( &translator );
insilmaril@243
   128
insilmaril@243
   129
	// Initializing the row of system flags
insilmaril@243
   130
	// is done in first call to MapEditor(),
insilmaril@243
   131
	// because we need at least one canvas first
insilmaril@243
   132
	systemFlagsDefault=NULL;
insilmaril@243
   133
	standardFlagsDefault=NULL;
insilmaril@243
   134
insilmaril@0
   135
	// Initialize window of TextEditor
insilmaril@0
   136
	textEditor = new TextEditor();
insilmaril@269
   137
	textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
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@514
   167
			m.runScriptEverywhere (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