void executeHistory(icmProcessorP processor, char *cmd) { int id; command_history_t *his; if(cmd == 0 || *cmd == '\0') { showHistory(); } else if(!strcmp(cmd, "!")) { if( his = lastHistory() ) { executeCommand(processor, his->cmd); } else { printf("ERROR: no previous command found\n"); } } else { if(!getNumberFromString(cmd, & id)) { if( his = findHistory(id) ) { executeCommand(processor, his->cmd); } else { printf("ERROR: could not find history '%d'\n", id); } } else { printf("ERROR: Bad number: '%s'\n", cmd); } } }
void toNewConnection::writeSettings(bool checkHistory) { int r = 0; Settings.setValue("geometry", saveGeometry()); toConfigurationNewSingle::Instance().setOption(ToConfiguration::Global::SavePasswordBool, checkBoxRememberPasswords->isChecked()); Settings.setValue(CONF_PROVIDER_LIST_SORT_OFFSET, (Previous->horizontalHeader()->sortIndicatorOrder() == Qt:: AscendingOrder ? 1 : -1)* Previous->horizontalHeader()->sortIndicatorSection()); Settings.remove("history"); if (!Provider->currentText().isEmpty() && checkHistory) { Settings.beginGroup("history/0"); Settings.setValue("provider", Provider->currentText()); Settings.setValue("username", Username->text()); if (toConfigurationNewSingle::Instance().option(ToConfiguration::Global::SavePasswordBool).toBool()) { Settings.setValue("password", Utils::toObfuscate(Password->text())); } Settings.setValue("host", Host->currentText()); Settings.setValue("port", Port->value()); Settings.setValue("database", Database->currentText()); Settings.setValue("schema", Schema->text()); Settings.setValue("color", colorComboBox->itemData(colorComboBox->currentIndex())); Settings.beginGroup("options"); QList<QCheckBox *> widgets = OptionGroup->findChildren<QCheckBox *>(); Q_FOREACH(QCheckBox * box, widgets) Settings.setValue(box->text(), box->isChecked()); Settings.endGroup(); // options Settings.endGroup(); // history/0 ++r; } // find history item with same options. will skip later. int skip = -1; if (checkHistory) { skip = findHistory(Provider->currentText(), Username->text(), Host->currentText(), Database->currentText(), Schema->text(), Port->value() ); } QMap<int, toConnectionOptions> c = connectionModel()->availableConnections(); foreach(int row, c.keys()) { if (row == skip)// && ++skipped) continue; toConnectionOptions &opt = c[row]; Settings.beginGroup("history/" + QString::number(r/*row*/));// + 1 - skipped)); Settings.setValue("provider", opt.provider); Settings.setValue("username", opt.username); Settings.setValue("host", opt.host); Settings.setValue("database", opt.database); Settings.setValue("schema", opt.schema); Settings.setValue("color", opt.color); Settings.setValue("port", opt.port); if (toConfigurationNewSingle::Instance().option(ToConfiguration::Global::SavePasswordBool).toBool()) { Settings.setValue("password", Utils::toObfuscate(opt.password)); } Settings.beginGroup("options"); Q_FOREACH(QString s, opt.options) Settings.setValue(s, true); Settings.endGroup(); Settings.endGroup(); ++r; } connectionModel()->readConfig(); }