mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Add option to add site permissions in preferences
BUG: 495391 Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
caa6749dbd
commit
6dc4b6d47b
@ -8,7 +8,10 @@
|
|||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "sqldatabase.h"
|
#include "sqldatabase.h"
|
||||||
|
|
||||||
const int rolePermission = Qt::UserRole + 10;
|
#include <QCompleter>
|
||||||
|
#include <QSqlQueryModel>
|
||||||
|
|
||||||
|
constexpr int rolePermission = Qt::UserRole;
|
||||||
|
|
||||||
SiteSettingsBrowseDialog::SiteSettingsBrowseDialog(QString &name, QString &sqlColumn, QWidget* parent)
|
SiteSettingsBrowseDialog::SiteSettingsBrowseDialog(QString &name, QString &sqlColumn, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
@ -20,6 +23,21 @@ SiteSettingsBrowseDialog::SiteSettingsBrowseDialog(QString &name, QString &sqlCo
|
|||||||
|
|
||||||
loadItems();
|
loadItems();
|
||||||
|
|
||||||
|
m_completer = new QCompleter(this);
|
||||||
|
m_completer->setCompletionMode(QCompleter::PopupCompletion);
|
||||||
|
m_completer->setFilterMode(Qt::MatchContains);
|
||||||
|
m_completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
m_completerModel = new QSqlQueryModel(this);
|
||||||
|
m_completerModel->setQuery(QSL("SELECT server from %1").arg(mApp->siteSettingsManager()->sqlTable()),
|
||||||
|
SqlDatabase::instance()->database());
|
||||||
|
m_completer->setModel(m_completerModel);
|
||||||
|
m_ui->urlEdit->setCompleter(m_completer);
|
||||||
|
|
||||||
|
m_ui->urlComboBox->addItem(tr("Ask"), SiteSettingsManager::Ask); /* Has to be first to be able to hide it */
|
||||||
|
m_ui->urlComboBox->addItem(tr("Allow"), SiteSettingsManager::Allow);
|
||||||
|
m_ui->urlComboBox->addItem(tr("Deny"), SiteSettingsManager::Deny);
|
||||||
|
m_ui->urlComboBox->addItem(tr("Default"), SiteSettingsManager::Default);
|
||||||
|
|
||||||
m_ui->treeWidget->header()->resizeSections(QHeaderView::ResizeToContents);
|
m_ui->treeWidget->header()->resizeSections(QHeaderView::ResizeToContents);
|
||||||
|
|
||||||
connect(m_ui->askButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Ask); });
|
connect(m_ui->askButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Ask); });
|
||||||
@ -27,6 +45,7 @@ SiteSettingsBrowseDialog::SiteSettingsBrowseDialog(QString &name, QString &sqlCo
|
|||||||
connect(m_ui->denyButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Deny); });
|
connect(m_ui->denyButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Deny); });
|
||||||
connect(m_ui->defaultButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Default); });
|
connect(m_ui->defaultButton, &QPushButton::clicked, this, [=]() { setPermission(SiteSettingsManager::Default); });
|
||||||
|
|
||||||
|
connect(m_ui->createButton, &QPushButton::clicked, this, &SiteSettingsBrowseDialog::createPermission);
|
||||||
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &SiteSettingsBrowseDialog::storeChanges);
|
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &SiteSettingsBrowseDialog::storeChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +90,7 @@ void SiteSettingsBrowseDialog::setPermission(const SiteSettingsManager::Permissi
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString server = item->text(0);
|
const QString server = item->text(0);
|
||||||
auto itemPermission = static_cast<SiteSettingsManager::Permission>(item->data(0, Qt::UserRole + 10).toInt());
|
auto itemPermission = static_cast<SiteSettingsManager::Permission>(item->data(0, rolePermission).toInt());
|
||||||
if (permission == itemPermission) {
|
if (permission == itemPermission) {
|
||||||
m_listModifications.remove(server);
|
m_listModifications.remove(server);
|
||||||
}
|
}
|
||||||
@ -85,6 +104,38 @@ void SiteSettingsBrowseDialog::setPermission(const SiteSettingsManager::Permissi
|
|||||||
void SiteSettingsBrowseDialog::hideAskButton()
|
void SiteSettingsBrowseDialog::hideAskButton()
|
||||||
{
|
{
|
||||||
m_ui->askButton->hide();
|
m_ui->askButton->hide();
|
||||||
|
m_ui->urlComboBox->removeItem(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SiteSettingsBrowseDialog::createPermission()
|
||||||
|
{
|
||||||
|
const QString server = mApp->siteSettingsManager()->adjustUrl(QUrl(m_ui->urlEdit->text()));
|
||||||
|
const auto permission = static_cast<SiteSettingsManager::Permission>(m_ui->urlComboBox->currentData(rolePermission).toInt());
|
||||||
|
|
||||||
|
if (server.isEmpty()) {
|
||||||
|
/* TODO: Print a status message or something to notify the user that url is not valid */
|
||||||
|
qWarning() << "An invalid URL.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto list_items = m_ui->treeWidget->findItems(server, Qt::MatchExactly);
|
||||||
|
|
||||||
|
if (list_items.isEmpty()) {
|
||||||
|
const QString permissionName = mApp->siteSettingsManager()->getPermissionName(permission);
|
||||||
|
|
||||||
|
auto* item = new QTreeWidgetItem(m_ui->treeWidget);
|
||||||
|
item->setText(0, server);
|
||||||
|
item->setText(1, permissionName);
|
||||||
|
item->setData(0, rolePermission, permission);
|
||||||
|
|
||||||
|
m_ui->treeWidget->addTopLevelItem(item);
|
||||||
|
m_ui->treeWidget->setCurrentItem(item);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_ui->treeWidget->setCurrentItem(list_items.first());
|
||||||
|
}
|
||||||
|
|
||||||
|
setPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
SiteSettingsBrowseDialog::~SiteSettingsBrowseDialog() = default;
|
SiteSettingsBrowseDialog::~SiteSettingsBrowseDialog() = default;
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
|
class QCompleter;
|
||||||
|
class QSqlQueryModel;
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class SiteSettingsBrowseDialog;
|
class SiteSettingsBrowseDialog;
|
||||||
@ -28,6 +31,7 @@ public:
|
|||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void storeChanges();
|
void storeChanges();
|
||||||
|
void createPermission();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadItems();
|
void loadItems();
|
||||||
@ -35,6 +39,8 @@ private:
|
|||||||
QScopedPointer<Ui::SiteSettingsBrowseDialog> m_ui;
|
QScopedPointer<Ui::SiteSettingsBrowseDialog> m_ui;
|
||||||
QHash<QString, int> m_listModifications;
|
QHash<QString, int> m_listModifications;
|
||||||
QString m_sqlColumn;
|
QString m_sqlColumn;
|
||||||
|
QCompleter *m_completer;
|
||||||
|
QSqlQueryModel * m_completerModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SITESETTINGSBROWSEDIALOG_H
|
#endif // SITESETTINGSBROWSEDIALOG_H
|
||||||
|
@ -14,7 +14,42 @@
|
|||||||
<string>Site Permissions</string>
|
<string>Site Permissions</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0">
|
<item row="2" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Url:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="urlEdit">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>https://kde.org</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="urlComboBox"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="nameLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QPushButton" name="createButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Set</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
<widget class="QTreeWidget" name="treeWidget">
|
<widget class="QTreeWidget" name="treeWidget">
|
||||||
<property name="indentation">
|
<property name="indentation">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
@ -37,8 +72,24 @@
|
|||||||
</column>
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="3" column="1">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Policy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="askButton">
|
<widget class="QPushButton" name="askButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -70,7 +121,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Orientation::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@ -82,20 +133,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="4" column="0" colspan="2">
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="nameLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user