# HG changeset patch # User John W. Eaton # Date 1384621526 18000 # Node ID b3e4ee8f4d6d0e0b9e649c7fc74fd04d4b69e225 # Parent 16cf38c39915712d33cfc8c4ab3dfdc75c49579d 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. diff -r 16cf38c39915 -r b3e4ee8f4d6d libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sat Nov 16 02:52:30 2013 -0500 +++ b/libgui/src/main-window.cc Sat Nov 16 12:05:26 2013 -0500 @@ -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[] = "\n\ -\n\ -

\n\ -Octave's community news source seems to be unavailable.\n\ -For the latest news, please check\n\ -http://octave.org/community-news.html\n\ -when you have a connection to the web (link opens in an external browser).\n\ -

\n\ -

\n\ -— The Octave Developers, " OCTAVE_RELEASE_DATE "\n\ -\n\ -\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 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 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 ("\n" + "\n" + "

\n" + "Octave's community news source seems to be unavailable.\n" + "

\n" + "

\n" + "For the latest news, please check\n" + "http://octave.org/community-news.html\n" + "when you have a connection to the web (link opens in an external browser).\n" + "

\n" + "

\n" + "— The Octave Developers, " OCTAVE_RELEASE_DATE "\n" + "

\n" + "\n" + "\n")); } else - html_text = fixed_community_news; + html_text = QString + (tr ("\n" + "\n" + "

\n" + "Connecting to the web to display the latest Octave Community news has been disabled.\n" + "

\n" + "

\n" + "For the latest news, please check\n" + "http://octave.org/community-news.html\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" + "

\n" + "

\n" + "— The Octave Developers, " OCTAVE_RELEASE_DATE "\n" + "

\n" + "\n" + "\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); diff -r 16cf38c39915 -r b3e4ee8f4d6d libgui/src/main-window.h --- a/libgui/src/main-window.h Sat Nov 16 02:52:30 2013 -0500 +++ b/libgui/src/main-window.h Sat Nov 16 12:05:26 2013 -0500 @@ -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 diff -r 16cf38c39915 -r b3e4ee8f4d6d libgui/src/welcome-wizard.cc --- a/libgui/src/welcome-wizard.cc Sat Nov 16 02:52:30 2013 -0500 +++ b/libgui/src/welcome-wizard.cc Sat Nov 16 12:05:26 2013 -0500 @@ -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 (); +} diff -r 16cf38c39915 -r b3e4ee8f4d6d libgui/src/welcome-wizard.h --- a/libgui/src/welcome-wizard.h Sat Nov 16 02:52:30 2013 -0500 +++ b/libgui/src/welcome-wizard.h Sat Nov 16 12:05:26 2013 -0500 @@ -42,13 +42,18 @@ QList page_ctor_list; QList::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