2 * Copyright (C) 2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "UnityCommandLineParser.h"
22#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"
23#define DEFAULT_GRID_UNIT_PX 8
25UnityCommandLineParser::UnityCommandLineParser(const QCoreApplication &app)
27 m_gridUnit = getenvFloat(ENV_GRID_UNIT_PX, DEFAULT_GRID_UNIT_PX);
29 QCommandLineParser parser;
30 parser.setApplicationDescription(QStringLiteral("Description: Unity 8 Shell"));
31 parser.addHelpOption();
33 QCommandLineOption fullscreenOption(QStringLiteral("fullscreen"),
34 QStringLiteral("Run in fullscreen"));
35 parser.addOption(fullscreenOption);
37 QCommandLineOption framelessOption(QStringLiteral("frameless"),
38 QStringLiteral("Run without window borders"));
39 parser.addOption(framelessOption);
41 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
42 QCommandLineOption mousetouchOption(QStringLiteral("mousetouch"),
43 QStringLiteral("Allow the mouse to provide touch input"));
44 parser.addOption(mousetouchOption);
47 QCommandLineOption windowGeometryOption(QStringList() << QStringLiteral("windowgeometry"),
48 QStringLiteral("Specify the window geometry as [<width>x<height>]"), QStringLiteral("windowgeometry"), QStringLiteral("1"));
49 parser.addOption(windowGeometryOption);
51 QCommandLineOption testabilityOption(QStringLiteral("testability"),
52 QStringLiteral("DISCOURAGED: Please set QT_LOAD_TESTABILITY instead.\nLoad the testability driver"));
53 parser.addOption(testabilityOption);
55 QCommandLineOption devicenameOption(QStringList() << QStringLiteral("devicename"),
56 QStringLiteral("Specify the device name instead of letting Unity 8 find it out"), QStringLiteral("devicename"), QLatin1String(""));
57 parser.addOption(devicenameOption);
59 QCommandLineOption modeOption(QStringLiteral("mode"),
60 QStringLiteral("Whether to run greeter and/or shell [full-greeter, full-shell, greeter, shell]"),
61 QStringLiteral("mode"), QStringLiteral("full-greeter"));
62 parser.addOption(modeOption);
64 QCommandLineOption qmlfileOption(QStringLiteral("qmlfile"),
65 QStringLiteral("The base qml file to load"),
66 QStringLiteral("qmlfile"), ::qmlDirectory() + "/ShellApplication.qml");
67 parser.addOption(qmlfileOption);
69 // Treat args with single dashes the same as arguments with two dashes
70 // Ex: -fullscreen == --fullscreen
71 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
75 if (parser.isSet(windowGeometryOption))
77 QStringList geom = parser.value(windowGeometryOption).split('x');
78 if (geom.count() == 2) {
79 m_windowGeometry.rwidth() = parsePixelsValue(geom[0]);
80 m_windowGeometry.rheight() = parsePixelsValue(geom[1]);
84 m_hasTestability = parser.isSet(testabilityOption);
85 m_hasFrameless = parser.isSet(framelessOption);
87 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
88 m_hasMouseToTouch = parser.isSet(mousetouchOption);
91 m_hasFullscreen = parser.isSet(fullscreenOption);
92 m_deviceName = parser.value(devicenameOption);
93 resolveMode(parser, modeOption);
95 m_qmlfile = parser.value(qmlfileOption);
98int UnityCommandLineParser::parsePixelsValue(const QString &str)
100 if (str.endsWith(QLatin1String("gu"), Qt::CaseInsensitive)) {
101 QString numStr = str;
102 numStr.remove(numStr.size() - 2, 2);
103 return numStr.toInt() * m_gridUnit;
109float UnityCommandLineParser::getenvFloat(const char* name, float defaultValue)
111 QByteArray stringValue = qgetenv(name);
113 float value = stringValue.toFloat(&ok);
114 return ok ? value : defaultValue;
117void UnityCommandLineParser::resolveMode(QCommandLineParser &parser, QCommandLineOption &modeOption)
119 // If an invalid option was specified, set it to the default
120 // If no default was provided in the QCommandLineOption constructor, abort.
121 if (!parser.isSet(modeOption) ||
122 (parser.value(modeOption) != QLatin1String("full-greeter") &&
123 parser.value(modeOption) != QLatin1String("full-shell") &&
124 parser.value(modeOption) != QLatin1String("greeter") &&
125 parser.value(modeOption) != QLatin1String("shell"))) {
127 const QStringList defaultValues = modeOption.defaultValues();
128 if (!defaultValues.isEmpty()) {
129 m_mode = defaultValues.first();
130 qWarning() << "Mode argument was not provided or was set to an illegal value."
131 " Using default value of --mode=" << m_mode;
133 qFatal("Shell mode argument was not provided and there is no default mode.");
136 m_mode = parser.value(modeOption);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list