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