Mercurial > octave
annotate libgui/src/release-notes.cc @ 31649:deb553ac2c54
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Dec 2022 15:45:27 -0500 |
parents | 431f80aba37a 29d734430e5f |
children | 5f11de0e7440 |
rev | line source |
---|---|
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30398
diff
changeset
|
3 // Copyright (C) 2011-2022 The Octave Project Developers |
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 // |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 // |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 // This file is part of Octave. |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 // |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 // (at your option) any later version. |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 // |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 // GNU General Public License for more details. |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 // |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 // |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 # include "config.h" |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #endif |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
30690
e2c8c852399e
replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
30 #include <QApplication> |
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include <QFile> |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include <QIcon> |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include <QLayout> |
30690
e2c8c852399e
replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
34 #include <QScreen> |
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include <QTextBrowser> |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #include <QTextStream> |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include <QThread> |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include "release-notes.h" |
30690
e2c8c852399e
replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
40 #include "gui-utils.h" |
30964
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
41 #include "gui-preferences-dw.h" |
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 #include "gui-preferences-nr.h" |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
43 #include "gui-settings.h" |
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #include "news-reader.h" |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 #include "defaults.h" |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
48 OCTAVE_BEGIN_NAMESPACE(octave) |
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
49 |
31625
b26b768f23a4
eliminate base_qobject argument from release_notes constructor
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
50 release_notes::release_notes (void) |
30964
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
51 : QWidget (nullptr), m_browser (nullptr) |
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 { |
30964
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
53 |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
54 gui_settings settings; |
30964
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
55 |
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
56 // The icon |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
57 QString icon_set = settings.value (dw_icon_set).toString (); |
30964
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
58 |
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
59 if (icon_set != "NONE") |
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
60 m_release_notes_icon = dw_icon_set_names[icon_set] |
30398
d4d83344d653
maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29836
diff
changeset
|
61 + "ReleaseWidget.png"; |
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 else |
30964
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
63 m_release_notes_icon = dw_icon_set_names[icon_set]; |
29836
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 std::string news_file = config::oct_etc_dir () + "/NEWS"; |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 QString news; |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 QFile *file = new QFile (QString::fromStdString (news_file)); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 if (file->open (QFile::ReadOnly)) |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 { |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 QTextStream *stream = new QTextStream (file); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 news = stream->readAll (); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 if (! news.isEmpty ()) |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 { |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 // Convert '<', '>' which would be interpreted as HTML |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 news.replace ("<", "<"); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 news.replace (">", ">"); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 // Add HTML tags for pre-formatted text |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 news.prepend ("<pre>"); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 news.append ("</pre>"); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 } |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 else |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 news = (tr ("The release notes file '%1' is empty.") |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 . arg (QString::fromStdString (news_file))); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 } |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 else |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 news = (tr ("The release notes file '%1' cannot be read.") |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 . arg (QString::fromStdString (news_file))); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 m_browser = new QTextBrowser (this); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 m_browser->setText (news); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 QVBoxLayout *vlayout = new QVBoxLayout; |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 vlayout->addWidget (m_browser); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 setLayout (vlayout); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 setWindowTitle (tr ("Octave Release Notes")); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 m_browser->document ()->adjustSize (); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 int win_x, win_y; |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 get_screen_geometry (win_x, win_y); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 resize (win_x*2/5, win_y*2/3); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 move (20, 20); // move to the top left corner |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 } |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 void release_notes::display (void) |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 { |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 if (! isVisible ()) |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 show (); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 else if (isMinimized ()) |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 showNormal (); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 setWindowIcon (QIcon (m_release_notes_icon)); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 raise (); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 activateWindow (); |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 } |
56465c0739fa
allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
122 OCTAVE_END_NAMESPACE(octave) |