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