• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IJHack / QtPass / 23862950363

01 Apr 2026 05:54PM UTC coverage: 20.086% (+0.004%) from 20.082%
23862950363

push

github

web-flow
Merge pull request #890 from IJHack/fix/ai-findings-10-more

fix: address 10 more AI findings across 4 files

9 of 45 new or added lines in 7 files covered. (20.0%)

4 existing lines in 4 files now uncovered.

1030 of 5128 relevant lines covered (20.09%)

7.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/mainwindow.cpp
1
// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "mainwindow.h"
4

5
#ifdef QT_DEBUG
6
#include "debughelper.h"
7
#endif
8

9
#include "configdialog.h"
10
#include "filecontent.h"
11
#include "passworddialog.h"
12
#include "qpushbuttonasqrcode.h"
13
#include "qpushbuttonshowpassword.h"
14
#include "qpushbuttonwithclipboard.h"
15
#include "qtpass.h"
16
#include "qtpasssettings.h"
17
#include "trayicon.h"
18
#include "ui_mainwindow.h"
19
#include "usersdialog.h"
20
#include "util.h"
21
#include <QCloseEvent>
22
#include <QDesktopServices>
23
#include <QDialog>
24
#include <QDirIterator>
25
#include <QFileInfo>
26
#include <QInputDialog>
27
#include <QLabel>
28
#include <QMenu>
29
#include <QMessageBox>
30
#include <QShortcut>
31
#include <QTimer>
32
#include <utility>
33

34
/**
35
 * @brief MainWindow::MainWindow handles all of the main functionality and also
36
 * the main window.
37
 * @param searchText for searching from cli
38
 * @param parent pointer
39
 */
40
MainWindow::MainWindow(const QString &searchText, QWidget *parent)
×
41
    : QMainWindow(parent), ui(new Ui::MainWindow), keygen(nullptr),
×
42
      tray(nullptr) {
×
43
#ifdef __APPLE__
44
  // extra treatment for mac os
45
  // see http://doc.qt.io/qt-5/qkeysequence.html#qt_set_sequence_auto_mnemonic
46
  qt_set_sequence_auto_mnemonic(true);
47
#endif
48
  ui->setupUi(this);
×
49

50
  m_qtPass = new QtPass(this);
×
51

52
  // register shortcut ctrl/cmd + Q to close the main window
53
  new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this, SLOT(close()));
×
54
  // register shortcut ctrl/cmd + C to copy the currently selected password
55
  new QShortcut(QKeySequence(QKeySequence::StandardKey::Copy), this,
×
56
                SLOT(copyPasswordFromTreeview()));
×
57

58
  model.setNameFilters(QStringList() << "*.gpg");
×
59
  model.setNameFilterDisables(false);
×
60

61
  /*
62
   * I added this to solve Windows bug but now on GNU/Linux the main folder,
63
   * if hidden, disappear
64
   *
65
   * model.setFilter(QDir::NoDot);
66
   */
67

68
  QString passStore = QtPassSettings::getPassStore(Util::findPasswordStore());
×
69

70
  QModelIndex rootDir = model.setRootPath(passStore);
×
71
  model.fetchMore(rootDir);
×
72

73
  proxyModel.setModelAndStore(&model, passStore);
×
74
  selectionModel.reset(new QItemSelectionModel(&proxyModel));
×
75

76
  ui->treeView->setModel(&proxyModel);
×
77
  ui->treeView->setRootIndex(proxyModel.mapFromSource(rootDir));
×
78
  ui->treeView->setColumnHidden(1, true);
×
79
  ui->treeView->setColumnHidden(2, true);
×
80
  ui->treeView->setColumnHidden(3, true);
×
81
  ui->treeView->setHeaderHidden(true);
×
82
  ui->treeView->setIndentation(15);
×
83
  ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
×
84
  ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
×
85
  ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
×
86
  ui->treeView->sortByColumn(0, Qt::AscendingOrder);
×
87
  connect(ui->treeView, &QWidget::customContextMenuRequested, this,
×
88
          &MainWindow::showContextMenu);
×
89
  connect(ui->treeView, &DeselectableTreeView::emptyClicked, this,
×
90
          &MainWindow::deselect);
×
91

92
  if (QtPassSettings::isUseMonospace()) {
×
93
    QFont monospace("Monospace");
×
94
    monospace.setStyleHint(QFont::Monospace);
×
95
    ui->textBrowser->setFont(monospace);
×
96
  }
×
97
  if (QtPassSettings::isNoLineWrapping()) {
×
98
    ui->textBrowser->setLineWrapMode(QTextBrowser::NoWrap);
×
99
  }
100
  ui->textBrowser->setOpenExternalLinks(true);
×
101
  ui->textBrowser->setContextMenuPolicy(Qt::CustomContextMenu);
×
102
  connect(ui->textBrowser, &QWidget::customContextMenuRequested, this,
×
103
          &MainWindow::showBrowserContextMenu);
×
104

105
  updateProfileBox();
×
106

107
  QtPassSettings::getPass()->updateEnv();
×
108
  clearPanelTimer.setInterval(MS_PER_SECOND *
×
109
                              QtPassSettings::getAutoclearPanelSeconds());
×
110
  clearPanelTimer.setSingleShot(true);
×
NEW
111
  connect(&clearPanelTimer, &QTimer::timeout, this, [this]() { clearPanel(); });
×
112

113
  searchTimer.setInterval(350);
×
114
  searchTimer.setSingleShot(true);
×
115

116
  connect(&searchTimer, &QTimer::timeout, this, &MainWindow::onTimeoutSearch);
×
117

118
  initToolBarButtons();
×
119
  initStatusBar();
×
120

121
  ui->lineEdit->setClearButtonEnabled(true);
×
122

123
  setUiElementsEnabled(true);
×
124

125
  QTimer::singleShot(10, this, SLOT(focusInput()));
126

127
  ui->lineEdit->setText(searchText);
×
128

129
  if (!m_qtPass->init()) {
×
130
    // no working config so this should just quit
131
    QApplication::quit();
×
132
  }
133
}
×
134

135
MainWindow::~MainWindow() { delete m_qtPass; }
×
136

137
/**
138
 * @brief MainWindow::focusInput selects any text (if applicable) in the search
139
 * box and sets focus to it. Allows for easy searching, called at application
140
 * start and when receiving empty message in MainWindow::messageAvailable when
141
 * compiled with SINGLE_APP=1 (default).
142
 */
143
void MainWindow::focusInput() {
×
144
  ui->lineEdit->selectAll();
×
145
  ui->lineEdit->setFocus();
×
146
}
×
147

148
/**
149
 * @brief MainWindow::changeEvent sets focus to the search box
150
 * @param event
151
 */
152
void MainWindow::changeEvent(QEvent *event) {
×
153
  QWidget::changeEvent(event);
×
154
  if (event->type() == QEvent::ActivationChange) {
×
155
    if (isActiveWindow()) {
×
156
      focusInput();
×
157
    }
158
  }
159
}
×
160

161
/**
162
 * @brief MainWindow::initToolBarButtons init main ToolBar and connect actions
163
 */
164
void MainWindow::initToolBarButtons() {
×
165
  connect(ui->actionAddPassword, &QAction::triggered, this,
×
166
          &MainWindow::addPassword);
×
167
  connect(ui->actionAddFolder, &QAction::triggered, this,
×
168
          &MainWindow::addFolder);
×
169
  connect(ui->actionEdit, &QAction::triggered, this, &MainWindow::onEdit);
×
170
  connect(ui->actionDelete, &QAction::triggered, this, &MainWindow::onDelete);
×
171
  connect(ui->actionPush, &QAction::triggered, this, &MainWindow::onPush);
×
172
  connect(ui->actionUpdate, &QAction::triggered, this, &MainWindow::onUpdate);
×
173
  connect(ui->actionUsers, &QAction::triggered, this, &MainWindow::onUsers);
×
174
  connect(ui->actionConfig, &QAction::triggered, this, &MainWindow::onConfig);
×
175
  connect(ui->actionOtp, &QAction::triggered, this, &MainWindow::onOtp);
×
176

177
  ui->actionAddPassword->setIcon(
×
178
      QIcon::fromTheme("document-new", QIcon(":/icons/document-new.svg")));
×
179
  ui->actionAddFolder->setIcon(
×
180
      QIcon::fromTheme("folder-new", QIcon(":/icons/folder-new.svg")));
×
181
  ui->actionEdit->setIcon(QIcon::fromTheme(
×
182
      "document-properties", QIcon(":/icons/document-properties.svg")));
×
183
  ui->actionDelete->setIcon(
×
184
      QIcon::fromTheme("edit-delete", QIcon(":/icons/edit-delete.svg")));
×
185
  ui->actionPush->setIcon(
×
186
      QIcon::fromTheme("go-up", QIcon(":/icons/go-top.svg")));
×
187
  ui->actionUpdate->setIcon(
×
188
      QIcon::fromTheme("go-down", QIcon(":/icons/go-bottom.svg")));
×
189
  ui->actionUsers->setIcon(QIcon::fromTheme(
×
190
      "x-office-address-book", QIcon(":/icons/x-office-address-book.svg")));
×
191
  ui->actionConfig->setIcon(QIcon::fromTheme(
×
192
      "applications-system", QIcon(":/icons/applications-system.svg")));
×
193
}
×
194

195
/**
196
 * @brief MainWindow::initStatusBar init statusBar with default message and logo
197
 */
198
void MainWindow::initStatusBar() {
×
199
  ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000);
×
200

201
  QPixmap logo = QPixmap::fromImage(QImage(":/artwork/icon.svg"))
×
202
                     .scaledToHeight(statusBar()->height());
×
203
  auto *logoApp = new QLabel(statusBar());
×
204
  logoApp->setPixmap(logo);
×
205
  statusBar()->addPermanentWidget(logoApp);
×
206
}
×
207

208
auto MainWindow::getCurrentTreeViewIndex() -> QModelIndex {
×
209
  return ui->treeView->currentIndex();
×
210
}
211

212
void MainWindow::cleanKeygenDialog() {
×
213
  this->keygen->close();
×
214
  this->keygen = nullptr;
×
215
}
×
216

217
void MainWindow::flashText(const QString &text, const bool isError,
×
218
                           const bool isHtml) {
219
  if (isError) {
×
220
    ui->textBrowser->setTextColor(Qt::red);
×
221
  }
222

223
  if (isHtml) {
×
224
    QString _text = text;
225
    if (!ui->textBrowser->toPlainText().isEmpty()) {
×
226
      _text = ui->textBrowser->toHtml() + _text;
×
227
    }
228
    ui->textBrowser->setHtml(_text);
×
229
  } else {
230
    ui->textBrowser->setText(text);
×
231
    ui->textBrowser->setTextColor(Qt::black);
×
232
  }
233
}
×
234

235
/**
236
 * @brief MainWindow::config pops up the configuration screen and handles all
237
 * inter-window communication
238
 */
239
void MainWindow::applyTextBrowserSettings() {
×
240
  if (QtPassSettings::isUseMonospace()) {
×
241
    QFont monospace("Monospace");
×
242
    monospace.setStyleHint(QFont::Monospace);
×
243
    ui->textBrowser->setFont(monospace);
×
244
  } else {
×
245
    ui->textBrowser->setFont(QFont());
×
246
  }
247

248
  if (QtPassSettings::isNoLineWrapping()) {
×
249
    ui->textBrowser->setLineWrapMode(QTextBrowser::NoWrap);
×
250
  } else {
251
    ui->textBrowser->setLineWrapMode(QTextBrowser::WidgetWidth);
×
252
  }
253
}
×
254

255
void MainWindow::applyWindowFlagsSettings() {
×
256
  if (QtPassSettings::isAlwaysOnTop()) {
×
257
    Qt::WindowFlags flags = windowFlags();
258
    this->setWindowFlags(flags | Qt::WindowStaysOnTopHint);
×
259
  } else {
260
    this->setWindowFlags(Qt::Window);
×
261
  }
262
  this->show();
×
263
}
×
264

265
void MainWindow::config() {
×
266
  QScopedPointer<ConfigDialog> d(new ConfigDialog(this));
×
267
  d->setModal(true);
×
268
  // Automatically default to pass if it's available
269
  if (m_qtPass->isFreshStart() &&
×
270
      QFile(QtPassSettings::getPassExecutable()).exists()) {
×
271
    QtPassSettings::setUsePass(true);
×
272
  }
273

274
  if (m_qtPass->isFreshStart()) {
×
275
    d->wizard(); //  does shit
×
276
  }
277
  if (d->exec()) {
×
278
    if (d->result() == QDialog::Accepted) {
×
279
      applyTextBrowserSettings();
×
280
      applyWindowFlagsSettings();
×
281

282
      updateProfileBox();
×
283
      ui->treeView->setRootIndex(proxyModel.mapFromSource(
×
284
          model.setRootPath(QtPassSettings::getPassStore())));
×
285

286
      if (m_qtPass->isFreshStart() && !Util::configIsValid()) {
×
287
        config();
×
288
      }
289
      QtPassSettings::getPass()->updateEnv();
×
290
      clearPanelTimer.setInterval(MS_PER_SECOND *
×
291
                                  QtPassSettings::getAutoclearPanelSeconds());
×
292
      m_qtPass->setClipboardTimer();
×
293

294
      updateGitButtonVisibility();
×
295
      updateOtpButtonVisibility();
×
296
      if (QtPassSettings::isUseTrayIcon() && tray == nullptr) {
×
297
        initTrayIcon();
×
298
      } else if (!QtPassSettings::isUseTrayIcon() && tray != nullptr) {
×
299
        destroyTrayIcon();
×
300
      }
301
    }
302

303
    m_qtPass->setFreshStart(false);
×
304
  }
305
}
×
306

