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