]> git.lyx.org Git - lyx.git/commitdiff
remove_io_callback for Qt
authorJohn Levon <levon@movementarian.org>
Wed, 31 Jul 2002 04:33:03 +0000 (04:33 +0000)
committerJohn Levon <levon@movementarian.org>
Wed, 31 Jul 2002 04:33:03 +0000 (04:33 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4813 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/io_callback.h
src/frontends/qt2/lyx_gui.C

index 71f5b9512a181fece11014bded28acd18b8d88b7..19b47d66b8d36ba65af333e9f9afbdf38acbf9f3 100644 (file)
@@ -1,3 +1,9 @@
+2002-07-31  John Levon  <levon@movementarian.org>
+
+       * io_callback.h: make a more proper class
+
+       * lyx_gui.C: implement removal of I/O callbacks
 2002-07-30  John Levon  <levon@movementarian.org>
 
        * qlkey.h:
index 919625388d534cdddb60feb87325243b679dd1e0..101b6d7b19def836f3ceb90efe8939177880da71 100644 (file)
 #include <config.h>
 
 #include "lyxserver.h"
+#include "debug.h"
  
 #include <qsocketnotifier.h>
 
+#include <boost/scoped_ptr.hpp>
 /**
  * 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<QSocketNotifier> sn_;
        LyXComm * comm_;
 };
 
index b21382e0f27493472939190f11dd13b3637a5263..acb9e932cbbe76ed5e11d395de0d4bfc3478041b 100644 (file)
@@ -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<int, io_callback *> 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<int, io_callback *>::iterator it = io_callbacks.find(fd);
+       if (it != io_callbacks.end()) {
+               delete it->second;
+               io_callbacks.erase(it);
+       }
 }