File indexing completed on 2024-05-12 16:39:36

0001 /* This file is part of the KDE project
0002    Copyright (C) 2002, 2003 Lucijan Busch <lucijan@gmx.at>
0003    Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org>
0004    Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #include "KexiCommandLineOptions.h"
0023 #include "config-kexi.h"
0024 
0025 #include <KAboutData>
0026 #include <KLocalizedString>
0027 #include <KUser>
0028 
0029 #include <QCoreApplication>
0030 #include <QCommandLineParser>
0031 
0032 KexiCommandLineOptions::KexiCommandLineOptions( QCommandLineParser *parser)
0033     // NOTE: REMEMBER TO ADD NEW OPTIONS IN KexiStartupData::parseOptions()
0034 
0035     // Options related to entire projects:
0036     : createDb("createdb",
0037         xi18nc("'createdb' command line option",
0038                "Create a new, blank project using specified database driver and database "
0039                "name and exit immediately. You will be asked for confirmation if "
0040                "overwriting is needed.")),
0041     createAndOpenDb("create-opendb",
0042         xi18nc("'create-opendb' command line option",
0043                "Like --createdb, but also open newly created database.")),
0044     dropDb("dropdb",
0045         xi18nc("'dropdb' command line option",
0046                "Drop (remove) a project using specified database driver and database name. "
0047                "You will be asked for confirmation.")),
0048     dbDriver(QStringList() << "drv" << "dbdriver",
0049        xi18nc("'dbdriver' command line option",
0050               "Name of a database driver to be used when connecting to a database project "
0051               "(\"sqlite\" by default). Ignored if a shortcut filename is provided. "
0052               "Complete KDb-specific globally unique identifier can be used, "
0053               "e.g. \"org.kde.kdb.sqlite\" to specify exact vendor of the driver."),
0054        "name_or_id"),
0055     fileType(QStringList() << "t" << "type",
0056         xi18nc("'type' command line option",
0057                "Specify the type of file provided as an argument. This option is only "
0058                "useful if the filename does not have a valid extension set and its type "
0059                "cannot be determined unambiguously by examining its contents. This option "
0060                "is ignored if no file is specified as an argument.\n"
0061                "Available file types are:\n"
0062                "- \"project\" for a project file (the default)\n"
0063                "- \"shortcut\" for a shortcut file pointing to a\n"
0064                "  project.\n"
0065                "- \"connection\" for database connection data."),
0066         "name"),
0067     connectionShortcut(QStringList() << "conn" << "connection",
0068         xi18nc("'connection' command line option",
0069                "Specify a database connection shortcut .kexic file containing connection data. "
0070                "Can be used with --createdb or --create-opendb for convenience instead "
0071                "of using options such as --user, --host or --port.\n"
0072                "Note: Options like --user, --host have precedence over settings defined "
0073                "in the shortcut file."),
0074         "shortcut_filename"),
0075     readOnly("readonly",
0076         xi18nc("'readonly' command line option",
0077                "Specify that any database connections will be performed without write support. "
0078                "This option is ignored when \"createdb\" option is present, otherwise the "
0079                "database could not be created.")),
0080     userMode("user-mode",
0081         xi18nc("'user-mode' command line option",
0082                "Start project in User Mode, regardless of the project settings.")),
0083     designMode("design-mode",
0084         xi18nc("'design-mode' command line option",
0085                "Start project in Design Mode, regardless of the project settings.")),
0086     showNavigator("show-navigator",
0087         xi18nc("'show-navigator' command line option",
0088                "Show the Project Navigator side pane even if Kexi runs in User Mode.")),
0089     hideMenu("hide-menu",
0090         xi18nc("'hide-menu' command line option",
0091                "Hide the main menu (the tabbed toolbar) completely. A number of commands "
0092                "from the main menu is still visible. This option is useful in User Mode.")),
0093 
0094     // Options related to opening objects within a project:
0095     open("open",
0096         xi18nc("'open' command line option",
0097                "Open object of type 'object_type' and name 'object_name' from specified "
0098                "project on application start. 'object_type' is optional, if omitted - %1 "
0099                "type is assumed. Other object types can be %2, %3, %4, %5. "
0100                "There may by more or less types available depending on Kexi plugins "
0101                "installed.\n"
0102                "Use \"\" characters to specify names containing spaces.\n"
0103                "Examples: --open MyTable, --open %2:\"My very big query\"",
0104                "table", "query", "form", "report", "script"),
0105         "[object_type:]object_name"),
0106     design("design",
0107         xi18nc("'design' command line option",
0108                "Like --open, but the object will be opened in Design Mode, if one is available."),
0109         "[object_type:]object_name"),
0110     editText("edittext",
0111         xi18nc("'edittext' command line option",
0112                "Like --open, but the object will be opened in Text Mode, if one is available."),
0113         "[object_type:]object_name"),
0114     execute(QStringList() << "execute" << "exec",
0115         xi18nc("'execute' command line option",
0116                "Start execution of object of type 'object_type' and name 'object_name' on "
0117                "application start. 'object_type' is optional, if omitted - %1 type is "
0118                "assumed. Object type can be also %2. There may by more or less types "
0119                "available depending on Kexi plugins installed.\n"
0120                "Use \"\" characters to specify names containing spaces.",
0121                "macro", "script"),
0122         "[object_type:]object_name"),
0123     newObject("new",
0124         xi18nc("'new' command line option",
0125                "Start design of a new object of type 'object_type'."),
0126                "object_type"),
0127     print("print",
0128         xi18nc("'print' command line option",
0129                "Open the Print dialog window for an object of type 'object_type' and "
0130                "name 'object_name' in the specified project when the application starts "
0131                "for quick printing of the object's data. 'object_type' is optional; "
0132                "if omitted, %1 type is assumed. Object type can also be %2.",
0133                "table", "query"),
0134         "[object_type:]object_name"),
0135     printPreview("print-preview",
0136         xi18nc("'print-preview' command line option",
0137                "Open the Print Preview window for an object of type 'object_type' and "
0138                "name 'object_name' in the specified project when the application starts "
0139                "to see preview of the object's data printout. 'object_type' is optional; "
0140                "if omitted, %1 type is assumed. Object type can also be %2.",
0141                "table", "query"),
0142         "[object_type:]object_name"),
0143 
0144     // Options related to database servers:
0145     user(QStringList() << "u" << "user",
0146         xi18nc("'user' command line option",
0147                "Database server's user name when connecting to a project. Ignored if the "
0148                "project is opened using a shortcut file. Default user name is the same "
0149                "as the current login (<resource>%1</resource>).",
0150                KUser().loginName())),
0151 //! @todo re-add '-h' as soon as KAboutData::setupCommandLine() stops forcibly call parser->addHelpOption()
0152     host(QStringList() /*<< "h"*/ << "host",
0153         xi18nc("'host' command line option",
0154                "Network server's (host) name to be used when connecting to a database "
0155                "project. Ignored if the project is opened using a shortcut file. Default "
0156                "host is the local computer."),
0157         "name"),
0158     port("port",
0159         xi18nc("'port' command line option",
0160                "Network server's port number to be used when connecting to a database "
0161                "project. Ignored if the project is opened using a shortcut file. "
0162                "Defaults depend on the used server type (e.g. %1, %2).",
0163                "MySQL", "PostgreSQL"),
0164         "number"),
0165     localSocket(QStringList() << "socket" << "local-socket",
0166         xi18nc("'local-socket' command line option",
0167                "Local computer's socket filename to be used when connecting to "
0168                "a database project. Ignored if the project is opened using a shortcut file. "
0169                "Defaults depend on the used server type (e.g. %1, %2).",
0170                "MySQL", "PostgreSQL"),
0171         "filename"),
0172 
0173     // Options related to the GUI:
0174     skipConnDialog("skip-conn-dialog",
0175         xi18nc("'skip-conn-dialog' command line option",
0176                "Skip displaying connection dialog window and connect directly. Available "
0177                "when opening .kexic or .kexis shortcut files.")),
0178     fullScreen(QStringList() << "f" << "fullscreen",
0179         xi18nc("'fullscreen' command line option",
0180                "Start Kexi in full screen mode to occupy the whole screen area by hiding "
0181                "window decorations such as title bars.")),
0182 
0183     // Options that display configuration or state of Kexi installation.
0184     // When used, Kexi immediately exits without showing the GUI even if other options
0185     // or arguments are present.
0186     listPlugins("list-plugins",
0187       xi18nc("'list-plugins' command line option",
0188              "Displays list of plugins available for Kexi with their name, description, "
0189              "version and filenames."))
0190 {
0191      Q_UNUSED(parser);
0192 }
0193 
0194 QList<QCommandLineOption> KexiCommandLineOptions::autoopeningObjectsOptions() const
0195 {
0196     return {open, design, editText, execute, newObject
0197 #ifdef KEXI_QUICK_PRINTING_SUPPORT
0198             , print, printPreview
0199 #endif
0200     };
0201 }