1 #include <QApplication>
7 #include "flagrowobj.h"
8 #include "mainwindow.h"
13 #if defined(Q_OS_WIN32)
14 #define WIN32_LEAN_AND_MEAN
19 TextEditor *textEditor; // used in Constr. of LinkableMapObj
20 // initialized in mainwindow
26 Main *mainWindow; // used in BranchObj::select()
27 QString tmpVymDir; // All temp files go there, created in mainwindow
28 QString clipboardDir; // Clipboard used in all mapEditors
29 QString clipboardFile; // Clipboard used in all mapEditors
30 QDir vymBaseDir; // Containing all styles, scripts, images, ...
33 #if defined(Q_OS_WIN32)
36 QString iconPath; // Pointing to icons used for toolbars
37 QString flagsPath; // Pointing to flags
39 bool debug; // global debugging flag
40 FlagRow *systemFlagsMaster;
41 FlagRow *standardFlagsMaster;
43 Settings settings ("InSilmaril","vym"); // Organization, Application name
48 int statusbarTime=3500;
50 int main(int argc, char* argv[])
52 //Q_INIT_RESOURCE (application);
54 QApplication app(argc,argv);
57 vymVersion=__VYM_VERSION;
58 vymBuildDate=__VYM_BUILD_DATE;
59 vymCodeName=__VYM_CODENAME;
62 // Reading and initializing options commandline options
63 options.add ("debug", Option::Switch, "d", "debug");
64 options.add ("version", Option::Switch, "v","version");
65 options.add ("local", Option::Switch, "l", "local");
66 options.add ("help", Option::Switch, "h", "help");
67 options.add ("quit", Option::Switch, "q", "quit");
68 options.add ("run", Option::String, "r", "run");
69 options.add ("test", Option::String, "t", "test");
71 "VYM - View Your Mind\n"
72 "--------------------\n\n"
73 "Information about vym can be found in vym.pdf,\n"
74 "which should be part of the vym package.\n"
75 "It is also available at the project homepage:\n\n"
76 "http://www.InSilmaril.de/vym\n");
79 cout << endl << qPrintable( options.getHelpText())<<endl;
83 debug=options.isOn ("debug");
85 if (options.isOn ("version"))
87 cout << "VYM - View Your Mind (c) 2004-2007 Uwe Drechsel " << endl
88 <<" Version: "<<__VYM_VERSION <<endl
89 <<"Build date: "<<__VYM_BUILD_DATE << endl
90 <<" "<<__VYM_CODENAME<<endl;
95 // Use /usr/share/vym or /usr/local/share/vym or . ?
97 if (options.isOn ("local"))
99 vymBaseDir.setPath (vymBaseDir.currentDirPath());
101 // then look for environment variable
102 if (getenv("VYMHOME")!=0)
104 vymBaseDir.setPath (getenv("VYMHOME"));
106 // ok, let's find my way on my own
108 #if defined (Q_OS_MACX)
109 vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
111 #elif defined (Q_OS_WIN32)
115 if (GetModuleFileName(NULL, wbuf, 512))
117 QString mfn(QString::fromWCharArray(wbuf));
118 mfn.replace('\\', '/');
119 if (mfn.endsWith("/bin/vym.exe", Qt::CaseInsensitive))
126 if (basePath.isEmpty())
127 basePath = vymBaseDir.currentDirPath();
129 vymInstallDir.setPath(basePath);
130 vymBaseDir.setPath(basePath + "/share/vym");
133 vymBaseDir.setPath ("/usr/share/vym");
134 if (!vymBaseDir.exists())
136 vymBaseDir.setPath ("/usr/local/share/vym");
137 if (!vymBaseDir.exists())
138 vymBaseDir.setPath(vymBaseDir.currentDirPath() );
143 iconPath=vymBaseDir.path()+"/icons/";
144 flagsPath=vymBaseDir.path()+"/flags/";
147 lastImageDir=QDir().current();
148 lastFileDir=QDir().current();
150 if (options.isOn ("help"))
152 cout << qPrintable (options.getHelpText())<<endl;
156 // Initialize translations
157 QTranslator translator (0);
158 translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
159 app.installTranslator( &translator );
161 // Initializing the master rows of flags
162 systemFlagsMaster=new FlagRow;
163 systemFlagsMaster->setName ("systemFlagsMaster");
164 standardFlagsMaster=new FlagRow;
165 standardFlagsMaster->setName ("standardFlagsMaster");
168 // Initialize window of TextEditor
169 textEditor = new TextEditor();
170 textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
172 // Initialize mainwindow
173 #if defined(Q_OS_WIN32)
174 Main m(0, 0, (Qt::Window | Qt::MSWindowsOwnDC));
179 //m.resize(m.sizeHint());
180 m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
185 // Paint Mainwindow first time
186 qApp->processEvents();
191 if (options.isOn ("run"))
194 QString fn=options.getArg ("run");
198 if ( !f.open( QIODevice::ReadOnly ) )
200 QMessageBox::warning(0,
201 QObject::tr("Error"),
202 QObject::tr("Couldn't open %1.\n").arg(fn));
206 QTextStream ts( &f );
209 m.setScript (script);
210 m.runScriptEverywhere (script);
214 // For benchmarking we may want to quit instead of entering event loop
215 if (options.isOn ("quit"))
220 QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );