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
30 Main *mainWindow; // used in BranchObj::select()
32 QDBusConnection dbusConnection= QDBusConnection::sessionBus();
35 QString tmpVymDir; // All temp files go there, created in mainwindow
36 QString clipboardDir; // Clipboard used in all mapEditors
37 QString clipboardFile; // Clipboard used in all mapEditors
38 QDir vymBaseDir; // Containing all styles, scripts, images, ...
41 #if defined(Q_OS_WIN32)
44 QString iconPath; // Pointing to icons used for toolbars
45 QString flagsPath; // Pointing to flags
47 bool debug; // global debugging flag
48 FlagRow *systemFlagsMaster;
49 FlagRow *standardFlagsMaster;
51 Settings settings ("InSilmaril","vym"); // Organization, Application name
56 int statusbarTime=3500;
58 int main(int argc, char* argv[])
60 //Q_INIT_RESOURCE (application);
62 QApplication app(argc,argv);
65 vymVersion=__VYM_VERSION;
66 vymBuildDate=__VYM_BUILD_DATE;
67 vymCodeName=__VYM_CODENAME;
69 // Reading and initializing options commandline options
70 options.add ("debug", Option::Switch, "d", "debug");
71 options.add ("version", Option::Switch, "v","version");
72 options.add ("local", Option::Switch, "l", "local");
73 options.add ("help", Option::Switch, "h", "help");
74 options.add ("quit", Option::Switch, "q", "quit");
75 options.add ("run", Option::String, "r", "run");
76 options.add ("test", Option::String, "t", "test");
78 "VYM - View Your Mind\n"
79 "--------------------\n\n"
80 "Information about vym can be found in vym.pdf,\n"
81 "which should be part of the vym package.\n"
82 "It is also available at the project homepage:\n\n"
83 "http://www.InSilmaril.de/vym\n");
86 cout << endl << qPrintable( options.getHelpText())<<endl;
90 debug=options.isOn ("debug");
92 if (options.isOn ("version"))
94 cout << "VYM - View Your Mind (c) 2004-2009 Uwe Drechsel " << endl
95 <<" Version: "<<__VYM_VERSION <<endl
96 <<"Build date: "<<__VYM_BUILD_DATE << endl
97 <<" "<<__VYM_CODENAME<<endl;
103 if (debug) cout << "PID="<<getpid()<<endl;
104 dbusConnection.registerService (QString ("org.insilmaril.vym-%1").arg(getpid()));
106 // Use /usr/share/vym or /usr/local/share/vym or . ?
108 if (options.isOn ("local"))
110 vymBaseDir.setPath (vymBaseDir.currentDirPath());
112 // then look for environment variable
113 if (getenv("VYMHOME")!=0)
115 vymBaseDir.setPath (getenv("VYMHOME"));
117 // ok, let's find my way on my own
119 #if defined (Q_OS_MACX)
120 vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
122 #elif defined (Q_OS_WIN32)
126 if (GetModuleFileName(NULL, wbuf, 512))
128 QString mfn(QString::fromWCharArray(wbuf));
129 mfn.replace('\\', '/');
130 if (mfn.endsWith("/bin/vym.exe", Qt::CaseInsensitive))
137 if (basePath.isEmpty())
138 basePath = vymBaseDir.currentDirPath();
140 vymInstallDir.setPath(basePath);
141 vymBaseDir.setPath(basePath + "/share/vym");
144 vymBaseDir.setPath ("/usr/share/vym");
145 if (!vymBaseDir.exists())
147 vymBaseDir.setPath ("/usr/local/share/vym");
148 if (!vymBaseDir.exists())
149 vymBaseDir.setPath(vymBaseDir.currentDirPath() );
154 iconPath=vymBaseDir.path()+"/icons/";
155 flagsPath=vymBaseDir.path()+"/flags/";
158 lastImageDir=QDir().current();
159 lastFileDir=QDir().current();
161 if (options.isOn ("help"))
163 cout << qPrintable (options.getHelpText())<<endl;
167 // Initialize translations
168 QTranslator translator (0);
169 translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
170 app.installTranslator( &translator );
172 // Initializing the master rows of flags
173 systemFlagsMaster=new FlagRow;
174 systemFlagsMaster->setName ("systemFlagsMaster");
175 standardFlagsMaster=new FlagRow;
176 standardFlagsMaster->setName ("standardFlagsMaster");
179 // Initialize window of TextEditor
180 textEditor = new TextEditor();
181 textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
183 // Initialize mainwindow
184 #if defined(Q_OS_WIN32)
185 Main m(0, 0, (Qt::Window | Qt::MSWindowsOwnDC));
190 //m.resize(m.sizeHint());
191 m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
194 // Paint Mainwindow first time
195 qApp->processEvents();
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()) );