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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/17/2010 Added this text. :-)
20 #include <qmacstyle_mac.h>
23 QSplashScreen * splash = 0;
26 #include <qsproject.h>
29 #include "rs_fontlist.h"
30 #include "rs_patternlist.h"
31 #include "rs_scriptlist.h"
33 #include "rs_system.h"
34 #include "rs_fileio.h"
35 #include "rs_filtercxf.h"
36 #include "rs_filterdxf.h"
37 #include "rs_filterdxf1.h"
39 #include "dlginitial.h"
41 #include "qc_applicationwindow.h"
44 # include "rs_filtercam.h"
45 # include "rs_camdialog.h"
49 //# include "xpm/intro_camexpert.xpm"
50 //# include "xpm/splash_camexpert.xpm"
52 //# include "xpm/intro_qcad.xpm"
53 //# ifndef QC_CUSTOM_SPLASH
54 //# include "xpm/splash_qcad.xpm"
58 #ifndef QC_SPLASH_TXTCOL
59 # define QC_SPLASH_TXTCOL Qt::black
62 #ifdef QC_BUILTIN_STYLE
63 extern void applyBuiltinStyle();
67 * Main. Creates Application window.
69 * @todo Switch back to xpm instead of png. (No, we ain't doin' dat. >:-)
70 * Cleaning up #defines.
72 int main(int argc, char * argv[])
74 // Init compiled-in resources
75 Q_INIT_RESOURCE(architektonas);
77 RS_DEBUG->setLevel(RS_Debug::D_WARNING);
78 RS_DEBUG->print("param 0: %s", argv[0]);
80 // avoid . / , confusion on German environments
81 setlocale(LC_ALL, "C");
83 QApplication app(argc, argv);
85 for(int i=0; i<app.argc(); i++)
86 if (QString("--debug") == app.argv()[i])
87 RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING);
89 QFileInfo prgInfo(QFile::decodeName(argv[0]));
90 QString prgDir(prgInfo.absolutePath());
91 //fail RS_SYSTEM->init(QC_APPNAME, QC_VERSION, QC_APPDIR, prgDir);
92 // RS_SYSTEM->init("Architektonas", QC_VERSION, "qcad", prgDir);
93 RS_SYSTEM->init("Architektonas", QC_VERSION, "architektonas", prgDir);
95 RS_FILEIO->registerFilter(new RS_FilterCXF());
96 RS_FILEIO->registerFilter(new RS_FilterDXF());
97 RS_FILEIO->registerFilter(new RS_FilterDXF1());
99 RS_FILEIO->registerFilter(new RS_FilterCAM());
102 // parse command line arguments that might not need a launched program:
103 QStringList fileList = handleArgs(argc, argv);
109 settings.beginGroup("Defaults");
110 #ifndef QC_PREDEFINED_UNIT
111 unit = settings.value("Unit", "Invalid").toString();
113 unit = settings.value("Unit", QC_PREDEFINED_UNIT).toString();
117 // show initial config dialog:
118 if (unit == "Invalid")
120 RS_DEBUG->print("main: show initial config dialog..");
122 di.setText("<font size=\"+1\"><b>Welcome to Architektonas</b></font>"
124 "Please choose the unit you want to use for new drawings and your "
125 "preferred language.<br>"
126 "You can changes these settings later in the Options Dialog of Architektonas.");
127 // QPixmap pxm(":/res/intro.xpm");
128 // di.setPixmap(pxm);
129 di.setPixmap(QPixmap(":/res/intro.xpm"));
133 settings.beginGroup("Defaults");
134 unit = settings.value("Unit", "None").toString();
138 RS_DEBUG->print("main: show initial config dialog: OK");
141 #ifdef QSPLASHSCREEN_H
142 RS_DEBUG->print("main: splashscreen..");
144 //# ifdef QC_CUSTOM_SPLASH
145 // QPixmap * pixmap = new QPixmap(qPixmapFromMimeSource(QC_CUSTOM_SPLASH));
147 //// QPixmap * pixmap = new QPixmap(":/res/splash.xpm");
148 QPixmap * pixmap = new QPixmap(":/res/splash_qcad.xpm");
152 splash = new QSplashScreen(*pixmap);
154 splash->message(app.tr("Loading.."),
155 Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL);
156 RS_DEBUG->print("main: splashscreen: OK");
160 RS_DEBUG->print("main: init fontlist..");
162 RS_DEBUG->print("main: init fontlist: OK");
164 RS_DEBUG->print("main: init patternlist..");
165 RS_PATTERNLIST->init();
166 RS_DEBUG->print("main: init patternlist: OK");
168 RS_DEBUG->print("main: init scriptlist..");
169 RS_SCRIPTLIST->init();
170 RS_DEBUG->print("main: init scriptlist: OK");
172 RS_DEBUG->print("main: loading translation..");
173 settings.beginGroup("Appearance");
174 #ifdef QC_PREDEFINED_LOCALE
175 lang = settings.value("Language", "").toString();
179 lang = QC_PREDEFINED_LOCALE;
180 settings.setValue("Language", lang);
183 langCmd = settings.value("LanguageCmd", "").toString();
185 if (langCmd.isEmpty())
187 langCmd = QC_PREDEFINED_LOCALE;
188 settings.setValue("LanguageCmd", langCmd);
191 lang = settings.value("Language", "en").toString();
192 langCmd = settings.value("LanguageCmd", "en").toString();
196 RS_SYSTEM->loadTranslation(lang, langCmd);
197 RS_DEBUG->print("main: loading translation: OK");
199 #ifdef QSPLASHSCREEN_H
200 splash = new QSplashScreen(*pixmap);
202 // splash->message(QObject::tr("Loading.."), Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
203 splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
204 RS_DEBUG->print("main: splashscreen: OK");
207 //QApplication::setStyle(new QWindowsStyle());
208 //QApplication::setStyle(new QPlatinumStyle());
210 QApplication::setStyle(new QMacStyle());
213 #ifdef QC_BUILTIN_STYLE //js:
214 RS_DEBUG->print("main: applying built in style..");
218 RS_DEBUG->print("main: creating main window..");
219 QC_ApplicationWindow * appWin = new QC_ApplicationWindow();
220 RS_DEBUG->print("main: setting caption");
221 appWin->setWindowTitle("Architektonas");
222 RS_DEBUG->print("main: show main window");
224 RS_DEBUG->print("main: set focus");
226 RS_DEBUG->print("main: creating main window: OK");
228 #ifdef QSPLASHSCREEN_H
231 RS_DEBUG->print("main: updating splash..");
232 // splash->message(QObject::tr("Loading Library Paths.."),
233 splash->showMessage(QObject::tr("Loading Library Paths.."),
234 Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
235 RS_DEBUG->print("main: processing events");
236 qApp->processEvents();
237 RS_DEBUG->print("main: updating splash: OK");
242 RS_DEBUG->print("main: loading files..");
243 bool files_loaded = false;
245 for(QStringList::Iterator it=fileList.begin(); it!=fileList.end(); ++it)
247 #ifdef QSPLASHSCREEN_H
250 // splash->message(QObject::tr("Loading File %1..").arg(QDir::convertSeparators(*it)),
251 splash->showMessage(QObject::tr("Loading File %1..").arg(QDir::convertSeparators(*it)),
252 Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL);
253 qApp->processEvents();
256 appWin->slotFileOpen(*it, RS2::FormatUnknown);
260 RS_DEBUG->print("main: loading files: OK");
262 //none of this demo shit
264 // QTimer::singleShot(10 * 60 * 1000, appWin, SLOT(slotFileDemoQuit()));
267 #ifdef QSPLASHSCREEN_H
268 # ifndef QC_DELAYED_SPLASH_SCREEN
271 splash->finish(appWin);
279 //app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
281 // renew: avoid . / , confusion on German environments
282 //setlocale(LC_NUMERIC, "C");
283 setlocale(LC_ALL, "C");
285 RS_DEBUG->print("main: app.exec()");
288 appWin->slotFileNew();
290 appWin->slotRunStartScript();
296 RS_DEBUG->print("main: finished");
302 * Handles command line arguments that might not require a GUI.
304 * @return list of files to load on startup.
306 QStringList handleArgs(int argc, char * argv[])
308 RS_DEBUG->print("main: handling args..");
316 for(int i=1; i<argc; i++)
318 if (QString(argv[i]).startsWith("-") == false)
320 // QString fname = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absFilePath());
321 QString fname = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absoluteFilePath());
324 else if (QString(argv[i]) == "--exit")
329 else if (QString(argv[i]) == "--convert")
334 machine = QString(argv[i]);
337 RS_DEBUG->print(RS_Debug::D_WARNING, "No machine configuration given after --convert. Aborting..");
344 input = QString(argv[i]);
347 RS_DEBUG->print(RS_Debug::D_WARNING, "No input given after --convert. Aborting..");
354 output = QString(argv[i]);
357 RS_DEBUG->print(RS_Debug::D_WARNING, "No output given after --convert. Aborting..");
366 if (machine.isEmpty() == false && input.isEmpty() == false && output.isEmpty() == false)
370 RS_FILEIO->fileImport(gr, input, RS2::FormatUnknown);
371 RS_CamDialog dlg(gr, NULL);
372 dlg.activateMachineGenerator(machine);
375 fc.fileExport(gr, output, RS2::FormatCAM);
382 RS_DEBUG->print("main: handling args: OK");