Skip to content

Commit

Permalink
Migrate away from deprecated functions in Qt 6.9
Browse files Browse the repository at this point in the history
Closes #21412.
PR #21415.
  • Loading branch information
Chocobo1 authored Sep 30, 2024
1 parent c30a077 commit 7b45566
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
28 changes: 5 additions & 23 deletions src/base/net/smtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,29 +565,11 @@ void Smtp::logError(const QString &msg)

QString Smtp::getCurrentDateTime() const
{
// return date & time in the format specified in RFC 2822, section 3.3
const QDateTime nowDateTime = QDateTime::currentDateTime();
const QDate nowDate = nowDateTime.date();
const QLocale eng(QLocale::English);

const QString timeStr = nowDateTime.time().toString(u"HH:mm:ss");
const QString weekDayStr = eng.dayName(nowDate.dayOfWeek(), QLocale::ShortFormat);
const QString dayStr = QString::number(nowDate.day());
const QString monthStr = eng.monthName(nowDate.month(), QLocale::ShortFormat);
const QString yearStr = QString::number(nowDate.year());

QDateTime tmp = nowDateTime;
tmp.setTimeSpec(Qt::UTC);
const int timeOffsetHour = nowDateTime.secsTo(tmp) / 3600;
const int timeOffsetMin = nowDateTime.secsTo(tmp) / 60 - (60 * timeOffsetHour);
const int timeOffset = timeOffsetHour * 100 + timeOffsetMin;
// buf size = 11 to avoid format truncation warnings from snprintf
char buf[11] = {0};
std::snprintf(buf, sizeof(buf), "%+05d", timeOffset);
const auto timeOffsetStr = QString::fromUtf8(buf);

const QString ret = weekDayStr + u", " + dayStr + u' ' + monthStr + u' ' + yearStr + u' ' + timeStr + u' ' + timeOffsetStr;
return ret;
// [rfc2822] 3.3. Date and Time Specification
const auto now = QDateTime::currentDateTime();
const QLocale eng {QLocale::English};
const QString weekday = eng.dayName(now.date().dayOfWeek(), QLocale::ShortFormat);
return (weekday + u", " + now.toString(Qt::RFC2822Date));
}

void Smtp::error(QAbstractSocket::SocketError socketError)
Expand Down
3 changes: 2 additions & 1 deletion src/base/rss/rss_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <QMetaObject>
#include <QRegularExpression>
#include <QStringList>
#include <QTimeZone>
#include <QVariant>
#include <QXmlStreamEntityResolver>
#include <QXmlStreamReader>
Expand Down Expand Up @@ -521,7 +522,7 @@ namespace
return QDateTime::currentDateTime();

const QTime qTime(hour, minute, second);
QDateTime result(qDate, qTime, Qt::UTC);
QDateTime result(qDate, qTime, QTimeZone::UTC);
if (offset)
result = result.addSecs(-offset);
if (!result.isValid())
Expand Down
7 changes: 7 additions & 0 deletions src/gui/advancedsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <limits>

#include <QtVersionChecks>
#include <QHeaderView>
#include <QHostAddress>
#include <QLabel>
Expand Down Expand Up @@ -981,7 +982,13 @@ void AdvancedSettings::addRow(const int row, const QString &text, T *widget)
setCellWidget(row, VALUE, widget);

if constexpr (std::is_same_v<T, QCheckBox>)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
connect(widget, &QCheckBox::checkStateChanged, this, &AdvancedSettings::settingsChanged);
#else
connect(widget, &QCheckBox::stateChanged, this, &AdvancedSettings::settingsChanged);
#endif
}
else if constexpr (std::is_same_v<T, QSpinBox>)
connect(widget, qOverload<int>(&QSpinBox::valueChanged), this, &AdvancedSettings::settingsChanged);
else if constexpr (std::is_same_v<T, QComboBox>)
Expand Down
8 changes: 8 additions & 0 deletions src/gui/rss/automatedrssdownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "automatedrssdownloader.h"

#include <QtVersionChecks>
#include <QCursor>
#include <QFileDialog>
#include <QMenu>
Expand Down Expand Up @@ -129,10 +130,17 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent)
connect(m_ui->lineNotContains, &QLineEdit::textEdited, this, &AutomatedRssDownloader::updateMustNotLineValidity);
connect(m_ui->lineEFilter, &QLineEdit::textEdited, this, &AutomatedRssDownloader::handleRuleDefinitionChanged);
connect(m_ui->lineEFilter, &QLineEdit::textEdited, this, &AutomatedRssDownloader::updateEpisodeFilterValidity);
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
connect(m_ui->checkRegex, &QCheckBox::checkStateChanged, this, &AutomatedRssDownloader::handleRuleDefinitionChanged);
connect(m_ui->checkRegex, &QCheckBox::checkStateChanged, this, &AutomatedRssDownloader::updateMustLineValidity);
connect(m_ui->checkRegex, &QCheckBox::checkStateChanged, this, &AutomatedRssDownloader::updateMustNotLineValidity);
connect(m_ui->checkSmart, &QCheckBox::checkStateChanged, this, &AutomatedRssDownloader::handleRuleDefinitionChanged);
#else
connect(m_ui->checkRegex, &QCheckBox::stateChanged, this, &AutomatedRssDownloader::handleRuleDefinitionChanged);
connect(m_ui->checkRegex, &QCheckBox::stateChanged, this, &AutomatedRssDownloader::updateMustLineValidity);
connect(m_ui->checkRegex, &QCheckBox::stateChanged, this, &AutomatedRssDownloader::updateMustNotLineValidity);
connect(m_ui->checkSmart, &QCheckBox::stateChanged, this, &AutomatedRssDownloader::handleRuleDefinitionChanged);
#endif
connect(m_ui->spinIgnorePeriod, qOverload<int>(&QSpinBox::valueChanged)
, this, &AutomatedRssDownloader::handleRuleDefinitionChanged);

Expand Down

0 comments on commit 7b45566

Please sign in to comment.