File indexing completed on 2024-12-01 04:33:28

0001 /***************************************************************************
0002  *   Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>                     *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program 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         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
0018  ***************************************************************************/
0019 
0020 #include "generalwidget.h"
0021 
0022 #include <QTimeZone>
0023 
0024 #include "metalinker.h"
0025 
0026 GeneralWidget::GeneralWidget(QWidget *parent)
0027     : QWidget(parent)
0028 {
0029     ui.setupUi(this);
0030 
0031     ui.dynamic->setToolTip(ui.labelDynamic->toolTip());
0032 
0033     connect(ui.publishedGroupBox, &QGroupBox::toggled, this, &GeneralWidget::slotPublishedEnabled);
0034     connect(ui.updatedGroupBox, &QGroupBox::toggled, this, &GeneralWidget::slotUpdatedEnabled);
0035 }
0036 
0037 void GeneralWidget::load(const KGetMetalink::Metalink &metalink) const
0038 {
0039     ui.origin->setUrl(metalink.origin);
0040     ui.dynamic->setChecked(metalink.dynamic);
0041 
0042     ui.publishedGroupBox->setChecked(metalink.published.isValid());
0043     ui.use_publishedtimeoffset->setChecked(metalink.published.timeZoneOffset.isValid());
0044     if (metalink.published.isValid()) {
0045         ui.published->setDateTime(metalink.published.dateTime);
0046         ui.publishedoffset->setTime(metalink.published.timeZoneOffset);
0047         ui.publishedNegative->setChecked(metalink.published.negativeOffset);
0048     } else {
0049         ui.published->setDateTime(QDateTime::currentDateTime());
0050         QDateTime a = QDateTime::currentDateTime();
0051         a.setTimeZone(QTimeZone::systemTimeZone());
0052         int offset = a.offsetFromUtc();
0053         const bool negativeOffset = (offset < 0);
0054         offset = abs(offset);
0055         QTime time = QTime(0, 0, 0);
0056         time = time.addSecs(abs(offset));
0057         ui.publishedoffset->setTime(time);
0058 
0059         // to not enable publishedNegative block the signals
0060         ui.use_publishedtimeoffset->blockSignals(true);
0061         ui.use_publishedtimeoffset->setChecked(true);
0062         ui.use_publishedtimeoffset->blockSignals(false);
0063 
0064         ui.publishedNegative->setChecked(negativeOffset);
0065     }
0066 
0067     ui.updatedGroupBox->setChecked(metalink.updated.isValid());
0068     ui.use_updatedtimeoffset->setChecked(metalink.updated.timeZoneOffset.isValid());
0069     if (metalink.updated.isValid()) {
0070         ui.updated->setDateTime(metalink.updated.dateTime);
0071         ui.updatedoffset->setTime(metalink.updated.timeZoneOffset);
0072         ui.updatedNegative->setChecked(metalink.updated.negativeOffset);
0073     } else {
0074         ui.updated->setDateTime(QDateTime::currentDateTime());
0075         QDateTime a = QDateTime::currentDateTime();
0076         a.setTimeZone(QTimeZone::systemTimeZone());
0077         int offset = a.offsetFromUtc();
0078         const bool negativeOffset = (offset < 0);
0079         QTime time = QTime(0, 0, 0);
0080         time = time.addSecs(abs(offset));
0081         ui.updatedoffset->setTime(time);
0082 
0083         // to not enable publishedNegative block the signals
0084         ui.use_updatedtimeoffset->blockSignals(true);
0085         ui.use_updatedtimeoffset->setChecked(true);
0086         ui.use_updatedtimeoffset->blockSignals(false);
0087 
0088         ui.updatedNegative->setChecked(negativeOffset);
0089     }
0090 }
0091 
0092 void GeneralWidget::save(KGetMetalink::Metalink *metalink)
0093 {
0094     metalink->origin = QUrl(ui.origin->text());
0095     metalink->dynamic = ui.dynamic->isChecked();
0096 
0097     metalink->published.clear();
0098     if (ui.publishedGroupBox->isChecked()) {
0099         metalink->published.dateTime = ui.published->dateTime();
0100         if (ui.use_publishedtimeoffset->isChecked()) {
0101             metalink->published.timeZoneOffset = ui.publishedoffset->time();
0102         }
0103     }
0104 
0105     metalink->updated.clear();
0106     if (ui.updatedGroupBox->isChecked()) {
0107         metalink->updated.dateTime = ui.updated->dateTime();
0108         if (ui.use_updatedtimeoffset->isChecked()) {
0109             metalink->updated.timeZoneOffset = ui.updatedoffset->time();
0110         }
0111     }
0112 }
0113 
0114 void GeneralWidget::slotPublishedEnabled(bool enabled)
0115 {
0116     if (enabled) {
0117         ui.publishedNegative->setEnabled(ui.use_publishedtimeoffset->isChecked());
0118     }
0119 }
0120 
0121 void GeneralWidget::slotUpdatedEnabled(bool enabled)
0122 {
0123     if (enabled) {
0124         ui.updatedNegative->setEnabled(ui.use_updatedtimeoffset->isChecked());
0125     }
0126 }
0127 
0128 #include "moc_generalwidget.cpp"