Skip to content

Commit

Permalink
Merge branch 'dev-2.3_CU-861mzpq1c_changelog' into master_changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
iiLubos committed Sep 14, 2023
2 parents 77f8c75 + 7ab9a43 commit 1e6be86
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(MM_SRCS
appsettings.cpp
autosynccontroller.cpp
bluetoothdiscoverymodel.cpp
changelogmodel.cpp
codescanner.cpp
compass.cpp
featurelayerpair.cpp
Expand Down Expand Up @@ -128,6 +129,7 @@ set(MM_HDRS
appsettings.h
autosynccontroller.h
bluetoothdiscoverymodel.h
changelogmodel.h
codescanner.h
compass.h
enumhelper.h
Expand Down
121 changes: 121 additions & 0 deletions app/changelogmodel.cpp
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
}


47 changes: 47 additions & 0 deletions app/changelogmodel.h
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
2 changes: 2 additions & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
#include "workspacesproxymodel.h"
#include "invitationsmodel.h"
#include "invitationsproxymodel.h"
#include "changelogmodel.h"

#include "streamingintervaltype.h"

Expand Down Expand Up @@ -283,6 +284,7 @@ void initDeclarative()
qmlRegisterType<WorkspacesProxyModel>( "lc", 1, 0, "WorkspacesProxyModel" );
qmlRegisterType<InvitationsModel>( "lc", 1, 0, "InvitationsModel" );
qmlRegisterType<InvitationsProxyModel>( "lc", 1, 0, "InvitationsProxyModel" );
qmlRegisterType<ChangelogModel>( "lc", 1, 0, "ChangelogModel" );
qmlRegisterUncreatableType<AttributePreviewModel>( "lc", 1, 0, "AttributePreviewModel", "" );
qmlRegisterUncreatableMetaObject( ProjectStatus::staticMetaObject, "lc", 1, 0, "ProjectStatus", "ProjectStatus Enum" );
qRegisterMetaType< FeatureLayerPair >( "FeatureLayerPair" );
Expand Down
1 change: 1 addition & 0 deletions app/qml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ set(MM_QML
AccountPage.qml
AuthPanel.qml
Banner.qml
ChangelogPanel.qml
CircularProgressBar.qml
CodeScanner.qml
CodeScannerOverlay.qml
Expand Down
146 changes: 146 additions & 0 deletions app/qml/ChangelogPanel.qml
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()
}
}
}
}
17 changes: 17 additions & 0 deletions app/qml/SettingsPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ Item {
}
}

// Changelog
PanelItem {
text: qsTr("Changelog")
MouseArea {
anchors.fill: parent
onClicked: stackview.push(changelogPanelComponent)
}
}

// Help
PanelItem {
text: qsTr("Help")
Expand Down Expand Up @@ -391,6 +400,14 @@ Item {
}
}

Component {
id: changelogPanelComponent
ChangelogPanel {
onClose: stackview.pop(null)
Component.onCompleted: forceActiveFocus()
}
}

Component {
id: logPanelComponent
LogPanel {
Expand Down

1 comment on commit 1e6be86

@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.456411 just submitted!

Please sign in to comment.