Skip to content

Commit

Permalink
Updated changelog feature
Browse files Browse the repository at this point in the history
  • Loading branch information
iiLubos committed Sep 26, 2023
1 parent 1f754ca commit 2dd9bae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 54 deletions.
38 changes: 24 additions & 14 deletions app/changelogmodel.cpp
Original file line number Diff line number Diff line change
@@ -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 <QNetworkReply>
#include <QXmlStreamReader>
#include <QDebug>
#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 )
Expand Down Expand Up @@ -49,27 +59,27 @@ 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();
}
}
}
}
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 ) );
}
Expand All @@ -89,19 +99,19 @@ QHash<int, QByteArray> 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
{
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 {};
}
Expand All @@ -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" ) ) );
}


15 changes: 12 additions & 3 deletions app/changelogmodel.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -39,9 +48,9 @@ class ChangelogModel : public QAbstractListModel
void finished( const QString &title, const QString &link );

private:
QList<Changelog> _logs;
QNetworkAccessManager *_networkManager;
QDateTime _lastSeen;
QList<Changelog> mLogs;
QNetworkAccessManager *mNetworkManager;
QDateTime mLastSeen;
};

#endif // CHANGELOGMODEL_H
42 changes: 5 additions & 37 deletions app/qml/ChangelogPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ Item {
}

Page {
id: pane

width: parent.width
height: parent.height
anchors.verticalCenter: parent.verticalCenter
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }
}
Expand All @@ -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")
Expand Down

1 comment on commit 2dd9bae

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 23.09.458811 just submitted!

Please sign in to comment.