QtPass 1.5.1
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
configdialog.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
3#include "configdialog.h"
4#include "keygendialog.h"
5#include "mainwindow.h"
6#include "qtpasssettings.h"
7#include "ui_configdialog.h"
8#include "util.h"
9#include <QClipboard>
10#include <QDir>
11#include <QFileDialog>
12#include <QMessageBox>
13#include <QPushButton>
14#include <QSystemTrayIcon>
15#include <QTableWidgetItem>
16#include <utility>
17#ifdef Q_OS_WIN
18#include <windows.h>
19#endif
20
21#ifdef QT_DEBUG
22#include "debughelper.h"
23#endif
24
30 : QDialog(parent), ui(new Ui::ConfigDialog) {
31 mainWindow = parent;
32 ui->setupUi(this);
33
34 ui->passPath->setText(QtPassSettings::getPassExecutable());
36 ui->gpgPath->setText(QtPassSettings::getGpgExecutable());
37 ui->storePath->setText(QtPassSettings::getPassStore());
38
39 ui->spinBoxAutoclearSeconds->setValue(QtPassSettings::getAutoclearSeconds());
40 ui->spinBoxAutoclearPanelSeconds->setValue(
42 ui->checkBoxHidePassword->setChecked(QtPassSettings::isHidePassword());
43 ui->checkBoxHideContent->setChecked(QtPassSettings::isHideContent());
44 ui->checkBoxUseMonospace->setChecked(QtPassSettings::isUseMonospace());
45 ui->checkBoxDisplayAsIs->setChecked(QtPassSettings::isDisplayAsIs());
46 ui->checkBoxNoLineWrapping->setChecked(QtPassSettings::isNoLineWrapping());
47 ui->checkBoxAddGPGId->setChecked(QtPassSettings::isAddGPGId(true));
48
49 if (QSystemTrayIcon::isSystemTrayAvailable()) {
50 ui->checkBoxHideOnClose->setChecked(QtPassSettings::isHideOnClose());
51 ui->checkBoxStartMinimized->setChecked(QtPassSettings::isStartMinimized());
52 } else {
53 ui->checkBoxUseTrayIcon->setEnabled(false);
54 ui->checkBoxUseTrayIcon->setToolTip(tr("System tray is not available"));
55 ui->checkBoxHideOnClose->setEnabled(false);
56 ui->checkBoxStartMinimized->setEnabled(false);
57 }
58
59 ui->checkBoxAvoidCapitals->setChecked(QtPassSettings::isAvoidCapitals());
60 ui->checkBoxAvoidNumbers->setChecked(QtPassSettings::isAvoidNumbers());
61 ui->checkBoxLessRandom->setChecked(QtPassSettings::isLessRandom());
62 ui->checkBoxUseSymbols->setChecked(QtPassSettings::isUseSymbols());
63 ui->plainTextEditTemplate->setPlainText(QtPassSettings::getPassTemplate());
64 ui->checkBoxTemplateAllFields->setChecked(
66 ui->checkBoxAutoPull->setChecked(QtPassSettings::isAutoPull());
67 ui->checkBoxAutoPush->setChecked(QtPassSettings::isAutoPush());
68 ui->checkBoxAlwaysOnTop->setChecked(QtPassSettings::isAlwaysOnTop());
69
70#if defined(Q_OS_WIN)
71 ui->checkBoxUseOtp->hide();
72 ui->checkBoxUseQrencode->hide();
73 ui->label_10->hide();
74#endif
75
76 if (!isPassOtpAvailable()) {
77 ui->checkBoxUseOtp->setEnabled(false);
78 ui->checkBoxUseOtp->setToolTip(
79 tr("Pass OTP extension needs to be installed"));
80 }
81
82 if (!isQrencodeAvailable()) {
83 ui->checkBoxUseQrencode->setEnabled(false);
84 ui->checkBoxUseQrencode->setToolTip(tr("qrencode needs to be installed"));
85 }
86
90
96
99
102
103 ui->profileTable->verticalHeader()->hide();
104 ui->profileTable->horizontalHeader()->setSectionResizeMode(
105 1, QHeaderView::Stretch);
106 ui->label->setText(ui->label->text() + VERSION);
107 ui->comboBoxClipboard->clear();
108
109 ui->comboBoxClipboard->addItem(tr("No Clipboard"));
110 ui->comboBoxClipboard->addItem(tr("Always copy to clipboard"));
111 ui->comboBoxClipboard->addItem(tr("On-demand copy to clipboard"));
112
113 int currentIndex = QtPassSettings::getClipBoardTypeRaw();
114 ui->comboBoxClipboard->setCurrentIndex(currentIndex);
115 on_comboBoxClipboard_activated(currentIndex);
116
117 QClipboard *clip = QApplication::clipboard();
118 if (!clip->supportsSelection()) {
119 useSelection(false);
120 ui->checkBoxSelection->setVisible(false);
121 } else {
123 }
124
125 if (Util::checkConfig()) {
126 // Show Programs tab, which is likely
127 // what the user needs to fix now.
128 ui->tabWidget->setCurrentIndex(1);
129 }
130
131 connect(ui->profileTable, &QTableWidget::itemChanged, this,
132 &ConfigDialog::onProfileTableItemChanged);
133 connect(this, &ConfigDialog::accepted, this, &ConfigDialog::on_accepted);
134}
135
141 QtPassSettings::setGitExecutable(ui->gitPath->text());
142 QtPassSettings::setGpgExecutable(ui->gpgPath->text());
143 QtPassSettings::setPassExecutable(ui->passPath->text());
144}
145
151void ConfigDialog::setGitPath(const QString &path) {
152 ui->gitPath->setText(path);
153 ui->checkBoxUseGit->setEnabled(!path.isEmpty());
154 if (path.isEmpty()) {
155 useGit(false);
156 }
157}
158
164void ConfigDialog::usePass(bool usePass) {
165 ui->radioButtonNative->setChecked(!usePass);
166 ui->radioButtonPass->setChecked(usePass);
167 setGroupBoxState();
168}
169
170void ConfigDialog::validate(QTableWidgetItem *item) {
171 bool status = true;
172
173 if (item == nullptr) {
174 for (int i = 0; i < ui->profileTable->rowCount(); i++) {
175 for (int j = 0; j < ui->profileTable->columnCount(); j++) {
176 QTableWidgetItem *_item = ui->profileTable->item(i, j);
177
178 if (_item->text().isEmpty() && j != 2) {
179 _item->setBackground(Qt::red);
180 status = false;
181 break;
182 }
183 }
184
185 if (!status) {
186 break;
187 }
188 }
189 } else {
190 if (item->text().isEmpty() && item->column() != 2) {
191 item->setBackground(Qt::red);
192 status = false;
193 }
194 }
195
196 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
197}
198
199void ConfigDialog::on_accepted() {
200 QtPassSettings::setPassExecutable(ui->passPath->text());
201 QtPassSettings::setGitExecutable(ui->gitPath->text());
202 QtPassSettings::setGpgExecutable(ui->gpgPath->text());
204 Util::normalizeFolderPath(ui->storePath->text()));
205 QtPassSettings::setUsePass(ui->radioButtonPass->isChecked());
206 QtPassSettings::setClipBoardType(ui->comboBoxClipboard->currentIndex());
207 QtPassSettings::setUseSelection(ui->checkBoxSelection->isChecked());
208 QtPassSettings::setUseAutoclear(ui->checkBoxAutoclear->isChecked());
209 QtPassSettings::setAutoclearSeconds(ui->spinBoxAutoclearSeconds->value());
210 QtPassSettings::setUseAutoclearPanel(ui->checkBoxAutoclearPanel->isChecked());
212 ui->spinBoxAutoclearPanelSeconds->value());
213 QtPassSettings::setHidePassword(ui->checkBoxHidePassword->isChecked());
214 QtPassSettings::setHideContent(ui->checkBoxHideContent->isChecked());
215 QtPassSettings::setUseMonospace(ui->checkBoxUseMonospace->isChecked());
216 QtPassSettings::setDisplayAsIs(ui->checkBoxDisplayAsIs->isChecked());
217 QtPassSettings::setNoLineWrapping(ui->checkBoxNoLineWrapping->isChecked());
218 QtPassSettings::setAddGPGId(ui->checkBoxAddGPGId->isChecked());
219 QtPassSettings::setUseTrayIcon(ui->checkBoxUseTrayIcon->isEnabled() &&
220 ui->checkBoxUseTrayIcon->isChecked());
221 QtPassSettings::setHideOnClose(ui->checkBoxHideOnClose->isEnabled() &&
222 ui->checkBoxHideOnClose->isChecked());
223 QtPassSettings::setStartMinimized(ui->checkBoxStartMinimized->isEnabled() &&
224 ui->checkBoxStartMinimized->isChecked());
226 QtPassSettings::setUseGit(ui->checkBoxUseGit->isChecked());
227 QtPassSettings::setUseOtp(ui->checkBoxUseOtp->isChecked());
228 QtPassSettings::setUseQrencode(ui->checkBoxUseQrencode->isChecked());
229 QtPassSettings::setPwgenExecutable(ui->pwgenPath->text());
230 QtPassSettings::setUsePwgen(ui->checkBoxUsePwgen->isChecked());
231 QtPassSettings::setAvoidCapitals(ui->checkBoxAvoidCapitals->isChecked());
232 QtPassSettings::setAvoidNumbers(ui->checkBoxAvoidNumbers->isChecked());
233 QtPassSettings::setLessRandom(ui->checkBoxLessRandom->isChecked());
234 QtPassSettings::setUseSymbols(ui->checkBoxUseSymbols->isChecked());
236 QtPassSettings::setUseTemplate(ui->checkBoxUseTemplate->isChecked());
237 QtPassSettings::setPassTemplate(ui->plainTextEditTemplate->toPlainText());
239 ui->checkBoxTemplateAllFields->isChecked());
240 QtPassSettings::setAutoPush(ui->checkBoxAutoPush->isChecked());
241 QtPassSettings::setAutoPull(ui->checkBoxAutoPull->isChecked());
242 QtPassSettings::setAlwaysOnTop(ui->checkBoxAlwaysOnTop->isChecked());
243
245}
246
247void ConfigDialog::on_autodetectButton_clicked() {
248 QString pass = Util::findBinaryInPath("pass");
249 if (!pass.isEmpty()) {
250 ui->passPath->setText(pass);
251 }
252 usePass(!pass.isEmpty());
253 QString gpg = Util::findBinaryInPath("gpg2");
254 if (gpg.isEmpty()) {
255 gpg = Util::findBinaryInPath("gpg");
256 }
257 if (!gpg.isEmpty()) {
258 ui->gpgPath->setText(gpg);
259 }
260 QString git = Util::findBinaryInPath("git");
261 if (!git.isEmpty()) {
262 ui->gitPath->setText(git);
263 }
264 QString pwgen = Util::findBinaryInPath("pwgen");
265 if (!pwgen.isEmpty()) {
266 ui->pwgenPath->setText(pwgen);
267 }
268}
269
274void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
275
280void ConfigDialog::on_radioButtonPass_clicked() { setGroupBoxState(); }
281
286auto ConfigDialog::getSecretKeys() -> QStringList {
287 QList<UserInfo> keys = QtPassSettings::getPass()->listKeys("", true);
288 QStringList names;
289
290 if (keys.empty()) {
291 return names;
292 }
293
294 foreach (const UserInfo &sec, keys)
295 names << sec.name;
296
297 return names;
298}
299
303void ConfigDialog::setGroupBoxState() {
304 bool state = ui->radioButtonPass->isChecked();
305 ui->groupBoxNative->setEnabled(!state);
306 ui->groupBoxPass->setEnabled(state);
307}
308
313auto ConfigDialog::selectExecutable() -> QString {
314 QFileDialog dialog(this);
315 dialog.setFileMode(QFileDialog::ExistingFile);
316 dialog.setOption(QFileDialog::ReadOnly);
317 if (dialog.exec()) {
318 return dialog.selectedFiles().constFirst();
319 }
320
321 return {};
322}
323
328auto ConfigDialog::selectFolder() -> QString {
329 QFileDialog dialog(this);
330 dialog.setFileMode(QFileDialog::Directory);
331 dialog.setFilter(QDir::NoFilter);
332 dialog.setOption(QFileDialog::ShowDirsOnly);
333 if (dialog.exec()) {
334 return dialog.selectedFiles().constFirst();
335 }
336
337 return {};
338}
339
344void ConfigDialog::on_toolButtonGit_clicked() {
345 QString git = selectExecutable();
346 bool state = !git.isEmpty();
347 if (state) {
348 ui->gitPath->setText(git);
349 } else {
350 useGit(false);
351 }
352
353 ui->checkBoxUseGit->setEnabled(state);
354}
355
359void ConfigDialog::on_toolButtonGpg_clicked() {
360 QString gpg = selectExecutable();
361 if (!gpg.isEmpty()) {
362 ui->gpgPath->setText(gpg);
363 }
364}
365
369void ConfigDialog::on_toolButtonPass_clicked() {
370 QString pass = selectExecutable();
371 if (!pass.isEmpty()) {
372 ui->passPath->setText(pass);
373 }
374}
375
380void ConfigDialog::on_toolButtonStore_clicked() {
381 QString store = selectFolder();
382 if (!store.isEmpty()) { // TODO(annejan): call check
383 ui->storePath->setText(store);
384 }
385}
386
391void ConfigDialog::on_comboBoxClipboard_activated(int index) {
392 bool state = index > 0;
393
394 ui->checkBoxSelection->setEnabled(state);
395 ui->checkBoxAutoclear->setEnabled(state);
396 ui->checkBoxHidePassword->setEnabled(state);
397 ui->checkBoxHideContent->setEnabled(state);
398 if (state) {
399 ui->spinBoxAutoclearSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
400 ui->labelSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
401 } else {
402 ui->spinBoxAutoclearSeconds->setEnabled(false);
403 ui->labelSeconds->setEnabled(false);
404 }
405}
406
411void ConfigDialog::on_checkBoxAutoclearPanel_clicked() {
412 bool state = ui->checkBoxAutoclearPanel->isChecked();
413 ui->spinBoxAutoclearPanelSeconds->setEnabled(state);
414 ui->labelPanelSeconds->setEnabled(state);
415}
416
422void ConfigDialog::useSelection(bool useSelection) {
423 ui->checkBoxSelection->setChecked(useSelection);
424 on_checkBoxSelection_clicked();
425}
426
432void ConfigDialog::useAutoclear(bool useAutoclear) {
433 ui->checkBoxAutoclear->setChecked(useAutoclear);
434 on_checkBoxAutoclear_clicked();
435}
436
442void ConfigDialog::useAutoclearPanel(bool useAutoclearPanel) {
443 ui->checkBoxAutoclearPanel->setChecked(useAutoclearPanel);
444 on_checkBoxAutoclearPanel_clicked();
445}
446
451void ConfigDialog::on_checkBoxSelection_clicked() {
452 on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
453}
454
459void ConfigDialog::on_checkBoxAutoclear_clicked() {
460 on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
461}
462
470void ConfigDialog::genKey(const QString &batch, QDialog *dialog) {
471 mainWindow->generateKeyPair(batch, dialog);
472}
473
480void ConfigDialog::setProfiles(QHash<QString, QHash<QString, QString>> profiles,
481 const QString &currentProfile) {
482 // dbg()<< profiles;
483 if (profiles.contains("")) {
484 profiles.remove("");
485 // remove weird "" key value pairs
486 }
487
488 ui->profileTable->setRowCount(profiles.count());
489 QHashIterator<QString, QHash<QString, QString>> i(profiles);
490 int n = 0;
491 while (i.hasNext()) {
492 i.next();
493 if (!i.value().isEmpty() && !i.key().isEmpty()) {
494 ui->profileTable->setItem(n, 0, new QTableWidgetItem(i.key()));
495 ui->profileTable->setItem(n, 1,
496 new QTableWidgetItem(i.value().value("path")));
497 ui->profileTable->setItem(
498 n, 2, new QTableWidgetItem(i.value().value("signingKey")));
499 // dbg()<< "naam:" + i.key();
500 if (i.key() == currentProfile) {
501 ui->profileTable->selectRow(n);
502 }
503 }
504 ++n;
505 }
506}
507
512auto ConfigDialog::getProfiles() -> QHash<QString, QHash<QString, QString>> {
513 QHash<QString, QHash<QString, QString>> profiles;
514 // Check?
515 for (int i = 0; i < ui->profileTable->rowCount(); ++i) {
516 QHash<QString, QString> profile;
517 QTableWidgetItem *pathItem = ui->profileTable->item(i, 1);
518 if (nullptr != pathItem) {
519 QTableWidgetItem *item = ui->profileTable->item(i, 0);
520 if (item == nullptr) {
521 continue;
522 }
523 profile["path"] = pathItem->text();
524 QTableWidgetItem *signingKeyItem = ui->profileTable->item(i, 2);
525 if (nullptr != signingKeyItem) {
526 profile["signingKey"] = signingKeyItem->text();
527 }
528 profiles.insert(item->text(), profile);
529 }
530 }
531 return profiles;
532}
533
537void ConfigDialog::on_addButton_clicked() {
538 int n = ui->profileTable->rowCount();
539 ui->profileTable->insertRow(n);
540 ui->profileTable->setItem(n, 0, new QTableWidgetItem());
541 ui->profileTable->setItem(n, 1, new QTableWidgetItem(ui->storePath->text()));
542 ui->profileTable->setItem(n, 2, new QTableWidgetItem());
543 ui->profileTable->selectRow(n);
544 ui->deleteButton->setEnabled(true);
545
546 validate();
547}
548
552void ConfigDialog::on_deleteButton_clicked() {
553 QSet<int> selectedRows; // we use a set to prevent doubles
554 QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems();
555 if (itemList.count() == 0) {
556 QMessageBox::warning(this, tr("No profile selected"),
557 tr("No profile selected to delete"));
558 return;
559 }
560 QTableWidgetItem *item;
561 foreach (item, itemList)
562 selectedRows.insert(item->row());
563 // get a list, and sort it big to small
564 QList<int> rows = selectedRows.values();
565 std::sort(rows.begin(), rows.end());
566 // now actually do the removing:
567 foreach (int row, rows)
568 ui->profileTable->removeRow(row);
569 if (ui->profileTable->rowCount() < 1) {
570 ui->deleteButton->setEnabled(false);
571 }
572
573 validate();
574}
575
582void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
583 QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
584}
585
586auto ConfigDialog::isQrencodeAvailable() -> bool {
587#ifdef Q_OS_WIN
588 return false;
589#else
590 QProcess which;
591 which.start("which", QStringList() << "qrencode");
592 which.waitForFinished();
594 which.readAllStandardOutput().trimmed());
595 return which.exitCode() == 0;
596#endif
597}
598
599auto ConfigDialog::isPassOtpAvailable() -> bool {
600#ifdef Q_OS_WIN
601 return false;
602#else
603 QProcess pass;
604 pass.start(QtPassSettings::getPassExecutable(), QStringList() << "otp"
605 << "--help");
606 pass.waitForFinished(2000);
607 return pass.exitCode() == 0;
608#endif
609}
610
617 on_autodetectButton_clicked();
618
619 if (!checkGpgExistence()) {
620 return;
621 }
622 if (!checkSecretKeys()) {
623 return;
624 }
625 if (!checkPasswordStore()) {
626 return;
627 }
628 handleGpgIdFile();
629
630 ui->checkBoxHidePassword->setCheckState(Qt::Checked);
631}
632
633auto ConfigDialog::checkGpgExistence() -> bool {
634 QString gpg = ui->gpgPath->text();
635 if (!gpg.startsWith("wsl ") && !QFile(gpg).exists()) {
636 criticalMessage(
637 tr("GnuPG not found"),
638#ifdef Q_OS_WIN
639#ifdef WINSTORE
640 tr("Please install GnuPG on your system.<br>Install "
641 "<strong>Ubuntu</strong> from the Microsoft Store to get it.<br>"
642 "If you already did so, make sure you started it once and<br>"
643 "click \"Autodetect\" in the next dialog.")
644#else
645 tr("Please install GnuPG on your system.<br>Install "
646 "<strong>Ubuntu</strong> from the Microsoft Store<br>or <a "
647 "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
648 "from GnuPG.org")
649#endif
650#else
651 tr("Please install GnuPG on your system.<br>Install "
652 "<strong>gpg</strong> using your favorite package manager<br>or "
653 "<a "
654 "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
655 "from GnuPG.org")
656#endif
657 );
658 return false;
659 }
660 return true;
661}
662
663auto ConfigDialog::checkSecretKeys() -> bool {
664 QString gpg = ui->gpgPath->text();
665 QStringList names = getSecretKeys();
666
667#ifdef QT_DEBUG
668 dbg() << names;
669#endif
670
671 if ((gpg.startsWith("wsl ") || QFile(gpg).exists()) && names.empty()) {
672 KeygenDialog d(this);
673 return d.exec();
674 }
675 return true;
676}
677
678auto ConfigDialog::checkPasswordStore() -> bool {
679 QString passStore = ui->storePath->text();
680
681 if (!QFile(passStore).exists()) {
682 if (QMessageBox::question(
683 this, tr("Create password-store?"),
684 tr("Would you like to create a password-store at %1?")
685 .arg(passStore),
686 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
687 if (!QDir().mkdir(passStore)) {
688 QMessageBox::warning(
689 this, tr("Error"),
690 tr("Failed to create password-store at: %1").arg(passStore));
691 return false;
692 }
693#ifdef Q_OS_WIN
694 SetFileAttributes(passStore.toStdWString().c_str(),
695 FILE_ATTRIBUTE_HIDDEN);
696#endif
697 if (ui->checkBoxUseGit->isChecked()) {
698 emit mainWindow->passGitInitNeeded();
699 }
700 mainWindow->userDialog(passStore);
701 }
702 }
703 return true;
704}
705
706void ConfigDialog::handleGpgIdFile() {
707 QString passStore = ui->storePath->text();
708 if (!QFile(QDir(passStore).filePath(".gpg-id")).exists()) {
709#ifdef QT_DEBUG
710 dbg() << ".gpg-id file does not exist";
711#endif
712 criticalMessage(tr("Password store not initialised"),
713 tr("The folder %1 doesn't seem to be a password store or "
714 "is not yet initialised.")
715 .arg(passStore));
716
717 while (!QFile(passStore).exists()) {
718 on_toolButtonStore_clicked();
719 if (passStore == ui->storePath->text()) {
720 return;
721 }
722 passStore = ui->storePath->text();
723 }
724 if (!QFile(passStore + ".gpg-id").exists()) {
725#ifdef QT_DEBUG
726 dbg() << ".gpg-id file still does not exist :/";
727#endif
728 mainWindow->userDialog(passStore);
729 }
730 }
731}
732
738void ConfigDialog::useTrayIcon(bool useSystray) {
739 if (QSystemTrayIcon::isSystemTrayAvailable()) {
740 ui->checkBoxUseTrayIcon->setChecked(useSystray);
741 ui->checkBoxHideOnClose->setEnabled(useSystray);
742 ui->checkBoxStartMinimized->setEnabled(useSystray);
743
744 if (!useSystray) {
745 ui->checkBoxHideOnClose->setChecked(false);
746 ui->checkBoxStartMinimized->setChecked(false);
747 }
748 }
749}
750
755void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
756 bool state = ui->checkBoxUseTrayIcon->isChecked();
757 ui->checkBoxHideOnClose->setEnabled(state);
758 ui->checkBoxStartMinimized->setEnabled(state);
759}
760
765void ConfigDialog::closeEvent(QCloseEvent *event) {
766 // TODO(annejan): save window size or something?
767 event->accept();
768}
769
774void ConfigDialog::useGit(bool useGit) {
775 ui->checkBoxUseGit->setChecked(useGit);
776 on_checkBoxUseGit_clicked();
777}
778
783void ConfigDialog::useOtp(bool useOtp) {
784 ui->checkBoxUseOtp->setChecked(useOtp);
785}
786
791void ConfigDialog::useQrencode(bool useQrencode) {
792 ui->checkBoxUseQrencode->setChecked(useQrencode);
793}
794
799void ConfigDialog::on_checkBoxUseGit_clicked() {
800 ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
801 ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
802 ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
803}
804
809void ConfigDialog::on_toolButtonPwgen_clicked() {
810 QString pwgen = selectExecutable();
811 if (!pwgen.isEmpty()) {
812 ui->pwgenPath->setText(pwgen);
813 ui->checkBoxUsePwgen->setEnabled(true);
814 } else {
815 ui->checkBoxUsePwgen->setEnabled(false);
816 ui->checkBoxUsePwgen->setChecked(false);
817 }
818}
819
825void ConfigDialog::setPwgenPath(const QString &pwgen) {
826 ui->pwgenPath->setText(pwgen);
827 if (pwgen.isEmpty()) {
828 ui->checkBoxUsePwgen->setChecked(false);
829 ui->checkBoxUsePwgen->setEnabled(false);
830 }
831 on_checkBoxUsePwgen_clicked();
832}
833
838void ConfigDialog::on_checkBoxUsePwgen_clicked() {
839 bool usePwgen = ui->checkBoxUsePwgen->isChecked();
840 ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
841 ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
842 ui->checkBoxLessRandom->setEnabled(usePwgen);
843 ui->checkBoxUseSymbols->setEnabled(usePwgen);
844 ui->lineEditPasswordChars->setEnabled(!usePwgen);
845 ui->labelPasswordChars->setEnabled(!usePwgen);
846 ui->passwordCharTemplateSelector->setEnabled(!usePwgen);
847}
848
856void ConfigDialog::usePwgen(bool usePwgen) {
857 if (ui->pwgenPath->text().isEmpty()) {
858 usePwgen = false;
859 }
860 ui->checkBoxUsePwgen->setChecked(usePwgen);
861 on_checkBoxUsePwgen_clicked();
862}
863
865 const PasswordConfiguration &config) {
866 ui->spinBoxPasswordLength->setValue(config.length);
867 ui->passwordCharTemplateSelector->setCurrentIndex(config.selected);
869 ui->lineEditPasswordChars->setEnabled(false);
870 }
871 ui->lineEditPasswordChars->setText(config.Characters[config.selected]);
872}
873
876 config.length = ui->spinBoxPasswordLength->value();
877 config.selected = static_cast<PasswordConfiguration::characterSet>(
878 ui->passwordCharTemplateSelector->currentIndex());
880 ui->lineEditPasswordChars->text();
881 return config;
882}
883
890void ConfigDialog::on_passwordCharTemplateSelector_activated(int index) {
891 ui->lineEditPasswordChars->setText(
892 QtPassSettings::getPasswordConfiguration().Characters[index]);
893 if (index == 3) {
894 ui->lineEditPasswordChars->setEnabled(true);
895 } else {
896 ui->lineEditPasswordChars->setEnabled(false);
897 }
898}
899
904void ConfigDialog::on_checkBoxUseTemplate_clicked() {
905 ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
906 ui->checkBoxTemplateAllFields->setEnabled(
907 ui->checkBoxUseTemplate->isChecked());
908}
909
910void ConfigDialog::onProfileTableItemChanged(QTableWidgetItem *item) {
911 validate(item);
912}
913
918void ConfigDialog::useTemplate(bool useTemplate) {
919 ui->checkBoxUseTemplate->setChecked(useTemplate);
920 on_checkBoxUseTemplate_clicked();
921}
The ConfigDialog handles the configuration interface.
void setPasswordConfiguration(const PasswordConfiguration &config)
auto getProfiles() -> QHash< QString, QHash< QString, QString > >
ConfigDialog::getProfiles return profile list.
void useOtp(bool useOtp)
ConfigDialog::useOtp set preference for using otp plugin.
~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.
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 setPwgenPath(const QString &)
ConfigDialog::setPwgenPath set pwgen executable path. Enable or disable related options in the interf...
auto getPasswordConfiguration() -> PasswordConfiguration
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 useSelection(bool useSelection)
ConfigDialog::useSelection set the clipboard type use from MainWindow.
void genKey(const QString &, QDialog *)
ConfigDialog::genKey tunnel function to make MainWindow generate a gpg key pair.
Handles GPG keypair generation.
The MainWindow class does way too much, not only is it a switchboard, configuration handler and more,...
Definition mainwindow.h:39
void generateKeyPair(const QString &, QDialog *)
MainWindow::generateKeyPair internal gpg keypair generator . .
void userDialog(const QString &="")
MainWindow::userDialog see MainWindow::onUsers()
static auto isUseSelection(const bool &defaultValue=QVariant().toBool()) -> bool
static void setStartMinimized(const bool &startMinimized)
static auto isUseAutoclear(const bool &defaultValue=QVariant().toBool()) -> bool
static void setAutoclearPanelSeconds(const int &autoClearPanelSeconds)
static void setPassExecutable(const QString &passExecutable)
static auto isStartMinimized(const bool &defaultValue=QVariant().toBool()) -> bool
static auto getClipBoardTypeRaw(const Enums::clipBoardType &defaultvalue=Enums::CLIPBOARD_NEVER) -> int
static void setHidePassword(const bool &hidePassword)
static auto isUseOtp(const bool &defaultValue=QVariant().toBool()) -> bool
static void setPwgenExecutable(const QString &pwgenExecutable)
static auto getPwgenExecutable(const QString &defaultValue=QVariant().toString()) -> QString
static void setUseTrayIcon(const bool &useTrayIcon)
static auto isNoLineWrapping(const bool &defaultValue=QVariant().toBool()) -> bool
static void setPassStore(const QString &passStore)
static auto isHideContent(const bool &defaultValue=QVariant().toBool()) -> bool
static void setPasswordConfiguration(const PasswordConfiguration &config)
static void setHideOnClose(const bool &hideOnClose)
static auto getPass() -> Pass *
static auto getPasswordConfiguration() -> PasswordConfiguration
static auto isUseQrencode(const bool &defaultValue=QVariant().toBool()) -> bool
static auto isUseAutoclearPanel(const bool &defaultValue=QVariant().toBool()) -> bool
static auto isAutoPull(const bool &defaultValue=QVariant().toBool()) -> bool
static void setGitExecutable(const QString &gitExecutable)
static auto isUseGit(const bool &defaultValue=QVariant().toBool()) -> bool
static void setUseOtp(const bool &useOtp)
static void setProfiles(const QHash< QString, QHash< QString, QString > > &profiles)
static void setUsePwgen(const bool &usePwgen)
static auto isTemplateAllFields(const bool &defaultValue=QVariant().toBool()) -> bool
static auto isUsePass(const bool &defaultValue=QVariant().toBool()) -> bool
static auto getPassStore(const QString &defaultValue=QVariant().toString()) -> QString
static auto isUseTemplate(const bool &defaultValue=QVariant().toBool()) -> bool
static auto isUseTrayIcon(const bool &defaultValue=QVariant().toBool()) -> bool
static void setUseTemplate(const bool &useTemplate)
static auto isAvoidCapitals(const bool &defaultValue=QVariant().toBool()) -> bool
static auto isAddGPGId(const bool &defaultValue=QVariant().toBool()) -> bool
static auto getGpgExecutable(const QString &defaultValue=QVariant().toString()) -> QString
static void setAutoPull(const bool &autoPull)
static void setPassTemplate(const QString &passTemplate)
static auto isUseSymbols(const bool &defaultValue=QVariant().toBool()) -> bool
static void setGpgExecutable(const QString &gpgExecutable)
static void setVersion(const QString &version)
static void setUseAutoclear(const bool &useAutoclear)
static auto isLessRandom(const bool &defaultValue=QVariant().toBool()) -> bool
static void setAlwaysOnTop(const bool &alwaysOnTop)
static auto getPassTemplate(const QString &defaultValue=QVariant().toString()) -> QString
static void setDisplayAsIs(const bool &displayAsIs)
static void setUseMonospace(const bool &useMonospace)
static void setAvoidCapitals(const bool &avoidCapitals)
static void setQrencodeExecutable(const QString &qrencodeExecutable)
static auto getProfile(const QString &defaultValue=QVariant().toString()) -> QString
static auto isUseMonospace(const bool &defaultValue=QVariant().toBool()) -> bool
static void setAddGPGId(const bool &addGPGId)
static void setUsePass(const bool &usePass)
static auto getAutoclearPanelSeconds(const int &defaultValue=QVariant().toInt()) -> int
static auto isUsePwgen(const bool &defaultValue=QVariant().toBool()) -> bool
static auto isAlwaysOnTop(const bool &defaultValue=QVariant().toBool()) -> bool
static auto isAvoidNumbers(const bool &defaultValue=QVariant().toBool()) -> bool
static auto isHidePassword(const bool &defaultValue=QVariant().toBool()) -> bool
static auto getPassExecutable(const QString &defaultValue=QVariant().toString()) -> QString
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 void setAvoidNumbers(const bool &avoidNumbers)
static auto isHideOnClose(const bool &defaultValue=QVariant().toBool()) -> bool
static void setAutoPush(const bool &autoPush)
static void setClipBoardType(const int &clipBoardType)
static auto getProfiles() -> QHash< QString, QHash< QString, QString > >
static void setLessRandom(const bool &lessRandom)
static auto getAutoclearSeconds(const int &defaultValue=QVariant().toInt()) -> int
static void setHideContent(const bool &hideContent)
static auto isAutoPush(const bool &defaultValue=QVariant().toBool()) -> bool
static void setUseSelection(const bool &useSelection)
static auto getGitExecutable(const QString &defaultValue=QVariant().toString()) -> QString
static void setTemplateAllFields(const bool &templateAllFields)
static void setUseSymbols(const bool &useSymbols)
static auto isDisplayAsIs(const bool &defaultValue=QVariant().toBool()) -> bool
static void setUseGit(const bool &useGit)
static auto normalizeFolderPath(QString path) -> QString
Util::normalizeFolderPath let's always end folders with a QDir::separator()
Definition util.cpp:81
static auto checkConfig() -> bool
Util::checkConfig do we have prequisite settings?
Definition util.cpp:146
static auto findBinaryInPath(QString binary) -> QString
Util::findBinaryInPath search for executables.
Definition util.cpp:93
#define dbg()
Definition debughelper.h:9
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.
Definition userinfo.h:13
QString name
UserInfo::name full name.
Definition userinfo.h:34