File indexing completed on 2024-10-13 04:54:47

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "viewsdialog.h"
0007 
0008 // local
0009 #include "ui_viewsdialog.h"
0010 #include "viewshandler.h"
0011 #include "../settingsdialog/layoutscontroller.h"
0012 
0013 namespace Latte {
0014 namespace Settings {
0015 namespace Dialog {
0016 
0017 ViewsDialog::ViewsDialog(SettingsDialog *parent, Controller::Layouts *controller)
0018     : GenericDialog(parent),
0019       m_parentDlg(parent),
0020       m_ui(new Ui::ViewsDialog),
0021       m_layoutsController(controller),
0022       m_storage(KConfigGroup(KSharedConfig::openConfig(),"LatteSettingsDialog").group("ViewsDialog"))
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::ViewsHandler(this);
0031 
0032     //! Button Group
0033     m_applyNowBtn = new QPushButton(QIcon::fromTheme("dialog-yes"), i18n("Apply Now"), m_ui->buttonBox);
0034     m_applyNowBtn->setToolTip(i18n("Apply all dock, panels changes now"));
0035     m_ui->buttonBox->addButton(m_applyNowBtn, QDialogButtonBox::ApplyRole);
0036 
0037     //! Signals/Slots
0038     connect(m_handler, &Handler::ViewsHandler::currentLayoutChanged, this, &ViewsDialog::updateApplyButtonsState);
0039     connect(m_handler, &Handler::ViewsHandler::dataChanged, this, &ViewsDialog::updateApplyButtonsState);
0040 
0041     connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
0042             this, &ViewsDialog::onCancel);
0043 
0044     connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), &QPushButton::clicked,
0045             this, &ViewsDialog::onReset);
0046 
0047     connect(m_applyNowBtn, &QPushButton::clicked, this, &ViewsDialog::onApply);
0048 
0049     resize(m_windowSize);
0050     updateApplyButtonsState();    
0051 }
0052 
0053 ViewsDialog::~ViewsDialog()
0054 {
0055     saveConfig();
0056 }
0057 
0058 Controller::Layouts *ViewsDialog::layoutsController() const
0059 {
0060     return m_layoutsController;
0061 }
0062 
0063 Ui::ViewsDialog *ViewsDialog::ui() const
0064 {
0065     return m_ui;
0066 }
0067 
0068 Latte::Corona *ViewsDialog::corona() const
0069 {
0070     return m_parentDlg->corona();
0071 }
0072 
0073 void ViewsDialog::updateApplyButtonsState()
0074 {
0075     bool changed = m_handler->hasChangedData();
0076 
0077     m_applyNowBtn->setEnabled(changed);
0078     m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(changed);
0079 }
0080 
0081 void ViewsDialog::accept()
0082 {
0083     qDebug() << Q_FUNC_INFO;
0084 }
0085 
0086 void ViewsDialog::onOk()
0087 {
0088     qDebug() << Q_FUNC_INFO;
0089 //    m_handler->save();
0090     close();
0091 }
0092 
0093 void ViewsDialog::onApply()
0094 {
0095     qDebug() << Q_FUNC_INFO;
0096     m_handler->save();
0097 }
0098 
0099 void ViewsDialog::onCancel()
0100 {
0101     qDebug() << Q_FUNC_INFO;
0102     close();
0103 }
0104 
0105 void ViewsDialog::onReset()
0106 {
0107     qDebug() << Q_FUNC_INFO;
0108     m_handler->reset();
0109 }
0110 
0111 void ViewsDialog::loadConfig()
0112 {
0113     m_windowSize = m_storage.readEntry("windowSize", QSize(980, 630));
0114 }
0115 
0116 void ViewsDialog::saveConfig()
0117 {
0118     m_storage.writeEntry("windowSize", size());
0119 }
0120 
0121 }
0122 }
0123 }