1 #include <QApplication>
3 #include "flagrowobj.h"
4 #include "mainwindow.h"
9 #if defined(Q_OS_WIN32)
10 #define WIN32_LEAN_AND_MEAN
15 TextEditor *textEditor; // used in Constr. of LinkableMapObj
16 // initialized in mainwindow
22 Main *mainWindow; // used in BranchObj::select()
23 QString tmpVymDir; // All temp files go there, created in mainwindow
24 QString clipboardDir; // Clipboard used in all mapEditors
25 QString clipboardFile; // Clipboard used in all mapEditors
26 QDir vymBaseDir; // Containing all styles, scripts, images, ...
29 #if defined(Q_OS_WIN32)
32 QString iconPath; // Pointing to icons used for toolbars
33 QString flagsPath; // Pointing to flags
35 bool debug; // global debugging flag
36 FlagRowObj *systemFlagsDefault; // used to copy from in LinkableMapObj
37 FlagRowObj *standardFlagsDefault;
40 Settings settings ("InSilmaril","vym"); // Organization, Application name
45 int statusbarTime=3500;
47 int main(int argc, char* argv[])
49 //Q_INIT_RESOURCE (application);
51 QApplication app(argc,argv);
54 vymVersion=__VYM_VERSION;
55 vymBuildDate=__VYM_BUILD_DATE;
56 vymCodeName=__VYM_CODENAME;
59 // Reading and initializing options commandline options
60 options.add ("debug", Option::Switch, "d", "debug");
61 options.add ("version", Option::Switch, "v","version");
62 options.add ("local", Option::Switch, "l", "local");
63 options.add ("help", Option::Switch, "h", "help");
64 options.add ("quit", Option::Switch, "q", "quit");
65 options.add ("run", Option::String, "r", "run");
66 options.add ("test", Option::String, "t", "test");
68 "VYM - View Your Mind\n"
69 "--------------------\n\n"
70 "Information about vym can be found in vym.pdf,\n"
71 "which should be part of the vym package.\n"
72 "It is also available at the project homepage:\n\n"
73 "http://www.InSilmaril.de/vym\n");
76 cout << endl << options.getHelpText().ascii()<<endl;
80 debug=options.isOn ("debug");
82 if (options.isOn ("version"))
84 cout << "VYM - View Your Mind (c) 2004-2007 Uwe Drechsel " << endl
85 <<" Version: "<<__VYM_VERSION <<endl
86 <<"Build date: "<<__VYM_BUILD_DATE << endl
87 <<" "<<__VYM_CODENAME<<endl;
92 // Use /usr/share/vym or /usr/local/share/vym or . ?
94 if (options.isOn ("local"))
96 vymBaseDir.setPath (vymBaseDir.currentDirPath());
98 // then look for environment variable
99 if (getenv("VYMHOME")!=0)
101 vymBaseDir.setPath (getenv("VYMHOME"));
103 // ok, let's find my way on my own
105 #if defined (Q_OS_MACX)
106 vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
108 #elif defined (Q_OS_WIN32)
112 if (GetModuleFileName(NULL, wbuf, 512))
114 QString mfn(QString::fromWCharArray(wbuf));
115 mfn.replace('\\', '/');
116 if (mfn.endsWith("/bin/vym.exe", Qt::CaseInsensitive))
123 if (basePath.isEmpty())
124 basePath = vymBaseDir.currentDirPath();
126 vymInstallDir.setPath(basePath);
127 vymBaseDir.setPath(basePath + "/share/vym");
130 vymBaseDir.setPath ("/usr/share/vym");
131 if (!vymBaseDir.exists())
133 vymBaseDir.setPath ("/usr/local/share/vym");
134 if (!vymBaseDir.exists())
135 vymBaseDir.setPath(vymBaseDir.currentDirPath() );
140 iconPath=vymBaseDir.path()+"/icons/";
141 flagsPath=vymBaseDir.path()+"/flags/";
144 lastImageDir=QDir().current();
145 lastFileDir=QDir().current();
147 if (options.isOn ("help"))
149 cout << options.getHelpText().ascii()<<endl;
153 // Initialize translations
154 QTranslator translator (0);
155 translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
156 app.installTranslator( &translator );
158 // Initializing the row of system flags
159 // is done in first call to MapEditor(),
160 // because we need at least one canvas first
161 systemFlagsDefault=NULL;
162 standardFlagsDefault=NULL;
164 // Initialize window of TextEditor
165 textEditor = new TextEditor();
166 textEditor->setIcon (QPixmap (iconPath+"vym-editor.png"));
168 // Initialize mainwindow
169 #if defined(Q_OS_WIN32)
170 Main m(0, 0, (Qt::Window | Qt::MSWindowsOwnDC));
175 //m.resize(m.sizeHint());
176 m.setIcon (QPixmap (iconPath+"vym-48x48.png"));
182 if (options.isOn ("run"))
185 QString fn=options.getArg ("run");
189 if ( !f.open( QIODevice::ReadOnly ) )
191 QMessageBox::warning(0,
192 QObject::tr("Error"),
193 QObject::tr("Couldn't open %1.\n").arg(fn));
197 QTextStream ts( &f );
200 m.setScript (script);
201 m.runScriptEverywhere (script);
205 // For benchmarking we may want to quit instead of entering event loop
206 if (options.isOn ("quit"))
211 QObject::connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );