File indexing completed on 2024-12-08 04:34:09

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "bannerinfowidget.h"
0008 #include "bannerinfolistsearchlinewidget.h"
0009 #include "bannerinfolistview.h"
0010 #include "model/bannerinfosfilterproxymodel.h"
0011 #include "model/bannerinfosmodel.h"
0012 #include "rocketchataccount.h"
0013 
0014 #include <QVBoxLayout>
0015 
0016 BannerInfoWidget::BannerInfoWidget(RocketChatAccount *account, QWidget *parent)
0017     : QWidget{parent}
0018     , mBannerInfoListSearchLineWidget(new BannerInfoListSearchLineWidget(this))
0019     , mBannerInfoListView(new BannerInfoListView(account, this))
0020     , mBannerInfosFilterProxyModel(new BannerInfosFilterProxyModel(this))
0021     , mRocketChatAccount(account)
0022 {
0023     auto mainLayout = new QVBoxLayout(this);
0024     mainLayout->setContentsMargins({});
0025     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0026 
0027     mBannerInfosFilterProxyModel->setObjectName(QStringLiteral("mBannerInfosFilterProxyModel"));
0028     auto model = new BannerInfosModel(this);
0029     if (mRocketChatAccount) {
0030         model->insertBannerInfos(mRocketChatAccount->bannerInfos());
0031     }
0032 
0033     mBannerInfosFilterProxyModel->setSourceModel(model);
0034     mBannerInfoListView->setModel(mBannerInfosFilterProxyModel);
0035 
0036     mBannerInfoListSearchLineWidget->setObjectName(QStringLiteral("mBannerInfoListSearchLineWidget"));
0037     mainLayout->addWidget(mBannerInfoListSearchLineWidget);
0038 
0039     mBannerInfoListView->setObjectName(QStringLiteral("mBannerInfoListView"));
0040     mainLayout->addWidget(mBannerInfoListView);
0041 
0042     connect(mBannerInfoListSearchLineWidget, &BannerInfoListSearchLineWidget::filterChanged, this, &BannerInfoWidget::initializeProxyModel);
0043     initializeProxyModel();
0044 }
0045 
0046 BannerInfoWidget::~BannerInfoWidget() = default;
0047 
0048 void BannerInfoWidget::initializeProxyModel()
0049 {
0050     mBannerInfosFilterProxyModel->setFilterFixedString(mBannerInfoListSearchLineWidget->searchText());
0051     mBannerInfosFilterProxyModel->setShowUnread(mBannerInfoListSearchLineWidget->showOnlyUnread());
0052 }
0053 
0054 #include "moc_bannerinfowidget.cpp"