Mercurial > octave
view libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp @ 22177:6e9f5408c0db
Save settings in Qt convention, delete all children in destructors (bug #45366)
* QUnixTerminalImpl.cpp (QUnixTerminalImpl::~QUnixTerminalImpl): Delete
dynamic objects pointed to by m_terminal (TerminalModel), m_kpty (KPty) and
m_terminalView (TerminalView). (bug fix)
* files-dock-widget.cc: (files_dock_widget::~files_dock_widget): Rename to
save_settings. Return if variable 'settings' is not valid object pointer.
(files_dock_widget::save_settings): Added. Similar code as destructor was.
Call base class octave_dock_widget::save_settings at end of routine.
* files-dock-widget.h: (files_dock_widget::~files_dock_widget): Provide empty
destructor.
(files_dock_widget::save_settings): Added, public slot.
* find-files-dialog.cc: (find_files_dialog::~find_files_dialog): Moved most
of the code, except the statement deleting the directory iterator, to
new routine save_settings.
(find_files_dialog::save_settings): Added. Large portion of the code that was
in the destructor. Return immediately if variable 'settings' is not valid
object pointer.
* find-files-dialog.h: (find_files_dialog::save_settings): Added, public slot.
* history-dock-widget.cc: (history_dock_widget::~history_dock_widget): Rename
to save_settings. Return if variable 'settings' is not valid object pointer.
(history_dock_widget::save_settings): Similar code as destructor was. Call
base class octave_dock_widget::save_settings at end of routine.
* history-dock-widget.h: (history_dock_widget::~history_dock_widget): Provide
empty destructor.
(history_dock_widget::save_settings): Added, public slot.
* main-window.cc (main_window::prepare_to_exit): If find_files_dlg is valid,
call the object's save_settings routine.
(main_window::construct): Connect appropriate slot of all objects that must
save_settings information to the qApp aboutToQuit signal. (Except for
find_files_dlg, see above.) At end of this sequence, connect aboutToQuit to
the shortcut_manager and resource_manager function that deletes instance.
* octave-dock-widget.cc: (octave_dock_widget::~octave_dock_widget): Rename to
save_settings. Return if variable 'settings' is not valid object pointer.
(octave_dock_widget::save_settings): Similar code as destructor was.
* octave-dock-widget.h: (octave_dock_widget::~octave_dock_widget): Provide
empty destructor.
(octave_dock_widget::save_settings): Added, public slot.
* octave-qt-link.cc (octave_qt_link::do_prompt_new_edit_file): Check that
'settings' pointer is valid before using.
* resource-manager.cc: Remove "singleton-cleanup.h" header reference.
(resource_manager::instance_ok): Do not add cleanup_instance to worker
thread's exit cleanup procedure.
* resource-manager.h (resource_manager::instance) Change variable to public for
connecting.
(resource_manager::cleanup_instance) Change to a public slot for connecting to
qApp aboutToQuit signal.
(resource_manager::resource_manager): Remove an unused variation of the
constructor.
(resource_manager::operator =) Removed.
* settings-dialog.cc: Add QMessageBox to header file list.
(settings_dialog::settings_dialog): If QSettings pointer settings is not valid
return immediately.
(settings_dialog::show_tab): Condition setting the current index on pointer
'settings' being valid.
(settings_dialog::write_changed_settings): Remove FIXME comment. If the
settings are not valid, display a dialog about missing file and return.
* shortcut-manager.cc: Remove "singleton-cleanup.h" header reference.
(shortcut_manager::instance_ok): Do not add cleanup_instance to worker
thread's exit cleanup procedure.
* shortcut-manager.h (shortcut_manager::instance) Change variable to public for
connecting.
(shortcut_manager::cleanup_instance) Change to a public slot for connecting to
qApp aboutToQuit signal.
(shortcut_manager::shortcut_manager): Remove an unused variation of the
constructor.
(shortcut_manager::operator =) Removed.
* terminal-dock-widget.cc (terminal_dock_widget::~terminal_dock_widget): Added.
Delete QTerminal terminal. (bug fix)
* terminal-dock-widget.h (terminal_dock_widget::~terminal_dock_widget): Added.
* workspace-view.cc: (workspace_view::workspace_view): Place code hunk using
QSettings pointer 'settings' within a conditional block.
(workspace_view::~workspace_view): Rename to save_settings. Return if
variable 'settings' is not valid object pointer.
(workspace_view::save_settings): Almost same code as destructor was. Call base
class octave_dock_widget::save_settings at end of routine.
* workspace-view.h: (workspace_view::~workspace_view): Provide empty
destructor.
(workspace_view::save_settings): Added, public slot.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Mon, 25 Jul 2016 17:44:02 -0400 |
parents | 4197fc428c7d |
children | bac0d6f07a3e |
line wrap: on
line source
/* Copyright (C) 2008 e_k (e_k@users.sourceforge.net) Copyright (C) 2012-2015 Jacob Dawid <jacob.dawid@cybercatalyst.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include <QDebug> #include "unix/QUnixTerminalImpl.h" #include "unix/kpty.h" #include <termios.h> QUnixTerminalImpl::QUnixTerminalImpl(QWidget *parent) : QTerminal(parent) { setMinimumSize(300, 200); initialize(); } void QUnixTerminalImpl::initialize() { m_terminalView = new TerminalView(this); m_terminalView->setKeyboardCursorShape(TerminalView::UnderlineCursor); m_terminalView->setBlinkingCursor(true); m_terminalView->setBellMode(TerminalView::NotifyBell); m_terminalView->setTerminalSizeHint(true); m_terminalView->setContextMenuPolicy(Qt::CustomContextMenu); m_terminalView->setTripleClickMode(TerminalView::SelectWholeLine); m_terminalView->setTerminalSizeStartup(true); m_terminalView->setSize(80, 40); m_terminalView->setScrollBarPosition(TerminalView::ScrollBarRight); connect(m_terminalView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(handleCustomContextMenuRequested(QPoint))); connect (m_terminalView, SIGNAL (interrupt_signal (void)), this, SLOT (terminal_interrupt ())); #ifdef Q_OS_MAC QFont font = QFont("Monaco"); font.setStyleHint(QFont::TypeWriter); font.setPointSize(11); #else QFont font = QFont("Monospace"); font.setStyleHint(QFont::TypeWriter); font.setPointSize(10); #endif setTerminalFont(font); setFocusPolicy (Qt::StrongFocus); setFocusProxy(m_terminalView); setFocus(Qt::OtherFocusReason); m_kpty = new KPty(); m_kpty->open(); m_terminalModel = new TerminalModel(m_kpty); m_terminalModel->setAutoClose(true); m_terminalModel->setCodec(QTextCodec::codecForName("UTF-8")); m_terminalModel->setHistoryType(HistoryTypeBuffer (1000)); m_terminalModel->setDarkBackground(true); m_terminalModel->setKeyBindings(""); m_terminalModel->run(); m_terminalModel->addView(m_terminalView); connectToPty(); } void QUnixTerminalImpl::setScrollBufferSize(int value) { if (value > 0) { m_terminalModel->clearHistory (); m_terminalModel->setHistoryType (HistoryTypeBuffer ( value )); } else m_terminalModel->setHistoryType (HistoryTypeNone ()); } void QUnixTerminalImpl::connectToPty() { // Store the file descriptor associated with the STDERR stream onto // another temporary file descriptor for reconnect in the destructor. fdstderr = dup (STDERR_FILENO); int fds = m_kpty->slaveFd(); dup2 (fds, STDIN_FILENO); dup2 (fds, STDOUT_FILENO); dup2 (fds, STDERR_FILENO); if(!isatty(STDIN_FILENO)) { qDebug("Error: stdin is not a tty."); } if(!isatty(STDOUT_FILENO)) { qDebug("Error: stdout is not a tty."); } if(!isatty(STDERR_FILENO)) { qDebug("Error: stderr is not a tty."); } } QUnixTerminalImpl::~QUnixTerminalImpl() { delete m_terminalModel; delete m_kpty; delete m_terminalView; // Restore stderr so that any errors at exit might appear somewhere. dup2 (fdstderr, STDERR_FILENO); emit destroyed(); } void QUnixTerminalImpl::setTerminalFont(const QFont &font) { if(!m_terminalView) return; m_terminalView->setVTFont(font); } void QUnixTerminalImpl::setSize(int h, int v) { if(!m_terminalView) return; m_terminalView->setSize(h, v); } void QUnixTerminalImpl::sendText(const QString& text) { m_terminalModel->sendText(text); } void QUnixTerminalImpl::setCursorType(CursorType type, bool blinking) { switch(type) { case UnderlineCursor: m_terminalView->setKeyboardCursorShape(TerminalView::UnderlineCursor); break; case BlockCursor: m_terminalView->setKeyboardCursorShape(TerminalView::BlockCursor); break; case IBeamCursor: m_terminalView->setKeyboardCursorShape(TerminalView::IBeamCursor); break; } m_terminalView->setBlinkingCursor(blinking); } // FIXME -- not sure how to make these work properly given the way the // Unix terminal handles colors. void QUnixTerminalImpl::setBackgroundColor (const QColor& color) { ColorEntry cols[TABLE_COLORS]; const ColorEntry * curr_cols = m_terminalView->colorTable(); for(int i=0;i<TABLE_COLORS;i++) { cols[i] = curr_cols[i]; } cols[DEFAULT_BACK_COLOR].color = color; m_terminalView->setColorTable(cols); } void QUnixTerminalImpl::setForegroundColor (const QColor& color) { ColorEntry cols[TABLE_COLORS]; const ColorEntry * curr_cols = m_terminalView->colorTable(); for(int i=0;i<TABLE_COLORS;i++) { cols[i] = curr_cols[i]; } cols[DEFAULT_FORE_COLOR].color = color; m_terminalView->setColorTable(cols); } void QUnixTerminalImpl::setSelectionColor (const QColor& color) { } void QUnixTerminalImpl::setCursorColor (bool useForegroundColor, const QColor& color) { m_terminalView->setKeyboardCursorColor (useForegroundColor, color); } void QUnixTerminalImpl::showEvent(QShowEvent *) { m_terminalView->updateImage(); m_terminalView->repaint(); m_terminalView->update(); } void QUnixTerminalImpl::resizeEvent(QResizeEvent*) { m_terminalView->resize(this->size()); m_terminalView->updateImage(); m_terminalView->repaint(); m_terminalView->update(); } void QUnixTerminalImpl::copyClipboard() { m_terminalView->copyClipboard (_extra_interrupt); } void QUnixTerminalImpl::pasteClipboard() { m_terminalView->pasteClipboard(); } void QUnixTerminalImpl::selectAll() { m_terminalView->selectAll(); } QString QUnixTerminalImpl::selectedText () { return m_terminalView->selectedText (); } void QUnixTerminalImpl::has_extra_interrupt (bool extra) { _extra_interrupt = extra; }