File indexing completed on 2024-12-15 03:45:05

0001 /*
0002     SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include "auditlogbrowserdialog.h"
0008 #include "ui_auditlogbrowserdialog.h"
0009 
0010 #include <auditloguicontroller.h>
0011 
0012 #include <QDateTime>
0013 #include <QPushButton>
0014 
0015 using namespace KUserFeedback;
0016 
0017 AuditLogBrowserDialog::AuditLogBrowserDialog(QWidget *parent)
0018     : QDialog(parent)
0019     , ui(new Ui::AuditLogBrowserDialog)
0020     , m_controller(nullptr)
0021 {
0022     ui->setupUi(this);
0023 
0024     connect(ui->logEntryBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &AuditLogBrowserDialog::logEntrySelected);
0025 
0026     auto clearButton = ui->buttonBox->button(QDialogButtonBox::Discard);
0027     Q_ASSERT(clearButton);
0028     clearButton->setText(tr("Delete Log"));
0029     connect(clearButton, &QPushButton::clicked, this, &AuditLogBrowserDialog::close);
0030 
0031     setEnabled(false);
0032 }
0033 
0034 AuditLogBrowserDialog::~AuditLogBrowserDialog()
0035 {
0036 }
0037 
0038 void AuditLogBrowserDialog::setUiController(AuditLogUiController *controller)
0039 {
0040     Q_ASSERT(controller);
0041     m_controller = controller;
0042     ui->logEntryBox->setModel(controller->logEntryModel());
0043     logEntrySelected();
0044 
0045     auto clearButton = ui->buttonBox->button(QDialogButtonBox::Discard);
0046     connect(clearButton, &QPushButton::clicked, controller, &AuditLogUiController::clear);
0047 
0048     setEnabled(true);
0049 }
0050 
0051 void AuditLogBrowserDialog::logEntrySelected()
0052 {
0053     const auto dt = ui->logEntryBox->currentData().toDateTime();
0054     ui->logEntryView->setText(m_controller->logEntry(dt));
0055 }
0056 
0057 #include "moc_auditlogbrowserdialog.cpp"