Menu

[2edc72]: / main.cpp  Maximize  Restore  History

Download this file

293 lines (247 with data), 8.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#include <QApplication>
#include <QtDBus/QDBusConnection>
#include <iostream>
using namespace std;
#include "findwidget.h"
#include "findresultwidget.h"
#include "flagrow.h"
#include "flagrowobj.h"
#include "headingeditor.h"
#include "mainwindow.h"
#include "noteeditor.h"
#include "options.h"
#include "settings.h"
#include "version.h"
#if defined(Q_OS_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <sys/types.h> // To retrieve PID for use in DBUS
#include <unistd.h>
QString vymName;
QString vymVersion;
QString vymBuildDate;
QString vymCodeName;
QString vymInstanceName;
bool bugzillaClientAvailable; // openSUSE specific currently
HeadingEditor *headingEditor;
NoteEditor *noteEditor; // used in Constr. of LinkableMapObj
// initialized in mainwindow
Main *mainWindow; // used in BranchObj::select()
FindWidget *findWidget;
FindResultWidget *findResultWidget;
QDBusConnection dbusConnection= QDBusConnection::sessionBus();
QString tmpVymDir; // All temp files go there, created in mainwindow
QString clipboardDir; // Clipboard used in all mapEditors
QString clipboardFile; // Clipboard used in all mapEditors
QDir vymBaseDir; // Containing all styles, scripts, images, ...
QDir lastImageDir;
QDir lastMapDir;
QDir lastExportDir;
#if defined(Q_OS_WIN32)
QDir vymInstallDir;
#endif
QString iconPath; // Pointing to icons used for toolbars
QString flagsPath; // Pointing to flags
bool clipboardEmpty;
bool debug; // global debugging flag
FlagRow *systemFlagsMaster;
FlagRow *standardFlagsMaster;
Settings settings ("InSilmaril","vym"); // Organization, Application name
Options options;
ImageIO imageIO;
int statusbarTime=10000;
int main(int argc, char* argv[])
{
//Q_INIT_RESOURCE (application);
QApplication app(argc,argv);
vymName=__VYM_NAME;
vymVersion=__VYM_VERSION;
vymBuildDate=__VYM_BUILD_DATE;
vymCodeName=__VYM_CODENAME;
// Reading and initializing options commandline options
options.add ("batch", Option::Switch, "b", "batch");
options.add ("debug", Option::Switch, "d", "debug");
options.add ("help", Option::Switch, "h", "help");
options.add ("local", Option::Switch, "l", "local");
options.add ("name", Option::String, "n", "name");
options.add ("quit", Option::Switch, "q", "quit");
options.add ("run", Option::String, "r", "run");
options.add ("restore", Option::Switch, "R", "restore");
options.add ("shortcuts", Option::Switch, "s", "shortcuts");
options.add ("shortcutsLaTeX", Option::Switch, "sl", "shortcutsLaTeX");
options.add ("version", Option::Switch, "v","version");
options.setHelpText (
"VYM - View Your Mind\n"
"--------------------\n\n"
"Information about vym can be found in vym.pdf,\n"
"which should be part of the vym package.\n"
"It is also available at the project homepage:\n\n"
"http://www.InSilmaril.de/vym\n\n"
"Usage: vym [OPTION]... [FILE]... \n"
"Open FILEs with vym\n\n"
"-b batch batch mode: hide windows\n"
"-d debug Show debugging output\n"
"-h help Show this help text\n"
"-l local Run with ressources in current directory\n"
"-n STRING name Set name of instance for DBus access\n"
"-q quit Quit immediatly after start for benchmarking\n"
"-r FILE run Run script\n"
"-R restore Restore last session\n"
"-s shortcuts Show Keyboard shortcuts on start\n"
"-sl LaTeX Show Keyboard shortcuts in LaTeX format on start\n"
"-v version Show vym version\n"
);
if (options.parse())
{
cout << endl << qPrintable( options.getHelpText())<<endl;
return 1;
}
debug=options.isOn ("debug");
if (options.isOn ("version"))
{
cout << "VYM - View Your Mind (c) 2004-2011 Uwe Drechsel " << endl
<<" Version: "<<__VYM_VERSION <<endl
<<"Build date: "<<__VYM_BUILD_DATE << endl
<<" "<<__VYM_CODENAME<<endl;
return 0;
}
// Register for DBUS
if (debug) cout << "PID="<<getpid()<<endl;
QString pidString=QString ("%1").arg(getpid());
if (!dbusConnection.registerService ("org.insilmaril.vym-"+pidString))
{
fprintf(stderr, "%s\n",
qPrintable(QDBusConnection::sessionBus().lastError().message()));
exit(1);
}
if (options.isOn ("name"))
vymInstanceName=options.getArg ("name");
else
vymInstanceName=pidString;
// Use /usr/share/vym or /usr/local/share/vym or . ?
// First try options
if (options.isOn ("local"))
{
vymBaseDir.setPath (vymBaseDir.currentPath());
} else
// then look for environment variable
if (getenv("VYMHOME")!=0)
{
vymBaseDir.setPath (getenv("VYMHOME"));
} else
// ok, let's find my way on my own
{
#if defined (Q_OS_MACX)
vymBaseDir.setPath(vymBaseDir.currentPath() +"/vym.app/Contents/Resources");
#elif defined (Q_OS_WIN32)
QString basePath;
wchar_t wbuf[512];
if (GetModuleFileName(NULL, wbuf, 512))
{
QString mfn(QString::fromWCharArray(wbuf));
mfn.replace('\\', '/');
if (mfn.endsWith("/bin/vym.exe", Qt::CaseInsensitive))
{
mfn.chop(12);
basePath = mfn;
}
}
if (basePath.isEmpty())
basePath = vymBaseDir.currentDirPath();
vymInstallDir.setPath(basePath);
vymBaseDir.setPath(basePath + "/share/vym");
#else
vymBaseDir.setPath ("/usr/share/vym");
if (!vymBaseDir.exists())
{
vymBaseDir.setPath ("/usr/local/share/vym");
if (!vymBaseDir.exists())
vymBaseDir.setPath(vymBaseDir.currentPath() );
}
#endif
}
iconPath=vymBaseDir.path()+"/icons/";
flagsPath=vymBaseDir.path()+"/flags/";
// Some directories
QDir useDir;
if (options.isOn ("local"))
useDir=QDir().current();
else
useDir=QDir().home();
lastImageDir=useDir;
lastMapDir=useDir;
lastExportDir=useDir;
if (options.isOn ("help"))
{
cout << qPrintable (options.getHelpText())<<endl;
return 0;
}
// Initialize translations
QTranslator translator (0);
//translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
translator.load( QString("vym_")+QLocale().name(), vymBaseDir.path() + "/lang");
app.installTranslator( &translator );
// Initializing the master rows of flags
systemFlagsMaster=new FlagRow;
systemFlagsMaster->setName ("systemFlagsMaster");
standardFlagsMaster=new FlagRow;
standardFlagsMaster->setName ("standardFlagsMaster");
// Initialize window of NoteEditor
noteEditor = new NoteEditor();
noteEditor->setWindowIcon (QPixmap (iconPath+"vym-editor.png"));
headingEditor = new HeadingEditor();
// Check if there is a BugzillaClient
QFileInfo fi("/var/adm/perl-modules/perl-SUSE-BugzillaClient");
bugzillaClientAvailable=fi.exists();
// Initialize mainwindow
#if defined(Q_OS_WIN32)
Main m(0, Qt::Window | Qt::MSWindowsOwnDC);
#else
Main m;
#endif
m.setWindowIcon (QPixmap (iconPath+"vym.png"));
m.fileNew();
if (options.isOn ("batch"))
m.hide();
else
{
// Paint Mainwindow first time
qApp->processEvents();
m.show();
}
m.loadCmdLine();
// Restore last session
if (options.isOn ("restore"))
m.fileRestoreSession();
// Run script
if (options.isOn ("run"))
{
QString script;
QString fn=options.getArg ("run");
if ( !fn.isEmpty() )
{
QFile f( fn );
if ( !f.open( QFile::ReadOnly|QFile::Text ) )
{
QString error (QObject::tr("Error"));
QString msg (QObject::tr("Couldn't open \"%1\"\n%2.").arg(fn).arg(f.errorString()));
if (options.isOn("batch"))
qWarning ()<<error+": "+msg;
else
QMessageBox::warning(0, error,msg);
return 0;
}
QTextStream in( &f );
script= in.readAll();
f.close();
m.setScript (script);
m.runScriptEverywhere (script);
}
}
// For benchmarking we may want to quit instead of entering event loop
if (options.isOn ("quit")) return 0;
// Enable some last minute cleanup
QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
return app.exec();
}