From 1faca4e07e182d7cc51d390da4c6c295fd114cd2 Mon Sep 17 00:00:00 2001 From: John Levon Date: Wed, 31 Jul 2002 04:33:03 +0000 Subject: [PATCH] remove_io_callback for Qt git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4813 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 6 ++++++ src/frontends/qt2/io_callback.h | 13 +++++++++---- src/frontends/qt2/lyx_gui.C | 20 +++++++++++++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 71f5b9512a..19b47d66b8 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,9 @@ +2002-07-31 John Levon + + * io_callback.h: make a more proper class + + * lyx_gui.C: implement removal of I/O callbacks + 2002-07-30 John Levon * qlkey.h: diff --git a/src/frontends/qt2/io_callback.h b/src/frontends/qt2/io_callback.h index 919625388d..101b6d7b19 100644 --- a/src/frontends/qt2/io_callback.h +++ b/src/frontends/qt2/io_callback.h @@ -13,9 +13,12 @@ #include #include "lyxserver.h" +#include "debug.h" #include +#include + /** * io_callback - a simple wrapper for asynchronous pipe notification * @@ -30,17 +33,19 @@ public: /// connect a read ready notification for fd to the LyXComm io_callback(int fd, LyXComm * comm) : comm_(comm) { - QSocketNotifier * sn = new QSocketNotifier(fd, - QSocketNotifier::Read, this); - connect(sn, SIGNAL(activated(int)), this, SLOT(data_received())); + sn_.reset(new QSocketNotifier(fd, QSocketNotifier::Read, this)); + connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received())); } - + public slots: void data_received() { comm_->read_ready(); } private: + /// our notifier + boost::scoped_ptr sn_; + LyXComm * comm_; }; diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index b21382e0f2..acb9e932cb 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -47,7 +47,7 @@ using std::exit; #endif using std::vector; -using std::hex; +using std::map; using std::endl; extern BufferList bufferlist; @@ -147,9 +147,23 @@ bool lyx_gui::font_available(LyXFont const & font) return fontloader.available(font); } + +namespace { + map io_callbacks; +} + void lyx_gui::set_read_callback(int fd, LyXComm * comm) { - // FIXME: "leak" - new io_callback(fd, comm); + io_callbacks[fd] = new io_callback(fd, comm); +} + + +void lyx_gui::remove_read_callback(int fd) +{ + map::iterator it = io_callbacks.find(fd); + if (it != io_callbacks.end()) { + delete it->second; + io_callbacks.erase(it); + } }