Mercurial > octave
annotate libgui/src/community-news.cc @ 31647:431f80aba37a
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Dec 2022 15:37:43 -0500 |
parents | ca7d58406f82 c6d54dd31a7e |
children | deb553ac2c54 |
rev | line source |
---|---|
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
a946d742fb97
allow community news 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:
29835
diff
changeset
|
3 // Copyright (C) 2011-2022 The Octave Project Developers |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 // |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 // |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 // This file is part of Octave. |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 // |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 // (at your option) any later version. |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 // |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 // GNU General Public License for more details. |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 // |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news 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 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 // |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 # include "config.h" |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #endif |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include <QLayout> |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include <QTextBrowser> |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include <QThread> |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include "community-news.h" |
30690
e2c8c852399e
replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
35 #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
|
36 #include "gui-preferences-dw.h" |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "gui-preferences-nr.h" |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
38 #include "gui-settings.h" |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include "news-reader.h" |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
41 OCTAVE_BEGIN_NAMESPACE(octave) |
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
42 |
31639
ca7d58406f82
eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
43 community_news::community_news (int serial) |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 : QWidget (nullptr), m_browser (nullptr) |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 { |
31639
ca7d58406f82
eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
46 construct ("https://octave.org", "community-news.html", serial); |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 } |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 |
31639
ca7d58406f82
eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
49 community_news::community_news (QWidget *parent, const QString& base_url, |
ca7d58406f82
eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
50 const QString& page, int serial) |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 : QWidget (parent), m_browser (nullptr) |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 { |
31639
ca7d58406f82
eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
53 construct (base_url, page, serial); |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 } |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 |
31639
ca7d58406f82
eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
56 void community_news::construct (const QString& base_url, const QString& page, |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 int serial) |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 { |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 m_browser = new QTextBrowser (this); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 m_browser->setObjectName ("OctaveNews"); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 m_browser->setOpenExternalLinks (true); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 QVBoxLayout *vlayout = new QVBoxLayout; |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 vlayout->addWidget (m_browser); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 setLayout (vlayout); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 setWindowTitle (tr ("Octave Community News")); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 int win_x, win_y; |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 get_screen_geometry (win_x, win_y); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 resize (win_x/2, win_y/2); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 move ((win_x - width ())/2, (win_y - height ())/2); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
77 gui_settings settings; |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 |
30964
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
79 QString icon; |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
80 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
|
81 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
|
82 // No extra icon for Community news, take the one of the release notes |
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
83 icon = dw_icon_set_names[icon_set] + "ReleaseWidget.png"; |
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
84 else |
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
85 icon = dw_icon_set_names[icon_set]; |
04601f6c47f4
fix broken icon path after new icon structure in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30690
diff
changeset
|
86 |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 setWindowIcon (QIcon (icon)); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 // FIXME: This is a news reader preference, so shouldn't it be used |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 // in the news_reader object? |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
92 bool connect_to_web = settings.value (nr_allow_connection).toBool (); |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 QThread *worker_thread = new QThread; |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 |
31639
ca7d58406f82
eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
96 news_reader *reader |
ca7d58406f82
eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents:
31619
diff
changeset
|
97 = new news_reader (base_url, page, serial, connect_to_web); |
29835
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 reader->moveToThread (worker_thread); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 connect (reader, &news_reader::display_news_signal, |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 this, &community_news::set_news); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 connect (worker_thread, &QThread::started, |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 reader, &news_reader::process); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 connect (reader, &news_reader::finished, worker_thread, &QThread::quit); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 connect (reader, &news_reader::finished, reader, &news_reader::deleteLater); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 connect (worker_thread, &QThread::finished, |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 worker_thread, &QThread::deleteLater); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 worker_thread->start (); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 } |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 void community_news::set_news (const QString& news) |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 { |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 m_browser->setHtml (news); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 } |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 void community_news::display (void) |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 { |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 if (! isVisible ()) |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 show (); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 else if (isMinimized ()) |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 showNormal (); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 raise (); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 activateWindow (); |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 } |
a946d742fb97
allow community news window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
30964
diff
changeset
|
133 OCTAVE_END_NAMESPACE(octave) |