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