/** * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved. * * This file is part of the QCAD project. * * QCAD is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * QCAD is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with QCAD. */ include("library.js"); include("AddOn.js"); include("scripts/File/OpenFile/OpenFile.js"); include("scripts/File/AutoSave/AutoSave.js"); include("scripts/Tools/arguments.js"); // allow plugins to extend autostart through autostart1.js, autostart2.js, ...: for (var i=1; i<10; i++) { var fn = "scripts/autostart" + i + ".js"; if (new QFileInfo(fn).exists() || new QFileInfo(":/" + fn).exists()) { include(fn); } } /** * Prints version information. */ function version() { print(); print("Version: " + RSettings.getVersionString()); print("Qt Version: " + RSettings.getQtVersionString()); print("Release Date: " + RSettings.getReleaseDate()); print(); } /** * Prints command line usage information on stdout. */ function usage() { print("\nUsage: " + RSettings.getOriginalArguments()[0] + " [Options] [Files to open]\n" + "\n" + "-allow-multiple-instances Don't try to avoid multiple instances from running\n" + " simultaneously.\n" + "-always-load-scripts Forces reloading of scripts when they are used.\n" + " This is mainly useful during script development,\n" + " to apply changes without restarting QCAD.\n" + "-app-id [ID] Set application ID. Multiple instances of the\n" + " same application (same ID) cannot run\n" + " simultaneously unless -allow-multiple-instances\n" + " is used.\n" + "-autostart [script file] Starts the given script file instead of the default\n" + " scripts/autostart.js. Note that with this option,\n" + " QCAD is not started but rather the application \n" + " implemented in the given script.\n" + "-config [path] Reads and stores settings in a configuration file\n" + " at the given location instead of the default location.\n" + "-debug-action-order Print action order information in menus\n" + "-enable-script-debugger Enables the script debugger.\n" + " NOT recommended as this may cause unexpected\n" + " behavior when using QCAD.\n" + "-exec [script file] [options] Executes the given script file directly\n" + " after staring QCAD. Options after the script\n" + " file are passed on to the script.\n" + "-help Displays this help.\n" + "-ignore-script-files Ignore script files on disk.\n" + " Only load scripts from plugins if applicable.\n" + "-locale [locale] Sets the locale to be used (overrides\n" + " the language set in the preferences).\n" + " E.g. '-locale de' starts QCAD in German.\n" + "-no-gui Don't use GUI. X11: don't connect to X11 server.\n" + "-no-show Use but don't display GUI.\n" + "-filter [filter] Opens the subsequent file(s) with the explicitly \n" + " given import filter.\n" + "-font-substitution A B Substitute font A with font B.\n" + "-rescan Rescan scripts folder for new add-ons\n" + "-version Displays the application version.\n" + "-enable-xdata Enables XData (custom properties) support.\n" + "-quit Quits QCAD, for example after executing the\n" + " given script(s).\n" ); printGenericUsage(); print("\n"); } /** * Executes the scripts that are given as arguments of -exec. * \return true if the application should quit after executing the * scripts, false otherwise. */ function execScripts(args) { for (var i = 1; i < args.length; ++i) { if (args[i] === "-exec") { ++i; if (isNull(args[i])) { break; } // check for existing action (e.g. "scripts/File/NewFile/NewFile.js"): var action = RGuiAction.getByScriptFile(args[i]); // script is not an existing action: if (isNull(action)) { // include (run) script which might or might not be action: var scriptFile = args[i]; var scriptFilePath = getAbsolutePathForArg(scriptFile); if (new QFileInfo(scriptFilePath).exists()) { // including the script evaluates (runs) it: include(scriptFilePath); // check if script created a class of same name as file base name: var fi = new QFileInfo(scriptFile); var className = fi.baseName(); if (!isNull(global[className])) { // gui action might not exist yet for this script, create one: action = new RGuiAction(""); action.setScriptFile(scriptFilePath); action.setRequiresDocument(false); } } else { qWarning("script not found: ", args[i]); } } // script is action or created action: if (!isNull(action)) { ++i; // handle script arguments: while (!isNull(args[i]) && args[i] !== "-exec") { action.addArgument(args[i]); ++i; } --i; action.slotTrigger(); } } if (args[i] === "-quit") { RSettings.setQuitFlag(); } } } /** * Sets up drag and drop support (dropping files on the application window * opens them). */ function setUpDragAndDrop(appWin) { appWin.dragEnter.connect(function(event) { event.acceptProposedAction(); }); appWin.drop.connect(function(event) { // workaround for Qt keyboard focus bug: var appWin = RMainWindowQt.getMainWindow(); if (!isNull(appWin)) { appWin.activateWindow(); appWin.raise(); appWin.setFocus(Qt.OtherFocusReason); } var urls = getUrlsFromMimeData(event.mimeData()); var urlStrings = []; for (var i = 0; i < urls.length; ++i) { urlStrings.push(urls[i].toString()); } openFiles(urlStrings, false); event.acceptProposedAction(); }); } /** * Loads translations for all add-ons if appropriate. */ function loadTranslations(addOns, splash) { var locale = RSettings.getLocale(); if (!isNull(splash)) { // no translations yet: splash.showMessage("Loading translations...\n", Qt.AlignBottom); } // load C++ translations: var modules = ["qt", "assistant", "qt_help", "qcadcore", "qcadentity", "qcadgui"]; if (RSettings.isQt(5) || RSettings.isQt(6)) { modules.unshift("qtbase"); } var i; var module; for (var mi=0; mi=args.length) { break; } module = args[i]; if (++i>=args.length) { break; } var dir = args[i]; RSettings.loadTranslations(module, [autoPath(dir)]); } } // RSettings.loadTranslations("scripts", [autoPath("ts")]); // RSettings.loadTranslations("proscripts", [autoPath("../qcadpro/ts")]); // RSettings.loadTranslations("camscripts", [autoPath("../qcadcam/ts")]); // install one QTranslator for each script add-on if available: if (!isNull(splash)) { splash.showMessage(qsTr("Loading add-on translations...") + "\n", Qt.AlignBottom); QCoreApplication.processEvents(); } //RSettings.loadTranslations("Scripts_" + locale, [autoPath("scripts/ts")]); for (i = 0; i < addOns.length; ++i) { var addOn = addOns[i]; if (isNull(addOn)) { qWarning("Null add on found"); continue; } var fi = new QFileInfo(addOn.getPath() + "/ts"); if (!fi.exists()) { // no ts dir: continue; } RSettings.loadTranslations(addOn.getClassName(), [addOn.getPath() + "/ts"]); } } /** * Loads and initializes all add-ons. * * \param addOns array of AddOn objects. * \param splash the splash window for displaying status updates. */ function loadAddOns(addOns, splash) { if (!isNull(splash)) { splash.showMessage(qsTr("Loading add-ons...") + "\n", Qt.AlignBottom); QCoreApplication.processEvents(); } var addOn; var i; for (i=0; i0) { qApp.applicationName = n; } } // if locale is given, don't show first start dialog: if (isFirstStart && !args.contains("-locale")) { include("scripts/Widgets/FirstStart/FirstStart.js"); var first = new FirstStart(); first.showDialog(); } RPluginLoader.initTranslations(); // correct library paths from 'library' to 'libraries': if (RSettings.getIntValue("Application/Version", 0)<=3000008) { var oldDefaultSource = new QFileInfo("library").absoluteFilePath(); var librarySources = RSettings.getValue("LibraryBrowser/SourceList", []); if (!isNull(librarySources)) { for (i=0; imaxPri) { var s = pluginInfo.get(key); if (!isNull(s)) { fn = s; maxPri = pri; } } } var pixmap = new QPixmap(fn); splash = new QSplashScreen(pixmap); splash.objectName = "Splash"; if (!args.contains("-no-show")) { splash.show(); } } RFontList.initSubstitutions(); // mark config file with current version number: var previousVersion = RSettings.getStringValue("Application/Version", ""); RSettings.setValue("Application/Version", RSettings.getNumericalVersionString()); // save first start information: RSettings.setFirstStart(isFirstStart); // save new version information: RSettings.setNewVersion(newVersion); RSettings.setPreviousVersion(parseInt(previousVersion, 10)); RPluginLoader.postInitPlugins(RPluginInterface.GotSplashWindow); // scan for script add-ons (forced for first start, first start after // update, if configured): var addOns; var addOnFilePaths = RSettings.getValue("AddOns/List", []); if (addOnFilePaths.length===0 || newVersion || args.contains("-rescan") || RSettings.getBoolValue("Scripting/Rescan", true)===true) { if (!isNull(splash)) { // no translations yet: splash.showMessage("...\n", Qt.AlignBottom); QCoreApplication.processEvents(); } addOns = AddOn.getAddOns(); var addOnList = []; for (i = 0; i < addOns.length; ++i) { addOnList.push(addOns[i].getFilePath()); } RSettings.setValue("AddOns/List", addOnList); } else { addOns = []; for (i=0; i