-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-2.3_CU-861mzpq1c_changelog' into master_changelog
- Loading branch information
Showing
7 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include "ChangelogModel.h" | ||
#include <QNetworkReply> | ||
#include <QXmlStreamReader> | ||
#include <QDebug> | ||
|
||
ChangelogModel::ChangelogModel( QObject *parent ) : QAbstractListModel{parent} | ||
{ | ||
_networkManager = new QNetworkAccessManager( this ); | ||
connect( _networkManager, &QNetworkAccessManager::finished, this, &ChangelogModel::onFinished ); | ||
} | ||
|
||
void ChangelogModel::onFinished( QNetworkReply *reply ) | ||
{ | ||
if ( reply->error() == QNetworkReply::NoError ) | ||
{ | ||
QXmlStreamReader xml( reply ); | ||
QString title, description, link, pubDate; | ||
while ( !xml.atEnd() ) | ||
{ | ||
xml.readNext(); | ||
if ( xml.isStartElement() ) | ||
{ | ||
if ( xml.name().toString() == "item" ) | ||
{ | ||
title.clear(); | ||
description.clear(); | ||
link.clear(); | ||
pubDate.clear(); | ||
} | ||
else if ( xml.name().toString() == "title" ) | ||
{ | ||
title = xml.readElementText(); | ||
} | ||
else if ( xml.name().toString() == "description" ) | ||
{ | ||
description = xml.readElementText(); | ||
} | ||
else if ( xml.name().toString() == "link" ) | ||
{ | ||
link = xml.readElementText(); | ||
} | ||
else if ( xml.name().toString() == "pubDate" ) | ||
{ | ||
pubDate = xml.readElementText(); | ||
} | ||
} | ||
else if ( xml.isEndElement() ) | ||
{ | ||
if ( xml.name().toString() == "item" ) | ||
{ | ||
QDateTime dt = QDateTime::fromString( pubDate, "ddd, dd MMM yyyy hh:mm:ss t" ); | ||
if ( dt > _lastSeen ) | ||
{ | ||
beginInsertRows( QModelIndex(), rowCount(), rowCount() ); | ||
_logs << Changelog{ title, description, link, dt }; | ||
endInsertRows(); | ||
} | ||
} | ||
} | ||
} | ||
if ( xml.hasError() ) | ||
{ | ||
qWarning() << "XML error:" << xml.errorString(); | ||
} | ||
} | ||
else | ||
{ | ||
qWarning() << "Network error:" << reply->errorString(); | ||
} | ||
reply->deleteLater(); | ||
|
||
if ( !_logs.isEmpty() ) | ||
{ | ||
emit dataChanged( createIndex( 0, 0 ), createIndex( rowCount(), 0 ) ); | ||
} | ||
} | ||
|
||
QHash<int, QByteArray> ChangelogModel::roleNames() const | ||
{ | ||
return | ||
{ | ||
{ TitleRole, "title" }, | ||
{ DescriptionRole, "description" }, | ||
{ LinkRole, "link" }, | ||
{ DateRole, "date" } | ||
}; | ||
} | ||
|
||
int ChangelogModel::rowCount( const QModelIndex &parent ) const | ||
{ | ||
Q_UNUSED( parent ) | ||
return _logs.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() ); | ||
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" ); | ||
|
||
return {}; | ||
} | ||
|
||
// TODO: if all=false, get the date of last seen | ||
void ChangelogModel::seeChangelogs( bool all ) | ||
{ | ||
beginResetModel(); | ||
_logs.clear(); | ||
endResetModel(); | ||
|
||
// get all the changes | ||
_lastSeen = QDateTime::fromMSecsSinceEpoch( 0 ); | ||
_networkManager->get( QNetworkRequest( QUrl( "https://zive.aktuality.sk/rss/najnovsie" ) ) ); // TODO get URL from somewhere | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef CHANGELOGMODEL_H | ||
#define CHANGELOGMODEL_H | ||
|
||
#include "QNetworkAccessManager" | ||
#include <QAbstractListModel> | ||
#include <QDate> | ||
|
||
struct Changelog | ||
{ | ||
QString title; | ||
QString description; | ||
QString link; | ||
QDateTime date; | ||
}; | ||
|
||
class ChangelogModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
Q_ENUMS( MyRoles ) | ||
|
||
public: | ||
enum MyRoles | ||
{ | ||
TitleRole = Qt::UserRole + 1, DescriptionRole, LinkRole, DateRole | ||
}; | ||
|
||
ChangelogModel( QObject *parent = nullptr ); | ||
|
||
QHash<int, QByteArray> roleNames() const override; | ||
int rowCount( const QModelIndex &parent = QModelIndex() ) const override; | ||
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override; | ||
|
||
Q_INVOKABLE void seeChangelogs( bool all = false ); | ||
|
||
private slots: | ||
void onFinished( QNetworkReply *reply ); | ||
|
||
signals: | ||
void finished( const QString &title, const QString &link ); | ||
|
||
private: | ||
QList<Changelog> _logs; | ||
QNetworkAccessManager *_networkManager; | ||
QDateTime _lastSeen; | ||
}; | ||
|
||
#endif // CHANGELOGMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
import QtQuick | ||
import QtQuick.Controls | ||
import QtQuick.Layouts | ||
import QtQuick.Dialogs | ||
|
||
import "." // import InputStyle singleton | ||
import "./components" | ||
import lc 1.0 | ||
|
||
Item { | ||
id: root | ||
|
||
signal close | ||
|
||
Keys.onReleased: function( event ) { | ||
if (event.key === Qt.Key_Back || event.key === Qt.Key_Escape) { | ||
event.accepted = true | ||
close() | ||
} | ||
} | ||
|
||
Page { | ||
id: pane | ||
|
||
width: parent.width | ||
height: parent.height | ||
anchors.verticalCenter: parent.verticalCenter | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
clip: true | ||
|
||
background: Rectangle { | ||
color: "white" | ||
} | ||
|
||
header: PanelHeader { | ||
id: header | ||
height: InputStyle.rowHeightHeader | ||
width: parent.width | ||
color: "white" | ||
rowHeight: InputStyle.rowHeightHeader | ||
titleText: qsTr("Change Log") | ||
|
||
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 | ||
width: parent.width | ||
font.pixelSize: InputStyle.fontPixelSizeNormal | ||
color: InputStyle.fontColor | ||
} | ||
|
||
Button { | ||
id: closeButton | ||
anchors.right: parent.right | ||
onClicked: close() | ||
contentItem: Text { text: "❌" } | ||
background: Item {} | ||
} | ||
|
||
ListView { | ||
id: changelogView | ||
width: parent.width | ||
anchors.top: subTitle.bottom | ||
anchors.topMargin: 20 | ||
anchors.bottom: parent.bottom | ||
spacing: 3 | ||
clip: true | ||
model: ChangelogModel {} | ||
delegate: MouseArea { | ||
width: changeItem.width | ||
height: changeItem.height | ||
onClicked: Qt.openUrlExternally(link) | ||
Column { | ||
id: changeItem | ||
width: changelogView.width | ||
Rectangle { width: parent.width; height: 2; color: "lightGray" } | ||
Text { text: date; 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 } | ||
} | ||
} | ||
|
||
ScrollBar.vertical: ScrollBar { | ||
parent: changelogView.parent | ||
anchors.top: changelogView.top | ||
anchors.left: changelogView.right | ||
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") | ||
|
||
onClicked: { | ||
changelogView.model.seeChangelogs() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1e6be86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS - version 23.09.456411 just submitted!