Mercurial > hg > octave-nkf
changeset 17940:b3e4ee8f4d6d
respect option for opting out of web connections for community news
* main-window.h, main-window.cc (main_window::main_window): Check
settings for news/allow_web_connection. Don't load and display
community news at startup if the community news web connection is
disabled.
(news_reader::connect_to_web): New data member.
(news_reader_process): Display different messages for network
unavailable and disabled web connections. Don't connect to web if
connect_to_web is false.
(main_window::load_and_display_community_news): Check settings for
news/allow_web_connection and pass value to news_reader constructor.
* welcome-wizard.h, welcome-wizard.cc
(welcome_wizard::allow_web_connect_state): New data member.
(welcome_wizard::handle_web_connect_option): New slot.
(setup_community_news::setup_community_news): Connect checkbox signal
to welcome_wizard::handle_web_connect_option.
(welcome_wizard::accept): New slot. Initialize resources here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 16 Nov 2013 12:05:26 -0500 |
parents | 16cf38c39915 |
children | 9799a996b2c1 |
files | libgui/src/main-window.cc libgui/src/main-window.h libgui/src/welcome-wizard.cc libgui/src/welcome-wizard.h |
diffstat | 4 files changed, 133 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -92,11 +92,15 @@ { QSettings *settings = resource_manager::get_settings (); + bool connect_to_web = true; QDateTime last_checked; int serial = 0; if (settings) { + connect_to_web + = settings->value ("news/allow_web_connection", true).toBool (); + last_checked = settings->value ("news/last_time_checked", QDateTime ()).toDateTime (); @@ -106,7 +110,8 @@ QDateTime current = QDateTime::currentDateTimeUtc (); QDateTime one_day_ago = current.addDays (-1); - if (! last_checked.isValid () || one_day_ago > last_checked) + if (connect_to_web + && (! last_checked.isValid () || one_day_ago > last_checked)) load_and_display_community_news (serial); // We have to set up all our windows, before we finally launch octave. @@ -343,85 +348,108 @@ release_notes_window->activateWindow (); } -static const char fixed_community_news[] = "<html>\n\ -<body>\n\ -<p>\n\ -Octave's community news source seems to be unavailable.\n\ -For the latest news, please check\n\ -<a href=\"http://octave.org/community-news.html\">http://octave.org/community-news.html</a>\n\ -when you have a connection to the web (link opens in an external browser).\n\ -</p>\n\ -<p>\n\ -<small><em>— The Octave Developers, " OCTAVE_RELEASE_DATE "</em></small>\n\ -</body>\n\ -</html>\n"; - void news_reader::process (void) { - // Run this part in a separate thread so Octave can continue to run - // while we wait for the page to load. Then emit the signal to - // display it when we have the page contents. - - QString url = base_url + "/" + page; - std::ostringstream buf; - url_transfer octave_dot_org (url.toStdString (), buf); - - Array<std::string> param; - octave_dot_org.http_get (param); - QString html_text; - if (octave_dot_org.good ()) - html_text = QString::fromStdString (buf.str ()); + if (connect_to_web) + { + // Run this part in a separate thread so Octave can continue to + // run while we wait for the page to load. Then emit the signal + // to display it when we have the page contents. - if (html_text.contains ("this-is-the-gnu-octave-community-news-page")) - { - if (serial >= 0) - { - QSettings *settings = resource_manager::get_settings (); + QString url = base_url + "/" + page; + std::ostringstream buf; + url_transfer octave_dot_org (url.toStdString (), buf); + + Array<std::string> param; + octave_dot_org.http_get (param); - if (settings) - { - settings->setValue ("news/last_time_checked", - QDateTime::currentDateTimeUtc ()); + if (octave_dot_org.good ()) + html_text = QString::fromStdString (buf.str ()); - settings->sync (); - } + if (html_text.contains ("this-is-the-gnu-octave-community-news-page")) + { + if (serial >= 0) + { + QSettings *settings = resource_manager::get_settings (); - QString tag ("community-news-page-serial="); + if (settings) + { + settings->setValue ("news/last_time_checked", + QDateTime::currentDateTimeUtc ()); - int b = html_text.indexOf (tag); + settings->sync (); + } + + QString tag ("community-news-page-serial="); + + int b = html_text.indexOf (tag); - if (b) - { - b += tag.length (); + if (b) + { + b += tag.length (); - int e = html_text.indexOf ("\n", b); + int e = html_text.indexOf ("\n", b); - QString tmp = html_text.mid (b, e-b); + QString tmp = html_text.mid (b, e-b); - int curr_page_serial = tmp.toInt (); + int curr_page_serial = tmp.toInt (); - if (curr_page_serial > serial) - { - if (settings) + if (curr_page_serial > serial) { - settings->setValue ("news/last_news_item", - curr_page_serial); + if (settings) + { + settings->setValue ("news/last_news_item", + curr_page_serial); - settings->sync (); + settings->sync (); + } } + else + return; } else return; } - else - return; } + else + html_text = QString + (tr ("<html>\n" + "<body>\n" + "<p>\n" + "Octave's community news source seems to be unavailable.\n" + "</p>\n" + "<p>\n" + "For the latest news, please check\n" + "<a href=\"http://octave.org/community-news.html\">http://octave.org/community-news.html</a>\n" + "when you have a connection to the web (link opens in an external browser).\n" + "</p>\n" + "<p>\n" + "<small><em>— The Octave Developers, " OCTAVE_RELEASE_DATE "</em></small>\n" + "</p>\n" + "</body>\n" + "</html>\n")); } else - html_text = fixed_community_news; + html_text = QString + (tr ("<html>\n" + "<body>\n" + "<p>\n" + "Connecting to the web to display the latest Octave Community news has been disabled.\n" + "</p>\n" + "<p>\n" + "For the latest news, please check\n" + "<a href=\"http://octave.org/community-news.html\">http://octave.org/community-news.html</a>\n" + "when you have a connection to the web (link opens in an external browser)\n" + "or enable web connections for news in Octave's network settings dialog.\n" + "</p>\n" + "<p>\n" + "<small><em>— The Octave Developers, " OCTAVE_RELEASE_DATE "</em></small>\n" + "</p>\n" + "</body>\n" + "</html>\n")); emit display_news_signal (html_text); @@ -431,12 +459,20 @@ void main_window::load_and_display_community_news (int serial) { + QSettings *settings = resource_manager::get_settings (); + + bool connect_to_web + = (settings + ? settings->value ("news/allow_web_connection", true).toBool () + : true); + QString base_url = "http://octave.org"; QString page = "community-news.html"; QThread *worker_thread = new QThread; - news_reader *reader = new news_reader (base_url, page, serial); + news_reader *reader = new news_reader (base_url, page, serial, + connect_to_web); reader->moveToThread (worker_thread);
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -348,8 +348,9 @@ public: news_reader (const QString& xbase_url, const QString& xpage, - int xserial = -1) - : QObject (), base_url (xbase_url), page (xpage), serial (xserial) + int xserial = -1, bool xconnect_to_web = false) + : QObject (), base_url (xbase_url), page (xpage), serial (xserial), + connect_to_web (xconnect_to_web) { } public slots: @@ -367,6 +368,7 @@ QString base_url; QString page; int serial; + bool connect_to_web; }; #endif // MAINWINDOW_H
--- a/libgui/src/welcome-wizard.cc +++ b/libgui/src/welcome-wizard.cc @@ -200,6 +200,9 @@ next->setDefault (true); next->setFocus (); + connect (checkbox, SIGNAL (stateChanged (int)), + wizard, SLOT (handle_web_connect_option (int))); + connect (previous, SIGNAL (clicked ()), wizard, SLOT (previous_page ())); connect (next, SIGNAL (clicked ()), wizard, SLOT (next_page ())); connect (cancel, SIGNAL (clicked ()), wizard, SLOT (reject ())); @@ -319,7 +322,8 @@ welcome_wizard::welcome_wizard (QWidget *p) : QDialog (p), page_ctor_list (), page_list_iterator (), - current_page (initial_page::create (this)) + current_page (initial_page::create (this)), + allow_web_connect_state (true) { page_ctor_list.push_back (initial_page::create); page_ctor_list.push_back (setup_community_news::create); @@ -337,6 +341,12 @@ } void +welcome_wizard::handle_web_connect_option (int state) +{ + allow_web_connect_state = state == Qt::Checked; +} + +void welcome_wizard::show_page (void) { delete current_page; @@ -365,3 +375,23 @@ show_page (); } + +void +welcome_wizard::accept (void) +{ + // Create default settings file. + + resource_manager::reload_settings (); + + QSettings *settings = resource_manager::get_settings (); + + if (settings) + { + settings->setValue ("news/allow_web_connection", + allow_web_connect_state); + + settings->sync (); + } + + QDialog::accept (); +}
--- a/libgui/src/welcome-wizard.h +++ b/libgui/src/welcome-wizard.h @@ -42,13 +42,18 @@ QList<page_creator_fptr> page_ctor_list; QList<page_creator_fptr>::iterator page_list_iterator; - QWidget *current_page; + QWidget *current_page; + bool allow_web_connect_state; private slots: + void handle_web_connect_option (int state); + void show_page (void); void previous_page (void); void next_page (void); + + void accept (void); }; #endif // WELCOMEWIZARD_H