foreach (const QString &headerRow, headerLines) { QRegExp messageIdRx("^Message-ID: (.*)$", Qt::CaseInsensitive); QRegExp fromRx("^From: (.*)$", Qt::CaseInsensitive); QRegExp toRx("^To: (.*)$", Qt::CaseInsensitive); QRegExp ccRx("^Cc: (.*)$", Qt::CaseInsensitive); QRegExp subjectRx("^Subject: (.*)$", Qt::CaseInsensitive); QRegExp dateRx("^Date: (.*)$", Qt::CaseInsensitive); QRegExp mimeVerstionRx("^MIME-Version: (.*)$", Qt::CaseInsensitive); QRegExp contentTransferEncodingRx("^Content-Transfer-Encoding: (.*)$", Qt::CaseInsensitive); QRegExp contentTypeRx("^Content-Type: (.*)$", Qt::CaseInsensitive); if (messageIdRx.indexIn(headerRow) != -1) setMessageId(messageIdRx.cap(1)); else if (fromRx.indexIn(headerRow) != -1) setFrom(headerDecode(fromRx.cap(1))); else if (toRx.indexIn(headerRow) != -1) setTo(headerDecode(toRx.cap(1))); else if (ccRx.indexIn(headerRow) != -1) setCc(headerDecode(ccRx.cap(1))); else if (subjectRx.indexIn(headerRow) != -1) setSubject(headerDecode(subjectRx.cap(1))); else if (dateRx.indexIn(headerRow) != -1) { QDateTime date = QDateTime::fromString(dateRx.cap(1), Qt::RFC2822Date); setDate(date); } else if (mimeVerstionRx.indexIn(headerRow) != -1) setMimeVersion(mimeVerstionRx.cap(1)); else if (contentTransferEncodingRx.indexIn(headerRow) != -1) setContentTransferEncoding(IqPostmanAbstractContent::contentTransferEncodingFromString(headerRow)); else if (contentTypeRx.indexIn(headerRow) != -1) setContentType(IqPostmanAbstractContentType::createFromString(headerRow)); }
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()); } } } }