From 3261ea0b95b0aa40c451e4edf3c1055cc6a0010a Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Fri, 28 Feb 2025 12:43:43 +0900 Subject: [PATCH] chore(ci): expand test sources - Avoid zip archive from repository for security Signed-off-by: Hiroshi Miura --- ci/accelbubble.7z | Bin 3846 -> 0 bytes ci/accelbubble/Bluebubble.svg | 10 ++ ci/accelbubble/Bubble.qml | 60 +++++++++ ci/accelbubble/Info.plist | 34 +++++ ci/accelbubble/Page1Form.ui.qml | 74 +++++++++++ ci/accelbubble/Page2Form.ui.qml | 67 ++++++++++ ci/accelbubble/accelbubble.pro | 37 ++++++ ci/accelbubble/main.cpp | 66 ++++++++++ ci/accelbubble/main.qml | 141 ++++++++++++++++++++ ci/accelbubble/qml.qrc | 10 ++ ci/accelbubble/qtquickcontrols2.conf | 6 + ci/helloworld.7z | Bin 439 -> 0 bytes ci/helloworld/hello.pro | 9 ++ ci/helloworld/main.cpp | 12 ++ ci/helloworld_qttools.7z | Bin 425 -> 0 bytes ci/helloworld_qttools/hello.pro | 7 + ci/helloworld_qttools/main.cpp | 13 ++ ci/openglwindow.7z | Bin 3134 -> 0 bytes ci/openglwindow/CMakeLists.txt | 34 +++++ ci/openglwindow/main.cpp | 130 +++++++++++++++++++ ci/openglwindow/openglwindow.cpp | 114 ++++++++++++++++ ci/openglwindow/openglwindow.h | 44 +++++++ ci/openglwindow/openglwindow.pri | 4 + ci/openglwindow/openglwindow.pro | 7 + ci/openglwindow_qt5/main.cpp | 180 ++++++++++++++++++++++++++ ci/openglwindow_qt5/openglwindow.cpp | 166 ++++++++++++++++++++++++ ci/openglwindow_qt5/openglwindow.h | 91 +++++++++++++ ci/openglwindow_qt5/openglwindow.pri | 3 + ci/openglwindow_qt5/openglwindow.pro | 7 + ci/openglwindow_qt6.7z | Bin 2513 -> 0 bytes ci/redditclient.7z | Bin 3890 -> 0 bytes ci/redditclient/main.cpp | 76 +++++++++++ ci/redditclient/redditclient.pro | 17 +++ ci/redditclient/redditmodel.cpp | 130 +++++++++++++++++++ ci/redditclient/redditmodel.h | 86 ++++++++++++ ci/redditclient/redditwrapper.cpp | 133 +++++++++++++++++++ ci/redditclient/redditwrapper.h | 85 ++++++++++++ ci/redditclient_qt5/main.cpp | 76 +++++++++++ ci/redditclient_qt5/redditclient.pro | 17 +++ ci/redditclient_qt5/redditmodel.cpp | 130 +++++++++++++++++++ ci/redditclient_qt5/redditmodel.h | 86 ++++++++++++ ci/redditclient_qt5/redditwrapper.cpp | 133 +++++++++++++++++++ ci/redditclient_qt5/redditwrapper.h | 85 ++++++++++++ ci/steps.yml | 70 +++------- 44 files changed, 2398 insertions(+), 52 deletions(-) delete mode 100644 ci/accelbubble.7z create mode 100644 ci/accelbubble/Bluebubble.svg create mode 100644 ci/accelbubble/Bubble.qml create mode 100644 ci/accelbubble/Info.plist create mode 100644 ci/accelbubble/Page1Form.ui.qml create mode 100644 ci/accelbubble/Page2Form.ui.qml create mode 100644 ci/accelbubble/accelbubble.pro create mode 100644 ci/accelbubble/main.cpp create mode 100644 ci/accelbubble/main.qml create mode 100644 ci/accelbubble/qml.qrc create mode 100644 ci/accelbubble/qtquickcontrols2.conf delete mode 100644 ci/helloworld.7z create mode 100644 ci/helloworld/hello.pro create mode 100644 ci/helloworld/main.cpp delete mode 100644 ci/helloworld_qttools.7z create mode 100644 ci/helloworld_qttools/hello.pro create mode 100644 ci/helloworld_qttools/main.cpp delete mode 100644 ci/openglwindow.7z create mode 100644 ci/openglwindow/CMakeLists.txt create mode 100644 ci/openglwindow/main.cpp create mode 100644 ci/openglwindow/openglwindow.cpp create mode 100644 ci/openglwindow/openglwindow.h create mode 100644 ci/openglwindow/openglwindow.pri create mode 100644 ci/openglwindow/openglwindow.pro create mode 100644 ci/openglwindow_qt5/main.cpp create mode 100644 ci/openglwindow_qt5/openglwindow.cpp create mode 100644 ci/openglwindow_qt5/openglwindow.h create mode 100644 ci/openglwindow_qt5/openglwindow.pri create mode 100644 ci/openglwindow_qt5/openglwindow.pro delete mode 100644 ci/openglwindow_qt6.7z delete mode 100644 ci/redditclient.7z create mode 100644 ci/redditclient/main.cpp create mode 100644 ci/redditclient/redditclient.pro create mode 100644 ci/redditclient/redditmodel.cpp create mode 100644 ci/redditclient/redditmodel.h create mode 100644 ci/redditclient/redditwrapper.cpp create mode 100644 ci/redditclient/redditwrapper.h create mode 100644 ci/redditclient_qt5/main.cpp create mode 100644 ci/redditclient_qt5/redditclient.pro create mode 100644 ci/redditclient_qt5/redditmodel.cpp create mode 100644 ci/redditclient_qt5/redditmodel.h create mode 100644 ci/redditclient_qt5/redditwrapper.cpp create mode 100644 ci/redditclient_qt5/redditwrapper.h diff --git a/ci/accelbubble.7z b/ci/accelbubble.7z deleted file mode 100644 index 0cdb0a6f2cfe3bae444f6a66b17a3fef9e1b2693..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3846 zcmV+h5Bcyndc3bE8~_A6E1_J&4gdfE0000Z000000000Yr`A2-N%akjT>u^r%ZCxz z&SsGhgC5HLdo$F3>9^bCsc|(5O8xQb55#87R?HG(Ua4EEJ+kI&*LruBA-(dzgXBQi z|Cs7l>5w$*zEMD#NJi`%EJ@L3>Oqy~W2X?+KNC0a0dObcNiG8~7^rGQr)q z18YLYy0MaI)!m_i;_`2EPCN!zx^SL!$3$y%d(wnFo6C3r8KeN~WwpY zX6F)V^ur5W9sURiAO>Ek0zKq@^!sl*&%`XUityBood5O zylD}Ri>XjTE(G?17bBb=k6`=@QL#nf9YGI@eA^L(C0vo&6)XkMaW-v(z`Y3Q9^2S} z7Z8MM9W+=(g4q+pV<**mDo> zO>Z2St;(oa3Cx{OESvC5H@=Z#m?6*ub8dM!oAyW!L`HA@?KI$w$kyW{x8odnFxxm!#*@l4r!w*OW_IRf_o?; z_d|q<^OA-rld@ersYyG`vxJ+NbgzWG>^kIJK4$jziw9La?s_jBYP>WxFYlh~31tsA zPskM7RRgO*WV+yQBbqmFul_D3$kaMYn#DGEk~!pyIv7lojtK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|K zi&R=$Mx@AUt&i!T1WH63rToDII{q|vn`w-dhe`43^jf`-vwk$<`96b3(;dO3Eyjpo z(Tb*Y!DpyDJBuZ@`fI`3n*>`RzIn{yzRF%?STfX!xs(&FTZV451CK;ffD0PA=N+Yh z)3@MiVCKgAdnNZ;xPl2X|HIVMbgt;pCI9It@G~l^xcKXku%}cTy^nmc#iXqV3r(*& zFp;&?K5Hn{(fkm_Of{Ad&9JBQWv;Z86upw#(ER`RG(xl4ybC(bYgmgBXn$@5|F`F` zJuOe#q(&4L)WvCdl-x#FlRE@5IN>*n?*dWD00000finlL57oaJxz=ncA4naT^i5cV z^~>oGuHF$4zw2BBfVzQ<_e9kdERW)10fejTY>QM$UhrBFVOp26q zVV`qay}HsD-b?7i|7=P^5N9Z^gk2u9*ZLB=M8FHi`#J zqB?SkFk1qz*q>xASmIr6v-san(LMGi=d^+R307`X?Mfm}Y)`?)b~z1@>YdJdLJxcKWdzfJ z|A~~gels$ykI$Pj;a#xemY|^k000*TjgtWhfiM6E3jqKDBLe{e1zi9T000bw8VUhi IircvW02V)CCjbBd diff --git a/ci/accelbubble/Bluebubble.svg b/ci/accelbubble/Bluebubble.svg new file mode 100644 index 00000000..d9c406c4 --- /dev/null +++ b/ci/accelbubble/Bluebubble.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/ci/accelbubble/Bubble.qml b/ci/accelbubble/Bubble.qml new file mode 100644 index 00000000..67e1c592 --- /dev/null +++ b/ci/accelbubble/Bubble.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Controls 2.2 + +Image { + source: "Bluebubble.svg" + smooth: true + property real centerX + property real centerY + property real bubbleCenter +} diff --git a/ci/accelbubble/Info.plist b/ci/accelbubble/Info.plist new file mode 100644 index 00000000..90725455 --- /dev/null +++ b/ci/accelbubble/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDisplayName + accelbubble + CFBundleExecutable + accelbubble + CFBundleGetInfoString + Created by Qt/QMake + CFBundleIdentifier + com.digia.accelbubble + CFBundleName + accelbubble + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + NOTE + This file was generated by Qt/QMake. + UILaunchStoryboardName + LaunchScreen + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + + diff --git a/ci/accelbubble/Page1Form.ui.qml b/ci/accelbubble/Page1Form.ui.qml new file mode 100644 index 00000000..0ab08fc4 --- /dev/null +++ b/ci/accelbubble/Page1Form.ui.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.9 +import QtQuick.Controls 2.2 + +Page { + width: 600 + height: 400 + property alias bubble: bubble + property alias mainWindow: mainWindow + + header: Label { + text: qsTr("Page 1") + font.pixelSize: Qt.application.font.pixelSize * 2 + padding: 10 + } + + Rectangle { + id: mainWindow + color: "#ffffff" + anchors.fill: parent + + Bubble { + id: bubble + } + } +} diff --git a/ci/accelbubble/Page2Form.ui.qml b/ci/accelbubble/Page2Form.ui.qml new file mode 100644 index 00000000..11a8abff --- /dev/null +++ b/ci/accelbubble/Page2Form.ui.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.9 +import QtQuick.Controls 2.2 + +Page { + width: 600 + height: 400 + + header: Label { + text: qsTr("Page 2") + font.pixelSize: Qt.application.font.pixelSize * 2 + padding: 10 + } + + Label { + text: qsTr("You are on Page 2.") + anchors.centerIn: parent + } +} diff --git a/ci/accelbubble/accelbubble.pro b/ci/accelbubble/accelbubble.pro new file mode 100644 index 00000000..2ad69426 --- /dev/null +++ b/ci/accelbubble/accelbubble.pro @@ -0,0 +1,37 @@ +QT += quick svg xml + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += main.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + + ios { + QTPLUGIN += qsvg qsvgicon qtsensors_ios + QMAKE_INFO_PLIST = Info.plist + } + +DISTFILES += \ + Bluebubble.svg diff --git a/ci/accelbubble/main.cpp b/ci/accelbubble/main.cpp new file mode 100644 index 00000000..4e002b28 --- /dev/null +++ b/ci/accelbubble/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/ci/accelbubble/main.qml b/ci/accelbubble/main.qml new file mode 100644 index 00000000..26fe2598 --- /dev/null +++ b/ci/accelbubble/main.qml @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtSensors 5.9 + +ApplicationWindow { + visible: true + width: 640 + height: 480 + title: qsTr("Accelerate Bubble") + + SwipeView { + id: swipeView + anchors.fill: parent + currentIndex: tabBar.currentIndex + + Page1Form { + bubble { + id: bubble + centerX: mainWindow.width / 2 + centerY: mainWindow.height / 2 + bubbleCenter: bubble.width / 2 + x: bubble.centerX - bubble.bubbleCenter + y: bubble.centerY - bubble.bubbleCenter + + Behavior on y { + SmoothedAnimation { + easing.type: Easing.Linear + duration: 100 + } + } + Behavior on x { + SmoothedAnimation { + easing.type: Easing.Linear + duration: 100 + } + } + } + } + + Page2Form { + } + } + + footer: TabBar { + id: tabBar + currentIndex: swipeView.currentIndex + + TabButton { + text: qsTr("Page 1") + } + TabButton { + text: qsTr("Page 2") + } + } + + Accelerometer { + id: accel + dataRate: 100 + active: true + + onReadingChanged: { + var newX = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * 0.1) + var newY = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * 0.1) + + if (isNaN(newX) || isNaN(newY)) + return; + + if (newX < 0) + newX = 0 + + if (newX > mainWindow.width - bubble.width) + newX = mainWindow.width - bubble.width + + if (newY < 18) + newY = 18 + + if (newY > mainWindow.height - bubble.height) + newY = mainWindow.height - bubble.height + + bubble.x = newX + bubble.y = newY + } + } + + function calcPitch(x, y, z) { + return -(Math.atan(y / Math.sqrt(x * x + z * z)) * 57.2957795); + } + function calcRoll(x, y, z) { + return -(Math.atan(x / Math.sqrt(y * y + z * z)) * 57.2957795); + } +} diff --git a/ci/accelbubble/qml.qrc b/ci/accelbubble/qml.qrc new file mode 100644 index 00000000..7d7777ac --- /dev/null +++ b/ci/accelbubble/qml.qrc @@ -0,0 +1,10 @@ + + + Page1Form.ui.qml + Page2Form.ui.qml + qtquickcontrols2.conf + Bubble.qml + Bluebubble.svg + main.qml + + diff --git a/ci/accelbubble/qtquickcontrols2.conf b/ci/accelbubble/qtquickcontrols2.conf new file mode 100644 index 00000000..75b2cb8f --- /dev/null +++ b/ci/accelbubble/qtquickcontrols2.conf @@ -0,0 +1,6 @@ +; This file can be edited to change the style of the application +; Read "Qt Quick Controls 2 Configuration File" for details: +; http://doc.qt.io/qt-5/qtquickcontrols2-configuration.html + +[Controls] +Style=Default diff --git a/ci/helloworld.7z b/ci/helloworld.7z deleted file mode 100644 index ffbf45d245ca730f837c01734c1968dbdd6f1147..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 439 zcmV;o0Z9Hgdc3bE8~_A)?UxF40RR910000Z000000001kT%b+h0XhKVT>vPR02zD{ zJPM}Eb*`B7x9*mAv=PtJi)0wl=&njk;&tS}Gi;j9A#b|RVaR?!z_LkAz?mO>P&?O82m@*cXD8&T=9wn<+t!tdWtLn@Ny4XV0r#u*y0V4yb_c0000N27v1U h34n$E5C8xSfZ7THDv7t^006h&yD|U( diff --git a/ci/helloworld/hello.pro b/ci/helloworld/hello.pro new file mode 100644 index 00000000..57f727a2 --- /dev/null +++ b/ci/helloworld/hello.pro @@ -0,0 +1,9 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = Hello +TEMPLATE = app + +SOURCES += main.cpp + diff --git a/ci/helloworld/main.cpp b/ci/helloworld/main.cpp new file mode 100644 index 00000000..cd61fcbc --- /dev/null +++ b/ci/helloworld/main.cpp @@ -0,0 +1,12 @@ +#include +#include + +int main(int argc, char **argv) +{ + QApplication app (argc, argv); + + QPushButton button ("Hello world !"); + button.show(); + + return app.exec(); +} \ No newline at end of file diff --git a/ci/helloworld_qttools.7z b/ci/helloworld_qttools.7z deleted file mode 100644 index cd17b1deba7f96081606922b69f2bc65f38510a3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 425 zcmV;a0apGudc3bE8~_BrMqVps0RR910000Z000000000iqKSau0Wbj1T>vPR02zD{ zJPOVR2i@3&U=&nY0OL0r!PzOwKx%*Z<2`@8REEln9wu!8u?K&~jIx&&0@ohucx&4x zR%QF#s!&~kCv4RNug~q^(HqX1#&Qn@8!tZ~@^{JFh~$XvNMpmVrGZX@2zQ!zZ(9F& z-{o5iQ1Ml%^YayeIiZ;x`l{=5RajY{49y40ZN;~{O|vLCeN#XPan4F+_9{k4s^LV} z^%ip|MMIY2_Xd>gHt#UmMA*-6$}9Bv2zDyGeDk4VawWhxgf+ds0U#&2KNFd@$r{27Xf9i*09@A&{~FMj z3p1CbOAxyIpn5_KFr3?2okZ-gUqe;kW1M|lAqevX02c;;*8vHDj{pY?0RRCb0|5aA TT>uaO01SZo3IS)M3BdpW{XVvs diff --git a/ci/helloworld_qttools/hello.pro b/ci/helloworld_qttools/hello.pro new file mode 100644 index 00000000..03a8fe60 --- /dev/null +++ b/ci/helloworld_qttools/hello.pro @@ -0,0 +1,7 @@ +QT += uitools + +TARGET = Hello +TEMPLATE = app + +SOURCES += main.cpp + diff --git a/ci/helloworld_qttools/main.cpp b/ci/helloworld_qttools/main.cpp new file mode 100644 index 00000000..7d6d1924 --- /dev/null +++ b/ci/helloworld_qttools/main.cpp @@ -0,0 +1,13 @@ +#include +#include +#include + +int main(int argc, char **argv) +{ + QApplication app (argc, argv); + QUiLoader loader; + QPushButton button ("Hello world !"); + button.show(); + + return app.exec(); +} diff --git a/ci/openglwindow.7z b/ci/openglwindow.7z deleted file mode 100644 index c43192dfdb2f2fe9d04ae7616a0fb8a5e5bf5d6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3134 zcmV-E48ij^dc3bE8~_9o@89tI3jhEB0000Z000000001OEjBLTGbjsBT>uw~vpEGu z5Qw*KGJL|jv`Qj5>r+(T`^sBV^_|RfXk8DRp6J$nZT7@xBK}z`94W^HUbJ zzpGrV%3voJjoy!z<1%bJ-WI02c)Ijf({_ULD4*JkQOyosoVSDWLUvt5YVMDK1PrQ= zueCw;aB1{c>`ymG;yPFZ#QT(ZdT6ZZdQ@&%hNb&6qqtN}84Vh^gx0PDZ1gjON$RL? zyhi#tb?^NBU>qm7eaXge!`^sRjc2A#(bRqkNweJ3f6I=e)i*)hXyCFI=I5;NCCGu8 zRL$5~vTDT7f5De~+%6t3@?YTxRbE!Bcsd#r%gUQ>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2^JKN64O0LS!JYJsmrsORXp#3@MbA-`$`|k4`in0b$8vkqTzeAqmlvZj;VpG( zb$P9p?EBkq&t5mS^8AUJ3FHRX^cn|jj`@z_N)%b=fZafsizU)+oDkl$)}yo6%cy-8 zRPfd+ure3}MU*U!!L{K9w8goQKsUZE90->Q%XF`JG2(BZX;&cKexLXy(@<4PMZNk+ z-n00$>tqXeu(vYY+B3&3pAX(+du%@2dXc24kH&vlmIe*5(n)re@nLl4lBsb*TIjteI7`byy{y9u5170{ z6f1B-)J9NopQ~&?~finlL57no{TGu4g{u=K zU6z}PFvSF=2GK%`$uJ_!HwRK86Cx$75(@1gPLi8N05;;4u<=%c$?~0xdPTSodhKtJ zA?CSq z@$qIna(F0`+<5blO(-Oy$RD*^y)}Bf?bEEi@50?Ee-3000*Ti&p^&fTREi3jqKD YBLe{e1zi9T000bu)(QbIH4)VS0Pg_)o&W#< diff --git a/ci/openglwindow/CMakeLists.txt b/ci/openglwindow/CMakeLists.txt new file mode 100644 index 00000000..3d5511ef --- /dev/null +++ b/ci/openglwindow/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.16) +project(openglwindow LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/openglwindow") + +find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL) + +qt_add_executable(openglwindow + main.cpp + openglwindow.cpp openglwindow.h +) + +set_target_properties(openglwindow PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(openglwindow PUBLIC + Qt::Core + Qt::Gui + Qt::OpenGL +) + +install(TARGETS openglwindow + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/ci/openglwindow/main.cpp b/ci/openglwindow/main.cpp new file mode 100644 index 00000000..6813dc9e --- /dev/null +++ b/ci/openglwindow/main.cpp @@ -0,0 +1,130 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "openglwindow.h" + +#include +#include +#include +#include +#include + + +//! [1] +class TriangleWindow : public OpenGLWindow +{ +public: + using OpenGLWindow::OpenGLWindow; + + void initialize() override; + void render() override; + +private: + GLint m_posAttr = 0; + GLint m_colAttr = 0; + GLint m_matrixUniform = 0; + + QOpenGLShaderProgram *m_program = nullptr; + int m_frame = 0; +}; +//! [1] + +//! [2] +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + QSurfaceFormat format; + format.setSamples(16); + + TriangleWindow window; + window.setFormat(format); + window.resize(640, 480); + window.show(); + + window.setAnimating(true); + + return app.exec(); +} +//! [2] + + +//! [3] +static const char *vertexShaderSource = + "attribute highp vec4 posAttr;\n" + "attribute lowp vec4 colAttr;\n" + "varying lowp vec4 col;\n" + "uniform highp mat4 matrix;\n" + "void main() {\n" + " col = colAttr;\n" + " gl_Position = matrix * posAttr;\n" + "}\n"; + +static const char *fragmentShaderSource = + "varying lowp vec4 col;\n" + "void main() {\n" + " gl_FragColor = col;\n" + "}\n"; +//! [3] + +//! [4] +void TriangleWindow::initialize() +{ + m_program = new QOpenGLShaderProgram(this); + m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); + m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); + m_program->link(); + m_posAttr = m_program->attributeLocation("posAttr"); + Q_ASSERT(m_posAttr != -1); + m_colAttr = m_program->attributeLocation("colAttr"); + Q_ASSERT(m_colAttr != -1); + m_matrixUniform = m_program->uniformLocation("matrix"); + Q_ASSERT(m_matrixUniform != -1); +} +//! [4] + +//! [5] +void TriangleWindow::render() +{ + const qreal retinaScale = devicePixelRatio(); + glViewport(0, 0, width() * retinaScale, height() * retinaScale); + + glClear(GL_COLOR_BUFFER_BIT); + + m_program->bind(); + + QMatrix4x4 matrix; + matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f); + matrix.translate(0, 0, -2); + matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0); + + m_program->setUniformValue(m_matrixUniform, matrix); + + static const GLfloat vertices[] = { + 0.0f, 0.707f, + -0.5f, -0.5f, + 0.5f, -0.5f + }; + + static const GLfloat colors[] = { + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f + }; + + glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices); + glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors); + + glEnableVertexAttribArray(m_posAttr); + glEnableVertexAttribArray(m_colAttr); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableVertexAttribArray(m_colAttr); + glDisableVertexAttribArray(m_posAttr); + + m_program->release(); + + ++m_frame; +} +//! [5] diff --git a/ci/openglwindow/openglwindow.cpp b/ci/openglwindow/openglwindow.cpp new file mode 100644 index 00000000..4869f45e --- /dev/null +++ b/ci/openglwindow/openglwindow.cpp @@ -0,0 +1,114 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "openglwindow.h" + +#include +#include +#include + +//! [1] +OpenGLWindow::OpenGLWindow(QWindow *parent) + : QWindow(parent) +{ + setSurfaceType(QWindow::OpenGLSurface); +} +//! [1] + +OpenGLWindow::~OpenGLWindow() +{ + delete m_device; +} +//! [2] +void OpenGLWindow::render(QPainter *painter) +{ + Q_UNUSED(painter); +} + +void OpenGLWindow::initialize() +{ +} + +void OpenGLWindow::render() +{ + if (!m_device) + m_device = new QOpenGLPaintDevice; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + m_device->setSize(size() * devicePixelRatio()); + m_device->setDevicePixelRatio(devicePixelRatio()); + + QPainter painter(m_device); + render(&painter); +} +//! [2] + +//! [3] +void OpenGLWindow::renderLater() +{ + requestUpdate(); +} + +bool OpenGLWindow::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::UpdateRequest: + renderNow(); + return true; + default: + return QWindow::event(event); + } +} + +void OpenGLWindow::exposeEvent(QExposeEvent *event) +{ + Q_UNUSED(event); + + if (isExposed()) + renderNow(); +} +//! [3] + +//! [4] +void OpenGLWindow::renderNow() +{ + if (!isExposed()) + return; + + bool needsInitialize = false; + + if (!m_context) { + m_context = new QOpenGLContext(this); + m_context->setFormat(requestedFormat()); + m_context->create(); + + needsInitialize = true; + } + + m_context->makeCurrent(this); + + if (needsInitialize) { + initializeOpenGLFunctions(); + initialize(); + } + + render(); + + m_context->swapBuffers(this); + + if (m_animating) + renderLater(); +} +//! [4] + +//! [5] +void OpenGLWindow::setAnimating(bool animating) +{ + m_animating = animating; + + if (animating) + renderLater(); +} +//! [5] + diff --git a/ci/openglwindow/openglwindow.h b/ci/openglwindow/openglwindow.h new file mode 100644 index 00000000..7206fc57 --- /dev/null +++ b/ci/openglwindow/openglwindow.h @@ -0,0 +1,44 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QOpenGLContext; +class QOpenGLPaintDevice; +QT_END_NAMESPACE + +//! [1] +class OpenGLWindow : public QWindow, protected QOpenGLFunctions +{ + Q_OBJECT +public: + explicit OpenGLWindow(QWindow *parent = nullptr); + ~OpenGLWindow(); + + virtual void render(QPainter *painter); + virtual void render(); + + virtual void initialize(); + + void setAnimating(bool animating); + +public slots: + void renderLater(); + void renderNow(); + +protected: + bool event(QEvent *event) override; + + void exposeEvent(QExposeEvent *event) override; + +private: + bool m_animating = false; + + QOpenGLContext *m_context = nullptr; + QOpenGLPaintDevice *m_device = nullptr; +}; +//! [1] + diff --git a/ci/openglwindow/openglwindow.pri b/ci/openglwindow/openglwindow.pri new file mode 100644 index 00000000..30320df3 --- /dev/null +++ b/ci/openglwindow/openglwindow.pri @@ -0,0 +1,4 @@ +QT += opengl +INCLUDEPATH += $$PWD +SOURCES += $$PWD/openglwindow.cpp +HEADERS += $$PWD/openglwindow.h diff --git a/ci/openglwindow/openglwindow.pro b/ci/openglwindow/openglwindow.pro new file mode 100644 index 00000000..8b1ae71c --- /dev/null +++ b/ci/openglwindow/openglwindow.pro @@ -0,0 +1,7 @@ +include(openglwindow.pri) + +SOURCES += \ + main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/opengl/openglwindow +INSTALLS += target diff --git a/ci/openglwindow_qt5/main.cpp b/ci/openglwindow_qt5/main.cpp new file mode 100644 index 00000000..90c93f0d --- /dev/null +++ b/ci/openglwindow_qt5/main.cpp @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "openglwindow.h" + +#include +#include +#include +#include + +#include + +//! [1] +class TriangleWindow : public OpenGLWindow +{ +public: + TriangleWindow(); + + void initialize() override; + void render() override; + +private: + GLuint m_posAttr; + GLuint m_colAttr; + GLuint m_matrixUniform; + + QOpenGLShaderProgram *m_program; + int m_frame; +}; + +TriangleWindow::TriangleWindow() + : m_program(0) + , m_frame(0) +{ +} +//! [1] + +//! [2] +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + QSurfaceFormat format; + format.setSamples(16); + + TriangleWindow window; + window.setFormat(format); + window.resize(640, 480); + window.show(); + + window.setAnimating(true); + + return app.exec(); +} +//! [2] + + +//! [3] +static const char *vertexShaderSource = + "attribute highp vec4 posAttr;\n" + "attribute lowp vec4 colAttr;\n" + "varying lowp vec4 col;\n" + "uniform highp mat4 matrix;\n" + "void main() {\n" + " col = colAttr;\n" + " gl_Position = matrix * posAttr;\n" + "}\n"; + +static const char *fragmentShaderSource = + "varying lowp vec4 col;\n" + "void main() {\n" + " gl_FragColor = col;\n" + "}\n"; +//! [3] + +//! [4] +void TriangleWindow::initialize() +{ + m_program = new QOpenGLShaderProgram(this); + m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); + m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); + m_program->link(); + m_posAttr = m_program->attributeLocation("posAttr"); + m_colAttr = m_program->attributeLocation("colAttr"); + m_matrixUniform = m_program->uniformLocation("matrix"); +} +//! [4] + +//! [5] +void TriangleWindow::render() +{ + const qreal retinaScale = devicePixelRatio(); + glViewport(0, 0, width() * retinaScale, height() * retinaScale); + + glClear(GL_COLOR_BUFFER_BIT); + + m_program->bind(); + + QMatrix4x4 matrix; + matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f); + matrix.translate(0, 0, -2); + matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0); + + m_program->setUniformValue(m_matrixUniform, matrix); + + GLfloat vertices[] = { + 0.0f, 0.707f, + -0.5f, -0.5f, + 0.5f, -0.5f + }; + + GLfloat colors[] = { + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f + }; + + glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices); + glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors); + + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableVertexAttribArray(1); + glDisableVertexAttribArray(0); + + m_program->release(); + + ++m_frame; +} +//! [5] diff --git a/ci/openglwindow_qt5/openglwindow.cpp b/ci/openglwindow_qt5/openglwindow.cpp new file mode 100644 index 00000000..a0c85006 --- /dev/null +++ b/ci/openglwindow_qt5/openglwindow.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "openglwindow.h" + +#include + +#include +#include +#include + +//! [1] +OpenGLWindow::OpenGLWindow(QWindow *parent) + : QWindow(parent) + , m_animating(false) + , m_context(0) + , m_device(0) +{ + setSurfaceType(QWindow::OpenGLSurface); +} +//! [1] + +OpenGLWindow::~OpenGLWindow() +{ + delete m_device; +} +//! [2] +void OpenGLWindow::render(QPainter *painter) +{ + Q_UNUSED(painter); +} + +void OpenGLWindow::initialize() +{ +} + +void OpenGLWindow::render() +{ + if (!m_device) + m_device = new QOpenGLPaintDevice; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + m_device->setSize(size() * devicePixelRatio()); + m_device->setDevicePixelRatio(devicePixelRatio()); + + QPainter painter(m_device); + render(&painter); +} +//! [2] + +//! [3] +void OpenGLWindow::renderLater() +{ + requestUpdate(); +} + +bool OpenGLWindow::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::UpdateRequest: + renderNow(); + return true; + default: + return QWindow::event(event); + } +} + +void OpenGLWindow::exposeEvent(QExposeEvent *event) +{ + Q_UNUSED(event); + + if (isExposed()) + renderNow(); +} +//! [3] + +//! [4] +void OpenGLWindow::renderNow() +{ + if (!isExposed()) + return; + + bool needsInitialize = false; + + if (!m_context) { + m_context = new QOpenGLContext(this); + m_context->setFormat(requestedFormat()); + m_context->create(); + + needsInitialize = true; + } + + m_context->makeCurrent(this); + + if (needsInitialize) { + initializeOpenGLFunctions(); + initialize(); + } + + render(); + + m_context->swapBuffers(this); + + if (m_animating) + renderLater(); +} +//! [4] + +//! [5] +void OpenGLWindow::setAnimating(bool animating) +{ + m_animating = animating; + + if (animating) + renderLater(); +} +//! [5] + diff --git a/ci/openglwindow_qt5/openglwindow.h b/ci/openglwindow_qt5/openglwindow.h new file mode 100644 index 00000000..6e6c1d74 --- /dev/null +++ b/ci/openglwindow_qt5/openglwindow.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QOpenGLContext; +class QOpenGLPaintDevice; +QT_END_NAMESPACE + +//! [1] +class OpenGLWindow : public QWindow, protected QOpenGLFunctions +{ + Q_OBJECT +public: + explicit OpenGLWindow(QWindow *parent = 0); + ~OpenGLWindow(); + + virtual void render(QPainter *painter); + virtual void render(); + + virtual void initialize(); + + void setAnimating(bool animating); + +public slots: + void renderLater(); + void renderNow(); + +protected: + bool event(QEvent *event) override; + + void exposeEvent(QExposeEvent *event) override; + +private: + bool m_animating; + + QOpenGLContext *m_context; + QOpenGLPaintDevice *m_device; +}; +//! [1] + diff --git a/ci/openglwindow_qt5/openglwindow.pri b/ci/openglwindow_qt5/openglwindow.pri new file mode 100644 index 00000000..45b0b0cd --- /dev/null +++ b/ci/openglwindow_qt5/openglwindow.pri @@ -0,0 +1,3 @@ +INCLUDEPATH += $$PWD +SOURCES += $$PWD/openglwindow.cpp +HEADERS += $$PWD/openglwindow.h diff --git a/ci/openglwindow_qt5/openglwindow.pro b/ci/openglwindow_qt5/openglwindow.pro new file mode 100644 index 00000000..93f18f3d --- /dev/null +++ b/ci/openglwindow_qt5/openglwindow.pro @@ -0,0 +1,7 @@ +include(openglwindow.pri) + +SOURCES += \ + main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/gui/openglwindow +INSTALLS += target diff --git a/ci/openglwindow_qt6.7z b/ci/openglwindow_qt6.7z deleted file mode 100644 index 332a8f2e218435e0826011ebf0ac74b0bcc76696..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2513 zcmV;?2`=_Gdc3bE8~_BN2&k!!2><{90000Z000000000!O3QWN8|?_dT>vqgNJp(Z z^kSf1E^j)R68Fv;3+-8%;E!|hEB2N0Hy^>~NPUZ^V=Xyw!cKwNKW$qb&D2z`CrEty z3OiT(=bL7IiFywE5~&F?&k=Y|AS}!M5d_>g=(PIFGx~39dCz~Pd#&Zqs2Krnkp-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IZv z^35CTZ02Dg&gO1`*LU^(Evm~OS!f)gEN5G($$b7*%GpJUS!G}b?u&7y0Cb{FqSL6+ zOlQX~;v-C{_1-s$fmQ+|lRe2Ou`2uHmi72HH&&XFm+wvJ(Ww9c02c;`$N>p}#sCKk b0RRCb0|5aAT>uaO01Sc}3IV-u+{pj{J~F$| diff --git a/ci/redditclient.7z b/ci/redditclient.7z deleted file mode 100644 index 4e346cc218524800cda47a705898794f520d7828..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3890 zcmV-256$p5dc3bE8~_BfUtQMk4gdfE0000Z000000001RD2V*vPjU>cT>uw~vpEKW zxO<~(^2u;xYP~^b%|_xe`d@Gv_%4cQNKfK2^XZKl00@|^rdrMS`IOw8IYJk<;JkOM zL-ha;dSx5Fu%`u`4b@9}GDhNE5|o%k={R}lE=`MwNk3v$7J=?`%M*y zd7YJ2C*5YVI>=UIVNgX!##?9J-ml6T_8*BaNsnYOPVAF#B786zoBsp`rC_`?@osGk>-UpAtcXA zUeXn3H-#cRbW#-h(ftRF+n>F#v1f0D0Ov6ZU0x&A5Ut{`ocEw7ss$7`J4{=Efh@U* zv3+s>2P?lnw|sYLh*-Ntp%tj^q{=212t2{u+lQ?>SuI+!w9_TwN*15Ri#@cpdc9Z|G~sa~pogO$zBE8CWx`Fu2zIZ2rKd01W-Ej62P<%b z8z}U;ZuGu|unXMCKz=%M=zcbM^w_rL-CKR4?bi+`_bz)5n^?F6kF0lOO2Xv~TQEBBwSu3{mGwc*C4g-s-?K@qB z??moGm|phKzPrT1Mrdwm#Z!?lWTjpYMF6(nI~CwA{#Q(EuAxOhK-yugrFv}uP_);1dfG z)PW~Y(&5VW%eT4teV^NUmIpT+qRWS{Be3VQ<1=t~H+TX>6_+$*`+OsQhA;6Q-?aC{@5X3vnS(YbG|9Mv`hILNY8n>#82cKEMrUXZQ;9i7mp z5$Bxw2q4JZ%TT|HeER7O@B#JUji=VD_O~5p4nl6A_q#KM@EhH6dXVC@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b)rV&NO3(+_3nI9=(ToQ1xQ&l+j&ECnSII}rG5{-Lv$xg(Qk>Fnb@c)(?V$df#W!%$w zIzMq4X}~rreVxfC$ttCaK~naC31!J|Zj7HZHkaWuVY%01aF zl)ik1Ydb@T*R`7eU8x-(=^#l{Q+cwuYBUVO5TZ-jqcA^ASD8N`fFCIK=Ly4;HyEq84qG)-i5W(onKB_+;Z6x#Gzp@J|t06)Rb zvk*?H9FNkkw8-Kw7*5Ozm*6A=QXsMw^nMk|O!07B>_!iJ_mHm=Yw>l7j+I!NgYhH! zuS-khDd8y6xG*juOECZd-~yikNL>IGih@4ah(?hYm2h>DLVqi;UxE(+@ zOS2IEdd@mK^ii5U0bSVyCW(Zy==obU|Ej4JG(u)wmcGo3K4l#t(+zCG`vamre!HGQ z@`34-6{r>Y`u~5s15;zQL`PPJkg9IStzZ(XLl&8)Z+lig;!YeJly%U162vE0M769z zGp+oqp!tZY_zTN9u-};@6s;3wfc<5ab5|hgtD+T}n004nA2d*)nQB0p} zxp9{fK=kDcUJ;P?FqmH9K3N68g*_^NOA}U>XARY|)z~%Q>6XIuiTAyid#1RnEE!jL zOocxTd!#S;O1MA}(1xIWZcUYM0El1)XN3-F?ubNLLx2RX<`Ww*I(JOve9}20sNTI8 zHWj*6=H3}dLQ?V6uJvS4T6M~#`OFIoZWNbZQz$|7QTthFhZE%|ed!0Qc=j3L@R?*% z5I;Ie2dAjd+Zp#pmU^Z)big$3Ywx*tz#13dUA>*Bdwhbz&(Siv89+B81xFiOARBuL z?f2Sn3Q4w51mWlr000*Tjs*b;fa(AT3jqKDBLe{e1zi9T000bvstN&`aFr+k05cwE AsQ>@~ diff --git a/ci/redditclient/main.cpp b/ci/redditclient/main.cpp new file mode 100644 index 00000000..d451fd1b --- /dev/null +++ b/ci/redditclient/main.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "redditmodel.h" + +#include +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + QCommandLineParser parser; + const QCommandLineOption clientId(QStringList() << "i" << "client-id", + "Specifies the application client id", "client_id"); + + parser.addOptions({clientId}); + parser.process(app); + + if (parser.isSet(clientId)) { + QListView view; + RedditModel model(parser.value(clientId)); + view.setModel(&model); + view.show(); + return app.exec(); + } else { + parser.showHelp(); + } + return 0; +} diff --git a/ci/redditclient/redditclient.pro b/ci/redditclient/redditclient.pro new file mode 100644 index 00000000..456fc781 --- /dev/null +++ b/ci/redditclient/redditclient.pro @@ -0,0 +1,17 @@ +QT += widgets network networkauth +requires(qtConfig(listview)) + +TARGET = redditclient + +# Input +SOURCES += main.cpp \ + redditmodel.cpp \ + redditwrapper.cpp + +HEADERS += \ + redditmodel.h \ + redditwrapper.h + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/oauth/redditclient +INSTALLS += target diff --git a/ci/redditclient/redditmodel.cpp b/ci/redditclient/redditmodel.cpp new file mode 100644 index 00000000..a415e04b --- /dev/null +++ b/ci/redditclient/redditmodel.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "redditmodel.h" + +#include +#include + +RedditModel::RedditModel(QObject *parent) : QAbstractTableModel(parent) {} + +RedditModel::RedditModel(const QString &clientId, QObject *parent) : + QAbstractTableModel(parent), + redditWrapper(clientId) +{ + grant(); +} + +int RedditModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return threads.size(); +} + +int RedditModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return threads.size() ? 1 : 0; +} + +QVariant RedditModel::data(const QModelIndex &index, int role) const +{ + Q_UNUSED(role); + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DisplayRole) { + const auto childrenObject = threads.at(index.row()); + Q_ASSERT(childrenObject.value("data").isObject()); + const auto dataObject = childrenObject.value("data").toObject(); + return dataObject.value("title").toString(); + } + return QVariant(); +} + +void RedditModel::grant() +{ + redditWrapper.grant(); + connect(&redditWrapper, &RedditWrapper::authenticated, this, &RedditModel::update); +} + +void RedditModel::update() +{ + auto reply = redditWrapper.requestHotThreads(); + + connect(reply, &QNetworkReply::finished, [=]() { + reply->deleteLater(); + if (reply->error() != QNetworkReply::NoError) { + emit error(reply->errorString()); + return; + } + const auto json = reply->readAll(); + const auto document = QJsonDocument::fromJson(json); + Q_ASSERT(document.isObject()); + const auto rootObject = document.object(); + Q_ASSERT(rootObject.value("kind").toString() == "Listing"); + const auto dataValue = rootObject.value("data"); + Q_ASSERT(dataValue.isObject()); + const auto dataObject = dataValue.toObject(); + const auto childrenValue = dataObject.value("children"); + Q_ASSERT(childrenValue.isArray()); + const auto childrenArray = childrenValue.toArray(); + + if (childrenArray.isEmpty()) + return; + + beginInsertRows(QModelIndex(), threads.size(), childrenArray.size() + threads.size() - 1); + for (const auto childValue : qAsConst(childrenArray)) { + Q_ASSERT(childValue.isObject()); + threads.append(childValue.toObject()); + } + endInsertRows(); + }); +} diff --git a/ci/redditclient/redditmodel.h b/ci/redditclient/redditmodel.h new file mode 100644 index 00000000..98dbb907 --- /dev/null +++ b/ci/redditclient/redditmodel.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef REDDITMODEL_H +#define REDDITMODEL_H + +#include "redditwrapper.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QNetworkReply) + +class RedditModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + RedditModel(QObject *parent = nullptr); + RedditModel(const QString &clientId, QObject *parent = nullptr); + + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + + void grant(); + +signals: + void error(const QString &errorString); + +private slots: + void update(); + +private: + RedditWrapper redditWrapper; + QPointer liveThreadReply; + QList threads; +}; + +#endif // REDDITMODEL_H diff --git a/ci/redditclient/redditwrapper.cpp b/ci/redditclient/redditwrapper.cpp new file mode 100644 index 00000000..c112671c --- /dev/null +++ b/ci/redditclient/redditwrapper.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "redditwrapper.h" + +#include +#include +#include + +const QUrl newUrl("https://oauth.reddit.com/new"); +const QUrl hotUrl("https://oauth.reddit.com/hot"); +const QUrl liveThreadsUrl("https://oauth.reddit.com/live/XXXX/about.json"); + +RedditWrapper::RedditWrapper(QObject *parent) : QObject(parent) +{ + auto replyHandler = new QOAuthHttpServerReplyHandler(1337, this); + oauth2.setReplyHandler(replyHandler); + oauth2.setAuthorizationUrl(QUrl("https://www.reddit.com/api/v1/authorize")); + oauth2.setAccessTokenUrl(QUrl("https://www.reddit.com/api/v1/access_token")); + oauth2.setScope("identity read"); + + connect(&oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=]( + QAbstractOAuth::Status status) { + if (status == QAbstractOAuth::Status::Granted) + emit authenticated(); + }); + oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QMultiMap *parameters) { + if (stage == QAbstractOAuth::Stage::RequestingAuthorization && isPermanent()) + parameters->insert("duration", "permanent"); + }); + connect(&oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, + &QDesktopServices::openUrl); +} + +RedditWrapper::RedditWrapper(const QString &clientIdentifier, QObject *parent) : + RedditWrapper(parent) +{ + oauth2.setClientIdentifier(clientIdentifier); +} + +QNetworkReply *RedditWrapper::requestHotThreads() +{ + qDebug() << "Getting hot threads..."; + return oauth2.get(hotUrl); +} + +bool RedditWrapper::isPermanent() const +{ + return permanent; +} + +void RedditWrapper::setPermanent(bool value) +{ + permanent = value; +} + +void RedditWrapper::grant() +{ + oauth2.grant(); +} + +void RedditWrapper::subscribeToLiveUpdates() +{ + qDebug() << "Susbscribing..."; + QNetworkReply *reply = oauth2.get(liveThreadsUrl); + connect(reply, &QNetworkReply::finished, [=]() { + reply->deleteLater(); + if (reply->error() != QNetworkReply::NoError) { + qCritical() << "Reddit error:" << reply->errorString(); + return; + } + + const auto json = reply->readAll(); + + const auto document = QJsonDocument::fromJson(json); + Q_ASSERT(document.isObject()); + const auto rootObject = document.object(); + const auto dataValue = rootObject.value("data"); + Q_ASSERT(dataValue.isObject()); + const auto dataObject = dataValue.toObject(); + const auto websocketUrlValue = dataObject.value("websocket_url"); + Q_ASSERT(websocketUrlValue.isString() && websocketUrlValue.toString().size()); + const QUrl websocketUrl(websocketUrlValue.toString()); + emit subscribed(websocketUrl); + }); +} diff --git a/ci/redditclient/redditwrapper.h b/ci/redditclient/redditwrapper.h new file mode 100644 index 00000000..4b86ba97 --- /dev/null +++ b/ci/redditclient/redditwrapper.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef REDDITWRAPPER_H +#define REDDITWRAPPER_H + +#include +#include + +#include + +class RedditWrapper : public QObject +{ + Q_OBJECT + +public: + RedditWrapper(QObject *parent = nullptr); + RedditWrapper(const QString &clientIdentifier, QObject *parent = nullptr); + + QNetworkReply *requestHotThreads(); + + bool isPermanent() const; + void setPermanent(bool value); + +public slots: + void grant(); + void subscribeToLiveUpdates(); + +signals: + void authenticated(); + void subscribed(const QUrl &url); + +private: + QOAuth2AuthorizationCodeFlow oauth2; + bool permanent = false; +}; + +#endif // REDDITWRAPPER_H diff --git a/ci/redditclient_qt5/main.cpp b/ci/redditclient_qt5/main.cpp new file mode 100644 index 00000000..d451fd1b --- /dev/null +++ b/ci/redditclient_qt5/main.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "redditmodel.h" + +#include +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + QCommandLineParser parser; + const QCommandLineOption clientId(QStringList() << "i" << "client-id", + "Specifies the application client id", "client_id"); + + parser.addOptions({clientId}); + parser.process(app); + + if (parser.isSet(clientId)) { + QListView view; + RedditModel model(parser.value(clientId)); + view.setModel(&model); + view.show(); + return app.exec(); + } else { + parser.showHelp(); + } + return 0; +} diff --git a/ci/redditclient_qt5/redditclient.pro b/ci/redditclient_qt5/redditclient.pro new file mode 100644 index 00000000..456fc781 --- /dev/null +++ b/ci/redditclient_qt5/redditclient.pro @@ -0,0 +1,17 @@ +QT += widgets network networkauth +requires(qtConfig(listview)) + +TARGET = redditclient + +# Input +SOURCES += main.cpp \ + redditmodel.cpp \ + redditwrapper.cpp + +HEADERS += \ + redditmodel.h \ + redditwrapper.h + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/oauth/redditclient +INSTALLS += target diff --git a/ci/redditclient_qt5/redditmodel.cpp b/ci/redditclient_qt5/redditmodel.cpp new file mode 100644 index 00000000..a415e04b --- /dev/null +++ b/ci/redditclient_qt5/redditmodel.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "redditmodel.h" + +#include +#include + +RedditModel::RedditModel(QObject *parent) : QAbstractTableModel(parent) {} + +RedditModel::RedditModel(const QString &clientId, QObject *parent) : + QAbstractTableModel(parent), + redditWrapper(clientId) +{ + grant(); +} + +int RedditModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return threads.size(); +} + +int RedditModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return threads.size() ? 1 : 0; +} + +QVariant RedditModel::data(const QModelIndex &index, int role) const +{ + Q_UNUSED(role); + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DisplayRole) { + const auto childrenObject = threads.at(index.row()); + Q_ASSERT(childrenObject.value("data").isObject()); + const auto dataObject = childrenObject.value("data").toObject(); + return dataObject.value("title").toString(); + } + return QVariant(); +} + +void RedditModel::grant() +{ + redditWrapper.grant(); + connect(&redditWrapper, &RedditWrapper::authenticated, this, &RedditModel::update); +} + +void RedditModel::update() +{ + auto reply = redditWrapper.requestHotThreads(); + + connect(reply, &QNetworkReply::finished, [=]() { + reply->deleteLater(); + if (reply->error() != QNetworkReply::NoError) { + emit error(reply->errorString()); + return; + } + const auto json = reply->readAll(); + const auto document = QJsonDocument::fromJson(json); + Q_ASSERT(document.isObject()); + const auto rootObject = document.object(); + Q_ASSERT(rootObject.value("kind").toString() == "Listing"); + const auto dataValue = rootObject.value("data"); + Q_ASSERT(dataValue.isObject()); + const auto dataObject = dataValue.toObject(); + const auto childrenValue = dataObject.value("children"); + Q_ASSERT(childrenValue.isArray()); + const auto childrenArray = childrenValue.toArray(); + + if (childrenArray.isEmpty()) + return; + + beginInsertRows(QModelIndex(), threads.size(), childrenArray.size() + threads.size() - 1); + for (const auto childValue : qAsConst(childrenArray)) { + Q_ASSERT(childValue.isObject()); + threads.append(childValue.toObject()); + } + endInsertRows(); + }); +} diff --git a/ci/redditclient_qt5/redditmodel.h b/ci/redditclient_qt5/redditmodel.h new file mode 100644 index 00000000..98dbb907 --- /dev/null +++ b/ci/redditclient_qt5/redditmodel.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef REDDITMODEL_H +#define REDDITMODEL_H + +#include "redditwrapper.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QNetworkReply) + +class RedditModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + RedditModel(QObject *parent = nullptr); + RedditModel(const QString &clientId, QObject *parent = nullptr); + + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + + void grant(); + +signals: + void error(const QString &errorString); + +private slots: + void update(); + +private: + RedditWrapper redditWrapper; + QPointer liveThreadReply; + QList threads; +}; + +#endif // REDDITMODEL_H diff --git a/ci/redditclient_qt5/redditwrapper.cpp b/ci/redditclient_qt5/redditwrapper.cpp new file mode 100644 index 00000000..105f670b --- /dev/null +++ b/ci/redditclient_qt5/redditwrapper.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "redditwrapper.h" + +#include +#include +#include + +const QUrl newUrl("https://oauth.reddit.com/new"); +const QUrl hotUrl("https://oauth.reddit.com/hot"); +const QUrl liveThreadsUrl("https://oauth.reddit.com/live/XXXX/about.json"); + +RedditWrapper::RedditWrapper(QObject *parent) : QObject(parent) +{ + auto replyHandler = new QOAuthHttpServerReplyHandler(1337, this); + oauth2.setReplyHandler(replyHandler); + oauth2.setAuthorizationUrl(QUrl("https://www.reddit.com/api/v1/authorize")); + oauth2.setAccessTokenUrl(QUrl("https://www.reddit.com/api/v1/access_token")); + oauth2.setScope("identity read"); + + connect(&oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=]( + QAbstractOAuth::Status status) { + if (status == QAbstractOAuth::Status::Granted) + emit authenticated(); + }); + oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap *parameters) { + if (stage == QAbstractOAuth::Stage::RequestingAuthorization && isPermanent()) + parameters->insert("duration", "permanent"); + }); + connect(&oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, + &QDesktopServices::openUrl); +} + +RedditWrapper::RedditWrapper(const QString &clientIdentifier, QObject *parent) : + RedditWrapper(parent) +{ + oauth2.setClientIdentifier(clientIdentifier); +} + +QNetworkReply *RedditWrapper::requestHotThreads() +{ + qDebug() << "Getting hot threads..."; + return oauth2.get(hotUrl); +} + +bool RedditWrapper::isPermanent() const +{ + return permanent; +} + +void RedditWrapper::setPermanent(bool value) +{ + permanent = value; +} + +void RedditWrapper::grant() +{ + oauth2.grant(); +} + +void RedditWrapper::subscribeToLiveUpdates() +{ + qDebug() << "Susbscribing..."; + QNetworkReply *reply = oauth2.get(liveThreadsUrl); + connect(reply, &QNetworkReply::finished, [=]() { + reply->deleteLater(); + if (reply->error() != QNetworkReply::NoError) { + qCritical() << "Reddit error:" << reply->errorString(); + return; + } + + const auto json = reply->readAll(); + + const auto document = QJsonDocument::fromJson(json); + Q_ASSERT(document.isObject()); + const auto rootObject = document.object(); + const auto dataValue = rootObject.value("data"); + Q_ASSERT(dataValue.isObject()); + const auto dataObject = dataValue.toObject(); + const auto websocketUrlValue = dataObject.value("websocket_url"); + Q_ASSERT(websocketUrlValue.isString() && websocketUrlValue.toString().size()); + const QUrl websocketUrl(websocketUrlValue.toString()); + emit subscribed(websocketUrl); + }); +} diff --git a/ci/redditclient_qt5/redditwrapper.h b/ci/redditclient_qt5/redditwrapper.h new file mode 100644 index 00000000..4b86ba97 --- /dev/null +++ b/ci/redditclient_qt5/redditwrapper.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Network Auth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef REDDITWRAPPER_H +#define REDDITWRAPPER_H + +#include +#include + +#include + +class RedditWrapper : public QObject +{ + Q_OBJECT + +public: + RedditWrapper(QObject *parent = nullptr); + RedditWrapper(const QString &clientIdentifier, QObject *parent = nullptr); + + QNetworkReply *requestHotThreads(); + + bool isPermanent() const; + void setPermanent(bool value); + +public slots: + void grant(); + void subscribeToLiveUpdates(); + +signals: + void authenticated(); + void subscribed(const QUrl &url); + +private: + QOAuth2AuthorizationCodeFlow oauth2; + bool permanent = false; +}; + +#endif // REDDITWRAPPER_H diff --git a/ci/steps.yml b/ci/steps.yml index ca09a461..799c5729 100644 --- a/ci/steps.yml +++ b/ci/steps.yml @@ -167,10 +167,8 @@ steps: unzip android-ndk-r21e-darwin-x86_64.zip fi export ANDROID_NDK_ROOT=$(Build.SourcesDirectory)/android-ndk-r21e - mkdir $(Build.BinariesDirectory)/tests - (cd $(Build.BinariesDirectory)/tests; 7zr x $(Build.SourcesDirectory)/ci/accelbubble.7z) export PATH=$(QT_BINDIR):$PATH - qmake $(Build.BinariesDirectory)/tests/accelbubble + qmake $(Build.SourcesDirectory)/ci/accelbubble make condition: | and( @@ -188,10 +186,8 @@ steps: # for iOS target - bash: | set -ex - mkdir $(Build.BinariesDirectory)/tests - (cd $(Build.BinariesDirectory)/tests; 7zr x $(Build.SourcesDirectory)/ci/accelbubble.7z) export PATH=$(QT_BINDIR):$PATH - qmake $(Build.BinariesDirectory)/tests/accelbubble + qmake $(Build.SourcesDirectory)/ci/accelbubble make condition: | and(eq(variables['TARGET'], 'ios'), @@ -250,10 +246,8 @@ steps: # When no modules - script: | set -ex - mkdir $(Build.BinariesDirectory)/tests - (cd $(Build.BinariesDirectory)/tests; 7zr x $(Build.SourcesDirectory)/ci/helloworld.7z) export PATH=$(QT_BINDIR):$PATH - qmake $(Build.BinariesDirectory)/tests/helloworld + qmake $(Build.SourcesDirectory)/ci/helloworld make condition: | and( @@ -278,11 +272,7 @@ steps: Import-VisualStudioVars -VisualStudioVersion $(VSVER) -Architecture $(ARCHITECTURE) $env:Path += ";$(WIN_QT_BINDIR)" - mkdir $(Build.BinariesDirectory)\tests - cd $(Build.BinariesDirectory)\tests - 7z x $(Build.SourcesDirectory)\ci\helloworld.7z - cd .. - qmake $(Build.BinariesDirectory)\tests\helloworld + qmake $(Build.SourcesDirectory)\ci\helloworld jom } elseif ( $env:TOOLCHAIN -eq 'MINGW' ) { python -m aqt install-tool $(if (($QT_BASE_MIRROR + "") -ne "") { "-b $QT_BASE_MIRROR" } else {""}) ` @@ -294,11 +284,7 @@ steps: } Set-Item -Path Env:Path -Value ("$(Build.BinariesDirectory)\Qt\Tools\$(MINGW_FOLDER)\bin;$(WIN_QT_BINDIR);" + $Env:Path) Write-Host "Path == " + $env:Path - mkdir $(Build.BinariesDirectory)\tests - cd $(Build.BinariesDirectory)\tests - 7z x $(Build.SourcesDirectory)\ci\helloworld.7z - cd .. - qmake $(Build.BinariesDirectory)\tests\helloworld + qmake $(Build.SourcesDirectory)\ci\helloworld mingw32-make } condition: | @@ -315,11 +301,8 @@ steps: # When --archives non-empty - script: | set -ex - rm -rf $(Build.BinariesDirectory)/tests - mkdir $(Build.BinariesDirectory)/tests - (cd $(Build.BinariesDirectory)/tests && 7zr x $(Build.SourcesDirectory)/ci/helloworld_qttools.7z) export PATH=$(QT_BINDIR):$PATH - qmake -d $(Build.BinariesDirectory)/tests/helloworld_qttools + qmake $(Build.SourcesDirectory)/ci/helloworld_qttools make condition: | and( @@ -343,11 +326,7 @@ steps: Import-VisualStudioVars -VisualStudioVersion $(VSVER) -Architecture $(ARCHITECTURE) $env:Path += ";$(WIN_QT_BINDIR)" - try { rm -r -fo $(Build.BinariesDirectory)\tests } catch { $Error.Clear() } - mkdir $(Build.BinariesDirectory)\tests - cd $(Build.BinariesDirectory)\tests - 7z x $(Build.SourcesDirectory)\ci\helloworld_qttools.7z - qmake -d $(Build.BinariesDirectory)\tests\helloworld_qttools + qmake $(Build.SourcesDirectory)\ci\helloworld_qttools nmake } elseif ( $env:TOOLCHAIN -eq 'MINGW' ) { Set-Item -Path Env:Path -Value ("$(Build.BinariesDirectory)\Qt\Tools\$(MINGW_FOLDER)\bin;$(WIN_QT_BINDIR);" + $Env:Path) @@ -362,10 +341,7 @@ steps: } } try { rm -r -fo $(Build.BinariesDirectory)\tests } catch { $Error.Clear() } - mkdir $(Build.BinariesDirectory)\tests - cd $(Build.BinariesDirectory)\tests - 7z x $(Build.SourcesDirectory)\ci\helloworld_qttools.7z - qmake -d $(Build.BinariesDirectory)\tests\helloworld_qttools + qmake $(Build.SourcesDirectory)\ci\helloworld_qttools mingw32-make } condition: | @@ -389,11 +365,7 @@ steps: Import-VisualStudioVars -VisualStudioVersion $(VSVER) -Architecture $(ARCHITECTURE) $env:Path += ";$(WIN_QT_BINDIR)" echo Add Qt to PATH: $env:PATH - mkdir $(Build.BinariesDirectory)/tests - cd $(Build.BinariesDirectory)/tests - 7z x $(Build.SourcesDirectory)/ci/redditclient.7z - cd .. - qmake $(Build.BinariesDirectory)\tests\redditclient + qmake $(Build.SourcesDirectory)/ci/redditclient nmake condition: | and( @@ -405,13 +377,12 @@ steps: displayName: build test with qmake with MSVC with extra module - bash: | set -ex - mkdir $(Build.BinariesDirectory)/tests - (cd $(Build.BinariesDirectory)/tests; 7zr x $(Build.SourcesDirectory)/ci/redditclient.7z) + export PATH=$(QT_BINDIR):$PATH if [[ "6" -eq "${QT_VERSION:0:1}" ]]; then - (cd $(Build.BinariesDirectory)/tests/redditclient;patch -i redditclient_6.diff -p1) + qmake $(Build.SourcesDirectory)/ci/redditclient + else + qmake $(Build.SourcesDirectory)/ci/redditclient_qt5 fi - export PATH=$(QT_BINDIR):$PATH - qmake $(Build.BinariesDirectory)/tests/redditclient make condition: | and( @@ -434,15 +405,12 @@ steps: ./emsdk install $(EMSDK_VERSION) ./emsdk activate --embedded $(EMSDK_VERSION) source $(Build.BinariesDirectory)/emsdk/emsdk_env.sh - mkdir $(Build.BinariesDirectory)/tests + export PATH=$(QT_BINDIR):$PATH if [[ $(QT_VERSION) = 6* ]]; then - OPENGLWINDOW_7Z="openglwindow_qt6.7z" + qmake $(Build.SourcesDirectory)/ci/openglwindow else - OPENGLWINDOW_7Z="openglwindow.7z" + qmake $(Build.SourcesDirectory)/ci/openglwindow_qt5 fi - (cd $(Build.BinariesDirectory)/tests; 7zr x $(Build.SourcesDirectory)/ci/$OPENGLWINDOW_7Z) - export PATH=$(QT_BINDIR):$PATH - qmake $(Build.BinariesDirectory)/tests/openglwindow make workingDirectory: $(Build.BinariesDirectory) condition: | @@ -468,13 +436,11 @@ steps: echo "Add Qt/qmake to PATH at $(WIN_QT_BINDIR):" echo "$env:Path" if ('$(QT_VERSION)' -like '6*') { - 7z x $(Build.SourcesDirectory)\ci\openglwindow_qt6.7z echo "Inlined qmake.bat command is: $(WIN_AUTODESK_QT_BINDIR)\qmake -qtconf $(WIN_QT_BINDIR)\target_qt.conf $(Build.BinariesDirectory)\tests\openglwindow" - $(WIN_AUTODESK_QT_BINDIR)\qmake.exe -qtconf "$(WIN_QT_BINDIR)\target_qt.conf" $(Build.BinariesDirectory)\tests\openglwindow + $(WIN_AUTODESK_QT_BINDIR)\qmake.exe -qtconf "$(WIN_QT_BINDIR)\target_qt.conf" $(Build.SourcesDirectory)\ci\openglwindow } else { - 7z x $(Build.SourcesDirectory)\ci\openglwindow.7z echo "Qt5: run qmake.exe" - qmake $(Build.BinariesDirectory)\tests\openglwindow + qmake $(Build.SourcesDirectory)\ci\openglwindow_qt5 } if ($false -eq $?) { Write-Error "qmake failed."