Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/welcomewidget.cpp
1 | /* Atelier KDE Printer Host for 3D Printing | 1 | /* Atelier KDE Printer Host for 3D Printing | ||
---|---|---|---|---|---|
2 | Copyright (C) <2018> | 2 | Copyright (C) <2018> | ||
3 | Author: Lays Rodrigues - lays.rodrigues@kde.org | 3 | Author: Lays Rodrigues - lays.rodrigues@kde.org | ||
4 | Chris Rizzitello - rizzitello@kde.org | ||||
4 | 5 | | |||
5 | This program is free software: you can redistribute it and/or modify | 6 | This program is free software: you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation, either version 3 of the License, or | 8 | the Free Software Foundation, either version 3 of the License, or | ||
8 | (at your option) any later version. | 9 | (at your option) any later version. | ||
9 | 10 | | |||
10 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 16 Lines | |||||
28 | #include <QScrollArea> | 29 | #include <QScrollArea> | ||
29 | #include <QStyle> | 30 | #include <QStyle> | ||
30 | #include <QTimer> | 31 | #include <QTimer> | ||
31 | #include <QToolButton> | 32 | #include <QToolButton> | ||
32 | #include <QVBoxLayout> | 33 | #include <QVBoxLayout> | ||
33 | #include "welcomewidget.h" | 34 | #include "welcomewidget.h" | ||
34 | 35 | | |||
35 | #define POSTS_LIMIT 5 | 36 | #define POSTS_LIMIT 5 | ||
36 | 37 | const QString WelcomeWidget::m_telegramLink = QStringLiteral(R"(<a href="http://t.me/KDEAtelier">)"); | |||
37 | WelcomeWidget::WelcomeWidget(QWidget *parent): QWidget(parent), m_newsFeedWidget(new QWidget) | 38 | const QString WelcomeWidget::m_documentsLink = QStringLiteral(R"(<a href="http://atelier.kde.org/documentation/atelier">)"); | ||
39 | const QString WelcomeWidget::m_linkClose = QStringLiteral("</a>"); | ||||
40 | | ||||
41 | WelcomeWidget::WelcomeWidget(QWidget *parent) | ||||
42 | : QWidget(parent) | ||||
43 | , m_newsFeedWidget(new QWidget(this)) | ||||
38 | { | 44 | { | ||
39 | QFont appFont = font(); | 45 | QFont appFont = font(); | ||
40 | 46 | | |||
41 | auto hlayout = new QHBoxLayout; | 47 | auto hlayout = new QHBoxLayout; | ||
42 | auto layout = new QVBoxLayout; | 48 | auto layout = new QVBoxLayout; | ||
43 | auto label = new QLabel; | 49 | auto label = new QLabel(this); | ||
44 | 50 | | |||
45 | label->setText(i18n("Welcome to Atelier!")); | 51 | label->setText(i18n("Welcome to Atelier!")); | ||
46 | appFont.setPointSize(font().pointSize() + 4); | 52 | appFont.setPointSize(font().pointSize() + 4); | ||
47 | label->setFont(appFont); | 53 | label->setFont(appFont); | ||
48 | hlayout->addWidget(label); | 54 | hlayout->addWidget(label); | ||
49 | 55 | | |||
50 | label = new QLabel; | 56 | label = new QLabel(this); | ||
51 | label->setPixmap(QPixmap(":/icon/logo")); | 57 | label->setPixmap(QPixmap(":/icon/logo")); | ||
52 | label->setLayoutDirection(Qt::LayoutDirection::RightToLeft); | 58 | label->setLayoutDirection(Qt::LayoutDirection::RightToLeft); | ||
53 | hlayout->addWidget(label); | 59 | hlayout->addWidget(label); | ||
54 | layout->addItem(hlayout); | 60 | layout->addItem(hlayout); | ||
55 | 61 | | |||
56 | auto line = new QFrame; | 62 | auto line = new QFrame(this); | ||
57 | line->setFrameShape(QFrame::HLine); | 63 | line->setFrameShape(QFrame::HLine); | ||
58 | layout->addWidget(line); | 64 | layout->addWidget(line); | ||
59 | 65 | | |||
60 | appFont.setPointSize(font().pointSize() + 2); | 66 | appFont.setPointSize(font().pointSize() + 2); | ||
61 | label = new QLabel(i18n("Quick Connect Guide")); | 67 | label = new QLabel(i18n("Quick Connect Guide"), this); | ||
62 | label->setFont(appFont); | 68 | label->setFont(appFont); | ||
63 | layout->addWidget(label); | 69 | layout->addWidget(label); | ||
64 | 70 | | |||
65 | for (const QString &sentence : { | 71 | for (const QString &sentence : { | ||
66 | i18n("1 - Create a Profile."), i18n("2 - Select the device."), i18n("3 - Select the profile and connect.") | 72 | i18n("1 - Create a Profile."), i18n("2 - Select the device."), i18n("3 - Select the profile and connect.") | ||
67 | }) { | 73 | }) { | ||
68 | label = new QLabel(sentence); | 74 | label = new QLabel(sentence, this); | ||
69 | layout->addWidget(label); | 75 | layout->addWidget(label); | ||
70 | } | 76 | } | ||
71 | 77 | | |||
72 | label = new QLabel(i18n("Having a connection problem?")); | 78 | label = new QLabel(i18n("Having a connection problem?"), this); | ||
73 | label->setFont(appFont); | 79 | label->setFont(appFont); | ||
74 | layout->addWidget(label); | 80 | layout->addWidget(label); | ||
75 | 81 | | |||
76 | label = new QLabel(i18n("See the info section of the Log for common problems.")); | 82 | label = new QLabel(i18n("See the info section of the Log for common problems."), this); | ||
77 | layout->addWidget(label); | 83 | layout->addWidget(label); | ||
78 | 84 | | |||
79 | label = new QLabel(i18n("Check our <a href=\"http://atelier.kde.org/documentation/atelier\">Atelier Docs</a> for more information.")); | 85 | label = new QLabel(i18n("Check our %1Atelier Docs%2 for more information.", m_documentsLink, m_linkClose), this); | ||
80 | label->setOpenExternalLinks(true); | 86 | label->setOpenExternalLinks(true); | ||
81 | layout->addWidget(label); | 87 | layout->addWidget(label); | ||
82 | 88 | | |||
83 | label = new QLabel(i18n("Check our last news!")); | 89 | label = new QLabel(i18n("Atelier news!"), this); | ||
84 | label->setFont(appFont); | 90 | label->setFont(appFont); | ||
85 | layout->addWidget(label); | 91 | layout->addWidget(label); | ||
86 | retrieveRssFeed(); | 92 | retrieveRssFeed(); | ||
87 | layout->addWidget(m_newsFeedWidget); | 93 | layout->addWidget(m_newsFeedWidget); | ||
88 | 94 | | |||
89 | label = new QLabel(i18n("Get Involved")); | 95 | label = new QLabel(i18n("Get Involved"), this); | ||
90 | label->setFont(appFont); | 96 | label->setFont(appFont); | ||
91 | layout->addWidget(label); | 97 | layout->addWidget(label); | ||
92 | 98 | | |||
93 | label = new QLabel(QString("<a href=\"http://t.me/KDEAtelier\">") + i18n("Join our Telegram Group!") + QString("</a>")); | 99 | label = new QLabel(i18n("Join our %1Telegram Group%2!", m_telegramLink, m_linkClose), this); | ||
94 | label->setOpenExternalLinks(true); | 100 | label->setOpenExternalLinks(true); | ||
95 | layout->addWidget(label); | 101 | layout->addWidget(label); | ||
96 | 102 | | |||
97 | label = new QLabel(i18n("You can also find us on Freenode IRC #kde-atelier")); | 103 | label = new QLabel(i18n("You can also find us on Freenode IRC #kde-atelier"), this); | ||
98 | layout->addWidget(label); | 104 | layout->addWidget(label); | ||
99 | 105 | | |||
100 | layout->addStretch(); | 106 | layout->addStretch(); | ||
101 | 107 | | |||
102 | auto infoWidget = new QWidget(); | 108 | auto infoWidget = new QWidget(this); | ||
103 | infoWidget->setLayout(layout); | 109 | infoWidget->setLayout(layout); | ||
104 | 110 | | |||
105 | auto scrollArea = new QScrollArea(this); | 111 | auto scrollArea = new QScrollArea(this); | ||
106 | scrollArea->setWidget(infoWidget); | 112 | scrollArea->setWidget(infoWidget); | ||
107 | scrollArea->setWidgetResizable(true); | 113 | scrollArea->setWidgetResizable(true); | ||
108 | 114 | | |||
109 | layout = new QVBoxLayout; | 115 | layout = new QVBoxLayout; | ||
110 | layout->addWidget(scrollArea); | 116 | layout->addWidget(scrollArea); | ||
111 | setLayout(layout); | 117 | setLayout(layout); | ||
112 | } | 118 | } | ||
113 | 119 | | |||
114 | WelcomeWidget::~WelcomeWidget() | | |||
115 | { | | |||
116 | | ||||
117 | } | | |||
118 | | ||||
119 | void WelcomeWidget::retrieveRssFeed() | 120 | void WelcomeWidget::retrieveRssFeed() | ||
120 | { | 121 | { | ||
121 | auto manager = new QNetworkAccessManager(); | 122 | auto manager = new QNetworkAccessManager(this); | ||
122 | for (const QUrl &url : { | 123 | for (const QUrl &url : { | ||
123 | QUrl("https://rizzitello.wordpress.com/category/atelier/feed/"), | 124 | QUrl("https://rizzitello.wordpress.com/category/atelier/feed/"), | ||
124 | QUrl("https://laysrodriguesdev.wordpress.com/category/atelier/feed/") | 125 | QUrl("https://laysrodriguesdev.wordpress.com/category/atelier/feed/") | ||
125 | }) { | 126 | }) { | ||
126 | QNetworkRequest request(url); | 127 | QNetworkRequest request(url); | ||
127 | request.setRawHeader("User-Agent", "Atelier 1.0"); | 128 | request.setRawHeader("User-Agent", "Atelier 1.0"); | ||
128 | manager->get(request); | 129 | manager->get(request); | ||
129 | connect(manager, &QNetworkAccessManager::finished, this, [&](QNetworkReply * reply) { | 130 | connect(manager, &QNetworkAccessManager::finished, this, [&](QNetworkReply * reply) { | ||
130 | if (reply->error()) { | 131 | if (reply->error()) { | ||
131 | return; | 132 | return; | ||
132 | } else { | 133 | } | ||
133 | QDomDocument document; | 134 | QDomDocument document; | ||
134 | if (document.setContent(reply->readAll())) { | 135 | if (document.setContent(reply->readAll())) { | ||
135 | parseRss(document); | 136 | parseRss(document); | ||
136 | } | 137 | } | ||
137 | } | | |||
138 | }); | 138 | }); | ||
139 | } | 139 | } | ||
140 | } | 140 | } | ||
141 | 141 | | |||
142 | void WelcomeWidget::parseRss(const QDomDocument &document) | 142 | void WelcomeWidget::parseRss(const QDomDocument &document) | ||
143 | { | 143 | { | ||
144 | auto itemList = document.elementsByTagName("item"); | 144 | auto itemList = document.elementsByTagName("item"); | ||
145 | QRegularExpression dateRegex("(?<date>\\d{2} \\w{3} \\d{4})"); | 145 | QRegularExpression dateRegex(QStringLiteral(R"((?<date>\d{2} \w{3} \d{4}))")); | ||
146 | 146 | | |||
147 | for (int i = 0; i < itemList.count(); ++i) { | 147 | for (int i = 0; i < itemList.count(); ++i) { | ||
148 | auto node = itemList.at(i); | 148 | auto node = itemList.at(i); | ||
149 | if (node.isElement()) { | 149 | if (node.isElement()) { | ||
150 | //Sample of date format Wed, 24 May 2017 13:46:07 +0000 | 150 | //Sample of date format Wed, 24 May 2017 13:46:07 +0000 | ||
151 | QString pDate = node.firstChildElement("pubDate").toElement().text(); | 151 | QString pDate = node.firstChildElement("pubDate").toElement().text(); | ||
152 | QRegularExpressionMatch match = dateRegex.match(pDate); | 152 | QRegularExpressionMatch match = dateRegex.match(pDate); | ||
153 | if (match.hasMatch()) { | 153 | if (match.hasMatch()) { | ||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |