34
34
*/
35
35
MainWindow::MainWindow (QWidget *parent)
36
36
: QMainWindow(parent), ui(new Ui::MainWindow), fusedav(this ), keygen(NULL ),
37
- tray(NULL ), pass( nullptr ) {
37
+ tray(NULL ) {
38
38
// connect(process.data(), SIGNAL(readyReadStandardOutput()), this,
39
39
// SLOT(readyRead()));
40
-
41
- // TODO(bezet): this should be reconnected dynamically when pass changes
42
- connect (&rpass, SIGNAL (error (QProcess::ProcessError)), this ,
43
- SLOT (processError (QProcess::ProcessError)));
44
- connect (&rpass, SIGNAL (finished (int , QProcess::ExitStatus)), this ,
45
- SLOT (processFinished (int , QProcess::ExitStatus)));
46
- connect (&rpass, SIGNAL (startingExecuteWrapper ()), this ,
47
- SLOT (executeWrapperStarted ()));
48
- connect (&rpass, SIGNAL (statusMsg (QString, int )), this ,
49
- SLOT (showStatusMessage (QString, int )));
50
- connect (&rpass, SIGNAL (critical (QString, QString)), this ,
51
- SLOT (critical (QString, QString)));
52
-
53
- connect (&ipass, SIGNAL (error (QProcess::ProcessError)), this ,
54
- SLOT (processError (QProcess::ProcessError)));
55
- connect (&ipass, SIGNAL (finished (int , QProcess::ExitStatus)), this ,
56
- SLOT (processFinished (int , QProcess::ExitStatus)));
57
- connect (&ipass, SIGNAL (startingExecuteWrapper ()), this ,
58
- SLOT (executeWrapperStarted ()));
59
- connect (&ipass, SIGNAL (statusMsg (QString, int )), this ,
60
- SLOT (showStatusMessage (QString, int )));
61
- connect (&ipass, SIGNAL (critical (QString, QString)), this ,
62
- SLOT (critical (QString, QString)));
63
- // only for ipass
64
- connect (&ipass, SIGNAL (startReencryptPath ()), this ,
65
- SLOT (startReencryptPath ()));
66
- connect (&ipass, SIGNAL (endReencryptPath ()), this , SLOT (endReencryptPath ()));
67
- connect (&ipass, SIGNAL (lastDecrypt (QString)), this ,
68
- SLOT (setLastDecrypt (QString)));
69
-
70
40
ui->setupUi (this );
71
41
enableUiElements (true );
72
42
execQueue = new QQueue<execQueueItem>;
@@ -100,6 +70,23 @@ MainWindow::MainWindow(QWidget *parent)
100
70
#if QT_VERSION >= QT_VERSION_CHECK(5,2,0)
101
71
ui->lineEdit ->setClearButtonEnabled (true );
102
72
#endif
73
+ connect (QtPassSettings::getPass (), SIGNAL (error (QProcess::ProcessError)), this ,
74
+ SLOT (processError (QProcess::ProcessError)));
75
+ connect (QtPassSettings::getPass (), SIGNAL (finished (int , QProcess::ExitStatus)), this ,
76
+ SLOT (processFinished (int , QProcess::ExitStatus)));
77
+ connect (QtPassSettings::getPass (), SIGNAL (startingExecuteWrapper ()), this ,
78
+ SLOT (executeWrapperStarted ()));
79
+ connect (QtPassSettings::getPass (), SIGNAL (statusMsg (QString, int )), this ,
80
+ SLOT (showStatusMessage (QString, int )));
81
+ connect (QtPassSettings::getPass (), SIGNAL (critical (QString, QString)), this ,
82
+ SLOT (critical (QString, QString)));
83
+
84
+ // only for ipass
85
+ connect (QtPassSettings::getImitatePass (), SIGNAL (startReencryptPath ()), this ,
86
+ SLOT (startReencryptPath ()));
87
+ connect (QtPassSettings::getImitatePass (), SIGNAL (endReencryptPath ()), this , SLOT (endReencryptPath ()));
88
+ connect (QtPassSettings::getImitatePass (), SIGNAL (lastDecrypt (QString)), this ,
89
+ SLOT (setLastDecrypt (QString)));
103
90
}
104
91
105
92
/* *
@@ -343,15 +330,7 @@ bool MainWindow::checkConfig() {
343
330
this , SLOT (showBrowserContextMenu (const QPoint &)));
344
331
345
332
updateProfileBox ();
346
-
347
- // TODO(bezet): make this check unnecessary
348
- if (pass == nullptr ) {
349
- if (QtPassSettings::isUsePass ())
350
- pass = &rpass;
351
- else
352
- pass = &ipass;
353
- }
354
- pass->updateEnv ();
333
+ QtPassSettings::getPass ()->updateEnv ();
355
334
356
335
if (!QtPassSettings::isUseGit () ||
357
336
(QtPassSettings::getGitExecutable ().isEmpty () &&
@@ -381,7 +360,6 @@ void MainWindow::config() {
381
360
// Automatically default to pass if it's available
382
361
if (freshStart && QFile (QtPassSettings::getPassExecutable ()).exists ()) {
383
362
QtPassSettings::setUsePass (true );
384
- pass = &rpass;
385
363
}
386
364
387
365
d->setPassPath (QtPassSettings::getPassExecutable ());
@@ -429,10 +407,6 @@ void MainWindow::config() {
429
407
QtPassSettings::setPassStore (
430
408
Util::normalizeFolderPath (d->getStorePath ()));
431
409
QtPassSettings::setUsePass (d->usePass ());
432
- if (d->usePass ())
433
- pass = &rpass;
434
- else
435
- pass = &ipass;
436
410
QtPassSettings::setClipBoardType (d->useClipboard ());
437
411
QtPassSettings::setUseAutoclear (d->useAutoclear ());
438
412
QtPassSettings::setAutoclearSeconds (d->getAutoclear ());
@@ -482,7 +456,7 @@ void MainWindow::config() {
482
456
483
457
if (freshStart && Util::checkConfig ())
484
458
config ();
485
- pass ->updateEnv ();
459
+ QtPassSettings::getPass () ->updateEnv ();
486
460
if (!QtPassSettings::isUseGit () ||
487
461
(QtPassSettings::getGitExecutable ().isEmpty () &&
488
462
QtPassSettings::getPassExecutable ().isEmpty ())) {
@@ -512,7 +486,7 @@ void MainWindow::config() {
512
486
void MainWindow::on_updateButton_clicked () {
513
487
ui->statusBar ->showMessage (tr (" Updating password-store" ), 2000 );
514
488
currentAction = GIT;
515
- pass ->GitPull ();
489
+ QtPassSettings::getPass () ->GitPull ();
516
490
}
517
491
518
492
/* *
@@ -521,7 +495,7 @@ void MainWindow::on_updateButton_clicked() {
521
495
void MainWindow::on_pushButton_clicked () {
522
496
ui->statusBar ->showMessage (tr (" Updating password-store" ), 2000 );
523
497
currentAction = GIT;
524
- pass ->GitPush ();
498
+ QtPassSettings::getPass () ->GitPush ();
525
499
}
526
500
527
501
@@ -559,7 +533,7 @@ void MainWindow::on_treeView_clicked(const QModelIndex &index) {
559
533
ui->passwordName ->setText (getFile (index , true ));
560
534
if (!file.isEmpty () && !cleared) {
561
535
currentAction = GPG;
562
- pass ->Show (file);
536
+ QtPassSettings::getPass () ->Show (file);
563
537
} else {
564
538
clearPanel (false );
565
539
ui->editButton ->setEnabled (false );
@@ -605,7 +579,7 @@ void MainWindow::deselect() {
605
579
*/
606
580
void MainWindow::executePassGitInit () {
607
581
qDebug () << " Pass git init called" ;
608
- pass ->GitInit ();
582
+ QtPassSettings::getPass () ->GitInit ();
609
583
}
610
584
611
585
void MainWindow::executeWrapperStarted () {
@@ -630,8 +604,8 @@ void MainWindow::readyRead(bool finished = false) {
630
604
QString output = " " ;
631
605
QString error = " " ;
632
606
if (currentAction != GPG_INTERNAL) {
633
- error = pass ->readAllStandardError ();
634
- QByteArray processOutBytes = pass ->readAllStandardOutput ();
607
+ error = QtPassSettings::getPass () ->readAllStandardError ();
608
+ QByteArray processOutBytes = QtPassSettings::getPass () ->readAllStandardOutput ();
635
609
QTextCodec *codec = QTextCodec::codecForLocale ();
636
610
output = codec->toUnicode (processOutBytes);
637
611
if (finished && currentAction == GPG) {
@@ -836,7 +810,7 @@ void MainWindow::processError(QProcess::ProcessError error) {
836
810
ui->textBrowser ->setText (errorString);
837
811
// TODO(bezet): this probably shall be done in finished handler(I guess it
838
812
// finishes even on error)
839
- if (pass ->state () == QProcess::NotRunning)
813
+ if (QtPassSettings::getPass () ->state () == QProcess::NotRunning)
840
814
enableUiElements (true );
841
815
}
842
816
@@ -934,7 +908,7 @@ void MainWindow::setPassword(QString file, bool overwrite, bool isNew = false) {
934
908
newValue += " \n " ;
935
909
936
910
currentAction = EDIT;
937
- pass ->Insert (file, newValue, overwrite);
911
+ QtPassSettings::getPass () ->Insert (file, newValue, overwrite);
938
912
939
913
if (QtPassSettings::isUseGit () && QtPassSettings::isAutoPush ())
940
914
on_pushButton_clicked ();
@@ -989,7 +963,7 @@ void MainWindow::on_deleteButton_clicked() {
989
963
if (fileOrFolder.isFile ()) {
990
964
file = getFile (ui->treeView ->currentIndex (), QtPassSettings::isUsePass ());
991
965
} else {
992
- file = getDir (ui->treeView ->currentIndex (), QtPassSettings::isUsePass ());
966
+ file = Util:: getDir (ui->treeView ->currentIndex (), QtPassSettings::isUsePass (), model, proxyModel );
993
967
isDir = true ;
994
968
}
995
969
@@ -1002,7 +976,7 @@ void MainWindow::on_deleteButton_clicked() {
1002
976
return ;
1003
977
1004
978
currentAction = REMOVE;
1005
- pass ->Remove (file, isDir);
979
+ QtPassSettings::getPass () ->Remove (file, isDir);
1006
980
// TODO(bezet): hide inside interface?
1007
981
if (QtPassSettings::isUseGit () && QtPassSettings::isAutoPush ())
1008
982
on_pushButton_clicked ();
@@ -1038,7 +1012,7 @@ void MainWindow::userDialog(QString dir) {
1038
1012
// TODO(bezet): temporary wrapper
1039
1013
QList<UserInfo> MainWindow::listKeys (QString keystring, bool secret) {
1040
1014
currentAction = GPG_INTERNAL;
1041
- return pass ->listKeys (keystring, secret);
1015
+ return QtPassSettings::getPass () ->listKeys (keystring, secret);
1042
1016
}
1043
1017
1044
1018
/* *
@@ -1064,7 +1038,7 @@ void MainWindow::on_usersButton_clicked() {
1064
1038
: currentDir;
1065
1039
int count = 0 ;
1066
1040
QString recipients =
1067
- pass ->getRecipientString (dir.isEmpty () ? " " : dir, " " , &count);
1041
+ QtPassSettings::getPass () ->getRecipientString (dir.isEmpty () ? " " : dir, " " , &count);
1068
1042
if (!recipients.isEmpty ())
1069
1043
selected_users = listKeys (recipients);
1070
1044
foreach (const UserInfo &sel, selected_users) {
@@ -1074,7 +1048,7 @@ void MainWindow::on_usersButton_clicked() {
1074
1048
}
1075
1049
if (count > selected_users.size ()) {
1076
1050
// Some keys seem missing from keyring, add them separately
1077
- QStringList recipients = pass ->getRecipientList (dir.isEmpty () ? " " : dir);
1051
+ QStringList recipients = QtPassSettings::getPass () ->getRecipientList (dir.isEmpty () ? " " : dir);
1078
1052
foreach (const QString recipient, recipients) {
1079
1053
if (listKeys (recipient).size () < 1 ) {
1080
1054
UserInfo i;
@@ -1093,7 +1067,7 @@ void MainWindow::on_usersButton_clicked() {
1093
1067
}
1094
1068
d.setUsers (NULL );
1095
1069
1096
- pass ->Init (dir, users);
1070
+ QtPassSettings::getPass () ->Init (dir, users);
1097
1071
1098
1072
if (QtPassSettings::isAutoPush ())
1099
1073
on_pushButton_clicked ();
@@ -1159,7 +1133,7 @@ void MainWindow::generateKeyPair(QString batch, QDialog *keygenWindow) {
1159
1133
keygen = keygenWindow;
1160
1134
ui->statusBar ->showMessage (tr (" Generating GPG key pair" ), 60000 );
1161
1135
currentAction = GPG_INTERNAL;
1162
- pass ->GenerateGPGKeys (batch);
1136
+ QtPassSettings::getPass () ->GenerateGPGKeys (batch);
1163
1137
}
1164
1138
1165
1139
/* *
@@ -1202,7 +1176,7 @@ void MainWindow::on_profileBox_currentIndexChanged(QString name) {
1202
1176
QtPassSettings::setPassStore (QtPassSettings::getProfiles ()[name]);
1203
1177
ui->statusBar ->showMessage (tr (" Profile changed to %1" ).arg (name), 2000 );
1204
1178
1205
- pass ->resetPasswordStoreDir ();
1179
+ QtPassSettings::getPass () ->resetPasswordStoreDir ();
1206
1180
1207
1181
ui->treeView ->setRootIndex (proxyModel.mapFromSource (
1208
1182
model.setRootPath (QtPassSettings::getPassStore ())));
@@ -1389,16 +1363,16 @@ void MainWindow::addFolder() {
1389
1363
void MainWindow::editPassword () {
1390
1364
if (QtPassSettings::isUseGit () && QtPassSettings::isAutoPull ())
1391
1365
on_updateButton_clicked ();
1392
- pass ->waitFor (30 );
1393
- pass ->waitForProcess ();
1366
+ QtPassSettings::getPass () ->waitFor (30 );
1367
+ QtPassSettings::getPass () ->waitForProcess ();
1394
1368
// TODO(annejan) move to editbutton stuff possibly?
1395
1369
currentDir = Util::getDir (ui->treeView ->currentIndex (), false , model, proxyModel);
1396
1370
lastDecrypt = " Could not decrypt" ;
1397
1371
QString file =
1398
1372
getFile (ui->treeView ->currentIndex (), QtPassSettings::isUsePass ());
1399
1373
if (!file.isEmpty ()) {
1400
1374
currentAction = GPG;
1401
- if (pass ->Show (file, true ) == QProcess::NormalExit)
1375
+ if (QtPassSettings::getPass () ->Show (file, true ) == QProcess::NormalExit)
1402
1376
on_editButton_clicked ();
1403
1377
}
1404
1378
}
@@ -1424,7 +1398,7 @@ QString MainWindow::generatePassword(int length,
1424
1398
" set in the configuration!" ));
1425
1399
return QString ();
1426
1400
}
1427
- return pass ->Generate (length, pwdConfig.Characters [selection]);
1401
+ return QtPassSettings::getPass () ->Generate (length, pwdConfig.Characters [selection]);
1428
1402
}
1429
1403
1430
1404
/* *
0 commit comments