File indexing completed on 2022-09-27 16:31:45

0001 /*
0002     SPDX-FileCopyrightText: 2015-2022 Laurent Montel <montel@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include "kdeapplicationdebugsettingpage.h"
0009 #include "kdeapplicationtreelistwidget.h"
0010 #include <KLocalizedString>
0011 #include <KTreeWidgetSearchLine>
0012 #include <QEvent>
0013 #include <QKeyEvent>
0014 #include <QPushButton>
0015 #include <QVBoxLayout>
0016 
0017 KDEApplicationDebugSettingPage::KDEApplicationDebugSettingPage(QWidget *parent)
0018     : QWidget(parent)
0019     , mTreeListWidget(new KDEApplicationTreeListWidget(this))
0020     , mTreeListWidgetSearchLine(new KTreeWidgetSearchLine(this, mTreeListWidget))
0021     , mEnableDebug(new QPushButton(i18n("Enable All Debug"), this))
0022     , mTurnOffDebug(new QPushButton(i18n("Turn Off Debug"), this))
0023     , mTurnOffAllMessages(new QPushButton(i18n("Turn Off All Messages"), this))
0024 {
0025     auto mainLayout = new QVBoxLayout(this);
0026     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0027 
0028     mTreeListWidget->setObjectName(QStringLiteral("listwidget"));
0029 
0030     mTreeListWidgetSearchLine->setPlaceholderText(i18n("Search..."));
0031     mTreeListWidgetSearchLine->setObjectName(QStringLiteral("searchline"));
0032     mTreeListWidgetSearchLine->setSearchColumns(mTreeListWidget->searchColumns());
0033     mainLayout->addWidget(mTreeListWidgetSearchLine);
0034 
0035     mainLayout->addWidget(mTreeListWidget);
0036 
0037     auto buttonLayout = new QHBoxLayout;
0038     mainLayout->addLayout(buttonLayout);
0039 
0040     mEnableDebug->setObjectName(QStringLiteral("selectall"));
0041     buttonLayout->addWidget(mEnableDebug);
0042     connect(mEnableDebug, &QAbstractButton::clicked, this, &KDEApplicationDebugSettingPage::slotSelectAllDebug);
0043 
0044     mTurnOffDebug->setObjectName(QStringLiteral("deselectall"));
0045     buttonLayout->addWidget(mTurnOffDebug);
0046     connect(mTurnOffDebug, &QAbstractButton::clicked, this, &KDEApplicationDebugSettingPage::slotDeselectAllDebug);
0047 
0048     mTurnOffAllMessages->setObjectName(QStringLiteral("deselectallmessage"));
0049     buttonLayout->addWidget(mTurnOffAllMessages);
0050     connect(mTurnOffAllMessages, &QAbstractButton::clicked, this, &KDEApplicationDebugSettingPage::slotDeselectAllMessages);
0051 
0052     mTreeListWidgetSearchLine->installEventFilter(this);
0053 }
0054 
0055 KDEApplicationDebugSettingPage::~KDEApplicationDebugSettingPage() = default;
0056 
0057 void KDEApplicationDebugSettingPage::forceFocus()
0058 {
0059     mTreeListWidgetSearchLine->setFocus();
0060 }
0061 
0062 bool KDEApplicationDebugSettingPage::eventFilter(QObject *obj, QEvent *event)
0063 {
0064     if (event->type() == QEvent::KeyPress && obj == mTreeListWidgetSearchLine) {
0065         auto key = static_cast<QKeyEvent *>(event);
0066         if ((key->key() == Qt::Key_Enter) || (key->key() == Qt::Key_Return)) {
0067             event->accept();
0068             return true;
0069         }
0070     }
0071     return QWidget::eventFilter(obj, event);
0072 }
0073 
0074 void KDEApplicationDebugSettingPage::slotSelectAllDebug()
0075 {
0076     mTreeListWidget->selectAllDebugCategories();
0077 }
0078 
0079 void KDEApplicationDebugSettingPage::slotDeselectAllDebug()
0080 {
0081     mTreeListWidget->deSelectAllDebugCategories();
0082 }
0083 
0084 void KDEApplicationDebugSettingPage::slotDeselectAllMessages()
0085 {
0086     mTreeListWidget->deSelectAllMessagesCategories();
0087 }
0088 
0089 void KDEApplicationDebugSettingPage::fillList(const LoggingCategory::List &list)
0090 {
0091     mTreeListWidget->fillList(list);
0092 }
0093 
0094 LoggingCategory::List KDEApplicationDebugSettingPage::rules(bool forceSavingAllRules) const
0095 {
0096     return mTreeListWidget->rules(forceSavingAllRules);
0097 }
0098 
0099 void KDEApplicationDebugSettingPage::insertCategories(const LoggingCategory::List &list)
0100 {
0101     mTreeListWidget->insertCategories(list);
0102 }
0103 
0104 void KDEApplicationDebugSettingPage::restoreToDefault()
0105 {
0106     mTreeListWidget->restoreToDefault();
0107 }