void Settings::setInteger(QString key, int value) { settings().setValue(key, value); }
bool ConfigFile::deltaSyncEnabled() const { QSettings settings(configFile(), QSettings::IniFormat); return settings.value(QLatin1String(deltaSyncEnabledC), false).toBool(); // default to false }
bool ConfigFile::promptDeleteFiles() const { QSettings settings(configFile(), QSettings::IniFormat); return settings.value(QLatin1String(promptDeleteC), true).toBool(); }
void ConfigFile::setUpdateChannel(const QString &channel) { QSettings settings(configFile(), QSettings::IniFormat); settings.setValue(QLatin1String(updateChannelC), channel); }
void ConfigFile::setMaxLogLines(int lines) { QSettings settings(configFile(), QSettings::IniFormat); settings.setValue(QLatin1String(maxLogLinesC), lines); settings.sync(); }
qint64 ConfigFile::minChunkSize() const { QSettings settings(configFile(), QSettings::IniFormat); return settings.value(QLatin1String(minChunkSizeC), 1000 * 1000).toLongLong(); // default to 1 MB }
void ConfigFile::setOptionalDesktopNotifications(bool show) { QSettings settings(configFile(), QSettings::IniFormat); settings.setValue(QLatin1String(optionalDesktopNoficationsC), show); settings.sync(); }
bool CheckExternalScripts::loadModuleEx(std::string alias, NSCAPI::moduleLoadMode) { try { sh::settings_registry settings(get_settings_proxy()); settings.set_alias(alias, "external scripts"); commands_.set_path(settings.alias().get_settings_path("scripts")); aliases_.set_path(settings.alias().get_settings_path("alias")); std::string wrappings_path = settings.alias().get_settings_path("wrappings"); settings.alias().add_path_to_settings() ("wrappings", sh::string_map_path(&wrappings_) , "EXTERNAL SCRIPT WRAPPINGS SECTION", "A list of templates for wrapped scripts.\n%SCRIPT% will be replaced by the actual script an %ARGS% will be replaced by any given arguments.", "WRAPPING", "An external script wrapping") ("alias", sh::fun_values_path(boost::bind(&CheckExternalScripts::add_alias, this, _1, _2)), "ALIAS SECTION", "A list of aliases available.\n" "An alias is an internal command that has been predefined to provide a single command without arguments. Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)", "ALIAS", "Query alias") ; settings.register_all(); settings.notify(); settings.clear(); if (wrappings_.find("ps1") == wrappings_.end()) { wrappings_["ps1"] = "cmd /c echo If (-Not (Test-Path \"scripts\\%SCRIPT%\") ) { Write-Host \"UNKNOWN: Script `\"%SCRIPT%`\" not found.\"; exit(3) }; scripts\\%SCRIPT% $ARGS$; exit($lastexitcode) | powershell.exe /noprofile -command -"; settings.register_key(wrappings_path, "ps1", NSCAPI::key_string, "POWERSHELL WRAPPING", "", "", false); settings.set_static_key(wrappings_path, "ps1", wrappings_["ps1"]); } if (wrappings_.find("vbs") == wrappings_.end()) { wrappings_["vbs"] = "cscript.exe //T:30 //NoLogo scripts\\\\lib\\\\wrapper.vbs %SCRIPT% %ARGS%"; settings.register_key(wrappings_path, "vbs", NSCAPI::key_string, "VISUAL BASIC WRAPPING", "", "", false); settings.set_static_key(wrappings_path, "vbs", wrappings_["vbs"]); } if (wrappings_.find("bat") == wrappings_.end()) { wrappings_["bat"] = "scripts\\\\%SCRIPT% %ARGS%"; settings.register_key(wrappings_path, "bat", NSCAPI::key_string, "BATCH FILE WRAPPING", "", "", false); settings.set_static_key(wrappings_path, "bat", wrappings_["bat"]); } if (aliases_.empty()) { NSC_DEBUG_MSG("No aliases found (adding default)"); add_alias("alias_cpu", "check_cpu"); add_alias("alias_cpu_ex", "check_cpu \"warn=load > $ARG1$\" \"crit=load > $ARG2$\" time=5m time=1m time=30s"); add_alias("alias_mem", "check_memory"); add_alias("alias_up", "check_uptime"); add_alias("alias_disk", "check_drivesize"); add_alias("alias_disk_loose", "check_drivesize"); add_alias("alias_volumes", "check_drivesize"); add_alias("alias_volumes_loose", "check_drivesize"); add_alias("alias_service", "check_service"); add_alias("alias_service_ex", "check_service \"exclude=Net Driver HPZ12\" \"exclude=Pml Driver HPZ12\" exclude=stisvc"); add_alias("alias_process", "check_process \"process=$ARG1$\" \"crit=state != 'started'\""); add_alias("alias_process_stopped", "check_process \"process=$ARG1$\" \"crit=state != 'stopped'\""); add_alias("alias_process_count", "check_process \"process=$ARG1$\" \"warn=count > $ARG2$\" \"crit=count > $ARG3$\""); add_alias("alias_process_hung", "check_process \"filter=is_hung\" \"crit=count>0\""); add_alias("alias_event_log", "check_eventlog"); add_alias("alias_file_size", "check_files \"path=$ARG1$\" \"crit=size > $ARG2$\" \"top-syntax=${list}\" \"detail-syntax=${filename] ${size}\" max-dir-depth=10"); add_alias("alias_file_age", "check_files \"path=$ARG1$\" \"crit=written > $ARG2$\" \"top-syntax=${list}\" \"detail-syntax=${filename] ${written}\" max-dir-depth=10"); add_alias("alias_sched_all", "check_tasksched show-all \"syntax=${title}: ${exit_code}\" \"crit=exit_code ne 0\""); add_alias("alias_sched_long", "check_tasksched \"filter=status = 'running'\" \"detail-syntax=${title} (${most_recent_run_time})\" \"crit=most_recent_run_time < -$ARG1$\""); add_alias("alias_sched_task", "check_tasksched show-all \"filter=title eq '$ARG1$'\" \"detail-syntax=${title} (${exit_code})\" \"crit=exit_code ne 0\""); // add_alias("alias_updates", "check_updates -warning 0 -critical 0"); } settings.alias().add_path_to_settings() ("EXTERNAL SCRIPT SECTION", "Section for external scripts configuration options (CheckExternalScripts).") ("scripts", sh::fun_values_path(boost::bind(&CheckExternalScripts::add_command, this, _1, _2)), "SCRIPT SECTION", "A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>", "SCRIPT", "For more configuration options add a dedicated section (if you add a new section you can customize the user and various other advanced features)") ("wrapped scripts", sh::fun_values_path(boost::bind(&CheckExternalScripts::add_wrapping, this, _1, _2)), "WRAPPED SCRIPTS SECTION", "A list of wrapped scripts (ie. scruts using a template mechanism). The template used will be defined by the extension of the script.", "WRAPPED SCRIPT", "A wrapped script defenitions") ; settings.alias().add_key_to_settings() ("timeout", sh::uint_key(&timeout, 60), "COMMAND TIMEOUT", "The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.") ("allow arguments", sh::bool_key(&allowArgs_, false), "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the we will allow clients to specify arguments to commands that are executed.") ("allow nasty characters", sh::bool_key(&allowNasty_, false), "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.") ("script path", sh::string_key(&scriptDirectory_), "SCRIPT DIRECTORY", "Load all scripts in a directory and use them as commands. Probably dangerous but useful if you have loads of scripts :)") ; settings.alias().add_templates() ("scripts", "plus", "Add a simple script", "Add binding for a simple script", "{" "\"fields\": [ " " { \"id\": \"alias\", \"title\" : \"Alias\", \"type\" : \"input\", \"desc\" : \"This will identify the command\"} , " " { \"id\": \"script\", \"title\" : \"Script\", \"type\" : \"data-choice\", \"desc\" : \"The name of the script\",\"exec\" : \"CheckExternalScripts list --json\" } , " " { \"id\": \"args\", \"title\" : \"Arguments\", \"type\" : \"input\", \"desc\" : \"Command line arguments for the script use $ARG1$ to specify arguments\" } , " " { \"id\": \"cmd\", \"key\" : \"command\", \"title\" : \"A\", \"type\" : \"hidden\", \"desc\" : \"A\" } " " ], " "\"events\": { " "\"onSave\": \"(function (node) { node.save_path = self.path; var f = node.get_field('cmd'); f.key = node.get_field('alias').value(); var val = node.get_field('script').value(); if (node.get_field('args').value()) { val += ' ' + node.get_field('args').value(); }; f.value(val)})\"" "}" "}") ("alias", "plus", "Add an alias", "Add binding for an alias", "{" "\"fields\": [ " " { \"id\": \"alias\", \"title\" : \"Alias\", \"type\" : \"input\", \"desc\" : \"This will identify the command\"} , " " { \"id\": \"command\", \"title\" : \"Command\", \"type\" : \"data-choice\", \"desc\" : \"The name of the command to execute\",\"exec\" : \"CheckExternalScripts list --json --query\" } , " " { \"id\": \"args\", \"title\" : \"Arguments\", \"type\" : \"input\", \"desc\" : \"Command line arguments for the command. use $ARG1$ to specify arguments\" } , " " { \"id\": \"cmd\", \"key\" : \"command\", \"title\" : \"A\", \"type\" : \"hidden\", \"desc\" : \"A\" } " " ], " "\"events\": { " "\"onSave\": \"(function (node) { node.save_path = self.path; \nvar f = node.get_field('cmd'); \nf.key = node.get_field('alias').value(); \nvar val = node.get_field('command').value(); \nif (node.get_field('args').value()) { \nval += ' ' + node.get_field('args').value(); }; \nf.value(val)})\"" "}" "}") ; settings.register_all(); settings.notify(); std::string scripts_path = settings.alias().get_settings_path("scripts"); std::string alias_path = settings.alias().get_settings_path("alias"); commands_.add_samples(get_settings_proxy()); commands_.add_missing(get_settings_proxy(), "default", "", true); aliases_.add_samples(get_settings_proxy()); aliases_.add_missing(get_settings_proxy(), "default", "", true); if (!scriptDirectory_.empty()) { addAllScriptsFrom(scriptDirectory_); } root_ = get_base_path(); nscapi::core_helper core(get_core(), get_id()); BOOST_FOREACH(const boost::shared_ptr<commands::command_object> &o, commands_.get_object_list()) { core.register_alias(o->get_alias(), "External script: " + o->command); } BOOST_FOREACH(const boost::shared_ptr<alias::command_object> &o, aliases_.get_object_list()) { core.register_alias(o->get_alias(), "Alias for: " + o->command); } } catch (...) { NSC_LOG_ERROR_EX("loading"); return false; } return true; }
void BtSettings::setAudioProfileChannel(const QBluetoothAddress &addr, QBluetooth::SDPProfile profile, int channel) { QSettings settings("Trolltech", "BluetoothKnownHeadsets"); settings.setValue(addr.toString() + "/" + QString::number(int(profile)), channel); }
void ChessWidget::onUseOpenBook(bool o) { QSettings settings(tr("Dimock"), tr("qchess")); settings.setValue(tr("open_book"), o); }
void ChessWidget::createMenu() { QMenu * gameMenu = menuBar()->addMenu(tr("&Game")); onNewAction_ = new QAction(tr("&New"), this); onNewAction_->setStatusTip(tr("Start new game")); onLoadAction_ = new QAction(tr("&Load"), this); onLoadAction_->setStatusTip(tr("Load previously saved game")); onSaveAction_ = new QAction(tr("&Save"), this); onSaveAction_->setStatusTip(tr("Save current game")); onPrevAction_ = new QAction(tr("&Undo move"), this); onPrevAction_->setStatusTip(tr("Undo last move. (only step of one color will be undone)")); onNextAction_ = new QAction(tr("&Redo move"), this); onNextAction_->setStatusTip(tr("Restore undone move")); onGoAction_ = new QAction(tr("&Go"), this); onGoAction_->setStatusTip(tr("Lets program make move")); onTurnBoardAction_ = new QAction(tr("&Turn board"), this); onTurnBoardAction_->setStatusTip(tr("Turn board to play another color")); onTurnBoardAction_->setCheckable(true); onTurnBoardAction_->setChecked(false); onHumanVsHumanAction_ = new QAction(tr("&Human vs. Human"), this); onHumanVsHumanAction_->setStatusTip(tr("Switch to Human with Human mode")); onHumanVsHumanAction_->setCheckable(true); onHumanVsHumanAction_->setChecked(false); QSettings settings(tr("Dimock"), tr("qchess")); onOpenBookAction_ = new QAction(tr("&Open book"), this); onOpenBookAction_->setStatusTip(tr("Use open book")); onOpenBookAction_->setCheckable(true); onOpenBookAction_->setChecked( settings.value(tr("open_book"), true).toBool() ); onSettingsAction_ = new QAction(tr("Settin&gs"), this); onSettingsAction_->setStatusTip(tr("Change game settings")); gameMenu->addAction(onNewAction_); gameMenu->addAction(onLoadAction_); gameMenu->addAction(onSaveAction_); gameMenu->addAction(onPrevAction_); gameMenu->addAction(onNextAction_); gameMenu->addAction(onGoAction_); gameMenu->addAction(onTurnBoardAction_); gameMenu->addAction(onOpenBookAction_); gameMenu->addSeparator(); gameMenu->addAction(onHumanVsHumanAction_); gameMenu->addSeparator(); gameMenu->addAction(onSettingsAction_); connect(onNewAction_, SIGNAL(triggered()), this, SLOT(onNew())); connect(onLoadAction_, SIGNAL(triggered()), this, SLOT(onLoad())); connect(onSaveAction_, SIGNAL(triggered()), this, SLOT(onSave())); connect(onPrevAction_, SIGNAL(triggered()), this, SLOT(onPrev())); connect(onNextAction_, SIGNAL(triggered()), this, SLOT(onNext())); connect(onGoAction_, SIGNAL(triggered()), this, SLOT(onGo())); connect(onTurnBoardAction_, SIGNAL(toggled(bool)), this, SLOT(onTurnBoard(bool))); connect(onHumanVsHumanAction_, SIGNAL(toggled(bool)), this, SLOT(onHumanWithHumanMode(bool))); connect(onOpenBookAction_, SIGNAL(toggled(bool)), this, SLOT(onUseOpenBook(bool))); connect(onSettingsAction_, SIGNAL(triggered()), this, SLOT(onSettings())); }
void Settings::setMap(QString key, QMap<QString, QVariant> value) { settings().setValue(key, value); }
void Settings::setBoolean(QString key, bool value) { settings().setValue(key, value); }
void Settings::setStringList(QString key, QStringList value) { settings().setValue(key, value); }
void ConfigFile::setShowInExplorerNavigationPane(bool show) { QSettings settings(configFile(), QSettings::IniFormat); settings.setValue(QLatin1String(showInExplorerNavigationPaneC), show); settings.sync(); }
int BtSettings::audioProfileChannel(const QBluetoothAddress &addr, QBluetooth::SDPProfile profile) { QSettings settings("Trolltech", "BluetoothKnownHeadsets"); return settings.value(addr.toString() + "/" + QString::number(int(profile)), -1).toInt(); }
int ConfigFile::timeout() const { QSettings settings(configFile(), QSettings::IniFormat); return settings.value(QLatin1String(timeoutC), 300).toInt(); // default to 5 min }
uint32_t serial::baudrate () const { uint32_t r; settings(& r, nullptr, nullptr, nullptr); return r; }
chrono::milliseconds ConfigFile::targetChunkUploadDuration() const { QSettings settings(configFile(), QSettings::IniFormat); return millisecondsValue(settings, targetChunkUploadDurationC, chrono::minutes(1)); }
serial::databits_t serial::databits () const { databits_t r; settings(nullptr, & r, nullptr, nullptr); return r; }
chrono::milliseconds OCC::ConfigFile::fullLocalDiscoveryInterval() const { QSettings settings(configFile(), QSettings::IniFormat); settings.beginGroup(defaultConnection()); return millisecondsValue(settings, fullLocalDiscoveryIntervalC, chrono::hours(1)); }
serial::stopbits_t serial::stopbits () const { stopbits_t r; settings(nullptr, nullptr, & r, nullptr); return r; }
int ConfigFile::maxLogLines() const { QSettings settings(configFile(), QSettings::IniFormat); return settings.value(QLatin1String(maxLogLinesC), DEFAULT_MAX_LOG_LINES).toInt(); }
serial::parity_t serial::parity () const { parity_t r; settings(nullptr, nullptr, nullptr, & r); return r; }
void ConfigFile::setValue(const QString &key, const QVariant &value) { QSettings settings(configFile(), QSettings::IniFormat); settings.setValue(key, value); }
// reading, writing of .creatortheme ini file //////////////////////////////// void Theme::writeSettings(const QString &filename) const { QSettings settings(filename, QSettings::IniFormat); const QMetaObject &m = *metaObject(); { settings.setValue(QLatin1String("ThemeName"), d->name); settings.setValue(QLatin1String("PreferredStyles"), d->preferredStyles); } { settings.beginGroup(QLatin1String("Palette")); for (int i = 0, total = d->colors.size(); i < total; ++i) { const QPair<QColor, QString> var = d->colors[i]; if (var.second.isEmpty()) continue; settings.setValue(var.second, writeColor(var.first)); } settings.endGroup(); } { settings.beginGroup(QLatin1String("Colors")); const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Color")); for (int i = 0, total = e.keyCount(); i < total; ++i) { const QString key = QLatin1String(e.key(i)); const QPair<QColor, QString> var = d->colors[i]; if (!var.second.isEmpty()) settings.setValue(key, var.second); // named color else settings.setValue(key, writeColor(var.first)); } settings.endGroup(); } { settings.beginGroup(QLatin1String("ImageFiles")); const QMetaEnum e = m.enumerator(m.indexOfEnumerator("ImageFile")); for (int i = 0, total = e.keyCount(); i < total; ++i) { const QString key = QLatin1String(e.key(i)); const QString &var = d->imageFiles.at(i); if (!var.isEmpty()) settings.setValue(key, var); } settings.endGroup(); } { settings.beginGroup(QLatin1String("Gradients")); const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Gradient")); for (int i = 0, total = e.keyCount(); i < total; ++i) { const QString key = QLatin1String(e.key(i)); QGradientStops stops = gradient(static_cast<Theme::Gradient>(i)); settings.beginWriteArray(key); int k = 0; foreach (const QGradientStop stop, stops) { settings.setArrayIndex(k); settings.setValue(QLatin1String("pos"), stop.first); settings.setValue(QLatin1String("color"), writeColor(stop.second)); ++k; } settings.endArray(); } settings.endGroup(); }
qint64 ConfigFile::deltaSyncMinFileSize() const { QSettings settings(configFile(), QSettings::IniFormat); return settings.value(QLatin1String(deltaSyncMinimumFileSizeC), 10 * 1024 * 1024).toLongLong(); // default to 10 MiB }
bool ConfigFile::optionalDesktopNotifications() const { QSettings settings(configFile(), QSettings::IniFormat); return settings.value(QLatin1String(optionalDesktopNoficationsC), true).toBool(); }
void ConfigFile::setPromptDeleteFiles(bool promptDeleteFiles) { QSettings settings(configFile(), QSettings::IniFormat); settings.setValue(QLatin1String(promptDeleteC), promptDeleteFiles); }
QString Settings::fileName() { return settings().fileName(); }