GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
community-news.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 <QDesktopWidget>
31#include <QLayout>
32#include <QTextBrowser>
33#include <QThread>
34
35#include "community-news.h"
36#include "gui-preferences-nr.h"
37#include "news-reader.h"
38#include "octave-qobject.h"
39
40namespace octave
41{
43 : QWidget (nullptr), m_browser (nullptr)
44 {
45 construct (oct_qobj, "https://octave.org", "community-news.html", serial);
46 }
47
49 const QString& base_url, const QString& page,
50 int serial)
51 : QWidget (parent), m_browser (nullptr)
52 {
53 construct (oct_qobj, base_url, page, serial);
54 }
55
57 const QString& base_url, const QString& page,
58 int serial)
59 {
60 m_browser = new QTextBrowser (this);
61
62 m_browser->setObjectName ("OctaveNews");
63 m_browser->setOpenExternalLinks (true);
64
65 QVBoxLayout *vlayout = new QVBoxLayout;
66
67 vlayout->addWidget (m_browser);
68
69 setLayout (vlayout);
70 setWindowTitle (tr ("Octave Community News"));
71
72 int win_x, win_y;
73 get_screen_geometry (win_x, win_y);
74
75 resize (win_x/2, win_y/2);
76 move ((win_x - width ())/2, (win_y - height ())/2);
77
78 resource_manager& rmgr = oct_qobj.get_resource_manager ();
80
81 // FIXME: should be configurable... See also the icon for the
82 // release notes window.
83 QString icon = ":/actions/icons/logo.png";
84 setWindowIcon (QIcon (icon));
85
86 // FIXME: This is a news reader preference, so shouldn't it be used
87 // in the news_reader object?
88
89 bool connect_to_web
90 = (settings
91 ? settings->value (nr_allow_connection).toBool ()
92 : true);
93
94 QThread *worker_thread = new QThread;
95
96 news_reader *reader = new news_reader (oct_qobj, base_url, page,
97 serial, connect_to_web);
98
99 reader->moveToThread (worker_thread);
100
101 connect (reader, &news_reader::display_news_signal,
103
104 connect (worker_thread, &QThread::started,
105 reader, &news_reader::process);
106
107 connect (reader, &news_reader::finished, worker_thread, &QThread::quit);
108
109 connect (reader, &news_reader::finished, reader, &news_reader::deleteLater);
110
111 connect (worker_thread, &QThread::finished,
112 worker_thread, &QThread::deleteLater);
113
114 worker_thread->start ();
115 }
116
117 void community_news::set_news (const QString& news)
118 {
119 m_browser->setHtml (news);
120 }
121
123 {
124 if (! isVisible ())
125 show ();
126 else if (isMinimized ())
127 showNormal ();
128
129 raise ();
130 activateWindow ();
131 }
132
133 // FIXME: This function is duplicated in main_window.cc. Maybe it
134 // should be a utility function?
135
136 void community_news::get_screen_geometry (int& width, int& height)
137 {
138 QRect screen_geometry = QApplication::desktop ()->availableGeometry (this);
139
140 width = screen_geometry.width ();
141 height = screen_geometry.height ();
142 }
143}
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
QTextBrowser * m_browser
void get_screen_geometry(int &width, int &height)
void set_news(const QString &news)
community_news(base_qobject &oct_qobj, int serial)
void construct(base_qobject &oct_qobj, const QString &base_url, const QString &page, int serial)
void display_news_signal(const QString &news)
void process(void)
Definition: news-reader.cc:44
gui_settings * get_settings(void) const
const gui_pref nr_allow_connection("news/allow_web_connection", QVariant(false))