307
/**
308
 * @brief MainWindow::onUpdate do a git pull
309
 */
310
void MainWindow::onUpdate(bool block) {
×
311
  ui->statusBar->showMessage(tr("Updating password-store"), 2000);
×
312
  if (block) {
×
313
    QtPassSettings::getPass()->GitPull_b();
×
314
  } else {
315
    QtPassSettings::getPass()->GitPull();
×
316
  }
317
}
×
318

319
/**
320
 * @brief MainWindow::onPush do a git push
321
 */
322
void MainWindow::onPush() {
×
323
  if (QtPassSettings::isUseGit()) {
×
324
    ui->statusBar->showMessage(tr("Updating password-store"), 2000);
×
325
    QtPassSettings::getPass()->GitPush();
×
326
  }
327
}
×
328

329
/**
330
 * @brief MainWindow::getFile get the selected file path
331
 * @param index
332
 * @param forPass returns relative path without '.gpg' extension
333
 * @return path
334
 * @return
335
 */
336
auto MainWindow::getFile(const QModelIndex &index, bool forPass) -> QString {
×
337
  if (!index.isValid() ||
×
338
      !model.fileInfo(proxyModel.mapToSource(index)).isFile()) {
×
339
    return {};
340
  }
341
  QString filePath = model.filePath(proxyModel.mapToSource(index));
×
342
  if (forPass) {
×
343
    filePath = QDir(QtPassSettings::getPassStore()).relativeFilePath(filePath);
×
344
    filePath.replace(Util::endsWithGpg(), "");
×
345
  }
346
  return filePath;
347
}
348

349
/**
350
 * @brief MainWindow::on_treeView_clicked read the selected password file
351
 * @param index
352
 */
353
void MainWindow::on_treeView_clicked(const QModelIndex &index) {
×
354
  bool cleared = ui->treeView->currentIndex().flags() == Qt::NoItemFlags;
×
355
  currentDir =
356
      Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel);
×
357
  // Clear any previously cached clipped text before showing new password
358
  m_qtPass->clearClippedText();
×
359
  QString file = getFile(index, true);
×
360
  ui->passwordName->setText(getFile(index, true));
×
361
  if (!file.isEmpty() && !cleared) {
×
362
    QtPassSettings::getPass()->Show(file);
×
363
  } else {
364
    clearPanel(false);
×
365
    ui->actionEdit->setEnabled(false);
×
366
    ui->actionDelete->setEnabled(true);
×
367
  }
368
}
×
369

370
/**
371
 * @brief MainWindow::on_treeView_doubleClicked when doubleclicked on
372
 * TreeViewItem, open the edit Window
373
 * @param index
374
 */
375
void MainWindow::on_treeView_doubleClicked(const QModelIndex &index) {
×
376
  QFileInfo fileOrFolder =
377
      model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex()));
×
378

379
  if (fileOrFolder.isFile()) {
×
380
    editPassword(getFile(index, true));
×
381
  }
382
}
×
383

384
/**
385
 * @brief MainWindow::deselect clear the selection, password and copy buffer
386
 */
387
void MainWindow::deselect() {
×
388
  currentDir = "";
×
389
  m_qtPass->clearClipboard();
×
390
  ui->treeView->clearSelection();
×
391
  ui->actionEdit->setEnabled(false);
×
392
  ui->actionDelete->setEnabled(false);
×
393
  ui->passwordName->setText("");
×
394
  clearPanel(false);
×
395
}
×
396

397
void MainWindow::executeWrapperStarted() {
×
398
  clearTemplateWidgets();
×
399
  ui->textBrowser->clear();
×
400
  setUiElementsEnabled(false);
×
401
  clearPanelTimer.stop();
×
402
}
×
403

404
void MainWindow::passShowHandler(const QString &p_output) {
×
405
  QStringList templ = QtPassSettings::isUseTemplate()
×
406
                          ? QtPassSettings::getPassTemplate().split("\n")
×
407
                          : QStringList();
×
408
  bool allFields =
409
      QtPassSettings::isUseTemplate() && QtPassSettings::isTemplateAllFields();
×
410
  FileContent fileContent = FileContent::parse(p_output, templ, allFields);
×
411
  QString output = p_output;
412
  QString password = fileContent.getPassword();
×
413

414
  // set clipped text
415
  m_qtPass->setClippedText(password, p_output);
×
416

417
  // first clear the current view:
418
  clearTemplateWidgets();
×
419

420
  // show what is needed:
421
  if (QtPassSettings::isHideContent()) {
×
422
    output = "***" + tr("Content hidden") + "***";
×
423
  } else if (!QtPassSettings::isDisplayAsIs()) {
×
424
    if (!password.isEmpty()) {
×
425
      // set the password, it is hidden if needed in addToGridLayout
426
      addToGridLayout(0, tr("Password"), password);
×
427
    }
428

429
    NamedValues namedValues = fileContent.getNamedValues();
×
430
    for (int j = 0; j < namedValues.length(); ++j) {
×
431
      const NamedValue &nv = namedValues.at(j);
432
      addToGridLayout(j + 1, nv.name, nv.value);
×
433
    }
434
    if (ui->gridLayout->count() == 0) {
×
435
      ui->verticalLayoutPassword->setSpacing(0);
×
436
    } else {
437
      ui->verticalLayoutPassword->setSpacing(6);
×
438
    }
439

440
    output = fileContent.getRemainingDataForDisplay();
×
441
  }
442

443
  if (QtPassSettings::isUseAutoclearPanel()) {
×
444
    clearPanelTimer.start();
×
445
  }
446

447
  emit passShowHandlerFinished(output);
×
448
  setUiElementsEnabled(true);
×
449
}
×
450

451
void MainWindow::passOtpHandler(const QString &p_output) {
×
452
  if (!p_output.isEmpty()) {
×
453
    addToGridLayout(ui->gridLayout->count() + 1, tr("OTP Code"), p_output);
×
454
    m_qtPass->copyTextToClipboard(p_output);
×
455
    showStatusMessage(tr("OTP code copied to clipboard"));
×
456
  } else {
457
    flashText(tr("No OTP code found in this password entry"), true);
×
458
  }
459
  if (QtPassSettings::isUseAutoclearPanel()) {
×
460
    clearPanelTimer.start();
×
461
  }
462
  setUiElementsEnabled(true);
×
463
}
×
464

465
/**
466
 * @brief MainWindow::clearPanel hide the information from shoulder surfers
467
 */
