File indexing completed on 2024-04-21 05:54:05

0001 /*
0002     SPDX-FileCopyrightText: 2005-2007, 2010 Tom Albers <toma@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 // Local includes.
0008 #include "setupmaximized.h"
0009 #include "rsiwidget.h" // effects enum
0010 
0011 // QT includes.
0012 #include <QApplication>
0013 #include <QCheckBox>
0014 #include <QComboBox>
0015 #include <QDir>
0016 #include <QFileDialog>
0017 #include <QGroupBox>
0018 #include <QHBoxLayout>
0019 #include <QLabel>
0020 #include <QLineEdit>
0021 #include <QPushButton>
0022 #include <QSlider>
0023 #include <QVBoxLayout>
0024 
0025 // KDE includes.
0026 #include <KConfigGroup>
0027 #include <KLocalizedString>
0028 #include <KPluralHandlingSpinBox>
0029 #include <KSharedConfig>
0030 #include <KWindowSystem>
0031 
0032 class SetupMaximizedPriv
0033 {
0034 public:
0035     QWidget *colorBox;
0036     QWidget *fontBox;
0037     QGroupBox *slideshowBox;
0038     QGroupBox *plasmaBox;
0039     QGroupBox *grayBox;
0040     QPushButton *counterFontBut;
0041     QPushButton *folderBut;
0042     QLineEdit *imageFolderEdit;
0043     QCheckBox *searchRecursiveCheck;
0044     QCheckBox *hideMinimizeButton;
0045     QCheckBox *hideLockButton;
0046     QCheckBox *hidePostponeButton;
0047     QCheckBox *disableAccel;
0048     QPushButton *changePathButton;
0049     KPluralHandlingSpinBox *slideInterval;
0050     KPluralHandlingSpinBox *popupDuration;
0051     QLabel *popupDurationLabel;
0052     QGroupBox *popupBox;
0053     QCheckBox *usePopup;
0054     QCheckBox *useFlash;
0055     QLabel *useFlashLabel;
0056     QCheckBox *readOnlyPlasma;
0057     QLabel *effectLabel;
0058     QComboBox *effectBox;
0059     QSlider *graySlider;
0060     QCheckBox *showSmallImagesCheck;
0061     QCheckBox *expandImageToFullScreen;
0062 };
0063 
0064 SetupMaximized::SetupMaximized(QWidget *parent)
0065     : QWidget(parent)
0066 {
0067     d = new SetupMaximizedPriv;
0068 
0069     QVBoxLayout *l = new QVBoxLayout(this);
0070 
0071     // Counterbox and skipbox next to eachother
0072 
0073     d->effectLabel = new QLabel();
0074     d->effectBox = new QComboBox(this);
0075     if (KWindowSystem::compositingActive())
0076         d->effectBox->addItem(i18n("Simple Gray Effect"), QVariant(RSIObject::SimpleGray));
0077     else
0078         d->effectBox->addItem(i18n("Complete Black Effect"), QVariant(RSIObject::SimpleGray));
0079     d->effectBox->addItem(i18n("Show Plasma Dashboard"), QVariant(RSIObject::Plasma));
0080     d->effectBox->addItem(i18n("Show Slide Show of Images"), QVariant(RSIObject::SlideShow));
0081     d->effectBox->addItem(i18n("Show a Passive Popup"), QVariant(RSIObject::Popup));
0082     d->effectLabel->setBuddy(d->effectBox);
0083 
0084     connect(d->effectBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &SetupMaximized::slotEffectChanged);
0085 
0086     //---------------- SKIP BOX
0087     QGroupBox *skipBox = new QGroupBox(this);
0088     skipBox->setTitle(i18n("Skipping Breaks"));
0089 
0090     d->hideMinimizeButton = new QCheckBox(i18n("&Hide skip button"), this);
0091     d->hideMinimizeButton->setWhatsThis(
0092         i18n("Check this option to disable and "
0093              "hide the skip button. This way you can prevent skipping the break."));
0094 
0095     d->hideLockButton = new QCheckBox(i18n("&Hide lock button"), this);
0096     d->hideLockButton->setWhatsThis(
0097         i18n("Check this option to disable and "
0098              "hide the lock button. This way you can prevent pressing the wrong button."));
0099     d->hidePostponeButton = new QCheckBox(i18n("&Hide postpone button"), this);
0100     d->hidePostponeButton->setWhatsThis(
0101         i18n("Check this option to disable and "
0102              "hide the postpone break button. This way you can prevent pressing the wrong button."));
0103 
0104     d->disableAccel = new QCheckBox(i18n("&Disable shortcut (Esc)"), this);
0105     d->disableAccel->setWhatsThis(
0106         i18n("Check this option to disable the ESC key skipping "
0107              "the break."));
0108 
0109     QVBoxLayout *vbox1 = new QVBoxLayout(skipBox);
0110     vbox1->addWidget(d->hideMinimizeButton);
0111     vbox1->addWidget(d->hideLockButton);
0112     vbox1->addWidget(d->hidePostponeButton);
0113     vbox1->addWidget(d->disableAccel);
0114     vbox1->addStretch(1);
0115     skipBox->setLayout(vbox1);
0116 
0117     //------------------ Plasma Setup
0118     d->plasmaBox = new QGroupBox(this);
0119     d->plasmaBox->setTitle(i18n("Plasma Dashboard"));
0120 
0121     d->readOnlyPlasma = new QCheckBox(i18n("Read Only"), this);
0122 
0123     QVBoxLayout *vbox5 = new QVBoxLayout(d->plasmaBox);
0124     vbox5->addWidget(d->readOnlyPlasma);
0125     d->plasmaBox->setLayout(vbox5);
0126 
0127     //------------------ Gray Setup
0128     d->grayBox = new QGroupBox(this);
0129     d->grayBox->setTitle(i18n("Transparency level"));
0130 
0131     QWidget *hboxslider = new QWidget(this);
0132     QHBoxLayout *hboxsliderHBoxLayout = new QHBoxLayout(hboxslider);
0133     hboxsliderHBoxLayout->setContentsMargins(0, 0, 0, 0);
0134     hboxsliderHBoxLayout->setSpacing(30);
0135     QLabel *lt = new QLabel(i18n("Transparent"), hboxslider);
0136     hboxsliderHBoxLayout->addWidget(lt);
0137     d->graySlider = new QSlider(hboxslider);
0138     hboxsliderHBoxLayout->addWidget(d->graySlider);
0139     d->graySlider->setOrientation(Qt::Horizontal);
0140     d->graySlider->setMinimum(0);
0141     d->graySlider->setPageStep(10);
0142     d->graySlider->setSingleStep(5);
0143     d->graySlider->setTickPosition(QSlider::TicksBelow);
0144     d->graySlider->setMaximum(100);
0145     QLabel *ls = new QLabel(i18n("Solid"), hboxslider);
0146     hboxsliderHBoxLayout->addWidget(ls);
0147 
0148     QVBoxLayout *vbox8 = new QVBoxLayout(d->grayBox);
0149     vbox8->addWidget(hboxslider);
0150     d->grayBox->setLayout(vbox8);
0151 
0152     //------------------ PATH Setup
0153     d->slideshowBox = new QGroupBox(this);
0154     d->slideshowBox->setTitle(i18n("Slideshow"));
0155 
0156     QWidget *imageFolderBox = new QWidget(this);
0157     QHBoxLayout *imageFolderBoxHBoxLayout = new QHBoxLayout(imageFolderBox);
0158     imageFolderBoxHBoxLayout->setContentsMargins(0, 0, 0, 0);
0159     d->imageFolderEdit = new QLineEdit(imageFolderBox);
0160     d->imageFolderEdit->setWhatsThis(
0161         i18n("Select the folder from which you "
0162              "want to see images. These images are randomly shown during the breaks. "
0163              "It will be searched recursively if you want..."));
0164     d->changePathButton = new QPushButton(i18n("&Change..."), imageFolderBox);
0165     imageFolderBoxHBoxLayout->addWidget(d->changePathButton);
0166     imageFolderBoxHBoxLayout->addWidget(d->imageFolderEdit);
0167     d->searchRecursiveCheck = new QCheckBox(i18n("Search path recursively"), this);
0168     d->showSmallImagesCheck = new QCheckBox(i18n("Show small images"), this);
0169     d->expandImageToFullScreen = new QCheckBox(i18n("Expand image to full screen"), this);
0170     d->expandImageToFullScreen->setWhatsThis(
0171         i18n("If checked then image will be expanded to full screen. "
0172              "Part of the image outside the screen area will be cropped. "
0173              "Otherwise the image will be displayed completely but there may grey areas around it. "));
0174 
0175     QWidget *m5 = new QWidget(this);
0176     QHBoxLayout *m5HBoxLayout = new QHBoxLayout(m5);
0177     m5HBoxLayout->setContentsMargins(0, 0, 0, 0);
0178     QLabel *l5 = new QLabel(i18n("Change images every:") + ' ', m5);
0179     m5HBoxLayout->addWidget(l5);
0180     l5->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
0181     l5->setWhatsThis(
0182         i18n("Here you can set how long one image should be "
0183              "shown before it is replaced by the next one."));
0184     d->slideInterval = new KPluralHandlingSpinBox(m5);
0185     m5HBoxLayout->addWidget(d->slideInterval);
0186     d->slideInterval->setRange(3, 1000);
0187     d->slideInterval->setSuffix(ki18np(" second", " seconds"));
0188 
0189     connect(d->changePathButton, &QPushButton::clicked, this, &SetupMaximized::slotFolderPicker);
0190     connect(d->imageFolderEdit, &QLineEdit::textChanged, this, &SetupMaximized::slotFolderEdited);
0191 
0192     QVBoxLayout *vboxg = new QVBoxLayout(d->slideshowBox);
0193     vboxg->addWidget(imageFolderBox);
0194     vboxg->addWidget(d->searchRecursiveCheck);
0195     vboxg->addWidget(d->showSmallImagesCheck);
0196     vboxg->addWidget(d->expandImageToFullScreen);
0197     vboxg->addWidget(m5);
0198     d->slideshowBox->setLayout(vboxg);
0199 
0200     //---------------- Popup setup
0201 
0202     d->popupBox = new QGroupBox(this);
0203     d->popupBox->setTitle(i18n("Popup"));
0204 
0205     QLabel *label = new QLabel(i18n("RSIBreak can show a popup before replacing your whole screen with the effect chosen above."), this);
0206     label->setWordWrap(true);
0207 
0208     d->usePopup = new QCheckBox(i18n("&Use the popup"), this);
0209     connect(d->usePopup, &QCheckBox::toggled, this, &SetupMaximized::slotHideFlash);
0210     d->usePopup->setWhatsThis(i18n("Shows a countdown popup when it is time to break. The countdown resets on activity."));
0211     label->setBuddy(d->usePopup);
0212 
0213     QWidget *m6 = new QWidget(this);
0214     QHBoxLayout *m6HBoxLayout = new QHBoxLayout(m6);
0215     m6HBoxLayout->setContentsMargins(0, 0, 0, 0);
0216     d->popupDurationLabel = new QLabel(i18n("Popup patience:") + ' ', m6);
0217     m6HBoxLayout->addWidget(d->popupDurationLabel);
0218     d->popupDurationLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
0219     d->popupDurationLabel->setWhatsThis(i18n("Maximum time the patience popup will be shown before the effect kicking in."));
0220     d->popupDurationLabel->setSizePolicy(d->popupDurationLabel->sizePolicy().horizontalPolicy(), QSizePolicy::Minimum);
0221     d->popupDuration = new KPluralHandlingSpinBox(m6);
0222     m6HBoxLayout->addWidget(d->popupDuration);
0223     d->popupDuration->setRange(3, 1000);
0224     d->popupDuration->setSuffix(ki18np(" second", " seconds"));
0225     d->popupDurationLabel->setBuddy(d->popupDuration);
0226 
0227     d->useFlashLabel = new QLabel(i18n("The popup can flash when it detects that you are still active."), this);
0228     d->useFlashLabel->setWordWrap(true);
0229     d->useFlashLabel->setSizePolicy(d->useFlashLabel->sizePolicy().horizontalPolicy(), QSizePolicy::Minimum);
0230 
0231     d->useFlash = new QCheckBox(i18n("&Flash on activity"), this);
0232     d->useFlash->setWhatsThis(
0233         i18n("With this checkbox you can indicate "
0234              "if you want to see the popup flash when there is activity."));
0235     d->useFlashLabel->setBuddy(d->useFlashLabel);
0236 
0237     QVBoxLayout *vbox3 = new QVBoxLayout(d->popupBox);
0238     vbox3->addWidget(label);
0239     vbox3->addWidget(d->usePopup);
0240     vbox3->addWidget(m6);
0241     vbox3->addWidget(d->useFlashLabel);
0242     vbox3->addWidget(d->useFlash);
0243     d->popupBox->setLayout(vbox3);
0244 
0245     l->addWidget(d->effectLabel);
0246     l->addWidget(d->effectBox);
0247     l->addWidget(d->grayBox);
0248     l->addWidget(d->plasmaBox);
0249     l->addWidget(d->slideshowBox);
0250     l->addWidget(skipBox);
0251     l->addWidget(d->popupBox);
0252     l->addStretch(1);
0253     setLayout(l);
0254     readSettings();
0255     slotHideFlash();
0256 }
0257 
0258 SetupMaximized::~SetupMaximized()
0259 {
0260     delete d;
0261 }
0262 
0263 void SetupMaximized::slotSetUseIdleTimer(bool useIdleTimer)
0264 {
0265     d->popupBox->setEnabled(useIdleTimer);
0266 }
0267 
0268 void SetupMaximized::slotEffectChanged(int current)
0269 {
0270     int effect = d->effectBox->itemData(current).toInt();
0271     switch (effect) {
0272     case RSIObject::SlideShow:
0273         d->slideshowBox->setVisible(true);
0274         d->plasmaBox->setVisible(false);
0275         d->grayBox->setVisible(false);
0276         break;
0277     case RSIObject::Plasma:
0278         d->slideshowBox->setVisible(false);
0279         d->plasmaBox->setVisible(true);
0280         d->grayBox->setVisible(false);
0281         break;
0282     case RSIObject::SimpleGray:
0283         d->slideshowBox->setVisible(false);
0284         d->plasmaBox->setVisible(false);
0285         d->grayBox->setVisible(KWindowSystem::compositingActive());
0286         break;
0287     case RSIObject::Popup:
0288     default:
0289         d->slideshowBox->setVisible(false);
0290         d->plasmaBox->setVisible(false);
0291         break;
0292     }
0293 }
0294 
0295 void SetupMaximized::slotFolderPicker()
0296 {
0297     QString result = QFileDialog::getExistingDirectory(this, d->imageFolderEdit->text());
0298 
0299     if (!result.isEmpty())
0300         d->imageFolderEdit->setText(result);
0301 }
0302 
0303 void SetupMaximized::slotFolderEdited(const QString &newPath)
0304 {
0305     if (newPath.isEmpty()) {
0306         d->imageFolderEdit->setText(QDir::homePath());
0307         return;
0308     }
0309 
0310     if (!newPath.startsWith('/')) {
0311         d->imageFolderEdit->setText(QDir::homePath() + '/' + newPath);
0312     }
0313 }
0314 
0315 void SetupMaximized::slotHideFlash()
0316 {
0317     d->effectLabel->setText(d->usePopup->isChecked() ? i18n("Choose the effect you want after patience runs out")
0318                                                      : i18n("Choose the effect you want during breaks"));
0319     d->useFlash->setEnabled(d->usePopup->isChecked());
0320     d->useFlashLabel->setEnabled(d->usePopup->isChecked());
0321     d->popupDuration->setEnabled(d->usePopup->isChecked());
0322     d->popupDurationLabel->setEnabled(d->usePopup->isChecked());
0323 }
0324 
0325 void SetupMaximized::applySettings()
0326 {
0327     KConfigGroup config = KSharedConfig::openConfig()->group("General Settings");
0328     config.writeEntry("ImageFolder", d->imageFolderEdit->text());
0329     config.writeEntry("SlideInterval", d->slideInterval->value());
0330     config.writeEntry("Patience", d->popupDuration->value());
0331 
0332     config.writeEntry("HideMinimizeButton", d->hideMinimizeButton->isChecked());
0333     config.writeEntry("HideLockButton", d->hideLockButton->isChecked());
0334     config.writeEntry("HidePostponeButton", d->hidePostponeButton->isChecked());
0335     config.writeEntry("SearchRecursiveCheck", d->searchRecursiveCheck->isChecked());
0336     config.writeEntry("ShowSmallImagesCheck", d->showSmallImagesCheck->isChecked());
0337     config.writeEntry("ExpandImageToFullScreen", d->expandImageToFullScreen->isChecked());
0338     config.writeEntry("Effect", d->effectBox->itemData(d->effectBox->currentIndex()));
0339 
0340     config.writeEntry("DisableAccel", d->disableAccel->isChecked());
0341     config.writeEntry("UsePlasmaReadOnly", d->readOnlyPlasma->isChecked());
0342     config.writeEntry("Graylevel", d->graySlider->value());
0343     config = KSharedConfig::openConfig()->group("Popup Settings");
0344     config.writeEntry("UsePopup", d->usePopup->isChecked());
0345     config.writeEntry("UseFlash", d->useFlash->isChecked());
0346 
0347     config.sync();
0348 }
0349 
0350 void SetupMaximized::readSettings()
0351 {
0352     const QString dir = QDir::home().path();
0353 
0354     KConfigGroup config = KSharedConfig::openConfig()->group("General Settings");
0355     d->imageFolderEdit->setText(config.readEntry("ImageFolder", dir));
0356     d->slideInterval->setValue(config.readEntry("SlideInterval", 10));
0357     d->popupDuration->setValue(config.readEntry("Patience", 30));
0358 
0359     d->hideMinimizeButton->setChecked(config.readEntry("HideMinimizeButton", false));
0360     d->hideLockButton->setChecked(config.readEntry("HideLockButton", false));
0361     d->hidePostponeButton->setChecked(config.readEntry("HidePostponeButton", false));
0362 
0363     const int effect = d->effectBox->findData(QVariant(config.readEntry("Effect", 0)));
0364     d->effectBox->setCurrentIndex(effect);
0365     slotEffectChanged(effect);
0366 
0367     d->searchRecursiveCheck->setChecked(config.readEntry("SearchRecursiveCheck", false));
0368     d->showSmallImagesCheck->setChecked(config.readEntry("ShowSmallImagesCheck", true));
0369     d->expandImageToFullScreen->setChecked(config.readEntry("ExpandImageToFullScreen", true));
0370     d->disableAccel->setChecked(config.readEntry("DisableAccel", false));
0371     d->readOnlyPlasma->setChecked(config.readEntry("UsePlasmaReadOnly", true));
0372     d->graySlider->setValue(config.readEntry("Graylevel", 80));
0373     config = KSharedConfig::openConfig()->group("Popup Settings");
0374     d->usePopup->setChecked(config.readEntry("UsePopup", true));
0375     d->useFlash->setChecked(config.readEntry("UseFlash", true));
0376 }