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