468
void MainWindow::clearPanel(bool notify) {
×
469
  while (ui->gridLayout->count() > 0) {
×
470
    QLayoutItem *item = ui->gridLayout->takeAt(0);
×
471
    delete item->widget();
×
472
    delete item;
×
473
  }
474
  if (notify) {
×
475
    QString output = "***" + tr("Password and Content hidden") + "***";
×
476
    ui->textBrowser->setHtml(output);
×
477
  } else {
478
    ui->textBrowser->setHtml("");
×
479
  }
480
}
×
481

482
/**
483
 * @brief MainWindow::setUiElementsEnabled enable or disable the relevant UI
484
 * elements
485
 * @param state
486
 */
487
void MainWindow::setUiElementsEnabled(bool state) {
×
488
  ui->treeView->setEnabled(state);
×
489
  ui->lineEdit->setEnabled(state);
×
490
  ui->lineEdit->installEventFilter(this);
×
491
  ui->actionAddPassword->setEnabled(state);
×
492
  ui->actionAddFolder->setEnabled(state);
×
493
  ui->actionUsers->setEnabled(state);
×
494
  ui->actionConfig->setEnabled(state);
×
495
  // is a file selected?
496
  state &= ui->treeView->currentIndex().isValid();
×
497
  ui->actionDelete->setEnabled(state);
×
498
  ui->actionEdit->setEnabled(state);
×
499
  updateGitButtonVisibility();
×
500
  updateOtpButtonVisibility();
×
501
}
×
502

503
void MainWindow::restoreWindow() {
×
504
  QByteArray geometry = QtPassSettings::getGeometry(saveGeometry());
×
505
  restoreGeometry(geometry);
×
506
  QByteArray savestate = QtPassSettings::getSavestate(saveState());
×
507
  restoreState(savestate);
×
508
  QPoint position = QtPassSettings::getPos(pos());
×
509
  move(position);
×
510
  QSize newSize = QtPassSettings::getSize(size());
×
511
  resize(newSize);
×
512
  if (QtPassSettings::isMaximized(isMaximized())) {
×
513
    showMaximized();
×
514
  }
515

516
  if (QtPassSettings::isAlwaysOnTop()) {
×
517
    Qt::WindowFlags flags = windowFlags();
518
    setWindowFlags(flags | Qt::WindowStaysOnTopHint);
×
519
    show();
×
520
  }
521

522
  if (QtPassSettings::isUseTrayIcon() && tray == nullptr) {
×
523
    initTrayIcon();
×
524
    if (QtPassSettings::isStartMinimized()) {
×
525
      // since we are still in constructor, can't directly hide
526
      QTimer::singleShot(10, this, SLOT(hide()));
×
527
    }
528
  } else if (!QtPassSettings::isUseTrayIcon() && tray != nullptr) {
×
529
    destroyTrayIcon();
×
530
  }
531
}
×
532

533
/**
534
 * @brief MainWindow::on_configButton_clicked run Mainwindow::config
535
 */
536
void MainWindow::onConfig() { config(); }
×
537

538
/**
539
 * @brief Executes when the string in the search box changes, collapses the
540
 * TreeView
541
 * @param arg1
542
 */
543
void MainWindow::on_lineEdit_textChanged(const QString &arg1) {
×
544
  ui->statusBar->showMessage(tr("Looking for: %1").arg(arg1), 1000);
×
545
  ui->treeView->expandAll();
×
546
  clearPanel(false);
×
547
  ui->passwordName->setText("");
×
548
  ui->actionEdit->setEnabled(false);
×
549
  ui->actionDelete->setEnabled(false);
×
550
  searchTimer.start();
×
551
}
×
552

553
/**
554
 * @brief MainWindow::onTimeoutSearch Fired when search is finished or too much
555
 * time from two keypresses is elapsed
556
 */
557
void MainWindow::onTimeoutSearch() {
×
558
  QString query = ui->lineEdit->text();
×
559

560
  if (query.isEmpty()) {
×
561
    ui->treeView->collapseAll();
×
562
    deselect();
×
563
  }
564

565
  query.replace(QStringLiteral(" "), ".*");
×
566
  QRegularExpression regExp(query, QRegularExpression::CaseInsensitiveOption);
×
567
  proxyModel.setFilterRegularExpression(regExp);
×
568
  ui->treeView->setRootIndex(proxyModel.mapFromSource(
×
569
      model.setRootPath(QtPassSettings::getPassStore())));
×
570

571
  if (proxyModel.rowCount() > 0 && !query.isEmpty()) {
×
572
    selectFirstFile();
×
573
  } else {
574
    ui->actionEdit->setEnabled(false);
×
575
    ui->actionDelete->setEnabled(false);
×
576
  }
577
}
×
578

579
/**
580
 * @brief MainWindow::on_lineEdit_returnPressed get searching
581
 *
582
 * Select the first possible file in the tree
583
 */
584
void MainWindow::on_lineEdit_returnPressed() {
×
585
#ifdef QT_DEBUG
586
  dbg() << "on_lineEdit_returnPressed" << proxyModel.rowCount();
587
#endif
588

589
  if (proxyModel.rowCount() > 0) {
×
590
    selectFirstFile();
×
591
    on_treeView_clicked(ui->treeView->currentIndex());
×
592
  }
593
}
×
594

595
/**
596
 * @brief MainWindow::selectFirstFile select the first possible file in the
597
 * tree
598
 */
599
void MainWindow::selectFirstFile() {
×
600
  QModelIndex index = proxyModel.mapFromSource(
×
601
      model.setRootPath(QtPassSettings::getPassStore()));
×
602
  index = firstFile(index);
×
603
  ui->treeView->setCurrentIndex(index);
×
604
}
×
605

606
/**
607
 * @brief MainWindow::firstFile return location of first possible file
608
 * @param parentIndex
609
 * @return QModelIndex
610
 */
611
auto MainWindow::firstFile(QModelIndex parentIndex) -> QModelIndex {
×
612
  QModelIndex index = parentIndex;
×
613
  int numRows = proxyModel.rowCount(parentIndex);
×
614
  for (int row = 0; row < numRows; ++row) {
×
615
    index = proxyModel.index(row, 0, parentIndex);
×
616
    if (model.fileInfo(proxyModel.mapToSource(index)).isFile()) {
×
617
      return index;
×
618
    }
619
    if (proxyModel.hasChildren(index)) {
×
620
      return firstFile(index);
×
621
    }
622
  }
623
  return index;
×
624
}
625

626
/**
627
 * @brief MainWindow::setPassword open passworddialog
628
 * @param file which pgp file
629
 * @param isNew insert (not update)
630
 */
631
void MainWindow::setPassword(const QString &file, bool isNew) {
×
632
  PasswordDialog d(file, isNew, this);
×
633

634
  if (!d.exec()) {
×
635
    ui->treeView->setFocus();
×
636
  }
637
}
×
638

639
/**
640
 * @brief MainWindow::addPassword add a new password by showing a
641
 * number of dialogs.
642
 */
