From 2dd9bae4b488d4eb2df6de4d708f8bf1ec6b907a Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 26 Sep 2023 16:22:46 +0200 Subject: [PATCH] Updated changelog feature --- app/changelogmodel.cpp | 38 +++++++++++++++++++++------------- app/changelogmodel.h | 15 +++++++++++--- app/qml/ChangelogPanel.qml | 42 +++++--------------------------------- 3 files changed, 41 insertions(+), 54 deletions(-) diff --git a/app/changelogmodel.cpp b/app/changelogmodel.cpp index 879110224..0da6633c8 100644 --- a/app/changelogmodel.cpp +++ b/app/changelogmodel.cpp @@ -1,12 +1,22 @@ -#include "ChangelogModel.h" +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "changelogmodel.h" #include #include #include +#include "coreutils.h" ChangelogModel::ChangelogModel( QObject *parent ) : QAbstractListModel{parent} { - _networkManager = new QNetworkAccessManager( this ); - connect( _networkManager, &QNetworkAccessManager::finished, this, &ChangelogModel::onFinished ); + mNetworkManager = new QNetworkAccessManager( this ); + connect( mNetworkManager, &QNetworkAccessManager::finished, this, &ChangelogModel::onFinished ); } void ChangelogModel::onFinished( QNetworkReply *reply ) @@ -49,10 +59,10 @@ void ChangelogModel::onFinished( QNetworkReply *reply ) if ( xml.name().toString() == "item" ) { QDateTime dt = QDateTime::fromString( pubDate, "ddd, dd MMM yyyy hh:mm:ss t" ); - if ( dt > _lastSeen ) + if ( dt > mLastSeen ) { beginInsertRows( QModelIndex(), rowCount(), rowCount() ); - _logs << Changelog{ title, description, link, dt }; + mLogs << Changelog{ title, description, link, dt }; endInsertRows(); } } @@ -60,16 +70,16 @@ void ChangelogModel::onFinished( QNetworkReply *reply ) } if ( xml.hasError() ) { - qWarning() << "XML error:" << xml.errorString(); + CoreUtils::log( QStringLiteral( "Changelog" ), QStringLiteral( "Failed to parse changelog. Xml parse error: " ).arg( xml.errorString() ) ); } } else { - qWarning() << "Network error:" << reply->errorString(); + CoreUtils::log( QStringLiteral( "Changelog" ), QStringLiteral( "Failed to get changelog. Server Error: %1" ).arg( reply->errorString() ) ); } reply->deleteLater(); - if ( !_logs.isEmpty() ) + if ( !mLogs.isEmpty() ) { emit dataChanged( createIndex( 0, 0 ), createIndex( rowCount(), 0 ) ); } @@ -89,7 +99,7 @@ QHash ChangelogModel::roleNames() const int ChangelogModel::rowCount( const QModelIndex &parent ) const { Q_UNUSED( parent ) - return _logs.size(); + return mLogs.size(); } QVariant ChangelogModel::data( const QModelIndex &index, int role ) const @@ -97,11 +107,11 @@ QVariant ChangelogModel::data( const QModelIndex &index, int role ) const if ( !hasIndex( index.row(), index.column(), index.parent() ) ) return {}; - Changelog log = _logs.at( index.row() ); + Changelog log = mLogs.at( index.row() ); if ( role == TitleRole ) return log.title; if ( role == DescriptionRole ) return log.description; if ( role == LinkRole ) return log.link; - if ( role == DateRole ) return log.date.toString( "ddd, dd MMMM yyyy" ); + if ( role == DateRole ) return log.date; return {}; } @@ -110,12 +120,12 @@ QVariant ChangelogModel::data( const QModelIndex &index, int role ) const void ChangelogModel::seeChangelogs( bool all ) { beginResetModel(); - _logs.clear(); + mLogs.clear(); endResetModel(); // get all the changes - _lastSeen = QDateTime::fromMSecsSinceEpoch( 0 ); - _networkManager->get( QNetworkRequest( QUrl( "https://wishlist.merginmaps.com/rss/changelog.xml" ) ) ); // TODO get URL from somewhere + mLastSeen = QDateTime::fromMSecsSinceEpoch( 0 ); + mNetworkManager->get( QNetworkRequest( QUrl( "https://wishlist.merginmaps.com/rss/changelog.xml" ) ) ); } diff --git a/app/changelogmodel.h b/app/changelogmodel.h index 4d10211ef..5d5e0da9c 100644 --- a/app/changelogmodel.h +++ b/app/changelogmodel.h @@ -1,3 +1,12 @@ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + #ifndef CHANGELOGMODEL_H #define CHANGELOGMODEL_H @@ -39,9 +48,9 @@ class ChangelogModel : public QAbstractListModel void finished( const QString &title, const QString &link ); private: - QList _logs; - QNetworkAccessManager *_networkManager; - QDateTime _lastSeen; + QList mLogs; + QNetworkAccessManager *mNetworkManager; + QDateTime mLastSeen; }; #endif // CHANGELOGMODEL_H diff --git a/app/qml/ChangelogPanel.qml b/app/qml/ChangelogPanel.qml index e63aa935f..4779911e0 100644 --- a/app/qml/ChangelogPanel.qml +++ b/app/qml/ChangelogPanel.qml @@ -29,8 +29,6 @@ Item { } Page { - id: pane - width: parent.width height: parent.height anchors.verticalCenter: parent.verticalCenter @@ -42,36 +40,26 @@ Item { } header: PanelHeader { - id: header height: InputStyle.rowHeightHeader width: parent.width color: InputStyle.clrPanelMain rowHeight: InputStyle.rowHeightHeader - titleText: qsTr("Change Log") + titleText: qsTr("What's new") onBack: root.close() withBackButton: true } Item { - id: changelogItem anchors.horizontalCenter: parent.horizontalCenter width: root.width - InputStyle.panelMargin height: parent.height Component.onCompleted: changelogView.model.seeChangelogs() - Text { - id: title - text: qsTr("What's new") - wrapMode: Text.WordWrap - width: parent.width - font.pixelSize: InputStyle.fontPixelSizeHeader - color: InputStyle.fontColor - } - Text { id: subTitle + anchors.top: title.bottom text: qsTr("See what changed since you were last here") wrapMode: Text.WordWrap @@ -80,17 +68,9 @@ Item { color: InputStyle.fontColor } - Button { - id: closeButton - anchors.right: parent.right - onClicked: close() - contentItem: Text { text: "❌" } - background: Item {} - visible: false - } - ListView { id: changelogView + width: parent.width anchors.top: subTitle.bottom anchors.topMargin: InputStyle.panelMargin @@ -106,7 +86,8 @@ Item { id: changeItem width: changelogView.width Rectangle { width: parent.width; height: InputStyle.changelogLineWidth; color: InputStyle.changelogLineWColor } - Text { text: date; font.italic: true; wrapMode: Text.WordWrap; width: parent.width; font.pixelSize: InputStyle.fontPixelSizeNormal; color: InputStyle.fontColor } + Text { text: Qt.locale().dayName( date.getDay(), Locale.ShortFormat ) + ", " + date.getDate() + " " + Qt.locale().monthName( date.getMonth(), Locale.LongFormat ) + font.italic: true; wrapMode: Text.WordWrap; width: parent.width; font.pixelSize: InputStyle.fontPixelSizeNormal; color: InputStyle.fontColor } Text { text: title; font.bold: true; wrapMode: Text.WordWrap; width: parent.width; font.pixelSize: InputStyle.fontPixelSizeBig; color: InputStyle.fontColor } Text { text: description; wrapMode: Text.WordWrap; width: parent.width; font.pixelSize: InputStyle.fontPixelSizeNormal; color: InputStyle.fontColor } } @@ -119,22 +100,9 @@ Item { anchors.bottom: changelogView.bottom } } - - Button { - id: seeAllChangesButton - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottom: parent.bottom - onClicked: { - changelogView.model.seeChangelogs(true) - } - text: qsTr("Show all changes") - visible: false - } } footer: DelegateButton { - id: showAllButton - width: root.width height: InputStyle.rowHeightHeader text: qsTr("Show all changes")