GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
release-notes.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 <QApplication>
31 #include <QFile>
32 #include <QIcon>
33 #include <QLayout>
34 #include <QScreen>
35 #include <QTextBrowser>
36 #include <QTextStream>
37 #include <QThread>
38 
39 #include "release-notes.h"
40 #include "gui-utils.h"
41 #include "gui-preferences-dw.h"
42 #include "gui-preferences-nr.h"
43 #include "news-reader.h"
44 #include "octave-qobject.h"
45 
46 #include "defaults.h"
47 
49 
51 : QWidget (nullptr), m_browser (nullptr)
52 {
53 
54  resource_manager& rmgr = oct_qobj.get_resource_manager ();
56 
57  // The icon
58  QString icon_set = settings->value (dw_icon_set).toString ();
59  if (icon_set != "NONE")
60  m_release_notes_icon = dw_icon_set_names[icon_set]
61  + "ReleaseWidget.png";
62  else
63  m_release_notes_icon = dw_icon_set_names[icon_set];
64 
65  std::string news_file = config::oct_etc_dir () + "/NEWS";
66 
67  QString news;
68 
69  QFile *file = new QFile (QString::fromStdString (news_file));
70  if (file->open (QFile::ReadOnly))
71  {
72  QTextStream *stream = new QTextStream (file);
73  news = stream->readAll ();
74  if (! news.isEmpty ())
75  {
76  // Convert '<', '>' which would be interpreted as HTML
77  news.replace ("<", "&lt;");
78  news.replace (">", "&gt;");
79  // Add HTML tags for pre-formatted text
80  news.prepend ("<pre>");
81  news.append ("</pre>");
82  }
83  else
84  news = (tr ("The release notes file '%1' is empty.")
85  . arg (QString::fromStdString (news_file)));
86  }
87  else
88  news = (tr ("The release notes file '%1' cannot be read.")
89  . arg (QString::fromStdString (news_file)));
90 
91  m_browser = new QTextBrowser (this);
92  m_browser->setText (news);
93 
94  QVBoxLayout *vlayout = new QVBoxLayout;
95  vlayout->addWidget (m_browser);
96 
97  setLayout (vlayout);
98  setWindowTitle (tr ("Octave Release Notes"));
99 
100  m_browser->document ()->adjustSize ();
101 
102  int win_x, win_y;
103  get_screen_geometry (win_x, win_y);
104 
105  resize (win_x*2/5, win_y*2/3);
106  move (20, 20); // move to the top left corner
107 }
108 
110 {
111  if (! isVisible ())
112  show ();
113  else if (isMinimized ())
114  showNormal ();
115 
116  setWindowIcon (QIcon (m_release_notes_icon));
117 
118  raise ();
119  activateWindow ();
120 }
121 
OCTAVE_END_NAMESPACE(octave)
Base class for Octave interfaces that use Qt.
void display(void)
QString m_release_notes_icon
Definition: release-notes.h:55
gui_settings * get_settings(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string oct_etc_dir(void)
Definition: defaults.cc:339
const QHash< QString, QString > dw_icon_set_names
const gui_pref dw_icon_set("DockWidgets/widget_icon_set", QVariant("NONE"))
OCTGUI_API void get_screen_geometry(int &width, int &height)
Definition: gui-utils.cc:51
QString fromStdString(const std::string &s)