File indexing completed on 2024-05-12 05:28:35

0001 //////////////////////////////////////////////////////////////////////////////
0002 // breezeexceptiondialog.cpp
0003 // -------------------
0004 //
0005 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 //
0007 // SPDX-License-Identifier: MIT
0008 //////////////////////////////////////////////////////////////////////////////
0009 
0010 #include "breezeexceptiondialog.h"
0011 #include "breezedetectwidget.h"
0012 
0013 namespace Breeze
0014 {
0015 //___________________________________________
0016 ExceptionDialog::ExceptionDialog(QWidget *parent)
0017     : QDialog(parent)
0018 {
0019     m_ui.setupUi(this);
0020 
0021     connect(m_ui.buttonBox->button(QDialogButtonBox::Cancel), &QAbstractButton::clicked, this, &QWidget::close);
0022 
0023     // store checkboxes from ui into list
0024     m_checkboxes.insert(BorderSize, m_ui.borderSizeCheckBox);
0025 
0026     // detect window properties
0027     connect(m_ui.detectDialogButton, &QAbstractButton::clicked, this, &ExceptionDialog::selectWindowProperties);
0028 
0029     // connections
0030     connect(m_ui.exceptionType, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()));
0031     connect(m_ui.exceptionEditor, &QLineEdit::textChanged, this, &ExceptionDialog::updateChanged);
0032     connect(m_ui.borderSizeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()));
0033 
0034     for (CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter) {
0035         connect(iter.value(), &QAbstractButton::clicked, this, &ExceptionDialog::updateChanged);
0036     }
0037 
0038     connect(m_ui.hideTitleBar, &QAbstractButton::clicked, this, &ExceptionDialog::updateChanged);
0039 }
0040 
0041 //___________________________________________
0042 void ExceptionDialog::setException(InternalSettingsPtr exception)
0043 {
0044     // store exception internally
0045     m_exception = exception;
0046 
0047     // type
0048     m_ui.exceptionType->setCurrentIndex(m_exception->exceptionType());
0049     m_ui.exceptionEditor->setText(m_exception->exceptionPattern());
0050     m_ui.borderSizeComboBox->setCurrentIndex(m_exception->borderSize());
0051     m_ui.hideTitleBar->setChecked(m_exception->hideTitleBar());
0052 
0053     // mask
0054     for (CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter) {
0055         iter.value()->setChecked(m_exception->mask() & iter.key());
0056     }
0057 
0058     setChanged(false);
0059 }
0060 
0061 //___________________________________________
0062 void ExceptionDialog::save()
0063 {
0064     m_exception->setExceptionType(m_ui.exceptionType->currentIndex());
0065     m_exception->setExceptionPattern(m_ui.exceptionEditor->text());
0066     m_exception->setBorderSize(m_ui.borderSizeComboBox->currentIndex());
0067     m_exception->setHideTitleBar(m_ui.hideTitleBar->isChecked());
0068 
0069     // mask
0070     unsigned int mask = None;
0071     for (CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter) {
0072         if (iter.value()->isChecked()) {
0073             mask |= iter.key();
0074         }
0075     }
0076 
0077     m_exception->setMask(mask);
0078 
0079     setChanged(false);
0080 }
0081 
0082 //___________________________________________
0083 void ExceptionDialog::updateChanged()
0084 {
0085     bool modified(false);
0086     if (m_exception->exceptionType() != m_ui.exceptionType->currentIndex()) {
0087         modified = true;
0088     } else if (m_exception->exceptionPattern() != m_ui.exceptionEditor->text()) {
0089         modified = true;
0090     } else if (m_exception->borderSize() != m_ui.borderSizeComboBox->currentIndex()) {
0091         modified = true;
0092     } else if (m_exception->hideTitleBar() != m_ui.hideTitleBar->isChecked()) {
0093         modified = true;
0094     } else {
0095         // check mask
0096         for (CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter) {
0097             if (iter.value()->isChecked() != (bool)(m_exception->mask() & iter.key())) {
0098                 modified = true;
0099                 break;
0100             }
0101         }
0102     }
0103 
0104     setChanged(modified);
0105 }
0106 
0107 //___________________________________________
0108 void ExceptionDialog::selectWindowProperties()
0109 {
0110     // create widget
0111     if (!m_detectDialog) {
0112         m_detectDialog = new DetectDialog(this);
0113         connect(m_detectDialog, &DetectDialog::detectionDone, this, &ExceptionDialog::readWindowProperties);
0114     }
0115 
0116     m_detectDialog->detect();
0117 }
0118 
0119 //___________________________________________
0120 void ExceptionDialog::readWindowProperties(bool valid)
0121 {
0122     Q_CHECK_PTR(m_detectDialog);
0123     if (valid) {
0124         // window info
0125         const QVariantMap properties = m_detectDialog->properties();
0126 
0127         switch (m_ui.exceptionType->currentIndex()) {
0128         default:
0129         case InternalSettings::ExceptionWindowClassName:
0130             m_ui.exceptionEditor->setText(properties.value(QStringLiteral("resourceClass")).toString());
0131             break;
0132 
0133         case InternalSettings::ExceptionWindowTitle:
0134             m_ui.exceptionEditor->setText(properties.value(QStringLiteral("caption")).toString());
0135             break;
0136         }
0137     }
0138 
0139     delete m_detectDialog;
0140     m_detectDialog = nullptr;
0141 }
0142 
0143 }