-
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.
- Loading branch information
Showing
60 changed files
with
2,355 additions
and
383 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,125 @@ | ||
/*************************************************************************** | ||
* * | ||
* 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" | ||
#include "inputhelp.h" | ||
|
||
ChangelogModel::ChangelogModel( QObject *parent ) : QAbstractListModel{parent} | ||
{ | ||
mNetworkManager = new QNetworkAccessManager( this ); | ||
connect( mNetworkManager, &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() == QStringLiteral( "item" ) ) | ||
{ | ||
title.clear(); | ||
description.clear(); | ||
link.clear(); | ||
pubDate.clear(); | ||
} | ||
else if ( xml.name().toString() == QStringLiteral( "title" ) ) | ||
{ | ||
title = xml.readElementText(); | ||
} | ||
else if ( xml.name().toString() == QStringLiteral( "description" ) ) | ||
{ | ||
description = xml.readElementText(); | ||
} | ||
else if ( xml.name().toString() == QStringLiteral( "link" ) ) | ||
{ | ||
link = xml.readElementText(); | ||
} | ||
else if ( xml.name().toString() == QStringLiteral( "pubDate" ) ) | ||
{ | ||
pubDate = xml.readElementText(); | ||
} | ||
} | ||
else if ( xml.isEndElement() ) | ||
{ | ||
if ( xml.name().toString() == "item" ) | ||
{ | ||
const QDateTime &dt = QDateTime::fromString( pubDate, "ddd, dd MMM yyyy hh:mm:ss t" ); | ||
beginInsertRows( QModelIndex(), rowCount(), rowCount() ); | ||
mLogs << Changelog{ title, description, link, dt }; | ||
endInsertRows(); | ||
} | ||
} | ||
} | ||
if ( xml.hasError() ) | ||
{ | ||
CoreUtils::log( QStringLiteral( "Changelog" ), QStringLiteral( "Failed to parse changelog. Xml parse error: " ).arg( xml.errorString() ) ); | ||
} | ||
} | ||
else | ||
{ | ||
CoreUtils::log( QStringLiteral( "Changelog" ), QStringLiteral( "Failed to get changelog. Server Error: %1" ).arg( reply->errorString() ) ); | ||
emit errorMsgChanged( reply->errorString() ); | ||
} | ||
reply->deleteLater(); | ||
|
||
if ( !mLogs.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 mLogs.size(); | ||
} | ||
|
||
QVariant ChangelogModel::data( const QModelIndex &index, int role ) const | ||
{ | ||
if ( !hasIndex( index.row(), index.column(), index.parent() ) ) | ||
return {}; | ||
|
||
Changelog log = mLogs.at( index.row() ); | ||
if ( role == TitleRole ) return log.title; | ||
if ( role == DescriptionRole ) return log.descriptionWithoutImages(); | ||
if ( role == LinkRole ) return log.link; | ||
if ( role == DateRole ) return log.date; | ||
|
||
return {}; | ||
} | ||
|
||
// fill the dialog | ||
void ChangelogModel::seeChangelogs() | ||
{ | ||
beginResetModel(); | ||
mLogs.clear(); | ||
endResetModel(); | ||
mNetworkManager->get( QNetworkRequest( QUrl( InputHelp::changelogLink() ) ) ); | ||
} |
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,59 @@ | ||
/*************************************************************************** | ||
* * | ||
* 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 | ||
|
||
#include "QNetworkAccessManager" | ||
#include <QAbstractListModel> | ||
#include <QDate> | ||
#include <QRegularExpression> | ||
|
||
struct Changelog | ||
{ | ||
QString title; | ||
QString description; | ||
QString link; | ||
QDateTime date; | ||
|
||
QString descriptionWithoutImages() { return description.replace( QRegularExpression( "<img .*?>" ), "" ); }; | ||
}; | ||
|
||
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(); | ||
|
||
private slots: | ||
void onFinished( QNetworkReply *reply ); | ||
|
||
signals: | ||
void finished( const QString &title, const QString &link ); | ||
void errorMsgChanged( const QString &msg ); | ||
|
||
private: | ||
QList<Changelog> mLogs; | ||
QNetworkAccessManager *mNetworkManager; | ||
}; | ||
|
||
#endif // CHANGELOGMODEL_H |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Oops, something went wrong.
5a300d1
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.11.490611 just submitted!