From f1b3184aaae743fc41dfac4b9dd1842f1da5c067 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 4 May 2020 10:07:07 +0200 Subject: [PATCH] Fix obsolete code. --- src/librssguard/core/feeddownloader.cpp | 15 ++++++++------- src/librssguard/core/feeddownloader.h | 2 -- .../dynamic-shortcuts/dynamicshortcutswidget.cpp | 8 +++----- .../dynamic-shortcuts/dynamicshortcutswidget.h | 3 --- src/librssguard/gui/squeezelabel.cpp | 4 ++++ src/librssguard/gui/squeezelabel.h | 2 +- src/librssguard/miscellaneous/autosaver.cpp | 4 ++-- src/librssguard/miscellaneous/autosaver.h | 4 ++-- .../miscellaneous/databasefactory.cpp | 14 ++++++++++++-- src/librssguard/miscellaneous/textfactory.cpp | 4 ++++ src/librssguard/miscellaneous/textfactory.h | 6 ------ src/librssguard/network-web/downloadmanager.h | 9 +++++---- .../services/abstract/cacheforserviceroot.cpp | 16 ++++++++-------- .../services/abstract/gui/formfeeddetails.cpp | 5 ++++- 14 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/librssguard/core/feeddownloader.cpp b/src/librssguard/core/feeddownloader.cpp index 217422727..96ad24a69 100644 --- a/src/librssguard/core/feeddownloader.cpp +++ b/src/librssguard/core/feeddownloader.cpp @@ -43,8 +43,11 @@ void FeedDownloader::updateAvailableFeeds() { } while (!m_feeds.isEmpty()) { - connect(m_feeds.first(), &Feed::messagesObtained, this, &FeedDownloader::oneFeedUpdateFinished, - (Qt::ConnectionType)(Qt::UniqueConnection | Qt::AutoConnection)); + connect(m_feeds.first(), + &Feed::messagesObtained, + this, + &FeedDownloader::oneFeedUpdateFinished, + Qt::ConnectionType(Qt::UniqueConnection | Qt::AutoConnection)); if (m_threadPool->tryStart(m_feeds.first())) { m_feeds.removeFirst(); @@ -150,11 +153,9 @@ void FeedDownloadResults::appendUpdatedFeed(const QPair& feed) { } void FeedDownloadResults::sort() { - qSort(m_updatedFeeds.begin(), m_updatedFeeds.end(), FeedDownloadResults::lessThan); -} - -bool FeedDownloadResults::lessThan(const QPair& lhs, const QPair& rhs) { - return lhs.second > rhs.second; + std::sort(m_updatedFeeds.begin(), m_updatedFeeds.end(), [](const QPair& lhs, const QPair& rhs) { + return lhs.second > rhs.second; + }); } void FeedDownloadResults::clear() { diff --git a/src/librssguard/core/feeddownloader.h b/src/librssguard/core/feeddownloader.h index 12f2a38e2..8ce1b7f90 100644 --- a/src/librssguard/core/feeddownloader.h +++ b/src/librssguard/core/feeddownloader.h @@ -23,8 +23,6 @@ class FeedDownloadResults { void sort(); void clear(); - static bool lessThan(const QPair& lhs, const QPair& rhs); - private: // QString represents title if the feed, int represents count of newly downloaded messages. diff --git a/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.cpp b/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.cpp index 7734905a7..28858a98f 100644 --- a/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.cpp +++ b/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.cpp @@ -48,7 +48,9 @@ void DynamicShortcutsWidget::updateShortcuts() { void DynamicShortcutsWidget::populate(QList actions) { m_actionBindings.clear(); - qSort(actions.begin(), actions.end(), DynamicShortcutsWidget::lessThan); + std::sort(actions.begin(), actions.end(), [](QAction* lhs, QAction* rhs) { + return QString::localeAwareCompare(lhs->text().replace(QL1S("&"), QString()), rhs->text().replace(QL1S("&"), QString())) < 0; + }); int row_id = 0; // FIXME: Maybe separate actions into "categories". Each category will start with label. @@ -93,7 +95,3 @@ void DynamicShortcutsWidget::populate(QList actions) { m_layout->setRowStretch(row_id, 1); m_layout->setColumnStretch(1, 1); } - -bool DynamicShortcutsWidget::lessThan(QAction* lhs, QAction* rhs) { - return QString::localeAwareCompare(lhs->text().replace(QL1S("&"), QString()), rhs->text().replace(QL1S("&"), QString())) < 0; -} diff --git a/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.h b/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.h index 2d0176fa6..d2583a297 100644 --- a/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.h +++ b/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.h @@ -38,9 +38,6 @@ class DynamicShortcutsWidget : public QWidget { signals: void setupChanged(); - private: - static bool lessThan(QAction* lhs, QAction* rhs); - private: QGridLayout* m_layout; diff --git a/src/librssguard/gui/squeezelabel.cpp b/src/librssguard/gui/squeezelabel.cpp index acb91135e..38a124379 100644 --- a/src/librssguard/gui/squeezelabel.cpp +++ b/src/librssguard/gui/squeezelabel.cpp @@ -9,7 +9,11 @@ void SqueezeLabel::paintEvent(QPaintEvent* event) { m_squeezedTextCache = text(); QFontMetrics fm = fontMetrics(); +#if QT_VERSION >= 0x050B00 // Qt >= 5.11.0 + if (fm.horizontalAdvance(m_squeezedTextCache) > contentsRect().width()) { +#else if (fm.width(m_squeezedTextCache) > contentsRect().width()) { +#endif setText(fm.elidedText(text(), Qt::ElideMiddle, width())); } } diff --git a/src/librssguard/gui/squeezelabel.h b/src/librssguard/gui/squeezelabel.h index 7c41250ef..66ee252f2 100644 --- a/src/librssguard/gui/squeezelabel.h +++ b/src/librssguard/gui/squeezelabel.h @@ -9,7 +9,7 @@ class SqueezeLabel : public QLabel { Q_OBJECT public: - explicit SqueezeLabel(QWidget* parent = 0); + explicit SqueezeLabel(QWidget* parent = nullptr); protected: void paintEvent(QPaintEvent* event); diff --git a/src/librssguard/miscellaneous/autosaver.cpp b/src/librssguard/miscellaneous/autosaver.cpp index 2e94bb250..5658a1d00 100644 --- a/src/librssguard/miscellaneous/autosaver.cpp +++ b/src/librssguard/miscellaneous/autosaver.cpp @@ -24,7 +24,7 @@ AutoSaver::~AutoSaver() { } void AutoSaver::changeOccurred() { - if (m_firstChange.isNull()) { + if (!m_firstChange.isValid()) { m_firstChange.start(); } @@ -48,7 +48,7 @@ void AutoSaver::timerEvent(QTimerEvent* event) { void AutoSaver::saveIfNeccessary() { if (m_timer.isActive()) { m_timer.stop(); - m_firstChange = QTime(); + m_firstChange.invalidate(); if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection)) { qWarning("AutoSaver: error invoking slot save() on parent."); diff --git a/src/librssguard/miscellaneous/autosaver.h b/src/librssguard/miscellaneous/autosaver.h index 16a50f567..7eee19a48 100644 --- a/src/librssguard/miscellaneous/autosaver.h +++ b/src/librssguard/miscellaneous/autosaver.h @@ -4,8 +4,8 @@ #define AUTOSAVER_H #include +#include #include -#include class AutoSaver : public QObject { Q_OBJECT @@ -24,7 +24,7 @@ class AutoSaver : public QObject { private: QBasicTimer m_timer; - QTime m_firstChange; + QElapsedTimer m_firstChange; }; #endif // AUTOSAVER_H diff --git a/src/librssguard/miscellaneous/databasefactory.cpp b/src/librssguard/miscellaneous/databasefactory.cpp index d0ea5a3de..c83988a8f 100644 --- a/src/librssguard/miscellaneous/databasefactory.cpp +++ b/src/librssguard/miscellaneous/databasefactory.cpp @@ -104,8 +104,18 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString& } } else if (database.lastError().isValid()) { - // Connection failed, do cleanup and return specific error code. - return static_cast(database.lastError().number()); + auto nat = database.lastError().nativeErrorCode(); + bool nat_converted = false; + auto nat_int = nat.toInt(&nat_converted); + + if (nat_converted) { + return static_cast(nat_int); + } + else { + qWarning("Failed to recognize MySQL error code: '%s'.", qPrintable(nat)); + + return MySQLError::MySQLUnknownError; + } } else { return MySQLError::MySQLUnknownError; diff --git a/src/librssguard/miscellaneous/textfactory.cpp b/src/librssguard/miscellaneous/textfactory.cpp index 9d2770a97..8b0467d21 100755 --- a/src/librssguard/miscellaneous/textfactory.cpp +++ b/src/librssguard/miscellaneous/textfactory.cpp @@ -30,7 +30,11 @@ int TextFactory::stringWidth(const QString& string, const QFontMetrics& metrics) int width = 0; foreach (const QString& line, lines) { +#if QT_VERSION >= 0x050B00 // Qt >= 5.11.0 + int line_width = metrics.horizontalAdvance(line); +#else int line_width = metrics.width(line); +#endif if (line_width > width) { width = line_width; diff --git a/src/librssguard/miscellaneous/textfactory.h b/src/librssguard/miscellaneous/textfactory.h index ada853610..71771e9d1 100755 --- a/src/librssguard/miscellaneous/textfactory.h +++ b/src/librssguard/miscellaneous/textfactory.h @@ -15,12 +15,6 @@ class TextFactory { TextFactory(); public: - - // Returns true if lhs is smaller than rhs if case-insensitive string comparison is used. - static inline bool isCaseInsensitiveLessThan(const QString& lhs, const QString& rhs) { - return lhs.toLower() < rhs.toLower(); - } - static int stringHeight(const QString& string, const QFontMetrics& metrics); static int stringWidth(const QString& string, const QFontMetrics& metrics); diff --git a/src/librssguard/network-web/downloadmanager.h b/src/librssguard/network-web/downloadmanager.h index 6d0222f24..28def92cb 100644 --- a/src/librssguard/network-web/downloadmanager.h +++ b/src/librssguard/network-web/downloadmanager.h @@ -9,6 +9,7 @@ #include "gui/tabcontent.h" #include +#include #include #include @@ -27,7 +28,7 @@ class DownloadItem : public QWidget { public: // Constructors. - explicit DownloadItem(QNetworkReply* reply = 0, QWidget* parent = 0); + explicit DownloadItem(QNetworkReply* reply = 0, QWidget* parent = nullptr); virtual ~DownloadItem(); bool downloading() const; @@ -67,7 +68,7 @@ class DownloadItem : public QWidget { QFile m_output; QNetworkReply* m_reply; qint64 m_bytesReceived; - QTime m_downloadTime; + QElapsedTimer m_downloadTime; QTime m_lastProgressTime; bool m_requestFileName; bool m_startedSaving; @@ -95,7 +96,7 @@ class DownloadManager : public TabContent { Q_ENUM(RemovePolicy) - explicit DownloadManager(QWidget* parent = 0); + explicit DownloadManager(QWidget* parent = nullptr); virtual ~DownloadManager(); #if defined(USE_WEBENGINE) @@ -159,7 +160,7 @@ class DownloadModel : public QAbstractListModel { friend class DownloadManager; public: - explicit DownloadModel(DownloadManager* download_manager, QObject* parent = 0); + explicit DownloadModel(DownloadManager* download_manager, QObject* parent = nullptr); QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; int rowCount(const QModelIndex& parent = QModelIndex()) const; diff --git a/src/librssguard/services/abstract/cacheforserviceroot.cpp b/src/librssguard/services/abstract/cacheforserviceroot.cpp index d20e13a17..a48140521 100644 --- a/src/librssguard/services/abstract/cacheforserviceroot.cpp +++ b/src/librssguard/services/abstract/cacheforserviceroot.cpp @@ -22,15 +22,15 @@ void CacheForServiceRoot::addMessageStatesToCache(const QList& ids_of_m // Store changes, they will be sent to server later. list_act.append(ids_of_messages); - QSet set_act = list_act.toSet(); - QSet set_other = list_other.toSet(); + QSet set_act(list_act.begin(), list_act.end()); + QSet set_other(list_other.begin(), list_other.end()); // Now, we want to remove all IDS from list_other, which are contained in list. set_other -= set_act; list_act.clear(); - list_act.append(set_act.toList()); + list_act.append(set_act.values()); list_other.clear(); - list_other.append(set_other.toList()); + list_other.append(set_other.values()); m_cacheSaveMutex->unlock(); } @@ -43,15 +43,15 @@ void CacheForServiceRoot::addMessageStatesToCache(const QStringList& ids_of_mess // Store changes, they will be sent to server later. list_act.append(ids_of_messages); - QSet set_act = list_act.toSet(); - QSet set_other = list_other.toSet(); + QSet set_act(list_act.begin(), list_act.end()); + QSet set_other(list_other.begin(), list_other.end()); // Now, we want to remove all IDS from list_other, which are contained in list. set_other -= set_act; list_act.clear(); - list_act.append(set_act.toList()); + list_act.append(set_act.values()); list_other.clear(); - list_other.append(set_other.toList()); + list_other.append(set_other.values()); m_cacheSaveMutex->unlock(); } diff --git a/src/librssguard/services/abstract/gui/formfeeddetails.cpp b/src/librssguard/services/abstract/gui/formfeeddetails.cpp index 7a520aa5a..5c87a968c 100644 --- a/src/librssguard/services/abstract/gui/formfeeddetails.cpp +++ b/src/librssguard/services/abstract/gui/formfeeddetails.cpp @@ -330,7 +330,10 @@ void FormFeedDetails::initialize() { } // Sort encodings and add them. - qSort(encoded_encodings.begin(), encoded_encodings.end(), TextFactory::isCaseInsensitiveLessThan); + std::sort(encoded_encodings.begin(), encoded_encodings.end(), [](const QString& lhs, const QString& rhs) { + return lhs.toLower() < rhs.toLower(); + }); + m_ui->m_cmbEncoding->addItems(encoded_encodings); // Setup menu & actions for icon selection.