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>
31 #include "rs_fontlist.h"
32 #include "rs_patternlist.h"
33 #include "rs_scriptlist.h"
35 #include "rs_system.h"
36 #include "rs_fileio.h"
37 #include "rs_filtercxf.h"
38 #include "rs_filterdxf.h"
39 #include "rs_filterdxf1.h"
41 #include "dlginitial.h"
43 #include "applicationwindow.h"
46 # include "rs_filtercam.h"
47 # include "rs_camdialog.h"
51 //# include "xpm/intro_camexpert.xpm"
52 //# include "xpm/splash_camexpert.xpm"
54 //# include "xpm/intro_qcad.xpm"
55 //# ifndef QC_CUSTOM_SPLASH
56 //# include "xpm/splash_qcad.xpm"
60 #ifndef QC_SPLASH_TXTCOL
61 # define QC_SPLASH_TXTCOL Qt::black
64 #ifdef QC_BUILTIN_STYLE
65 extern void applyBuiltinStyle();
69 * Main. Creates Application window.
71 * @todo Switch back to xpm instead of png. (No, we ain't doin' dat. >:-)
72 * Cleaning up #defines.
74 int main(int argc, char * argv[])
76 // Init compiled-in resources
77 Q_INIT_RESOURCE(architektonas);
79 RS_DEBUG->setLevel(RS_Debug::D_WARNING);
80 RS_DEBUG->print("param 0: %s", argv[0]);
82 // avoid . / , confusion on German environments
83 setlocale(LC_ALL, "C");
85 QApplication app(argc, argv);
87 for(int i=0; i<app.argc(); i++)
88 if (QString("--debug") == app.argv()[i])
89 RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING);
91 QFileInfo prgInfo(QFile::decodeName(argv[0]));
92 QString prgDir(prgInfo.absolutePath());
93 //fail RS_SYSTEM->init(QC_APPNAME, QC_VERSION, QC_APPDIR, prgDir);
94 // RS_SYSTEM->init("Architektonas", QC_VERSION, "qcad", prgDir);
95 RS_SYSTEM->init("Architektonas", QC_VERSION, "architektonas", prgDir);
97 RS_FILEIO->registerFilter(new RS_FilterCXF());
98 RS_FILEIO->registerFilter(new RS_FilterDXF());
99 RS_FILEIO->registerFilter(new RS_FilterDXF1());
101 RS_FILEIO->registerFilter(new RS_FilterCAM());
104 // parse command line arguments that might not need a launched program:
105 QStringList fileList = handleArgs(argc, argv);
111 settings.beginGroup("Defaults");
112 #ifndef QC_PREDEFINED_UNIT
113 unit = settings.value("Unit", "Invalid").toString();
115 unit = settings.value("Unit", QC_PREDEFINED_UNIT).toString();
119 // show initial config dialog:
120 if (unit == "Invalid")
122 RS_DEBUG->print("main: show initial config dialog..");
124 di.setText("<font size=\"+1\"><b>Welcome to Architektonas</b></font>"
126 "Please choose the unit you want to use for new drawings and your "
127 "preferred language.<br>"
128 "You can changes these settings later in the Options Dialog of Architektonas.");
129 // QPixmap pxm(":/res/intro.xpm");
130 // di.setPixmap(pxm);
131 di.setPixmap(QPixmap(":/res/intro.xpm"));
135 settings.beginGroup("Defaults");
136 unit = settings.value("Unit", "None").toString();
140 RS_DEBUG->print("main: show initial config dialog: OK");
143 #ifdef QSPLASHSCREEN_H
144 RS_DEBUG->print("main: splashscreen..");
146 //# ifdef QC_CUSTOM_SPLASH
147 // QPixmap * pixmap = new QPixmap(qPixmapFromMimeSource(QC_CUSTOM_SPLASH));
149 //// QPixmap * pixmap = new QPixmap(":/res/splash.xpm");
150 // QPixmap * pixmap = new QPixmap(":/res/splash_qcad.xpm");
151 QPixmap * pixmap = new QPixmap(":/res/splash.png");
155 splash = new QSplashScreen(*pixmap);
157 splash->message(app.tr("Loading.."),
158 Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL);
159 RS_DEBUG->print("main: splashscreen: OK");
163 RS_DEBUG->print("main: init fontlist..");
165 RS_DEBUG->print("main: init fontlist: OK");
167 RS_DEBUG->print("main: init patternlist..");
168 RS_PATTERNLIST->init();
169 RS_DEBUG->print("main: init patternlist: OK");
171 RS_DEBUG->print("main: init scriptlist..");
172 RS_SCRIPTLIST->init();
173 RS_DEBUG->print("main: init scriptlist: OK");
175 RS_DEBUG->print("main: loading translation..");
176 settings.beginGroup("Appearance");
177 #ifdef QC_PREDEFINED_LOCALE
178 lang = settings.value("Language", "").toString();
182 lang = QC_PREDEFINED_LOCALE;
183 settings.setValue("Language", lang);
186 langCmd = settings.value("LanguageCmd", "").toString();
188 if (langCmd.isEmpty())
190 langCmd = QC_PREDEFINED_LOCALE;
191 settings.setValue("LanguageCmd", langCmd);
194 lang = settings.value("Language", "en").toString();
195 langCmd = settings.value("LanguageCmd", "en").toString();
199 RS_SYSTEM->loadTranslation(lang, langCmd);
200 RS_DEBUG->print("main: loading translation: OK");
202 #ifdef QSPLASHSCREEN_H
203 splash = new QSplashScreen(*pixmap);
205 // splash->message(QObject::tr("Loading.."), Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
206 splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
207 RS_DEBUG->print("main: splashscreen: OK");
210 //QApplication::setStyle(new QWindowsStyle());
211 //QApplication::setStyle(new QPlatinumStyle());
213 QApplication::setStyle(new QMacStyle());
216 #ifdef QC_BUILTIN_STYLE //js:
217 RS_DEBUG->print("main: applying built in style..");
221 RS_DEBUG->print("main: creating main window..");
222 ApplicationWindow * appWin = new ApplicationWindow();
223 RS_DEBUG->print("main: setting caption");
224 appWin->setWindowTitle("Architektonas");
225 RS_DEBUG->print("main: show main window");
227 RS_DEBUG->print("main: set focus");
229 RS_DEBUG->print("main: creating main window: OK");
231 #ifdef QSPLASHSCREEN_H
234 RS_DEBUG->print("main: updating splash..");
235 // splash->message(QObject::tr("Loading Library Paths.."),
236 splash->showMessage(QObject::tr("Loading Library Paths.."),
237 Qt::AlignRight | Qt::AlignBottom, QC_SPLASH_TXTCOL);
238 RS_DEBUG->print("main: processing events");
239 qApp->processEvents();
240 RS_DEBUG->print("main: updating splash: OK");
245 RS_DEBUG->print("main: loading files..");
246 bool files_loaded = false;
248 for(QStringList::Iterator it=fileList.begin(); it!=fileList.end(); ++it)
250 #ifdef QSPLASHSCREEN_H
253 // splash->message(QObject::tr("Loading File %1..").arg(QDir::convertSeparators(*it)),
254 splash->showMessage(QObject::tr("Loading File %1..").arg(QDir::convertSeparators(*it)),
255 Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL);
256 qApp->processEvents();
259 appWin->slotFileOpen(*it, RS2::FormatUnknown);
263 RS_DEBUG->print("main: loading files: OK");
265 //none of this demo shit
267 // QTimer::singleShot(10 * 60 * 1000, appWin, SLOT(slotFileDemoQuit()));
270 #ifdef QSPLASHSCREEN_H
271 # ifndef QC_DELAYED_SPLASH_SCREEN
274 splash->finish(appWin);
282 //app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
284 // renew: avoid . / , confusion on German environments
285 //setlocale(LC_NUMERIC, "C");
286 setlocale(LC_ALL, "C");
288 RS_DEBUG->print("main: app.exec()");
291 appWin->slotFileNew();
293 appWin->slotRunStartScript();
299 RS_DEBUG->print("main: finished");
305 * Handles command line arguments that might not require a GUI.
307 * @return list of files to load on startup.
309 QStringList handleArgs(int argc, char * argv[])
311 RS_DEBUG->print("main: handling args..");
319 for(int i=1; i<argc; i++)
321 if (QString(argv[i]).startsWith("-") == false)
323 // QString fname = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absFilePath());
324 QString fname = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absoluteFilePath());
327 else if (QString(argv[i]) == "--exit")
332 else if (QString(argv[i]) == "--convert")
337 machine = QString(argv[i]);
340 RS_DEBUG->print(RS_Debug::D_WARNING, "No machine configuration given after --convert. Aborting..");
347 input = QString(argv[i]);
350 RS_DEBUG->print(RS_Debug::D_WARNING, "No input given after --convert. Aborting..");
357 output = QString(argv[i]);
360 RS_DEBUG->print(RS_Debug::D_WARNING, "No output given after --convert. Aborting..");
369 if (machine.isEmpty() == false && input.isEmpty() == false && output.isEmpty() == false)
373 RS_FILEIO->fileImport(gr, input, RS2::FormatUnknown);
374 RS_CamDialog dlg(gr, NULL);
375 dlg.activateMachineGenerator(machine);
378 fc.fileExport(gr, output, RS2::FormatCAM);
385 RS_DEBUG->print("main: handling args: OK");