Exemplo n.º 1
0
void CLIProcessor::parseCLIArgsPostConfig(const QStringList& argList, QSettings* confSettings)
{
	// Over-ride config file options with command line options
	// We should catch exceptions from argsGetOptionWithArg...
	int fullScreen, altitude;
	float fov;
	QString landscapeId, homePlanet, longitude, latitude, skyDate, skyTime;
	QString projectionType, screenshotDir, multiresImage, startupScript;
	QString lgmode, lgport;
	int lgoffset;
	try
	{
		bool dumpOpenGLDetails = argsGetOption(argList, "-d", "--dump-opengl-details");
		qApp->setProperty("dump_OpenGL_details", dumpOpenGLDetails);
		fullScreen = argsGetYesNoOption(argList, "-f", "--full-screen", -1);
		landscapeId = argsGetOptionWithArg(argList, "", "--landscape", "").toString();
		homePlanet = argsGetOptionWithArg(argList, "", "--home-planet", "").toString();
		altitude = argsGetOptionWithArg(argList, "", "--altitude", -1).toInt();
		longitude = argsGetOptionWithArg(argList, "", "--longitude", "").toString();
		latitude = argsGetOptionWithArg(argList, "", "--latitude", "").toString();
		skyDate = argsGetOptionWithArg(argList, "", "--sky-date", "").toString();
		skyTime = argsGetOptionWithArg(argList, "", "--sky-time", "").toString();
		fov = argsGetOptionWithArg(argList, "", "--fov", -1.f).toFloat();
		projectionType = argsGetOptionWithArg(argList, "", "--projection-type", "").toString();
		screenshotDir = argsGetOptionWithArg(argList, "", "--screenshot-dir", "").toString();
		multiresImage = argsGetOptionWithArg(argList, "", "--multires-image", "").toString();
		startupScript = argsGetOptionWithArg(argList, "", "--startup-script", "").toString();
		lgmode = argsGetOptionWithArg(argList, "", "--lg", "").toString();
		lgoffset = argsGetOptionWithArg(argList, "", "--lg-offset", 0).toInt();
		lgport = argsGetOptionWithArg(argList, "", "--lg-port", "5000").toString();
	}
	catch (std::runtime_error& e)
	{
		qCritical() << "ERROR while checking command line options: " << e.what();
		exit(0);
	}

	// Will be -1 if option is not found, in which case we don't change anything.
	if (fullScreen==1)
		confSettings->setValue("video/fullscreen", true);
	else if (fullScreen==0)
		confSettings->setValue("video/fullscreen", false);
	if (!landscapeId.isEmpty()) confSettings->setValue("location_run_once/landscape_name", landscapeId);
	if (!homePlanet.isEmpty()) confSettings->setValue("location_run_once/home_planet", homePlanet);
	if (altitude!=-1) confSettings->setValue("location_run_once/altitude", altitude);
	if (!longitude.isEmpty()) confSettings->setValue("location_run_once/longitude", StelUtils::getDecAngle(longitude)); // Store longitude in radian
	if (!latitude.isEmpty()) confSettings->setValue("location_run_once/latitude", StelUtils::getDecAngle(latitude)); // Store latitude in radian
	if (!lgmode.isEmpty()) {
		confSettings->setValue("lg/mode", lgmode.toUpper());
		confSettings->setValue("lg/port", lgport);
		confSettings->setValue("lg/offset", lgoffset);
///		std::cout << "conf values : " << lgmode.toStdString() << " " << lgoffset << std::endl;
	} else
		confSettings->setValue("lg/mode", "");

	if (!skyDate.isEmpty() || !skyTime.isEmpty())
	{
		// Get the Julian date for the start of the current day
		// and the extra necessary for the time of day as separate
		// components.  Then if the --sky-date and/or --sky-time flags
		// are set we over-ride the component, and finally add them to
		// get the full julian date and set that.

		// First, lets determine the Julian day number and the part for the time of day
		QDateTime now = QDateTime::currentDateTime();
		double skyDatePart = now.date().toJulianDay();
		double skyTimePart = StelUtils::qTimeToJDFraction(now.time());

		// Over-ride the skyDatePart if the user specified the date using --sky-date
		if (!skyDate.isEmpty())
		{
			// validate the argument format, we will tolerate yyyy-mm-dd by removing all -'s
			QRegExp dateRx("\\d{8}");
			if (dateRx.exactMatch(skyDate.remove("-")))
				skyDatePart = QDate::fromString(skyDate, "yyyyMMdd").toJulianDay();
			else
				qWarning() << "WARNING: --sky-date argument has unrecognised format  (I want yyyymmdd)";
		}

		if (!skyTime.isEmpty())
		{
			QRegExp timeRx("\\d{1,2}:\\d{2}:\\d{2}");
			if (timeRx.exactMatch(skyTime))
				skyTimePart = StelUtils::qTimeToJDFraction(QTime::fromString(skyTime, "hh:mm:ss"));
			else
				qWarning() << "WARNING: --sky-time argument has unrecognised format (I want hh:mm:ss)";
		}

		confSettings->setValue("navigation/startup_time_mode", "preset");
		confSettings->setValue("navigation/preset_sky_time", skyDatePart + skyTimePart);
	}

	if (!multiresImage.isEmpty())
		confSettings->setValue("skylayers/clilayer", multiresImage);
	else
	{
		confSettings->remove("skylayers/clilayer");
	}

	if (!startupScript.isEmpty())
	{
		qApp->setProperty("onetime_startup_script", startupScript);
	}

	if (fov>0.0) confSettings->setValue("navigation/init_fov", fov);
	if (!projectionType.isEmpty()) confSettings->setValue("projection/type", projectionType);
	if (!screenshotDir.isEmpty())
	{
		try
		{
			QString newShotDir = QDir::fromNativeSeparators(argsGetOptionWithArg(argList, "", "--screenshot-dir", "").toString());
			if (!newShotDir.isEmpty())
				StelFileMgr::setScreenshotDir(newShotDir);
		}
		catch (std::runtime_error& e)
		{
			qWarning() << "WARNING: problem while setting screenshot directory for --screenshot-dir option: " << e.what();
		}
	}
	else
	{
		const QString& confScreenshotDir = QDir::fromNativeSeparators(confSettings->value("main/screenshot_dir", "").toString());
		if (!confScreenshotDir.isEmpty())
		{
			try
			{
				StelFileMgr::setScreenshotDir(confScreenshotDir);
			}
			catch (std::runtime_error& e)
			{
				qWarning() << "WARNING: problem while setting screenshot from config file setting: " << e.what();
			}
		}
		else
		{
			QString screenshotDirSuffix = "/Stellarium";
			if (!QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).isEmpty())
				screenshotDir = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation)[0].append(screenshotDirSuffix);
			else
				screenshotDir = StelFileMgr::getUserDir().append(screenshotDirSuffix);

			try
			{
				StelFileMgr::setScreenshotDir(screenshotDir);
				confSettings->setValue("main/screenshot_dir", screenshotDir);
			}
			catch (std::runtime_error &e)
			{
				qDebug("Error: cannot create screenshot directory: %s", e.what());
			}
		}
	}
}
Exemplo n.º 2
0
void CLIProcessor::parseCLIArgsPreConfig(const QStringList& argList)
{
	if (argsGetOption(argList, "-v", "--version"))
	{
		std::cout << qPrintable(StelUtils::getApplicationName()) << std::endl;
		exit(0);
	}

	if (argsGetOption(argList, "-h", "--help"))
	{
		// Get the basename of binary
		QString binName = argList.at(0);
		binName.remove(QRegExp("^.*[/\\\\]"));

		std::cout << "Usage:\n"
		          << "  "
		          << qPrintable(binName) << " [options]\n\n"
		          << "Options:\n"
		          << "--version (or -v)       : Print program name and version and exit.\n"
		          << "--help (or -h)          : This cruft.\n"
		          << "--config-file (or -c)   : Use an alternative name for the config file\n"
		          << "--user-dir (or -u)      : Use an alternative user data directory\n"
			  //<< "--safe-mode (or -s)     : Disable GL shaders and use older GL engine\n"
			  << "--dump-opengl-details (or -d) : dump information about OpenGL support to logfile\n"
			  << "                          Try this is you have graphics problems\n"
		          << "--full-screen (or -f)   : With argument \"yes\" or \"no\" over-rides\n"
		          << "                          the full screen setting in the config file\n"
		          << "--screenshot-dir        : Specify directory to save screenshots\n"
		          << "--startup-script        : Specify name of startup script\n"
		          << "--home-planet           : Specify observer planet (English name)\n"
		          << "--altitude              : Specify observer altitude in meters\n"
		          << "--longitude             : Specify longitude, e.g. +53d58\\'16.65\\\"\n"
		          << "--latitude              : Specify latitude, e.g. -1d4\\'27.48\\\"\n"
		          << "--list-landscapes       : Print a list of value landscape IDs\n"
		          << "--landscape             : Start using landscape whose ID (dir name)\n"
		          << "                          is passed as parameter to option\n"
		          << "--sky-date              : Specify sky date in format yyyymmdd\n"
		          << "--sky-time              : Specify sky time in format hh:mm:ss\n"
		          << "--fov                   : Specify the field of view (degrees)\n"
		          << "--projection-type       : Specify projection type, e.g. stereographic\n"
		          << "--restore-defaults      : Delete existing config.ini and use defaults\n"
		          << "--multires-image        : With filename / URL argument, specify a\n"
		          << "                          multi-resolution image to load\n";
		exit(0);
	}

	/*
	if (argsGetOption(argList, "-s", "--safe-mode"))
	{
		qApp->setProperty("onetime_safe_mode", true);
	}
	*/

	if (argsGetOption(argList, "", "--list-landscapes"))
	{
		const QSet<QString>& landscapeIds = StelFileMgr::listContents("landscapes", StelFileMgr::Directory);
		foreach (const QString& i, landscapeIds)
		{
			// finding the file will throw an exception if it is not found
			// in that case we won't output the landscape ID as it cannot work
			if (!StelFileMgr::findFile("landscapes/" + i + "/landscape.ini").isEmpty())
				std::cout << qPrintable(i) << std::endl;
		}
		exit(0);
	}

	try
	{
		QString newUserDir;
		newUserDir = argsGetOptionWithArg(argList, "-u", "--user-dir", "").toString();
		if (newUserDir!="" && !newUserDir.isEmpty())
			StelFileMgr::setUserDir(newUserDir);
	}
	catch (std::runtime_error& e)
	{
		qCritical() << "ERROR: while processing --user-dir option: " << e.what();
		exit(1);
	}
}
Exemplo n.º 3
0
void CLIProcessor::parseCLIArgsPreConfig(const QStringList& argList)
{
	if (argsGetOption(argList, "-v", "--version"))
	{
		std::cout << qPrintable(StelUtils::getApplicationName()) << std::endl;
		exit(0);
	}

	if (argsGetOption(argList, "-h", "--help"))
	{
		// Get the basename of binary
		QString binName = argList.at(0);
		binName.remove(QRegExp("^.*[/\\\\]"));

		std::cout << "Usage:\n"
		          << "  "
		          << qPrintable(binName) << " [options]\n\n"
		          << "Options:\n"
			  << "--version (or -v)       : Print program name and version and exit.\n"
			  << "--help (or -h)          : This cruft.\n"
			  << "--config-file (or -c)   : Use an alternative name for the config file\n"
			  << "--user-dir (or -u)      : Use an alternative user data directory\n"
			  << "--verbose               : Even more diagnostic output in logfile \n"
			  << "                          (esp. multimedia handling)\n"
			  << "--fix-text (or -t)      : May fix text rendering problems\n"
			#ifdef Q_OS_WIN
			  << "--angle-mode (or -a)    : Use ANGLE as OpenGL ES2 rendering engine (autodetect driver)\n"
			  << "--angle-d3d9 (or -9)    : Force use Direct3D 9 for ANGLE OpenGL ES2 rendering engine\n"
			  << "--angle-d3d11           : Force use Direct3D 11 for ANGLE OpenGL ES2 rendering engine\n"
			  << "--angle-warp            : Force use the Direct3D 11 software rasterizer for ANGLE OpenGL ES2 rendering engine\n"
			  << "--mesa-mode (or -m)     : Use MESA as software OpenGL rendering engine\n"
			  << "--safe-mode (or -s)     : Synonymous to --mesa-mode \n"
			#endif
			  << "--dump-opengl-details (or -d) : dump information about OpenGL support to logfile.\n"
			  << "                          Use this is you have graphics problems\n"
			  << "                          and want to send a bug report\n"
			  << "--full-screen (or -f)   : With argument \"yes\" or \"no\" over-rides\n"
			  << "                          the full screen setting in the config file\n"
			  << "--screenshot-dir        : Specify directory to save screenshots\n"
			  << "--startup-script        : Specify name of startup script\n"
			  << "--home-planet           : Specify observer planet (English name)\n"
			  << "--altitude              : Specify observer altitude in meters\n"
			  << "--longitude             : Specify longitude, e.g. +53d58\\'16.65\\\"\n"
			  << "--latitude              : Specify latitude, e.g. -1d4\\'27.48\\\"\n"
			  << "--list-landscapes       : Print a list of valid landscape IDs\n"
		          << "--landscape             : Start using landscape whose ID (dir name)\n"
		          << "                          is passed as parameter to option\n"
		          << "--sky-date              : Specify sky date in format yyyymmdd\n"
		          << "--sky-time              : Specify sky time in format hh:mm:ss\n"
		          << "--fov                   : Specify the field of view (degrees)\n"
		          << "--projection-type       : Specify projection type, e.g. stereographic\n"
		          << "--restore-defaults      : Delete existing config.ini and use defaults\n"
		          << "--multires-image        : With filename / URL argument, specify a\n"
		          << "                          multi-resolution image to load\n";
		exit(0);
	}

	if (argsGetOption(argList, "", "--verbose"))
	{
		qApp->setProperty("verbose", true);
	}
	if (argsGetOption(argList, "-t", "--fix-text"))
	{
		qApp->setProperty("text_texture", true); // Will be observed in StelPainter::drawText()
	}

	#ifdef Q_OS_WIN
	if (argsGetOption(argList, "-s", "--safe-mode"))
	{
		qApp->setProperty("onetime_mesa_mode", true);
	}
	if (argsGetOption(argList, "-a", "--angle-mode"))
	{
		qApp->setProperty("onetime_angle_mode", true);
	}
	if (argsGetOption(argList, "-9", "--angle-d3d9"))
	{
		qputenv("QT_ANGLE_PLATFORM", "d3d9");
		qApp->setProperty("onetime_angle_mode", true);
	}
	if (argsGetOption(argList, "", "--angle-d3d11"))
	{
		qputenv("QT_ANGLE_PLATFORM", "d3d11");
		qApp->setProperty("onetime_angle_mode", true);
	}
	if (argsGetOption(argList, "", "--angle-warp"))
	{
		qputenv("QT_ANGLE_PLATFORM", "warp");
		qApp->setProperty("onetime_angle_mode", true);
	}
	if (argsGetOption(argList, "-m", "--mesa-mode"))
	{
		qApp->setProperty("onetime_mesa_mode", true);
	}
	#endif
	if (argsGetOption(argList, "", "--list-landscapes"))
	{
		const QSet<QString>& landscapeIds = StelFileMgr::listContents("landscapes", StelFileMgr::Directory);
		foreach (const QString& i, landscapeIds)
		{
			// finding the file will throw an exception if it is not found
			// in that case we won't output the landscape ID as it cannot work
			if (!StelFileMgr::findFile("landscapes/" + i + "/landscape.ini").isEmpty())
				std::cout << qPrintable(i) << std::endl;
		}
		exit(0);
	}

	try
	{
		QString newUserDir;
		newUserDir = argsGetOptionWithArg(argList, "-u", "--user-dir", "").toString();
		if (newUserDir!="" && !newUserDir.isEmpty())
			StelFileMgr::setUserDir(newUserDir);
	}
	catch (std::runtime_error& e)
	{
		qCritical() << "ERROR: while processing --user-dir option: " << e.what();
		exit(1);
	}
}