forked from IJHack/QtPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigdialog.cpp
972 lines (875 loc) · 26.2 KB
/
configdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
#include "configdialog.h"
#include "keygendialog.h"
#include "mainwindow.h"
#include "ui_configdialog.h"
#include <QDebug>
#include <QDir>
#include <QMessageBox>
#ifdef Q_OS_WIN
#include <windows.h>
#endif
/**
* @brief ConfigDialog::ConfigDialog this sets up the configuration screen.
* @param parent
*/
ConfigDialog::ConfigDialog(MainWindow *parent)
: QDialog(parent), ui(new Ui::ConfigDialog) {
mainWindow = parent;
ui->setupUi(this);
ui->profileTable->verticalHeader()->hide();
ui->profileTable->horizontalHeader()->setStretchLastSection(true);
ui->label->setText(ui->label->text() + VERSION);
ui->comboBoxClipboard->clear();
ui->comboBoxClipboard->addItem(tr("No Clipboard"));
ui->comboBoxClipboard->addItem(tr("Always copy to clipboard"));
ui->comboBoxClipboard->addItem(tr("On-demand copy to clipboard"));
ui->comboBoxClipboard->setCurrentIndex(0);
}
/**
* @brief ConfigDialog::~ConfigDialog config destructor, makes sure the
* mainWindow knows about git, gpg and pass executables.
*/
ConfigDialog::~ConfigDialog() {
mainWindow->setGitExecutable(ui->gitPath->text());
mainWindow->setGpgExecutable(ui->gpgPath->text());
mainWindow->setPassExecutable(ui->passPath->text());
}
/**
* @brief ConfigDialog::setPassPath set the pass executable path.
* @param path
*/
void ConfigDialog::setPassPath(QString path) { ui->passPath->setText(path); }
/**
* @brief ConfigDialog::setGitPath set the git executable path.
* Make sure the checkBoxUseGit is updated.
* @param path
*/
void ConfigDialog::setGitPath(QString path) {
ui->gitPath->setText(path);
if (path.isEmpty()) {
useGit(false);
ui->checkBoxUseGit->setEnabled(false);
} else {
ui->checkBoxUseGit->setEnabled(true);
}
}
/**
* @brief ConfigDialog::setGpgPath set the gpg executable path.
* @param path
*/
void ConfigDialog::setGpgPath(QString path) { ui->gpgPath->setText(path); }
/**
* @brief ConfigDialog::setStorePath set the .password-store folder path.
* @param path
*/
void ConfigDialog::setStorePath(QString path) { ui->storePath->setText(path); }
/**
* @brief ConfigDialog::getPassPath return path to pass.
* @return
*/
QString ConfigDialog::getPassPath() { return ui->passPath->text(); }
/**
* @brief ConfigDialog::getGitPath return path to git.
* @return
*/
QString ConfigDialog::getGitPath() { return ui->gitPath->text(); }
/**
* @brief ConfigDialog::getGpgPath return path to gpg.
* @return
*/
QString ConfigDialog::getGpgPath() { return ui->gpgPath->text(); }
/**
* @brief ConfigDialog::getStorePath return path to .password-store.
* @return
*/
QString ConfigDialog::getStorePath() { return ui->storePath->text(); }
/**
* @brief ConfigDialog::usePass return wether or not we want to use pass (or
* native gpg+git etc).
* @return
*/
bool ConfigDialog::usePass() { return ui->radioButtonPass->isChecked(); }
/**
* @brief ConfigDialog::usePass set wether or not we want to use pass.
* Update radio buttons accordingly.
* @param usePass
*/
void ConfigDialog::usePass(bool usePass) {
if (usePass) {
ui->radioButtonNative->setChecked(false);
ui->radioButtonPass->setChecked(true);
} else {
ui->radioButtonNative->setChecked(true);
ui->radioButtonPass->setChecked(false);
}
setGroupBoxState();
}
/**
* @brief ConfigDialog::on_radioButtonNative_clicked wrapper for
* ConfigDialog::setGroupBoxState()
*/
void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
/**
* @brief ConfigDialog::on_radioButtonPass_clicked wrapper for
* ConfigDialog::setGroupBoxState()
*/
void ConfigDialog::on_radioButtonPass_clicked() { setGroupBoxState(); }
/**
* @brief ConfigDialog::setGroupBoxState update checkboxes.
*/
void ConfigDialog::setGroupBoxState() {
if (ui->radioButtonPass->isChecked()) {
ui->groupBoxNative->setEnabled(false);
ui->groupBoxPass->setEnabled(true);
} else {
ui->groupBoxNative->setEnabled(true);
ui->groupBoxPass->setEnabled(false);
}
}
/**
* @brief ConfigDialog::selectExecutable pop-up to choose an executable.
* @return
*/
QString ConfigDialog::selectExecutable() {
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setOption(QFileDialog::ReadOnly);
if (dialog.exec())
return dialog.selectedFiles().first();
else
return "";
}
/**
* @brief ConfigDialog::selectFolder pop-up to choose a folder.
* @return
*/
QString ConfigDialog::selectFolder() {
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
dialog.setFilter(QDir::NoFilter);
dialog.setOption(QFileDialog::ShowDirsOnly);
if (dialog.exec())
return dialog.selectedFiles().first();
else
return "";
}
/**
* @brief ConfigDialog::on_toolButtonGit_clicked get git application.
* Enable checkboxes if found.
*/
void ConfigDialog::on_toolButtonGit_clicked() {
QString git = selectExecutable();
if (!git.isEmpty()) {
ui->gitPath->setText(git);
ui->checkBoxUseGit->setEnabled(true);
} else {
useGit(false);
ui->checkBoxUseGit->setEnabled(false);
}
}
/**
* @brief ConfigDialog::on_toolButtonGpg_clicked get gpg application.
*/
void ConfigDialog::on_toolButtonGpg_clicked() {
QString gpg = selectExecutable();
if (!gpg.isEmpty())
ui->gpgPath->setText(gpg);
}
/**
* @brief ConfigDialog::on_toolButtonPass_clicked get pass application.
*/
void ConfigDialog::on_toolButtonPass_clicked() {
QString pass = selectExecutable();
if (!pass.isEmpty())
ui->passPath->setText(pass);
}
/**
* @brief ConfigDialog::on_toolButtonStore_clicked get .password-store
* location.s
*/
void ConfigDialog::on_toolButtonStore_clicked() {
QString store = selectFolder();
if (!store.isEmpty()) // TODO(annejan) call check
ui->storePath->setText(store);
}
/**
* @brief ConfigDialog::on_comboBoxClipboard_activated show and hide options.
* @param index of selectbox (0 = no clipboard).
*/
void ConfigDialog::on_comboBoxClipboard_activated(int index) {
if (index > 0) {
ui->checkBoxAutoclear->setEnabled(true);
ui->checkBoxHidePassword->setEnabled(true);
ui->checkBoxHideContent->setEnabled(true);
if (ui->checkBoxAutoclear->isChecked()) {
ui->spinBoxAutoclearSeconds->setEnabled(true);
ui->labelSeconds->setEnabled(true);
} else {
ui->spinBoxAutoclearSeconds->setEnabled(false);
ui->labelSeconds->setEnabled(false);
}
} else {
ui->checkBoxAutoclear->setEnabled(false);
ui->spinBoxAutoclearSeconds->setEnabled(false);
ui->labelSeconds->setEnabled(false);
ui->checkBoxHidePassword->setEnabled(false);
ui->checkBoxHideContent->setEnabled(false);
}
}
/**
* @brief ConfigDialog::on_checkBoxAutoclearPanel_clicked enable and disable
* options based on autoclear use.
*/
void ConfigDialog::on_checkBoxAutoclearPanel_clicked() {
if (ui->checkBoxAutoclearPanel->isChecked()) {
ui->spinBoxAutoclearPanelSeconds->setEnabled(true);
ui->labelPanelSeconds->setEnabled(true);
} else {
ui->spinBoxAutoclearPanelSeconds->setEnabled(false);
ui->labelPanelSeconds->setEnabled(false);
}
}
/**
* @brief ConfigDialog::useClipboard set the clipboard use from MainWindow.
*/
void ConfigDialog::useClipboard(MainWindow::clipBoardType useClipboard) {
ui->comboBoxClipboard->setCurrentIndex(static_cast<int>(useClipboard));
on_comboBoxClipboard_activated(static_cast<int>(useClipboard));
}
/**
* @brief ConfigDialog::useAutoclear set the clipboard autoclear use from
* MainWindow.
* @param useAutoclear
*/
void ConfigDialog::useAutoclear(bool useAutoclear) {
ui->checkBoxAutoclear->setChecked(useAutoclear);
on_checkBoxAutoclear_clicked();
}
/**
* @brief ConfigDialog::setAutoclear set the clipboard autoclear timout from
* MainWindow.
* @param seconds
*/
void ConfigDialog::setAutoclear(int seconds) {
ui->spinBoxAutoclearSeconds->setValue(seconds);
}
/**
* @brief ConfigDialog::useAutoclearPanel set the panel autoclear use from
* MainWindow.
* @param useAutoclearPanel
*/
void ConfigDialog::useAutoclearPanel(bool useAutoclearPanel) {
ui->checkBoxAutoclearPanel->setChecked(useAutoclearPanel);
on_checkBoxAutoclearPanel_clicked();
}
/**
* @brief ConfigDialog::setAutoclearPanel set the panel autoclear timout from
* MainWindow.
* @param seconds
*/
void ConfigDialog::setAutoclearPanel(int seconds) {
ui->spinBoxAutoclearPanelSeconds->setValue(seconds);
}
/**
* @brief ConfigDialog::useClipboard set the use of clipboard from MainWindow.
* @return
*/
MainWindow::clipBoardType ConfigDialog::useClipboard() {
return static_cast<MainWindow::clipBoardType>(
ui->comboBoxClipboard->currentIndex());
}
/**
* @brief ConfigDialog::useAutoclear return the use of clipboard autoclear.
* @return
*/
bool ConfigDialog::useAutoclear() { return ui->checkBoxAutoclear->isChecked(); }
/**
* @brief ConfigDialog::getAutoclear return the clipboard autoclear timout.
* @return
*/
int ConfigDialog::getAutoclear() {
return ui->spinBoxAutoclearSeconds->value();
}
/**
* @brief ConfigDialog::on_checkBoxAutoclear_clicked checkbox clicked, update
* state via ConfigDialog::on_comboBoxClipboard_activated
*/
void ConfigDialog::on_checkBoxAutoclear_clicked() {
on_comboBoxClipboard_activated(1);
}
/**
* @brief ConfigDialog::useAutoclearPanel return panel autoclear usage.
* @return
*/
bool ConfigDialog::useAutoclearPanel() {
return ui->checkBoxAutoclearPanel->isChecked();
}
/**
* @brief ConfigDialog::getAutoclearPanel return panel autoclear timeout.
* @return
*/
int ConfigDialog::getAutoclearPanel() {
return ui->spinBoxAutoclearPanelSeconds->value();
}
/**
* @brief ConfigDialog::hidePassword return preference for hiding passwords from
* shoulder-surfers.
* @return
*/
bool ConfigDialog::hidePassword() {
return ui->checkBoxHidePassword->isChecked();
}
/**
* @brief ConfigDialog::hideContent return preference for hiding all information
* from shoulder-surfers.
* @return
*/
bool ConfigDialog::hideContent() {
return ui->checkBoxHideContent->isChecked();
}
/**
* @brief ConfigDialog::hidePassword set preference for hiding passwords from
* shoulder-surfers.
* @param hidePassword
*/
void ConfigDialog::hidePassword(bool hidePassword) {
ui->checkBoxHidePassword->setChecked(hidePassword);
}
/**
* @brief ConfigDialog::hideContent set preference for hiding all content from
* shoulder-surfers.
* @param hideContent
*/
void ConfigDialog::hideContent(bool hideContent) {
ui->checkBoxHideContent->setChecked(hideContent);
}
/**
* @brief ConfigDialog::addGPGId return preference for always adding gpg-id
* changes to git.
* @return
*/
bool ConfigDialog::addGPGId() { return ui->checkBoxAddGPGId->isChecked(); }
/**
* @brief ConfigDialog::addGPGId set preference for always adding gpg-id changes
* to git.
* @param addGPGId
*/
void ConfigDialog::addGPGId(bool addGPGId) {
ui->checkBoxAddGPGId->setChecked(addGPGId);
}
/**
* @brief ConfigDialog::genKey tunnel function to make MainWindow generate a gpg
* key pair.
* @todo refactor the process to not be entangled so much.
* @param batch
* @param dialog
*/
void ConfigDialog::genKey(QString batch, QDialog *dialog) {
mainWindow->generateKeyPair(batch, dialog);
}
/**
* @brief ConfigDialog::setProfiles set the profiles and chosen profile from
* MainWindow.
* @param profiles
* @param profile
*/
void ConfigDialog::setProfiles(QHash<QString, QString> profiles,
QString profile) {
// qDebug() << profiles;
if (profiles.contains("")) {
profiles.remove("");
// remove weird "" key value pairs
}
ui->profileTable->setRowCount(profiles.count());
QHashIterator<QString, QString> i(profiles);
int n = 0;
while (i.hasNext()) {
i.next();
if (!i.value().isEmpty() && !i.key().isEmpty()) {
ui->profileTable->setItem(n, 0, new QTableWidgetItem(i.key()));
ui->profileTable->setItem(n, 1, new QTableWidgetItem(i.value()));
// qDebug() << "naam:" + i.key();
if (i.key() == profile)
ui->profileTable->selectRow(n);
}
++n;
}
}
/**
* @brief ConfigDialog::getProfiles return profile list.
* @return
*/
QHash<QString, QString> ConfigDialog::getProfiles() {
QHash<QString, QString> profiles;
// Check?
for (int i = 0; i < ui->profileTable->rowCount(); ++i) {
QTableWidgetItem *pathItem = ui->profileTable->item(i, 1);
if (0 != pathItem) {
QTableWidgetItem *item = ui->profileTable->item(i, 0);
if (item == 0) {
qDebug() << "empty name, should fix in frontend";
continue;
}
profiles.insert(item->text(), pathItem->text());
}
}
return profiles;
}
/**
* @brief ConfigDialog::on_addButton_clicked add a profile row.
*/
void ConfigDialog::on_addButton_clicked() {
int n = ui->profileTable->rowCount();
ui->profileTable->insertRow(n);
ui->profileTable->setItem(n, 1, new QTableWidgetItem(ui->storePath->text()));
ui->profileTable->selectRow(n);
ui->deleteButton->setEnabled(true);
}
/**
* @brief ConfigDialog::on_deleteButton_clicked remove a profile row.
*/
void ConfigDialog::on_deleteButton_clicked() {
QSet<int> selectedRows; // we use a set to prevent doubles
QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems();
if (itemList.count() == 0) {
QMessageBox::warning(this, tr("No profile selected"),
tr("No profile selected to delete"));
return;
}
QTableWidgetItem *item;
foreach (item, itemList)
selectedRows.insert(item->row());
// get a list, and sort it big to small
QList<int> rows = selectedRows.toList();
qSort(rows.begin(), rows.end());
// now actually do the removing:
foreach (int row, rows)
ui->profileTable->removeRow(row);
if (ui->profileTable->rowCount() < 1)
ui->deleteButton->setEnabled(false);
}
/**
* @brief ConfigDialog::criticalMessage weapper for showing critical messages in
* a popup.
* @param title
* @param text
*/
void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
}
/**
* @brief ConfigDialog::wizard first-time use wizard.
* @todo make this thing more reliable.
*/
void ConfigDialog::wizard() {
// mainWindow->checkConfig();
bool clean = false;
QString gpg = ui->gpgPath->text();
// QString gpg = mainWindow->getGpgExecutable();
if (!QFile(gpg).exists()) {
criticalMessage(
tr("GnuPG not found"),
tr("Please install GnuPG on your system.<br>Install "
"<strong>gpg</strong> using your favorite package manager<br>or <a "
"href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
"from GnuPG.org"));
clean = true;
}
QStringList names = mainWindow->getSecretKeys();
qDebug() << names;
if (QFile(gpg).exists() && names.empty()) {
KeygenDialog d(this);
if (!d.exec())
return;
}
QString passStore = ui->storePath->text();
if (!QFile(passStore).exists()) {
// TODO(annejan) pass version?
if (QMessageBox::question(
this, tr("Create password-store?"),
tr("Would you like to create a password-store at %1?")
.arg(passStore),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
QDir().mkdir(passStore);
#ifdef Q_OS_WIN
SetFileAttributes(passStore.toStdWString().c_str(),
FILE_ATTRIBUTE_HIDDEN);
#endif
if (useGit())
mainWindow->executePassGitInit();
mainWindow->userDialog(passStore);
}
}
if (!QFile(passStore + ".gpg-id").exists()) {
qDebug() << ".gpg-id file does not exist";
if (!clean) {
criticalMessage(tr("Password store not initialised"),
tr("The folder %1 doesn't seem to be a password store or "
"is not yet initialised.")
.arg(passStore));
}
while (!QFile(passStore).exists()) {
on_toolButtonStore_clicked();
// allow user to cancel
if (passStore == ui->storePath->text())
return;
passStore = ui->storePath->text();
}
if (!QFile(passStore + ".gpg-id").exists()) {
qDebug() << ".gpg-id file still does not exist :/";
// appears not to be store
// init yes / no ?
mainWindow->userDialog(passStore);
}
}
}
/**
* @brief ConfigDialog::useTrayIcon return preference for using a (system) tray
* icon.
* @return
*/
bool ConfigDialog::useTrayIcon() {
return ui->checkBoxUseTrayIcon->isChecked();
}
/**
* @brief ConfigDialog::hideOnClose return preference for hiding instead of
* closing (quitting) application.
* @return
*/
bool ConfigDialog::hideOnClose() {
return ui->checkBoxHideOnClose->isEnabled() &&
ui->checkBoxHideOnClose->isChecked();
}
/**
* @brief ConfigDialog::useTrayIcon set preference for using trayicon.
* Enable or disable related checkboxes accordingly.
* @param useSystray
*/
void ConfigDialog::useTrayIcon(bool useSystray) {
ui->checkBoxUseTrayIcon->setChecked(useSystray);
ui->checkBoxHideOnClose->setEnabled(useSystray);
ui->checkBoxStartMinimized->setEnabled(useSystray);
if (!useSystray) {
ui->checkBoxHideOnClose->setChecked(false);
ui->checkBoxStartMinimized->setChecked(false);
}
}
/**
* @brief ConfigDialog::hideOnClose set preference for hiding instead of closing
* (quitting) application.
* @param hideOnClose
*/
void ConfigDialog::hideOnClose(bool hideOnClose) {
ui->checkBoxHideOnClose->setChecked(hideOnClose);
}
/**
* @brief ConfigDialog::on_checkBoxUseTrayIcon_clicked enable and disable
* related checkboxes.
*/
void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
if (ui->checkBoxUseTrayIcon->isChecked()) {
ui->checkBoxHideOnClose->setEnabled(true);
ui->checkBoxStartMinimized->setEnabled(true);
} else {
ui->checkBoxStartMinimized->setEnabled(false);
ui->checkBoxHideOnClose->setEnabled(false);
}
}
/**
* @brief ConfigDialog::closeEvent close this window.
* @param event
*/
void ConfigDialog::closeEvent(QCloseEvent *event) {
// TODO(annejan) save window size or something?
event->accept();
}
/**
* @brief ConfigDialog::useGit set preference for using git.
* @param useGit
*/
void ConfigDialog::useGit(bool useGit) {
ui->checkBoxUseGit->setChecked(useGit);
on_checkBoxUseGit_clicked();
}
/**
* @brief ConfigDialog::useGit retrun preference for using git.
* @return
*/
bool ConfigDialog::useGit() { return ui->checkBoxUseGit->isChecked(); }
/**
* @brief ConfigDialog::on_checkBoxUseGit_clicked enable or disable related
* checkboxes.
*/
void ConfigDialog::on_checkBoxUseGit_clicked() {
ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
}
/**
* @brief ConfigDialog::on_toolButtonPwgen_clicked enable or disable related
* options in the interface.
*/
void ConfigDialog::on_toolButtonPwgen_clicked() {
QString pwgen = selectExecutable();
if (!pwgen.isEmpty()) {
ui->pwgenPath->setText(pwgen);
ui->checkBoxUsePwgen->setEnabled(true);
} else {
ui->checkBoxUsePwgen->setEnabled(false);
ui->checkBoxUsePwgen->setChecked(false);
}
}
/**
* @brief ConfigDialog::getPwgenPath return pwgen executable path.
* @return
*/
QString ConfigDialog::getPwgenPath() { return ui->pwgenPath->text(); }
/**
* @brief ConfigDialog::setPwgenPath set pwgen executable path.
* Enable or disable related options in the interface.
* @param pwgen
*/
void ConfigDialog::setPwgenPath(QString pwgen) {
ui->pwgenPath->setText(pwgen);
if (pwgen.isEmpty()) {
ui->checkBoxUsePwgen->setChecked(false);
ui->checkBoxUsePwgen->setEnabled(false);
}
on_checkBoxUsePwgen_clicked();
}
/**
* @brief ConfigDialog::on_checkBoxUsPwgen_clicked enable or disable related
* options in the interface.
*/
void ConfigDialog::on_checkBoxUsePwgen_clicked() {
bool usePwgen = ui->checkBoxUsePwgen->isChecked();
ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
ui->checkBoxLessRandom->setEnabled(usePwgen);
ui->checkBoxUseSymbols->setEnabled(usePwgen);
ui->lineEditPasswordChars->setEnabled(!usePwgen);
ui->labelPasswordChars->setEnabled(!usePwgen);
}
/**
* @brief ConfigDialog::usePwgen set preference for using pwgen (can be
* overruled buy empty pwgenPath).
* enable or disable related options in the interface via
* ConfigDialog::on_checkBoxUsePwgen_clicked
* @param usePwgen
*/
void ConfigDialog::usePwgen(bool usePwgen) {
if (ui->pwgenPath->text().isEmpty())
usePwgen = false;
ui->checkBoxUsePwgen->setChecked(usePwgen);
on_checkBoxUsePwgen_clicked();
}
/**
* @brief ConfigDialog::avoidCapitals set preference for avoiding uppercase
* letters using pwgen.
* @param avoidCapitals
*/
void ConfigDialog::avoidCapitals(bool avoidCapitals) {
ui->checkBoxAvoidCapitals->setChecked(avoidCapitals);
}
/**
* @brief ConfigDialog::avoidNumbers set preference for using numbers in pwgen
* generated password.
* @param avoidNumbers
*/
void ConfigDialog::avoidNumbers(bool avoidNumbers) {
ui->checkBoxAvoidNumbers->setChecked(avoidNumbers);
}
/**
* @brief ConfigDialog::lessRandom set preference for using less random
* passwords.
* @param lessRandom
*/
void ConfigDialog::lessRandom(bool lessRandom) {
ui->checkBoxLessRandom->setChecked(lessRandom);
}
/**
* @brief ConfigDialog::useSymbols set preference for using special characters
* in pwgen.
* @param useSymbols
*/
void ConfigDialog::useSymbols(bool useSymbols) {
ui->checkBoxUseSymbols->setChecked(useSymbols);
}
/**
* @brief ConfigDialog::setPasswordLength set the length of desired (generated)
* passwords.
* @param pwLen
*/
void ConfigDialog::setPasswordLength(int pwLen) {
ui->spinBoxPasswordLength->setValue(pwLen);
}
/**
* @brief ConfigDialog::setPasswordChars use these charcters to generate
* password (non-pwgen option).
* @param pwChars
*/
void ConfigDialog::setPasswordChars(QString pwChars) {
ui->lineEditPasswordChars->setText(pwChars);
}
/**
* @brief ConfigDialog::usePwgen return preference for using pwgen.
* @return
*/
bool ConfigDialog::usePwgen() { return ui->checkBoxUsePwgen->isChecked(); }
/**
* @brief ConfigDialog::avoidCapitals return preference for avoiding uppercase
* letters using pwgen.
* @return
*/
bool ConfigDialog::avoidCapitals() {
return ui->checkBoxAvoidCapitals->isChecked();
}
/**
* @brief ConfigDialog::avoidNumbers return preference for using numbers in
* generated password using pwgen.
* @return
*/
bool ConfigDialog::avoidNumbers() {
return ui->checkBoxAvoidNumbers->isChecked();
}
/**
* @brief ConfigDialog::lessRandom return preference for using less random
* passwords in pwgen.
* @return
*/
bool ConfigDialog::lessRandom() { return ui->checkBoxLessRandom->isChecked(); }
/**
* @brief ConfigDialog::useSymbols return preference for using special
* characters with pwgen.
* @return
*/
bool ConfigDialog::useSymbols() { return ui->checkBoxUseSymbols->isChecked(); }
/**
* @brief ConfigDialog::getPasswordLength return desired length for generated
* passwords.
* @return
*/
int ConfigDialog::getPasswordLength() {
return ui->spinBoxPasswordLength->value();
}
/**
* @brief ConfigDialog::getPasswordChars return characters to use in password
* generation (non-pwgen).
* @return
*/
QString ConfigDialog::getPasswordChars() {
return ui->lineEditPasswordChars->text();
}
/**
* @brief ConfigDialog::startMinimized return preference for starting
* application minimized (tray icon).
* @return
*/
bool ConfigDialog::startMinimized() {
return ui->checkBoxStartMinimized->isChecked();
}
/**
* @brief ConfigDialog::startMinimized set preference for starting application
* minimized (tray icon).
* @param startMinimized
*/
void ConfigDialog::startMinimized(bool startMinimized) {
ui->checkBoxStartMinimized->setChecked(startMinimized);
}
/**
* @brief ConfigDialog::on_checkBoxUseTemplate_clicked enable or disable the
* template field and options.
*/
void ConfigDialog::on_checkBoxUseTemplate_clicked() {
ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
ui->checkBoxTemplateAllFields->setEnabled(
ui->checkBoxUseTemplate->isChecked());
}
/**
* @brief ConfigDialog::useTemplate set preference for using templates.
* @param useTemplate
*/
void ConfigDialog::useTemplate(bool useTemplate) {
ui->checkBoxUseTemplate->setChecked(useTemplate);
on_checkBoxUseTemplate_clicked();
}
/**
* @brief ConfigDialog::useTemplate return preference for using templates.
* @return
*/
bool ConfigDialog::useTemplate() {
return ui->checkBoxUseTemplate->isChecked();
}
/**
* @brief ConfigDialog::setTemplate set the desired template.
* @param passTemplate
*/
void ConfigDialog::setTemplate(QString passTemplate) {
ui->plainTextEditTemplate->setPlainText(passTemplate);
}
/**
* @brief ConfigDialog::getTemplate return the desired template.
* @return
*/
QString ConfigDialog::getTemplate() {
return ui->plainTextEditTemplate->toPlainText();
}
/**
* @brief ConfigDialog::autoPull set preference for automatically pulling from
* git
* @param autoPull
*/
void ConfigDialog::autoPull(bool autoPull) {
ui->checkBoxAutoPull->setChecked(autoPull);
}
/**
* @brief ConfigDialog::autoPush set preference for automatically pushing to git
* @param autoPush
*/
void ConfigDialog::autoPush(bool autoPush) {
ui->checkBoxAutoPush->setChecked(autoPush);
}
/**
* @brief ConfigDialog::autoPull return preference for automatically pulling
* from git
* @return
*/
bool ConfigDialog::autoPull() { return ui->checkBoxAutoPull->isChecked(); }
/**
* @brief ConfigDialog::autoPush return preference for automatically pushing to
* git
* @return
*/
bool ConfigDialog::autoPush() { return ui->checkBoxAutoPush->isChecked(); }
/**
* @brief ConfigDialog::templateAllFields return preference for templating all
* tokenisable fields
* @return
*/
bool ConfigDialog::templateAllFields() {
return ui->checkBoxTemplateAllFields->isChecked();
}
/**
* @brief ConfigDialog::templateAllFields set preference for templating all
* tokenisable fields
* @param templateAll
*/
void ConfigDialog::templateAllFields(bool templateAll) {
ui->checkBoxTemplateAllFields->setChecked(templateAll);
}
/**
* @brief ConfigDialog::alwaysOnTop set preference for running application on
* top of others
* @param alwaysOnTop
*/
void ConfigDialog::alwaysOnTop(bool alwaysOnTop) {
ui->checkBoxAlwaysOnTop->setChecked(alwaysOnTop);
}
/**
* @brief ConfigDialog::alwaysOnTop return preference for running application on
* top of others.
* @return
*/
bool ConfigDialog::alwaysOnTop() {
return ui->checkBoxAlwaysOnTop->isChecked();
}