annotate libgui/src/release-notes.cc @ 30964:04601f6c47f4

fix broken icon path after new icon structure in GUI * community-news.cc: use window icon configured in the preferences * documentation-dock-widget.cc (documentation_dock_widget) * files-dock-widget.cc (files_dock_widget) * history-dock-widget.cc (history_dock_widget) * terminal-dock-widget.cc (terminal_dock_widget) * variable-editor.cc (variable_editor) * workspace-view.cc (workspace_view) do not set window icon here as it is set in the main window * gui-preferences-dw.h: organize dw_icon_set_names in a hash * file-editor.cc (notice_settings): fix path to tab close icon on mac * find-dialog.cc (find_dialog): do not set window icon here, it is already set by the editor * main-window.cc (notice_settings): set dok widget icons using the new hash structure of available icon sets (construct): use global const settings instead of literal string for main window icon * octave-qobject.cc (release_notes_widget): pass base qobject to the release note constructor * release-notes.cc (release_notes): get qbase object as argument, get desired window icon from settings * release-notes.h: constructor with base object as argument * variable-editor.cc (toplevel_change): use icon path from const preferences instead of literal strings * welcome-wizard.cc (make_octave_logo): use icon path from const preferences instead of literal strings
author Torsten Lilge <ttl-octave@mailbox.org>
date Sat, 23 Apr 2022 18:10:45 +0200
parents e2c8c852399e
children ad014fc78bd6 c6d54dd31a7e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "news-reader.h"
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "octave-qobject.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
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 namespace octave
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 {
30964
04601f6c47f4 fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30690
diff changeset
50 release_notes::release_notes (base_qobject& oct_qobj)
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
04601f6c47f4 fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30690
diff changeset
54 resource_manager& rmgr = oct_qobj.get_resource_manager ();
04601f6c47f4 fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30690
diff changeset
55 gui_settings *settings = rmgr.get_settings ();
04601f6c47f4 fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30690
diff changeset
56
04601f6c47f4 fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30690
diff changeset
57 // The icon
04601f6c47f4 fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30690
diff changeset
58 QString icon_set = settings->value (dw_icon_set).toString ();
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 ("<", "&lt;");
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 news.replace (">", "&gt;");
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
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 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
93 m_browser->setText (news);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 QVBoxLayout *vlayout = new QVBoxLayout;
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 vlayout->addWidget (m_browser);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 setLayout (vlayout);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 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
100
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 m_browser->document ()->adjustSize ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 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
104 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
105
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 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
107 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
108 }
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 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
111 {
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 if (! isVisible ())
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 show ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 else if (isMinimized ())
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 showNormal ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 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
118
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 raise ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 activateWindow ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 }
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 }