GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
news-reader.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2011-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <string>
31
32#include <QDateTime>
33#include <QString>
34
35#include "news-reader.h"
36#include "octave-qobject.h"
37#include "gui-preferences-nr.h"
38
39#include "url-transfer.h"
40#include "version.h"
41
42namespace octave
43{
45 {
46 QString html_text;
47
49 {
50 // Run this part in a separate thread so Octave can continue to
51 // run while we wait for the page to load. Then emit the signal
52 // to display it when we have the page contents.
53
54 QString url = m_base_url + '/' + m_page;
55 std::ostringstream buf;
56 url_transfer octave_dot_org (url.toStdString (), buf);
57
58 if (octave_dot_org.is_valid ())
59 {
61 octave_dot_org.http_get (param);
62
63 if (octave_dot_org.good ())
64 html_text = QString::fromStdString (buf.str ());
65 }
66
67 if (html_text.contains ("this-is-the-gnu-octave-community-news-page"))
68 {
69 if (m_serial >= 0)
70 {
73
74 if (settings)
75 {
76 settings->setValue (nr_last_time.key,
77 QDateTime::currentDateTime ());
78
79 settings->sync ();
80 }
81
82 QString tag ("community-news-page-serial=");
83
84 int b = html_text.indexOf (tag);
85
86 if (b)
87 {
88 b += tag.length ();
89
90 int e = html_text.indexOf ("\n", b);
91
92 QString tmp = html_text.mid (b, e-b);
93
94 int curr_page_serial = tmp.toInt ();
95
96 if (curr_page_serial > m_serial)
97 {
98 if (settings)
99 {
100 settings->setValue (nr_last_news.key,
101 curr_page_serial);
102
103 settings->sync ();
104 }
105 }
106 else
107 return;
108 }
109 else
110 return;
111 }
112 }
113 else
114 html_text = QString
115 (tr ("<html>\n"
116 "<body>\n"
117 "<p>\n"
118 "Octave's community news source seems to be unavailable.\n"
119 "</p>\n"
120 "<p>\n"
121 "For the latest news, please check\n"
122 "<a href=\"https://octave.org/community-news.html\">https://octave.org/community-news.html</a>\n"
123 "when you have a connection to the web (link opens in an external browser).\n"
124 "</p>\n"
125 "<p>\n"
126 "<small><em>&mdash; The Octave Developers, ") + OCTAVE_RELEASE_DATE + "</em></small>\n"
127 "</p>\n"
128 "</body>\n"
129 "</html>\n");
130 }
131 else
132 html_text = QString
133 (tr ("<html>\n"
134 "<body>\n"
135 "<p>\n"
136 "Connecting to the web to display the latest Octave Community news has been disabled.\n"
137 "</p>\n"
138 "<p>\n"
139 "For the latest news, please check\n"
140 "<a href=\"https://octave.org/community-news.html\">https://octave.org/community-news.html</a>\n"
141 "when you have a connection to the web (link opens in an external browser)\n"
142 "or enable web connections for news in Octave's network settings dialog.\n"
143 "</p>\n"
144 "<p>\n"
145 "<small><em>&mdash; The Octave Developers, ") + OCTAVE_RELEASE_DATE + "</em></small>\n"
146 "</p>\n"
147 "</body>\n"
148 "</html>\n");
149
150 emit display_news_signal (html_text);
151
152 emit finished ();
153 }
154}
resource_manager & get_resource_manager(void)
void display_news_signal(const QString &news)
void process(void)
Definition: news-reader.cc:44
base_qobject & m_octave_qobj
Definition: news-reader.h:61
gui_settings * get_settings(void) const
bool good(void) const
Definition: url-transfer.h:188
void http_get(const Array< std::string > &param)
Definition: url-transfer.h:257
bool is_valid(void) const
Definition: url-transfer.h:186
const gui_pref nr_last_news("news/last_news_item", QVariant(0))
const gui_pref nr_last_time("news/last_time_checked", QVariant(QDateTime()))
QString fromStdString(const std::string &s)
const QString key