1 #include <QApplication>
2 #include <QtDBus/QDBusConnection>
7 #include "adaptor.h" //FIXME-3
10 #include "flagrowobj.h"
11 #include "mainwindow.h"
16 #if defined(Q_OS_WIN32)
17 #define WIN32_LEAN_AND_MEAN
22 TextEditor *textEditor; // used in Constr. of LinkableMapObj
23 // initialized in mainwindow
29 Main *mainWindow; // used in BranchObj::select()
30 QDBusConnection dbusConnection= QDBusConnection::sessionBus();
32 QString tmpVymDir; // All temp files go there, created in mainwindow
33 QString clipboardDir; // Clipboard used in all mapEditors
34 QString clipboardFile; // Clipboard used in all mapEditors
35 QDir vymBaseDir; // Containing all styles, scripts, images, ...
38 #if defined(Q_OS_WIN32)
41 QString iconPath; // Pointing to icons used for toolbars
42 QString flagsPath; // Pointing to flags
44 bool debug; // global debugging flag
45 FlagRow *systemFlagsMaster;
46 FlagRow *standardFlagsMaster;
48 Settings settings ("InSilmaril","vym"); // Organization, Application name
53 int statusbarTime=3500;
55 int main(int argc, char* argv[])
57 //Q_INIT_RESOURCE (application);
59 QApplication app(argc,argv);
62 vymVersion=__VYM_VERSION;
63 vymBuildDate=__VYM_BUILD_DATE;
64 vymCodeName=__VYM_CODENAME;
67 // Reading and initializing options commandline options
68 options.add ("debug", Option::Switch, "d", "debug");
69 options.add ("version", Option::Switch, "v","version");
70 options.add ("local", Option::Switch, "l", "local");
71 options.add ("help", Option::Switch, "h", "help");
72 options.add ("quit", Option::Switch, "q", "quit");
73 options.add ("run", Option::String, "r", "run");
74 options.add ("test", Option::String, "t", "test");
76 "VYM - View Your Mind\n"
77 "--------------------\n\n"
78 "Information about vym can be found in vym.pdf,\n"
79 "which should be part of the vym package.\n"
80 "It is also available at the project homepage:\n\n"
81 "http://www.InSilmaril.de/vym\n");
84 cout << endl << qPrintable( options.getHelpText())<<endl;
88 debug=options.isOn ("debug");
90 if (options.isOn ("version"))
92 cout << "VYM - View Your Mind (c) 2004-2007 Uwe Drechsel " << endl
93 <<" Version: "<<__VYM_VERSION <<endl
94 <<"Build date: "<<__VYM_BUILD_DATE << endl
95 <<" "<<__VYM_CODENAME<<endl;
100 // Use /usr/share/vym or /usr/local/share/vym or . ?
102 if (options.isOn ("local"))
104 vymBaseDir.setPath (vymBaseDir.currentDirPath());
106 // then look for environment variable
107 if (getenv("VYMHOME")!=0)
109 vymBaseDir.setPath (getenv("VYMHOME"));
111 // ok, let's find my way on my own
113 #if defined (Q_OS_MACX)
114 vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
116 #elif defined (Q_OS_WIN32)
120 if (GetModuleFileName(NULL, wbuf, 512))
122 QString mfn(QString::fromWCharArray(wbuf));
123 mfn.replace('\\', '/');
124 if (mfn.endsWith("/bin/vym.exe", Qt::CaseInsensitive))
131 if (basePath.isEmpty())
132 basePath = vymBaseDir.currentDirPath();
134 vymInstallDir.setPath(basePath);
135 vymBaseDir.setPath(basePath + "/share/vym");
138 vymBaseDir.setPath ("/usr/share/vym");
139 if (!vymBaseDir.exists())
141 vymBaseDir.setPath ("/usr/local/share/vym");
142 if (!vymBaseDir.exists())
143 vymBaseDir.setPath(vymBaseDir.currentDirPath() );
148 iconPath=vymBaseDir.path()+"/icons/";
149 flagsPath=vymBaseDir.path()+"/flags/";
152 lastImageDir=QDir().current();
153 lastFileDir=QDir().current();
155 if (options.isOn ("help"))
157 cout << qPrintable (options.getHelpText())<<endl;
161 // Initialize translations
162 QTranslator translator (0);
163 translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
164 app.installTranslator( &translator );
166 // Initializing the master rows of flags
167 systemFlagsMaster=new FlagRow;
168 systemFlagsMaster->setName ("systemFlagsMaster");
169 standardFlagsMaster=new FlagRow;
170 standardFlagsMaster->setName ("standardFlagsMaster");
173 // Initialize window of TextEditor
174 textEditor = new TextEditor();
175 textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
177 // Initialize mainwindow
178 #if defined(Q_OS_WIN32)
179 Main m(0, 0, (Qt::Window | Qt::MSWindowsOwnDC));
184 //m.resize(m.sizeHint());
185 m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
188 // Paint Mainwindow first time
189 qApp->processEvents();
191 // FIXME-3 playing around with dbus
194 dbusConnection.registerService("org.insilmaril.MainWindow");
195 QDBusConnection::sessionBus().registerObject("/MainApplication", &app);
202 if (options.isOn ("run"))
205 QString fn=options.getArg ("run");
209 if ( !f.open( QIODevice::ReadOnly ) )
211 QMessageBox::warning(0,
212 QObject::tr("Error"),
213 QObject::tr("Couldn't open %1.\n").arg(fn));
217 QTextStream ts( &f );
220 m.setScript (script);
221 m.runScriptEverywhere (script);
225 // For benchmarking we may want to quit instead of entering event loop
226 if (options.isOn ("quit"))
231 QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );