QtPass  1.2.1
Multi-platform GUI for pass, the standard unix password manager.
mainwindow.cpp
Go to the documentation of this file.
1 #include "mainwindow.h"
2 #include "debughelper.h"
3 #include <QClipboard>
4 #include <QCloseEvent>
5 #include <QFileInfo>
6 #include <QInputDialog>
7 #include <QLabel>
8 #include <QMessageBox>
9 #include <QQueue>
10 #include <QShortcut>
11 #include <QTextCodec>
12 #include <QTimer>
13 #ifdef Q_OS_WIN
14 #define WIN32_LEAN_AND_MEAN /*_KILLING_MACHINE*/
15 #define WIN32_EXTRA_LEAN
16 #include <windows.h>
17 #include <winnetwk.h>
18 #undef DELETE
19 #endif
20 #include "configdialog.h"
21 #include "keygendialog.h"
22 #include "passworddialog.h"
24 #include "qtpasssettings.h"
25 #include "settingsconstants.h"
26 #include "ui_mainwindow.h"
27 #include "usersdialog.h"
28 #include "util.h"
29 
35 MainWindow::MainWindow(QWidget *parent)
36  : QMainWindow(parent), ui(new Ui::MainWindow), fusedav(this), keygen(NULL),
37  tray(NULL) {
38 #ifdef __APPLE__
39  // extra treatment for mac os
40  // see http://doc.qt.io/qt-5/qkeysequence.html#qt_set_sequence_auto_mnemonic
41  qt_set_sequence_auto_mnemonic(true);
42 #endif
43  // register shortcut ctrl/cmd + Q to close the main window
44  new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
45 
46  // TODO(bezet): this should be reconnected dynamically when pass changes
47  connectPassSignalHandlers(QtPassSettings::getRealPass());
48  connectPassSignalHandlers(QtPassSettings::getImitatePass());
49 
50  // only for ipass
51  connect(QtPassSettings::getImitatePass(), SIGNAL(startReencryptPath()), this,
52  SLOT(startReencryptPath()));
53  connect(QtPassSettings::getImitatePass(), SIGNAL(endReencryptPath()), this,
54  SLOT(endReencryptPath()));
55 
56  ui->setupUi(this);
57  enableUiElements(true);
58  ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000);
59  freshStart = true;
60  startupPhase = true;
61  clearPanelTimer.setSingleShot(true);
62  connect(&clearPanelTimer, SIGNAL(timeout()), this, SLOT(clearPanel()));
63  clearClipboardTimer.setSingleShot(true);
64  connect(&clearClipboardTimer, SIGNAL(timeout()), this,
65  SLOT(clearClipboard()));
67  if (!checkConfig()) {
68  // no working config
69  QApplication::quit();
70  }
71  clippedText = "";
72  QtPass = NULL;
73  QTimer::singleShot(10, this, SLOT(focusInput()));
74 
75  // Add a Actions to the Add-Button
76  QIcon addFileIcon = QIcon::fromTheme("file_new");
77  QIcon addFolderIcon = QIcon::fromTheme("folder_new");
78  actionAddPassword = new QAction(addFileIcon, tr("Add Password"), this);
79  actionAddFolder = new QAction(addFolderIcon, tr("Add Folder"), this);
80 
81  ui->addButton->addAction(actionAddPassword);
82  ui->addButton->addAction(actionAddFolder);
83 
84  connect(actionAddPassword, SIGNAL(triggered()), this,
85  SLOT(on_addButton_clicked()));
86  connect(actionAddFolder, SIGNAL(triggered()), this, SLOT(addFolder()));
87  qsrand(static_cast<uint>(QTime::currentTime().msec()));
88 
89 #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
90  ui->lineEdit->setClearButtonEnabled(true);
91 #endif
92 }
93 
100 void MainWindow::focusInput() {
101  ui->lineEdit->selectAll();
102  ui->lineEdit->setFocus();
103 }
104 
109 #ifdef Q_OS_WIN
111  WNetCancelConnection2A(QtPassSettings::getPassStore().toUtf8().constData(),
112  0, 1);
113 #else
114  if (fusedav.state() == QProcess::Running) {
115  fusedav.terminate();
116  fusedav.waitForFinished(2000);
117  }
118 #endif
119 }
120 
125 void MainWindow::changeEvent(QEvent *event) {
126  QWidget::changeEvent(event);
127  if (event->type() == QEvent::ActivationChange) {
128  if (this->isActiveWindow()) {
129  ui->lineEdit->selectAll();
130  ui->lineEdit->setFocus();
131  }
132  }
133 }
134 
142 void MainWindow::connectPassSignalHandlers(Pass *pass) {
143 
144  // TODO(bezet): this is never emitted(should be), also naming(see
145  // critical())
146  connect(pass, &Pass::error, this, &MainWindow::processError);
147  connect(pass, &Pass::startingExecuteWrapper, this,
148  &MainWindow::executeWrapperStarted);
149  connect(pass, &Pass::critical, this, &MainWindow::critical);
150  connect(pass, &Pass::statusMsg, this, &MainWindow::showStatusMessage);
151  connect(pass, &Pass::processErrorExit, this, &MainWindow::processErrorExit);
152 
153  connect(pass, &Pass::finishedGitInit, this, &MainWindow::passStoreChanged);
154  connect(pass, &Pass::finishedGitPull, this, &MainWindow::processFinished);
155  connect(pass, &Pass::finishedGitPush, this, &MainWindow::processFinished);
156  connect(pass, &Pass::finishedShow, this, &MainWindow::passShowHandler);
157  connect(pass, &Pass::finishedInsert, this, &MainWindow::finishedInsert);
158  connect(pass, &Pass::finishedRemove, this, &MainWindow::passStoreChanged);
159  connect(pass, &Pass::finishedInit, this, &MainWindow::passStoreChanged);
160  connect(pass, &Pass::finishedMove, this, &MainWindow::passStoreChanged);
161  connect(pass, &Pass::finishedCopy, this, &MainWindow::passStoreChanged);
162 
163  connect(pass, &Pass::finishedGenerateGPGKeys, this,
164  &MainWindow::keyGenerationComplete);
165 }
166 
170 void MainWindow::mountWebDav() {
171 #ifdef Q_OS_WIN
172  char dst[20] = {0};
173  NETRESOURCEA netres;
174  memset(&netres, 0, sizeof(netres));
175  netres.dwType = RESOURCETYPE_DISK;
176  netres.lpLocalName = 0;
177  netres.lpRemoteName = QtPassSettings::getWebDavUrl().toUtf8().data();
178  DWORD size = sizeof(dst);
179  DWORD r = WNetUseConnectionA(
180  reinterpret_cast<HWND>(effectiveWinId()), &netres,
181  QtPassSettings::getWebDavPassword().toUtf8().constData(),
182  QtPassSettings::getWebDavUser().toUtf8().constData(),
183  CONNECT_TEMPORARY | CONNECT_INTERACTIVE | CONNECT_REDIRECT, dst, &size,
184  0);
185  if (r == NO_ERROR) {
187  } else {
188  char message[256] = {0};
189  FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, r, 0, message,
190  sizeof(message), 0);
191  ui->textBrowser->setTextColor(Qt::red);
192  ui->textBrowser->setText(tr("Failed to connect WebDAV:\n") + message +
193  " (0x" + QString::number(r, 16) + ")");
194  ui->textBrowser->setTextColor(Qt::black);
195  }
196 #else
197  fusedav.start("fusedav -o nonempty -u \"" + QtPassSettings::getWebDavUser() +
198  "\" " + QtPassSettings::getWebDavUrl() + " \"" +
200  fusedav.waitForStarted();
201  if (fusedav.state() == QProcess::Running) {
202  QString pwd = QtPassSettings::getWebDavPassword();
203  bool ok = true;
204  if (pwd.isEmpty()) {
205  pwd = QInputDialog::getText(this, tr("QtPass WebDAV password"),
206  tr("Enter password to connect to WebDAV:"),
207  QLineEdit::Password, "", &ok);
208  }
209  if (ok && !pwd.isEmpty()) {
210  fusedav.write(pwd.toUtf8() + '\n');
211  fusedav.closeWriteChannel();
212  fusedav.waitForFinished(2000);
213  } else {
214  fusedav.terminate();
215  }
216  }
217  QString error = fusedav.readAllStandardError();
218  int prompt = error.indexOf("Password:");
219  if (prompt >= 0)
220  error.remove(0, prompt + 10);
221  if (fusedav.state() != QProcess::Running)
222  error = tr("fusedav exited unexpectedly\n") + error;
223  if (error.size() > 0) {
224  ui->textBrowser->setTextColor(Qt::red);
225  ui->textBrowser->setText(
226  tr("Failed to start fusedav to connect WebDAV:\n") + error);
227  ui->textBrowser->setTextColor(Qt::black);
228  }
229 #endif
230 }
231 
237  QString version = QtPassSettings::getVersion();
238 
239  if (freshStart) {
240  QByteArray geometry = QtPassSettings::getGeometry(saveGeometry());
241  restoreGeometry(geometry);
242  QByteArray savestate = QtPassSettings::getSavestate(saveState());
243  restoreState(savestate);
244  QPoint position = QtPassSettings::getPos(pos());
245  move(position);
246  QSize newSize = QtPassSettings::getSize(size());
247  resize(newSize);
248  QList<int> splitter = ui->splitter->sizes();
249  int left = QtPassSettings::getSplitterLeft(splitter[0]);
250  int right = QtPassSettings::getSplitterRight(splitter[1]);
251  if (left > 0 || right > 0) {
252  splitter[0] = left;
253  splitter[1] = right;
254  ui->splitter->setSizes(splitter);
255  }
256  if (QtPassSettings::isMaximized(isMaximized())) {
257  showMaximized();
258  }
259  }
260 
262  QtPassSettings::setPassStore(passStore);
263 
264  QString passExecutable =
266  QtPassSettings::setPassExecutable(passExecutable);
267 
268  QString gitExecutable =
270  QtPassSettings::setGitExecutable(gitExecutable);
271 
272  QString gpgExecutable =
274  QtPassSettings::setGpgExecutable(gpgExecutable);
275 
276  QString pwgenExecutable =
278  QtPassSettings::setPwgenExecutable(pwgenExecutable);
279 
285 
287  Qt::WindowFlags flags = windowFlags();
288  this->setWindowFlags(flags | Qt::WindowStaysOnTopHint);
289  this->show();
290  }
291 
292  if (QtPassSettings::isUseTrayIcon() && tray == NULL) {
293  initTrayIcon();
294  if (freshStart && QtPassSettings::isStartMinimized()) {
295  // since we are still in constructor, can't directly hide
296  QTimer::singleShot(10, this, SLOT(hide()));
297  }
298  } else if (!QtPassSettings::isUseTrayIcon() && tray != NULL) {
299  destroyTrayIcon();
300  }
301 
302  // dbg()<< version;
303 
304  // Config updates
305  if (version.isEmpty()) {
306  dbg() << "assuming fresh install";
311  if (!QtPassSettings::getPwgenExecutable().isEmpty())
313  else
315  QtPassSettings::setPassTemplate("login\nurl");
316  } else {
317  // QStringList ver = version.split(".");
318  // dbg()<< ver;
319  // if (ver[0] == "0" && ver[1] == "8") {
321  // }
322  if (QtPassSettings::getPassTemplate().isEmpty())
323  QtPassSettings::setPassTemplate("login\nurl");
324  }
325 
327 
328  if (Util::checkConfig()) {
329  config();
330  if (freshStart && Util::checkConfig())
331  return false;
332  }
333 
334  freshStart = false;
335 
336  // TODO(annejan): this needs to be before we try to access the store,
337  // but it would be better to do it after the Window is shown,
338  // as the long delay it can cause is irritating otherwise.
340  mountWebDav();
341 
342  model.setNameFilters(QStringList() << "*.gpg");
343  model.setNameFilterDisables(false);
344 
345  proxyModel.setSourceModel(&model);
346  proxyModel.setModelAndStore(&model, QtPassSettings::getPassStore());
347  selectionModel.reset(new QItemSelectionModel(&proxyModel));
348  model.fetchMore(model.setRootPath(QtPassSettings::getPassStore()));
349  model.sort(0, Qt::AscendingOrder);
350 
351  ui->treeView->setModel(&proxyModel);
352  ui->treeView->setRootIndex(proxyModel.mapFromSource(
353  model.setRootPath(QtPassSettings::getPassStore())));
354  ui->treeView->setColumnHidden(1, true);
355  ui->treeView->setColumnHidden(2, true);
356  ui->treeView->setColumnHidden(3, true);
357  ui->treeView->setHeaderHidden(true);
358  ui->treeView->setIndentation(15);
359  ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
360  ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
361  connect(ui->treeView, SIGNAL(customContextMenuRequested(const QPoint &)),
362  this, SLOT(showContextMenu(const QPoint &)));
363  connect(ui->treeView, SIGNAL(emptyClicked()), this, SLOT(deselect()));
364  ui->textBrowser->setOpenExternalLinks(true);
365  ui->textBrowser->setContextMenuPolicy(Qt::CustomContextMenu);
366  connect(ui->textBrowser, SIGNAL(customContextMenuRequested(const QPoint &)),
367  this, SLOT(showBrowserContextMenu(const QPoint &)));
368 
369  updateProfileBox();
371  clearPanelTimer.setInterval(1000 *
373  clearClipboardTimer.setInterval(1000 * QtPassSettings::getAutoclearSeconds());
374  if (!QtPassSettings::isUseGit() ||
375  (QtPassSettings::getGitExecutable().isEmpty() &&
376  QtPassSettings::getPassExecutable().isEmpty())) {
377  ui->pushButton->hide();
378  ui->updateButton->hide();
379  ui->horizontalSpacer->changeSize(0, 20, QSizePolicy::Maximum,
380  QSizePolicy::Minimum);
381  } else {
382  ui->pushButton->show();
383  ui->updateButton->show();
384  ui->horizontalSpacer->changeSize(24, 24, QSizePolicy::Minimum,
385  QSizePolicy::Minimum);
386  }
387 
388  startupPhase = false;
389  return true;
390 }
391 
397  QScopedPointer<ConfigDialog> d(new ConfigDialog(this));
398  d->setModal(true);
399  // Automatically default to pass if it's available
400  if (freshStart && QFile(QtPassSettings::getPassExecutable()).exists()) {
402  }
403 
404  d->setPassPath(QtPassSettings::getPassExecutable());
405  d->setGitPath(QtPassSettings::getGitExecutable());
406  d->setGpgPath(QtPassSettings::getGpgExecutable());
407  d->setStorePath(QtPassSettings::getPassStore());
408  d->usePass(QtPassSettings::isUsePass());
409  d->useClipboard(QtPassSettings::getClipBoardType());
410  d->useSelection(QtPassSettings::isUseSelection());
411  d->useAutoclear(QtPassSettings::isUseAutoclear());
412  d->setAutoclear(QtPassSettings::getAutoclearSeconds());
413  d->useAutoclearPanel(QtPassSettings::isUseAutoclearPanel());
414  d->setAutoclearPanel(QtPassSettings::getAutoclearPanelSeconds());
415  d->hidePassword(QtPassSettings::isHidePassword());
416  d->hideContent(QtPassSettings::isHideContent());
417  d->addGPGId(QtPassSettings::isAddGPGId(true));
418  d->useTrayIcon(QtPassSettings::isUseTrayIcon());
419  d->hideOnClose(QtPassSettings::isHideOnClose());
420  d->startMinimized(QtPassSettings::isStartMinimized());
422  d->useGit(QtPassSettings::isUseGit());
423  d->setPwgenPath(QtPassSettings::getPwgenExecutable());
424  d->usePwgen(QtPassSettings::isUsePwgen());
425  d->avoidCapitals(QtPassSettings::isAvoidCapitals());
426  d->avoidNumbers(QtPassSettings::isAvoidNumbers());
427  d->lessRandom(QtPassSettings::isLessRandom());
428  d->useSymbols(QtPassSettings::isUseSymbols());
429  d->setPasswordLength(pwdConfig.length);
430  d->setPwdTemplateSelector(pwdConfig.selected);
432  d->setLineEditEnabled(false);
433  d->setPasswordChars(pwdConfig.Characters[pwdConfig.selected]);
434  d->useTemplate(QtPassSettings::isUseTemplate());
435  d->setTemplate(QtPassSettings::getPassTemplate());
436  d->templateAllFields(QtPassSettings::isTemplateAllFields());
437  d->autoPull(QtPassSettings::isAutoPull());
438  d->autoPush(QtPassSettings::isAutoPush());
439  d->alwaysOnTop(QtPassSettings::isAlwaysOnTop());
440  if (startupPhase)
441  d->wizard(); // does shit
442  if (d->exec()) {
443  if (d->result() == QDialog::Accepted) {
444  QtPassSettings::setPassExecutable(d->getPassPath());
445  QtPassSettings::setGitExecutable(d->getGitPath());
446  QtPassSettings::setGpgExecutable(d->getGpgPath());
448  Util::normalizeFolderPath(d->getStorePath()));
449  QtPassSettings::setUsePass(d->usePass());
450  QtPassSettings::setClipBoardType(d->useClipboard());
451  QtPassSettings::setUseSelection(d->useSelection());
452  QtPassSettings::setUseAutoclear(d->useAutoclear());
453  QtPassSettings::setAutoclearSeconds(d->getAutoclear());
454  QtPassSettings::setUseAutoclearPanel(d->useAutoclearPanel());
455  QtPassSettings::setAutoclearPanelSeconds(d->getAutoclearPanel());
456  QtPassSettings::setHidePassword(d->hidePassword());
457  QtPassSettings::setHideContent(d->hideContent());
458  QtPassSettings::setAddGPGId(d->addGPGId());
459  QtPassSettings::setUseTrayIcon(d->useTrayIcon());
460  QtPassSettings::setHideOnClose(d->hideOnClose());
461  QtPassSettings::setStartMinimized(d->startMinimized());
462  QtPassSettings::setProfiles(d->getProfiles());
463  QtPassSettings::setUseGit(d->useGit());
464  QtPassSettings::setPwgenExecutable(d->getPwgenPath());
465  QtPassSettings::setUsePwgen(d->usePwgen());
466  QtPassSettings::setAvoidCapitals(d->avoidCapitals());
467  QtPassSettings::setAvoidNumbers(d->avoidNumbers());
468  QtPassSettings::setLessRandom(d->lessRandom());
469  QtPassSettings::setUseSymbols(d->useSymbols());
470  pwdConfig.length = d->getPasswordLength();
472  d->getPwdTemplateSelector());
474  d->getPasswordChars();
475  QtPassSettings::setUseTemplate(d->useTemplate());
476  QtPassSettings::setPassTemplate(d->getTemplate());
477  QtPassSettings::setTemplateAllFields(d->templateAllFields());
478  QtPassSettings::setAutoPush(d->autoPush());
479  QtPassSettings::setAutoPull(d->autoPull());
480  QtPassSettings::setAlwaysOnTop(d->alwaysOnTop());
481 
487 
489  Qt::WindowFlags flags = windowFlags();
490  this->setWindowFlags(flags | Qt::WindowStaysOnTopHint);
491  this->show();
492  } else {
493  this->setWindowFlags(Qt::Window);
494  this->show();
495  }
496 
497  updateProfileBox();
498  ui->treeView->setRootIndex(proxyModel.mapFromSource(
499  model.setRootPath(QtPassSettings::getPassStore())));
500 
501  if (freshStart && Util::checkConfig())
502  config();
504  clearPanelTimer.setInterval(1000 *
506  clearClipboardTimer.setInterval(1000 *
508 
509  if (!QtPassSettings::isUseGit() ||
510  (QtPassSettings::getGitExecutable().isEmpty() &&
511  QtPassSettings::getPassExecutable().isEmpty())) {
512  ui->pushButton->hide();
513  ui->updateButton->hide();
514  ui->horizontalSpacer->changeSize(0, 20, QSizePolicy::Maximum,
515  QSizePolicy::Minimum);
516  } else {
517  ui->pushButton->show();
518  ui->updateButton->show();
519  ui->horizontalSpacer->changeSize(24, 24, QSizePolicy::Minimum,
520  QSizePolicy::Minimum);
521  }
522  if (QtPassSettings::isUseTrayIcon() && tray == NULL)
523  initTrayIcon();
524  else if (!QtPassSettings::isUseTrayIcon() && tray != NULL)
525  destroyTrayIcon();
526  }
527  freshStart = false;
528  }
529 }
530 
534 void MainWindow::on_updateButton_clicked(bool block) {
535  ui->statusBar->showMessage(tr("Updating password-store"), 2000);
536  if (block)
538  else
540 }
541 
545 void MainWindow::on_pushButton_clicked() {
546  if (QtPassSettings::isUseGit()) {
547  ui->statusBar->showMessage(tr("Updating password-store"), 2000);
549  }
550 }
551 
559 QString MainWindow::getFile(const QModelIndex &index, bool forPass) {
560  if (!index.isValid() ||
561  !model.fileInfo(proxyModel.mapToSource(index)).isFile())
562  return QString();
563  QString filePath = model.filePath(proxyModel.mapToSource(index));
564  if (forPass) {
565  filePath = QDir(QtPassSettings::getPassStore()).relativeFilePath(filePath);
566  filePath.replace(QRegExp("\\.gpg$"), "");
567  }
568  return filePath;
569 }
570 
575 void MainWindow::on_treeView_clicked(const QModelIndex &index) {
576  bool cleared = ui->treeView->currentIndex().flags() == Qt::NoItemFlags;
577  currentDir =
578  Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel);
579  // TODO(bezet): "Could not decrypt";
580  clippedText = "";
581  QString file = getFile(index, true);
582  ui->passwordName->setText(getFile(index, true));
583  if (!file.isEmpty() && !cleared) {
584  QtPassSettings::getPass()->Show(file);
585  } else {
586  clearPanel(false);
587  ui->editButton->setEnabled(false);
588  ui->deleteButton->setEnabled(true);
589  }
590 }
591 
597 void MainWindow::on_treeView_doubleClicked(const QModelIndex &index) {
598  QFileInfo fileOrFolder =
599  model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex()));
600 
601  if (fileOrFolder.isFile()) {
602  editPassword(getFile(index, true));
603  }
604 }
605 
610  currentDir = "/";
611  clearClipboard();
612  ui->passwordName->setText("");
613  clearPanel(false);
614 }
615 
620  dbg() << "Pass git init called";
622 }
623 
624 void MainWindow::executeWrapperStarted() {
625  clearTemplateWidgets();
626  ui->textBrowser->clear();
627  enableUiElements(false);
628  clearPanelTimer.stop();
629 }
630 
631 void MainWindow::keyGenerationComplete(const QString &p_output,
632  const QString &p_errout) {
633  // qDebug() << p_output;
634  // qDebug() << p_errout;
635  if (0 != keygen) {
636  qDebug() << "Keygen Done";
637  keygen->close();
638  keygen = 0;
639  // TODO(annejan) some sanity checking ?
640  }
641  processFinished(p_output, p_errout);
642 }
643 
644 void MainWindow::passShowHandler(const QString &p_output) {
645  QString output = p_output;
646  {
647  QStringList tokens = p_output.split("\n");
648  QString password = tokens.at(0);
649  tokens.erase(tokens.begin());
650 
652  !p_output.isEmpty()) {
653  clippedText = password;
655  copyTextToClipboard(password);
657  clearPanelTimer.start();
658  }
661  output = "***" + tr("Password hidden") + "***";
662  output += tokens.join("\n");
663  }
665  output = "***" + tr("Content hidden") + "***";
666  }
667 
668  clearTemplateWidgets();
670  QStringList remainingTokens;
671  for (int j = 0; j < tokens.length(); ++j) {
672  QString token = tokens.at(j);
673  if (token.contains(':')) {
674  int colon = token.indexOf(':');
675  QString field = token.left(colon);
677  QtPassSettings::getPassTemplate().contains(field)) {
678  QString value = token.right(token.length() - colon - 1);
679  if (!QtPassSettings::getPassTemplate().contains(field) &&
680  value.startsWith("//")) {
681  remainingTokens.append(token);
682  continue; // colon is probably from a url
683  }
684  addToGridLayout(j + 1, field, value);
685  }
686  } else {
687  remainingTokens.append(token);
688  }
689  }
690  if (ui->gridLayout->count() == 0)
691  ui->verticalLayoutPassword->setSpacing(0);
692  else
693  ui->verticalLayoutPassword->setSpacing(6);
694  output = remainingTokens.join("\n");
695  } else if (!QtPassSettings::isHideContent()) {
696  output = tokens.join("\n");
697  }
698  if (!QtPassSettings::isHideContent() && !password.isEmpty()) {
699  // now set the password. If we set it earlier, the layout will be
700  // cleared
701  addToGridLayout(0, tr("Password"), password);
702  }
704  clearPanelTimer.start();
705  }
706  }
707 
708  DisplayInTextBrowser(output);
709  enableUiElements(true);
710 }
711 
712 void MainWindow::passStoreChanged(const QString &p_out, const QString &p_err) {
713  processFinished(p_out, p_err);
714  doGitPush();
715 }
716 
717 void MainWindow::doGitPush() {
719  on_pushButton_clicked();
720 }
721 
722 void MainWindow::finishedInsert(const QString &p_output,
723  const QString &p_errout) {
724  processFinished(p_output, p_errout);
725  doGitPush();
726  on_treeView_clicked(ui->treeView->currentIndex());
727 }
728 
729 void MainWindow::DisplayInTextBrowser(QString output, QString prefix,
730  QString postfix) {
731 
732  output.replace(QRegExp("<"), "&lt;");
733  output.replace(QRegExp(">"), "&gt;");
734  output.replace(QRegExp(" "), "&nbsp;");
735 
736  output.replace(
737  QRegExp("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
738  "<a href=\"\\1\">\\1</a>");
739  output.replace(QRegExp("\n"), "<br />");
740  output = prefix + output + postfix;
741  if (!ui->textBrowser->toPlainText().isEmpty())
742  output = ui->textBrowser->toHtml() + output;
743  ui->textBrowser->setHtml(output);
744 }
745 
746 void MainWindow::processErrorExit(int exitCode, const QString &p_error) {
747  if (!p_error.isEmpty()) {
748  QString output;
749  QString error = p_error;
750  error.replace(QRegExp("<"), "&lt;");
751  error.replace(QRegExp(">"), "&gt;");
752  error.replace(QRegExp(" "), "&nbsp;");
753  if (exitCode == 0) {
754  // https://github.com/IJHack/qtpass/issues/111
755  output = "<span style=\"color: darkgray;\">" + error + "</span><br />";
756  } else {
757  output = "<span style=\"color: red;\">" + error + "</span><br />";
758  }
759 
760  output.replace(
761  QRegExp("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
762  "<a href=\"\\1\">\\1</a>");
763  output.replace(QRegExp("\n"), "<br />");
764  if (!ui->textBrowser->toPlainText().isEmpty())
765  output = ui->textBrowser->toHtml() + output;
766  ui->textBrowser->setHtml(output);
767  }
768  enableUiElements(true);
769 }
770 
774 void MainWindow::clearClipboard() {
775  QClipboard *clipboard = QApplication::clipboard();
777  QString clippedText = clipboard->text(QClipboard::Clipboard);
778  } else {
779  QString clippedText = clipboard->text(QClipboard::Selection);
780  }
781  if (clippedText == this->clippedText) {
783  clipboard->clear(QClipboard::Clipboard);
784  } else {
785  clipboard->clear(QClipboard::Selection);
786  }
787  ui->statusBar->showMessage(tr("Clipboard cleared"), 2000);
788  } else {
789  ui->statusBar->showMessage(tr("Clipboard not cleared"), 2000);
790  }
791 }
792 
796 void MainWindow::clearPanel(bool notify) {
797  while (ui->gridLayout->count() > 0) {
798  QLayoutItem *item = ui->gridLayout->takeAt(0);
799  delete item->widget();
800  delete item;
801  }
802  if (notify) {
803  QString output = "***" + tr("Password and Content hidden") + "***";
804  ui->textBrowser->setHtml(output);
805  } else {
806  ui->textBrowser->setHtml("");
807  }
808 }
809 
817 void MainWindow::processFinished(const QString &p_output,
818  const QString &p_errout) {
819  DisplayInTextBrowser(p_output);
820  // Sometimes there is error output even with 0 exit code, which is
821  // assumed in this function
822  processErrorExit(0, p_errout);
823  enableUiElements(true);
824 }
825 
831 void MainWindow::enableUiElements(bool state) {
832  ui->updateButton->setEnabled(state);
833  ui->treeView->setEnabled(state);
834  ui->lineEdit->setEnabled(state);
835  ui->lineEdit->installEventFilter(this);
836  ui->addButton->setEnabled(state);
837  ui->usersButton->setEnabled(state);
838  ui->configButton->setEnabled(state);
839  // is a file selected?
840  state &= ui->treeView->currentIndex().isValid();
841  ui->deleteButton->setEnabled(state);
842  ui->editButton->setEnabled(state);
843  ui->pushButton->setEnabled(state);
844 }
845 
850 void MainWindow::processError(QProcess::ProcessError error) {
851  QString errorString;
852  switch (error) {
853  case QProcess::FailedToStart:
854  errorString = tr("QProcess::FailedToStart");
855  break;
856  case QProcess::Crashed:
857  errorString = tr("QProcess::Crashed");
858  break;
859  case QProcess::Timedout:
860  errorString = tr("QProcess::Timedout");
861  break;
862  case QProcess::ReadError:
863  errorString = tr("QProcess::ReadError");
864  break;
865  case QProcess::WriteError:
866  errorString = tr("QProcess::WriteError");
867  break;
868  case QProcess::UnknownError:
869  errorString = tr("QProcess::UnknownError");
870  break;
871  }
872  ui->textBrowser->setTextColor(Qt::red);
873  ui->textBrowser->setText(errorString);
874  ui->textBrowser->setTextColor(Qt::black);
875  enableUiElements(true);
876 }
877 
881 void MainWindow::on_configButton_clicked() { config(); }
882 
888 void MainWindow::on_lineEdit_textChanged(const QString &arg1) {
889  ui->treeView->expandAll();
890  ui->statusBar->showMessage(tr("Looking for: %1").arg(arg1), 1000);
891  QString query = arg1;
892  query.replace(QRegExp(" "), ".*");
893  QRegExp regExp(query, Qt::CaseInsensitive);
894  proxyModel.setFilterRegExp(regExp);
895  ui->treeView->setRootIndex(proxyModel.mapFromSource(
896  model.setRootPath(QtPassSettings::getPassStore())));
897  selectFirstFile();
898 }
899 
905 void MainWindow::on_lineEdit_returnPressed() {
906  dbg() << "on_lineEdit_returnPressed";
907  selectFirstFile();
908  on_treeView_clicked(ui->treeView->currentIndex());
909 }
910 
915 void MainWindow::selectFirstFile() {
916  QModelIndex index = proxyModel.mapFromSource(
917  model.setRootPath(QtPassSettings::getPassStore()));
918  index = firstFile(index);
919  ui->treeView->setCurrentIndex(index);
920 }
921 
927 QModelIndex MainWindow::firstFile(QModelIndex parentIndex) {
928  QModelIndex index = parentIndex;
929  int numRows = proxyModel.rowCount(parentIndex);
930  for (int row = 0; row < numRows; ++row) {
931  index = proxyModel.index(row, 0, parentIndex);
932  if (model.fileInfo(proxyModel.mapToSource(index)).isFile())
933  return index;
934  if (proxyModel.hasChildren(index))
935  return firstFile(index);
936  }
937  return index;
938 }
939 
947 void MainWindow::setPassword(QString file, bool isNew) {
948  PasswordDialog d(pwdConfig, this);
951  // TODO(bezet): add error handling
952  QtPassSettings::getPass()->Show(file);
953  d.setFile(file);
954  d.usePwgen(QtPassSettings::isUsePwgen());
955  d.setTemplate(QtPassSettings::getPassTemplate());
956  d.useTemplate(QtPassSettings::isUseTemplate());
957  d.templateAll(QtPassSettings::isTemplateAllFields());
958  if (!d.exec()) {
959  d.setPassword(QString());
960  return;
961  }
962  QString newValue = d.getPassword();
963  if (newValue.isEmpty())
964  return;
965 
966  if (newValue.right(1) != "\n")
967  newValue += "\n";
968 
969  QtPassSettings::getPass()->Insert(file, newValue, !isNew);
970 }
971 
976 void MainWindow::on_addButton_clicked() {
977  bool ok;
978  QString dir =
979  Util::getDir(ui->treeView->currentIndex(), true, model, proxyModel);
980  QString file =
981  QInputDialog::getText(this, tr("New file"),
982  tr("New password file: \n(Will be placed in %1 )")
984  Util::getDir(ui->treeView->currentIndex(),
985  true, model, proxyModel)),
986  QLineEdit::Normal, "", &ok);
987  if (!ok || file.isEmpty())
988  return;
989  file = dir + file;
990  setPassword(file);
991 }
992 
997 void MainWindow::on_deleteButton_clicked() {
998  QFileInfo fileOrFolder =
999  model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex()));
1000  QString file = "";
1001  bool isDir = false;
1002 
1003  if (fileOrFolder.isFile()) {
1004  file = getFile(ui->treeView->currentIndex(), true);
1005  } else {
1006  file = Util::getDir(ui->treeView->currentIndex(), true, model, proxyModel);
1007  isDir = true;
1008  }
1009 
1010  if (QMessageBox::question(
1011  this, isDir ? tr("Delete folder?") : tr("Delete password?"),
1012  tr("Are you sure you want to delete %1%2?")
1013  .arg(QDir::separator() + file)
1014  .arg(isDir ? tr(" and whole content") : ""),
1015  QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
1016  return;
1017 
1018  QtPassSettings::getPass()->Remove(file, isDir);
1019 }
1020 
1024 void MainWindow::on_editButton_clicked() {
1025  QString file = getFile(ui->treeView->currentIndex(), true);
1026  editPassword(file);
1027 }
1028 
1033 void MainWindow::userDialog(QString dir) {
1034  if (!dir.isEmpty())
1035  currentDir = dir;
1036  on_usersButton_clicked();
1037 }
1038 
1044 void MainWindow::on_usersButton_clicked() {
1045  QList<UserInfo> users = QtPassSettings::getPass()->listKeys();
1046  if (users.size() == 0) {
1047  QMessageBox::critical(this, tr("Can not get key list"),
1048  tr("Unable to get list of available gpg keys"));
1049  return;
1050  }
1051  QList<UserInfo> secret_keys = QtPassSettings::getPass()->listKeys("", true);
1052  foreach (const UserInfo &sec, secret_keys) {
1053  for (QList<UserInfo>::iterator it = users.begin(); it != users.end(); ++it)
1054  if (sec.key_id == it->key_id)
1055  it->have_secret = true;
1056  }
1057  QList<UserInfo> selected_users;
1058  QString dir =
1059  currentDir.isEmpty()
1060  ? Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel)
1061  : currentDir;
1062  int count = 0;
1063  QString recipients = QtPassSettings::getPass()->getRecipientString(
1064  dir.isEmpty() ? "" : dir, " ", &count);
1065  if (!recipients.isEmpty())
1066  selected_users = QtPassSettings::getPass()->listKeys(recipients);
1067  foreach (const UserInfo &sel, selected_users) {
1068  for (QList<UserInfo>::iterator it = users.begin(); it != users.end(); ++it)
1069  if (sel.key_id == it->key_id)
1070  it->enabled = true;
1071  }
1072  if (count > selected_users.size()) {
1073  // Some keys seem missing from keyring, add them separately
1074  QStringList recipients =
1075  QtPassSettings::getPass()->getRecipientList(dir.isEmpty() ? "" : dir);
1076  foreach (const QString recipient, recipients) {
1077  if (QtPassSettings::getPass()->listKeys(recipient).size() < 1) {
1078  UserInfo i;
1079  i.enabled = true;
1080  i.key_id = recipient;
1081  i.name = " ?? " + tr("Key not found in keyring");
1082  users.append(i);
1083  }
1084  }
1085  }
1086  UsersDialog d(this);
1087  d.setUsers(&users);
1088  if (!d.exec()) {
1089  d.setUsers(NULL);
1090  return;
1091  }
1092  d.setUsers(NULL);
1093 
1094  QtPassSettings::getPass()->Init(dir, users);
1095 }
1096 
1102 #if SINGLE_APP
1103  connect(app, SIGNAL(messageAvailable(QString)), this,
1104  SLOT(messageAvailable(QString)));
1105 #endif
1106 }
1107 
1112 void MainWindow::messageAvailable(QString message) {
1113  if (message.isEmpty()) {
1114  focusInput();
1115  } else {
1116  ui->treeView->expandAll();
1117  ui->lineEdit->setText(message);
1118  on_lineEdit_returnPressed();
1119  }
1120  show();
1121  raise();
1122 }
1123 
1129 void MainWindow::setText(QString text) { ui->lineEdit->setText(text); }
1130 
1136  QList<UserInfo> keys = QtPassSettings::getPass()->listKeys("", true);
1137  QStringList names;
1138 
1139  if (keys.size() == 0)
1140  return names;
1141 
1142  foreach (const UserInfo &sec, keys)
1143  names << sec.name;
1144 
1145  return names;
1146 }
1147 
1153 void MainWindow::generateKeyPair(QString batch, QDialog *keygenWindow) {
1154  keygen = keygenWindow;
1155  ui->statusBar->showMessage(tr("Generating GPG key pair"), 60000);
1157 }
1158 
1163 void MainWindow::updateProfileBox() {
1164  // dbg()<< profiles.size();
1165  if (QtPassSettings::getProfiles().isEmpty()) {
1166  ui->profileBox->hide();
1167  } else {
1168  ui->profileBox->show();
1169  if (QtPassSettings::getProfiles().size() < 2)
1170  ui->profileBox->setEnabled(false);
1171  else
1172  ui->profileBox->setEnabled(true);
1173  ui->profileBox->clear();
1174  QHashIterator<QString, QString> i(QtPassSettings::getProfiles());
1175  while (i.hasNext()) {
1176  i.next();
1177  if (!i.key().isEmpty())
1178  ui->profileBox->addItem(i.key());
1179  }
1180  }
1181  int index = ui->profileBox->findText(QtPassSettings::getProfile());
1182  if (index != -1) // -1 for not found
1183  ui->profileBox->setCurrentIndex(index);
1184 }
1185 
1191 void MainWindow::on_profileBox_currentIndexChanged(QString name) {
1192  if (startupPhase || name == QtPassSettings::getProfile())
1193  return;
1195 
1197  ui->statusBar->showMessage(tr("Profile changed to %1").arg(name), 2000);
1198 
1200 
1201  ui->treeView->setRootIndex(proxyModel.mapFromSource(
1202  model.setRootPath(QtPassSettings::getPassStore())));
1203 }
1204 
1210 void MainWindow::initTrayIcon() {
1211  if (tray != NULL) {
1212  dbg() << "Creating tray icon again?";
1213  return;
1214  }
1215  if (QSystemTrayIcon::isSystemTrayAvailable() == true) {
1216  // Setup tray icon
1217  this->tray = new TrayIcon(this);
1218  if (tray == NULL)
1219  dbg() << "Allocating tray icon failed.";
1220  } else {
1221  dbg() << "No tray icon for this OS possibly also not show options?";
1222  }
1223 }
1224 
1228 void MainWindow::destroyTrayIcon() {
1229  if (tray == NULL) {
1230  dbg() << "Destroy non existing tray icon?";
1231  return;
1232  }
1233  delete this->tray;
1234  tray = NULL;
1235 }
1236 
1241 void MainWindow::closeEvent(QCloseEvent *event) {
1243  this->hide();
1244  event->ignore();
1245  } else {
1246  clearClipboard();
1247  QtPassSettings::setGeometry(saveGeometry());
1248  QtPassSettings::setSavestate(saveState());
1249  QtPassSettings::setMaximized(isMaximized());
1250  if (!isMaximized()) {
1251  QtPassSettings::setPos(pos());
1252  QtPassSettings::setSize(size());
1253  }
1254  QtPassSettings::setSplitterLeft(ui->splitter->sizes()[0]);
1255  QtPassSettings::setSplitterRight(ui->splitter->sizes()[1]);
1256  event->accept();
1257  }
1258 }
1259 
1267 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1268  if (obj == ui->lineEdit && event->type() == QEvent::KeyPress) {
1269  QKeyEvent *key = static_cast<QKeyEvent *>(event);
1270  if (key->key() == Qt::Key_Down) {
1271  ui->treeView->setFocus();
1272  }
1273  }
1274  return QObject::eventFilter(obj, event);
1275 }
1276 
1281 void MainWindow::keyPressEvent(QKeyEvent *event) {
1282  switch (event->key()) {
1283  case Qt::Key_Delete:
1284  on_deleteButton_clicked();
1285  break;
1286  case Qt::Key_Return:
1287  case Qt::Key_Enter:
1288  on_treeView_clicked(ui->treeView->currentIndex());
1289  break;
1290  case Qt::Key_Escape:
1291  ui->lineEdit->clear();
1292  break;
1293  default:
1294  break;
1295  }
1296 }
1297 
1303 void MainWindow::showContextMenu(const QPoint &pos) {
1304  QModelIndex index = ui->treeView->indexAt(pos);
1305  bool selected = true;
1306  if (!index.isValid()) {
1307  ui->treeView->clearSelection();
1308  ui->deleteButton->setEnabled(false);
1309  ui->editButton->setEnabled(false);
1310  currentDir = "";
1311  selected = false;
1312  }
1313 
1314  ui->treeView->setCurrentIndex(index);
1315 
1316  QPoint globalPos = ui->treeView->viewport()->mapToGlobal(pos);
1317 
1318  QFileInfo fileOrFolder =
1319  model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex()));
1320 
1321  QMenu contextMenu;
1322  if (!selected || fileOrFolder.isDir()) {
1323  QAction *addFolder = contextMenu.addAction(tr("Add folder"));
1324  QAction *addPassword = contextMenu.addAction(tr("Add password"));
1325  QAction *users = contextMenu.addAction(tr("Users"));
1326  connect(addFolder, SIGNAL(triggered()), this, SLOT(addFolder()));
1327  connect(addPassword, SIGNAL(triggered()), this,
1328  SLOT(on_addButton_clicked()));
1329  connect(users, SIGNAL(triggered()), this, SLOT(on_usersButton_clicked()));
1330  } else if (fileOrFolder.isFile()) {
1331  QAction *edit = contextMenu.addAction(tr("Edit"));
1332  connect(edit, SIGNAL(triggered()), this, SLOT(on_editButton_clicked()));
1333  }
1334  if (selected) {
1335  // if (useClipboard != CLIPBOARD_NEVER) {
1336  // contextMenu.addSeparator();
1337  // QAction* copyItem = contextMenu.addAction(tr("Copy Password"));
1338  // if (getClippedPassword().length() == 0) copyItem->setEnabled(false);
1339  // connect(copyItem, SIGNAL(triggered()), this,
1340  // SLOT(copyPasswordToClipboard()));
1341  // }
1342  contextMenu.addSeparator();
1343  QAction *deleteItem = contextMenu.addAction(tr("Delete"));
1344  connect(deleteItem, SIGNAL(triggered()), this,
1345  SLOT(on_deleteButton_clicked()));
1346  }
1347  contextMenu.exec(globalPos);
1348 }
1349 
1355 void MainWindow::showBrowserContextMenu(const QPoint &pos) {
1356  QMenu *contextMenu = ui->textBrowser->createStandardContextMenu(pos);
1357  QPoint globalPos = ui->textBrowser->viewport()->mapToGlobal(pos);
1358 
1359  contextMenu->exec(globalPos);
1360 }
1361 
1365 void MainWindow::addFolder() {
1366  bool ok;
1367  QString dir =
1368  Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel);
1369  QString newdir =
1370  QInputDialog::getText(this, tr("New file"),
1371  tr("New Folder: \n(Will be placed in %1 )")
1373  Util::getDir(ui->treeView->currentIndex(),
1374  true, model, proxyModel)),
1375  QLineEdit::Normal, "", &ok);
1376  if (!ok || newdir.isEmpty())
1377  return;
1378  newdir.prepend(dir);
1379  // dbg()<< newdir;
1380  QDir().mkdir(newdir);
1381 }
1382 
1387 void MainWindow::editPassword(const QString &file) {
1388  if (!file.isEmpty()) {
1390  on_updateButton_clicked(true);
1391  setPassword(file, false);
1392  }
1393 }
1394 
1399 void MainWindow::clearTemplateWidgets() {
1400  while (ui->gridLayout->count() > 0) {
1401  QLayoutItem *item = ui->gridLayout->takeAt(0);
1402  delete item->widget();
1403  delete item;
1404  }
1405  ui->verticalLayoutPassword->setSpacing(0);
1406 }
1407 
1412 void MainWindow::copyTextToClipboard(const QString &text) {
1413  QClipboard *clip = QApplication::clipboard();
1415  clip->setText(text, QClipboard::Clipboard);
1416  } else {
1417  clip->setText(text, QClipboard::Selection);
1418  }
1419  clippedText = text;
1420  ui->statusBar->showMessage(tr("Copied to clipboard"), 2000);
1422  clearClipboardTimer.start();
1423  }
1424 }
1425 
1432 void MainWindow::addToGridLayout(int position, const QString &field,
1433  const QString &value) {
1434  QString trimmedField = field.trimmed();
1435  QString trimmedValue = value.trimmed();
1436 
1437  // Combine the Copy button and the line edit in one widget
1438  QFrame *frame = new QFrame();
1439  QLayout *ly = new QHBoxLayout();
1440  ly->setContentsMargins(5, 2, 2, 2);
1441  frame->setLayout(ly);
1443  QPushButtonWithClipboard *fieldLabel =
1444  new QPushButtonWithClipboard(trimmedValue, this);
1445  connect(fieldLabel, SIGNAL(clicked(QString)), this,
1446  SLOT(copyTextToClipboard(QString)));
1447 
1448  fieldLabel->setStyleSheet("border-style: none ; background: transparent;");
1449  // fieldLabel->setContentsMargins(0,5,5,0);
1450  frame->layout()->addWidget(fieldLabel);
1451  }
1452 
1453  // set the echo mode to password, if the field is "password"
1454  if (QtPassSettings::isHidePassword() && trimmedField == tr("Password")) {
1455  QLineEdit *line = new QLineEdit();
1456  line->setObjectName(trimmedField);
1457  line->setText(trimmedValue);
1458  line->setReadOnly(true);
1459  line->setStyleSheet("border-style: none ; background: transparent;");
1460  line->setContentsMargins(0, 0, 0, 0);
1461  line->setEchoMode(QLineEdit::Password);
1462  frame->layout()->addWidget(line);
1463  } else {
1464  QTextBrowser *line = new QTextBrowser();
1465  line->setOpenExternalLinks(true);
1466  line->setOpenLinks(true);
1467  line->setMaximumHeight(26);
1468  line->setMinimumHeight(26);
1469  line->setSizePolicy(
1470  QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
1471  line->setObjectName(trimmedField);
1472  trimmedValue.replace(
1473  QRegExp("((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://\\S+)"),
1474  "<a href=\"\\1\">\\1</a>");
1475  line->setText(trimmedValue);
1476  line->setReadOnly(true);
1477  line->setStyleSheet("border-style: none ; background: transparent;");
1478  line->setContentsMargins(0, 0, 0, 0);
1479  frame->layout()->addWidget(line);
1480  }
1481 
1482  frame->setStyleSheet(
1483  ".QFrame{border: 1px solid lightgrey; border-radius: 5px;}");
1484 
1485  // set into the layout
1486  ui->gridLayout->addWidget(new QLabel(trimmedField), position, 0);
1487  ui->gridLayout->addWidget(frame, position, 1);
1488 }
1489 
1496 void MainWindow::showStatusMessage(QString msg, int timeout) {
1497  ui->statusBar->showMessage(msg, timeout);
1498 }
1499 
1503 void MainWindow::startReencryptPath() {
1504  enableUiElements(false);
1505  ui->treeView->setDisabled(true);
1506 }
1507 
1511 void MainWindow::endReencryptPath() { enableUiElements(true); }
1512 
1518 void MainWindow::critical(QString title, QString msg) {
1519  QMessageBox::critical(this, title, msg);
1520 }
static void setPwgenExecutable(const QString &pwgenExecutable)
void finishedMove(const QString &, const QString &)
static void setAutoclearSeconds(const int &autoClearSeconds)
static int getAutoclearSeconds(const int &defaultValue=QVariant().toInt())
static void setUsePwgen(const bool &usePwgen)
static bool isStartMinimized(const bool &defaultValue=QVariant().toBool())
static bool isMaximized(const bool &defaultValue=QVariant().toBool())
static void setUsePass(const bool &usePass)
void finishedCopy(const QString &, const QString &)
static bool isLessRandom(const bool &defaultValue=QVariant().toBool())
static void setPassExecutable(const QString &passExecutable)
void GenerateGPGKeys(QString batch)
Pass::GenerateGPGKeys internal gpg keypair generator . .
Definition: pass.cpp:106
passwordConfiguration pwdConfig
MainWindow::pwdConfig instance of passwordConfiguration.
Definition: mainwindow.h:61
void setText(QString)
MainWindow::setText do a search from an external source (eg: commandline)
int length
passwordConfiguration::length of password.
Definition: datahelpers.h:25
void finishedGenerateGPGKeys(const QString &, const QString &)
static void setSplitterLeft(const int &splitterLeft)
Stylish widget to allow copying of password and account details.
bool enabled
UserInfo::enabled.
Definition: datahelpers.h:85
void finishedGitPush(const QString &, const QString &)
void error(QProcess::ProcessError)
#define dbg()
Definition: debughelper.h:7
static bool isAlwaysOnTop(const bool &defaultValue=QVariant().toBool())
static QPoint getPos(const QPoint &defaultValue=QVariant().toPoint())
QList< UserInfo > listKeys(QString keystring="", bool secret=false)
Pass::listKeys list users.
Definition: pass.cpp:120
static void setPasswordChars(const QString &passwordChars)
static QString findBinaryInPath(QString binary)
Util::findBinaryInPath search for executables.
Definition: util.cpp:77
static void setAutoPush(const bool &autoPush)
static void setGitExecutable(const QString &gitExecutable)
static void setAlwaysOnTop(const bool &alwaysOnTop)
static bool isUseSelection(const bool &defaultValue=QVariant().toBool())
QString key_id
UserInfo::key_id hexadecimal representation.
Definition: datahelpers.h:71
static void setPassTemplate(const QString &passTemplate)
void finishedInsert(const QString &, const QString &)
~MainWindow()
MainWindow::~MainWindow destroy!
Definition: mainwindow.cpp:108
static QString getPasswordChars(const QString &defaultValue=QVariant().toString())
static void setUseGit(const bool &useGit)
static void setClipBoardType(const Enums::clipBoardType &clipBoardType)
static void setPos(const QPoint &pos)
static bool isAvoidNumbers(const bool &defaultValue=QVariant().toBool())
static ImitatePass * getImitatePass()
static void setHideContent(const bool &hideContent)
static bool isUseAutoclearPanel(const bool &defaultValue=QVariant().toBool())
static bool isUseWebDav(const bool &defaultValue=QVariant().toBool())
static void setSize(const QSize &size)
static void setLessRandom(const bool &lessRandom)
void finishedRemove(const QString &, const QString &)
static void setAutoPull(const bool &autoPull)
static void setSplitterRight(const int &splitterRight)
QString Characters[CHARSETS_COUNT]
passwordConfiguration::Characters the different character sets.
Definition: datahelpers.h:29
static bool isAddGPGId(const bool &defaultValue=QVariant().toBool())
static bool isUseAutoclear(const bool &defaultValue=QVariant().toBool())
virtual void GitInit()=0
static bool isHideOnClose(const bool &defaultValue=QVariant().toBool())
bool eventFilter(QObject *obj, QEvent *event)
MainWindow::eventFilter filter out some events and focus the treeview.
static void setProfiles(const QHash< QString, QString > &profiles)
static bool isUseGit(const bool &defaultValue=QVariant().toBool())
void config()
MainWindow::config pops up the configuration screen and handles all inter-window communication.
Definition: mainwindow.cpp:396
Acts as an abstraction for pass or pass imitation.
Definition: pass.h:27
static QString getPassStore(const QString &defaultValue=QVariant().toString())
static void setProfile(const QString &profile)
void userDialog(QString="")
MainWindow::userDialog see MainWindow::on_usersButton_clicked()
virtual void Remove(QString file, bool isDir)=0
static void setMaximized(const bool &maximized)
static QString getGitExecutable(const QString &defaultValue=QVariant().toString())
void finishedGitPull(const QString &, const QString &)
virtual void Show(QString file)=0
static void setAutoclearPanelSeconds(const int &autoClearPanelSeconds)
void critical(QString, QString)
void setModelAndStore(QFileSystemModel *sourceModel, QString passStore)
StoreModel::setModelAndStore update the source model and store.
Definition: storemodel.cpp:79
static void setUseAutoclearPanel(const bool &useAutoclearPanel)
enum passwordConfiguration::characterSet selected
PasswordDialog Handles the inserting and editing of passwords.
static bool isUseTrayIcon(const bool &defaultValue=QVariant().toBool())
void closeEvent(QCloseEvent *event)
MainWindow::closeEvent hide or quit.
static QString getRecipientString(QString for_file, QString separator=" ", int *count=NULL)
Pass::getRecipientString formated string for use with GPG.
Definition: pass.cpp:267
Handles listing and editing of GPG users.
Definition: usersdialog.h:23
virtual void GitPull_b()=0
void changeEvent(QEvent *event)
MainWindow::changeEvent sets focus to the search box.
Definition: mainwindow.cpp:125
static void setAvoidNumbers(const bool &avoidNumbers)
static QString getPassExecutable(const QString &defaultValue=QVariant().toString())
Handles the systemtray icon and menu.
Definition: trayicon.h:15
void keyPressEvent(QKeyEvent *event)
MainWindow::keyPressEvent did anyone press return, enter or escape?
static QString getVersion(const QString &defaultValue=QVariant().toString())
void executePassGitInit()
MainWindow::executePassGitInit git init wrapper.
Definition: mainwindow.cpp:619
static void setHideOnClose(const bool &hideOnClose)
static QStringList getRecipientList(QString for_file)
Pass::getRecipientList return list of gpg-id&#39;s to encrypt for.
Definition: pass.cpp:231
static bool isAvoidCapitals(const bool &defaultValue=QVariant().toBool())
static QByteArray getSavestate(const QByteArray &defaultValue=QVariant().toByteArray())
static QSize getSize(const QSize &defaultValue=QVariant().toSize())
virtual void GitPush()=0
void setApp(SingleApplication *app)
MainWindow::setApp make sure we know what/who/where we are.
The SingleApplication class is used for commandline intergration.
static Pass * getPass()
void statusMsg(QString, int)
virtual void GitPull()=0
static void setGpgExecutable(const QString &gpgExecutable)
static QString getWebDavUser(const QString &defaultValue=QVariant().toString())
static void setStartMinimized(const bool &startMinimized)
MainWindow(QWidget *parent=0)
MainWindow::MainWindow handles all of the main functionality and also the main window.
Definition: mainwindow.cpp:35
void finishedInit(const QString &, const QString &)
static bool isUsePwgen(const bool &defaultValue=QVariant().toBool())
static void setSavestate(const QByteArray &saveState)
static void setUseAutoclear(const bool &useAutoclear)
static QString getPassTemplate(const QString &defaultValue=QVariant().toString())
static Enums::clipBoardType getClipBoardType(const Enums::clipBoardType &defaultvalue=Enums::CLIPBOARD_NEVER)
static QString getWebDavUrl(const QString &defaultValue=QVariant().toString())
static QString getPwgenExecutable(const QString &defaultValue=QVariant().toString())
static bool isUseSymbols(const bool &defaultValue=QVariant().toBool())
void updateEnv()
Pass::updateEnv update the execution environment (used when switching profiles)
Definition: pass.cpp:210
The ConfigDialog handles the configuration interface.
Definition: configdialog.h:22
QString name
UserInfo::name full name.
Definition: datahelpers.h:67
bool checkConfig()
MainWindow::checkConfig make sure we are ready to go as soon as possible.
Definition: mainwindow.cpp:236
Stores key info lines including validity, creation date and more.
Definition: datahelpers.h:46
static void setUseTemplate(const bool &useTemplate)
static QByteArray getGeometry(const QByteArray &defaultValue=QVariant().toByteArray())
static void setPasswordCharsselection(const int &passwordCharsselection)
static int getSplitterRight(const int &defaultValue=QVariant().toInt())
static int getAutoclearPanelSeconds(const int &defaultValue=QVariant().toInt())
static void setAddGPGId(const bool &addGPGId)
static QString getGpgExecutable(const QString &defaultValue=QVariant().toString())
void finishedShow(const QString &)
static bool isUseTemplate(const bool &defaultValue=QVariant().toBool())
static QString getWebDavPassword(const QString &defaultValue=QVariant().toString())
static bool isTemplateAllFields(const bool &defaultValue=QVariant().toBool())
static void setUseSymbols(const bool &useSymbols)
QStringList getSecretKeys()
MainWindow::getSecretKeys get list of secret/private keys.
static QString getDir(const QModelIndex &index, bool forPass, const QFileSystemModel &model, const StoreModel &storeModel)
Util::getDir get selectd folder path.
Definition: util.cpp:148
virtual void Insert(QString file, QString value, bool force)=0
void finishedGitInit(const QString &, const QString &)
static void setTemplateAllFields(const bool &templateAllFields)
static QHash< QString, QString > getProfiles()
void deselect()
MainWindow::deselect clear the selection, password and copy buffer.
Definition: mainwindow.cpp:609
static void setUseTrayIcon(const bool &useTrayIcon)
static void setGeometry(const QByteArray &geometry)
static int getSplitterLeft(const int &defaultValue=QVariant().toInt())
void generateKeyPair(QString, QDialog *)
MainWindow::generateKeyPair internal gpg keypair generator . .
characterSet
passwordConfiguration::selected character set.
Definition: datahelpers.h:15
virtual void Init(QString path, const QList< UserInfo > &users)=0
void startingExecuteWrapper()
void processErrorExit(int exitCode, const QString &err)
void setPass(const QString &output)
The MainWindow class does way too much, not only is it a switchboard, configuration handler and more...
Definition: mainwindow.h:42
static RealPass * getRealPass()
static bool isHidePassword(const bool &defaultValue=QVariant().toBool())
static QString findPasswordStore()
Util::findPasswordStore look for common .password-store folder location.
Definition: util.cpp:43
static bool isHideContent(const bool &defaultValue=QVariant().toBool())
static bool checkConfig()
Util::checkConfig do we have prequisite settings?
Definition: util.cpp:120
static QString getProfile(const QString &defaultValue=QVariant().toString())
static void setVersion(const QString &version)
static void setHidePassword(const bool &hidePassword)
static void setPassStore(const QString &passStore)
static void setUseSelection(const bool &useSelection)
static void setPasswordLength(const int &passwordLength)
static int getPasswordCharsselection(const int &defaultValue=QVariant().toInt())
static int getPasswordLength(const int &defaultValue=QVariant().toInt())
static bool isAutoPull(const bool &defaultValue=QVariant().toBool())
static bool isUsePass(const bool &defaultValue=QVariant().toBool())
static QString normalizeFolderPath(QString path)
Util::normalizeFolderPath let&#39;s always end folders with a QDir::separator()
Definition: util.cpp:66
static bool isAutoPush(const bool &defaultValue=QVariant().toBool())
static void setAvoidCapitals(const bool &avoidCapitals)