3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/17/2010 Added this text. :-)
22 #include <qmacstyle_mac.h>
25 QSplashScreen * splash = 0;
28 #include <qsproject.h>
32 #include "patternlist.h"
33 #include "scriptlist.h"
37 #include "filtercxf.h"
38 #include "filterdxf.h"
39 #include "filterdxf1.h"
41 #include "dlginitial.h"
43 #include "applicationwindow.h"
46 # include "filtercam.h"
47 # include "camdialog.h"
50 #ifndef QC_SPLASH_TXTCOL
51 # define QC_SPLASH_TXTCOL Qt::black
54 #ifdef QC_BUILTIN_STYLE
55 extern void applyBuiltinStyle();
59 * Main. Creates Application window.
61 * @todo Switch back to xpm instead of png. (No, we ain't doin' dat. >:-)
62 * Cleaning up #defines.
64 int main(int argc, char * argv[])
66 // Init compiled-in resources
67 Q_INIT_RESOURCE(architektonas);
69 DEBUG->setLevel(Debug::D_WARNING);
70 DEBUG->print("param 0: %s", argv[0]);
72 // avoid . / , confusion on German environments
73 setlocale(LC_ALL, "C");
75 QApplication app(argc, argv);
77 for(int i=0; i<app.argc(); i++)
78 if (QString("--debug") == app.argv()[i])
79 DEBUG->setLevel(Debug::D_DEBUGGING);
81 QFileInfo prgInfo(QFile::decodeName(argv[0]));
82 QString prgDir(prgInfo.absolutePath());
83 //fail SYSTEM->init(QC_APPNAME, QC_VERSION, QC_APPDIR, prgDir);
84 // SYSTEM->init("Architektonas", QC_VERSION, "qcad", prgDir);
85 SYSTEM->init("Architektonas", QC_VERSION, "architektonas", prgDir);
87 FILEIO->registerFilter(new FilterCXF());
88 FILEIO->registerFilter(new FilterDXF());
89 FILEIO->registerFilter(new FilterDXF1());
91 FILEIO->registerFilter(new FilterCAM());
94 // parse command line arguments that might not need a launched program:
95 QStringList fileList = handleArgs(argc, argv);
101 settings.beginGroup("Defaults");
102 #ifndef QC_PREDEFINED_UNIT
103 unit = settings.value("Unit", "Invalid").toString();
105 unit = settings.value("Unit", QC_PREDEFINED_UNIT).toString();
109 // Show initial config dialog if necessary:
110 if (unit == "Invalid")
112 DEBUG->print("main: show initial config dialog..");
114 di.setText("<font size=\"+1\"><b>Welcome to Architektonas</b></font>"
116 "Please choose the unit you want to use for new drawings and your "
117 "preferred language.<br>"
118 "You can changes these settings later in the Options Dialog of Architektonas.");
119 di.setPixmap(QPixmap(":/res/intro.xpm"));
123 settings.beginGroup("Defaults");
124 unit = settings.value("Unit", "None").toString();
128 DEBUG->print("main: show initial config dialog: OK");
131 #ifdef QSPLASHSCREEN_H
132 DEBUG->print("main: splashscreen..");
134 QPixmap * pixmap = new QPixmap(":/res/splash.png");
137 DEBUG->print("main: init fontlist..");
139 DEBUG->print("main: init fontlist: OK");
141 DEBUG->print("main: init patternlist..");
143 DEBUG->print("main: init patternlist: OK");
145 DEBUG->print("main: init scriptlist..");
147 DEBUG->print("main: init scriptlist: OK");
149 DEBUG->print("main: loading translation..");
150 settings.beginGroup("Appearance");
151 #ifdef QC_PREDEFINED_LOCALE
152 lang = settings.value("Language", "").toString();
156 lang = QC_PREDEFINED_LOCALE;
157 settings.setValue("Language", lang);
160 langCmd = settings.value("LanguageCmd", "").toString();
162 if (langCmd.isEmpty())
164 langCmd = QC_PREDEFINED_LOCALE;
165 settings.setValue("LanguageCmd", langCmd);
168 lang = settings.value("Language", "en").toString();
169 langCmd = settings.value("LanguageCmd", "en").toString();
173 SYSTEM->loadTranslation(lang, langCmd);
174 DEBUG->print("main: loading translation: OK");
176 #ifdef QSPLASHSCREEN_H
177 splash = new QSplashScreen(*pixmap);
179 // splash->message(QObject::tr("Loading.."), Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
180 splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
181 DEBUG->print("main: splashscreen: OK");
184 //QApplication::setStyle(new QWindowsStyle());
185 //QApplication::setStyle(new QPlatinumStyle());
187 QApplication::setStyle(new QMacStyle());
190 #ifdef QC_BUILTIN_STYLE //js:
191 DEBUG->print("main: applying built in style..");
195 DEBUG->print("main: creating main window..");
196 ApplicationWindow * appWin = new ApplicationWindow();
197 DEBUG->print("main: setting caption");
198 appWin->setWindowTitle("Architektonas");
199 DEBUG->print("main: show main window");
201 DEBUG->print("main: set focus");
203 DEBUG->print("main: creating main window: OK");
205 #ifdef QSPLASHSCREEN_H
208 DEBUG->print("main: updating splash..");
209 // splash->message(QObject::tr("Loading Library Paths.."),
210 splash->showMessage(QObject::tr("Loading Library Paths.."),
211 Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
212 DEBUG->print("main: processing events");
213 qApp->processEvents();
214 DEBUG->print("main: updating splash: OK");
219 DEBUG->print("main: loading files..");
220 bool filesLoaded = false;
222 for(QStringList::Iterator it=fileList.begin(); it!=fileList.end(); ++it)
224 #ifdef QSPLASHSCREEN_H
227 // splash->message(QObject::tr("Loading File %1..").arg(QDir::convertSeparators(*it)),
228 splash->showMessage(QObject::tr("Loading File %1..").arg(QDir::convertSeparators(*it)),
229 Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL);
230 qApp->processEvents();
233 appWin->slotFileOpen(*it, RS2::FormatUnknown);
237 DEBUG->print("main: loading files: OK");
239 #ifdef QSPLASHSCREEN_H
240 # ifndef QC_DELAYED_SPLASH_SCREEN
243 splash->finish(appWin);
251 // renew: avoid . / , confusion on German environments
252 //setlocale(LC_NUMERIC, "C");
253 setlocale(LC_ALL, "C");
255 DEBUG->print("main: app.exec()");
258 appWin->slotFileNew();
260 appWin->slotRunStartScript();
266 DEBUG->print("main: finished");
272 * Handles command line arguments that might not require a GUI.
274 * @return list of files to load on startup.
276 QStringList handleArgs(int argc, char * argv[])
278 DEBUG->print("main: handling args..");
286 for(int i=1; i<argc; i++)
288 if (QString(argv[i]).startsWith("-") == false)
290 // QString fname = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absFilePath());
291 QString fname = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absoluteFilePath());
294 else if (QString(argv[i]) == "--exit")
299 else if (QString(argv[i]) == "--convert")
304 machine = QString(argv[i]);
307 DEBUG->print(Debug::D_WARNING, "No machine configuration given after --convert. Aborting..");
314 input = QString(argv[i]);
317 DEBUG->print(Debug::D_WARNING, "No input given after --convert. Aborting..");
324 output = QString(argv[i]);
327 DEBUG->print(Debug::D_WARNING, "No output given after --convert. Aborting..");
336 if (machine.isEmpty() == false && input.isEmpty() == false && output.isEmpty() == false)
340 FILEIO->fileImport(gr, input, RS2::FormatUnknown);
341 RS_CamDialog dlg(gr, NULL);
342 dlg.activateMachineGenerator(machine);
345 fc.fileExport(gr, output, RS2::FormatCAM);
352 DEBUG->print("main: handling args: OK");