mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-06 05:57:37 +03:00
Show UI warning for invalid URLs
This commit is contained in:
parent
663393d994
commit
c0f29cc790
11 changed files with 211 additions and 2 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "EntryURLModel.h"
|
||||
|
||||
#include "core/Entry.h"
|
||||
#include "core/FilePath.h"
|
||||
#include "core/Tools.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -26,6 +27,7 @@
|
|||
EntryURLModel::EntryURLModel(QObject* parent)
|
||||
: QStandardItemModel(parent)
|
||||
, m_entryAttributes(nullptr)
|
||||
, m_errorIcon(filePath()->icon("status", "dialog-error"))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -53,6 +55,33 @@ void EntryURLModel::setEntryAttributes(EntryAttributes* entryAttributes)
|
|||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant EntryURLModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto key = keyByIndex(index);
|
||||
if (key.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto value = m_entryAttributes->value(key);
|
||||
const auto urlValid = Tools::checkUrlValid(value);
|
||||
|
||||
if (role == Qt::BackgroundRole && !urlValid) {
|
||||
return QColor(255, 125, 125);
|
||||
} else if (role == Qt::DecorationRole && !urlValid) {
|
||||
return m_errorIcon;
|
||||
} else if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||
return value;
|
||||
} else if (role == Qt::ToolTipRole && !urlValid) {
|
||||
return tr("Invalid URL");
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool EntryURLModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
if (!index.isValid() || role != Qt::EditRole || value.type() != QVariant::String || value.toString().isEmpty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue