GNU Octave 7.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-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 <QFile>
32#include <QIcon>
33#include <QLayout>
34#include <QTextBrowser>
35#include <QTextStream>
36#include <QThread>
37
38#include "release-notes.h"
39#include "gui-preferences-nr.h"
40#include "news-reader.h"
41#include "octave-qobject.h"
42
43#include "defaults.h"
44
45namespace octave
46{
48 : QWidget (nullptr), m_browser (nullptr),
49 m_release_notes_icon (":/actions/icons/logo.png")
50 {
51#if 0
52 // The following code was in main-window.cc. How should that be
53 // handled here?
54 if (dw_icon_set_names[icon_set_found].name != "NONE")
55 m_release_notes_icon = dw_icon_set_names[icon_set_found].path
56 + "ReleaseWidget.png";
57 else
58 m_release_notes_icon = ":/actions/icons/logo.png";
59#endif
60
61 std::string news_file = config::oct_etc_dir () + "/NEWS";
62
63 QString news;
64
65 QFile *file = new QFile (QString::fromStdString (news_file));
66 if (file->open (QFile::ReadOnly))
67 {
68 QTextStream *stream = new QTextStream (file);
69 news = stream->readAll ();
70 if (! news.isEmpty ())
71 {
72 // Convert '<', '>' which would be interpreted as HTML
73 news.replace ("<", "&lt;");
74 news.replace (">", "&gt;");
75 // Add HTML tags for pre-formatted text
76 news.prepend ("<pre>");
77 news.append ("</pre>");
78 }
79 else
80 news = (tr ("The release notes file '%1' is empty.")
81 . arg (QString::fromStdString (news_file)));
82 }
83 else
84 news = (tr ("The release notes file '%1' cannot be read.")
85 . arg (QString::fromStdString (news_file)));
86
87
88 m_browser = new QTextBrowser (this);
89 m_browser->setText (news);
90
91 QVBoxLayout *vlayout = new QVBoxLayout;
92 vlayout->addWidget (m_browser);
93
94 setLayout (vlayout);
95 setWindowTitle (tr ("Octave Release Notes"));
96
97 m_browser->document ()->adjustSize ();
98
99 int win_x, win_y;
100 get_screen_geometry (win_x, win_y);
101
102 resize (win_x*2/5, win_y*2/3);
103 move (20, 20); // move to the top left corner
104 }
105
107 {
108 if (! isVisible ())
109 show ();
110 else if (isMinimized ())
111 showNormal ();
112
113 setWindowIcon (QIcon (m_release_notes_icon));
114
115 raise ();
116 activateWindow ();
117 }
118
119 // FIXME: This function is duplicated in main_window.cc. Maybe it
120 // should be a utility function?
121
122 void release_notes::get_screen_geometry (int& width, int& height)
123 {
124 QRect screen_geometry = QApplication::desktop ()->availableGeometry (this);
125
126 width = screen_geometry.width ();
127 height = screen_geometry.height ();
128 }
129}
void get_screen_geometry(int &width, int &height)
QTextBrowser * m_browser
Definition: release-notes.h:56
const struct @23 dw_icon_set_names[]
QString name
std::string oct_etc_dir(void)
Definition: defaults.cc:339
QString fromStdString(const std::string &s)