Skip to content

Commit

Permalink
Display "(CUSTOM)" prefix for user-provided wordlists
Browse files Browse the repository at this point in the history
  • Loading branch information
snipfoo committed Aug 3, 2021
1 parent 1c6d343 commit a54bb8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions share/translations/keepassx_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5363,6 +5363,10 @@ Expect some bugs and minor issues, this version is not meant for production use.
<source>Wordlist:</source>
<translation>Wordlist:</translation>
</message>
<message>
<source>(CUSTOM)</source>
<translation>(CUSTOM)</translation>
</message>
<message>
<source>Word Separator:</source>
<translation>Word Separator:</translation>
Expand Down
6 changes: 5 additions & 1 deletion share/translations/keepassx_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5312,6 +5312,10 @@ Attendez-vous à des bogues et des problèmes mineurs. Cette version n’est pas
<source>Wordlist:</source>
<translation>Liste de mots :</translation>
</message>
<message>
<source>(CUSTOM)</source>
<translation>(PERSONNALISÉE)</translation>
</message>
<message>
<source>Word Separator:</source>
<translation>Séparateur de mot :</translation>
Expand Down Expand Up @@ -7861,4 +7865,4 @@ Exemple : JBSWY3DPEHPK3PXP</translation>
<translation>Aucune clé matérielle détectée</translation>
</message>
</context>
</TS>
</TS>
26 changes: 18 additions & 8 deletions src/gui/PasswordGeneratorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,25 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent)
m_ui->wordCaseComboBox->addItem(tr("UPPER CASE"), PassphraseGenerator::UPPERCASE);
m_ui->wordCaseComboBox->addItem(tr("Title Case"), PassphraseGenerator::TITLECASE);

// load system-wide wordlists
QDir path(resources()->wordlistPath(""));
QStringList files = path.entryList(QDir::Files);
for (auto name = files.begin(); name != files.end(); ++name) {
m_ui->comboBoxWordList->addItem(*name, *name);
}

// load user-provided wordlists
path = QDir(resources()->userWordlistPath(""));
if (path.exists()) {
QString textPrefix = tr("(CUSTOM)") + " ";
QString pathPrefix = path.absolutePath() + "/";
QStringList userFiles = path.entryList(QDir::Files);
for (auto name = userFiles.begin(); name != userFiles.end(); ++name) {
name->prepend(pathPrefix);
m_ui->comboBoxWordList->addItem(textPrefix + *name, pathPrefix + *name);
}
files += userFiles;
}
m_ui->comboBoxWordList->addItems(files);
if (files.size() > 1) {

if (m_ui->comboBoxWordList->count() > 1) {
m_ui->comboBoxWordList->setVisible(true);
m_ui->labelWordList->setVisible(true);
} else {
Expand Down Expand Up @@ -165,7 +171,10 @@ void PasswordGeneratorWidget::loadSettings()
// Diceware config
m_ui->spinBoxWordCount->setValue(config()->get(Config::PasswordGenerator_WordCount).toInt());
m_ui->editWordSeparator->setText(config()->get(Config::PasswordGenerator_WordSeparator).toString());
m_ui->comboBoxWordList->setCurrentText(config()->get(Config::PasswordGenerator_WordList).toString());
int i = m_ui->comboBoxWordList->findData(config()->get(Config::PasswordGenerator_WordList).toString());
if (i > -1) {
m_ui->comboBoxWordList->setCurrentIndex(i);
}
m_ui->wordCaseComboBox->setCurrentIndex(config()->get(Config::PasswordGenerator_WordCase).toInt());

// Password or diceware?
Expand Down Expand Up @@ -206,7 +215,7 @@ void PasswordGeneratorWidget::saveSettings()
// Diceware config
config()->set(Config::PasswordGenerator_WordCount, m_ui->spinBoxWordCount->value());
config()->set(Config::PasswordGenerator_WordSeparator, m_ui->editWordSeparator->text());
config()->set(Config::PasswordGenerator_WordList, m_ui->comboBoxWordList->currentText());
config()->set(Config::PasswordGenerator_WordList, m_ui->comboBoxWordList->currentData());
config()->set(Config::PasswordGenerator_WordCase, m_ui->wordCaseComboBox->currentIndex());

// Password or diceware?
Expand Down Expand Up @@ -541,8 +550,9 @@ void PasswordGeneratorWidget::updateGenerator()
static_cast<PassphraseGenerator::PassphraseWordCase>(m_ui->wordCaseComboBox->currentData().toInt()));

m_dicewareGenerator->setWordCount(m_ui->spinBoxWordCount->value());
if (!m_ui->comboBoxWordList->currentText().isEmpty()) {
QString path = m_ui->comboBoxWordList->currentText();
const QVariant itemData = m_ui->comboBoxWordList->currentData();
if (itemData.type() == QMetaType::QString && !itemData.toString().isEmpty()) {
QString path = itemData.toString();
if (!path.startsWith("/")) {
path = resources()->wordlistPath(path);
}
Expand Down

0 comments on commit a54bb8a

Please sign in to comment.