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