2010-10-06 13:40:50 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2017-06-09 17:40:36 -04:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2010-10-06 13:40:50 -04:00
|
|
|
*
|
|
|
|
* 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 "EditEntryWidget.h"
|
2012-04-14 09:43:41 -04:00
|
|
|
#include "ui_EditEntryWidgetAdvanced.h"
|
2012-07-16 11:40:28 -04:00
|
|
|
#include "ui_EditEntryWidgetAutoType.h"
|
2012-05-15 14:12:05 -04:00
|
|
|
#include "ui_EditEntryWidgetHistory.h"
|
2010-10-06 13:40:50 -04:00
|
|
|
#include "ui_EditEntryWidgetMain.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "ui_EditEntryWidgetSSHAgent.h"
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2018-09-30 08:45:06 -04:00
|
|
|
#include <QButtonGroup>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QColorDialog>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QDesktopServices>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QEvent>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QMenu>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QMimeData>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QSortFilterProxyModel>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QStackedLayout>
|
|
|
|
#include <QStandardPaths>
|
2014-12-03 15:50:17 -05:00
|
|
|
#include <QTemporaryFile>
|
2017-12-08 14:06:30 -05:00
|
|
|
|
2017-11-07 11:58:08 -05:00
|
|
|
#include "autotype/AutoType.h"
|
2018-09-30 08:45:06 -04:00
|
|
|
#include "core/Clock.h"
|
2013-07-04 07:41:51 -04:00
|
|
|
#include "core/Config.h"
|
2012-05-20 17:08:23 -04:00
|
|
|
#include "core/Database.h"
|
2010-10-06 13:40:50 -04:00
|
|
|
#include "core/Entry.h"
|
2014-01-12 11:08:36 -05:00
|
|
|
#include "core/FilePath.h"
|
2012-05-15 10:50:42 -04:00
|
|
|
#include "core/Metadata.h"
|
2012-08-15 16:47:41 -04:00
|
|
|
#include "core/TimeDelta.h"
|
2012-05-02 05:11:28 -04:00
|
|
|
#include "core/Tools.h"
|
2017-10-29 11:17:24 -04:00
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
#include "sshagent/KeeAgentSettings.h"
|
|
|
|
#include "sshagent/OpenSSHKey.h"
|
|
|
|
#include "sshagent/SSHAgent.h"
|
|
|
|
#endif
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/Clipboard.h"
|
2012-05-15 09:30:00 -04:00
|
|
|
#include "gui/EditWidgetIcons.h"
|
2012-10-29 17:41:37 -04:00
|
|
|
#include "gui/EditWidgetProperties.h"
|
2012-05-02 05:11:28 -04:00
|
|
|
#include "gui/FileDialog.h"
|
2017-11-25 04:12:31 -05:00
|
|
|
#include "gui/Font.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2012-07-16 11:40:28 -04:00
|
|
|
#include "gui/entry/AutoTypeAssociationsModel.h"
|
2012-05-16 04:16:32 -04:00
|
|
|
#include "gui/entry/EntryAttachmentsModel.h"
|
|
|
|
#include "gui/entry/EntryAttributesModel.h"
|
2012-05-15 14:12:05 -04:00
|
|
|
#include "gui/entry/EntryHistoryModel.h"
|
2010-10-06 13:40:50 -04:00
|
|
|
|
|
|
|
EditEntryWidget::EditEntryWidget(QWidget* parent)
|
2012-05-15 04:50:08 -04:00
|
|
|
: EditWidget(parent)
|
2015-07-24 12:28:12 -04:00
|
|
|
, m_entry(nullptr)
|
2010-10-06 13:40:50 -04:00
|
|
|
, m_mainUi(new Ui::EditEntryWidgetMain())
|
2012-04-14 09:43:41 -04:00
|
|
|
, m_advancedUi(new Ui::EditEntryWidgetAdvanced())
|
2012-07-16 11:40:28 -04:00
|
|
|
, m_autoTypeUi(new Ui::EditEntryWidgetAutoType())
|
2017-10-29 11:17:24 -04:00
|
|
|
, m_sshAgentUi(new Ui::EditEntryWidgetSSHAgent())
|
2012-05-15 14:12:05 -04:00
|
|
|
, m_historyUi(new Ui::EditEntryWidgetHistory())
|
2012-05-15 09:30:00 -04:00
|
|
|
, m_mainWidget(new QWidget())
|
|
|
|
, m_advancedWidget(new QWidget())
|
|
|
|
, m_iconsWidget(new EditWidgetIcons())
|
2012-07-16 11:40:28 -04:00
|
|
|
, m_autoTypeWidget(new QWidget())
|
2017-10-29 11:17:24 -04:00
|
|
|
, m_sshAgentWidget(new QWidget())
|
2012-10-29 17:41:37 -04:00
|
|
|
, m_editWidgetProperties(new EditWidgetProperties())
|
2012-05-15 14:12:05 -04:00
|
|
|
, m_historyWidget(new QWidget())
|
2012-07-16 11:47:21 -04:00
|
|
|
, m_entryAttributes(new EntryAttributes(this))
|
|
|
|
, m_attributesModel(new EntryAttributesModel(m_advancedWidget))
|
|
|
|
, m_historyModel(new EntryHistoryModel(this))
|
|
|
|
, m_sortModel(new QSortFilterProxyModel(this))
|
2012-07-16 11:40:28 -04:00
|
|
|
, m_autoTypeAssoc(new AutoTypeAssociations(this))
|
|
|
|
, m_autoTypeAssocModel(new AutoTypeAssociationsModel(this))
|
|
|
|
, m_autoTypeDefaultSequenceGroup(new QButtonGroup(this))
|
|
|
|
, m_autoTypeWindowSequenceGroup(new QButtonGroup(this))
|
2012-10-29 18:11:42 -04:00
|
|
|
{
|
|
|
|
setupMain();
|
|
|
|
setupAdvanced();
|
|
|
|
setupIcon();
|
|
|
|
setupAutoType();
|
2017-10-29 11:17:24 -04:00
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
if (config()->get("SSHAgent", false).toBool()) {
|
|
|
|
setupSSHAgent();
|
|
|
|
m_sshAgentEnabled = true;
|
|
|
|
} else {
|
|
|
|
m_sshAgentEnabled = false;
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-29 18:11:42 -04:00
|
|
|
setupProperties();
|
|
|
|
setupHistory();
|
2018-03-10 22:31:43 -05:00
|
|
|
setupEntryUpdate();
|
2012-10-29 18:11:42 -04:00
|
|
|
|
2017-06-13 20:55:53 -04:00
|
|
|
connect(this, SIGNAL(accepted()), SLOT(acceptEntry()));
|
2012-10-29 18:11:42 -04:00
|
|
|
connect(this, SIGNAL(rejected()), SLOT(cancel()));
|
2018-02-17 22:16:45 -05:00
|
|
|
connect(this, SIGNAL(apply()), SLOT(commitEntry()));
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(m_iconsWidget,
|
|
|
|
SIGNAL(messageEditEntry(QString, MessageWidget::MessageType)),
|
|
|
|
SLOT(showMessage(QString, MessageWidget::MessageType)));
|
2015-01-21 11:19:05 -05:00
|
|
|
connect(m_iconsWidget, SIGNAL(messageEditEntryDismiss()), SLOT(hideMessage()));
|
2018-03-31 16:01:30 -04:00
|
|
|
|
2017-02-12 17:05:48 -05:00
|
|
|
m_mainUi->passwordGenerator->layout()->setContentsMargins(0, 0, 0, 0);
|
2012-10-29 18:11:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EditEntryWidget::~EditEntryWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::setupMain()
|
2010-10-06 13:40:50 -04:00
|
|
|
{
|
|
|
|
m_mainUi->setupUi(m_mainWidget);
|
2017-02-22 08:05:59 -05:00
|
|
|
addPage(tr("Entry"), FilePath::instance()->icon("actions", "document-edit"), m_mainWidget);
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2014-01-12 11:08:36 -05:00
|
|
|
m_mainUi->togglePasswordButton->setIcon(filePath()->onOffIcon("actions", "password-show"));
|
2018-09-22 15:26:14 -04:00
|
|
|
m_mainUi->togglePasswordGeneratorButton->setIcon(filePath()->icon("actions", "password-generator"));
|
2014-01-12 11:08:36 -05:00
|
|
|
connect(m_mainUi->togglePasswordButton, SIGNAL(toggled(bool)), m_mainUi->passwordEdit, SLOT(setShowPassword(bool)));
|
2016-12-01 23:13:27 -05:00
|
|
|
connect(m_mainUi->togglePasswordGeneratorButton, SIGNAL(toggled(bool)), SLOT(togglePasswordGeneratorButton(bool)));
|
2012-10-29 18:11:42 -04:00
|
|
|
connect(m_mainUi->expireCheck, SIGNAL(toggled(bool)), m_mainUi->expireDatePicker, SLOT(setEnabled(bool)));
|
2017-05-28 22:58:15 -04:00
|
|
|
connect(m_mainUi->notesEnabled, SIGNAL(toggled(bool)), this, SLOT(toggleHideNotes(bool)));
|
2014-01-12 11:08:36 -05:00
|
|
|
m_mainUi->passwordRepeatEdit->enableVerifyMode(m_mainUi->passwordEdit);
|
2016-11-23 21:59:24 -05:00
|
|
|
connect(m_mainUi->passwordGenerator, SIGNAL(appliedPassword(QString)), SLOT(setGeneratedPassword(QString)));
|
2012-10-29 18:11:42 -04:00
|
|
|
|
|
|
|
m_mainUi->expirePresets->setMenu(createPresetsMenu());
|
|
|
|
connect(m_mainUi->expirePresets->menu(), SIGNAL(triggered(QAction*)), this, SLOT(useExpiryPreset(QAction*)));
|
2013-03-10 17:23:10 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
QAction* action = new QAction(this);
|
2015-04-14 11:27:49 -04:00
|
|
|
action->setShortcut(Qt::CTRL | Qt::Key_Return);
|
2018-02-17 22:16:45 -05:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(commitEntry()));
|
2015-04-14 11:27:49 -04:00
|
|
|
this->addAction(action);
|
|
|
|
|
2013-03-10 17:23:10 -04:00
|
|
|
m_mainUi->passwordGenerator->hide();
|
2013-03-12 17:42:06 -04:00
|
|
|
m_mainUi->passwordGenerator->reset();
|
2012-10-29 18:11:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::setupAdvanced()
|
|
|
|
{
|
2012-04-14 09:43:41 -04:00
|
|
|
m_advancedUi->setupUi(m_advancedWidget);
|
2017-02-22 08:05:59 -05:00
|
|
|
addPage(tr("Advanced"), FilePath::instance()->icon("categories", "preferences-other"), m_advancedWidget);
|
2012-04-14 09:43:41 -04:00
|
|
|
|
2017-12-19 08:36:09 -05:00
|
|
|
m_advancedUi->attachmentsWidget->setReadOnly(false);
|
|
|
|
m_advancedUi->attachmentsWidget->setButtonsVisible(true);
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(m_advancedUi->attachmentsWidget,
|
|
|
|
&EntryAttachmentsWidget::errorOccurred,
|
|
|
|
this,
|
|
|
|
[this](const QString& error) { showMessage(error, MessageWidget::Error); });
|
2012-04-14 09:43:41 -04:00
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
m_attributesModel->setEntryAttributes(m_entryAttributes);
|
2012-04-14 09:43:41 -04:00
|
|
|
m_advancedUi->attributesView->setModel(m_attributesModel);
|
2012-04-28 13:11:15 -04:00
|
|
|
connect(m_advancedUi->addAttributeButton, SIGNAL(clicked()), SLOT(insertAttribute()));
|
|
|
|
connect(m_advancedUi->editAttributeButton, SIGNAL(clicked()), SLOT(editCurrentAttribute()));
|
|
|
|
connect(m_advancedUi->removeAttributeButton, SIGNAL(clicked()), SLOT(removeCurrentAttribute()));
|
2017-03-07 22:38:18 -05:00
|
|
|
connect(m_advancedUi->protectAttributeButton, SIGNAL(toggled(bool)), SLOT(protectCurrentAttribute(bool)));
|
|
|
|
connect(m_advancedUi->revealAttributeButton, SIGNAL(clicked(bool)), SLOT(revealCurrentAttribute()));
|
2012-04-28 13:11:15 -04:00
|
|
|
connect(m_advancedUi->attributesView->selectionModel(),
|
2018-03-31 16:01:30 -04:00
|
|
|
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
2012-04-28 13:11:15 -04:00
|
|
|
SLOT(updateCurrentAttribute()));
|
2018-02-19 14:59:04 -05:00
|
|
|
connect(m_advancedUi->fgColorButton, SIGNAL(clicked()), SLOT(pickColor()));
|
|
|
|
connect(m_advancedUi->bgColorButton, SIGNAL(clicked()), SLOT(pickColor()));
|
2012-10-29 18:11:42 -04:00
|
|
|
}
|
2012-04-14 09:43:41 -04:00
|
|
|
|
2012-10-29 18:11:42 -04:00
|
|
|
void EditEntryWidget::setupIcon()
|
|
|
|
{
|
2017-02-22 08:05:59 -05:00
|
|
|
addPage(tr("Icon"), FilePath::instance()->icon("apps", "preferences-desktop-icons"), m_iconsWidget);
|
2012-10-29 18:11:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::setupAutoType()
|
|
|
|
{
|
|
|
|
m_autoTypeUi->setupUi(m_autoTypeWidget);
|
2017-02-22 08:05:59 -05:00
|
|
|
addPage(tr("Auto-Type"), FilePath::instance()->icon("actions", "key-enter"), m_autoTypeWidget);
|
2012-01-07 10:18:21 -05:00
|
|
|
|
2012-07-16 11:40:28 -04:00
|
|
|
m_autoTypeDefaultSequenceGroup->addButton(m_autoTypeUi->inheritSequenceButton);
|
|
|
|
m_autoTypeDefaultSequenceGroup->addButton(m_autoTypeUi->customSequenceButton);
|
|
|
|
m_autoTypeAssocModel->setAutoTypeAssociations(m_autoTypeAssoc);
|
|
|
|
m_autoTypeUi->assocView->setModel(m_autoTypeAssocModel);
|
|
|
|
m_autoTypeUi->assocView->setColumnHidden(1, true);
|
2012-07-20 04:28:18 -04:00
|
|
|
connect(m_autoTypeUi->enableButton, SIGNAL(toggled(bool)), SLOT(updateAutoTypeEnabled()));
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(
|
|
|
|
m_autoTypeUi->customSequenceButton, SIGNAL(toggled(bool)), m_autoTypeUi->sequenceEdit, SLOT(setEnabled(bool)));
|
|
|
|
connect(m_autoTypeUi->customWindowSequenceButton,
|
|
|
|
SIGNAL(toggled(bool)),
|
|
|
|
m_autoTypeUi->windowSequenceEdit,
|
|
|
|
SLOT(setEnabled(bool)));
|
2012-07-16 11:40:28 -04:00
|
|
|
connect(m_autoTypeUi->assocAddButton, SIGNAL(clicked()), SLOT(insertAutoTypeAssoc()));
|
|
|
|
connect(m_autoTypeUi->assocRemoveButton, SIGNAL(clicked()), SLOT(removeAutoTypeAssoc()));
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(m_autoTypeUi->assocView->selectionModel(),
|
|
|
|
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
|
2012-07-20 04:28:18 -04:00
|
|
|
SLOT(updateAutoTypeEnabled()));
|
|
|
|
connect(m_autoTypeAssocModel, SIGNAL(modelReset()), SLOT(updateAutoTypeEnabled()));
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(m_autoTypeUi->assocView->selectionModel(),
|
|
|
|
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
|
2012-07-16 11:40:28 -04:00
|
|
|
SLOT(loadCurrentAssoc(QModelIndex)));
|
|
|
|
connect(m_autoTypeAssocModel, SIGNAL(modelReset()), SLOT(clearCurrentAssoc()));
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(m_autoTypeUi->windowTitleCombo, SIGNAL(editTextChanged(QString)), SLOT(applyCurrentAssoc()));
|
|
|
|
connect(m_autoTypeUi->customWindowSequenceButton, SIGNAL(toggled(bool)), SLOT(applyCurrentAssoc()));
|
|
|
|
connect(m_autoTypeUi->windowSequenceEdit, SIGNAL(textChanged(QString)), SLOT(applyCurrentAssoc()));
|
2012-10-29 18:11:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::setupProperties()
|
|
|
|
{
|
2017-02-22 08:05:59 -05:00
|
|
|
addPage(tr("Properties"), FilePath::instance()->icon("actions", "document-properties"), m_editWidgetProperties);
|
2012-10-29 18:11:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::setupHistory()
|
|
|
|
{
|
|
|
|
m_historyUi->setupUi(m_historyWidget);
|
2017-02-22 08:05:59 -05:00
|
|
|
addPage(tr("History"), FilePath::instance()->icon("actions", "view-history"), m_historyWidget);
|
2012-07-16 11:40:28 -04:00
|
|
|
|
2012-06-10 10:02:03 -04:00
|
|
|
m_sortModel->setSourceModel(m_historyModel);
|
|
|
|
m_sortModel->setDynamicSortFilter(true);
|
|
|
|
m_sortModel->setSortLocaleAware(true);
|
|
|
|
m_sortModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
m_sortModel->setSortRole(Qt::UserRole);
|
|
|
|
|
|
|
|
m_historyUi->historyView->setModel(m_sortModel);
|
2012-05-15 14:12:05 -04:00
|
|
|
m_historyUi->historyView->setRootIsDecorated(false);
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(m_historyUi->historyView, SIGNAL(activated(QModelIndex)), SLOT(histEntryActivated(QModelIndex)));
|
2012-05-18 13:22:22 -04:00
|
|
|
connect(m_historyUi->historyView->selectionModel(),
|
2018-03-31 16:01:30 -04:00
|
|
|
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
|
|
|
SLOT(updateHistoryButtons(QModelIndex, QModelIndex)));
|
2012-05-18 13:22:22 -04:00
|
|
|
connect(m_historyUi->showButton, SIGNAL(clicked()), SLOT(showHistoryEntry()));
|
2012-05-18 14:58:34 -04:00
|
|
|
connect(m_historyUi->restoreButton, SIGNAL(clicked()), SLOT(restoreHistoryEntry()));
|
2012-05-18 13:22:22 -04:00
|
|
|
connect(m_historyUi->deleteButton, SIGNAL(clicked()), SLOT(deleteHistoryEntry()));
|
2012-05-18 14:15:02 -04:00
|
|
|
connect(m_historyUi->deleteAllButton, SIGNAL(clicked()), SLOT(deleteAllHistoryEntries()));
|
2010-10-06 13:40:50 -04:00
|
|
|
}
|
|
|
|
|
2018-03-10 22:31:43 -05:00
|
|
|
void EditEntryWidget::setupEntryUpdate()
|
|
|
|
{
|
|
|
|
// Entry tab
|
|
|
|
connect(m_mainUi->titleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_mainUi->usernameEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_mainUi->passwordEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_mainUi->passwordRepeatEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_mainUi->urlEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_mainUi->expireCheck, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_mainUi->notesEnabled, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_mainUi->expireDatePicker, SIGNAL(dateTimeChanged(const QDateTime&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_mainUi->notesEdit, SIGNAL(textChanged()), this, SLOT(setUnsavedChanges()));
|
|
|
|
|
|
|
|
// Advanced tab
|
|
|
|
connect(m_advancedUi->attributesEdit, SIGNAL(textChanged()), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_advancedUi->protectAttributeButton, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_advancedUi->fgColorCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_advancedUi->bgColorCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_advancedUi->attachmentsWidget, SIGNAL(widgetUpdated()), this, SLOT(setUnsavedChanges()));
|
|
|
|
|
|
|
|
// Icon tab
|
|
|
|
connect(m_iconsWidget, SIGNAL(widgetUpdated()), this, SLOT(setUnsavedChanges()));
|
|
|
|
|
|
|
|
// Auto-Type tab
|
|
|
|
connect(m_autoTypeUi->enableButton, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_autoTypeUi->customWindowSequenceButton, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_autoTypeUi->inheritSequenceButton, SIGNAL(toggled(bool)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_autoTypeUi->customSequenceButton, SIGNAL(toggled(bool)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_autoTypeUi->windowSequenceEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_autoTypeUi->sequenceEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_autoTypeUi->windowTitleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_autoTypeUi->windowTitleCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
// Properties and History tabs don't need extra connections
|
2018-03-10 22:31:43 -05:00
|
|
|
|
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
// SSH Agent tab
|
|
|
|
if (config()->get("SSHAgent", false).toBool()) {
|
|
|
|
connect(m_sshAgentUi->attachmentRadioButton, SIGNAL(toggled(bool)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_sshAgentUi->externalFileRadioButton, SIGNAL(toggled(bool)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_sshAgentUi->attachmentComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setUnsavedChanges()));
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(
|
|
|
|
m_sshAgentUi->attachmentComboBox, SIGNAL(editTextChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
2018-03-10 22:31:43 -05:00
|
|
|
connect(m_sshAgentUi->externalFileEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_sshAgentUi->addKeyToAgentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_sshAgentUi->removeKeyFromAgentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(
|
|
|
|
m_sshAgentUi->requireUserConfirmationCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
2018-03-10 22:31:43 -05:00
|
|
|
connect(m_sshAgentUi->lifetimeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
connect(m_sshAgentUi->lifetimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setUnsavedChanges()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-05-15 14:12:05 -04:00
|
|
|
void EditEntryWidget::emitHistoryEntryActivated(const QModelIndex& index)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!m_history);
|
|
|
|
|
|
|
|
Entry* entry = m_historyModel->entryFromIndex(index);
|
2017-03-10 09:58:42 -05:00
|
|
|
emit historyEntryActivated(entry);
|
2012-05-15 14:12:05 -04:00
|
|
|
}
|
|
|
|
|
2012-06-10 10:02:03 -04:00
|
|
|
void EditEntryWidget::histEntryActivated(const QModelIndex& index)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!m_history);
|
|
|
|
|
|
|
|
QModelIndex indexMapped = m_sortModel->mapToSource(index);
|
|
|
|
if (indexMapped.isValid()) {
|
|
|
|
emitHistoryEntryActivated(indexMapped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-18 13:22:22 -04:00
|
|
|
void EditEntryWidget::updateHistoryButtons(const QModelIndex& current, const QModelIndex& previous)
|
|
|
|
{
|
|
|
|
Q_UNUSED(previous);
|
|
|
|
|
|
|
|
if (current.isValid()) {
|
|
|
|
m_historyUi->showButton->setEnabled(true);
|
2012-05-18 14:58:34 -04:00
|
|
|
m_historyUi->restoreButton->setEnabled(true);
|
2012-05-18 13:22:22 -04:00
|
|
|
m_historyUi->deleteButton->setEnabled(true);
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-05-18 13:22:22 -04:00
|
|
|
m_historyUi->showButton->setEnabled(false);
|
|
|
|
m_historyUi->restoreButton->setEnabled(false);
|
|
|
|
m_historyUi->deleteButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-29 11:17:24 -04:00
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
void EditEntryWidget::setupSSHAgent()
|
|
|
|
{
|
|
|
|
m_sshAgentUi->setupUi(m_sshAgentWidget);
|
|
|
|
|
2017-11-25 04:12:31 -05:00
|
|
|
QFont fixedFont = Font::fixedFont();
|
|
|
|
m_sshAgentUi->fingerprintTextLabel->setFont(fixedFont);
|
|
|
|
m_sshAgentUi->commentTextLabel->setFont(fixedFont);
|
|
|
|
m_sshAgentUi->publicKeyEdit->setFont(fixedFont);
|
|
|
|
|
|
|
|
connect(m_sshAgentUi->attachmentRadioButton, SIGNAL(clicked(bool)), SLOT(updateSSHAgentKeyInfo()));
|
2018-02-03 01:17:38 -05:00
|
|
|
connect(m_sshAgentUi->attachmentComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateSSHAgentAttachment()));
|
2017-11-25 04:12:31 -05:00
|
|
|
connect(m_sshAgentUi->externalFileRadioButton, SIGNAL(clicked(bool)), SLOT(updateSSHAgentKeyInfo()));
|
|
|
|
connect(m_sshAgentUi->externalFileEdit, SIGNAL(textChanged(QString)), SLOT(updateSSHAgentKeyInfo()));
|
2017-10-29 11:17:24 -04:00
|
|
|
connect(m_sshAgentUi->browseButton, SIGNAL(clicked()), SLOT(browsePrivateKey()));
|
|
|
|
connect(m_sshAgentUi->addToAgentButton, SIGNAL(clicked()), SLOT(addKeyToAgent()));
|
|
|
|
connect(m_sshAgentUi->removeFromAgentButton, SIGNAL(clicked()), SLOT(removeKeyFromAgent()));
|
|
|
|
connect(m_sshAgentUi->decryptButton, SIGNAL(clicked()), SLOT(decryptPrivateKey()));
|
|
|
|
connect(m_sshAgentUi->copyToClipboardButton, SIGNAL(clicked()), SLOT(copyPublicKey()));
|
|
|
|
|
2018-04-04 21:42:14 -04:00
|
|
|
connect(m_advancedUi->attachmentsWidget->entryAttachments(), SIGNAL(modified()), SLOT(updateSSHAgentAttachments()));
|
2018-03-07 21:35:06 -05:00
|
|
|
|
2017-10-29 11:17:24 -04:00
|
|
|
addPage(tr("SSH Agent"), FilePath::instance()->icon("apps", "utilities-terminal"), m_sshAgentWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::updateSSHAgent()
|
|
|
|
{
|
|
|
|
KeeAgentSettings settings;
|
2017-12-25 11:07:02 -05:00
|
|
|
settings.fromXml(m_advancedUi->attachmentsWidget->getAttachment("KeeAgent.settings"));
|
2017-10-29 11:17:24 -04:00
|
|
|
|
|
|
|
m_sshAgentUi->addKeyToAgentCheckBox->setChecked(settings.addAtDatabaseOpen());
|
|
|
|
m_sshAgentUi->removeKeyFromAgentCheckBox->setChecked(settings.removeAtDatabaseClose());
|
|
|
|
m_sshAgentUi->requireUserConfirmationCheckBox->setChecked(settings.useConfirmConstraintWhenAdding());
|
|
|
|
m_sshAgentUi->lifetimeCheckBox->setChecked(settings.useLifetimeConstraintWhenAdding());
|
|
|
|
m_sshAgentUi->lifetimeSpinBox->setValue(settings.lifetimeConstraintDuration());
|
2017-11-25 04:12:31 -05:00
|
|
|
m_sshAgentUi->attachmentComboBox->clear();
|
2017-10-29 11:17:24 -04:00
|
|
|
m_sshAgentUi->addToAgentButton->setEnabled(false);
|
|
|
|
m_sshAgentUi->removeFromAgentButton->setEnabled(false);
|
|
|
|
m_sshAgentUi->copyToClipboardButton->setEnabled(false);
|
|
|
|
|
2018-03-07 21:35:06 -05:00
|
|
|
m_sshAgentSettings = settings;
|
|
|
|
updateSSHAgentAttachments();
|
2017-11-25 04:12:31 -05:00
|
|
|
|
2017-10-29 11:17:24 -04:00
|
|
|
if (settings.selectedType() == "attachment") {
|
2017-11-25 04:12:31 -05:00
|
|
|
m_sshAgentUi->attachmentRadioButton->setChecked(true);
|
2017-10-29 11:17:24 -04:00
|
|
|
} else {
|
2017-11-25 04:12:31 -05:00
|
|
|
m_sshAgentUi->externalFileRadioButton->setChecked(true);
|
2017-10-29 11:17:24 -04:00
|
|
|
}
|
|
|
|
|
2017-11-25 04:12:31 -05:00
|
|
|
updateSSHAgentKeyInfo();
|
2017-10-29 11:17:24 -04:00
|
|
|
}
|
|
|
|
|
2018-02-03 01:17:38 -05:00
|
|
|
void EditEntryWidget::updateSSHAgentAttachment()
|
|
|
|
{
|
|
|
|
m_sshAgentUi->attachmentRadioButton->setChecked(true);
|
|
|
|
updateSSHAgentKeyInfo();
|
|
|
|
}
|
|
|
|
|
2018-03-07 21:35:06 -05:00
|
|
|
void EditEntryWidget::updateSSHAgentAttachments()
|
|
|
|
{
|
|
|
|
m_sshAgentUi->attachmentComboBox->clear();
|
|
|
|
m_sshAgentUi->attachmentComboBox->addItem("");
|
|
|
|
|
|
|
|
auto attachments = m_advancedUi->attachmentsWidget->entryAttachments();
|
|
|
|
for (const QString& fileName : attachments->keys()) {
|
|
|
|
if (fileName == "KeeAgent.settings") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sshAgentUi->attachmentComboBox->addItem(fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sshAgentUi->attachmentComboBox->setCurrentText(m_sshAgentSettings.attachmentName());
|
|
|
|
m_sshAgentUi->externalFileEdit->setText(m_sshAgentSettings.fileName());
|
|
|
|
}
|
|
|
|
|
2017-10-29 11:17:24 -04:00
|
|
|
void EditEntryWidget::updateSSHAgentKeyInfo()
|
|
|
|
{
|
|
|
|
m_sshAgentUi->addToAgentButton->setEnabled(false);
|
|
|
|
m_sshAgentUi->removeFromAgentButton->setEnabled(false);
|
|
|
|
m_sshAgentUi->copyToClipboardButton->setEnabled(false);
|
2017-11-25 04:12:31 -05:00
|
|
|
m_sshAgentUi->fingerprintTextLabel->setText(tr("n/a"));
|
|
|
|
m_sshAgentUi->commentTextLabel->setText(tr("n/a"));
|
2017-10-29 11:17:24 -04:00
|
|
|
m_sshAgentUi->decryptButton->setEnabled(false);
|
|
|
|
m_sshAgentUi->publicKeyEdit->document()->setPlainText("");
|
|
|
|
|
|
|
|
OpenSSHKey key;
|
|
|
|
|
|
|
|
if (!getOpenSSHKey(key)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
if (!key.fingerprint().isEmpty()) {
|
2018-07-14 08:42:28 -04:00
|
|
|
m_sshAgentUi->fingerprintTextLabel->setText(
|
|
|
|
key.fingerprint(QCryptographicHash::Md5) +
|
|
|
|
"\n" +
|
|
|
|
key.fingerprint(QCryptographicHash::Sha256)
|
|
|
|
);
|
2018-03-01 11:27:53 -05:00
|
|
|
} else {
|
|
|
|
m_sshAgentUi->fingerprintTextLabel->setText(tr("(encrypted)"));
|
|
|
|
}
|
2017-10-29 11:17:24 -04:00
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
if (!key.comment().isEmpty() || !key.encrypted()) {
|
|
|
|
m_sshAgentUi->commentTextLabel->setText(key.comment());
|
|
|
|
} else {
|
2017-11-25 04:12:31 -05:00
|
|
|
m_sshAgentUi->commentTextLabel->setText(tr("(encrypted)"));
|
2017-10-29 11:17:24 -04:00
|
|
|
m_sshAgentUi->decryptButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
if (!key.publicKey().isEmpty()) {
|
|
|
|
m_sshAgentUi->publicKeyEdit->document()->setPlainText(key.publicKey());
|
|
|
|
m_sshAgentUi->copyToClipboardButton->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
m_sshAgentUi->publicKeyEdit->document()->setPlainText(tr("(encrypted)"));
|
|
|
|
m_sshAgentUi->copyToClipboardButton->setDisabled(true);
|
|
|
|
}
|
2017-10-29 11:17:24 -04:00
|
|
|
|
|
|
|
// enable agent buttons only if we have an agent running
|
|
|
|
if (SSHAgent::instance()->isAgentRunning()) {
|
|
|
|
m_sshAgentUi->addToAgentButton->setEnabled(true);
|
|
|
|
m_sshAgentUi->removeFromAgentButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::saveSSHAgentConfig()
|
|
|
|
{
|
|
|
|
KeeAgentSettings settings;
|
2017-11-25 04:12:31 -05:00
|
|
|
QString privateKeyPath = m_sshAgentUi->attachmentComboBox->currentText();
|
2017-10-29 11:17:24 -04:00
|
|
|
|
|
|
|
settings.setAddAtDatabaseOpen(m_sshAgentUi->addKeyToAgentCheckBox->isChecked());
|
|
|
|
settings.setRemoveAtDatabaseClose(m_sshAgentUi->removeKeyFromAgentCheckBox->isChecked());
|
|
|
|
settings.setUseConfirmConstraintWhenAdding(m_sshAgentUi->requireUserConfirmationCheckBox->isChecked());
|
|
|
|
settings.setUseLifetimeConstraintWhenAdding(m_sshAgentUi->lifetimeCheckBox->isChecked());
|
|
|
|
settings.setLifetimeConstraintDuration(m_sshAgentUi->lifetimeSpinBox->value());
|
|
|
|
|
2017-11-25 04:12:31 -05:00
|
|
|
if (m_sshAgentUi->attachmentRadioButton->isChecked()) {
|
2017-10-29 11:17:24 -04:00
|
|
|
settings.setSelectedType("attachment");
|
|
|
|
} else {
|
|
|
|
settings.setSelectedType("file");
|
|
|
|
}
|
2017-11-25 04:12:31 -05:00
|
|
|
settings.setAttachmentName(m_sshAgentUi->attachmentComboBox->currentText());
|
|
|
|
settings.setFileName(m_sshAgentUi->externalFileEdit->text());
|
2017-10-29 11:17:24 -04:00
|
|
|
|
|
|
|
// we don't use this as we don't run an agent but for compatibility we set it if necessary
|
|
|
|
settings.setAllowUseOfSshKey(settings.addAtDatabaseOpen() || settings.removeAtDatabaseClose());
|
|
|
|
|
|
|
|
// we don't use this either but we don't want it to dirty flag the config
|
|
|
|
settings.setSaveAttachmentToTempFile(m_sshAgentSettings.saveAttachmentToTempFile());
|
|
|
|
|
2017-12-25 11:07:02 -05:00
|
|
|
if (settings.isDefault()) {
|
|
|
|
m_advancedUi->attachmentsWidget->removeAttachment("KeeAgent.settings");
|
2017-10-29 11:17:24 -04:00
|
|
|
} else if (settings != m_sshAgentSettings) {
|
2017-12-25 11:07:02 -05:00
|
|
|
m_advancedUi->attachmentsWidget->setAttachment("KeeAgent.settings", settings.toXml());
|
2017-10-29 11:17:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_sshAgentSettings = settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::browsePrivateKey()
|
|
|
|
{
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Select private key"), "");
|
|
|
|
if (!fileName.isEmpty()) {
|
2017-11-25 04:12:31 -05:00
|
|
|
m_sshAgentUi->externalFileEdit->setText(fileName);
|
2018-02-03 01:17:38 -05:00
|
|
|
m_sshAgentUi->externalFileRadioButton->setChecked(true);
|
|
|
|
updateSSHAgentKeyInfo();
|
2017-10-29 11:17:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
bool EditEntryWidget::getOpenSSHKey(OpenSSHKey& key, bool decrypt)
|
2017-10-29 11:17:24 -04:00
|
|
|
{
|
2018-03-07 23:43:26 -05:00
|
|
|
QString fileName;
|
2017-10-29 11:17:24 -04:00
|
|
|
QByteArray privateKeyData;
|
|
|
|
|
2017-11-25 04:12:31 -05:00
|
|
|
if (m_sshAgentUi->attachmentRadioButton->isChecked()) {
|
2018-03-07 23:43:26 -05:00
|
|
|
fileName = m_sshAgentUi->attachmentComboBox->currentText();
|
|
|
|
privateKeyData = m_advancedUi->attachmentsWidget->getAttachment(fileName);
|
2017-10-29 11:17:24 -04:00
|
|
|
} else {
|
2017-11-25 04:12:31 -05:00
|
|
|
QFile localFile(m_sshAgentUi->externalFileEdit->text());
|
2018-03-07 23:43:26 -05:00
|
|
|
QFileInfo localFileInfo(localFile);
|
|
|
|
fileName = localFileInfo.fileName();
|
2017-11-25 04:12:31 -05:00
|
|
|
|
|
|
|
if (localFile.fileName().isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-29 11:17:24 -04:00
|
|
|
|
|
|
|
if (localFile.size() > 1024 * 1024) {
|
|
|
|
showMessage(tr("File too large to be a private key"), MessageWidget::Error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!localFile.open(QIODevice::ReadOnly)) {
|
|
|
|
showMessage(tr("Failed to open private key"), MessageWidget::Error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
privateKeyData = localFile.readAll();
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
if (privateKeyData.isEmpty()) {
|
2017-11-25 04:12:31 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-29 11:17:24 -04:00
|
|
|
if (!key.parse(privateKeyData)) {
|
|
|
|
showMessage(key.errorString(), MessageWidget::Error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
if (key.encrypted() && (decrypt || key.publicKey().isEmpty())) {
|
|
|
|
if (!key.openPrivateKey(m_entry->password())) {
|
|
|
|
showMessage(key.errorString(), MessageWidget::Error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 12:00:35 -05:00
|
|
|
if (key.comment().isEmpty()) {
|
|
|
|
key.setComment(m_entry->username());
|
|
|
|
}
|
|
|
|
|
2018-03-07 23:43:26 -05:00
|
|
|
if (key.comment().isEmpty()) {
|
|
|
|
key.setComment(fileName);
|
|
|
|
}
|
|
|
|
|
2017-10-29 11:17:24 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::addKeyToAgent()
|
|
|
|
{
|
|
|
|
OpenSSHKey key;
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
if (!getOpenSSHKey(key, true)) {
|
2017-10-29 11:17:24 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
m_sshAgentUi->commentTextLabel->setText(key.comment());
|
|
|
|
m_sshAgentUi->publicKeyEdit->document()->setPlainText(key.publicKey());
|
2017-10-29 11:17:24 -04:00
|
|
|
|
|
|
|
quint32 lifetime = 0;
|
|
|
|
bool confirm = m_sshAgentUi->requireUserConfirmationCheckBox->isChecked();
|
|
|
|
|
|
|
|
if (m_sshAgentUi->lifetimeCheckBox->isChecked()) {
|
|
|
|
lifetime = m_sshAgentUi->lifetimeSpinBox->value();
|
|
|
|
}
|
|
|
|
|
2018-03-03 10:49:00 -05:00
|
|
|
if (!SSHAgent::instance()->addIdentity(key, lifetime, confirm)) {
|
|
|
|
showMessage(SSHAgent::instance()->errorString(), MessageWidget::Error);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-29 11:17:24 -04:00
|
|
|
|
|
|
|
if (m_sshAgentUi->removeKeyFromAgentCheckBox->isChecked()) {
|
|
|
|
SSHAgent::instance()->removeIdentityAtLock(key, m_entry->uuid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::removeKeyFromAgent()
|
|
|
|
{
|
|
|
|
OpenSSHKey key;
|
|
|
|
|
2018-03-03 10:49:00 -05:00
|
|
|
if (!getOpenSSHKey(key)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SSHAgent::instance()->removeIdentity(key)) {
|
|
|
|
showMessage(SSHAgent::instance()->errorString(), MessageWidget::Error);
|
|
|
|
return;
|
2017-10-29 11:17:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::decryptPrivateKey()
|
|
|
|
{
|
|
|
|
OpenSSHKey key;
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
if (!getOpenSSHKey(key, true)) {
|
2017-10-29 11:17:24 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:27:53 -05:00
|
|
|
if (!key.comment().isEmpty()) {
|
2017-11-25 04:12:31 -05:00
|
|
|
m_sshAgentUi->commentTextLabel->setText(key.comment());
|
2018-03-01 11:27:53 -05:00
|
|
|
} else {
|
|
|
|
m_sshAgentUi->commentTextLabel->setText(tr("n/a"));
|
2017-10-29 11:17:24 -04:00
|
|
|
}
|
2018-03-01 11:27:53 -05:00
|
|
|
|
2018-07-14 08:42:28 -04:00
|
|
|
m_sshAgentUi->fingerprintTextLabel->setText(
|
|
|
|
key.fingerprint(QCryptographicHash::Md5) +
|
|
|
|
"\n" +
|
|
|
|
key.fingerprint(QCryptographicHash::Sha256)
|
|
|
|
);
|
2018-03-01 11:27:53 -05:00
|
|
|
m_sshAgentUi->publicKeyEdit->document()->setPlainText(key.publicKey());
|
|
|
|
m_sshAgentUi->copyToClipboardButton->setEnabled(true);
|
2017-10-29 11:17:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::copyPublicKey()
|
|
|
|
{
|
|
|
|
clipboard()->setText(m_sshAgentUi->publicKeyEdit->document()->toPlainText());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-15 16:47:41 -04:00
|
|
|
void EditEntryWidget::useExpiryPreset(QAction* action)
|
|
|
|
{
|
|
|
|
m_mainUi->expireCheck->setChecked(true);
|
|
|
|
TimeDelta delta = action->data().value<TimeDelta>();
|
2018-09-30 08:45:06 -04:00
|
|
|
QDateTime now = Clock::currentDateTime();
|
2012-08-15 16:47:41 -04:00
|
|
|
QDateTime expiryDateTime = now + delta;
|
|
|
|
m_mainUi->expireDatePicker->setDateTime(expiryDateTime);
|
|
|
|
}
|
|
|
|
|
2017-05-28 22:58:15 -04:00
|
|
|
void EditEntryWidget::toggleHideNotes(bool visible)
|
|
|
|
{
|
|
|
|
m_mainUi->notesEdit->setVisible(visible);
|
|
|
|
m_mainUi->notesHint->setVisible(!visible);
|
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:54 -04:00
|
|
|
QString EditEntryWidget::entryTitle() const
|
|
|
|
{
|
|
|
|
if (m_entry) {
|
|
|
|
return m_entry->title();
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-10-21 15:45:54 -04:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const QString& parentName, Database* database)
|
2010-10-06 13:40:50 -04:00
|
|
|
{
|
|
|
|
m_entry = entry;
|
2012-05-13 13:02:07 -04:00
|
|
|
m_database = database;
|
2012-05-10 04:29:25 -04:00
|
|
|
m_create = create;
|
2012-05-15 14:12:05 -04:00
|
|
|
m_history = history;
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2012-05-15 14:12:05 -04:00
|
|
|
if (history) {
|
2017-06-28 19:04:23 -04:00
|
|
|
setHeadline(QString("%1 > %2").arg(parentName, tr("Entry history")));
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-05-15 14:12:05 -04:00
|
|
|
if (create) {
|
2017-06-28 19:04:23 -04:00
|
|
|
setHeadline(QString("%1 > %2").arg(parentName, tr("Add entry")));
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
|
|
|
setHeadline(QString("%1 > %2 > %3").arg(parentName, entry->title(), tr("Edit entry")));
|
2012-05-15 14:12:05 -04:00
|
|
|
}
|
2011-12-27 10:04:59 -05:00
|
|
|
}
|
2010-10-06 16:54:07 -04:00
|
|
|
|
2012-05-18 14:58:34 -04:00
|
|
|
setForms(entry);
|
2015-05-03 12:59:19 -04:00
|
|
|
setReadOnly(m_history);
|
2012-07-01 18:15:31 -04:00
|
|
|
|
2017-02-21 19:05:24 -05:00
|
|
|
setCurrentPage(0);
|
|
|
|
setPageHidden(m_historyWidget, m_history || m_entry->historyItems().count() < 1);
|
2018-03-10 22:31:43 -05:00
|
|
|
|
|
|
|
// Force the user to Save/Apply/Discard new entries
|
|
|
|
setUnsavedChanges(m_create);
|
2012-05-18 14:58:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::setForms(const Entry* entry, bool restore)
|
|
|
|
{
|
|
|
|
m_mainUi->titleEdit->setReadOnly(m_history);
|
|
|
|
m_mainUi->usernameEdit->setReadOnly(m_history);
|
|
|
|
m_mainUi->urlEdit->setReadOnly(m_history);
|
|
|
|
m_mainUi->passwordEdit->setReadOnly(m_history);
|
|
|
|
m_mainUi->passwordRepeatEdit->setReadOnly(m_history);
|
|
|
|
m_mainUi->expireCheck->setEnabled(!m_history);
|
|
|
|
m_mainUi->expireDatePicker->setReadOnly(m_history);
|
2017-10-25 10:40:14 -04:00
|
|
|
m_mainUi->notesEnabled->setChecked(!config()->get("security/hidenotes").toBool());
|
2013-03-10 14:47:08 -04:00
|
|
|
m_mainUi->notesEdit->setReadOnly(m_history);
|
2017-10-25 10:40:14 -04:00
|
|
|
m_mainUi->notesEdit->setVisible(!config()->get("security/hidenotes").toBool());
|
|
|
|
m_mainUi->notesHint->setVisible(config()->get("security/hidenotes").toBool());
|
2016-12-01 23:13:27 -05:00
|
|
|
m_mainUi->togglePasswordGeneratorButton->setChecked(false);
|
|
|
|
m_mainUi->togglePasswordGeneratorButton->setDisabled(m_history);
|
2018-09-25 20:44:19 -04:00
|
|
|
m_mainUi->passwordGenerator->reset(entry->password().length());
|
2017-12-19 08:36:09 -05:00
|
|
|
|
|
|
|
m_advancedUi->attachmentsWidget->setReadOnly(m_history);
|
2012-05-18 14:58:34 -04:00
|
|
|
m_advancedUi->addAttributeButton->setEnabled(!m_history);
|
2012-05-15 14:12:05 -04:00
|
|
|
m_advancedUi->editAttributeButton->setEnabled(false);
|
|
|
|
m_advancedUi->removeAttributeButton->setEnabled(false);
|
2012-05-18 14:58:34 -04:00
|
|
|
m_advancedUi->attributesEdit->setReadOnly(m_history);
|
2012-05-15 14:12:05 -04:00
|
|
|
QAbstractItemView::EditTriggers editTriggers;
|
2012-05-18 14:58:34 -04:00
|
|
|
if (m_history) {
|
2012-05-15 14:12:05 -04:00
|
|
|
editTriggers = QAbstractItemView::NoEditTriggers;
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-05-15 14:12:05 -04:00
|
|
|
editTriggers = QAbstractItemView::DoubleClicked;
|
|
|
|
}
|
|
|
|
m_advancedUi->attributesView->setEditTriggers(editTriggers);
|
2018-02-19 14:59:04 -05:00
|
|
|
setupColorButton(true, entry->foregroundColor());
|
|
|
|
setupColorButton(false, entry->backgroundColor());
|
2012-05-18 14:58:34 -04:00
|
|
|
m_iconsWidget->setEnabled(!m_history);
|
2012-07-23 06:42:05 -04:00
|
|
|
m_autoTypeUi->sequenceEdit->setReadOnly(m_history);
|
2012-07-16 11:40:28 -04:00
|
|
|
m_autoTypeUi->windowTitleCombo->lineEdit()->setReadOnly(m_history);
|
|
|
|
m_autoTypeUi->windowSequenceEdit->setReadOnly(m_history);
|
2012-05-18 14:58:34 -04:00
|
|
|
m_historyWidget->setEnabled(!m_history);
|
2012-05-15 14:12:05 -04:00
|
|
|
|
2010-10-06 13:40:50 -04:00
|
|
|
m_mainUi->titleEdit->setText(entry->title());
|
|
|
|
m_mainUi->usernameEdit->setText(entry->username());
|
|
|
|
m_mainUi->urlEdit->setText(entry->url());
|
2012-01-07 10:18:21 -05:00
|
|
|
m_mainUi->passwordEdit->setText(entry->password());
|
|
|
|
m_mainUi->passwordRepeatEdit->setText(entry->password());
|
|
|
|
m_mainUi->expireCheck->setChecked(entry->timeInfo().expires());
|
2012-04-18 09:29:04 -04:00
|
|
|
m_mainUi->expireDatePicker->setDateTime(entry->timeInfo().expiryTime().toLocalTime());
|
2012-08-15 16:47:41 -04:00
|
|
|
m_mainUi->expirePresets->setEnabled(!m_history);
|
2014-01-12 11:23:47 -05:00
|
|
|
m_mainUi->togglePasswordButton->setChecked(config()->get("security/passwordscleartext").toBool());
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2013-03-10 14:47:08 -04:00
|
|
|
m_mainUi->notesEdit->setPlainText(entry->notes());
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2017-12-19 08:36:09 -05:00
|
|
|
m_advancedUi->attachmentsWidget->setEntryAttachments(entry->attachments());
|
2012-05-15 14:12:05 -04:00
|
|
|
m_entryAttributes->copyCustomKeysFrom(entry->attributes());
|
2012-04-23 17:19:29 -04:00
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
if (m_attributesModel->rowCount() != 0) {
|
|
|
|
m_advancedUi->attributesView->setCurrentIndex(m_attributesModel->index(0, 0));
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-04-30 12:22:02 -04:00
|
|
|
m_advancedUi->attributesEdit->setPlainText("");
|
2012-04-28 13:11:15 -04:00
|
|
|
m_advancedUi->attributesEdit->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2017-03-07 22:38:18 -05:00
|
|
|
QList<int> sizes = m_advancedUi->attributesSplitter->sizes();
|
|
|
|
sizes.replace(0, m_advancedUi->attributesSplitter->width() * 0.3);
|
|
|
|
sizes.replace(1, m_advancedUi->attributesSplitter->width() * 0.7);
|
|
|
|
m_advancedUi->attributesSplitter->setSizes(sizes);
|
|
|
|
|
2012-05-15 09:30:00 -04:00
|
|
|
IconStruct iconStruct;
|
|
|
|
iconStruct.uuid = entry->iconUuid();
|
|
|
|
iconStruct.number = entry->iconNumber();
|
2017-06-29 13:54:49 -04:00
|
|
|
m_iconsWidget->load(entry->uuid(), m_database, iconStruct, entry->webUrl());
|
2016-10-05 23:10:06 -04:00
|
|
|
connect(m_mainUi->urlEdit, SIGNAL(textChanged(QString)), m_iconsWidget, SLOT(setUrl(QString)));
|
2012-05-18 14:15:02 -04:00
|
|
|
|
2012-07-16 11:40:28 -04:00
|
|
|
m_autoTypeUi->enableButton->setChecked(entry->autoTypeEnabled());
|
|
|
|
if (entry->defaultAutoTypeSequence().isEmpty()) {
|
|
|
|
m_autoTypeUi->inheritSequenceButton->setChecked(true);
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-07-16 11:40:28 -04:00
|
|
|
m_autoTypeUi->customSequenceButton->setChecked(true);
|
|
|
|
}
|
2016-11-11 16:26:07 -05:00
|
|
|
m_autoTypeUi->sequenceEdit->setText(entry->effectiveAutoTypeSequence());
|
2012-10-21 06:47:30 -04:00
|
|
|
m_autoTypeUi->windowTitleCombo->lineEdit()->clear();
|
2018-01-18 18:50:22 -05:00
|
|
|
m_autoTypeUi->customWindowSequenceButton->setChecked(false);
|
2012-10-21 06:47:30 -04:00
|
|
|
m_autoTypeUi->windowSequenceEdit->setText("");
|
|
|
|
m_autoTypeAssoc->copyDataFrom(entry->autoTypeAssociations());
|
2017-10-06 11:22:59 -04:00
|
|
|
m_autoTypeAssocModel->setEntry(entry);
|
2012-07-16 11:40:28 -04:00
|
|
|
if (m_autoTypeAssoc->size() != 0) {
|
|
|
|
m_autoTypeUi->assocView->setCurrentIndex(m_autoTypeAssocModel->index(0, 0));
|
|
|
|
}
|
2012-07-20 06:08:09 -04:00
|
|
|
if (!m_history) {
|
|
|
|
m_autoTypeUi->windowTitleCombo->refreshWindowList();
|
|
|
|
}
|
2012-07-20 04:28:18 -04:00
|
|
|
updateAutoTypeEnabled();
|
2012-07-16 11:40:28 -04:00
|
|
|
|
2017-10-29 11:17:24 -04:00
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
if (m_sshAgentEnabled) {
|
|
|
|
updateSSHAgent();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-29 17:41:37 -04:00
|
|
|
m_editWidgetProperties->setFields(entry->timeInfo(), entry->uuid());
|
2018-02-06 10:37:06 -05:00
|
|
|
m_editWidgetProperties->setCustomData(entry->customData());
|
2012-10-29 17:41:37 -04:00
|
|
|
|
2012-05-18 14:58:34 -04:00
|
|
|
if (!m_history && !restore) {
|
|
|
|
m_historyModel->setEntries(entry->historyItems());
|
2012-05-30 10:37:46 -04:00
|
|
|
m_historyUi->historyView->sortByColumn(0, Qt::DescendingOrder);
|
2012-05-18 14:58:34 -04:00
|
|
|
}
|
|
|
|
if (m_historyModel->rowCount() > 0) {
|
|
|
|
m_historyUi->deleteAllButton->setEnabled(true);
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-05-18 14:58:34 -04:00
|
|
|
m_historyUi->deleteAllButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateHistoryButtons(m_historyUi->historyView->currentIndex(), QModelIndex());
|
|
|
|
|
|
|
|
m_mainUi->titleEdit->setFocus();
|
2010-10-06 13:40:50 -04:00
|
|
|
}
|
|
|
|
|
2018-02-17 22:16:45 -05:00
|
|
|
/**
|
|
|
|
* Commit the form values to in-memory database representation
|
|
|
|
*
|
|
|
|
* @return true is commit successful, otherwise false
|
|
|
|
*/
|
|
|
|
bool EditEntryWidget::commitEntry()
|
2010-10-06 13:40:50 -04:00
|
|
|
{
|
2012-05-15 14:12:05 -04:00
|
|
|
if (m_history) {
|
2015-05-03 12:58:44 -04:00
|
|
|
clear();
|
2015-01-19 20:27:56 -05:00
|
|
|
hideMessage();
|
2017-03-10 09:58:42 -05:00
|
|
|
emit editFinished(false);
|
2018-02-17 22:16:45 -05:00
|
|
|
return true;
|
2012-05-15 14:12:05 -04:00
|
|
|
}
|
|
|
|
|
2012-04-17 10:04:49 -04:00
|
|
|
if (!passwordsEqual()) {
|
2015-01-21 11:19:05 -05:00
|
|
|
showMessage(tr("Different passwords supplied."), MessageWidget::Error);
|
2018-02-17 22:16:45 -05:00
|
|
|
return false;
|
2012-04-17 10:04:49 -04:00
|
|
|
}
|
2012-04-23 15:06:04 -04:00
|
|
|
|
2018-02-17 22:16:45 -05:00
|
|
|
// Ask the user to apply the generator password, if open
|
2018-03-31 16:01:30 -04:00
|
|
|
if (m_mainUi->togglePasswordGeneratorButton->isChecked()
|
|
|
|
&& m_mainUi->passwordGenerator->getGeneratedPassword() != m_mainUi->passwordEdit->text()) {
|
|
|
|
auto answer = MessageBox::question(this,
|
|
|
|
tr("Apply generated password?"),
|
|
|
|
tr("Do you want to apply the generated password to this entry?"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::Yes);
|
2018-02-17 22:16:45 -05:00
|
|
|
if (answer == QMessageBox::Yes) {
|
|
|
|
m_mainUi->passwordGenerator->applyPassword();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide the password generator
|
|
|
|
m_mainUi->togglePasswordGeneratorButton->setChecked(false);
|
|
|
|
|
2017-03-07 22:38:18 -05:00
|
|
|
if (m_advancedUi->attributesView->currentIndex().isValid() && m_advancedUi->attributesEdit->isEnabled()) {
|
2012-04-28 13:11:15 -04:00
|
|
|
QString key = m_attributesModel->keyByIndex(m_advancedUi->attributesView->currentIndex());
|
2018-03-31 16:01:30 -04:00
|
|
|
m_entryAttributes->set(key, m_advancedUi->attributesEdit->toPlainText(), m_entryAttributes->isProtected(key));
|
2012-04-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_currentAttribute = QPersistentModelIndex();
|
|
|
|
|
2012-05-18 13:22:22 -04:00
|
|
|
// must stand before beginUpdate()
|
|
|
|
// we don't want to create a new history item, if only the history has changed
|
|
|
|
m_entry->removeHistoryItems(m_historyModel->deletedEntries());
|
2017-07-30 13:38:10 -04:00
|
|
|
m_historyModel->clearDeletedEntries();
|
2012-05-18 13:22:22 -04:00
|
|
|
|
2016-07-31 18:04:09 -04:00
|
|
|
m_autoTypeAssoc->removeEmpty();
|
|
|
|
|
2017-10-29 11:17:24 -04:00
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
if (m_sshAgentEnabled) {
|
|
|
|
saveSSHAgentConfig();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-05-10 04:29:25 -04:00
|
|
|
if (!m_create) {
|
|
|
|
m_entry->beginUpdate();
|
|
|
|
}
|
2012-04-23 15:06:04 -04:00
|
|
|
|
2016-07-31 18:04:09 -04:00
|
|
|
updateEntryData(m_entry);
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(false);
|
2016-07-31 18:04:09 -04:00
|
|
|
|
|
|
|
if (!m_create) {
|
|
|
|
m_entry->endUpdate();
|
|
|
|
}
|
2017-10-29 11:17:24 -04:00
|
|
|
|
|
|
|
#ifdef WITH_XC_SSHAGENT
|
|
|
|
if (m_sshAgentEnabled) {
|
|
|
|
updateSSHAgent();
|
|
|
|
}
|
|
|
|
#endif
|
2018-02-17 22:16:45 -05:00
|
|
|
|
2018-02-25 12:58:54 -05:00
|
|
|
m_historyModel->setEntries(m_entry->historyItems());
|
|
|
|
|
2018-02-17 22:16:45 -05:00
|
|
|
showMessage(tr("Entry updated successfully."), MessageWidget::Positive);
|
|
|
|
return true;
|
2017-06-13 20:55:53 -04:00
|
|
|
}
|
2016-07-31 18:04:09 -04:00
|
|
|
|
2017-06-13 20:55:53 -04:00
|
|
|
void EditEntryWidget::acceptEntry()
|
|
|
|
{
|
2018-02-17 22:16:45 -05:00
|
|
|
if (commitEntry()) {
|
|
|
|
clear();
|
|
|
|
emit editFinished(true);
|
2017-09-29 12:24:14 -04:00
|
|
|
}
|
2016-07-31 18:04:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::updateEntryData(Entry* entry) const
|
|
|
|
{
|
2018-02-25 14:17:43 -05:00
|
|
|
QRegularExpression newLineRegex("(?:\r?\n|\r)");
|
|
|
|
|
2017-01-28 08:18:43 -05:00
|
|
|
entry->attributes()->copyCustomKeysFrom(m_entryAttributes);
|
2017-12-19 08:36:09 -05:00
|
|
|
entry->attachments()->copyDataFrom(m_advancedUi->attachmentsWidget->entryAttachments());
|
2018-02-06 10:37:06 -05:00
|
|
|
entry->customData()->copyDataFrom(m_editWidgetProperties->customData());
|
2018-02-25 14:17:43 -05:00
|
|
|
entry->setTitle(m_mainUi->titleEdit->text().replace(newLineRegex, " "));
|
|
|
|
entry->setUsername(m_mainUi->usernameEdit->text().replace(newLineRegex, " "));
|
|
|
|
entry->setUrl(m_mainUi->urlEdit->text().replace(newLineRegex, " "));
|
2016-07-31 18:04:09 -04:00
|
|
|
entry->setPassword(m_mainUi->passwordEdit->text());
|
|
|
|
entry->setExpires(m_mainUi->expireCheck->isChecked());
|
|
|
|
entry->setExpiryTime(m_mainUi->expireDatePicker->dateTime().toUTC());
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2016-07-31 18:04:09 -04:00
|
|
|
entry->setNotes(m_mainUi->notesEdit->toPlainText());
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
if (m_advancedUi->fgColorCheckBox->isChecked() && m_advancedUi->fgColorButton->property("color").isValid()) {
|
2018-02-19 14:59:04 -05:00
|
|
|
entry->setForegroundColor(QColor(m_advancedUi->fgColorButton->property("color").toString()));
|
|
|
|
} else {
|
|
|
|
entry->setForegroundColor(QColor());
|
|
|
|
}
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
if (m_advancedUi->bgColorCheckBox->isChecked() && m_advancedUi->bgColorButton->property("color").isValid()) {
|
2018-02-19 14:59:04 -05:00
|
|
|
entry->setBackgroundColor(QColor(m_advancedUi->bgColorButton->property("color").toString()));
|
|
|
|
} else {
|
|
|
|
entry->setBackgroundColor(QColor());
|
|
|
|
}
|
|
|
|
|
2016-07-31 17:53:26 -04:00
|
|
|
IconStruct iconStruct = m_iconsWidget->state();
|
2012-05-15 09:30:00 -04:00
|
|
|
|
2012-05-15 10:50:42 -04:00
|
|
|
if (iconStruct.number < 0) {
|
2016-07-31 18:04:09 -04:00
|
|
|
entry->setIcon(Entry::DefaultIconNumber);
|
2018-02-19 14:59:04 -05:00
|
|
|
} else if (iconStruct.uuid.isNull()) {
|
2016-07-31 18:04:09 -04:00
|
|
|
entry->setIcon(iconStruct.number);
|
2018-02-19 14:59:04 -05:00
|
|
|
} else {
|
2016-07-31 18:04:09 -04:00
|
|
|
entry->setIcon(iconStruct.uuid);
|
2012-05-09 04:46:22 -04:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:04:09 -04:00
|
|
|
entry->setAutoTypeEnabled(m_autoTypeUi->enableButton->isChecked());
|
2012-10-21 06:47:30 -04:00
|
|
|
if (m_autoTypeUi->inheritSequenceButton->isChecked()) {
|
2016-07-31 18:04:09 -04:00
|
|
|
entry->setDefaultAutoTypeSequence(QString());
|
2018-02-19 14:59:04 -05:00
|
|
|
} else if (AutoType::verifyAutoTypeSyntax(m_autoTypeUi->sequenceEdit->text())) {
|
|
|
|
entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text());
|
2012-05-10 04:29:25 -04:00
|
|
|
}
|
2012-04-23 15:06:04 -04:00
|
|
|
|
2016-07-31 18:04:09 -04:00
|
|
|
entry->autoTypeAssociations()->copyDataFrom(m_autoTypeAssoc);
|
2010-10-06 13:40:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::cancel()
|
|
|
|
{
|
2012-05-15 14:12:05 -04:00
|
|
|
if (m_history) {
|
2015-01-11 10:20:59 -05:00
|
|
|
clear();
|
2015-01-19 20:27:56 -05:00
|
|
|
hideMessage();
|
2017-03-10 09:58:42 -05:00
|
|
|
emit editFinished(false);
|
2015-05-03 12:48:58 -04:00
|
|
|
return;
|
2012-05-15 14:12:05 -04:00
|
|
|
}
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
if (!m_entry->iconUuid().isNull() && !m_database->metadata()->containsCustomIcon(m_entry->iconUuid())) {
|
2012-05-15 10:50:42 -04:00
|
|
|
m_entry->setIcon(Entry::DefaultIconNumber);
|
|
|
|
}
|
|
|
|
|
2018-03-17 17:31:15 -04:00
|
|
|
if (!m_saved) {
|
2018-03-31 16:01:30 -04:00
|
|
|
auto result = MessageBox::question(this,
|
|
|
|
QString(),
|
|
|
|
tr("Entry has unsaved changes"),
|
2018-03-17 17:31:15 -04:00
|
|
|
QMessageBox::Cancel | QMessageBox::Save | QMessageBox::Discard,
|
|
|
|
QMessageBox::Cancel);
|
|
|
|
if (result == QMessageBox::Cancel) {
|
2018-09-25 20:44:19 -04:00
|
|
|
m_mainUi->passwordGenerator->reset();
|
2018-03-17 17:31:15 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (result == QMessageBox::Save) {
|
|
|
|
commitEntry();
|
|
|
|
m_saved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:20:59 -05:00
|
|
|
clear();
|
|
|
|
|
2017-10-28 09:23:45 -04:00
|
|
|
emit editFinished(m_saved);
|
2015-01-11 10:20:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::clear()
|
|
|
|
{
|
2015-07-24 12:28:12 -04:00
|
|
|
m_entry = nullptr;
|
|
|
|
m_database = nullptr;
|
2012-04-28 13:11:15 -04:00
|
|
|
m_entryAttributes->clear();
|
2017-12-19 08:36:09 -05:00
|
|
|
m_advancedUi->attachmentsWidget->clearAttachments();
|
2012-07-16 11:40:28 -04:00
|
|
|
m_autoTypeAssoc->clear();
|
2012-05-15 14:12:05 -04:00
|
|
|
m_historyModel->clear();
|
2016-07-31 17:53:26 -04:00
|
|
|
m_iconsWidget->reset();
|
2015-01-19 20:27:56 -05:00
|
|
|
hideMessage();
|
2010-10-06 13:40:50 -04:00
|
|
|
}
|
2012-01-07 10:18:21 -05:00
|
|
|
|
2016-07-31 18:22:04 -04:00
|
|
|
bool EditEntryWidget::hasBeenModified() const
|
|
|
|
{
|
|
|
|
// entry has been modified if a history item is to be deleted
|
|
|
|
if (!m_historyModel->deletedEntries().isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if updating the entry would modify it
|
|
|
|
QScopedPointer<Entry> entry(new Entry());
|
|
|
|
entry->copyDataFrom(m_entry);
|
|
|
|
|
|
|
|
entry->beginUpdate();
|
|
|
|
updateEntryData(entry.data());
|
|
|
|
return entry->endUpdate();
|
|
|
|
}
|
|
|
|
|
2013-03-10 17:23:10 -04:00
|
|
|
void EditEntryWidget::togglePasswordGeneratorButton(bool checked)
|
|
|
|
{
|
2016-08-06 05:29:47 -04:00
|
|
|
m_mainUi->passwordGenerator->regeneratePassword();
|
2013-03-10 17:23:10 -04:00
|
|
|
m_mainUi->passwordGenerator->setVisible(checked);
|
|
|
|
}
|
|
|
|
|
2012-04-17 10:04:49 -04:00
|
|
|
bool EditEntryWidget::passwordsEqual()
|
|
|
|
{
|
|
|
|
return m_mainUi->passwordEdit->text() == m_mainUi->passwordRepeatEdit->text();
|
|
|
|
}
|
|
|
|
|
2013-03-12 17:42:06 -04:00
|
|
|
void EditEntryWidget::setGeneratedPassword(const QString& password)
|
|
|
|
{
|
|
|
|
m_mainUi->passwordEdit->setText(password);
|
|
|
|
m_mainUi->passwordRepeatEdit->setText(password);
|
|
|
|
|
2016-12-01 23:13:27 -05:00
|
|
|
m_mainUi->togglePasswordGeneratorButton->setChecked(false);
|
2013-03-12 17:42:06 -04:00
|
|
|
}
|
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
void EditEntryWidget::insertAttribute()
|
|
|
|
{
|
2012-05-15 14:12:05 -04:00
|
|
|
Q_ASSERT(!m_history);
|
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
QString name = tr("New attribute");
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
while (m_entryAttributes->keys().contains(name)) {
|
2018-03-13 15:59:08 -04:00
|
|
|
name = tr("New attribute %1").arg(i);
|
2012-04-28 13:11:15 -04:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_entryAttributes->set(name, "");
|
|
|
|
QModelIndex index = m_attributesModel->indexByKey(name);
|
|
|
|
|
|
|
|
m_advancedUi->attributesView->setCurrentIndex(index);
|
|
|
|
m_advancedUi->attributesView->edit(index);
|
2018-03-10 22:31:43 -05:00
|
|
|
|
|
|
|
setUnsavedChanges(true);
|
2012-04-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::editCurrentAttribute()
|
|
|
|
{
|
2012-05-15 14:12:05 -04:00
|
|
|
Q_ASSERT(!m_history);
|
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
QModelIndex index = m_advancedUi->attributesView->currentIndex();
|
|
|
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
m_advancedUi->attributesView->edit(index);
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(true);
|
2012-04-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::removeCurrentAttribute()
|
|
|
|
{
|
2012-05-15 14:12:05 -04:00
|
|
|
Q_ASSERT(!m_history);
|
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
QModelIndex index = m_advancedUi->attributesView->currentIndex();
|
|
|
|
|
|
|
|
if (index.isValid()) {
|
2018-03-31 16:01:30 -04:00
|
|
|
if (MessageBox::question(this,
|
|
|
|
tr("Confirm Remove"),
|
|
|
|
tr("Are you sure you want to remove this attribute?"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No)
|
|
|
|
== QMessageBox::Yes) {
|
2017-03-07 22:38:18 -05:00
|
|
|
m_entryAttributes->remove(m_attributesModel->keyByIndex(index));
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(true);
|
2017-03-07 22:38:18 -05:00
|
|
|
}
|
2012-04-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::updateCurrentAttribute()
|
|
|
|
{
|
|
|
|
QModelIndex newIndex = m_advancedUi->attributesView->currentIndex();
|
2017-03-07 22:38:18 -05:00
|
|
|
QString newKey = m_attributesModel->keyByIndex(newIndex);
|
2012-04-28 13:11:15 -04:00
|
|
|
|
2017-03-07 22:38:18 -05:00
|
|
|
if (!m_history && m_currentAttribute != newIndex) {
|
|
|
|
// Save changes to the currently selected attribute if editing is enabled
|
|
|
|
if (m_currentAttribute.isValid() && m_advancedUi->attributesEdit->isEnabled()) {
|
|
|
|
QString currKey = m_attributesModel->keyByIndex(m_currentAttribute);
|
2018-03-31 16:01:30 -04:00
|
|
|
m_entryAttributes->set(
|
|
|
|
currKey, m_advancedUi->attributesEdit->toPlainText(), m_entryAttributes->isProtected(currKey));
|
|
|
|
}
|
2017-03-07 22:38:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
displayAttribute(newIndex, m_entryAttributes->isProtected(newKey));
|
|
|
|
|
|
|
|
m_currentAttribute = newIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::displayAttribute(QModelIndex index, bool showProtected)
|
|
|
|
{
|
|
|
|
// Block signals to prevent extra calls
|
|
|
|
m_advancedUi->protectAttributeButton->blockSignals(true);
|
|
|
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
QString key = m_attributesModel->keyByIndex(index);
|
|
|
|
if (showProtected) {
|
2018-03-13 15:59:08 -04:00
|
|
|
m_advancedUi->attributesEdit->setPlainText(tr("[PROTECTED] Press reveal to view or edit"));
|
2017-03-07 22:38:18 -05:00
|
|
|
m_advancedUi->attributesEdit->setEnabled(false);
|
|
|
|
m_advancedUi->revealAttributeButton->setEnabled(true);
|
|
|
|
m_advancedUi->protectAttributeButton->setChecked(true);
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2017-03-07 22:38:18 -05:00
|
|
|
m_advancedUi->attributesEdit->setPlainText(m_entryAttributes->value(key));
|
|
|
|
m_advancedUi->attributesEdit->setEnabled(true);
|
|
|
|
m_advancedUi->revealAttributeButton->setEnabled(false);
|
|
|
|
m_advancedUi->protectAttributeButton->setChecked(false);
|
2012-04-28 13:11:15 -04:00
|
|
|
}
|
2017-03-07 22:38:18 -05:00
|
|
|
|
|
|
|
// Don't allow editing in history view
|
|
|
|
m_advancedUi->protectAttributeButton->setEnabled(!m_history);
|
|
|
|
m_advancedUi->editAttributeButton->setEnabled(!m_history);
|
|
|
|
m_advancedUi->removeAttributeButton->setEnabled(!m_history);
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2017-03-07 22:38:18 -05:00
|
|
|
m_advancedUi->attributesEdit->setPlainText("");
|
|
|
|
m_advancedUi->attributesEdit->setEnabled(false);
|
|
|
|
m_advancedUi->revealAttributeButton->setEnabled(false);
|
|
|
|
m_advancedUi->protectAttributeButton->setChecked(false);
|
|
|
|
m_advancedUi->protectAttributeButton->setEnabled(false);
|
|
|
|
m_advancedUi->editAttributeButton->setEnabled(false);
|
|
|
|
m_advancedUi->removeAttributeButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_advancedUi->protectAttributeButton->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::protectCurrentAttribute(bool state)
|
|
|
|
{
|
|
|
|
QModelIndex index = m_advancedUi->attributesView->currentIndex();
|
|
|
|
if (!m_history && index.isValid()) {
|
|
|
|
QString key = m_attributesModel->keyByIndex(index);
|
|
|
|
if (state) {
|
|
|
|
// Save the current text and protect the attribute
|
|
|
|
m_entryAttributes->set(key, m_advancedUi->attributesEdit->toPlainText(), true);
|
|
|
|
} else {
|
|
|
|
// Unprotect the current attribute value (don't save text as it is obscured)
|
|
|
|
m_entryAttributes->set(key, m_entryAttributes->value(key), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the attribute
|
|
|
|
displayAttribute(index, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::revealCurrentAttribute()
|
|
|
|
{
|
2018-03-31 16:01:30 -04:00
|
|
|
if (!m_advancedUi->attributesEdit->isEnabled()) {
|
2017-03-07 22:38:18 -05:00
|
|
|
QModelIndex index = m_advancedUi->attributesView->currentIndex();
|
|
|
|
if (index.isValid()) {
|
2018-03-10 22:31:43 -05:00
|
|
|
bool oldBlockSignals = m_advancedUi->attributesEdit->blockSignals(true);
|
2017-03-07 22:38:18 -05:00
|
|
|
QString key = m_attributesModel->keyByIndex(index);
|
|
|
|
m_advancedUi->attributesEdit->setPlainText(m_entryAttributes->value(key));
|
|
|
|
m_advancedUi->attributesEdit->setEnabled(true);
|
2018-03-10 22:31:43 -05:00
|
|
|
m_advancedUi->attributesEdit->blockSignals(oldBlockSignals);
|
2012-05-15 14:12:05 -04:00
|
|
|
}
|
2012-04-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
}
|
2012-05-02 05:11:28 -04:00
|
|
|
|
2012-07-20 04:28:18 -04:00
|
|
|
void EditEntryWidget::updateAutoTypeEnabled()
|
2012-07-16 11:40:28 -04:00
|
|
|
{
|
2012-07-20 04:28:18 -04:00
|
|
|
bool autoTypeEnabled = m_autoTypeUi->enableButton->isChecked();
|
|
|
|
bool validIndex = m_autoTypeUi->assocView->currentIndex().isValid() && m_autoTypeAssoc->size() != 0;
|
|
|
|
|
|
|
|
m_autoTypeUi->enableButton->setEnabled(!m_history);
|
|
|
|
m_autoTypeUi->inheritSequenceButton->setEnabled(!m_history && autoTypeEnabled);
|
|
|
|
m_autoTypeUi->customSequenceButton->setEnabled(!m_history && autoTypeEnabled);
|
|
|
|
m_autoTypeUi->sequenceEdit->setEnabled(autoTypeEnabled && m_autoTypeUi->customSequenceButton->isChecked());
|
|
|
|
|
|
|
|
m_autoTypeUi->assocView->setEnabled(autoTypeEnabled);
|
|
|
|
m_autoTypeUi->assocAddButton->setEnabled(!m_history);
|
|
|
|
m_autoTypeUi->assocRemoveButton->setEnabled(!m_history && validIndex);
|
|
|
|
|
|
|
|
m_autoTypeUi->windowTitleLabel->setEnabled(autoTypeEnabled && validIndex);
|
|
|
|
m_autoTypeUi->windowTitleCombo->setEnabled(autoTypeEnabled && validIndex);
|
|
|
|
m_autoTypeUi->customWindowSequenceButton->setEnabled(!m_history && autoTypeEnabled && validIndex);
|
|
|
|
m_autoTypeUi->windowSequenceEdit->setEnabled(autoTypeEnabled && validIndex
|
|
|
|
&& m_autoTypeUi->customWindowSequenceButton->isChecked());
|
2012-07-16 11:40:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::insertAutoTypeAssoc()
|
|
|
|
{
|
|
|
|
AutoTypeAssociations::Association assoc;
|
|
|
|
m_autoTypeAssoc->add(assoc);
|
2012-07-20 04:28:18 -04:00
|
|
|
QModelIndex newIndex = m_autoTypeAssocModel->index(m_autoTypeAssoc->size() - 1, 0);
|
|
|
|
m_autoTypeUi->assocView->setCurrentIndex(newIndex);
|
|
|
|
loadCurrentAssoc(newIndex);
|
|
|
|
m_autoTypeUi->windowTitleCombo->setFocus();
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(true);
|
2012-07-16 11:40:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::removeAutoTypeAssoc()
|
|
|
|
{
|
|
|
|
QModelIndex currentIndex = m_autoTypeUi->assocView->currentIndex();
|
|
|
|
|
|
|
|
if (currentIndex.isValid()) {
|
|
|
|
m_autoTypeAssoc->remove(currentIndex.row());
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(true);
|
2012-07-16 11:40:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::loadCurrentAssoc(const QModelIndex& current)
|
|
|
|
{
|
2012-07-20 04:28:18 -04:00
|
|
|
if (current.isValid() && current.row() < m_autoTypeAssoc->size()) {
|
2012-07-16 11:40:28 -04:00
|
|
|
AutoTypeAssociations::Association assoc = m_autoTypeAssoc->get(current.row());
|
|
|
|
m_autoTypeUi->windowTitleCombo->setEditText(assoc.window);
|
|
|
|
if (assoc.sequence.isEmpty()) {
|
2018-01-18 18:50:22 -05:00
|
|
|
m_autoTypeUi->customWindowSequenceButton->setChecked(false);
|
|
|
|
m_autoTypeUi->windowSequenceEdit->setText(m_entry->effectiveAutoTypeSequence());
|
|
|
|
} else {
|
2012-07-16 11:40:28 -04:00
|
|
|
m_autoTypeUi->customWindowSequenceButton->setChecked(true);
|
2018-01-18 18:50:22 -05:00
|
|
|
m_autoTypeUi->windowSequenceEdit->setText(assoc.sequence);
|
2012-07-16 11:40:28 -04:00
|
|
|
}
|
2012-07-20 04:28:18 -04:00
|
|
|
|
|
|
|
updateAutoTypeEnabled();
|
2018-01-18 18:50:22 -05:00
|
|
|
} else {
|
2012-07-16 11:40:28 -04:00
|
|
|
clearCurrentAssoc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::clearCurrentAssoc()
|
|
|
|
{
|
|
|
|
m_autoTypeUi->windowTitleCombo->setEditText("");
|
2012-07-20 04:28:18 -04:00
|
|
|
|
2018-01-18 18:50:22 -05:00
|
|
|
m_autoTypeUi->customWindowSequenceButton->setChecked(false);
|
2012-07-16 11:40:28 -04:00
|
|
|
m_autoTypeUi->windowSequenceEdit->setText("");
|
2012-07-20 04:28:18 -04:00
|
|
|
|
|
|
|
updateAutoTypeEnabled();
|
2012-07-16 11:40:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::applyCurrentAssoc()
|
|
|
|
{
|
|
|
|
QModelIndex index = m_autoTypeUi->assocView->currentIndex();
|
|
|
|
|
|
|
|
if (!index.isValid() || m_autoTypeAssoc->size() == 0 || m_history) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoTypeAssociations::Association assoc;
|
|
|
|
assoc.window = m_autoTypeUi->windowTitleCombo->currentText();
|
|
|
|
if (m_autoTypeUi->customWindowSequenceButton->isChecked()) {
|
|
|
|
assoc.sequence = m_autoTypeUi->windowSequenceEdit->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_autoTypeAssoc->update(index.row(), assoc);
|
|
|
|
}
|
|
|
|
|
2012-05-18 13:22:22 -04:00
|
|
|
void EditEntryWidget::showHistoryEntry()
|
|
|
|
{
|
2012-06-10 10:02:03 -04:00
|
|
|
QModelIndex index = m_sortModel->mapToSource(m_historyUi->historyView->currentIndex());
|
2012-05-18 13:22:22 -04:00
|
|
|
if (index.isValid()) {
|
|
|
|
emitHistoryEntryActivated(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-18 14:58:34 -04:00
|
|
|
void EditEntryWidget::restoreHistoryEntry()
|
|
|
|
{
|
2012-06-10 10:02:03 -04:00
|
|
|
QModelIndex index = m_sortModel->mapToSource(m_historyUi->historyView->currentIndex());
|
2012-05-18 14:58:34 -04:00
|
|
|
if (index.isValid()) {
|
|
|
|
setForms(m_historyModel->entryFromIndex(index), true);
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(true);
|
2012-05-18 14:58:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-18 13:22:22 -04:00
|
|
|
void EditEntryWidget::deleteHistoryEntry()
|
|
|
|
{
|
2012-06-10 10:02:03 -04:00
|
|
|
QModelIndex index = m_sortModel->mapToSource(m_historyUi->historyView->currentIndex());
|
2012-05-18 13:22:22 -04:00
|
|
|
if (index.isValid()) {
|
|
|
|
m_historyModel->deleteIndex(index);
|
2012-05-18 14:15:02 -04:00
|
|
|
if (m_historyModel->rowCount() > 0) {
|
|
|
|
m_historyUi->deleteAllButton->setEnabled(true);
|
2017-07-30 13:38:10 -04:00
|
|
|
} else {
|
2012-05-18 14:15:02 -04:00
|
|
|
m_historyUi->deleteAllButton->setEnabled(false);
|
|
|
|
}
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(true);
|
2012-05-18 14:15:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::deleteAllHistoryEntries()
|
|
|
|
{
|
|
|
|
m_historyModel->deleteAll();
|
|
|
|
if (m_historyModel->rowCount() > 0) {
|
|
|
|
m_historyUi->deleteAllButton->setEnabled(true);
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-05-18 14:15:02 -04:00
|
|
|
m_historyUi->deleteAllButton->setEnabled(false);
|
2012-05-18 13:22:22 -04:00
|
|
|
}
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(true);
|
2012-05-18 13:22:22 -04:00
|
|
|
}
|
2012-08-15 16:47:41 -04:00
|
|
|
|
|
|
|
QMenu* EditEntryWidget::createPresetsMenu()
|
|
|
|
{
|
2012-11-02 11:21:32 -04:00
|
|
|
QMenu* expirePresetsMenu = new QMenu(this);
|
2012-08-15 16:47:41 -04:00
|
|
|
expirePresetsMenu->addAction(tr("Tomorrow"))->setData(QVariant::fromValue(TimeDelta::fromDays(1)));
|
|
|
|
expirePresetsMenu->addSeparator();
|
2018-10-28 10:47:24 -04:00
|
|
|
expirePresetsMenu->addAction(tr("%n week(s)", nullptr, 1))->setData(QVariant::fromValue(TimeDelta::fromDays(7)));
|
|
|
|
expirePresetsMenu->addAction(tr("%n week(s)", nullptr, 2))->setData(QVariant::fromValue(TimeDelta::fromDays(14)));
|
|
|
|
expirePresetsMenu->addAction(tr("%n week(s)", nullptr, 3))->setData(QVariant::fromValue(TimeDelta::fromDays(21)));
|
2012-08-15 16:47:41 -04:00
|
|
|
expirePresetsMenu->addSeparator();
|
2018-10-28 10:47:24 -04:00
|
|
|
expirePresetsMenu->addAction(tr("%n month(s)", nullptr, 1))->setData(QVariant::fromValue(TimeDelta::fromMonths(1)));
|
|
|
|
expirePresetsMenu->addAction(tr("%n month(s)", nullptr, 3))->setData(QVariant::fromValue(TimeDelta::fromMonths(3)));
|
|
|
|
expirePresetsMenu->addAction(tr("%n month(s)", nullptr, 6))->setData(QVariant::fromValue(TimeDelta::fromMonths(6)));
|
2012-08-15 16:47:41 -04:00
|
|
|
expirePresetsMenu->addSeparator();
|
2018-10-29 00:24:14 -04:00
|
|
|
expirePresetsMenu->addAction(tr("%n year(s)", 0, 1))->setData(QVariant::fromValue(TimeDelta::fromYears(1)));
|
|
|
|
expirePresetsMenu->addAction(tr("%n year(s)", 0, 2))->setData(QVariant::fromValue(TimeDelta::fromYears(2)));
|
|
|
|
expirePresetsMenu->addAction(tr("%n year(s)", 0, 3))->setData(QVariant::fromValue(TimeDelta::fromYears(3)));
|
2012-08-15 16:47:41 -04:00
|
|
|
return expirePresetsMenu;
|
|
|
|
}
|
2018-02-19 14:59:04 -05:00
|
|
|
|
2018-02-19 18:22:49 -05:00
|
|
|
void EditEntryWidget::setupColorButton(bool foreground, const QColor& color)
|
2018-02-19 14:59:04 -05:00
|
|
|
{
|
|
|
|
QWidget* button = m_advancedUi->fgColorButton;
|
|
|
|
QCheckBox* checkBox = m_advancedUi->fgColorCheckBox;
|
|
|
|
if (!foreground) {
|
|
|
|
button = m_advancedUi->bgColorButton;
|
|
|
|
checkBox = m_advancedUi->bgColorCheckBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color.isValid()) {
|
|
|
|
button->setStyleSheet(QString("background-color:%1").arg(color.name()));
|
|
|
|
button->setProperty("color", color.name());
|
|
|
|
checkBox->setChecked(true);
|
|
|
|
} else {
|
|
|
|
button->setStyleSheet("");
|
|
|
|
button->setProperty("color", QVariant());
|
|
|
|
checkBox->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::pickColor()
|
|
|
|
{
|
|
|
|
bool isForeground = (sender() == m_advancedUi->fgColorButton);
|
|
|
|
QColor oldColor = QColor(m_advancedUi->fgColorButton->property("color").toString());
|
|
|
|
if (!isForeground) {
|
|
|
|
oldColor = QColor(m_advancedUi->bgColorButton->property("color").toString());
|
|
|
|
}
|
|
|
|
|
2018-10-28 09:29:57 -04:00
|
|
|
QColor newColor = QColorDialog::getColor(oldColor);
|
2018-02-19 14:59:04 -05:00
|
|
|
if (newColor.isValid()) {
|
|
|
|
setupColorButton(isForeground, newColor);
|
2018-03-10 22:31:43 -05:00
|
|
|
setUnsavedChanges(true);
|
2018-02-19 14:59:04 -05:00
|
|
|
}
|
|
|
|
}
|
2018-03-10 22:31:43 -05:00
|
|
|
|
|
|
|
void EditEntryWidget::setUnsavedChanges(bool hasUnsaved)
|
|
|
|
{
|
|
|
|
m_saved = !hasUnsaved;
|
|
|
|
enableApplyButton(hasUnsaved);
|
|
|
|
}
|