mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-29 19:06:55 -05:00
Add support for multiple URLs in an entry
* Fixes #398 The new Browser Integration entry settings page has a list view with any additional URL's. These URL's are added to the entry attributes with KP2A_URL_<counter>, which means those are directly compatible with Keepass2Android.
This commit is contained in:
parent
e50261a99c
commit
f726d7501f
19 changed files with 568 additions and 104 deletions
|
|
@ -51,6 +51,7 @@
|
|||
#include "sshagent/SSHAgent.h"
|
||||
#endif
|
||||
#ifdef WITH_XC_BROWSER
|
||||
#include "EntryURLModel.h"
|
||||
#include "browser/BrowserService.h"
|
||||
#endif
|
||||
#include "gui/Clipboard.h"
|
||||
|
|
@ -82,7 +83,9 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
|
|||
, m_sshAgentWidget(new QWidget())
|
||||
#endif
|
||||
#ifdef WITH_XC_BROWSER
|
||||
, m_browserSettingsChanged(false)
|
||||
, m_browserWidget(new QWidget())
|
||||
, m_additionalURLsDataModel(new EntryURLModel(this))
|
||||
#endif
|
||||
, m_editWidgetProperties(new EditWidgetProperties())
|
||||
, m_historyWidget(new QWidget())
|
||||
|
|
@ -265,18 +268,112 @@ void EditEntryWidget::setupBrowser()
|
|||
|
||||
if (config()->get("Browser/Enabled", false).toBool()) {
|
||||
addPage(tr("Browser Integration"), FilePath::instance()->icon("apps", "internet-web-browser"), m_browserWidget);
|
||||
connect(m_browserUi->skipAutoSubmitCheckbox, SIGNAL(toggled(bool)), SLOT(updateBrowser()));
|
||||
connect(m_browserUi->hideEntryCheckbox, SIGNAL(toggled(bool)), SLOT(updateBrowser()));
|
||||
m_additionalURLsDataModel->setEntryAttributes(m_entryAttributes);
|
||||
m_browserUi->additionalURLsView->setModel(m_additionalURLsDataModel);
|
||||
|
||||
// clang-format off
|
||||
connect(m_browserUi->skipAutoSubmitCheckbox, SIGNAL(toggled(bool)), SLOT(updateBrowserModified()));
|
||||
connect(m_browserUi->hideEntryCheckbox, SIGNAL(toggled(bool)), SLOT(updateBrowserModified()));
|
||||
connect(m_browserUi->addURLButton, SIGNAL(clicked()), SLOT(insertURL()));
|
||||
connect(m_browserUi->removeURLButton, SIGNAL(clicked()), SLOT(removeCurrentURL()));
|
||||
connect(m_browserUi->editURLButton, SIGNAL(clicked()), SLOT(editCurrentURL()));
|
||||
connect(m_browserUi->additionalURLsView->selectionModel(),
|
||||
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||
SLOT(updateCurrentURL()));
|
||||
connect(m_additionalURLsDataModel,
|
||||
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)),
|
||||
SLOT(updateCurrentAttribute()));
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
void EditEntryWidget::updateBrowserModified()
|
||||
{
|
||||
m_browserSettingsChanged = true;
|
||||
}
|
||||
|
||||
void EditEntryWidget::updateBrowser()
|
||||
{
|
||||
if (!m_browserSettingsChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto skip = m_browserUi->skipAutoSubmitCheckbox->isChecked();
|
||||
auto hide = m_browserUi->hideEntryCheckbox->isChecked();
|
||||
m_customData->set(BrowserService::OPTION_SKIP_AUTO_SUBMIT, (skip ? QString("true") : QString("false")));
|
||||
m_customData->set(BrowserService::OPTION_HIDE_ENTRY, (hide ? QString("true") : QString("false")));
|
||||
}
|
||||
|
||||
void EditEntryWidget::insertURL()
|
||||
{
|
||||
Q_ASSERT(!m_history);
|
||||
|
||||
QString name("KP2A_URL");
|
||||
int i = 1;
|
||||
|
||||
while (m_entryAttributes->keys().contains(name)) {
|
||||
name = QString("KP2A_URL_%1").arg(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
m_entryAttributes->set(name, tr("<empty URL>"));
|
||||
QModelIndex index = m_additionalURLsDataModel->indexByKey(name);
|
||||
|
||||
m_browserUi->additionalURLsView->setCurrentIndex(index);
|
||||
m_browserUi->additionalURLsView->edit(index);
|
||||
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
void EditEntryWidget::removeCurrentURL()
|
||||
{
|
||||
Q_ASSERT(!m_history);
|
||||
|
||||
QModelIndex index = m_browserUi->additionalURLsView->currentIndex();
|
||||
|
||||
if (index.isValid()) {
|
||||
auto result = MessageBox::question(this,
|
||||
tr("Confirm Removal"),
|
||||
tr("Are you sure you want to remove this URL?"),
|
||||
MessageBox::Remove | MessageBox::Cancel,
|
||||
MessageBox::Cancel);
|
||||
|
||||
if (result == MessageBox::Remove) {
|
||||
m_entryAttributes->remove(m_additionalURLsDataModel->keyByIndex(index));
|
||||
if (m_additionalURLsDataModel->rowCount() == 0) {
|
||||
m_browserUi->editURLButton->setEnabled(false);
|
||||
m_browserUi->removeURLButton->setEnabled(false);
|
||||
}
|
||||
setModified(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditEntryWidget::editCurrentURL()
|
||||
{
|
||||
Q_ASSERT(!m_history);
|
||||
|
||||
QModelIndex index = m_browserUi->additionalURLsView->currentIndex();
|
||||
|
||||
if (index.isValid()) {
|
||||
m_browserUi->additionalURLsView->edit(index);
|
||||
setModified(true);
|
||||
}
|
||||
}
|
||||
|
||||
void EditEntryWidget::updateCurrentURL()
|
||||
{
|
||||
QModelIndex index = m_browserUi->additionalURLsView->currentIndex();
|
||||
|
||||
if (index.isValid()) {
|
||||
// Don't allow editing in history view
|
||||
m_browserUi->editURLButton->setEnabled(!m_history);
|
||||
m_browserUi->removeURLButton->setEnabled(!m_history);
|
||||
} else {
|
||||
m_browserUi->editURLButton->setEnabled(false);
|
||||
m_browserUi->removeURLButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void EditEntryWidget::setupProperties()
|
||||
|
|
@ -366,8 +463,11 @@ void EditEntryWidget::setupEntryUpdate()
|
|||
|
||||
#ifdef WITH_XC_BROWSER
|
||||
if (config()->get("Browser/Enabled", false).toBool()) {
|
||||
connect(m_browserUi->skipAutoSubmitCheckbox, SIGNAL(toggled(bool)), this, SLOT(setModified()));
|
||||
connect(m_browserUi->hideEntryCheckbox, SIGNAL(toggled(bool)), this, SLOT(setModified()));
|
||||
connect(m_browserUi->skipAutoSubmitCheckbox, SIGNAL(toggled(bool)), SLOT(setModified()));
|
||||
connect(m_browserUi->hideEntryCheckbox, SIGNAL(toggled(bool)), SLOT(setModified()));
|
||||
connect(m_browserUi->addURLButton, SIGNAL(toggled(bool)), SLOT(setModified()));
|
||||
connect(m_browserUi->removeURLButton, SIGNAL(toggled(bool)), SLOT(setModified()));
|
||||
connect(m_browserUi->editURLButton, SIGNAL(toggled(bool)), SLOT(setModified()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -862,7 +962,8 @@ void EditEntryWidget::setForms(Entry* entry, bool restore)
|
|||
|
||||
#ifdef WITH_XC_BROWSER
|
||||
if (m_customData->contains(BrowserService::OPTION_SKIP_AUTO_SUBMIT)) {
|
||||
m_browserUi->skipAutoSubmitCheckbox->setChecked(m_customData->value(BrowserService::OPTION_SKIP_AUTO_SUBMIT) == "true");
|
||||
m_browserUi->skipAutoSubmitCheckbox->setChecked(m_customData->value(BrowserService::OPTION_SKIP_AUTO_SUBMIT)
|
||||
== "true");
|
||||
} else {
|
||||
m_browserUi->skipAutoSubmitCheckbox->setChecked(false);
|
||||
}
|
||||
|
|
@ -872,6 +973,15 @@ void EditEntryWidget::setForms(Entry* entry, bool restore)
|
|||
} else {
|
||||
m_browserUi->hideEntryCheckbox->setChecked(false);
|
||||
}
|
||||
|
||||
m_browserUi->addURLButton->setEnabled(!m_history);
|
||||
m_browserUi->removeURLButton->setEnabled(false);
|
||||
m_browserUi->editURLButton->setEnabled(false);
|
||||
m_browserUi->additionalURLsView->setEditTriggers(editTriggers);
|
||||
|
||||
if (m_additionalURLsDataModel->rowCount() != 0) {
|
||||
m_browserUi->additionalURLsView->setCurrentIndex(m_additionalURLsDataModel->index(0, 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
m_editWidgetProperties->setFields(entry->timeInfo(), entry->uuid());
|
||||
|
|
@ -946,6 +1056,12 @@ bool EditEntryWidget::commitEntry()
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_XC_BROWSER
|
||||
if (config()->get("Browser/Enabled", false).toBool()) {
|
||||
updateBrowser();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_create) {
|
||||
m_entry->beginUpdate();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue