1 #include <QApplication>
2 #include <QtDBus/QDBusConnection>
7 #include "findwidget.h"
8 #include "findresultwidget.h"
10 #include "flagrowobj.h"
11 #include "mainwindow.h"
16 #if defined(Q_OS_WIN32)
17 #define WIN32_LEAN_AND_MEAN
21 #include <sys/types.h> // To retrieve PID for use in DBUS
25 TextEditor *textEditor; // used in Constr. of LinkableMapObj
26 // initialized in mainwindow
31 QString vymInstanceName;
33 Main *mainWindow; // used in BranchObj::select()
34 FindWidget *findWidget;
35 FindResultWidget *findResultWidget;
37 QDBusConnection dbusConnection= QDBusConnection::sessionBus();
39 QString tmpVymDir; // All temp files go there, created in mainwindow
40 QString clipboardDir; // Clipboard used in all mapEditors
41 QString clipboardFile; // Clipboard used in all mapEditors
42 QDir vymBaseDir; // Containing all styles, scripts, images, ...
45 #if defined(Q_OS_WIN32)
48 QString iconPath; // Pointing to icons used for toolbars
49 QString flagsPath; // Pointing to flags
51 bool debug; // global debugging flag
52 FlagRow *systemFlagsMaster;
53 FlagRow *standardFlagsMaster;
55 Settings settings ("InSilmaril","vym"); // Organization, Application name
60 int statusbarTime=3500;
62 int main(int argc, char* argv[])
64 //Q_INIT_RESOURCE (application);
66 QApplication app(argc,argv);
69 vymVersion=__VYM_VERSION;
70 vymBuildDate=__VYM_BUILD_DATE;
71 vymCodeName=__VYM_CODENAME;
73 // Reading and initializing options commandline options
74 options.add ("debug", Option::Switch, "d", "debug");
75 options.add ("version", Option::Switch, "v","version");
76 options.add ("local", Option::Switch, "l", "local");
77 options.add ("name", Option::String, "n", "name");
78 options.add ("help", Option::Switch, "h", "help");
79 options.add ("quit", Option::Switch, "q", "quit");
80 options.add ("run", Option::String, "r", "run");
81 options.add ("test", Option::String, "t", "test");
83 "VYM - View Your Mind\n"
84 "--------------------\n\n"
85 "Information about vym can be found in vym.pdf,\n"
86 "which should be part of the vym package.\n"
87 "It is also available at the project homepage:\n\n"
88 "http://www.InSilmaril.de/vym\n");
91 cout << endl << qPrintable( options.getHelpText())<<endl;
95 debug=options.isOn ("debug");
97 if (options.isOn ("version"))
99 cout << "VYM - View Your Mind (c) 2004-2009 Uwe Drechsel " << endl
100 <<" Version: "<<__VYM_VERSION <<endl
101 <<"Build date: "<<__VYM_BUILD_DATE << endl
102 <<" "<<__VYM_CODENAME<<endl;
108 if (debug) cout << "PID="<<getpid()<<endl;
109 QString pidString=QString ("%1").arg(getpid());
110 if (!dbusConnection.registerService ("org.insilmaril.vym-"+pidString))
112 fprintf(stderr, "%s\n",
113 qPrintable(QDBusConnection::sessionBus().lastError().message()));
117 if (options.isOn ("name"))
118 vymInstanceName=options.getArg ("name");
120 vymInstanceName=pidString;
123 // Use /usr/share/vym or /usr/local/share/vym or . ?
125 if (options.isOn ("local"))
127 vymBaseDir.setPath (vymBaseDir.currentDirPath());
129 // then look for environment variable
130 if (getenv("VYMHOME")!=0)
132 vymBaseDir.setPath (getenv("VYMHOME"));
134 // ok, let's find my way on my own
136 #if defined (Q_OS_MACX)
137 vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
139 #elif defined (Q_OS_WIN32)
143 if (GetModuleFileName(NULL, wbuf, 512))
145 QString mfn(QString::fromWCharArray(wbuf));
146 mfn.replace('\\', '/');
147 if (mfn.endsWith("/bin/vym.exe", Qt::CaseInsensitive))
154 if (basePath.isEmpty())
155 basePath = vymBaseDir.currentDirPath();
157 vymInstallDir.setPath(basePath);
158 vymBaseDir.setPath(basePath + "/share/vym");
161 vymBaseDir.setPath ("/usr/share/vym");
162 if (!vymBaseDir.exists())
164 vymBaseDir.setPath ("/usr/local/share/vym");
165 if (!vymBaseDir.exists())
166 vymBaseDir.setPath(vymBaseDir.currentDirPath() );
171 iconPath=vymBaseDir.path()+"/icons/";
172 flagsPath=vymBaseDir.path()+"/flags/";
175 lastImageDir=QDir().current();
176 lastFileDir=QDir().current();
178 if (options.isOn ("help"))
180 cout << qPrintable (options.getHelpText())<<endl;
184 // Initialize translations
185 QTranslator translator (0);
186 translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
187 app.installTranslator( &translator );
189 // Initializing the master rows of flags
190 systemFlagsMaster=new FlagRow;
191 systemFlagsMaster->setName ("systemFlagsMaster");
192 standardFlagsMaster=new FlagRow;
193 standardFlagsMaster->setName ("standardFlagsMaster");
196 // Initialize window of TextEditor
197 textEditor = new TextEditor();
198 textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
200 // Initialize mainwindow
201 #if defined(Q_OS_WIN32)
202 Main m(0, 0, (Qt::Window | Qt::MSWindowsOwnDC));
207 //m.resize(m.sizeHint());
208 m.setIcon (QPixmap (iconPath+"vym.png"));
211 // Paint Mainwindow first time
212 qApp->processEvents();
217 if (options.isOn ("run"))
220 QString fn=options.getArg ("run");
224 if ( !f.open( QIODevice::ReadOnly ) )
226 QMessageBox::warning(0,
227 QObject::tr("Error"),
228 QObject::tr("Couldn't open %1.\n").arg(fn));
232 QTextStream ts( &f );
235 m.setScript (script);
236 m.runScriptEverywhere (script);
240 // For benchmarking we may want to quit instead of entering event loop
241 if (options.isOn ("quit"))
246 // Enable some last minute cleanup
247 QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );