Mercurial > octave-nkf
annotate libgui/src/news-dock-widget.cc @ 17640:482222fe5b35
use QTextBrowser instead of QWebView to display community news
* configure.ac: Don't check for QtWebKit.
* news-dock-widget.h, news-dock-widget.cc (news_dock_widget):
Use QTextBrowser to display news.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 11 Oct 2013 20:04:49 -0400 |
parents | f5950975a172 |
children | 8680768efa8a |
rev | line source |
---|---|
17599
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 2013 John W. Eaton |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 option) any later version. |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 for more details. |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 #include <config.h> |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 #endif |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #include <iostream> |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 #include <QThread> |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include "news-dock-widget.h" |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include "Array.h" |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include "str-vec.h" |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include "url-transfer.h" |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "version.h" |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 news_dock_widget::news_dock_widget (QWidget *p) |
17640
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
40 : octave_dock_widget (p), browser (new QTextBrowser (this)) |
17599
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 { |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 setObjectName ("NewsDockWidget"); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 setWindowIcon (QIcon (":/icons/logo.png")); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 set_title (tr ("Community News")); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
17640
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
46 browser->setObjectName ("OctaveNews"); |
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
47 browser->setOpenExternalLinks (true); |
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
48 |
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
49 setWidget (browser); |
17599
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 load_news (); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 } |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 void |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 news_dock_widget::load_news (void) |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 { |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 QString base_url = "http://octave.org"; |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 QString page = "community-news.html"; |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 QThread *worker_thread = new QThread; |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 news_reader *reader = new news_reader (base_url, page); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 reader->moveToThread (worker_thread); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 |
17640
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
66 connect (reader, SIGNAL (display_news_signal (const QString&)), |
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
67 this, SLOT (display_news (const QString&))); |
17599
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 connect (worker_thread, SIGNAL (started (void)), reader, SLOT (process ())); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 connect (reader, SIGNAL (finished (void)), worker_thread, SLOT (quit ())); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 connect (reader, SIGNAL (finished (void)), reader, SLOT (deleteLater ())); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 connect (worker_thread, SIGNAL (finished (void)), |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 worker_thread, SLOT (deleteLater ())); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 worker_thread->start (); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 } |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 static const char fixed_news[] = "<html>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 <body>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 <p>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 This window will be used to inform you about Octave community events.\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 Octave may show it to you even if you've chosen hide the window by\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 default. We'll try not to bother you too much, but we do want to keep\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 you up to date with the latest information about important bug fixes,\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 new releases, or any other news that all Octave users should be aware of.\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 </p>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 <p>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 Currently, Octave's community news source seems to be unavailable.\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 For the latest news, please check\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 <a href=\"http://octave.org/community-news.html\">http://octave.org/community-news.html</a>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 when you have a connection to the web.\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 </p>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 <p>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 <small><em>— The Octave Developers, " OCTAVE_RELEASE_DATE "</em></small>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 </body>\n\ |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 </html>\n"; |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 void |
17640
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
102 news_dock_widget::display_news (const QString& news) |
17599
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 { |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 if (news.contains ("this-is-the-gnu-octave-community-news-page")) |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 { |
17640
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
106 browser->setHtml (news); |
17599
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 if (news.contains ("critical-news-event") && ! isVisible ()) |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 setVisible (true); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 } |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 else |
17640
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
112 browser->setHtml (fixed_news); |
17599
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 } |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 void |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 news_reader::process (void) |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 { |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 // Run this part in a separate thread so Octave can continue to run |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 // while we wait for the page to load. Then emit the signal to |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 // display it when we have the page contents. |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 QString url = base_url + "/" + page; |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 std::ostringstream buf; |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 url_transfer octave_dot_org (url.toStdString (), buf); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 Array<std::string> param; |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 octave_dot_org.http_get (param); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 QString html_text; |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 if (octave_dot_org.good ()) |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 html_text = QString::fromStdString (buf.str ()); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 |
17640
482222fe5b35
use QTextBrowser instead of QWebView to display community news
John W. Eaton <jwe@octave.org>
parents:
17599
diff
changeset
|
134 emit display_news_signal (html_text); |
17599
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 emit finished (); |
f5950975a172
community news dock widget and other user info in GUI
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 } |