Skip to content

Commit 0d61c56

Browse files
author
Janosch Knack
committed
refactoring the new pass class
1 parent 2fd7dc0 commit 0d61c56

13 files changed

+182
-103
lines changed

imitatepass.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,19 @@ void ImitatePass::reencryptPath(QString dir) {
282282
}
283283
emit endReencryptPath();
284284
}
285+
286+
void ImitatePass::Move(QDir srcDir, QDir destDir, bool force)
287+
{
288+
}
289+
290+
void ImitatePass::Move(QFile srcFile, QFile destFile, bool force)
291+
{
292+
}
293+
294+
void ImitatePass::Copy(QDir srcDir, QDir destDir, bool force)
295+
{
296+
}
297+
298+
void ImitatePass::Copy(QFile srcFile, QFile destFile, bool force)
299+
{
300+
}

imitatepass.h

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ class ImitatePass : public Pass {
2525
void startReencryptPath();
2626
void endReencryptPath();
2727
void lastDecrypt(QString);
28+
29+
// Pass interface
30+
public:
31+
void Move(QDir srcDir, QDir destDir, bool force = false);
32+
void Move(QFile srcFile, QFile destFile, bool force = false);
33+
void Copy(QDir srcDir, QDir destDir, bool force = false);
34+
void Copy(QFile srcFile, QFile destFile, bool force = false);
2835
};
2936

3037
#endif // IMITATEPASS_H

mainwindow.cpp