643
void MainWindow::addPassword() {
×
644
  bool ok;
645
  QString dir =
646
      Util::getDir(ui->treeView->currentIndex(), true, model, proxyModel);
×
647
  QString file =
648
      QInputDialog::getText(this, tr("New file"),
×
649
                            tr("New password file: \n(Will be placed in %1 )")
×
650
                                .arg(QtPassSettings::getPassStore() +
×
651
                                     Util::getDir(ui->treeView->currentIndex(),
×
652
                                                  true, model, proxyModel)),
653
                            QLineEdit::Normal, "", &ok);
×
654
  if (!ok || file.isEmpty()) {
×
655
    return;
656
  }
657
  file = dir + file;
×
658
  setPassword(file);
×
659
}
660

661
/**
662
 * @brief MainWindow::onDelete remove password, if you are
663
 * sure.
664
 */
665
void MainWindow::onDelete() {
×
666
  QModelIndex currentIndex = ui->treeView->currentIndex();
×
667
  if (!currentIndex.isValid()) {
668
    // This fixes https://github.com/IJHack/QtPass/issues/556
669
    // Otherwise the entire password directory would be deleted if
670
    // nothing is selected in the tree view.
671
    return;
×
672
  }
673

674
  QFileInfo fileOrFolder =
675
      model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex()));
×
676
  QString file = "";
×
677
  bool isDir = false;
678

679
  if (fileOrFolder.isFile()) {
×
680
    file = getFile(ui->treeView->currentIndex(), true);
×
681
  } else {
682
    file = Util::getDir(ui->treeView->currentIndex(), true, model, proxyModel);
×
683
    isDir = true;
684
  }
685

686
  QString dirMessage = tr(" and the whole content?");
687
  if (isDir) {
×
688
    QDirIterator it(model.rootPath() + QDir::separator() + file,
×
689
                    QDirIterator::Subdirectories);
×
690
    bool okDir = true;
691
    while (it.hasNext() && okDir) {
×
692
      it.next();
×
693
      if (QFileInfo(it.filePath()).isFile()) {
×
694
        if (QFileInfo(it.filePath()).suffix() != "gpg") {
×
695
          okDir = false;
696
          dirMessage = tr(" and the whole content? <br><strong>Attention: "
×
697
                          "there are unexpected files in the given folder, "
698
                          "check them before continue.</strong>");
699
        }
700
      }
701
    }
702
  }
×
703

704
  if (QMessageBox::question(
×
705
          this, isDir ? tr("Delete folder?") : tr("Delete password?"),
×
706
          tr("Are you sure you want to delete %1%2?")
×
707
              .arg(QDir::separator() + file, isDir ? dirMessage : "?"),
×
708
          QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
709
    return;
710
  }
711

712
  QtPassSettings::getPass()->Remove(file, isDir);
×
713
}
×
714

715
/**
716
 * @brief MainWindow::onOTP try and generate (selected) OTP code.
717
 */
718
void MainWindow::onOtp() {
×
719
  QString file = getFile(ui->treeView->currentIndex(), true);
×
720
  if (!file.isEmpty()) {
×
721
    if (QtPassSettings::isUseOtp()) {
×
722
      setUiElementsEnabled(false);
×
723
      QtPassSettings::getPass()->OtpGenerate(file);
×
724
    }
725
  } else {
726
    flashText(tr("No password selected for OTP generation"), true);
×
727
  }
728
}
×
729

730
/**
731
 * @brief MainWindow::onEdit try and edit (selected) password.
732
 */
733
void MainWindow::onEdit() {
×
734
  QString file = getFile(ui->treeView->currentIndex(), true);
×
735
  editPassword(file);
×
736
}
×
737

738
/**
739
 * @brief MainWindow::userDialog see MainWindow::onUsers()
740
 * @param dir folder to edit users for.
741
 */
742
void MainWindow::userDialog(const QString &dir) {
×
743
  if (!dir.isEmpty()) {
×
744
    currentDir = dir;
×
745
  }
746
  onUsers();
×
747
}
×
748

749
/**
750
 * @brief MainWindow::onUsers edit users for the current
751
 * folder,
752
 * gets lists and opens UserDialog.
753
 */
754
void MainWindow::onUsers() {
×
755
  QString dir =
756
      currentDir.isEmpty()
757
          ? Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel)
×
758
          : currentDir;
×
759

760
  UsersDialog d(dir, this);
×
761
  if (!d.exec()) {
×
762
    ui->treeView->setFocus();
×
763
  }
764
}
×
765

766
/**
767
 * @brief MainWindow::messageAvailable we have some text/message/search to do.
768
 * @param message
769
 */
770
void MainWindow::messageAvailable(const QString &message) {
×
771
  if (message.isEmpty()) {
×
772
    focusInput();
×
773
  } else {
774
    ui->treeView->expandAll();
×
775
    ui->lineEdit->setText(message);
×
776
    on_lineEdit_returnPressed();
×
777
  }
778
  show();
×
779
  raise();
×
780
}
×
781

782
/**
783
 * @brief MainWindow::generateKeyPair internal gpg keypair generator . .
784
 * @param batch
785
 * @param keygenWindow
786
 */
787
void MainWindow::generateKeyPair(const QString &batch, QDialog *keygenWindow) {
×
788
  keygen = keygenWindow;
×
789
  emit generateGPGKeyPair(batch);
×
790
}
×
791

792
/**
793
 * @brief MainWindow::updateProfileBox update the list of profiles, optionally
794
 * select a more appropriate one to view too
795
 */
796
void MainWindow::updateProfileBox() {
×
797
  QHash<QString, QHash<QString, QString>> profiles =
798
      QtPassSettings::getProfiles();
×
799

800
  if (profiles.isEmpty()) {
801
    ui->profileWidget->hide();
×
802
  } else {
803
    ui->profileWidget->show();
×
804
    ui->profileBox->setEnabled(profiles.size() > 1);
×
805
    ui->profileBox->clear();
×
806
    QHashIterator<QString, QHash<QString, QString>> i(profiles);
×
807
    while (i.hasNext()) {
×
808
      i.next();
809
      if (!i.key().isEmpty()) {
×
810
        ui->profileBox->addItem(i.key());
×
811
      }
812
    }
813
    ui->profileBox->model()->sort(0);
×
814
  }
815
  int index = ui->profileBox->findText(QtPassSettings::getProfile());
×
816
  if (index != -1) { //  -1 for not found
×
817
    ui->profileBox->setCurrentIndex(index);
×
818
  }
819
}
×
820

821
/**
822
 * @brief MainWindow::on_profileBox_currentIndexChanged make sure we show the
823
 * correct "profile"
824
 * @param name
825
 */
826
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
827
void MainWindow::on_profileBox_currentIndexChanged(QString name) {
828
#else
829
void MainWindow::on_profileBox_currentTextChanged(const QString &name) {
×
830
#endif
831
  if (m_qtPass->isFreshStart() || name == QtPassSettings::getProfile()) {
×
832
    return;
833
  }
834

835
  ui->lineEdit->clear();
×
836

837
  QtPassSettings::setProfile(name);
×
838

839
  QtPassSettings::setPassStore(
×
840
      QtPassSettings::getProfiles().value(name).value("path"));
×
841
  QtPassSettings::setPassSigningKey(
×
842
      QtPassSettings::getProfiles().value(name).value("signingKey"));
×
843
  ui->statusBar->showMessage(tr("Profile changed to %1").arg(name), 2000);
×
844

845
  QtPassSettings::getPass()->updateEnv();
×
846

847
  ui->treeView->selectionModel()->clear();
×
848
  ui->treeView->setRootIndex(proxyModel.mapFromSource(
×
849
      model.setRootPath(QtPassSettings::getPassStore())));
×
850

851
  ui->actionEdit->setEnabled(false);
×
852
  ui->actionDelete->setEnabled(false);
×
853
}
854

855
/**
856
 * @brief MainWindow::initTrayIcon show a nice tray icon on systems that
857
 * support
858
 * it
859
 */
860
void MainWindow::initTrayIcon() {
×
861
  this->tray = new TrayIcon(this);
×
862
  // Setup tray icon
863

864
  if (tray == nullptr) {
865
#ifdef QT_DEBUG
866
    dbg() << "Allocating tray icon failed.";
867
#endif
868
  }
869

870
  if (!tray->getIsAllocated()) {
×
871
    destroyTrayIcon();
×
872
  }
873
}
×
874

875
/**
876
 * @brief MainWindow::destroyTrayIcon remove that pesky tray icon
877
 */
878
void MainWindow::destroyTrayIcon() {
×
879
  delete this->tray;
×
880
  tray = nullptr;
×
881
}
×
882

883
/**
884
 * @brief MainWindow::closeEvent hide or quit
885
 * @param event
886
 */
887
void MainWindow::closeEvent(QCloseEvent *event) {
×
888
  if (QtPassSettings::isHideOnClose()) {
×
889
    this->hide();
×
890
    event->ignore();
891
  } else {
892
    m_qtPass->clearClipboard();
×
893

894
    QtPassSettings::setGeometry(saveGeometry());
×
895
    QtPassSettings::setSavestate(saveState());
×
896
    QtPassSettings::setMaximized(isMaximized());
×
897
    if (!isMaximized()) {
×
898
      QtPassSettings::setPos(pos());
×
899
      QtPassSettings::setSize(size());
×
900
    }
901
    event->accept();
902
  }
903
}
×
904

905
/**
906
 * @brief MainWindow::eventFilter filter out some events and focus the
907
 * treeview
908
 * @param obj
909
 * @param event
910
 * @return
911
 */
912
auto MainWindow::eventFilter(QObject *obj, QEvent *event) -> bool {
×
913
  if (obj == ui->lineEdit && event->type() == QEvent::KeyPress) {
×
914
    auto *key = dynamic_cast<QKeyEvent *>(event);
×
915
    if (key != nullptr && key->key() == Qt::Key_Down) {
×
916
      ui->treeView->setFocus();
×
917
    }
918
  }
919
  return QObject::eventFilter(obj, event);
×
920
}
921

922
/**
923
 * @brief MainWindow::keyPressEvent did anyone press return, enter or escape?
924
 * @param event
925
 */
926
void MainWindow::keyPressEvent(QKeyEvent *event) {
×
927
  switch (event->key()) {
×
928
  case Qt::Key_Delete:
×
929
    onDelete();
×
930
    break;
×
931
  case Qt::Key_Return:
×
932
  case Qt::Key_Enter:
933
    if (proxyModel.rowCount() > 0) {
×
934
      on_treeView_clicked(ui->treeView->currentIndex());
×
935
    }
936
    break;
937
  case Qt::Key_Escape:
×
938
    ui->lineEdit->clear();
×
939
    break;
×
940
  default:
941
    break;
942
  }
943
}
×
944

945
/**
946
 * @brief MainWindow::showContextMenu show us the (file or folder) context
947
 * menu
948
 * @param pos
949
 */
950
void MainWindow::showContextMenu(const QPoint &pos) {
×
951
  QModelIndex index = ui->treeView->indexAt(pos);
×
952
  bool selected = true;
953
  if (!index.isValid()) {
954
    ui->treeView->clearSelection();
×
955
    ui->actionDelete->setEnabled(false);
×
956
    ui->actionEdit->setEnabled(false);
×
957
    currentDir = "";
×
958
    selected = false;
959
  }
960

961
  ui->treeView->setCurrentIndex(index);
×
962

963
  QPoint globalPos = ui->treeView->viewport()->mapToGlobal(pos);
×
964

965
  QFileInfo fileOrFolder =
966
      model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex()));
×
967

968
  QMenu contextMenu;
×
969
  if (!selected || fileOrFolder.isDir()) {
×
970
    QAction *openFolder =
971
        contextMenu.addAction(tr("Open folder with file manager"));
×
972
    QAction *addFolder = contextMenu.addAction(tr("Add folder"));
×
973
    QAction *addPassword = contextMenu.addAction(tr("Add password"));
×
974
    QAction *users = contextMenu.addAction(tr("Users"));
×
975
    connect(openFolder, &QAction::triggered, this, &MainWindow::openFolder);
×
976
    connect(addFolder, &QAction::triggered, this, &MainWindow::addFolder);
×
977
    connect(addPassword, &QAction::triggered, this, &MainWindow::addPassword);
×
978
    connect(users, &QAction::triggered, this, &MainWindow::onUsers);
×
979
  } else if (fileOrFolder.isFile()) {
×
980
    QAction *edit = contextMenu.addAction(tr("Edit"));
×
981
    connect(edit, &QAction::triggered, this, &MainWindow::onEdit);
×
982
  }
983
  if (selected) {
×
984
    // if (useClipboard != CLIPBOARD_NEVER) {
985
    // contextMenu.addSeparator();
986
    // QAction* copyItem = contextMenu.addAction(tr("Copy Password"));
987
    // if (getClippedPassword().length() == 0) copyItem->setEnabled(false);
988
    // connect(copyItem, SIGNAL(triggered()), this,
989
    // SLOT(copyPasswordToClipboard()));
990
    // }
991
    contextMenu.addSeparator();
×
992
    if (fileOrFolder.isDir()) {
×
993
      QAction *renameFolder = contextMenu.addAction(tr("Rename folder"));
×
994
      connect(renameFolder, &QAction::triggered, this,
×
995
              &MainWindow::renameFolder);
×
996
    } else if (fileOrFolder.isFile()) {
×
997
      QAction *renamePassword = contextMenu.addAction(tr("Rename password"));
×
998
      connect(renamePassword, &QAction::triggered, this,
×
999
              &MainWindow::renamePassword);
×
1000
    }
1001
    QAction *deleteItem = contextMenu.addAction(tr("Delete"));
×
1002
    connect(deleteItem, &QAction::triggered, this, &MainWindow::onDelete);
×
1003
  }
1004
  contextMenu.exec(globalPos);
×
1005
}
×
1006

1007
/**
1008
 * @brief MainWindow::showBrowserContextMenu show us the context menu in
1009
 * password window
1010
 * @param pos
1011
 */
1012
void MainWindow::showBrowserContextMenu(const QPoint &pos) {
×
1013
  QMenu *contextMenu = ui->textBrowser->createStandardContextMenu(pos);
×
1014
  QPoint globalPos = ui->textBrowser->viewport()->mapToGlobal(pos);
×
1015

1016
  contextMenu->exec(globalPos);
×
1017
  delete contextMenu;
×
1018
}
×
1019

1020
/**
1021
 * @brief MainWindow::openFolder open the folder in the default file manager
1022
 */
1023
void MainWindow::openFolder() {
×
1024
  QString dir =
1025
      Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel);
×
1026

1027
  QString path = QDir::toNativeSeparators(dir);
×
1028
  QDesktopServices::openUrl(QUrl::fromLocalFile(path));
×
1029
}
×
1030

1031
/**
1032
 * @brief MainWindow::addFolder add a new folder to store passwords in
1033
 */
1034
void MainWindow::addFolder() {
×
1035
  bool ok;
1036
  QString dir =
1037
      Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel);
×
1038
  QString newdir =
1039
      QInputDialog::getText(this, tr("New file"),
×
1040
                            tr("New Folder: \n(Will be placed in %1 )")
×
1041
                                .arg(QtPassSettings::getPassStore() +
×
1042
                                     Util::getDir(ui->treeView->currentIndex(),
×
1043
                                                  true, model, proxyModel)),
1044
                            QLineEdit::Normal, "", &ok);
×
1045
  if (!ok || newdir.isEmpty()) {
×
1046
    return;
1047
  }
1048
  newdir.prepend(dir);
1049
  // dbg()<< newdir;
1050
  if (!QDir().mkdir(newdir)) {
×
1051
    QMessageBox::warning(this, tr("Error"),
×
1052
                         tr("Failed to create folder: %1").arg(newdir));
×
1053
    return;
×
1054
  }
1055
  if (QtPassSettings::isAddGPGId(true)) {
×
1056
    QString gpgIdFile = newdir + "/.gpg-id";
×
1057
    QFile gpgId(gpgIdFile);
×
1058
    if (!gpgId.open(QIODevice::WriteOnly)) {
×
1059
      QMessageBox::warning(
×
1060
          this, tr("Error"),
×
1061
          tr("Failed to create .gpg-id file in: %1").arg(newdir));
×
1062
      return;
1063
    }
1064
    QList<UserInfo> users = QtPassSettings::getPass()->listKeys("", true);
×
1065
    for (const UserInfo &user : users) {
×
1066
      if (user.enabled) {
×
1067
        gpgId.write((user.key_id + "\n").toUtf8());
×
1068
      }
1069
    }
1070
    gpgId.close();
×
1071
  }
×
1072
}
1073

1074
/**
1075
 * @brief MainWindow::renameFolder rename an existing folder
1076
 */
1077
void MainWindow::renameFolder() {
×
1078
  bool ok;
1079
  QString srcDir = QDir::cleanPath(
1080
      Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel));
×
1081
  QString srcDirName = QDir(srcDir).dirName();
×
1082
  QString newName =
1083
      QInputDialog::getText(this, tr("Rename file"), tr("Rename Folder To: "),
×
1084
                            QLineEdit::Normal, srcDirName, &ok);
×
1085
  if (!ok || newName.isEmpty()) {
×
1086
    return;
1087
  }
1088
  QString destDir = srcDir;
1089
  destDir.replace(srcDir.lastIndexOf(srcDirName), srcDirName.length(), newName);
×
1090
  QtPassSettings::getPass()->Move(srcDir, destDir);
×
1091
}
1092

1093
/**
1094
 * @brief MainWindow::editPassword read password and open edit window via
1095
 * MainWindow::onEdit()
1096
 */
1097
void MainWindow::editPassword(const QString &file) {
×
1098
  if (!file.isEmpty()) {
×
1099
    if (QtPassSettings::isUseGit() && QtPassSettings::isAutoPull()) {
×
1100
      onUpdate(true);
×
1101
    }
1102
    setPassword(file, false);
×
1103
  }
1104
}
×
1105

1106
/**
1107
 * @brief MainWindow::renamePassword rename an existing password
1108
 */
1109
void MainWindow::renamePassword() {
×
1110
  bool ok;
1111
  QString file = getFile(ui->treeView->currentIndex(), false);
×
1112
  QString filePath = QFileInfo(file).path();
×
1113
  QString fileName = QFileInfo(file).fileName();
×
1114
  if (fileName.endsWith(".gpg", Qt::CaseInsensitive)) {
×
1115
    fileName.chop(4);
×
1116
  }
1117

1118
  QString newName =
1119
      QInputDialog::getText(this, tr("Rename file"), tr("Rename File To: "),
×
1120
                            QLineEdit::Normal, fileName, &ok);
×
1121
  if (!ok || newName.isEmpty()) {
×
1122
    return;
1123
  }
1124
  QString newFile = QDir(filePath).filePath(newName);
×
1125
  QtPassSettings::getPass()->Move(file, newFile);
×
1126
}
1127

1128
/**
1129
 * @brief MainWindow::clearTemplateWidgets empty the template widget fields in
1130
 * the UI
1131
 */
1132
void MainWindow::clearTemplateWidgets() {
×
1133
  while (ui->gridLayout->count() > 0) {
×
1134
    QLayoutItem *item = ui->gridLayout->takeAt(0);
×
1135
    delete item->widget();
×
1136
    delete item;
×
1137
  }
1138
  ui->verticalLayoutPassword->setSpacing(0);
×
1139
}
×
1140

1141
void MainWindow::copyPasswordFromTreeview() {
×
1142
  QFileInfo fileOrFolder =
1143
      model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex()));
×
1144

1145
  if (fileOrFolder.isFile()) {
×
1146
    QString file = getFile(ui->treeView->currentIndex(), true);
×
1147
    // Disconnect any previous connection to avoid accumulation
NEW
1148
    disconnect(QtPassSettings::getPass(), &Pass::finishedShow, this,
×
1149
               &MainWindow::passwordFromFileToClipboard);
1150
    connect(QtPassSettings::getPass(), &Pass::finishedShow, this,
×
1151
            &MainWindow::passwordFromFileToClipboard);
×
1152
    QtPassSettings::getPass()->Show(file);
×
1153
  }
1154
}
×
1155

1156
void MainWindow::passwordFromFileToClipboard(const QString &text) {
×
1157
  QStringList tokens = text.split('\n');
×
1158
  m_qtPass->copyTextToClipboard(tokens[0]);
×
1159
}
×
1160

1161
/**
1162
 * @brief MainWindow::addToGridLayout add a field to the template grid
1163
 * @param position
1164
 * @param field
1165
 * @param value
1166
 */
1167
void MainWindow::addToGridLayout(int position, const QString &field,
×
1168
                                 const QString &value) {
1169
  QString trimmedField = field.trimmed();
1170
  QString trimmedValue = value.trimmed();
1171

1172
  // Combine the Copy button and the line edit in one widget
1173
  auto *frame = new QFrame();
×
1174
  QLayout *ly = new QHBoxLayout();
×
1175
  ly->setContentsMargins(5, 2, 2, 2);
×
1176
  ly->setSpacing(0);
×
1177
  frame->setLayout(ly);
×
1178
  if (QtPassSettings::getClipBoardType() != Enums::CLIPBOARD_NEVER) {
×
1179
    auto *fieldLabel = new QPushButtonWithClipboard(trimmedValue, this);
×
1180
    connect(fieldLabel, &QPushButtonWithClipboard::clicked, m_qtPass,
×
1181
            &QtPass::copyTextToClipboard);
×
1182

1183
    fieldLabel->setStyleSheet(
×
1184
        "border-style: none ; background: transparent; padding: 0; margin: 0;");
1185
    frame->layout()->addWidget(fieldLabel);
×
1186
  }
1187

1188
  if (QtPassSettings::isUseQrencode()) {
×
1189
    auto *qrbutton = new QPushButtonAsQRCode(trimmedValue, this);
×
1190
    connect(qrbutton, &QPushButtonAsQRCode::clicked, m_qtPass,
×
1191
            &QtPass::showTextAsQRCode);
×
1192
    qrbutton->setStyleSheet(
×
1193
        "border-style: none ; background: transparent; padding: 0; margin: 0;");
1194
    frame->layout()->addWidget(qrbutton);
×
1195
  }
1196

1197
  // set the echo mode to password, if the field is "password"
1198
  const QString lineStyle =
1199
      QtPassSettings::isUseMonospace()
×
1200
          ? "border-style: none; background: transparent; font-family: "
1201
            "monospace;"
1202
          : "border-style: none; background: transparent;";
×
1203

1204
  if (QtPassSettings::isHidePassword() && trimmedField == tr("Password")) {
×
1205
    auto *line = new QLineEdit();
×
1206
    line->setObjectName(trimmedField);
×
1207
    line->setText(trimmedValue);
×
1208
    line->setReadOnly(true);
×
1209
    line->setStyleSheet(lineStyle);
×
1210
    line->setContentsMargins(0, 0, 0, 0);
×
1211
    line->setEchoMode(QLineEdit::Password);
×
1212
    auto *showButton = new QPushButtonShowPassword(line, this);
×
1213
    showButton->setStyleSheet(
×
1214
        "border-style: none ; background: transparent; padding: 0; margin: 0;");
1215
    showButton->setContentsMargins(0, 0, 0, 0);
×
1216
    frame->layout()->addWidget(showButton);
×
1217
    frame->layout()->addWidget(line);
×
1218
  } else {
1219
    auto *line = new QTextBrowser();
×
1220
    line->setOpenExternalLinks(true);
×
1221
    line->setOpenLinks(true);
×
1222
    line->setMaximumHeight(26);
×
1223
    line->setMinimumHeight(26);
×
1224
    line->setSizePolicy(
×
1225
        QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
1226
    line->setObjectName(trimmedField);
×
1227
    trimmedValue.replace(Util::protocolRegex(), R"(<a href="\1">\1</a>)");
×
1228
    line->setText(trimmedValue);
×
1229
    line->setReadOnly(true);
×
1230
    line->setStyleSheet(lineStyle);
×
1231
    line->setContentsMargins(0, 0, 0, 0);
×
1232
    frame->layout()->addWidget(line);
×
1233
  }
1234

1235
  frame->setStyleSheet(
×
1236
      ".QFrame{border: 1px solid lightgrey; border-radius: 5px;}");
1237

1238
  // set into the layout
1239
  ui->gridLayout->addWidget(new QLabel(trimmedField), position, 0);
×
1240
  ui->gridLayout->addWidget(frame, position, 1);
×
1241
}
×
1242

1243
/**
1244
 * @brief Displays message in status bar
1245
 *
1246
 * @param msg     text to be displayed
1247
 * @param timeout time for which msg shall be visible
1248
 */
1249
void MainWindow::showStatusMessage(const QString &msg, int timeout) {
×
1250
  ui->statusBar->showMessage(msg, timeout);
×
1251
}
×
1252

1253
/**
1254
 * @brief MainWindow::startReencryptPath disable ui elements and treeview
1255
 */
1256
void MainWindow::startReencryptPath() {
×
1257
  setUiElementsEnabled(false);
×
1258
  ui->treeView->setDisabled(true);
×
1259
}
×
1260

1261
/**
1262
 * @brief MainWindow::endReencryptPath re-enable ui elements
1263
 */
1264
void MainWindow::endReencryptPath() { setUiElementsEnabled(true); }
×
1265

1266
void MainWindow::updateGitButtonVisibility() {
×
1267
  if (!QtPassSettings::isUseGit() ||
×
1268
      (QtPassSettings::getGitExecutable().isEmpty() &&
×
1269
       QtPassSettings::getPassExecutable().isEmpty())) {
×
1270
    enableGitButtons(false);
×
1271
  } else {
1272
    enableGitButtons(true);
×
1273
  }
1274
}
×
1275

1276
void MainWindow::updateOtpButtonVisibility() {
×
1277
#if defined(Q_OS_WIN) || defined(__APPLE__)
1278
  ui->actionOtp->setVisible(false);
1279
#endif
1280
  if (!QtPassSettings::isUseOtp()) {
×
1281
    ui->actionOtp->setEnabled(false);
×
1282
  } else {
1283
    ui->actionOtp->setEnabled(true);
×
1284
  }
1285
}
×
1286

1287
void MainWindow::enableGitButtons(const bool &state) {
×
1288
  // Following GNOME guidelines is preferable disable buttons instead of hide
1289
  ui->actionPush->setEnabled(state);
×
1290
  ui->actionUpdate->setEnabled(state);
×
1291
}
×
1292

1293
/**
1294
 * @brief MainWindow::critical critical message popup wrapper.
1295
 * @param title
1296
 * @param msg
1297
 */
1298
void MainWindow::critical(const QString &title, const QString &msg) {
×
1299
  QMessageBox::critical(this, title, msg);
×
1300
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc