Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package qt6-networkauth for openSUSE:Factory checked in at 2023-10-02 20:05:37 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/qt6-networkauth (Old) and /work/SRC/openSUSE:Factory/.qt6-networkauth.new.28202 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "qt6-networkauth" Mon Oct 2 20:05:37 2023 rev:23 rq:1114500 version:6.5.3 Changes: -------- --- /work/SRC/openSUSE:Factory/qt6-networkauth/qt6-networkauth.changes 2023-07-26 13:23:09.539725921 +0200 +++ /work/SRC/openSUSE:Factory/.qt6-networkauth.new.28202/qt6-networkauth.changes 2023-10-02 20:07:27.868958053 +0200 @@ -1,0 +2,6 @@ +Thu Sep 28 07:34:15 UTC 2023 - Christophe Marin <christo...@krop.fr> + +- Update to 6.5.3 + * https://www.qt.io/blog/qt-6.5.3-released + +------------------------------------------------------------------- Old: ---- qtnetworkauth-everywhere-src-6.5.2.tar.xz New: ---- qtnetworkauth-everywhere-src-6.5.3.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ qt6-networkauth.spec ++++++ --- /var/tmp/diff_new_pack.EYm1cv/_old 2023-10-02 20:07:28.992998477 +0200 +++ /var/tmp/diff_new_pack.EYm1cv/_new 2023-10-02 20:07:28.992998477 +0200 @@ -16,7 +16,7 @@ # -%define real_version 6.5.2 +%define real_version 6.5.3 %define short_version 6.5 %define short_name qtnetworkauth %define tar_name qtnetworkauth-everywhere-src @@ -28,12 +28,12 @@ %endif # Name: qt6-networkauth%{?pkg_suffix} -Version: 6.5.2 +Version: 6.5.3 Release: 0 Summary: Set of APIs to obtain limited access to online accounts and HTTP services License: GPL-3.0-only WITH Qt-GPL-exception-1.0 URL: https://www.qt.io -Source: https://www.nic.funet.fi/pub/mirrors/download.qt-project.org/official_releases/qt/%{short_version}/%{real_version}%{tar_suffix}/submodules/%{tar_name}-%{real_version}%{tar_suffix}.tar.xz +Source: https://download.qt.io/official_releases/qt/%{short_version}/%{real_version}%{tar_suffix}/submodules/%{tar_name}-%{real_version}%{tar_suffix}.tar.xz Source99: qt6-networkauth-rpmlintrc BuildRequires: pkgconfig BuildRequires: qt6-core-private-devel ++++++ qtnetworkauth-everywhere-src-6.5.2.tar.xz -> qtnetworkauth-everywhere-src-6.5.3.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/.cmake.conf new/qtnetworkauth-everywhere-src-6.5.3/.cmake.conf --- old/qtnetworkauth-everywhere-src-6.5.2/.cmake.conf 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/.cmake.conf 2023-09-24 09:06:35.000000000 +0200 @@ -1,3 +1,3 @@ -set(QT_REPO_MODULE_VERSION "6.5.2") +set(QT_REPO_MODULE_VERSION "6.5.3") set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_AS_CONST=1") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/.tag new/qtnetworkauth-everywhere-src-6.5.3/.tag --- old/qtnetworkauth-everywhere-src-6.5.2/.tag 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/.tag 2023-09-24 09:06:35.000000000 +0200 @@ -1 +1 @@ -6a4fdc264d708e9634661e8b05bf6596393b83e8 +70e2a96d3bfdd8fab6c48a80ee0147a56233b894 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/dependencies.yaml new/qtnetworkauth-everywhere-src-6.5.3/dependencies.yaml --- old/qtnetworkauth-everywhere-src-6.5.2/dependencies.yaml 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/dependencies.yaml 2023-09-24 09:06:35.000000000 +0200 @@ -1,4 +1,4 @@ dependencies: ../qtbase: - ref: af457a9f0f7eb1a2a7d11f495da508faab91a442 + ref: 372eaedc5b8c771c46acc4c96e91bbade4ca3624 required: true diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/CMakeLists.txt new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/CMakeLists.txt --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/CMakeLists.txt 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/CMakeLists.txt 2023-09-24 09:06:35.000000000 +0200 @@ -4,6 +4,5 @@ # Generated from oauth.pro. if(TARGET Qt::Widgets) - qt_internal_add_example(twittertimeline) qt_internal_add_example(redditclient) endif() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/oauth.pro new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/oauth.pro --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/oauth.pro 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/oauth.pro 2023-09-24 09:06:35.000000000 +0200 @@ -2,6 +2,5 @@ qtHaveModule(widgets) { SUBDIRS += \ - twittertimeline \ redditclient } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/redditclient/doc/src/qtnetworkauth-redditclient.qdoc new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/redditclient/doc/src/qtnetworkauth-redditclient.qdoc --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/redditclient/doc/src/qtnetworkauth-redditclient.qdoc 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/redditclient/doc/src/qtnetworkauth-redditclient.qdoc 2023-09-24 09:06:35.000000000 +0200 @@ -3,6 +3,7 @@ /*! \example redditclient + \examplecategory {Networking} \title Reddit Example \ingroup examples-qtnetworkauth \brief Demonstrates authenticating with OAuth 2 to access Reddit. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/CMakeLists.txt new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/CMakeLists.txt --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/CMakeLists.txt 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1,47 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -# Generated from twittertimeline.pro. - -cmake_minimum_required(VERSION 3.16) -project(twittertimeline LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/oauth/twittertimeline") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Widgets) -find_package(Qt6 COMPONENTS Network) -find_package(Qt6 COMPONENTS NetworkAuth) - -qt_add_executable(twittertimeline - main.cpp - twitter.cpp twitter.h - twitterdialog.ui - twittertimelinemodel.cpp twittertimelinemodel.h -) -set_target_properties(twittertimeline PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE FALSE -) -target_link_libraries(twittertimeline PUBLIC - Qt::Core - Qt::Network - Qt::NetworkAuth - Qt::Widgets -) - -install(TARGETS twittertimeline - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) Binary files old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/doc/images/twittertimeline-example.png and new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/doc/images/twittertimeline-example.png differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/doc/src/qtnetworkauth-twittertimeline.qdoc new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/doc/src/qtnetworkauth-twittertimeline.qdoc --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/doc/src/qtnetworkauth-twittertimeline.qdoc 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/doc/src/qtnetworkauth-twittertimeline.qdoc 1970-01-01 01:00:00.000000000 +0100 @@ -1,22 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example twittertimeline - \title Twitter Timeline Example - \ingroup examples-qtnetworkauth - \brief Demonstrates authenticating with OAuth to access a Twitter timeline. - \excludefromcreator - \image twittertimeline-example.png Screenshot of the example - - The \e {Twitter Timeline} example uses OAuth, as supported by - \l {Qt Network Authorization}, to sign in to Twitter and display a timeline - of tweets (in text format) associated with the authenticated user. - - To use this example, a consumer key and secret from Twitter are needed. - To register the application visit https://apps.twitter.com. - Youâll need to add \e http://127.0.0.1:1337/callback as a callback URL - in your Twitter app settings. - - \include examples-run.qdocinc -*/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/main.cpp new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/main.cpp --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/main.cpp 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/main.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,78 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "ui_twitterdialog.h" -#include "twittertimelinemodel.h" - -#include <functional> - -#include <QUrl> -#include <QApplication> -#include <QNetworkReply> -#include <QNetworkRequest> -#include <QCommandLineParser> -#include <QCommandLineOption> - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - app.setApplicationName("Twitter Timeline"); - app.setApplicationDisplayName("Twitter Timeline"); - app.setOrganizationDomain("qt.io"); - app.setOrganizationName("The Qt Company"); - - QCommandLineParser parser; - QCommandLineOption token(QStringList() << "k" << "consumer-key", - "Application consumer key", "key"); - QCommandLineOption secret(QStringList() << "s" << "consumer-secret", - "Application consumer secret", "secret"); - QCommandLineOption connect(QStringList() << "c" << "connect", - "Connects to twitter. Requires consumer-key and consumer-secret"); - - parser.addOptions({ token, secret, connect }); - parser.process(app); - - struct TwitterDialog : QDialog, Ui::TwitterDialog { - TwitterTimelineModel model; - - TwitterDialog() - : QDialog() - { - setupUi(this); - view->setModel(&model); - view->horizontalHeader()->hideSection(0); - view->horizontalHeader()->hideSection(1); - } - } twitterDialog; - - const auto authenticate = [&]() { - const auto clientIdentifier = twitterDialog.clientIdLineEdit->text(); - const auto clientSharedSecret = twitterDialog.clientSecretLineEdit->text(); - twitterDialog.model.authenticate(qMakePair(clientIdentifier, clientSharedSecret)); - }; - const auto buttonSlot = [&]() { - if (twitterDialog.model.status() == Twitter::Status::Granted) - twitterDialog.model.updateTimeline(); - else - authenticate(); - }; - - twitterDialog.clientIdLineEdit->setText(parser.value(token)); - twitterDialog.clientSecretLineEdit->setText(parser.value(secret)); - if (parser.isSet(connect)) { - if (parser.value(token).isEmpty() || parser.value(secret).isEmpty()) { - parser.showHelp(); - } else { - authenticate(); - twitterDialog.view->setFocus(); - } - } - - QObject::connect(twitterDialog.pushButton, &QPushButton::clicked, buttonSlot); - QObject::connect(&twitterDialog.model, &TwitterTimelineModel::authenticated, - std::bind(&QPushButton::setText, twitterDialog.pushButton, "&Update")); - - twitterDialog.show(); - return app.exec(); -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twitter.cpp new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twitter.cpp --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twitter.cpp 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twitter.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,47 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "twitter.h" - -#include <QtGui> -#include <QtCore> -#include <QtNetwork> - -Twitter::Twitter(QObject *parent) : - Twitter(QString(), qMakePair(QString(), QString()), parent) -{} - -Twitter::Twitter(const QPair<QString, QString> &clientCredentials, QObject *parent) : - Twitter(QString(), clientCredentials, parent) -{} - -Twitter::Twitter(const QString &screenName, - const QPair<QString, QString> &clientCredentials, - QObject *parent) : - QOAuth1(clientCredentials.first, clientCredentials.second, nullptr, parent) -{ - replyHandler = new QOAuthHttpServerReplyHandler(1337, this); - replyHandler->setCallbackPath("callback"); - setReplyHandler(replyHandler); - setTemporaryCredentialsUrl(QUrl("https://api.twitter.com/oauth/request_token")); - setAuthorizationUrl(QUrl("https://api.twitter.com/oauth/authenticate")); - setTokenCredentialsUrl(QUrl("https://api.twitter.com/oauth/access_token")); - - connect(this, &QAbstractOAuth::authorizeWithBrowser, [=](QUrl url) { - QUrlQuery query(url); - - // Forces the user to enter their credentials to authorize the correct - // user account - query.addQueryItem("force_login", "true"); - - if (!screenName.isEmpty()) - query.addQueryItem("screen_name", screenName); - url.setQuery(query); - QDesktopServices::openUrl(url); - }); - - connect(this, &QOAuth1::granted, this, &Twitter::authenticated); - - if (!clientCredentials.first.isEmpty() && !clientCredentials.second.isEmpty()) - grant(); -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twitter.h new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twitter.h --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twitter.h 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twitter.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,31 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef TWITTERTIMELINE_TWITTER_H -#define TWITTERTIMELINE_TWITTER_H - -#include <QtCore> -#include <QtNetwork> -#include <QtNetworkAuth> - -class Twitter : public QOAuth1 -{ - Q_OBJECT - -public: - Twitter(QObject *parent = nullptr); - Twitter(const QPair<QString, QString> &clientCredentials, QObject *parent = nullptr); - Twitter(const QString &screenName, - const QPair<QString, QString> &clientCredentials, - QObject *parent = nullptr); - -signals: - void authenticated(); - -private: - Q_DISABLE_COPY(Twitter) - - QOAuthHttpServerReplyHandler *replyHandler = nullptr; -}; - -#endif // TWITTERTIMELINE_TWITTER_H diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twitterdialog.ui new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twitterdialog.ui --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twitterdialog.ui 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twitterdialog.ui 1970-01-01 01:00:00.000000000 +0100 @@ -1,73 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>TwitterDialog</class> - <widget class="QDialog" name="TwitterDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>800</width> - <height>600</height> - </rect> - </property> - <property name="windowTitle"> - <string>Twitter Timeline</string> - </property> - <layout class="QFormLayout" name="formLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="clientIdLabel"> - <property name="text"> - <string>C&lient Id:</string> - </property> - <property name="buddy"> - <cstring>clientIdLineEdit</cstring> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="clientIdLineEdit"/> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="clientSecretLabel"> - <property name="text"> - <string>Client &secret:</string> - </property> - <property name="buddy"> - <cstring>clientSecretLineEdit</cstring> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="clientSecretLineEdit"/> - </item> - <item row="2" column="0" colspan="2"> - <widget class="QPushButton" name="pushButton"> - <property name="text"> - <string>&Connect</string> - </property> - </widget> - </item> - <item row="3" column="0" colspan="2"> - <widget class="QTableView" name="view"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>1</verstretch> - </sizepolicy> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::NoSelection</enum> - </property> - <attribute name="horizontalHeaderStretchLastSection"> - <bool>true</bool> - </attribute> - <attribute name="verticalHeaderVisible"> - <bool>false</bool> - </attribute> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twittertimeline.pro new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twittertimeline.pro --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twittertimeline.pro 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twittertimeline.pro 1970-01-01 01:00:00.000000000 +0100 @@ -1,19 +0,0 @@ -QT = core widgets network networkauth -requires(qtConfig(tableview)) -CONFIG -= app_bundle - -HEADERS += \ - twitter.h \ - twittertimelinemodel.h - -SOURCES += \ - main.cpp \ - twitter.cpp \ - twittertimelinemodel.cpp - -FORMS += \ - twitterdialog.ui - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/oauth/twittertimeline -INSTALLS += target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twittertimelinemodel.cpp new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twittertimelinemodel.cpp --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twittertimelinemodel.cpp 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twittertimelinemodel.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,151 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "twittertimelinemodel.h" - -#include <QtGui> -#include <QtCore> -#include <QtWidgets> - -TwitterTimelineModel::TwitterTimelineModel(QObject *parent) : QAbstractTableModel(parent) -{ - connect(&twitter, &Twitter::authenticated, this, &TwitterTimelineModel::authenticated); - connect(&twitter, &Twitter::authenticated, this, &TwitterTimelineModel::updateTimeline); -} - -int TwitterTimelineModel::rowCount(const QModelIndex &parent) const -{ -#if defined(QT_DEBUG) - Q_ASSERT(!parent.isValid()); -#else - Q_UNUSED(parent); -#endif - return tweets.size(); -} - -QVariant TwitterTimelineModel::data(const QModelIndex &index, int role) const -{ - if (role != Qt::DisplayRole) - return QVariant(); - - auto it = tweets.begin(); - std::advance(it, index.row()); - switch (index.column()) - { - case 0: - return QString::number(it->id); - case 1: - return it->createdAt.toString(Qt::ISODateWithMs); - case 2: - return it->user; - case 3: - return it->text; - } - return QVariant(); -} - -int TwitterTimelineModel::columnCount(const QModelIndex &) const -{ - return 4; -} - -QVariant TwitterTimelineModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role != Qt::DisplayRole) - return QVariant(); - - if (orientation == Qt::Horizontal) { - switch (section) { - case 0: - return QStringLiteral("Id"); - case 1: - return QStringLiteral("Created at"); - case 2: - return QStringLiteral("User"); - case 3: - return QStringLiteral("Text"); - } - } - return section; -} - -void TwitterTimelineModel::authenticate(const QPair<QString, QString> &clientCredentials) -{ - twitter.setClientCredentials(clientCredentials); - twitter.grant(); -} - -QAbstractOAuth::Status TwitterTimelineModel::status() const -{ - return twitter.status(); -} - -void TwitterTimelineModel::updateTimeline() -{ - if (twitter.status() != Twitter::Status::Granted) - QMessageBox::warning(nullptr, qApp->applicationName(), "Not authenticated"); - - QUrl url("https://api.twitter.com/1.1/statuses/home_timeline.json"); - QVariantMap parameters; - if (tweets.size()) { - // Tweets are time-ordered, newest first. Pass the most recent - // ID we have to request everything more recent than it: - parameters.insert("since_id", QString::number(tweets.first().id)); - // From https://dev.twitter.com/rest/reference/get/search/tweets: - // Returns results with an ID greater than (that is, more recent than) - // the specified ID. There are limits to the number of Tweets which can - // be accessed through the API. If the limit of Tweets has occurred - // since the since_id, the since_id will be forced to the oldest ID - // available. - } - QNetworkReply *reply = twitter.get(url, parameters); - connect(reply, &QNetworkReply::finished, this, &TwitterTimelineModel::parseJson); -} - -void TwitterTimelineModel::parseJson() -{ - QJsonParseError parseError; - auto reply = qobject_cast<QNetworkReply*>(sender()); - Q_ASSERT(reply); - const auto data = reply->readAll(); - const auto document = QJsonDocument::fromJson(data, &parseError); - if (parseError.error) { - qCritical() << "TwitterTimelineModel::parseJson. Error at:" << parseError.offset - << parseError.errorString(); - return; - } else if (document.isObject()) { - // Error received :( - const auto object = document.object(); - const auto errorArray = object.value("errors").toArray(); - Q_ASSERT_X(errorArray.size(), "parse", data); - QStringList errors; - for (const auto error : errorArray) { - Q_ASSERT(error.isObject()); - Q_ASSERT(error.toObject().contains("message")); - errors.append(error.toObject().value("message").toString()); - } - QMessageBox::warning(nullptr, qApp->applicationName(), errors.join("<br />")); - return; - } - - Q_ASSERT_X(document.isArray(), "parse", data); - const auto array = document.array(); - if (array.size()) { - beginInsertRows(QModelIndex(), 0, array.size() - 1); - auto before = tweets.begin(); - for (const auto &value : array) { - Q_ASSERT(value.isObject()); - const auto object = value.toObject(); - const auto createdAt = QDateTime::fromString(object.value("created_at").toString(), - "ddd MMM dd HH:mm:ss +0000 yyyy"); - before = tweets.insert(before, Tweet{ - object.value("id").toVariant().toULongLong(), - createdAt, - object.value("user").toObject().value("name").toString(), - object.value("text").toString() - }); - std::advance(before, 1); - } - endInsertRows(); - } -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twittertimelinemodel.h new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twittertimelinemodel.h --- old/qtnetworkauth-everywhere-src-6.5.2/examples/oauth/twittertimeline/twittertimelinemodel.h 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/examples/oauth/twittertimeline/twittertimelinemodel.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,49 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef TWITTERTIMELINEMODEL_H -#define TWITTERTIMELINEMODEL_H - -#include "twitter.h" - -#include <QtCore> -#include <QtNetwork> - -class TwitterTimelineModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - TwitterTimelineModel(QObject *parent = nullptr); - - int rowCount(const QModelIndex &parent) const override; - QVariant data(const QModelIndex &index, int role) const override; - int columnCount(const QModelIndex &parent) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - - void authenticate(const QPair<QString, QString> &clientCredentials); - QAbstractOAuth::Status status() const; - -public slots: - void updateTimeline(); - -signals: - void authenticated(); - -private: - Q_DISABLE_COPY(TwitterTimelineModel) - - void parseJson(); - - struct Tweet { - quint64 id; - QDateTime createdAt; - QString user; - QString text; - }; - - QList<Tweet> tweets; - Twitter twitter; -}; - -#endif // TWITTERTIMELINEMODEL_H diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/src/oauth/qabstractoauthreplyhandler.cpp new/qtnetworkauth-everywhere-src-6.5.3/src/oauth/qabstractoauthreplyhandler.cpp --- old/qtnetworkauth-everywhere-src-6.5.2/src/oauth/qabstractoauthreplyhandler.cpp 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/src/oauth/qabstractoauthreplyhandler.cpp 2023-09-24 09:06:35.000000000 +0200 @@ -45,7 +45,10 @@ After the server determines whether the request is valid this function will be called. Reimplement it to get the data received - from the server wrapped in \a reply. + from the server wrapped in \a reply. \a reply will be automatically + deleted using deleteLater(), it thus must not be stored beyond the + scope of this function. + */ /*! diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/src/oauth/qoauth2authorizationcodeflow.cpp new/qtnetworkauth-everywhere-src-6.5.3/src/oauth/qoauth2authorizationcodeflow.cpp --- old/qtnetworkauth-everywhere-src-6.5.2/src/oauth/qoauth2authorizationcodeflow.cpp 2023-07-07 05:20:36.000000000 +0200 +++ new/qtnetworkauth-everywhere-src-6.5.3/src/oauth/qoauth2authorizationcodeflow.cpp 2023-09-24 09:06:35.000000000 +0200 @@ -396,6 +396,7 @@ QAbstractOAuthReplyHandler *handler = replyHandler(); QObject::connect(reply, &QNetworkReply::finished, [handler, reply] { handler->networkReplyFinished(reply); }); + connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); QObjectPrivate::connect(d->replyHandler.data(), &QAbstractOAuthReplyHandler::tokensReceived, d, &QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished, Qt::UniqueConnection); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/CMakeLists.txt new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/CMakeLists.txt --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/CMakeLists.txt 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,47 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# Generated from twittertimeline.pro. + +cmake_minimum_required(VERSION 3.16) +project(twittertimeline LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/oauth/twittertimeline") + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Widgets) +find_package(Qt6 COMPONENTS Network) +find_package(Qt6 COMPONENTS NetworkAuth) + +qt_add_executable(twittertimeline + main.cpp + twitter.cpp twitter.h + twitterdialog.ui + twittertimelinemodel.cpp twittertimelinemodel.h +) +set_target_properties(twittertimeline PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE FALSE +) +target_link_libraries(twittertimeline PUBLIC + Qt::Core + Qt::Network + Qt::NetworkAuth + Qt::Widgets +) + +install(TARGETS twittertimeline + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) Binary files old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/doc/images/twittertimeline-example.png and new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/doc/images/twittertimeline-example.png differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/doc/src/qtnetworkauth-twittertimeline.qdoc new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/doc/src/qtnetworkauth-twittertimeline.qdoc --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/doc/src/qtnetworkauth-twittertimeline.qdoc 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/doc/src/qtnetworkauth-twittertimeline.qdoc 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,22 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! + \example twittertimeline + \title Twitter Timeline Example + \ingroup examples-qtnetworkauth + \brief Demonstrates authenticating with OAuth to access a Twitter timeline. + \excludefromcreator + \image twittertimeline-example.png Screenshot of the example + + The \e {Twitter Timeline} example uses OAuth, as supported by + \l {Qt Network Authorization}, to sign in to Twitter and display a timeline + of tweets (in text format) associated with the authenticated user. + + To use this example, a consumer key and secret from Twitter are needed. + To register the application visit https://apps.twitter.com. + Youâll need to add \e http://127.0.0.1:1337/callback as a callback URL + in your Twitter app settings. + + \include examples-run.qdocinc +*/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/main.cpp new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/main.cpp --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/main.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/main.cpp 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,78 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "ui_twitterdialog.h" +#include "twittertimelinemodel.h" + +#include <functional> + +#include <QUrl> +#include <QApplication> +#include <QNetworkReply> +#include <QNetworkRequest> +#include <QCommandLineParser> +#include <QCommandLineOption> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + app.setApplicationName("Twitter Timeline"); + app.setApplicationDisplayName("Twitter Timeline"); + app.setOrganizationDomain("qt.io"); + app.setOrganizationName("The Qt Company"); + + QCommandLineParser parser; + QCommandLineOption token(QStringList() << "k" << "consumer-key", + "Application consumer key", "key"); + QCommandLineOption secret(QStringList() << "s" << "consumer-secret", + "Application consumer secret", "secret"); + QCommandLineOption connect(QStringList() << "c" << "connect", + "Connects to twitter. Requires consumer-key and consumer-secret"); + + parser.addOptions({ token, secret, connect }); + parser.process(app); + + struct TwitterDialog : QDialog, Ui::TwitterDialog { + TwitterTimelineModel model; + + TwitterDialog() + : QDialog() + { + setupUi(this); + view->setModel(&model); + view->horizontalHeader()->hideSection(0); + view->horizontalHeader()->hideSection(1); + } + } twitterDialog; + + const auto authenticate = [&]() { + const auto clientIdentifier = twitterDialog.clientIdLineEdit->text(); + const auto clientSharedSecret = twitterDialog.clientSecretLineEdit->text(); + twitterDialog.model.authenticate(qMakePair(clientIdentifier, clientSharedSecret)); + }; + const auto buttonSlot = [&]() { + if (twitterDialog.model.status() == Twitter::Status::Granted) + twitterDialog.model.updateTimeline(); + else + authenticate(); + }; + + twitterDialog.clientIdLineEdit->setText(parser.value(token)); + twitterDialog.clientSecretLineEdit->setText(parser.value(secret)); + if (parser.isSet(connect)) { + if (parser.value(token).isEmpty() || parser.value(secret).isEmpty()) { + parser.showHelp(); + } else { + authenticate(); + twitterDialog.view->setFocus(); + } + } + + QObject::connect(twitterDialog.pushButton, &QPushButton::clicked, buttonSlot); + QObject::connect(&twitterDialog.model, &TwitterTimelineModel::authenticated, + std::bind(&QPushButton::setText, twitterDialog.pushButton, "&Update")); + + twitterDialog.show(); + return app.exec(); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twitter.cpp new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twitter.cpp --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twitter.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twitter.cpp 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,47 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "twitter.h" + +#include <QtGui> +#include <QtCore> +#include <QtNetwork> + +Twitter::Twitter(QObject *parent) : + Twitter(QString(), qMakePair(QString(), QString()), parent) +{} + +Twitter::Twitter(const QPair<QString, QString> &clientCredentials, QObject *parent) : + Twitter(QString(), clientCredentials, parent) +{} + +Twitter::Twitter(const QString &screenName, + const QPair<QString, QString> &clientCredentials, + QObject *parent) : + QOAuth1(clientCredentials.first, clientCredentials.second, nullptr, parent) +{ + replyHandler = new QOAuthHttpServerReplyHandler(1337, this); + replyHandler->setCallbackPath("callback"); + setReplyHandler(replyHandler); + setTemporaryCredentialsUrl(QUrl("https://api.twitter.com/oauth/request_token")); + setAuthorizationUrl(QUrl("https://api.twitter.com/oauth/authenticate")); + setTokenCredentialsUrl(QUrl("https://api.twitter.com/oauth/access_token")); + + connect(this, &QAbstractOAuth::authorizeWithBrowser, [=](QUrl url) { + QUrlQuery query(url); + + // Forces the user to enter their credentials to authorize the correct + // user account + query.addQueryItem("force_login", "true"); + + if (!screenName.isEmpty()) + query.addQueryItem("screen_name", screenName); + url.setQuery(query); + QDesktopServices::openUrl(url); + }); + + connect(this, &QOAuth1::granted, this, &Twitter::authenticated); + + if (!clientCredentials.first.isEmpty() && !clientCredentials.second.isEmpty()) + grant(); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twitter.h new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twitter.h --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twitter.h 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twitter.h 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,31 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef TWITTERTIMELINE_TWITTER_H +#define TWITTERTIMELINE_TWITTER_H + +#include <QtCore> +#include <QtNetwork> +#include <QtNetworkAuth> + +class Twitter : public QOAuth1 +{ + Q_OBJECT + +public: + Twitter(QObject *parent = nullptr); + Twitter(const QPair<QString, QString> &clientCredentials, QObject *parent = nullptr); + Twitter(const QString &screenName, + const QPair<QString, QString> &clientCredentials, + QObject *parent = nullptr); + +signals: + void authenticated(); + +private: + Q_DISABLE_COPY(Twitter) + + QOAuthHttpServerReplyHandler *replyHandler = nullptr; +}; + +#endif // TWITTERTIMELINE_TWITTER_H diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twitterdialog.ui new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twitterdialog.ui --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twitterdialog.ui 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twitterdialog.ui 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TwitterDialog</class> + <widget class="QDialog" name="TwitterDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>Twitter Timeline</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="clientIdLabel"> + <property name="text"> + <string>C&lient Id:</string> + </property> + <property name="buddy"> + <cstring>clientIdLineEdit</cstring> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="clientIdLineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="clientSecretLabel"> + <property name="text"> + <string>Client &secret:</string> + </property> + <property name="buddy"> + <cstring>clientSecretLineEdit</cstring> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="clientSecretLineEdit"/> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>&Connect</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QTableView" name="view"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::NoSelection</enum> + </property> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twittertimeline.pro new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twittertimeline.pro --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twittertimeline.pro 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twittertimeline.pro 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,19 @@ +QT = core widgets network networkauth +requires(qtConfig(tableview)) +CONFIG -= app_bundle + +HEADERS += \ + twitter.h \ + twittertimelinemodel.h + +SOURCES += \ + main.cpp \ + twitter.cpp \ + twittertimelinemodel.cpp + +FORMS += \ + twitterdialog.ui + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/oauth/twittertimeline +INSTALLS += target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twittertimelinemodel.cpp new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twittertimelinemodel.cpp --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twittertimelinemodel.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twittertimelinemodel.cpp 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,151 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "twittertimelinemodel.h" + +#include <QtGui> +#include <QtCore> +#include <QtWidgets> + +TwitterTimelineModel::TwitterTimelineModel(QObject *parent) : QAbstractTableModel(parent) +{ + connect(&twitter, &Twitter::authenticated, this, &TwitterTimelineModel::authenticated); + connect(&twitter, &Twitter::authenticated, this, &TwitterTimelineModel::updateTimeline); +} + +int TwitterTimelineModel::rowCount(const QModelIndex &parent) const +{ +#if defined(QT_DEBUG) + Q_ASSERT(!parent.isValid()); +#else + Q_UNUSED(parent); +#endif + return tweets.size(); +} + +QVariant TwitterTimelineModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + auto it = tweets.begin(); + std::advance(it, index.row()); + switch (index.column()) + { + case 0: + return QString::number(it->id); + case 1: + return it->createdAt.toString(Qt::ISODateWithMs); + case 2: + return it->user; + case 3: + return it->text; + } + return QVariant(); +} + +int TwitterTimelineModel::columnCount(const QModelIndex &) const +{ + return 4; +} + +QVariant TwitterTimelineModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) { + switch (section) { + case 0: + return QStringLiteral("Id"); + case 1: + return QStringLiteral("Created at"); + case 2: + return QStringLiteral("User"); + case 3: + return QStringLiteral("Text"); + } + } + return section; +} + +void TwitterTimelineModel::authenticate(const QPair<QString, QString> &clientCredentials) +{ + twitter.setClientCredentials(clientCredentials); + twitter.grant(); +} + +QAbstractOAuth::Status TwitterTimelineModel::status() const +{ + return twitter.status(); +} + +void TwitterTimelineModel::updateTimeline() +{ + if (twitter.status() != Twitter::Status::Granted) + QMessageBox::warning(nullptr, qApp->applicationName(), "Not authenticated"); + + QUrl url("https://api.twitter.com/1.1/statuses/home_timeline.json"); + QVariantMap parameters; + if (tweets.size()) { + // Tweets are time-ordered, newest first. Pass the most recent + // ID we have to request everything more recent than it: + parameters.insert("since_id", QString::number(tweets.first().id)); + // From https://dev.twitter.com/rest/reference/get/search/tweets: + // Returns results with an ID greater than (that is, more recent than) + // the specified ID. There are limits to the number of Tweets which can + // be accessed through the API. If the limit of Tweets has occurred + // since the since_id, the since_id will be forced to the oldest ID + // available. + } + QNetworkReply *reply = twitter.get(url, parameters); + connect(reply, &QNetworkReply::finished, this, &TwitterTimelineModel::parseJson); +} + +void TwitterTimelineModel::parseJson() +{ + QJsonParseError parseError; + auto reply = qobject_cast<QNetworkReply*>(sender()); + Q_ASSERT(reply); + const auto data = reply->readAll(); + const auto document = QJsonDocument::fromJson(data, &parseError); + if (parseError.error) { + qCritical() << "TwitterTimelineModel::parseJson. Error at:" << parseError.offset + << parseError.errorString(); + return; + } else if (document.isObject()) { + // Error received :( + const auto object = document.object(); + const auto errorArray = object.value("errors").toArray(); + Q_ASSERT_X(errorArray.size(), "parse", data); + QStringList errors; + for (const auto error : errorArray) { + Q_ASSERT(error.isObject()); + Q_ASSERT(error.toObject().contains("message")); + errors.append(error.toObject().value("message").toString()); + } + QMessageBox::warning(nullptr, qApp->applicationName(), errors.join("<br />")); + return; + } + + Q_ASSERT_X(document.isArray(), "parse", data); + const auto array = document.array(); + if (array.size()) { + beginInsertRows(QModelIndex(), 0, array.size() - 1); + auto before = tweets.begin(); + for (const auto &value : array) { + Q_ASSERT(value.isObject()); + const auto object = value.toObject(); + const auto createdAt = QDateTime::fromString(object.value("created_at").toString(), + "ddd MMM dd HH:mm:ss +0000 yyyy"); + before = tweets.insert(before, Tweet{ + object.value("id").toVariant().toULongLong(), + createdAt, + object.value("user").toObject().value("name").toString(), + object.value("text").toString() + }); + std::advance(before, 1); + } + endInsertRows(); + } +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twittertimelinemodel.h new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twittertimelinemodel.h --- old/qtnetworkauth-everywhere-src-6.5.2/tests/manual/examples/twittertimeline/twittertimelinemodel.h 1970-01-01 01:00:00.000000000 +0100 +++ new/qtnetworkauth-everywhere-src-6.5.3/tests/manual/examples/twittertimeline/twittertimelinemodel.h 2023-09-24 09:06:35.000000000 +0200 @@ -0,0 +1,49 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef TWITTERTIMELINEMODEL_H +#define TWITTERTIMELINEMODEL_H + +#include "twitter.h" + +#include <QtCore> +#include <QtNetwork> + +class TwitterTimelineModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + TwitterTimelineModel(QObject *parent = nullptr); + + int rowCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + int columnCount(const QModelIndex &parent) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + + void authenticate(const QPair<QString, QString> &clientCredentials); + QAbstractOAuth::Status status() const; + +public slots: + void updateTimeline(); + +signals: + void authenticated(); + +private: + Q_DISABLE_COPY(TwitterTimelineModel) + + void parseJson(); + + struct Tweet { + quint64 id; + QDateTime createdAt; + QString user; + QString text; + }; + + QList<Tweet> tweets; + Twitter twitter; +}; + +#endif // TWITTERTIMELINEMODEL_H