+40-66
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,9 @@
3434
*/
3535
MainWindow::MainWindow(QWidget *parent)
3636
: QMainWindow(parent), ui(new Ui::MainWindow), fusedav(this), keygen(NULL),
37-
tray(NULL), pass(nullptr) {
37+
tray(NULL) {
3838
// connect(process.data(), SIGNAL(readyReadStandardOutput()), this,
3939
// 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-
7040
ui->setupUi(this);
7141
enableUiElements(true);
7242
execQueue = new QQueue<execQueueItem>;
@@ -100,6 +70,23 @@ MainWindow::MainWindow(QWidget *parent)
10070
#if QT_VERSION >= QT_VERSION_CHECK(5,2,0)
10171
ui->lineEdit->setClearButtonEnabled(true);
10272
#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)));
10390
}
10491

10592
/**
@@ -343,15 +330,7 @@ bool MainWindow::checkConfig() {
343330
this, SLOT(showBrowserContextMenu(const QPoint &)));
344331

345332
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();
355334

356335
if (!QtPassSettings::isUseGit() ||
357336
(QtPassSettings::getGitExecutable().isEmpty() &&
@@ -381,7 +360,6 @@ void MainWindow::config() {
381360
// Automatically default to pass if it's available
382361
if (freshStart && QFile(QtPassSettings::getPassExecutable()).exists()) {
383362
QtPassSettings::setUsePass(true);
384-
pass = &rpass;
385363
}
386364

387365
d->setPassPath(QtPassSettings::getPassExecutable());
@@ -429,10 +407,6 @@ void MainWindow::config() {
429407
QtPassSettings::setPassStore(
430408
Util::normalizeFolderPath(d->getStorePath()));
431409
QtPassSettings::setUsePass(d->usePass());
432-
if (d->usePass())
433-
pass = &rpass;
434-
else
435-
pass = &ipass;
436410
QtPassSettings::setClipBoardType(d->useClipboard());
437411
QtPassSettings::setUseAutoclear(d->useAutoclear());
438412
QtPassSettings::setAutoclearSeconds(d->getAutoclear());
@@ -482,7 +456,7 @@ void MainWindow::config() {
482456

483457
if (freshStart && Util::checkConfig())
484458
config();
485-
pass->updateEnv();
459+
QtPassSettings::getPass()->updateEnv();
486460
if (!QtPassSettings::isUseGit() ||
487461
(QtPassSettings::getGitExecutable().isEmpty() &&
488462
QtPassSettings::getPassExecutable().isEmpty())) {
@@ -512,7 +486,7 @@ void MainWindow::config() {
512486
void MainWindow::on_updateButton_clicked() {
513487
ui->statusBar->showMessage(tr("Updating password-store"), 2000);
514488
currentAction = GIT;
515-
pass->GitPull();
489+
QtPassSettings::getPass()->GitPull();
516490
}
517491

518492
/**
@@ -521,7 +495,7 @@ void MainWindow::on_updateButton_clicked() {
521495
void MainWindow::on_pushButton_clicked() {
522496
ui->statusBar->showMessage(tr("Updating password-store"), 2000);
523497
currentAction = GIT;
524-
pass->GitPush();
498+
QtPassSettings::getPass()->GitPush();
525499
}
526500

527501

@@ -559,7 +533,7 @@ void MainWindow::on_treeView_clicked(const QModelIndex &index) {
559533
ui->passwordName->setText(getFile(index, true));
560534
if (!file.isEmpty() && !cleared) {
561535
currentAction = GPG;
562-
pass->Show(file);
536+
QtPassSettings::getPass()->Show(file);
563537
} else {
564538
clearPanel(false);
565539
ui->editButton->setEnabled(false);
@@ -605,7 +579,7 @@ void MainWindow::deselect() {
605579
*/
606580
void MainWindow::executePassGitInit() {
607581
qDebug() << "Pass git init called";
608-
pass->GitInit();
582+
QtPassSettings::getPass()->GitInit();
609583
}
610584

611585
void MainWindow::executeWrapperStarted() {
@@ -630,8 +604,8 @@ void MainWindow::readyRead(bool finished = false) {
630604
QString output = "";
631605
QString error = "";
632606
if (currentAction != GPG_INTERNAL) {
633-
error = pass->readAllStandardError();
634-
QByteArray processOutBytes = pass->readAllStandardOutput();
607+
error = QtPassSettings::getPass()->readAllStandardError();
608+
QByteArray processOutBytes = QtPassSettings::getPass()->readAllStandardOutput();
635609
QTextCodec *codec = QTextCodec::codecForLocale();
636610
output = codec->toUnicode(processOutBytes);
637611
if (finished && currentAction == GPG) {
@@ -836,7 +810,7 @@ void MainWindow::processError(QProcess::ProcessError error) {
836810
ui->textBrowser->setText(errorString);
837811
// TODO(bezet): this probably shall be done in finished handler(I guess it
838812
// finishes even on error)
839-
if (pass->state() == QProcess::NotRunning)
813+
if (QtPassSettings::getPass()->state() == QProcess::NotRunning)
840814
enableUiElements(true);
841815
}
842816

@@ -934,7 +908,7 @@ void MainWindow::setPassword(QString file, bool overwrite, bool isNew = false) {
934908
newValue += "\n";
935909

936910
currentAction = EDIT;
937-
pass->Insert(file, newValue, overwrite);
911+
QtPassSettings::getPass()->Insert(file, newValue, overwrite);
938912

939913
if (QtPassSettings::isUseGit() && QtPassSettings::isAutoPush())
940914
on_pushButton_clicked();
@@ -989,7 +963,7 @@ void MainWindow::on_deleteButton_clicked() {
989963
if (fileOrFolder.isFile()) {
990964
file = getFile(ui->treeView->currentIndex(), QtPassSettings::isUsePass());
991965
} else {
992-
file = getDir(ui->treeView->currentIndex(), QtPassSettings::isUsePass());
966+
file = Util::getDir(ui->treeView->currentIndex(), QtPassSettings::isUsePass(), model, proxyModel);
993967
isDir = true;
994968
}
995969

@@ -1002,7 +976,7 @@ void MainWindow::on_deleteButton_clicked() {
1002976
return;
1003977

1004978
currentAction = REMOVE;
1005-
pass->Remove(file, isDir);
979+
QtPassSettings::getPass()->Remove(file, isDir);
1006980
// TODO(bezet): hide inside interface?
1007981
if (QtPassSettings::isUseGit() && QtPassSettings::isAutoPush())
1008982
on_pushButton_clicked();
@@ -1038,7 +1012,7 @@ void MainWindow::userDialog(QString dir) {
10381012
// TODO(bezet): temporary wrapper
10391013
QList<UserInfo> MainWindow::listKeys(QString keystring, bool secret) {
10401014
currentAction = GPG_INTERNAL;
1041-
return pass->listKeys(keystring, secret);
1015+
return QtPassSettings::getPass()->listKeys(keystring, secret);
10421016
}
10431017

10441018
/**
@@ -1064,7 +1038,7 @@ void MainWindow::on_usersButton_clicked() {
10641038
: currentDir;
10651039
int count = 0;
10661040
QString recipients =
1067-
pass->getRecipientString(dir.isEmpty() ? "" : dir, " ", &count);
1041+
QtPassSettings::getPass()->getRecipientString(dir.isEmpty() ? "" : dir, " ", &count);
10681042
if (!recipients.isEmpty())
10691043
selected_users = listKeys(recipients);
10701044
foreach (const UserInfo &sel, selected_users) {
@@ -1074,7 +1048,7 @@ void MainWindow::on_usersButton_clicked() {
10741048
}
10751049
if (count > selected_users.size()) {
10761050
// 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);
10781052
foreach (const QString recipient, recipients) {
10791053
if (listKeys(recipient).size() < 1) {
10801054
UserInfo i;
@@ -1093,7 +1067,7 @@ void MainWindow::on_usersButton_clicked() {
10931067
}
10941068
d.setUsers(NULL);
10951069

1096-
pass->Init(dir, users);
1070+
QtPassSettings::getPass()->Init(dir, users);
10971071

10981072
if (QtPassSettings::isAutoPush())
10991073
on_pushButton_clicked();
@@ -1159,7 +1133,7 @@ void MainWindow::generateKeyPair(QString batch, QDialog *keygenWindow) {
11591133
keygen = keygenWindow;
11601134
ui->statusBar->showMessage(tr("Generating GPG key pair"), 60000);
11611135
currentAction = GPG_INTERNAL;
1162-
pass->GenerateGPGKeys(batch);
1136+
QtPassSettings::getPass()->GenerateGPGKeys(batch);
11631137
}
11641138

11651139
/**
@@ -1202,7 +1176,7 @@ void MainWindow::on_profileBox_currentIndexChanged(QString name) {
12021176
QtPassSettings::setPassStore(QtPassSettings::getProfiles()[name]);
12031177
ui->statusBar->showMessage(tr("Profile changed to %1").arg(name), 2000);
12041178

1205-
pass->resetPasswordStoreDir();
1179+
QtPassSettings::getPass()->resetPasswordStoreDir();
12061180

12071181
ui->treeView->setRootIndex(proxyModel.mapFromSource(
12081182
model.setRootPath(QtPassSettings::getPassStore())));
@@ -1389,16 +1363,16 @@ void MainWindow::addFolder() {
13891363
void MainWindow::editPassword() {
13901364
if (QtPassSettings::isUseGit() && QtPassSettings::isAutoPull())
13911365
on_updateButton_clicked();
1392-
pass->waitFor(30);
1393-
pass->waitForProcess();
1366+
QtPassSettings::getPass()->waitFor(30);
1367+
QtPassSettings::getPass()->waitForProcess();
13941368
// TODO(annejan) move to editbutton stuff possibly?
13951369
currentDir = Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel);
13961370
lastDecrypt = "Could not decrypt";
13971371
QString file =
13981372
getFile(ui->treeView->currentIndex(), QtPassSettings::isUsePass());
13991373
if (!file.isEmpty()) {
14001374
currentAction = GPG;
1401-
if (pass->Show(file, true) == QProcess::NormalExit)
1375+
if (QtPassSettings::getPass()->Show(file, true) == QProcess::NormalExit)
14021376
on_editButton_clicked();
14031377
}
14041378
}
@@ -1424,7 +1398,7 @@ QString MainWindow::generatePassword(int length,
14241398
"set in the configuration!"));
14251399
return QString();
14261400
}
1427-
return pass->Generate(length, pwdConfig.Characters[selection]);
1401+
return QtPassSettings::getPass()->Generate(length, pwdConfig.Characters[selection]);
14281402
}
14291403

14301404
/**

mainwindow.h

-3
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ private slots:
155155
QString currentDir;
156156
bool startupPhase;
157157
TrayIcon *tray;
158-
Pass *pass;
159-
RealPass rpass;
160-
ImitatePass ipass;
161158

162159
void updateText();
163160
void enableUiElements(bool state);

pass.cpp

+25-20
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,35 @@
33
#include "util.h"
44
#include <QTextCodec>
55

6+
67
Pass::Pass() : wrapperRunning(false) {
7-
connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
8-
SIGNAL(finished(int, QProcess::ExitStatus)));
9-
connect(&process, SIGNAL(error(QProcess::ProcessError)), this,
10-
SIGNAL(error(QProcess::ProcessError)));
11-
connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
12-
SLOT(processFinished(int, QProcess::ExitStatus)));
138

14-
env = QProcess::systemEnvironment();
9+
}
1510

16-
#ifdef __APPLE__
17-
// If it exists, add the gpgtools to PATH
18-
if (QFile("/usr/local/MacGPG2/bin").exists())
19-
env.replaceInStrings("PATH=", "PATH=/usr/local/MacGPG2/bin:");
20-
// Add missing /usr/local/bin
21-
if (env.filter("/usr/local/bin").isEmpty())
22-
env.replaceInStrings("PATH=", "PATH=/usr/local/bin:");
23-
#endif
11+
void Pass::init(){
12+
connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
13+
SIGNAL(finished(int, QProcess::ExitStatus)));
14+
connect(&process, SIGNAL(error(QProcess::ProcessError)), this,
15+
SIGNAL(error(QProcess::ProcessError)));
16+
connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
17+
SLOT(processFinished(int, QProcess::ExitStatus)));
2418

25-
if (!QtPassSettings::getGpgHome().isEmpty()) {
26-
QDir absHome(QtPassSettings::getGpgHome());
27-
absHome.makeAbsolute();
28-
env << "GNUPGHOME=" + absHome.path();
29-
}
19+
env = QProcess::systemEnvironment();
20+
21+
#ifdef __APPLE__
22+
// If it exists, add the gpgtools to PATH
23+
if (QFile("/usr/local/MacGPG2/bin").exists())
24+
env.replaceInStrings("PATH=", "PATH=/usr/local/MacGPG2/bin:");
25+
// Add missing /usr/local/bin
26+
if (env.filter("/usr/local/bin").isEmpty())
27+
env.replaceInStrings("PATH=", "PATH=/usr/local/bin:");
28+
#endif
29+
30+
if (!QtPassSettings::getGpgHome().isEmpty()) {
31+
QDir absHome(QtPassSettings::getGpgHome());
32+
absHome.makeAbsolute();
33+
env << "GNUPGHOME=" + absHome.path();
34+
}
3035
}
3136

3237
QProcess::ExitStatus Pass::waitForProcess() {

0 commit comments

Comments
 (0)