File indexing completed on 2024-05-19 05:35:17

0001 //////////////////////////////////////////////////////////////////////////////
0002 // oxygenexceptiondialog.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 "oxygenexceptiondialog.h"
0011 #include "config-oxygen.h"
0012 #include "oxygendetectwidget.h"
0013 
0014 #if OXYGEN_HAVE_X11
0015 #include <private/qtx11extras_p.h>
0016 #endif
0017 
0018 namespace Oxygen
0019 {
0020 //___________________________________________
0021 ExceptionDialog::ExceptionDialog(QWidget *parent)
0022     : QDialog(parent)
0023 {
0024     m_ui.setupUi(this);
0025 
0026     connect(m_ui.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(close()));
0027 
0028     // store checkboxes from ui into list
0029     m_checkboxes.insert(BorderSize, m_ui.borderSizeCheckBox);
0030 
0031     // detect window properties
0032     connect(m_ui.detectDialogButton, SIGNAL(clicked()), SLOT(selectWindowProperties()));
0033 
0034     // connections
0035     connect(m_ui.exceptionType, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()));
0036     connect(m_ui.exceptionEditor, SIGNAL(textChanged(QString)), SLOT(updateChanged()));
0037     connect(m_ui.borderSizeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()));
0038 
0039     for (CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter) {
0040         connect(iter.value(), SIGNAL(clicked()), SLOT(updateChanged()));
0041     }
0042 
0043     connect(m_ui.hideTitleBar, SIGNAL(clicked()), SLOT(updateChanged()));
0044 
0045 // hide detection dialog on non X11 platforms
0046 #if OXYGEN_HAVE_X11
0047     if (!QX11Info::isPlatformX11())
0048         m_ui.detectDialogButton->hide();
0049 #else
0050     m_ui.detectDialogButton->hide();
0051 #endif
0052 }
0053 
0054 //___________________________________________
0055 void ExceptionDialog::setException(InternalSettingsPtr exception)
0056 {
0057     // store exception internally
0058     m_exception = exception;
0059 
0060     // type
0061     m_ui.exceptionType->setCurrentIndex(m_exception->exceptionType());
0062     m_ui.exceptionEditor->setText(m_exception->exceptionPattern());
0063     m_ui.borderSizeComboBox->setCurrentIndex(m_exception->borderSize());
0064     m_ui.hideTitleBar->setChecked(m_exception->hideTitleBar());
0065 
0066     // mask
0067     for (CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter) {
0068         iter.value()->setChecked(m_exception->mask() & iter.key());
0069     }
0070 
0071     setChanged(false);
0072 }
0073 
0074 //___________________________________________
0075 void ExceptionDialog::save(void)
0076 {
0077     m_exception->setExceptionType(m_ui.exceptionType->currentIndex());
0078     m_exception->setExceptionPattern(m_ui.exceptionEditor->text());
0079     m_exception->setBorderSize(m_ui.borderSizeComboBox->currentIndex());
0080     m_exception->setHideTitleBar(m_ui.hideTitleBar->isChecked());
0081 
0082     // mask
0083     unsigned int mask = None;
0084     for (CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter) {
0085         if (iter.value()->isChecked())
0086             mask |= iter.key();
0087     }
0088 
0089     m_exception->setMask(mask);
0090 
0091     setChanged(false);
0092 }
0093 
0094 //___________________________________________
0095 void ExceptionDialog::updateChanged(void)
0096 {
0097     bool modified(false);
0098     if (m_exception->exceptionType() != m_ui.exceptionType->currentIndex())
0099         modified = true;
0100     else if (m_exception->exceptionPattern() != m_ui.exceptionEditor->text())
0101         modified = true;
0102     else if (m_exception->borderSize() != m_ui.borderSizeComboBox->currentIndex())
0103         modified = true;
0104     else if (m_exception->hideTitleBar() != m_ui.hideTitleBar->isChecked())
0105         modified = true;
0106     else {
0107         // check mask
0108         for (CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter) {
0109             if (iter.value()->isChecked() != (bool)(m_exception->mask() & iter.key())) {
0110                 modified = true;
0111                 break;
0112             }
0113         }
0114     }
0115 
0116     setChanged(modified);
0117 }
0118 
0119 //___________________________________________
0120 void ExceptionDialog::selectWindowProperties(void)
0121 {
0122     // create widget
0123     if (!m_detectDialog) {
0124         m_detectDialog = new DetectDialog(this);
0125         connect(m_detectDialog, SIGNAL(detectionDone(bool)), SLOT(readWindowProperties(bool)));
0126     }
0127 
0128     m_detectDialog->detect(0);
0129 }
0130 
0131 //___________________________________________
0132 void ExceptionDialog::readWindowProperties(bool valid)
0133 {
0134     Q_CHECK_PTR(m_detectDialog);
0135     if (valid) {
0136         // type
0137         m_ui.exceptionType->setCurrentIndex(m_detectDialog->exceptionType());
0138 
0139         // window info
0140         const KWindowInfo &info(m_detectDialog->windowInfo());
0141 
0142         switch (m_detectDialog->exceptionType()) {
0143         default:
0144         case InternalSettings::ExceptionWindowClassName:
0145             m_ui.exceptionEditor->setText(QString::fromUtf8(info.windowClassClass()));
0146             break;
0147 
0148         case InternalSettings::ExceptionWindowTitle:
0149             m_ui.exceptionEditor->setText(info.name());
0150             break;
0151         }
0152     }
0153 
0154     delete m_detectDialog;
0155     m_detectDialog = nullptr;
0156 }
0157 }