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"
21#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"
22#define DEFAULT_GRID_UNIT_PX 8
24UnityCommandLineParser::UnityCommandLineParser(const QCoreApplication &app)
26 m_gridUnit = getenvFloat(ENV_GRID_UNIT_PX, DEFAULT_GRID_UNIT_PX);
28 QCommandLineParser parser;
29 parser.setApplicationDescription("Description: Unity 8 Shell");
30 parser.addHelpOption();
32 QCommandLineOption fullscreenOption("fullscreen",
34 parser.addOption(fullscreenOption);
36 QCommandLineOption framelessOption("frameless",
37 "Run without window borders");
38 parser.addOption(framelessOption);
40 QCommandLineOption mousetouchOption("mousetouch",
41 "Allow the mouse to provide touch input");
42 parser.addOption(mousetouchOption);
44 QCommandLineOption windowGeometryOption(QStringList() << "windowgeometry",
45 "Specify the window geometry as [<width>x<height>]", "windowgeometry", "1");
46 parser.addOption(windowGeometryOption);
48 QCommandLineOption testabilityOption("testability",
49 "DISCOURAGED: Please set QT_LOAD_TESTABILITY instead.\nLoad the testability driver");
50 parser.addOption(testabilityOption);
52 QCommandLineOption devicenameOption(QStringList() << "devicename",
53 "Specify the device name instead of letting Unity 8 find it out", "devicename", "");
54 parser.addOption(devicenameOption);
56 QCommandLineOption modeOption("mode",
57 "Whether to run greeter and/or shell [full-greeter, full-shell, greeter, shell]",
58 "mode", "full-greeter");
59 parser.addOption(modeOption);
61 // Treat args with single dashes the same as arguments with two dashes
62 // Ex: -fullscreen == --fullscreen
63 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
67 if (parser.isSet(windowGeometryOption))
69 QStringList geom = parser.value(windowGeometryOption).split('x');
70 if (geom.count() == 2) {
71 m_windowGeometry.rwidth() = parsePixelsValue(geom[0]);
72 m_windowGeometry.rheight() = parsePixelsValue(geom[1]);
76 m_hasTestability = parser.isSet(testabilityOption);
77 m_hasFrameless = parser.isSet(framelessOption);
78 m_hasMouseToTouch = parser.isSet(mousetouchOption);
79 m_hasFullscreen = parser.isSet(fullscreenOption);
80 m_deviceName = parser.value(devicenameOption);
81 resolveMode(parser, modeOption);
84int UnityCommandLineParser::parsePixelsValue(const QString &str)
86 if (str.endsWith("gu", Qt::CaseInsensitive)) {
88 numStr.remove(numStr.size() - 2, 2);
89 return numStr.toInt() * m_gridUnit;
95float UnityCommandLineParser::getenvFloat(const char* name, float defaultValue)
97 QByteArray stringValue = qgetenv(name);
99 float value = stringValue.toFloat(&ok);
100 return ok ? value : defaultValue;
103void UnityCommandLineParser::resolveMode(QCommandLineParser &parser, QCommandLineOption &modeOption)
105 // If an invalid option was specified, set it to the default
106 // If no default was provided in the QCommandLineOption constructor, abort.
107 if (!parser.isSet(modeOption) ||
108 (parser.value(modeOption) != "full-greeter" &&
109 parser.value(modeOption) != "full-shell" &&
110 parser.value(modeOption) != "greeter" &&
111 parser.value(modeOption) != "shell")) {
113 if (modeOption.defaultValues().first() != nullptr) {
114 m_mode = modeOption.defaultValues().first();
115 qWarning() << "Mode argument was not provided or was set to an illegal value."
116 " Using default value of --mode=" << m_mode;
118 qFatal("Shell mode argument was not provided and there is no default mode.");
121 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