File indexing completed on 2025-01-19 04:47:00

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "adblockpluginurlinterceptoraddadblocklistwidget.h"
0008 #include <KLineEditEventHandler>
0009 #include <KLocalizedString>
0010 #include <QFormLayout>
0011 #include <QLineEdit>
0012 
0013 AdblockPluginUrlInterceptorAddAdblockListWidget::AdblockPluginUrlInterceptorAddAdblockListWidget(QWidget *parent)
0014     : QWidget{parent}
0015     , mName(new QLineEdit(this))
0016     , mUrl(new QLineEdit(this))
0017 {
0018     auto mainLayout = new QFormLayout(this);
0019     mainLayout->setContentsMargins({});
0020     mainLayout->setObjectName(QLatin1StringView("mainLayout"));
0021 
0022     mName->setObjectName(QLatin1StringView("mName"));
0023     mUrl->setObjectName(QLatin1StringView("mUrl"));
0024 
0025     mName->setClearButtonEnabled(true);
0026     mUrl->setClearButtonEnabled(true);
0027     KLineEditEventHandler::catchReturnKey(mName);
0028     KLineEditEventHandler::catchReturnKey(mUrl);
0029 
0030     mainLayout->addRow(i18n("Name:"), mName);
0031     mainLayout->addRow(i18n("Url:"), mUrl);
0032     mName->setFocus();
0033 }
0034 
0035 AdblockPluginUrlInterceptorAddAdblockListWidget::~AdblockPluginUrlInterceptorAddAdblockListWidget() = default;
0036 
0037 AdblockPluginUrlInterceptorAddAdblockListWidget::AdBlockListInfo AdblockPluginUrlInterceptorAddAdblockListWidget::info() const
0038 {
0039     AdblockPluginUrlInterceptorAddAdblockListWidget::AdBlockListInfo i;
0040     i.name = mName->text();
0041     i.url = mUrl->text();
0042     return i;
0043 }
0044 
0045 void AdblockPluginUrlInterceptorAddAdblockListWidget::setInfo(const AdBlockListInfo &adblockInfo)
0046 {
0047     mName->setText(adblockInfo.name);
0048     mUrl->setText(adblockInfo.url);
0049 }
0050 
0051 bool AdblockPluginUrlInterceptorAddAdblockListWidget::AdBlockListInfo::isValid() const
0052 {
0053     return !name.trimmed().isEmpty() && !url.trimmed().isEmpty();
0054 }
0055 
0056 bool AdblockPluginUrlInterceptorAddAdblockListWidget::AdBlockListInfo::operator==(const AdBlockListInfo &other) const
0057 {
0058     return name == other.name && url == other.url;
0059 }
0060 
0061 bool AdblockPluginUrlInterceptorAddAdblockListWidget::AdBlockListInfo::operator!=(const AdBlockListInfo &other) const
0062 {
0063     return !AdblockPluginUrlInterceptorAddAdblockListWidget::AdBlockListInfo::operator==(other);
0064 }
0065 
0066 QDebug operator<<(QDebug d, const AdblockPluginUrlInterceptorAddAdblockListWidget::AdBlockListInfo &t)
0067 {
0068     d << " Name " << t.name;
0069     d << " Url " << t.url;
0070     return d;
0071 }
0072 
0073 #include "moc_adblockpluginurlinterceptoraddadblocklistwidget.cpp"