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 "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");
149 QPixmap * pixmap = new QPixmap(":/res/splash.png");
153 splash = new QSplashScreen(*pixmap);
155 splash->message(app.tr("Loading.."),
156 Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL);
157 RS_DEBUG->print("main: splashscreen: OK");
161 RS_DEBUG->print("main: init fontlist..");
163 RS_DEBUG->print("main: init fontlist: OK");
165 RS_DEBUG->print("main: init patternlist..");
166 RS_PATTERNLIST->init();
167 RS_DEBUG->print("main: init patternlist: OK");
169 RS_DEBUG->print("main: init scriptlist..");
170 RS_SCRIPTLIST->init();
171 RS_DEBUG->print("main: init scriptlist: OK");
173 RS_DEBUG->print("main: loading translation..");
174 settings.beginGroup("Appearance");
175 #ifdef QC_PREDEFINED_LOCALE
176 lang = settings.value("Language", "").toString();
180 lang = QC_PREDEFINED_LOCALE;
181 settings.setValue("Language", lang);
184 langCmd = settings.value("LanguageCmd", "").toString();
186 if (langCmd.isEmpty())
188 langCmd = QC_PREDEFINED_LOCALE;
189 settings.setValue("LanguageCmd", langCmd);
192 lang = settings.value("Language", "en").toString();
193 langCmd = settings.value("LanguageCmd", "en").toString();
197 RS_SYSTEM->loadTranslation(lang, langCmd);
198 RS_DEBUG->print("main: loading translation: OK");
200 #ifdef QSPLASHSCREEN_H
201 splash = new QSplashScreen(*pixmap);
203 // splash->message(QObject::tr("Loading.."), Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
204 splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
205 RS_DEBUG->print("main: splashscreen: OK");
208 //QApplication::setStyle(new QWindowsStyle());
209 //QApplication::setStyle(new QPlatinumStyle());
211 QApplication::setStyle(new QMacStyle());
214 #ifdef QC_BUILTIN_STYLE //js:
215 RS_DEBUG->print("main: applying built in style..");
219 RS_DEBUG->print("main: creating main window..");
220 ApplicationWindow * appWin = new ApplicationWindow();
221 RS_DEBUG->print("main: setting caption");
222 appWin->setWindowTitle("Architektonas");
223 RS_DEBUG->print("main: show main window");
225 RS_DEBUG->print("main: set focus");
227 RS_DEBUG->print("main: creating main window: OK");
229 #ifdef QSPLASHSCREEN_H
232 RS_DEBUG->print("main: updating splash..");
233 // splash->message(QObject::tr("Loading Library Paths.."),
234 splash->showMessage(QObject::tr("Loading Library Paths.."),
235 Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
236 RS_DEBUG->print("main: processing events");
237 qApp->processEvents();
238 RS_DEBUG->print("main: updating splash: OK");
243 RS_DEBUG->print("main: loading files..");
244 bool files_loaded = false;
246 for(QStringList::Iterator it=fileList.begin(); it!=fileList.end(); ++it)
248 #ifdef QSPLASHSCREEN_H
251 // splash->message(QObject::tr("Loading File %1..").arg(QDir::convertSeparators(*it)),
252 splash->showMessage(QObject::tr("Loading File %1..").arg(QDir::convertSeparators(*it)),
253 Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL);
254 qApp->processEvents();
257 appWin->slotFileOpen(*it, RS2::FormatUnknown);
261 RS_DEBUG->print("main: loading files: OK");
263 //none of this demo shit
265 // QTimer::singleShot(10 * 60 * 1000, appWin, SLOT(slotFileDemoQuit()));
268 #ifdef QSPLASHSCREEN_H
269 # ifndef QC_DELAYED_SPLASH_SCREEN
272 splash->finish(appWin);
280 //app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
282 // renew: avoid . / , confusion on German environments
283 //setlocale(LC_NUMERIC, "C");
284 setlocale(LC_ALL, "C");
286 RS_DEBUG->print("main: app.exec()");
289 appWin->slotFileNew();
291 appWin->slotRunStartScript();
297 RS_DEBUG->print("main: finished");
303 * Handles command line arguments that might not require a GUI.
305 * @return list of files to load on startup.
307 QStringList handleArgs(int argc, char * argv[])
309 RS_DEBUG->print("main: handling args..");
317 for(int i=1; i<argc; i++)
319 if (QString(argv[i]).startsWith("-") == false)
321 // QString fname = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absFilePath());
322 QString fname = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absoluteFilePath());
325 else if (QString(argv[i]) == "--exit")
330 else if (QString(argv[i]) == "--convert")
335 machine = QString(argv[i]);
338 RS_DEBUG->print(RS_Debug::D_WARNING, "No machine configuration given after --convert. Aborting..");
345 input = QString(argv[i]);
348 RS_DEBUG->print(RS_Debug::D_WARNING, "No input given after --convert. Aborting..");
355 output = QString(argv[i]);
358 RS_DEBUG->print(RS_Debug::D_WARNING, "No output given after --convert. Aborting..");
367 if (machine.isEmpty() == false && input.isEmpty() == false && output.isEmpty() == false)
371 RS_FILEIO->fileImport(gr, input, RS2::FormatUnknown);
372 RS_CamDialog dlg(gr, NULL);
373 dlg.activateMachineGenerator(machine);
376 fc.fileExport(gr, output, RS2::FormatCAM);
383 RS_DEBUG->print("main: handling args: OK");