changeset 29836:56465c0739fa

allow release notes window to be opened from command line * main-window.h, main-window.cc (main_window::m_release_notes_windoow, main_window::m_release_notes_icon): Delete member variables and all uses. (main_window::display_release_notes): Delete. (main_window::show_release_notes_signal): New signal. (main_window::construct_news_menu): Use lambda function to emit show_release_notes_signal. * release-notes.h, release-notes.cc: New files. * libgui/src/module.mk: Update. * octave-qobject.h, octave-qobject.cc (base_qobject::base_qobject): Connect main_window show_release_notes_signal to base_qobject show_release_notes slot. If gui_app is true, connect main_window show_release_notes_signal to base_qobject show_release_notes slot. (base_qobject::start_gui): Also connect main_window show_release_notes_signal to base_qobject show_release_notes slot here. (base_qobject::m_release_notes): New member variable. (base_qobject::release_notes_widget, base_qobject::show_release_notes): New functions. * qt-interpreter-events.h, qt-interpreter-events.cc (qt_interpreter_events::show_release_notes): New function. (qt_interpreter_events::show_release_notes_signal): New signal. * event-manager.h, event-manager.cc (event_manager::show_release_notes): New function. (interpreter_events::show_release_notes): New virtual function. (F__event_manager_show_release_notes__): New function.
author John W. Eaton <jwe@octave.org>
date Sat, 26 Jun 2021 07:59:17 -0400
parents a946d742fb97
children 0d511d53dd55
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/module.mk libgui/src/octave-qobject.cc libgui/src/octave-qobject.h libgui/src/qt-interpreter-events.cc libgui/src/qt-interpreter-events.h libgui/src/release-notes.cc libgui/src/release-notes.h libinterp/corefcn/event-manager.cc libinterp/corefcn/event-manager.h
diffstat 11 files changed, 263 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Fri Jun 25 17:27:17 2021 -0400
+++ b/libgui/src/main-window.cc	Sat Jun 26 07:59:17 2021 -0400
@@ -101,7 +101,6 @@
       m_external_editor (new external_editor_interface (this, m_octave_qobj)),
       m_active_editor (m_external_editor), m_settings_dlg (nullptr),
       m_find_files_dlg (nullptr), m_set_path_dlg (nullptr),
-      m_release_notes_window (nullptr),
       m_clipboard (QApplication::clipboard ()),
       m_prevent_readline_conflicts (true),
       m_prevent_readline_conflicts_menu (false),
@@ -210,14 +209,7 @@
     focus_command_window ();
   }
 
-  main_window::~main_window (void)
-  {
-    // These must be explicitly deleted because they are not
-    // intentionally not children of main_window.  See the comments in
-    // the functions where they are constructed.
-
-    delete m_release_notes_window;
-  }
+  main_window::~main_window (void) { }
 
   void main_window::adopt_dock_widgets (void)
   {
@@ -847,71 +839,6 @@
       (QUrl ("https://octave.org/doc/interpreter/index.html"));
   }
 
-  void main_window::display_release_notes (void)
-  {
-    if (! m_release_notes_window)
-      {
-        std::string news_file = config::oct_etc_dir () + "/NEWS";
-
-        QString news;
-
-        QFile *file = new QFile (QString::fromStdString (news_file));
-        if (file->open (QFile::ReadOnly))
-          {
-            QTextStream *stream = new QTextStream (file);
-            news = stream->readAll ();
-            if (! news.isEmpty ())
-              {
-                // Convert '<', '>' which would be interpreted as HTML
-                news.replace ("<", "&lt;");
-                news.replace (">", "&gt;");
-                // Add HTML tags for pre-formatted text
-                news.prepend ("<pre>");
-                news.append ("</pre>");
-              }
-            else
-              news = (tr ("The release notes file '%1' is empty.")
-                      . arg (QString::fromStdString (news_file)));
-          }
-        else
-          news = (tr ("The release notes file '%1' cannot be read.")
-                  . arg (QString::fromStdString (news_file)));
-
-        // We want the window manager to give the release notes window
-        // a title bar, so don't its parent to main_window.  Do remember
-        // to delete in the main_window destructor.
-
-        m_release_notes_window = new QWidget ();
-
-        QTextBrowser *browser = new QTextBrowser (m_release_notes_window);
-        browser->setText (news);
-
-        QVBoxLayout *vlayout = new QVBoxLayout;
-        vlayout->addWidget (browser);
-
-        m_release_notes_window->setLayout (vlayout);
-        m_release_notes_window->setWindowTitle (tr ("Octave Release Notes"));
-
-        browser->document ()->adjustSize ();
-
-        int win_x, win_y;
-        get_screen_geometry (win_x, win_y);
-
-        m_release_notes_window->resize (win_x*2/5, win_y*2/3);
-        m_release_notes_window->move (20, 20);  // move to the top left corner
-      }
-
-    if (! m_release_notes_window->isVisible ())
-      m_release_notes_window->show ();
-    else if (m_release_notes_window->isMinimized ())
-      m_release_notes_window->showNormal ();
-
-    m_release_notes_window->setWindowIcon (QIcon (m_release_notes_icon));
-
-    m_release_notes_window->raise ();
-    m_release_notes_window->activateWindow ();
-  }
-
   void main_window::open_bug_tracker_page (void)
   {
     QDesktopServices::openUrl (QUrl ("https://octave.org/bugs.html"));
@@ -1014,11 +941,6 @@
             widget->setWindowIcon (QIcon (icon));
           }
       }
-    if (dw_icon_set_names[icon_set_found].name != "NONE")
-      m_release_notes_icon = dw_icon_set_names[icon_set_found].path
-                             + "ReleaseWidget.png";
-    else
-      m_release_notes_icon = ":/actions/icons/logo.png";
 
     int size_idx = settings->value (global_icon_size).toInt ();
     size_idx = (size_idx > 0) - (size_idx < 0) + 1;  // Make valid index from 0 to 2
