keepassxc/src/gui/DatabaseWidget.cpp

683 lines
21 KiB
C++
Raw Normal View History

2010-08-24 16:26:52 -04:00
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DatabaseWidget.h"
#include "ui_SearchWidget.h"
2010-08-24 16:26:52 -04:00
#include <QtCore/QTimer>
#include <QtGui/QAction>
2010-08-24 16:26:52 -04:00
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
2012-05-12 07:22:41 -04:00
#include <QtGui/QLineEdit>
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
#include <QtGui/QSplitter>
2010-08-24 16:26:52 -04:00
#include "core/DataPath.h"
#include "core/Metadata.h"
#include "core/Tools.h"
#include "gui/ChangeMasterKeyWidget.h"
#include "gui/Clipboard.h"
#include "gui/DatabaseOpenWidget.h"
#include "gui/DatabaseSettingsWidget.h"
#include "gui/KeePass1OpenWidget.h"
#include "gui/entry/EditEntryWidget.h"
#include "gui/entry/EntryView.h"
#include "gui/group/EditGroupWidget.h"
#include "gui/group/GroupView.h"
2010-08-24 16:26:52 -04:00
DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
2010-10-06 13:40:50 -04:00
: QStackedWidget(parent)
, m_db(db)
, m_searchUi(new Ui::SearchWidget())
, m_searchWidget(new QWidget())
2012-06-29 08:15:16 -04:00
, m_newGroup(Q_NULLPTR)
, m_newEntry(Q_NULLPTR)
, m_newParent(Q_NULLPTR)
, m_menuGroup(new QMenu(this))
, m_menuEntry(new QMenu(this))
2010-08-24 16:26:52 -04:00
{
m_searchUi->setupUi(m_searchWidget);
m_searchTimer = new QTimer(this);
m_searchTimer->setSingleShot(true);
2010-10-06 13:40:50 -04:00
m_mainWidget = new QWidget(this);
QLayout* layout = new QHBoxLayout(m_mainWidget);
QSplitter* splitter = new QSplitter(m_mainWidget);
QWidget* rightHandSideWidget = new QWidget(splitter);
m_searchWidget->setParent(rightHandSideWidget);
m_groupView = new GroupView(db, splitter);
m_groupView->setObjectName("groupView");
m_groupView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_groupView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showGroupContextMenu(QPoint)));
m_entryView = new EntryView(rightHandSideWidget);
m_entryView->setObjectName("entryView");
m_entryView->setContextMenuPolicy(Qt::CustomContextMenu);
m_entryView->setGroup(db->rootGroup());
connect(m_entryView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showEntryContextMenu(QPoint)));
2010-08-24 16:26:52 -04:00
2010-08-25 04:46:26 -04:00
QSizePolicy policy;
policy = m_groupView->sizePolicy();
policy.setHorizontalStretch(30);
m_groupView->setSizePolicy(policy);
2012-05-16 03:56:18 -04:00
policy = rightHandSideWidget->sizePolicy();
2010-08-25 04:46:26 -04:00
policy.setHorizontalStretch(70);
2012-05-16 03:56:18 -04:00
rightHandSideWidget->setSizePolicy(policy);
2012-05-12 07:22:41 -04:00
QAction* closeAction = new QAction(m_searchWidget);
QIcon closeIcon = dataPath()->icon("actions", "dialog-close");
closeAction->setIcon(closeIcon);
m_searchUi->closeSearchButton->setDefaultAction(closeAction);
m_searchWidget->hide();
2012-05-27 08:52:19 -04:00
m_searchUi->caseSensitiveCheckBox->setVisible(false);
2012-05-16 03:56:18 -04:00
QVBoxLayout* vLayout = new QVBoxLayout(rightHandSideWidget);
2012-05-27 05:24:56 -04:00
vLayout->setMargin(0);
vLayout->addWidget(m_searchWidget);
2012-05-12 07:22:41 -04:00
vLayout->addWidget(m_entryView);
2012-05-16 03:56:18 -04:00
rightHandSideWidget->setLayout(vLayout);
splitter->addWidget(m_groupView);
splitter->addWidget(rightHandSideWidget);
layout->addWidget(splitter);
2010-10-06 13:40:50 -04:00
m_mainWidget->setLayout(layout);
m_editEntryWidget = new EditEntryWidget();
m_editEntryWidget->setObjectName("editEntryWidget");
2012-05-15 14:12:05 -04:00
m_historyEditEntryWidget = new EditEntryWidget();
m_editGroupWidget = new EditGroupWidget();
m_editGroupWidget->setObjectName("editGroupWidget");
m_changeMasterKeyWidget = new ChangeMasterKeyWidget();
m_changeMasterKeyWidget->headlineLabel()->setText(tr("Change master key"));
QFont headlineLabelFont = m_changeMasterKeyWidget->headlineLabel()->font();
headlineLabelFont.setBold(true);
headlineLabelFont.setPointSize(headlineLabelFont.pointSize() + 2);
m_changeMasterKeyWidget->headlineLabel()->setFont(headlineLabelFont);
m_databaseSettingsWidget = new DatabaseSettingsWidget();
m_databaseOpenWidget = new DatabaseOpenWidget();
m_databaseOpenWidget->setObjectName("databaseOpenWidget");
m_keepass1OpenWidget = new KeePass1OpenWidget();
m_keepass1OpenWidget->setObjectName("keepass1OpenWidget");
2010-10-06 13:40:50 -04:00
addWidget(m_mainWidget);
addWidget(m_editEntryWidget);
addWidget(m_editGroupWidget);
addWidget(m_changeMasterKeyWidget);
addWidget(m_databaseSettingsWidget);
2012-05-15 14:12:05 -04:00
addWidget(m_historyEditEntryWidget);
addWidget(m_databaseOpenWidget);
addWidget(m_keepass1OpenWidget);
2010-10-06 13:40:50 -04:00
m_actionEntryNew = m_menuEntry->addAction(tr("Add new entry"), this, SLOT(createEntry()));
2012-05-27 09:18:18 -04:00
m_actionEntryNew->setIcon(dataPath()->icon("actions", "entry-new", false));
m_actionEntryClone = m_menuEntry->addAction(tr("Clone entry"), this, SLOT(cloneEntry()));
2012-05-27 09:18:18 -04:00
m_actionEntryClone->setIcon(dataPath()->icon("actions", "entry-clone", false));
m_actionEntryClone->setEnabled(false);
m_actionEntryEditView = m_menuEntry->addAction(tr("View/Edit entry"), this, SLOT(switchToEntryEdit()));
2012-05-27 09:18:18 -04:00
m_actionEntryEditView->setIcon(dataPath()->icon("actions", "entry-edit", false));
m_actionEntryEditView->setEnabled(false);
m_actionEntryDelete = m_menuEntry->addAction(tr("Delete entry"), this, SLOT(deleteEntry()));
2012-05-27 09:18:18 -04:00
m_actionEntryDelete->setIcon(dataPath()->icon("actions", "entry-delete", false));
m_actionEntryDelete->setEnabled(false);
m_actionEntryCopyUsername = m_menuEntry->addAction(tr("Copy username to clipboard"), this,
SLOT(copyUsername()), Qt::CTRL + Qt::Key_B);
m_actionEntryCopyUsername->setEnabled(false);
m_actionEntryCopyPassword = m_menuEntry->addAction(tr("Copy password to clipboard"), this,
SLOT(copyPassword()), Qt::CTRL + Qt::Key_C);
m_actionEntryCopyPassword->setEnabled(false);
m_actionGroupNew = m_menuGroup->addAction(tr("Add new group"), this, SLOT(createGroup()));
m_actionGroupNew->setIcon(dataPath()->icon("actions", "group-new", false));
m_actionGroupEdit = m_menuGroup->addAction(tr("Edit group"), this, SLOT(switchToGroupEdit()));
m_actionGroupEdit->setIcon(dataPath()->icon("actions", "group-edit", false));
m_actionGroupDelete = m_menuGroup->addAction(tr("Delete group"), this, SLOT(deleteGroup()));
m_actionGroupDelete->setIcon(dataPath()->icon("actions", "group-delete", false));
m_actionGroupDelete->setEnabled(false);
connect(m_groupView, SIGNAL(groupChanged(Group*)), this, SLOT(clearLastGroup(Group*)));
2012-05-27 10:53:07 -04:00
connect(m_groupView, SIGNAL(groupChanged(Group*)), SLOT(updateGroupActions(Group*)));
connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*)));
connect(m_entryView, SIGNAL(entryActivated(Entry*)), SLOT(switchToEntryEdit(Entry*)));
connect(m_editEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
2012-05-15 14:12:05 -04:00
connect(m_editEntryWidget, SIGNAL(historyEntryActivated(Entry*)), SLOT(switchToHistoryView(Entry*)));
connect(m_historyEditEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchBackToEntryEdit()));
connect(m_editGroupWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
connect(m_changeMasterKeyWidget, SIGNAL(editFinished(bool)), SLOT(updateMasterKey(bool)));
connect(m_databaseSettingsWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
connect(m_databaseOpenWidget, SIGNAL(editFinished(bool)), SLOT(openDatabase(bool)));
connect(m_keepass1OpenWidget, SIGNAL(editFinished(bool)), SLOT(openDatabase(bool)));
connect(this, SIGNAL(currentChanged(int)), this, SLOT(emitCurrentModeChanged()));
connect(m_searchUi->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(startSearchTimer()));
2012-05-27 07:19:12 -04:00
connect(m_searchUi->caseSensitiveCheckBox, SIGNAL(toggled(bool)), this, SLOT(startSearch()));
connect(m_searchUi->searchCurrentRadioButton, SIGNAL(toggled(bool)), this, SLOT(startSearch()));
connect(m_searchUi->searchRootRadioButton, SIGNAL(toggled(bool)), this, SLOT(startSearch()));
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(search()));
connect(closeAction, SIGNAL(triggered()), this, SLOT(closeSearch()));
connect(m_entryView, SIGNAL(entrySelectionChanged()), SLOT(updateEntryActions()));
2010-10-06 13:40:50 -04:00
setCurrentIndex(0);
}
DatabaseWidget::~DatabaseWidget()
{
}
DatabaseWidget::Mode DatabaseWidget::currentMode()
{
switch (currentIndex()) {
2012-04-25 14:22:55 -04:00
case -1:
return DatabaseWidget::None;
case 0:
return DatabaseWidget::ViewMode;
case 1: // entry edit
case 2: // group edit
case 3: // change master key
case 4: // database settings
2012-05-15 14:12:05 -04:00
case 5: // entry history
case 6: // open database
case 7: // keepass 1 import
2012-04-25 14:22:55 -04:00
return DatabaseWidget::EditMode;
default:
Q_ASSERT(false);
return DatabaseWidget::None;
}
}
bool DatabaseWidget::actionEnabled(Action action)
{
switch (action) {
case GroupNew:
return m_actionGroupNew->isEnabled();
case GroupEdit:
return m_actionGroupEdit->isEnabled();
case GroupDelete:
return m_actionGroupDelete->isEnabled();
case EntryNew:
return m_actionEntryNew->isEnabled();
case EntryClone:
return m_actionEntryClone->isEnabled();
case EntryEditView:
return m_actionEntryEditView->isEnabled();
case EntryDelete:
return m_actionEntryDelete->isEnabled();
case EntryCopyUsername:
return m_actionEntryCopyUsername->isEnabled();
case EntryCopyPassword:
return m_actionEntryCopyPassword->isEnabled();
default:
Q_ASSERT(false);
return false;
}
}
void DatabaseWidget::emitCurrentModeChanged()
{
Q_EMIT currentModeChanged(currentMode());
}
GroupView* DatabaseWidget::groupView()
2010-10-06 13:40:50 -04:00
{
return m_groupView;
}
EntryView* DatabaseWidget::entryView()
{
return m_entryView;
}
2012-07-06 13:21:19 -04:00
Database* DatabaseWidget::database()
{
return m_db;
}
2011-12-27 10:04:59 -05:00
void DatabaseWidget::createEntry()
{
if (!m_groupView->currentGroup()) {
Q_ASSERT(false);
return;
}
2011-12-27 10:04:59 -05:00
m_newEntry = new Entry();
m_newEntry->setUuid(Uuid::random());
2012-04-23 14:10:07 -04:00
m_newEntry->setUsername(m_db->metadata()->defaultUserName());
2011-12-27 10:04:59 -05:00
m_newParent = m_groupView->currentGroup();
switchToEntryEdit(m_newEntry, true);
}
2012-05-15 15:10:39 -04:00
void DatabaseWidget::cloneEntry()
{
Entry* currentEntry = m_entryView->currentEntry();
if (!currentEntry) {
Q_ASSERT(false);
return;
}
2012-05-15 15:10:39 -04:00
Entry* entry = currentEntry->clone();
entry->setUuid(Uuid::random());
entry->setGroup(currentEntry->group());
m_entryView->setFocus();
m_entryView->setCurrentEntry(entry);
}
2012-04-18 14:08:54 -04:00
void DatabaseWidget::deleteEntry()
{
Entry* currentEntry = m_entryView->currentEntry();
if (!currentEntry) {
Q_ASSERT(false);
return;
}
bool inRecylceBin = Tools::hasChild(m_db->metadata()->recycleBin(), currentEntry);
if (inRecylceBin || !m_db->metadata()->recycleBinEnabled()) {
QMessageBox::StandardButton result = QMessageBox::question(
this, tr("Delete entry?"),
tr("Do you really want to delete the entry \"%1\" for good?")
.arg(currentEntry->title()),
QMessageBox::Yes | QMessageBox::No);
if (result == QMessageBox::Yes) {
delete currentEntry;
}
}
else {
m_db->recycleEntry(currentEntry);
}
2012-04-18 14:08:54 -04:00
}
void DatabaseWidget::copyUsername()
{
Entry* currentEntry = m_entryView->currentEntry();
if (!currentEntry) {
Q_ASSERT(false);
return;
}
clipboard()->setText(currentEntry->username());
}
void DatabaseWidget::copyPassword()
{
Entry* currentEntry = m_entryView->currentEntry();
if (!currentEntry) {
Q_ASSERT(false);
return;
}
clipboard()->setText(currentEntry->password());
}
void DatabaseWidget::createGroup()
{
if (!m_groupView->currentGroup()) {
Q_ASSERT(false);
return;
}
m_newGroup = new Group();
m_newGroup->setUuid(Uuid::random());
2011-12-27 10:04:59 -05:00
m_newParent = m_groupView->currentGroup();
switchToGroupEdit(m_newGroup, true);
}
2012-04-21 13:06:28 -04:00
void DatabaseWidget::deleteGroup()
{
Group* currentGroup = m_groupView->currentGroup();
if (!currentGroup || !canDeleteCurrentGoup()) {
Q_ASSERT(false);
return;
}
2012-04-21 13:06:28 -04:00
bool inRecylceBin = Tools::hasChild(m_db->metadata()->recycleBin(), currentGroup);
2012-04-21 13:06:28 -04:00
if (inRecylceBin || !m_db->metadata()->recycleBinEnabled()) {
QMessageBox::StandardButton result = QMessageBox::question(
this, tr("Delete group?"),
tr("Do you really want to delete the group \"%1\" for good?")
.arg(currentGroup->name()),
2012-04-21 13:06:28 -04:00
QMessageBox::Yes | QMessageBox::No);
if (result == QMessageBox::Yes) {
delete currentGroup;
2012-04-21 13:06:28 -04:00
}
}
else {
m_db->recycleGroup(currentGroup);
2012-04-21 13:06:28 -04:00
}
}
int DatabaseWidget::addWidget(QWidget* w)
{
w->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
int index = QStackedWidget::addWidget(w);
adjustSize();
return index;
}
void DatabaseWidget::setCurrentIndex(int index)
{
if (currentWidget()) {
currentWidget()->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
}
QStackedWidget::setCurrentIndex(index);
if (currentWidget()) {
currentWidget()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
}
adjustSize();
}
void DatabaseWidget::switchToView(bool accepted)
{
if (m_newGroup) {
if (accepted) {
2011-12-27 10:04:59 -05:00
m_newGroup->setParent(m_newParent);
m_groupView->setCurrentGroup(m_newGroup);
m_groupView->expandGroup(m_newParent);
}
else {
delete m_newGroup;
}
2012-06-29 08:15:16 -04:00
m_newGroup = Q_NULLPTR;
m_newParent = Q_NULLPTR;
2011-12-27 10:04:59 -05:00
}
else if (m_newEntry) {
if (accepted) {
m_newEntry->setGroup(m_newParent);
2012-05-02 13:33:37 -04:00
m_entryView->setFocus();
m_entryView->setCurrentEntry(m_newEntry);
2011-12-27 10:04:59 -05:00
}
else {
delete m_newEntry;
}
2012-06-29 08:15:16 -04:00
m_newEntry = Q_NULLPTR;
m_newParent = Q_NULLPTR;
}
2010-10-06 13:40:50 -04:00
setCurrentIndex(0);
}
2012-05-15 14:12:05 -04:00
void DatabaseWidget::switchToHistoryView(Entry* entry)
{
m_historyEditEntryWidget->loadEntry(entry, false, true, "", m_db);
setCurrentIndex(5);
}
void DatabaseWidget::switchBackToEntryEdit()
{
setCurrentIndex(1);
}
void DatabaseWidget::switchToEntryEdit(Entry* entry)
2010-10-06 13:40:50 -04:00
{
2011-12-27 10:04:59 -05:00
switchToEntryEdit(entry, false);
}
void DatabaseWidget::switchToEntryEdit(Entry* entry, bool create)
{
Group* group = m_groupView->currentGroup();
if (!group) {
Q_ASSERT(m_entryView->inSearch());
group = m_lastGroup;
}
Q_ASSERT(group);
2012-05-15 14:12:05 -04:00
m_editEntryWidget->loadEntry(entry, create, false, group->name(), m_db);
2010-10-06 13:40:50 -04:00
setCurrentIndex(1);
2010-08-24 16:26:52 -04:00
}
void DatabaseWidget::switchToGroupEdit(Group* group, bool create)
{
m_editGroupWidget->loadGroup(group, create, m_db);
setCurrentIndex(2);
}
void DatabaseWidget::updateMasterKey(bool accepted)
{
if (accepted) {
m_db->setKey(m_changeMasterKeyWidget->newMasterKey());
}
2012-04-16 18:22:44 -04:00
else if (!m_db->hasKey()) {
Q_EMIT closeRequest();
return;
}
setCurrentIndex(0);
}
void DatabaseWidget::openDatabase(bool accepted)
{
if (accepted) {
Database* oldDb = m_db;
m_db = static_cast<DatabaseOpenWidget*>(sender())->database();
m_groupView->changeDatabase(m_db);
Q_EMIT databaseChanged(m_db);
delete oldDb;
setCurrentIndex(0);
// We won't need those anymore and KeePass1OpenWidget closes
// the file in its dtor.
delete m_databaseOpenWidget;
2012-06-29 08:15:16 -04:00
m_databaseOpenWidget = Q_NULLPTR;
delete m_keepass1OpenWidget;
2012-06-29 08:15:16 -04:00
m_keepass1OpenWidget = Q_NULLPTR;
}
else {
if (m_databaseOpenWidget->database()) {
delete m_databaseOpenWidget->database();
}
Q_EMIT closeRequest();
}
}
void DatabaseWidget::switchToEntryEdit()
{
2011-12-29 13:01:58 -05:00
switchToEntryEdit(m_entryView->currentEntry(), false);
}
void DatabaseWidget::switchToGroupEdit()
{
switchToGroupEdit(m_groupView->currentGroup(), false);
}
void DatabaseWidget::switchToMasterKeyChange()
{
m_changeMasterKeyWidget->clearForms();
setCurrentIndex(3);
}
void DatabaseWidget::switchToDatabaseSettings()
{
m_databaseSettingsWidget->load(m_db);
setCurrentIndex(4);
}
2012-07-06 12:50:52 -04:00
void DatabaseWidget::switchToOpenDatabase(const QString& fileName)
{
2012-07-06 12:50:52 -04:00
m_databaseOpenWidget->load(fileName);
setCurrentIndex(6);
}
2012-07-06 12:50:52 -04:00
void DatabaseWidget::switchToOpenDatabase(const QString& fileName, const QString& password,
const QString& keyFile)
{
2012-07-06 12:50:52 -04:00
switchToOpenDatabase(fileName);
m_databaseOpenWidget->enterKey(password, keyFile);
}
2012-07-06 12:50:52 -04:00
void DatabaseWidget::switchToImportKeepass1(const QString& fileName)
{
2012-07-06 12:50:52 -04:00
m_keepass1OpenWidget->load(fileName);
setCurrentIndex(7);
}
void DatabaseWidget::toggleSearch()
{
if (m_entryView->inSearch()) {
closeSearch();
}
else {
showSearch();
}
}
void DatabaseWidget::closeSearch()
{
Q_ASSERT(m_lastGroup);
m_groupView->setCurrentGroup(m_lastGroup);
}
void DatabaseWidget::showSearch()
{
m_searchUi->searchEdit->blockSignals(true);
m_searchUi->searchEdit->clear();
m_searchUi->searchEdit->blockSignals(false);
m_searchUi->searchCurrentRadioButton->blockSignals(true);
m_searchUi->searchRootRadioButton->blockSignals(true);
m_searchUi->searchCurrentRadioButton->setChecked(true);
m_searchUi->searchCurrentRadioButton->blockSignals(false);
m_searchUi->searchRootRadioButton->blockSignals(false);
m_lastGroup = m_groupView->currentGroup();
2012-05-27 08:47:15 -04:00
Q_ASSERT(m_lastGroup);
if (m_lastGroup == m_db->rootGroup()) {
m_searchUi->optionsWidget->hide();
m_searchUi->searchCurrentRadioButton->hide();
m_searchUi->searchRootRadioButton->hide();
}
else {
m_searchUi->optionsWidget->show();
m_searchUi->searchCurrentRadioButton->show();
m_searchUi->searchRootRadioButton->show();
m_searchUi->searchCurrentRadioButton->setText(tr("Current group")
.append(" (")
.append(m_lastGroup->name())
.append(")"));
}
m_groupView->setCurrentIndex(QModelIndex());
m_searchWidget->show();
search();
m_searchUi->searchEdit->setFocus();
}
2012-05-12 07:22:41 -04:00
void DatabaseWidget::search()
{
2012-05-27 08:47:15 -04:00
Q_ASSERT(m_lastGroup);
Group* searchGroup;
if (m_searchUi->searchCurrentRadioButton->isChecked()) {
searchGroup = m_lastGroup;
}
else if (m_searchUi->searchRootRadioButton->isChecked()) {
searchGroup = m_db->rootGroup();
}
else {
Q_ASSERT(false);
return;
}
2012-05-27 07:19:12 -04:00
Qt::CaseSensitivity sensitivity;
if (m_searchUi->caseSensitiveCheckBox->isChecked()) {
sensitivity = Qt::CaseSensitive;
}
else {
sensitivity = Qt::CaseInsensitive;
}
QList<Entry*> searchResult = searchGroup->search(m_searchUi->searchEdit->text(), sensitivity);
2012-05-12 07:22:41 -04:00
2012-05-12 07:22:41 -04:00
m_entryView->search(searchResult);
}
void DatabaseWidget::startSearchTimer()
{
if (!m_searchTimer->isActive()) {
m_searchTimer->stop();
}
m_searchTimer->start(100);
}
2012-05-27 07:19:12 -04:00
void DatabaseWidget::startSearch()
{
if (!m_searchTimer->isActive()) {
m_searchTimer->stop();
}
search();
}
bool DatabaseWidget::dbHasKey()
{
return m_db->hasKey();
}
2012-04-21 13:06:28 -04:00
bool DatabaseWidget::canDeleteCurrentGoup()
{
bool isRootGroup = m_db->rootGroup() == m_groupView->currentGroup();
bool isRecycleBin = m_db->metadata()->recycleBin() == m_groupView->currentGroup();
return !isRootGroup && !isRecycleBin;
}
void DatabaseWidget::clearLastGroup(Group* group)
{
if (group) {
2012-06-29 08:15:16 -04:00
m_lastGroup = Q_NULLPTR;
m_searchWidget->hide();
}
}
2012-05-27 10:53:07 -04:00
void DatabaseWidget::updateGroupActions(Group* group)
{
m_actionGroupNew->setEnabled(group);
m_actionGroupEdit->setEnabled(group);
m_actionGroupDelete->setEnabled(group && canDeleteCurrentGoup());
}
void DatabaseWidget::updateEntryActions()
{
bool singleEntrySelected = m_entryView->isSingleEntrySelected();
bool inSearch = m_entryView->inSearch();
m_actionEntryNew->setEnabled(!inSearch);
m_actionEntryClone->setEnabled(singleEntrySelected && !inSearch);
m_actionEntryEditView->setEnabled(singleEntrySelected);
m_actionEntryDelete->setEnabled(singleEntrySelected);
m_actionEntryCopyUsername->setEnabled(singleEntrySelected);
m_actionEntryCopyPassword->setEnabled(singleEntrySelected);
}
void DatabaseWidget::showGroupContextMenu(const QPoint& pos)
{
m_menuGroup->popup(m_groupView->viewport()->mapToGlobal(pos));
}
void DatabaseWidget::showEntryContextMenu(const QPoint& pos)
{
m_menuEntry->popup(m_entryView->viewport()->mapToGlobal(pos));
}