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
19 #include <sys/types.h> // To retrieve PID for use in DBUS
23 TextEditor *textEditor; // used in Constr. of LinkableMapObj
24 // initialized in mainwindow
29 QString vymInstanceName;
31 Main *mainWindow; // used in BranchObj::select()
33 QDBusConnection dbusConnection= QDBusConnection::sessionBus();
36 QString tmpVymDir; // All temp files go there, created in mainwindow
37 QString clipboardDir; // Clipboard used in all mapEditors
38 QString clipboardFile; // Clipboard used in all mapEditors
39 QDir vymBaseDir; // Containing all styles, scripts, images, ...
42 #if defined(Q_OS_WIN32)
45 QString iconPath; // Pointing to icons used for toolbars
46 QString flagsPath; // Pointing to flags
48 bool debug; // global debugging flag
49 FlagRow *systemFlagsMaster;
50 FlagRow *standardFlagsMaster;
52 Settings settings ("InSilmaril","vym"); // Organization, Application name
57 int statusbarTime=3500;
59 int main(int argc, char* argv[])
61 //Q_INIT_RESOURCE (application);
63 QApplication app(argc,argv);
66 vymVersion=__VYM_VERSION;
67 vymBuildDate=__VYM_BUILD_DATE;
68 vymCodeName=__VYM_CODENAME;
70 // Reading and initializing options commandline options
71 options.add ("debug", Option::Switch, "d", "debug");
72 options.add ("version", Option::Switch, "v","version");
73 options.add ("local", Option::Switch, "l", "local");
74 options.add ("name", Option::String, "n", "name");
75 options.add ("help", Option::Switch, "h", "help");
76 options.add ("quit", Option::Switch, "q", "quit");
77 options.add ("run", Option::String, "r", "run");
78 options.add ("test", Option::String, "t", "test");
80 "VYM - View Your Mind\n"
81 "--------------------\n\n"
82 "Information about vym can be found in vym.pdf,\n"
83 "which should be part of the vym package.\n"
84 "It is also available at the project homepage:\n\n"
85 "http://www.InSilmaril.de/vym\n");
88 cout << endl << qPrintable( options.getHelpText())<<endl;
92 debug=options.isOn ("debug");
94 if (options.isOn ("version"))
96 cout << "VYM - View Your Mind (c) 2004-2009 Uwe Drechsel " << endl
97 <<" Version: "<<__VYM_VERSION <<endl
98 <<"Build date: "<<__VYM_BUILD_DATE << endl
99 <<" "<<__VYM_CODENAME<<endl;
105 if (debug) cout << "PID="<<getpid()<<endl;
106 QString pidString=QString ("%1").arg(getpid());
107 if (!dbusConnection.registerService ("org.insilmaril.vym-"+pidString))
109 fprintf(stderr, "%s\n",
110 qPrintable(QDBusConnection::sessionBus().lastError().message()));
114 if (options.isOn ("name"))
115 vymInstanceName=options.getArg ("name");
117 vymInstanceName=pidString;
120 // Use /usr/share/vym or /usr/local/share/vym or . ?
122 if (options.isOn ("local"))
124 vymBaseDir.setPath (vymBaseDir.currentDirPath());
126 // then look for environment variable
127 if (getenv("VYMHOME")!=0)
129 vymBaseDir.setPath (getenv("VYMHOME"));
131 // ok, let's find my way on my own
133 #if defined (Q_OS_MACX)
134 vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
136 #elif defined (Q_OS_WIN32)
140 if (GetModuleFileName(NULL, wbuf, 512))
142 QString mfn(QString::fromWCharArray(wbuf));
143 mfn.replace('\\', '/');
144 if (mfn.endsWith("/bin/vym.exe", Qt::CaseInsensitive))
151 if (basePath.isEmpty())
152 basePath = vymBaseDir.currentDirPath();
154 vymInstallDir.setPath(basePath);
155 vymBaseDir.setPath(basePath + "/share/vym");
158 vymBaseDir.setPath ("/usr/share/vym");
159 if (!vymBaseDir.exists())
161 vymBaseDir.setPath ("/usr/local/share/vym");
162 if (!vymBaseDir.exists())
163 vymBaseDir.setPath(vymBaseDir.currentDirPath() );
168 iconPath=vymBaseDir.path()+"/icons/";
169 flagsPath=vymBaseDir.path()+"/flags/";
172 lastImageDir=QDir().current();
173 lastFileDir=QDir().current();
175 if (options.isOn ("help"))
177 cout << qPrintable (options.getHelpText())<<endl;
181 // Initialize translations
182 QTranslator translator (0);
183 translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
184 app.installTranslator( &translator );
186 // Initializing the master rows of flags
187 systemFlagsMaster=new FlagRow;
188 systemFlagsMaster->setName ("systemFlagsMaster");
189 standardFlagsMaster=new FlagRow;
190 standardFlagsMaster->setName ("standardFlagsMaster");
193 // Initialize window of TextEditor
194 textEditor = new TextEditor();
195 textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
197 // Initialize mainwindow
198 #if defined(Q_OS_WIN32)
199 Main m(0, 0, (Qt::Window | Qt::MSWindowsOwnDC));
204 //m.resize(m.sizeHint());
205 m.setIcon (QPixmap (iconPath+"vym.png"));
208 // Paint Mainwindow first time
209 qApp->processEvents();
214 if (options.isOn ("run"))
217 QString fn=options.getArg ("run");
221 if ( !f.open( QIODevice::ReadOnly ) )
223 QMessageBox::warning(0,
224 QObject::tr("Error"),
225 QObject::tr("Couldn't open %1.\n").arg(fn));
229 QTextStream ts( &f );
232 m.setScript (script);
233 m.runScriptEverywhere (script);
237 // For benchmarking we may want to quit instead of entering event loop
238 if (options.isOn ("quit"))
243 // Enable some last minute cleanup
244 QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );