MCPcopy Create free account
hub / github.com/IJHack/QtPass / MainWindow

Method MainWindow

src/mainwindow.cpp:42–136  ·  view source on GitHub ↗

* @brief MainWindow::MainWindow handles all of the main functionality and also * the main window. * @param searchText for searching from cli * @param parent pointer */

Source from the content-addressed store, hash-verified

40 * @param parent pointer
41 */
42MainWindow::MainWindow(const QString &searchText, QWidget *parent)
43 : QMainWindow(parent), ui(new Ui::MainWindow), keygen(nullptr),
44 tray(nullptr) {
45#ifdef __APPLE__
46 // extra treatment for mac os
47 // see http://doc.qt.io/qt-5/qkeysequence.html#qt_set_sequence_auto_mnemonic
48 qt_set_sequence_auto_mnemonic(true);
49#endif
50 ui->setupUi(this);
51
52 m_qtPass = new QtPass(this);
53
54 // register shortcut ctrl/cmd + Q to close the main window
55 new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this, SLOT(close()));
56 // register shortcut ctrl/cmd + C to copy the currently selected password
57 new QShortcut(QKeySequence(QKeySequence::StandardKey::Copy), this,
58 SLOT(copyPasswordFromTreeview()));
59
60 model.setNameFilters(QStringList() << "*.gpg");
61 model.setNameFilterDisables(false);
62
63 /*
64 * I added this to solve Windows bug but now on GNU/Linux the main folder,
65 * if hidden, disappear
66 *
67 * model.setFilter(QDir::NoDot);
68 */
69
70 QString passStore = QtPassSettings::getPassStore(Util::findPasswordStore());
71
72 QModelIndex rootDir = model.setRootPath(passStore);
73 model.fetchMore(rootDir);
74
75 proxyModel.setModelAndStore(&model, passStore);
76 selectionModel.reset(new QItemSelectionModel(&proxyModel));
77
78 ui->treeView->setModel(&proxyModel);
79 ui->treeView->setRootIndex(proxyModel.mapFromSource(rootDir));
80 ui->treeView->setColumnHidden(1, true);
81 ui->treeView->setColumnHidden(2, true);
82 ui->treeView->setColumnHidden(3, true);
83 ui->treeView->setHeaderHidden(true);
84 ui->treeView->setIndentation(15);
85 ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
86 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
87 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
88 ui->treeView->sortByColumn(0, Qt::AscendingOrder);
89 connect(ui->treeView, &QWidget::customContextMenuRequested, this,
90 &MainWindow::showContextMenu);
91 connect(ui->treeView, &DeselectableTreeView::emptyClicked, this,
92 &MainWindow::deselect);
93
94 if (QtPassSettings::isUseMonospace()) {
95 QFont monospace("Monospace");
96 monospace.setStyleHint(QFont::Monospace);
97 ui->textBrowser->setFont(monospace);
98 }
99 if (QtPassSettings::isNoLineWrapping()) {

Callers

nothing calls this directly

Calls 3

updateEnvMethod · 0.80
setModelAndStoreMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected