1 #include <QApplication>
2 #include <QtDBus/QDBusConnection>
8 #include "flagrowobj.h"
9 #include "mainwindow.h"
14 #if defined(Q_OS_WIN32)
15 #define WIN32_LEAN_AND_MEAN
20 TextEditor *textEditor; // used in Constr. of LinkableMapObj
21 // initialized in mainwindow
27 Main *mainWindow; // used in BranchObj::select()
28 QDBusConnection dbusConnection= QDBusConnection::sessionBus();
30 QString tmpVymDir; // All temp files go there, created in mainwindow
31 QString clipboardDir; // Clipboard used in all mapEditors
32 QString clipboardFile; // Clipboard used in all mapEditors
33 QDir vymBaseDir; // Containing all styles, scripts, images, ...
36 #if defined(Q_OS_WIN32)
39 QString iconPath; // Pointing to icons used for toolbars
40 QString flagsPath; // Pointing to flags
42 bool debug; // global debugging flag
43 FlagRow *systemFlagsMaster;
44 FlagRow *standardFlagsMaster;
46 Settings settings ("InSilmaril","vym"); // Organization, Application name
51 int statusbarTime=3500;
53 int main(int argc, char* argv[])
55 //Q_INIT_RESOURCE (application);
57 QApplication app(argc,argv);
60 vymVersion=__VYM_VERSION;
61 vymBuildDate=__VYM_BUILD_DATE;
62 vymCodeName=__VYM_CODENAME;
65 // Reading and initializing options commandline options
66 options.add ("debug", Option::Switch, "d", "debug");
67 options.add ("version", Option::Switch, "v","version");
68 options.add ("local", Option::Switch, "l", "local");
69 options.add ("help", Option::Switch, "h", "help");
70 options.add ("quit", Option::Switch, "q", "quit");
71 options.add ("run", Option::String, "r", "run");
72 options.add ("test", Option::String, "t", "test");
74 "VYM - View Your Mind\n"
75 "--------------------\n\n"
76 "Information about vym can be found in vym.pdf,\n"
77 "which should be part of the vym package.\n"
78 "It is also available at the project homepage:\n\n"
79 "http://www.InSilmaril.de/vym\n");
82 cout << endl << qPrintable( options.getHelpText())<<endl;
86 debug=options.isOn ("debug");
88 if (options.isOn ("version"))
90 cout << "VYM - View Your Mind (c) 2004-2007 Uwe Drechsel " << endl
91 <<" Version: "<<__VYM_VERSION <<endl
92 <<"Build date: "<<__VYM_BUILD_DATE << endl
93 <<" "<<__VYM_CODENAME<<endl;
98 // Use /usr/share/vym or /usr/local/share/vym or . ?
100 if (options.isOn ("local"))
102 vymBaseDir.setPath (vymBaseDir.currentDirPath());
104 // then look for environment variable
105 if (getenv("VYMHOME")!=0)
107 vymBaseDir.setPath (getenv("VYMHOME"));
109 // ok, let's find my way on my own
111 #if defined (Q_OS_MACX)
112 vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
114 #elif defined (Q_OS_WIN32)
118 if (GetModuleFileName(NULL, wbuf, 512))
120 QString mfn(QString::fromWCharArray(wbuf));
121 mfn.replace('\\', '/');
122 if (mfn.endsWith("/bin/vym.exe", Qt::CaseInsensitive))
129 if (basePath.isEmpty())
130 basePath = vymBaseDir.currentDirPath();
132 vymInstallDir.setPath(basePath);
133 vymBaseDir.setPath(basePath + "/share/vym");
136 vymBaseDir.setPath ("/usr/share/vym");
137 if (!vymBaseDir.exists())
139 vymBaseDir.setPath ("/usr/local/share/vym");
140 if (!vymBaseDir.exists())
141 vymBaseDir.setPath(vymBaseDir.currentDirPath() );
146 iconPath=vymBaseDir.path()+"/icons/";
147 flagsPath=vymBaseDir.path()+"/flags/";
150 lastImageDir=QDir().current();
151 lastFileDir=QDir().current();
153 if (options.isOn ("help"))
155 cout << qPrintable (options.getHelpText())<<endl;
159 // Initialize translations
160 QTranslator translator (0);
161 translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
162 app.installTranslator( &translator );
164 // Initializing the master rows of flags
165 systemFlagsMaster=new FlagRow;
166 systemFlagsMaster->setName ("systemFlagsMaster");
167 standardFlagsMaster=new FlagRow;
168 standardFlagsMaster->setName ("standardFlagsMaster");
171 // Initialize window of TextEditor
172 textEditor = new TextEditor();
173 textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
175 // Initialize mainwindow
176 #if defined(Q_OS_WIN32)
177 Main m(0, 0, (Qt::Window | Qt::MSWindowsOwnDC));
182 //m.resize(m.sizeHint());
183 m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
186 // Paint Mainwindow first time
187 qApp->processEvents();
189 // FIXME-3 playing around with dbus
192 dbusConnection.registerService("org.insilmaril.MainWindow");
193 QDBusConnection::sessionBus().registerObject("/MainApplication", &app);
200 if (options.isOn ("run"))
203 QString fn=options.getArg ("run");
207 if ( !f.open( QIODevice::ReadOnly ) )
209 QMessageBox::warning(0,
210 QObject::tr("Error"),
211 QObject::tr("Couldn't open %1.\n").arg(fn));
215 QTextStream ts( &f );
218 m.setScript (script);
219 m.runScriptEverywhere (script);
223 // For benchmarking we may want to quit instead of entering event loop
224 if (options.isOn ("quit"))
229 // Enable some last minute cleanup
230 QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );