void SshKeyGenerator::generatePkcs8KeyString(const KeyPtr &key, bool privateKey, Botan::RandomNumberGenerator &rng) { Pipe pipe; pipe.start_msg(); QByteArray *keyData; if (privateKey) { QInputDialog d; d.setInputMode(QInputDialog::TextInput); d.setTextEchoMode(QLineEdit::Password); d.setWindowTitle(tr("Password for Private Key")); d.setLabelText(tr("It is recommended that you secure your private key\n" "with a password, which you can can enter below.")); d.setOkButtonText(tr("Encrypt key file")); d.setCancelButtonText(tr("Do not encrypt key file")); int result = QDialog::Accepted; QString password; while (result == QDialog::Accepted && password.isEmpty()) { result = d.exec(); password = d.textValue(); } if (result == QDialog::Accepted) PKCS8::encrypt_key(*key, pipe, rng, password.toLocal8Bit().data()); else PKCS8::encode(*key, pipe); keyData = &m_privateKey; } else { X509::encode(*key, pipe); keyData = &m_publicKey; } pipe.end_msg(); keyData->resize(pipe.remaining(pipe.message_count() - 1)); pipe.read(convertByteArray(*keyData), keyData->size(), pipe.message_count() - 1); }
QString GUI::_passwordDialog(const QString& cancel, const QString& body) { // we use a hack. It is considered that closing the dialog without explicitly clicking // disable history is confusing. But we can't distinguish between clicking the cancel // button and closing the dialog. So instead, we reverse the Ok and Cancel roles, // so that nothing but explicitly clicking disable history closes the dialog QString ret; QInputDialog dialog; dialog.setWindowTitle(tr("Enter your password")); dialog.setOkButtonText(cancel); dialog.setCancelButtonText(tr("Decrypt")); dialog.setInputMode(QInputDialog::TextInput); dialog.setTextEchoMode(QLineEdit::Password); dialog.setLabelText(body); // problem with previous hack: the default button is disable history, not decrypt. // use another hack to reverse the default buttons. // http://www.qtcentre.org/threads/49924-Change-property-of-QInputDialog-button QList<QDialogButtonBox*> l = dialog.findChildren<QDialogButtonBox*>(); if (!l.isEmpty()) { QPushButton* ok = l.first()->button(QDialogButtonBox::Ok); QPushButton* cancel = l.first()->button(QDialogButtonBox::Cancel); if (ok && cancel) { ok->setAutoDefault(false); ok->setDefault(false); ok->setText(QApplication::tr("Ok")); cancel->setAutoDefault(true); cancel->setDefault(true); cancel->setText(QApplication::tr("Cancel")); } else { qWarning() << "PasswordDialog: Missing button!"; } } else { qWarning() << "PasswordDialog: No QDialogButtonBox!"; } // using similar code, set QLabels to wrap for (auto* label : dialog.findChildren<QLabel*>()) label->setWordWrap(true); while (true) { int val = dialog.exec(); if (val == QDialog::Accepted) return QString(); ret = dialog.textValue(); if (!ret.isEmpty()) return ret; dialog.setTextValue(""); dialog.setLabelText(body + "\n\n" + tr("You must enter a non-empty password:")); } }
QString SshKeyGenerator::getPassword() const { QInputDialog d; d.setInputMode(QInputDialog::TextInput); d.setTextEchoMode(QLineEdit::Password); d.setWindowTitle(tr("Password for Private Key")); d.setLabelText(tr("It is recommended that you secure your private key\n" "with a password, which you can enter below.")); d.setOkButtonText(tr("Encrypt key file")); d.setCancelButtonText(tr("Do not encrypt key file")); int result = QDialog::Accepted; QString password; while (result == QDialog::Accepted && password.isEmpty()) { result = d.exec(); password = d.textValue(); } return result == QDialog::Accepted ? password : QString(); }
static bool execInputDialog_Int( const char *title, const char *label, int minVal, int maxVal, int &ret) { QInputDialog dlg; dlg.setWindowTitle(title); dlg.setLabelText(label); dlg.setOkButtonText("确定"); dlg.setCancelButtonText("取消"); dlg.setInputMode(QInputDialog::IntInput); dlg.setIntRange(minVal, maxVal); dlg.setIntValue(ret); if (dlg.exec() == QDialog::Accepted) { ret = dlg.intValue(); return true; } return false; }
void CMainWindow::on_cmdAdd_clicked() { // Input-Dialog zusammenbasteln QInputDialog *inDlg = new QInputDialog(this); inDlg->setOkButtonText("Platz suchen"); inDlg->setCancelButtonText("Suche abbrechen"); inDlg->setLabelText("Bitte geben Sie den oder die ICAO-Codes\ndes gesuchten Platzes ein\n(Mehrere ICAO-Codes durch Leerzeichen, Komma, Semikolon\noder Minus getrennt):"); // anzeigen und auswerten if(inDlg->exec() == QInputDialog::Accepted) { QString icao; icao = inDlg->textValue().toUpper(); QList<QString*> *lFields = parseFields(icao); mnet->getNewAirfields(lFields); } // Aufräumen delete inDlg; }
int FileListModel::importFromCsv(QWidget *parent, const QString &inFile) { QFile file(inFile); if(!file.open(QIODevice::ReadOnly)) { return CsvError_FileOpen; } QTextCodec *codec = NULL; QByteArray bomCheck = file.peek(16); if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xef\xbb\xbf")) { codec = QTextCodec::codecForName("UTF-8"); } else if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xff\xfe")) { codec = QTextCodec::codecForName("UTF-16LE"); } else if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xfe\xff")) { codec = QTextCodec::codecForName("UTF-16BE"); } else { const QString systemDefault = tr("(System Default)"); QStringList codecList; codecList.append(systemDefault); codecList.append(lamexp_available_codepages()); QInputDialog *input = new QInputDialog(parent); input->setLabelText(EXPAND(tr("Select ANSI Codepage for CSV file:"))); input->setOkButtonText(tr("OK")); input->setCancelButtonText(tr("Cancel")); input->setTextEchoMode(QLineEdit::Normal); input->setComboBoxItems(codecList); if(input->exec() < 1) { LAMEXP_DELETE(input); return CsvError_Aborted; } if(input->textValue().compare(systemDefault, Qt::CaseInsensitive)) { qDebug("User-selected codec is: %s", input->textValue().toLatin1().constData()); codec = QTextCodec::codecForName(input->textValue().toLatin1().constData()); } else { qDebug("Going to use the system's default codec!"); codec = QTextCodec::codecForName("System"); } LAMEXP_DELETE(input); } bomCheck.clear(); //----------------------// QTextStream stream(&file); stream.setAutoDetectUnicode(false); stream.setCodec(codec); QString headerLine = stream.readLine().simplified(); while(headerLine.isEmpty()) { if(stream.atEnd()) { qWarning("The file appears to be empty!"); return CsvError_FileRead; } qWarning("Skipping a blank line at beginning of CSV file!"); headerLine = stream.readLine().simplified(); } QStringList header = headerLine.split(";", QString::KeepEmptyParts); const int nCols = header.count(); const int nFiles = m_fileList.count(); if(nCols < 1) { qWarning("Header appears to be empty!"); return CsvError_FileRead; } bool *ignore = new bool[nCols]; memset(ignore, 0, sizeof(bool) * nCols); for(int i = 0; i < nCols; i++) { if((header[i] = header[i].trimmed()).isEmpty()) { ignore[i] = true; } } //----------------------// for(int i = 0; i < nFiles; i++) { if(stream.atEnd()) { LAMEXP_DELETE_ARRAY(ignore); return CsvError_Incomplete; } QString line = stream.readLine().simplified(); if(line.isEmpty()) { qWarning("Skipping a blank line in CSV file!"); continue; } QStringList data = line.split(";", QString::KeepEmptyParts); if(data.count() < header.count()) { qWarning("Skipping an incomplete line in CSV file!"); continue; } const QString key = m_fileList[i]; for(int j = 0; j < nCols; j++) { if(ignore[j]) { continue; } else if(CHECK_HDR(header.at(j), "POSITION")) { bool ok = false; unsigned int temp = data.at(j).trimmed().toUInt(&ok); if(ok) m_fileStore[key].metaInfo().setPosition(temp); } else if(CHECK_HDR(header.at(j), "TITLE")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setTitle(temp); } else if(CHECK_HDR(header.at(j), "ARTIST")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setArtist(temp); } else if(CHECK_HDR(header.at(j), "ALBUM")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setAlbum(temp); } else if(CHECK_HDR(header.at(j), "GENRE")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setGenre(temp); } else if(CHECK_HDR(header.at(j), "YEAR")) { bool ok = false; unsigned int temp = data.at(j).trimmed().toUInt(&ok); if(ok) m_fileStore[key].metaInfo().setYear(temp); } else if(CHECK_HDR(header.at(j), "COMMENT")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setComment(temp); } else { qWarning("Unkonw field '%s' will be ignored!", QUTF8(header.at(j))); ignore[j] = true; if(!checkArray(ignore, false, nCols)) { qWarning("No known fields left, aborting!"); return CsvError_NoTags; } } } } //----------------------// LAMEXP_DELETE_ARRAY(ignore); return CsvError_OK; }