5#include "ui_configdialog.h"
12#include <QSystemTrayIcon>
13#include <QTableWidgetItem>
37 ui->spinBoxAutoclearPanelSeconds->setValue(
46 if (QSystemTrayIcon::isSystemTrayAvailable()) {
50 ui->checkBoxUseTrayIcon->setEnabled(
false);
51 ui->checkBoxUseTrayIcon->setToolTip(tr(
"System tray is not available"));
52 ui->checkBoxHideOnClose->setEnabled(
false);
53 ui->checkBoxStartMinimized->setEnabled(
false);
61 ui->checkBoxTemplateAllFields->setChecked(
68 ui->checkBoxUseOtp->hide();
69 ui->checkBoxUseQrencode->hide();
73 if (!isPassOtpAvailable()) {
74 ui->checkBoxUseOtp->setEnabled(
false);
75 ui->checkBoxUseOtp->setToolTip(
76 tr(
"Pass OTP extension needs to be installed"));
79 if (!isQrencodeAvailable()) {
80 ui->checkBoxUseQrencode->setEnabled(
false);
81 ui->checkBoxUseQrencode->setToolTip(tr(
"qrencode needs to be installed"));
100 ui->profileTable->verticalHeader()->hide();
101 ui->profileTable->horizontalHeader()->setSectionResizeMode(
102 1, QHeaderView::Stretch);
103 ui->label->setText(ui->label->text() + VERSION);
104 ui->comboBoxClipboard->clear();
106 ui->comboBoxClipboard->addItem(tr(
"No Clipboard"));
107 ui->comboBoxClipboard->addItem(tr(
"Always copy to clipboard"));
108 ui->comboBoxClipboard->addItem(tr(
"On-demand copy to clipboard"));
111 ui->comboBoxClipboard->setCurrentIndex(currentIndex);
112 on_comboBoxClipboard_activated(currentIndex);
114 QClipboard *clip = QApplication::clipboard();
115 if (!clip->supportsSelection()) {
117 ui->checkBoxSelection->setVisible(
false);
125 ui->tabWidget->setCurrentIndex(1);
128 connect(ui->profileTable, &QTableWidget::itemChanged,
this,
129 &ConfigDialog::onProfileTableItemChanged);
130 connect(
this, &ConfigDialog::accepted,
this, &ConfigDialog::on_accepted);
148void ConfigDialog::setGitPath(QString path) {
149 ui->gitPath->setText(path);
150 ui->checkBoxUseGit->setEnabled(!path.isEmpty());
151 if (path.isEmpty()) {
161void ConfigDialog::usePass(
bool usePass) {
162 ui->radioButtonNative->setChecked(!usePass);
163 ui->radioButtonPass->setChecked(usePass);
167void ConfigDialog::validate(QTableWidgetItem *item) {
170 if (item ==
nullptr) {
171 for (
int i = 0; i < ui->profileTable->rowCount(); i++) {
172 for (
int j = 0; j < ui->profileTable->columnCount(); j++) {
173 QTableWidgetItem *_item = ui->profileTable->item(i, j);
175 if (_item->text().isEmpty() && j != 2) {
176 _item->setBackground(Qt::red);
186 if (item->text().isEmpty() && item->column() != 2) {
187 item->setBackground(Qt::red);
192 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
195void ConfigDialog::on_accepted() {
208 ui->spinBoxAutoclearPanelSeconds->value());
216 ui->checkBoxUseTrayIcon->isChecked());
218 ui->checkBoxHideOnClose->isChecked());
220 ui->checkBoxStartMinimized->isChecked());
235 ui->checkBoxTemplateAllFields->isChecked());
243void ConfigDialog::on_autodetectButton_clicked() {
246 ui->passPath->setText(pass);
247 usePass(!pass.isEmpty());
252 ui->gpgPath->setText(gpg);
255 ui->gitPath->setText(git);
257 if (!pwgen.isEmpty())
258 ui->pwgenPath->setText(pwgen);
265void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
271void ConfigDialog::on_radioButtonPass_clicked() { setGroupBoxState(); }
277QStringList ConfigDialog::getSecretKeys() {
293void ConfigDialog::setGroupBoxState() {
294 bool state = ui->radioButtonPass->isChecked();
295 ui->groupBoxNative->setEnabled(!state);
296 ui->groupBoxPass->setEnabled(state);
303QString ConfigDialog::selectExecutable() {
304 QFileDialog dialog(
this);
305 dialog.setFileMode(QFileDialog::ExistingFile);
306 dialog.setOption(QFileDialog::ReadOnly);
308 return dialog.selectedFiles().constFirst();
317QString ConfigDialog::selectFolder() {
318 QFileDialog dialog(
this);
319 dialog.setFileMode(QFileDialog::Directory);
320 dialog.setFilter(QDir::NoFilter);
321 dialog.setOption(QFileDialog::ShowDirsOnly);
323 return dialog.selectedFiles().constFirst();
332void ConfigDialog::on_toolButtonGit_clicked() {
333 QString git = selectExecutable();
334 bool state = !git.isEmpty();
336 ui->gitPath->setText(git);
341 ui->checkBoxUseGit->setEnabled(state);
347void ConfigDialog::on_toolButtonGpg_clicked() {
348 QString gpg = selectExecutable();
350 ui->gpgPath->setText(gpg);
356void ConfigDialog::on_toolButtonPass_clicked() {
357 QString pass = selectExecutable();
359 ui->passPath->setText(pass);
366void ConfigDialog::on_toolButtonStore_clicked() {
367 QString store = selectFolder();
368 if (!store.isEmpty())
369 ui->storePath->setText(store);
376void ConfigDialog::on_comboBoxClipboard_activated(
int index) {
377 bool state = index > 0;
379 ui->checkBoxSelection->setEnabled(state);
380 ui->checkBoxAutoclear->setEnabled(state);
381 ui->checkBoxHidePassword->setEnabled(state);
382 ui->checkBoxHideContent->setEnabled(state);
384 ui->spinBoxAutoclearSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
385 ui->labelSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
387 ui->spinBoxAutoclearSeconds->setEnabled(
false);
388 ui->labelSeconds->setEnabled(
false);
396void ConfigDialog::on_checkBoxAutoclearPanel_clicked() {
397 bool state = ui->checkBoxAutoclearPanel->isChecked();
398 ui->spinBoxAutoclearPanelSeconds->setEnabled(state);
399 ui->labelPanelSeconds->setEnabled(state);
409 on_checkBoxSelection_clicked();
419 on_checkBoxAutoclear_clicked();
429 on_checkBoxAutoclearPanel_clicked();
436void ConfigDialog::on_checkBoxSelection_clicked() {
437 on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
444void ConfigDialog::on_checkBoxAutoclear_clicked() {
445 on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
465void ConfigDialog::setProfiles(QHash<QString, QHash<QString, QString>> profiles,
466 QString currentProfile) {
468 if (profiles.contains(
"")) {
473 ui->profileTable->setRowCount(profiles.count());
474 QHashIterator<QString, QHash<QString, QString>> i(profiles);
476 while (i.hasNext()) {
478 if (!i.value().isEmpty() && !i.key().isEmpty()) {
479 ui->profileTable->setItem(n, 0,
new QTableWidgetItem(i.key()));
480 ui->profileTable->setItem(n, 1,
481 new QTableWidgetItem(i.value().value(
"path")));
482 ui->profileTable->setItem(
483 n, 2,
new QTableWidgetItem(i.value().value(
"signingKey")));
485 if (i.key() == currentProfile)
486 ui->profileTable->selectRow(n);
497 QHash<QString, QHash<QString, QString>> profiles;
499 for (
int i = 0; i < ui->profileTable->rowCount(); ++i) {
500 QHash<QString, QString> profile;
501 QTableWidgetItem *pathItem = ui->profileTable->item(i, 1);
502 if (
nullptr != pathItem) {
503 QTableWidgetItem *item = ui->profileTable->item(i, 0);
504 if (item ==
nullptr) {
507 profile[
"path"] = pathItem->text();
508 QTableWidgetItem *signingKeyItem = ui->profileTable->item(i, 2);
509 if (
nullptr != signingKeyItem) {
510 profile[
"signingKey"] = signingKeyItem->text();
512 profiles.insert(item->text(), profile);
521void ConfigDialog::on_addButton_clicked() {
522 int n = ui->profileTable->rowCount();
523 ui->profileTable->insertRow(n);
524 ui->profileTable->setItem(n, 0,
new QTableWidgetItem());
525 ui->profileTable->setItem(n, 1,
new QTableWidgetItem(ui->storePath->text()));
526 ui->profileTable->setItem(n, 2,
new QTableWidgetItem());
527 ui->profileTable->selectRow(n);
528 ui->deleteButton->setEnabled(
true);
536void ConfigDialog::on_deleteButton_clicked() {
537 QSet<int> selectedRows;
538 QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems();
539 if (itemList.count() == 0) {
540 QMessageBox::warning(
this, tr(
"No profile selected"),
541 tr(
"No profile selected to delete"));
544 QTableWidgetItem *item;
545 foreach (item, itemList)
546 selectedRows.insert(item->row());
548 QList<int> rows = selectedRows.values();
549 std::sort(rows.begin(), rows.end());
551 foreach (
int row, rows)
552 ui->profileTable->removeRow(row);
553 if (ui->profileTable->rowCount() < 1)
554 ui->deleteButton->setEnabled(
false);
565void ConfigDialog::criticalMessage(
const QString &title,
const QString &text) {
566 QMessageBox::critical(
this, title, text, QMessageBox::Ok, QMessageBox::Ok);
569bool ConfigDialog::isQrencodeAvailable() {
574 which.start(
"which", QStringList() <<
"qrencode");
575 which.waitForFinished();
577 which.readAllStandardOutput().trimmed());
578 return which.exitCode() == 0;
582bool ConfigDialog::isPassOtpAvailable() {
596 on_autodetectButton_clicked();
599 QString gpg = ui->gpgPath->text();
600 if (!gpg.startsWith(
"wsl ") && !QFile(gpg).exists()) {
602 tr(
"GnuPG not found"),
605 tr(
"Please install GnuPG on your system.<br>Install "
606 "<strong>Ubuntu</strong> from the Microsoft Store to get it.<br>"
607 "If you already did so, make sure you started it once and<br>"
608 "click \"Autodetect\" in the next dialog.")
610 tr(
"Please install GnuPG on your system.<br>Install "
611 "<strong>Ubuntu</strong> from the Microsoft Store<br>or <a "
612 "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
616 tr(
"Please install GnuPG on your system.<br>Install "
617 "<strong>gpg</strong> using your favorite package manager<br>or "
619 "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
626 QStringList names = getSecretKeys();
632 if ((gpg.startsWith(
"wsl ") || QFile(gpg).exists()) && names.empty()) {
638 QString passStore = ui->storePath->text();
640 if (!QFile(passStore).exists()) {
642 if (QMessageBox::question(
643 this, tr(
"Create password-store?"),
644 tr(
"Would you like to create a password-store at %1?")
646 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
647 QDir().mkdir(passStore);
649 SetFileAttributes(passStore.toStdWString().c_str(),
650 FILE_ATTRIBUTE_HIDDEN);
652 if (ui->checkBoxUseGit->isChecked())
658 if (!QFile(QDir(passStore).filePath(
".gpg-id")).exists()) {
660 dbg() <<
".gpg-id file does not exist";
663 criticalMessage(tr(
"Password store not initialised"),
664 tr(
"The folder %1 doesn't seem to be a password store or "
665 "is not yet initialised.")
668 while (!QFile(passStore).exists()) {
669 on_toolButtonStore_clicked();
671 if (passStore == ui->storePath->text())
673 passStore = ui->storePath->text();
675 if (!QFile(passStore +
".gpg-id").exists()) {
677 dbg() <<
".gpg-id file still does not exist :/";
685 ui->checkBoxHidePassword->setCheckState(Qt::Checked);
694 if (QSystemTrayIcon::isSystemTrayAvailable()) {
695 ui->checkBoxUseTrayIcon->setChecked(useSystray);
696 ui->checkBoxHideOnClose->setEnabled(useSystray);
697 ui->checkBoxStartMinimized->setEnabled(useSystray);
700 ui->checkBoxHideOnClose->setChecked(
false);
701 ui->checkBoxStartMinimized->setChecked(
false);
710void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
711 bool state = ui->checkBoxUseTrayIcon->isChecked();
712 ui->checkBoxHideOnClose->setEnabled(state);
713 ui->checkBoxStartMinimized->setEnabled(state);
730 ui->checkBoxUseGit->setChecked(
useGit);
731 on_checkBoxUseGit_clicked();
739 ui->checkBoxUseOtp->setChecked(
useOtp);
754void ConfigDialog::on_checkBoxUseGit_clicked() {
755 ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
756 ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
757 ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
764void ConfigDialog::on_toolButtonPwgen_clicked() {
765 QString pwgen = selectExecutable();
766 if (!pwgen.isEmpty()) {
767 ui->pwgenPath->setText(pwgen);
768 ui->checkBoxUsePwgen->setEnabled(
true);
770 ui->checkBoxUsePwgen->setEnabled(
false);
771 ui->checkBoxUsePwgen->setChecked(
false);
781 ui->pwgenPath->setText(pwgen);
782 if (pwgen.isEmpty()) {
783 ui->checkBoxUsePwgen->setChecked(
false);
784 ui->checkBoxUsePwgen->setEnabled(
false);
786 on_checkBoxUsePwgen_clicked();
793void ConfigDialog::on_checkBoxUsePwgen_clicked() {
794 bool usePwgen = ui->checkBoxUsePwgen->isChecked();
795 ui->checkBoxAvoidCapitals->setEnabled(
usePwgen);
796 ui->checkBoxAvoidNumbers->setEnabled(
usePwgen);
797 ui->checkBoxLessRandom->setEnabled(
usePwgen);
798 ui->checkBoxUseSymbols->setEnabled(
usePwgen);
799 ui->lineEditPasswordChars->setEnabled(!
usePwgen);
800 ui->labelPasswordChars->setEnabled(!
usePwgen);
801 ui->passwordCharTemplateSelector->setEnabled(!
usePwgen);
812 if (ui->pwgenPath->text().isEmpty())
814 ui->checkBoxUsePwgen->setChecked(
usePwgen);
815 on_checkBoxUsePwgen_clicked();
820 ui->spinBoxPasswordLength->setValue(config.
length);
821 ui->passwordCharTemplateSelector->setCurrentIndex(config.
selected);
823 ui->lineEditPasswordChars->setEnabled(
false);
829 config.
length = ui->spinBoxPasswordLength->value();
831 ui->passwordCharTemplateSelector->currentIndex());
833 ui->lineEditPasswordChars->text();
843void ConfigDialog::on_passwordCharTemplateSelector_activated(
int index) {
844 ui->lineEditPasswordChars->setText(
847 ui->lineEditPasswordChars->setEnabled(
true);
849 ui->lineEditPasswordChars->setEnabled(
false);
857void ConfigDialog::on_checkBoxUseTemplate_clicked() {
858 ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
859 ui->checkBoxTemplateAllFields->setEnabled(
860 ui->checkBoxUseTemplate->isChecked());
863void ConfigDialog::onProfileTableItemChanged(QTableWidgetItem *item) {
873 on_checkBoxUseTemplate_clicked();
The ConfigDialog handles the configuration interface.
void setPasswordConfiguration(const PasswordConfiguration &config)
PasswordConfiguration getPasswordConfiguration()
void useOtp(bool useOtp)
ConfigDialog::useOtp set preference for using otp plugin.
void genKey(QString, QDialog *)
ConfigDialog::genKey tunnel function to make MainWindow generate a gpg key pair.
~ConfigDialog()
ConfigDialog::~ConfigDialog config destructor, makes sure the mainWindow knows about git,...
void useGit(bool useGit)
ConfigDialog::useGit set preference for using git.
void useAutoclearPanel(bool useAutoclearPanel)
ConfigDialog::useAutoclearPanel set the panel autoclear use from MainWindow.
QHash< QString, QHash< QString, QString > > getProfiles()
ConfigDialog::getProfiles return profile list.
void useAutoclear(bool useAutoclear)
ConfigDialog::useAutoclear set the clipboard autoclear use from MainWindow.
void useQrencode(bool useQrencode)
ConfigDialog::useOtp set preference for using otp plugin.
void useTemplate(bool useTemplate)
ConfigDialog::useTemplate set preference for using templates.
ConfigDialog(MainWindow *parent)
ConfigDialog::ConfigDialog this sets up the configuration screen.
void closeEvent(QCloseEvent *event)
ConfigDialog::closeEvent close this window.
void useTrayIcon(bool useSystray)
ConfigDialog::useTrayIcon set preference for using trayicon. Enable or disable related checkboxes acc...
void usePwgen(bool usePwgen)
ConfigDialog::usePwgen set preference for using pwgen (can be overruled buy empty pwgenPath)....
void wizard()
ConfigDialog::wizard first-time use wizard.
void setPwgenPath(QString)
ConfigDialog::setPwgenPath set pwgen executable path. Enable or disable related options in the interf...
void useSelection(bool useSelection)
ConfigDialog::useSelection set the clipboard type use from MainWindow.
Handles GPG keypair generation.
The MainWindow class does way too much, not only is it a switchboard, configuration handler and more,...
void generateKeyPair(QString, QDialog *)
MainWindow::generateKeyPair internal gpg keypair generator . .
void userDialog(QString="")
MainWindow::userDialog see MainWindow::onUsers()
QList< UserInfo > listKeys(QStringList keystrings, bool secret=false)
Pass::listKeys list users.
static void setStartMinimized(const bool &startMinimized)
static bool isUseAutoclearPanel(const bool &defaultValue=QVariant().toBool())
static void setAutoclearPanelSeconds(const int &autoClearPanelSeconds)
static void setPassExecutable(const QString &passExecutable)
static bool isUseSymbols(const bool &defaultValue=QVariant().toBool())
static void setHidePassword(const bool &hidePassword)
static bool isUseTemplate(const bool &defaultValue=QVariant().toBool())
static void setPwgenExecutable(const QString &pwgenExecutable)
static bool isTemplateAllFields(const bool &defaultValue=QVariant().toBool())
static int getAutoclearPanelSeconds(const int &defaultValue=QVariant().toInt())
static void setUseTrayIcon(const bool &useTrayIcon)
static bool isUseOtp(const bool &defaultValue=QVariant().toBool())
static bool isLessRandom(const bool &defaultValue=QVariant().toBool())
static void setPassStore(const QString &passStore)
static void setPasswordConfiguration(const PasswordConfiguration &config)
static bool isUseGit(const bool &defaultValue=QVariant().toBool())
static void setHideOnClose(const bool &hideOnClose)
static bool isUsePass(const bool &defaultValue=QVariant().toBool())
static bool isAlwaysOnTop(const bool &defaultValue=QVariant().toBool())
static QString getPassTemplate(const QString &defaultValue=QVariant().toString())
static void setGitExecutable(const QString &gitExecutable)
static void setUseOtp(const bool &useOtp)
static int getAutoclearSeconds(const int &defaultValue=QVariant().toInt())
static void setProfiles(const QHash< QString, QHash< QString, QString > > &profiles)
static QString getProfile(const QString &defaultValue=QVariant().toString())
static void setUsePwgen(const bool &usePwgen)
static bool isHideOnClose(const bool &defaultValue=QVariant().toBool())
static bool isAvoidNumbers(const bool &defaultValue=QVariant().toBool())
static QString getPwgenExecutable(const QString &defaultValue=QVariant().toString())
static bool isAutoPull(const bool &defaultValue=QVariant().toBool())
static bool isUseTrayIcon(const bool &defaultValue=QVariant().toBool())
static bool isDisplayAsIs(const bool &defaultValue=QVariant().toBool())
static QHash< QString, QHash< QString, QString > > getProfiles()
static void setUseTemplate(const bool &useTemplate)
static bool isUsePwgen(const bool &defaultValue=QVariant().toBool())
static bool isAvoidCapitals(const bool &defaultValue=QVariant().toBool())
static void setAutoPull(const bool &autoPull)
static void setPassTemplate(const QString &passTemplate)
static void setGpgExecutable(const QString &gpgExecutable)
static bool isStartMinimized(const bool &defaultValue=QVariant().toBool())
static void setVersion(const QString &version)
static void setUseAutoclear(const bool &useAutoclear)
static void setAlwaysOnTop(const bool &alwaysOnTop)
static QString getGpgExecutable(const QString &defaultValue=QVariant().toString())
static void setDisplayAsIs(const bool &displayAsIs)
static void setUseMonospace(const bool &useMonospace)
static void setAvoidCapitals(const bool &avoidCapitals)
static PasswordConfiguration getPasswordConfiguration()
static void setQrencodeExecutable(const QString &qrencodeExecutable)
static void setAddGPGId(const bool &addGPGId)
static void setUsePass(const bool &usePass)
static bool isUseMonospace(const bool &defaultValue=QVariant().toBool())
static bool isUseQrencode(const bool &defaultValue=QVariant().toBool())
static int getClipBoardTypeRaw(const Enums::clipBoardType &defaultvalue=Enums::CLIPBOARD_NEVER)
static bool isAutoPush(const bool &defaultValue=QVariant().toBool())
static bool isHideContent(const bool &defaultValue=QVariant().toBool())
static QString getPassStore(const QString &defaultValue=QVariant().toString())
static void setUseAutoclearPanel(const bool &useAutoclearPanel)
static void setAutoclearSeconds(const int &autoClearSeconds)
static void setNoLineWrapping(const bool &noLineWrapping)
static void setUseQrencode(const bool &useQrencode)
static bool isNoLineWrapping(const bool &defaultValue=QVariant().toBool())
static void setAvoidNumbers(const bool &avoidNumbers)
static void setAutoPush(const bool &autoPush)
static void setClipBoardType(const int &clipBoardType)
static bool isUseAutoclear(const bool &defaultValue=QVariant().toBool())
static void setLessRandom(const bool &lessRandom)
static void setHideContent(const bool &hideContent)
static QString getPassExecutable(const QString &defaultValue=QVariant().toString())
static QString getGitExecutable(const QString &defaultValue=QVariant().toString())
static void setUseSelection(const bool &useSelection)
static void setTemplateAllFields(const bool &templateAllFields)
static void setUseSymbols(const bool &useSymbols)
static bool isAddGPGId(const bool &defaultValue=QVariant().toBool())
static bool isHidePassword(const bool &defaultValue=QVariant().toBool())
static bool isUseSelection(const bool &defaultValue=QVariant().toBool())
static void setUseGit(const bool &useGit)
static bool checkConfig()
Util::checkConfig do we have prequisite settings?
static QString normalizeFolderPath(QString path)
Util::normalizeFolderPath let's always end folders with a QDir::separator()
static QString findBinaryInPath(QString binary)
Util::findBinaryInPath search for executables.
Holds the Password configuration settings.
int length
Length of the password.
enum PasswordConfiguration::characterSet selected
characterSet
The selected character set.
QString Characters[CHARSETS_COUNT]
The different character sets.
Stores key info lines including validity, creation date and more.
QString name
UserInfo::name full name.