File indexing completed on 2024-05-12 16:37:20
0001 /* This file is part of the KDE project 0002 Copyright (C) 2017 Dag Andersen <danders@get2net.dk> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 // clazy:excludeall=qstring-arg 0021 #include "ConfigWorkVacationPanel.h" 0022 0023 #include "calligraplansettings.h" 0024 0025 0026 #include <kactioncollection.h> 0027 0028 #ifdef HAVE_KHOLIDAYS 0029 #include <KHolidays/HolidayRegion> 0030 #endif 0031 0032 #include <QFileDialog> 0033 0034 namespace KPlato 0035 { 0036 0037 ConfigWorkVacationPanel::ConfigWorkVacationPanel(QWidget *parent) 0038 : ConfigWorkVacationPanelImpl(parent) 0039 { 0040 } 0041 0042 //----------------------------- 0043 ConfigWorkVacationPanelImpl::ConfigWorkVacationPanelImpl(QWidget *p) 0044 : QWidget(p) 0045 { 0046 setupUi(this); 0047 kcfg_Region->hide(); 0048 #ifdef HAVE_KHOLIDAYS 0049 int idx = 0; 0050 const QString regionCode = kcfg_Region->text(); 0051 0052 region->addItem(i18n("Default"), "Default"); 0053 foreach(const QString &s, KHolidays::HolidayRegion::regionCodes()) { 0054 region->addItem(KHolidays::HolidayRegion::name(s), s); 0055 int row = region->count() - 1; 0056 region->setItemData(row, KHolidays::HolidayRegion::description(s), Qt::ToolTipRole); 0057 if (s == regionCode) { 0058 idx = row; 0059 } 0060 } 0061 connect(region, SIGNAL(currentIndexChanged(int)), this, SLOT(slotRegionChanged(int))); 0062 connect(kcfg_Region, &QLineEdit::textChanged, this, &ConfigWorkVacationPanelImpl::slotRegionCodeChanged); 0063 region->setCurrentIndex(idx); 0064 #else 0065 holidaysWidget->hide(); 0066 #endif 0067 } 0068 0069 #ifdef HAVE_KHOLIDAYS 0070 void ConfigWorkVacationPanelImpl::slotRegionChanged(int idx) 0071 { 0072 QString r = region->itemData(idx).toString(); 0073 if (r != kcfg_Region->text()) { 0074 kcfg_Region->setText(r); 0075 } 0076 } 0077 0078 void ConfigWorkVacationPanelImpl::slotRegionCodeChanged(const QString &code) 0079 { 0080 QString r = region->itemData(region->currentIndex()).toString(); 0081 if (r != code) { 0082 for (int idx = 0; idx < region->count(); ++idx) { 0083 if (region->itemData(idx).toString() == code) { 0084 region->setCurrentIndex(idx); 0085 break; 0086 } 0087 } 0088 } 0089 } 0090 #endif 0091 0092 } //KPlato namespace