GNU Octave  8.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-2023 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 <QLayout>
31 #include <QTextBrowser>
32 #include <QThread>
33 
34 #include "community-news.h"
35 #include "gui-utils.h"
36 #include "gui-preferences-dw.h"
37 #include "gui-preferences-nr.h"
38 #include "news-reader.h"
39 #include "octave-qobject.h"
40 
42 
43 community_news::community_news (base_qobject& oct_qobj, int serial)
44 : QWidget (nullptr), m_browser (nullptr)
45 {
46  construct (oct_qobj, "https://octave.org", "community-news.html", serial);
47 }
48 
50  const QString& base_url, const QString& page,
51  int serial)
52  : QWidget (parent), m_browser (nullptr)
53 {
54  construct (oct_qobj, base_url, page, serial);
55 }
56 
58  const QString& base_url, const QString& page,
59  int serial)
60 {
61  m_browser = new QTextBrowser (this);
62 
63  m_browser->setObjectName ("OctaveNews");
64  m_browser->setOpenExternalLinks (true);
65 
66  QVBoxLayout *vlayout = new QVBoxLayout;
67 
68  vlayout->addWidget (m_browser);
69 
70  setLayout (vlayout);
71  setWindowTitle (tr ("Octave Community News"));
72 
73  int win_x, win_y;
74  get_screen_geometry (win_x, win_y);
75 
76  resize (win_x/2, win_y/2);
77  move ((win_x - width ())/2, (win_y - height ())/2);
78 
79  resource_manager& rmgr = oct_qobj.get_resource_manager ();
81 
82  QString icon;
83  QString icon_set = settings->value (dw_icon_set).toString ();
84  if (icon_set != "NONE")
85  // No extra icon for Community news, take the one of the release notes
86  icon = dw_icon_set_names[icon_set] + "ReleaseWidget.png";
87  else
88  icon = dw_icon_set_names[icon_set];
89 
90  setWindowIcon (QIcon (icon));
91 
92  // FIXME: This is a news reader preference, so shouldn't it be used
93  // in the news_reader object?
94 
95  bool connect_to_web
96  = (settings
97  ? settings->value (nr_allow_connection).toBool ()
98  : true);
99 
100  QThread *worker_thread = new QThread;
101 
102  news_reader *reader = new news_reader (oct_qobj, base_url, page,
103  serial, connect_to_web);
104 
105  reader->moveToThread (worker_thread);
106 
107  connect (reader, &news_reader::display_news_signal,
108  this, &community_news::set_news);
109 
110  connect (worker_thread, &QThread::started,
111  reader, &news_reader::process);
112 
113  connect (reader, &news_reader::finished, worker_thread, &QThread::quit);
114 
115  connect (reader, &news_reader::finished, reader, &news_reader::deleteLater);
116 
117  connect (worker_thread, &QThread::finished,
118  worker_thread, &QThread::deleteLater);
119 
120  worker_thread->start ();
121 }
122 
123 void community_news::set_news (const QString& news)
124 {
125  m_browser->setHtml (news);
126 }
127 
129 {
130  if (! isVisible ())
131  show ();
132  else if (isMinimized ())
133  showNormal ();
134 
135  raise ();
136  activateWindow ();
137 }
138 
OCTAVE_END_NAMESPACE(octave)
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
void display(void)
void set_news(const QString &news)
QTextBrowser * m_browser
community_news(base_qobject &oct_qobj, int serial)
void construct(base_qobject &oct_qobj, const QString &base_url, const QString &page, int serial)
void process(void)
Definition: news-reader.cc:44
void display_news_signal(const QString &news)
void finished(void)
gui_settings * get_settings(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
const QHash< QString, QString > dw_icon_set_names
const gui_pref dw_icon_set("DockWidgets/widget_icon_set", QVariant("NONE"))
const gui_pref nr_allow_connection("news/allow_web_connection", QVariant(false))
OCTGUI_API void get_screen_geometry(int &width, int &height)
Definition: gui-utils.cc:51