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