File indexing completed on 2024-12-01 05:02:14

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "detailsdialog.h"
0007 
0008 // local
0009 #include "ui_detailsdialog.h"
0010 #include "detailshandler.h"
0011 #include "../settingsdialog/layoutscontroller.h"
0012 
0013 namespace Latte {
0014 namespace Settings {
0015 namespace Dialog {
0016 
0017 DetailsDialog::DetailsDialog(SettingsDialog *parent, Controller::Layouts *controller)
0018     : GenericDialog(parent),
0019       m_parentDlg(parent),
0020       m_ui(new Ui::DetailsDialog),
0021       m_layoutsController(controller),
0022       m_storage(KConfigGroup(KSharedConfig::openConfig(),"LatteSettingsDialog").group("DetailsDialog"))
0023 {
0024     setAttribute(Qt::WA_DeleteOnClose, true);
0025     loadConfig();
0026 
0027     //! first we need to setup the ui
0028     m_ui->setupUi(this);
0029     //! we must create handlers after creating/adjusting the ui
0030     m_handler = new Handler::DetailsHandler(this);
0031 
0032     connect(m_handler, &Handler::DetailsHandler::currentLayoutChanged, this, &DetailsDialog::updateApplyButtonsState);
0033     connect(m_handler, &Handler::DetailsHandler::dataChanged, this, &DetailsDialog::updateApplyButtonsState);
0034 
0035     connect(m_ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked,
0036             this, &DetailsDialog::onOk);
0037 
0038     connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
0039             this, &DetailsDialog::onCancel);
0040 
0041     connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), &QPushButton::clicked,
0042             this, &DetailsDialog::onReset);
0043 
0044     resize(m_windowSize);
0045     updateApplyButtonsState();
0046 }
0047 
0048 DetailsDialog::~DetailsDialog()
0049 {
0050     saveConfig();
0051 }
0052 
0053 Controller::Layouts *DetailsDialog::layoutsController() const
0054 {
0055     return m_layoutsController;
0056 }
0057 
0058 Ui::DetailsDialog *DetailsDialog::ui() const
0059 {
0060     return m_ui;
0061 }
0062 
0063 Latte::Corona *DetailsDialog::corona() const
0064 {
0065     return m_parentDlg->corona();
0066 }
0067 
0068 void DetailsDialog::updateApplyButtonsState()
0069 {
0070     if (m_handler->hasChangedData()) {
0071         m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
0072         m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(true);
0073     } else {
0074         m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
0075         m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
0076     }
0077 }
0078 
0079 void DetailsDialog::accept()
0080 {
0081     qDebug() << Q_FUNC_INFO;
0082 }
0083 
0084 void DetailsDialog::onOk()
0085 {
0086     qDebug() << Q_FUNC_INFO;
0087     m_handler->save();
0088     close();
0089 }
0090 
0091 void DetailsDialog::onCancel()
0092 {
0093     qDebug() << Q_FUNC_INFO;
0094     close();
0095 }
0096 
0097 void DetailsDialog::onReset()
0098 {
0099     qDebug() << Q_FUNC_INFO;
0100     m_handler->reset();
0101 }
0102 
0103 void DetailsDialog::loadConfig()
0104 {
0105     m_windowSize = m_storage.readEntry("windowSize", QSize(560, 640));
0106 }
0107 
0108 void DetailsDialog::saveConfig()
0109 {
0110     m_storage.writeEntry("windowSize", size());
0111 }
0112 
0113 }
0114 }
0115 }