@@ -2586,10 +2508,14 @@
   {
     QMenu *news_menu = m_add_menu (p, tr ("&News"));
 
-    m_release_notes_action = add_action (news_menu, QIcon (),
-                                         tr ("Release Notes"), SLOT (display_release_notes ()));
-
-    // Currently a special case so we can use a lambda expression.
+    m_release_notes_action
+      = news_menu->addAction (QIcon (), tr ("Release Notes"),
+                              [=] () {
+                                emit show_release_notes_signal ();
+                              });
+    addAction (m_release_notes_action);
+    m_release_notes_action->setShortcutContext (Qt::ApplicationShortcut);
+
     m_current_news_action
       = news_menu->addAction (QIcon (), tr ("Community News"),
                               [=] () {
--- a/libgui/src/main-window.h	Fri Jun 25 17:27:17 2021 -0400
+++ b/libgui/src/main-window.h	Sat Jun 26 07:59:17 2021 -0400
@@ -108,6 +108,7 @@
     void step_into_file_signal (void);
 
     void show_community_news_signal (int serial);
+    void show_release_notes_signal (void);
 
     void update_gui_lexer_signal (bool);
 
@@ -146,7 +147,6 @@
     void edit_mfile (const QString&, int);
     void file_remove_proxy (const QString& o, const QString& n);
     void open_online_documentation_page (void);
-    void display_release_notes (void);
     void open_bug_tracker_page (void);
     void open_octave_packages_page (void);
     void open_contribute_page (void);
@@ -333,8 +333,6 @@
     octave_dock_widget *m_previous_dock;
     octave_dock_widget *m_active_dock;
 
-    QString m_release_notes_icon;
-
     QToolBar *m_main_tool_bar;
 
     QMenu *m_debug_menu;
--- a/libgui/src/module.mk	Fri Jun 25 17:27:17 2021 -0400
+++ b/libgui/src/module.mk	Sat Jun 26 07:59:17 2021 -0400
@@ -149,6 +149,7 @@
   %reldir%/moc-main-window.cc \
   %reldir%/moc-news-reader.cc \
   %reldir%/moc-octave-qobject.cc \
+  %reldir%/moc-release-notes.cc \
   %reldir%/moc-settings-dialog.cc \
   %reldir%/moc-terminal-dock-widget.cc \
   %reldir%/moc-color-picker.cc \
@@ -235,6 +236,7 @@
   %reldir%/qt-application.h \
   %reldir%/qt-interpreter-events.h \
   %reldir%/qt-utils.h \
+  %reldir%/release-notes.h \
   %reldir%/resource-manager.h \
   %reldir%/settings-dialog.h \
   %reldir%/shortcut-manager.h \
@@ -280,6 +282,7 @@
   %reldir%/octave-qobject.cc \
   %reldir%/qt-interpreter-events.cc \
   %reldir%/qt-application.cc \
+  %reldir%/release-notes.cc \
   %reldir%/resource-manager.cc \
   %reldir%/settings-dialog.cc \
   %reldir%/shortcut-manager.cc \
--- a/libgui/src/octave-qobject.cc	Fri Jun 25 17:27:17 2021 -0400
+++ b/libgui/src/octave-qobject.cc	Sat Jun 26 07:59:17 2021 -0400
@@ -50,6 +50,7 @@
 #include "octave-qobject.h"
 #include "qt-application.h"
 #include "qt-interpreter-events.h"
+#include "release-notes.h"
 #include "resource-manager.h"
 #include "shortcut-manager.h"
 #include "terminal-dock-widget.h"
@@ -281,6 +282,9 @@
     connect (qt_link (), &qt_interpreter_events::show_community_news_signal,
              this, &base_qobject::show_community_news);
 
+    connect (qt_link (), &qt_interpreter_events::show_release_notes_signal,
+             this, &base_qobject::show_release_notes);
+
     if (m_app_context.experimental_terminal_widget ())
       {
         m_qapplication->setQuitOnLastWindowClosed (false);
@@ -294,6 +298,9 @@
             connect (m_main_window, &main_window::show_community_news_signal,
                      this, &base_qobject::show_community_news);
 
+            connect (m_main_window, &main_window::show_release_notes_signal,
+                     this, &base_qobject::show_release_notes);
+
             if (m_interpreter_ready)
               m_main_window->handle_octave_ready ();
             else
@@ -727,6 +734,14 @@
     return m_community_news;
   }
 
+  QPointer<release_notes> base_qobject::release_notes_widget (void)
+  {
+    if (! m_release_notes)
+      m_release_notes = QPointer<release_notes> (new release_notes ());
+
+    return m_release_notes;
+  }
+
   bool base_qobject::confirm_shutdown (void)
   {
     // Currently, we forward to main_window::confirm_shutdown instead of
@@ -759,6 +774,9 @@
         connect (m_main_window, &main_window::show_community_news_signal,
                  this, &base_qobject::show_community_news);
 
+        connect (m_main_window, &main_window::show_release_notes_signal,
+                 this, &base_qobject::show_release_notes);
+
         if (m_interpreter_ready)
           m_main_window->handle_octave_ready ();
         else
@@ -886,6 +904,14 @@
     m_community_news->display ();
   }
 
+  void base_qobject::show_release_notes (void)
+  {
+    // Ensure widget exists.
+    release_notes_widget ();
+
+    m_release_notes->display ();
+  }
+
   void base_qobject::execute_command (const QString& command)
   {
     emit interpreter_event
--- a/libgui/src/octave-qobject.h	Fri Jun 25 17:27:17 2021 -0400
+++ b/libgui/src/octave-qobject.h	Sat Jun 26 07:59:17 2021 -0400
@@ -44,6 +44,7 @@
   class main_window;
   class qt_application;
   class qt_interpreter_events;
+  class release_notes;
 
   //! This class is a simple wrapper around QApplication so that we can
   //! reimplement QApplication::notify.  The octave_qapplication object
@@ -186,6 +187,8 @@
 
     QPointer<community_news> community_news_widget (int serial = -1);
 
+    QPointer<release_notes> release_notes_widget (void);
+
     QThread *main_thread (void) { return m_main_thread; }
 
     // Declared virtual so that a derived class may redefine this
@@ -228,6 +231,8 @@
 
     void show_community_news (int serial);
 
+    void show_release_notes (void);
+
     void interpreter_ready (void);
 
     void interpreter_event (const fcn_callback& fcn);
@@ -298,6 +303,8 @@
 
     QPointer<community_news> m_community_news;
 
+    QPointer<release_notes> m_release_notes;
+
     main_window *m_main_window;
   };
 }
--- a/libgui/src/qt-interpreter-events.cc	Fri Jun 25 17:27:17 2021 -0400
+++ b/libgui/src/qt-interpreter-events.cc	Sat Jun 26 07:59:17 2021 -0400
@@ -291,6 +291,11 @@
     emit show_community_news_signal (serial);
   }
 
+  void qt_interpreter_events::show_release_notes (void)
+  {
+    emit show_release_notes_signal ();
+  }
+
   bool qt_interpreter_events::edit_file (const std::string& file)
   {
     emit edit_file_signal (QString::fromStdString (file));
--- a/libgui/src/qt-interpreter-events.h	Fri Jun 25 17:27:17 2021 -0400
+++ b/libgui/src/qt-interpreter-events.h	Sat Jun 26 07:59:17 2021 -0400
@@ -128,6 +128,7 @@
     void show_workspace (void);
 
     void show_community_news (int serial);
+    void show_release_notes (void);
 
     bool edit_file (const std::string& file);
 
@@ -282,6 +283,7 @@
     void show_workspace_signal (void);
 
     void show_community_news_signal (int serial);
+    void show_release_notes_signal (void);
 
     // Note: this signal currently not used by the old terminal widget.
     void interpreter_output_signal (const QString& msg);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/release-notes.cc	Sat Jun 26 07:59:17 2021 -0400
@@ -0,0 +1,129 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2011-2021 The Octave Project Developers
+//
+// See the file COPYRIGHT.md in the top-level directory of this
+// distribution or <https://octave.org/copyright/>.
+//
+// This file is part of Octave.
+//
+// Octave is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Octave is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Octave; see the file COPYING.  If not, see
+// <https://www.gnu.org/licenses/>.
+//
+////////////////////////////////////////////////////////////////////////
+
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#include <QDesktopWidget>
+#include <QFile>
+#include <QIcon>
+#include <QLayout>
+#include <QTextBrowser>
+#include <QTextStream>
+#include <QThread>
+
+#include "release-notes.h"
+#include "gui-preferences-nr.h"
+#include "news-reader.h"
+#include "octave-qobject.h"
+
+#include "defaults.h"
+
+namespace octave
+{
+  release_notes::release_notes (void)
+    : QWidget (nullptr), m_browser (nullptr),
+      m_release_notes_icon (":/actions/icons/logo.png")
+  {
+#if 0
+    // The following code was in main-window.cc.  How should that be
+    // handled here?
+    if (dw_icon_set_names[icon_set_found].name != "NONE")
+      m_release_notes_icon = dw_icon_set_names[icon_set_found].path
+        + "ReleaseWidget.png";
+    else
+      m_release_notes_icon = ":/actions/icons/logo.png";
+#endif
+
+    std::string news_file = config::oct_etc_dir () + "/NEWS";
+
+    QString news;
+
+    QFile *file = new QFile (QString::fromStdString (news_file));
+    if (file->open (QFile::ReadOnly))
+      {
+        QTextStream *stream = new QTextStream (file);
+        news = stream->readAll ();
+        if (! news.isEmpty ())
+          {
+            // Convert '<', '>' which would be interpreted as HTML
+            news.replace ("<", "&lt;");
+            news.replace (">", "&gt;");
+            // Add HTML tags for pre-formatted text
+            news.prepend ("<pre>");
+            news.append ("</pre>");
+          }
+        else
+          news = (tr ("The release notes file '%1' is empty.")
+                  . arg (QString::fromStdString (news_file)));
+      }
+    else
+      news = (tr ("The release notes file '%1' cannot be read.")
+              . arg (QString::fromStdString (news_file)));
+
+
+    m_browser = new QTextBrowser (this);
+    m_browser->setText (news);
+
+    QVBoxLayout *vlayout = new QVBoxLayout;
+    vlayout->addWidget (m_browser);
+
+    setLayout (vlayout);
+    setWindowTitle (tr ("Octave Release Notes"));
+
+    m_browser->document ()->adjustSize ();
+
+    int win_x, win_y;
+    get_screen_geometry (win_x, win_y);
+
+    resize (win_x*2/5, win_y*2/3);
+    move (20, 20);  // move to the top left corner
+  }
+
+  void release_notes::display (void)
+  {
+    if (! isVisible ())
+      show ();
+    else if (isMinimized ())
+      showNormal ();
+
+    setWindowIcon (QIcon (m_release_notes_icon));
+
+    raise ();
+    activateWindow ();
+  }
+
+  // FIXME: This function is duplicated in main_window.cc.  Maybe it
+  // should be a utility function?
+
+  void release_notes::get_screen_geometry (int& width, int& height)
+  {
+    QRect screen_geometry = QApplication::desktop ()->availableGeometry (this);
+
+    width = screen_geometry.width ();
+    height = screen_geometry.height ();
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/release-notes.h	Sat Jun 26 07:59:17 2021 -0400
@@ -0,0 +1,61 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2011-2021 The Octave Project Developers
+//
+// See the file COPYRIGHT.md in the top-level directory of this
+// distribution or <https://octave.org/copyright/>.
+//
+// This file is part of Octave.
+//
+// Octave is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Octave is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Octave; see the file COPYING.  If not, see
+// <https://www.gnu.org/licenses/>.
+//
+////////////////////////////////////////////////////////////////////////
+
+#if ! defined (octave_release_notes_h)
+#define octave_release_notes_h 1
+
+#include <QString>
+#include <QWidget>
+
+class QTextBrowser;
+
+namespace octave
+{
+  class base_qobject;
+
+  class release_notes : public QWidget
+  {
+    Q_OBJECT
+
+  public:
+
+    release_notes (void);
+
+    ~release_notes (void) = default;
+
+  public slots:
+
+    void display (void);
+
+  private:
+
+    void get_screen_geometry (int& width, int& height);
+
+    QTextBrowser *m_browser;
+    QString m_release_notes_icon;
+  };
+}
+
+#endif
--- a/libinterp/corefcn/event-manager.cc	Fri Jun 25 17:27:17 2021 -0400
+++ b/libinterp/corefcn/event-manager.cc	Sat Jun 26 07:59:17 2021 -0400
@@ -734,6 +734,19 @@
   return ovl ();
 }
 
+DEFMETHOD (__event_manager_show_release_notes__, interp, , ,
+           doc: /* -*- texinfo -*-
+@deftypefn {} {} __event_manager_show_release_notes__ ()
+Undocumented internal function.
+@end deftypefn */)
+{
+  octave::event_manager& evmgr = interp.get_event_manager ();
+
+  evmgr.show_release_notes ();
+
+  return ovl ();
+}
+
 DEFMETHOD (__event_manager_gui_status_update__, interp, args, ,
            doc: /* -*- texinfo -*-
 @deftypefn {} {} __event_manager_gui_status_update__ (@var{feature}, @var{status})
--- a/libinterp/corefcn/event-manager.h	Fri Jun 25 17:27:17 2021 -0400
+++ b/libinterp/corefcn/event-manager.h	Sat Jun 26 07:59:17 2021 -0400
@@ -162,6 +162,7 @@
     virtual void show_workspace (void) { }
 
     virtual void show_community_news (int /*serial*/) { }
+    virtual void show_release_notes (void) { }
 
     virtual bool edit_file (const std::string& /*file*/) { return false; }
 
@@ -493,6 +494,12 @@
         instance->show_community_news (serial);
     }
 
+    void show_release_notes (void)
+    {
+      if (enabled ())
+        instance->show_release_notes ();
+    }
+
     bool edit_file (const std::string& file)
     {
       return enabled () ? instance->edit_file (file) : false;