]> git.lyx.org Git - features.git/commitdiff
Rename class socket_callback into SocketCallback; adjust buidl systems;
authorAndré Pönitz <poenitz@gmx.net>
Sat, 15 Sep 2007 17:47:35 +0000 (17:47 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sat, 15 Sep 2007 17:47:35 +0000 (17:47 +0000)
prevent double deletion of socket notifier

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20296 a592a061-630c-0410-9148-cb99ea01b6c8

development/qmake/qt4/qt4.pro
development/scons/scons_manifest.py
src/frontends/Application.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/Makefile.am
src/frontends/qt4/SocketCallback.cpp [new file with mode: 0644]
src/frontends/qt4/SocketCallback.h [new file with mode: 0644]
src/frontends/qt4/socket_callback.cpp [deleted file]
src/frontends/qt4/socket_callback.h [deleted file]

index 649aa6c768240b6b0f7a47a85177dab48165e3fb..8766ca71644dc2d1cff272cb64b4696227fc8cc7 100644 (file)
@@ -88,7 +88,7 @@ HPP += PanelStack.h
 HPP += pch.h
 HPP += qlkey.h
 HPP += qt_helpers.h
-HPP += socket_callback.h
+HPP += SocketCallback.h
 HPP += TocModel.h
 HPP += TocWidget.h
 HPP += Validator.h
@@ -168,7 +168,7 @@ CPP += LengthCombo.cpp
 CPP += LyXFileDialog.cpp
 CPP += PanelStack.cpp
 CPP += qt_helpers.cpp
-CPP += socket_callback.cpp
+CPP += SocketCallback.cpp
 CPP += TocModel.cpp
 CPP += TocWidget.cpp
 CPP += Validator.cpp
index 4a9e52335bfbefe4712ee8e658b5f1be177073d2..d27ce53a23eb56af52ff452836a39cc70b2f1b4d 100644 (file)
@@ -913,7 +913,7 @@ src_frontends_qt4_header_files = Split('''
     Validator.h
     qlkey.h
     qt_helpers.h
-    socket_callback.h
+    SocketCallback.h
 ''')
 
 
@@ -997,7 +997,7 @@ src_frontends_qt4_files = Split('''
     Validator.cpp
     alert_pimpl.cpp
     qt_helpers.cpp
-    socket_callback.cpp
+    SocketCallback.cpp
 ''')
 
 
index cb8526cd08161db4ec35fc357aa92f86b4f5f0d2..3907669f07767475872e9f764e13e073be1987cc 100644 (file)
@@ -153,7 +153,7 @@ public:
        /// Start the main event loop.
        /// The batch command is programmed to be execute once
        /// the event loop is started.
-       virtual int const exec() = 0;
+       virtual int exec() = 0;
 
        /// Quit running LyX.
        /**
index fa3a2bb549c3f76b13672cb9b4f11871b6acade2..a65f1d0a3367139d39bb49a99d24c59a5fe63ac7 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "qt_helpers.h"
 #include "GuiImage.h"
-#include "socket_callback.h"
+#include "SocketCallback.h"
 
 #include "frontends/LyXView.h"
 
 using std::string;
 using std::endl;
 
-///////////////////////////////////////////////////////////////
-// You can find other X11 specific stuff
-// at the end of this file...
-///////////////////////////////////////////////////////////////
 
-namespace {
+namespace lyx {
 
-int getDPI()
+frontend::Application * createApplication(int & argc, char * argv[])
 {
-       QWidget w;
-       return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
+       return new frontend::GuiApplication(argc, argv);
 }
 
-} // namespace anon
 
+namespace frontend {
 
-namespace lyx {
-
-using support::FileName;
+////////////////////////////////////////////////////////////////////////
+// Mac specific stuff goes here...
 
-frontend::Application * createApplication(int & argc, char * argv[])
+class MenuTranslator : public QTranslator
 {
-       return new frontend::GuiApplication(argc, argv);
-}
+public:
+       QString translate(const char * /*context*/, 
+         const char * sourceText, 
+         const char * /*comment*/ = 0) 
+       {
+               string const s = sourceText;
+               if (s == N_("About %1") || s == N_("Preferences") 
+                               || s == N_("Reconfigure") || s == N_("Quit %1"))
+                       return qt_(s);
+               else 
+                       return QString();
+       }
+};
 
 
-namespace frontend {
+///////////////////////////////////////////////////////////////
+// You can find more platform specific stuff
+// at the end of this file...
+///////////////////////////////////////////////////////////////
 
-GuiApplication * guiApp;
 
+using support::FileName;
 
-GuiApplication::~GuiApplication()
-{
-       socket_callbacks_.clear();
-}
+GuiApplication * guiApp;
 
 
 GuiApplication::GuiApplication(int & argc, char ** argv)
-       : QApplication(argc, argv), Application(argc, argv)
+       : QApplication(argc, argv), Application(argc, argv), menu_trans_(0)
 {
        // Qt bug? setQuitOnLastWindowClosed(true); does not work
        setQuitOnLastWindowClosed(false);
@@ -145,7 +150,8 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        Image::loadableFormats = boost::bind(&GuiImage::loadableFormats);
 
        // needs to be done before reading lyxrc
-       lyxrc.dpi = getDPI();
+       QWidget w;
+       lyxrc.dpi = (w.logicalDpiX() + w.logicalDpiY()) / 2;
 
        LoaderQueue::setPriority(10,100);
 
@@ -157,19 +163,26 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
 }
 
 
-Clipboard& GuiApplication::clipboard()
+GuiApplication::~GuiApplication()
+{
+       delete menu_trans_;
+       socket_callbacks_.clear();
+}
+
+
+Clipboard & GuiApplication::clipboard()
 {
        return clipboard_;
 }
 
 
-Selection& GuiApplication::selection()
+Selection & GuiApplication::selection()
 {
        return selection_;
 }
 
 
-int const GuiApplication::exec()
+int GuiApplication::exec()
 {
        QTimer::singleShot(1, this, SLOT(execBatchCommands()));
        return QApplication::exec();
@@ -297,7 +310,7 @@ bool GuiApplication::getRgbColor(Color_color col,
 
 string const GuiApplication::hexName(Color_color col)
 {
-       return lyx::support::ltrim(fromqstr(color_cache_.get(col).name()), "#");
+       return support::ltrim(fromqstr(color_cache_.get(col).name()), "#");
 }
 
 
@@ -310,8 +323,7 @@ void GuiApplication::updateColor(Color_color)
 
 void GuiApplication::registerSocketCallback(int fd, boost::function<void()> func)
 {
-       socket_callbacks_[fd] =
-               boost::shared_ptr<socket_callback>(new socket_callback(fd, func));
+       socket_callbacks_[fd] = new SocketCallback(this, fd, func);
 }
 
 
@@ -369,36 +381,10 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
 }
 #endif
 
-
-////////////////////////////////////////////////////////////////////////
-// Mac specific stuff goes here...
-
-class MenuTranslator : public QTranslator {
-public:
-       virtual ~MenuTranslator() {};
-       virtual QString translate(const char * context, 
-                                 const char * sourceText, 
-                                 const char * comment = 0) const;
-};
-
-
-QString MenuTranslator::translate(const char * /*context*/, 
-                                 const char * sourceText, 
-                                 const char *) const
-{
-       string const s = sourceText;
-       if (s == N_("About %1") || s == N_("Preferences") 
-           || s == N_("Reconfigure") || s == N_("Quit %1"))
-               return qt_(s);
-       else 
-               return QString();
-}
-
-
 void GuiApplication::addMenuTranslator()
 {
-       menu_trans_.reset(new MenuTranslator());
-       installTranslator(menu_trans_.get());
+       menu_trans_ = new MenuTranslator();
+       installTranslator(menu_trans_);
 }
 
 
index 46a50b45f450869c8505e24658e5c6fe0f726d4d..17dfd1a3b5307c95eaecd95d3ba4e2c2264abfb0 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "frontends/Application.h"
 
-#include <boost/scoped_ptr.hpp>
-
 #include <QApplication>
 #include <QTranslator>
 
@@ -31,7 +29,7 @@ class QSessionManager;
 namespace lyx {
 
 class BufferView;
-class socket_callback;
+class SocketCallback;
 
 namespace frontend {
 
@@ -60,7 +58,7 @@ public:
        virtual Clipboard & clipboard();
        virtual Selection & selection();
        virtual FontLoader & fontLoader() { return font_loader_; }
-       virtual int const exec();
+       virtual int exec();
        virtual Gui & gui() { return gui_; }
        virtual void exit(int status);
        virtual bool event(QEvent * e);
@@ -106,18 +104,18 @@ private:
        ///
        QTranslator qt_trans_;
        ///
-       std::map<int, boost::shared_ptr<socket_callback> > socket_callbacks_;
+       std::map<int, SocketCallback *> socket_callbacks_;
 
 #ifdef Q_WS_X11
 public:
-       bool x11EventFilter (XEvent * ev);
+       bool x11EventFilter(XEvent * ev);
 #endif
 
        /// A translator suitable for the entries in the LyX menu.
        /// Only needed with Qt/Mac.
        void addMenuTranslator();
        ///
-       boost::scoped_ptr<MenuTranslator> menu_trans_;
+       MenuTranslator * menu_trans_;
 }; // GuiApplication
 
 extern GuiApplication * guiApp;
index 63c97c5b176de7bf27aed602061c6bb9512b28c3..60e2802bdba79faf3f4df08c828d1d6d22b9688e 100644 (file)
@@ -111,7 +111,7 @@ SOURCEFILES = \
        LyXFileDialog.cpp \
        PanelStack.cpp \
        qt_helpers.cpp \
-       socket_callback.cpp \
+       SocketCallback.cpp \
        TocModel.cpp \
        TocWidget.cpp \
        Validator.cpp 
@@ -194,7 +194,7 @@ MOCHEADER = \
        LyXFileDialog.h \
        PanelStack.h \
        qlkey.h \
-       socket_callback.h \
+       SocketCallback.h \
        TocModel.h \
        TocWidget.h \
        Validator.h
diff --git a/src/frontends/qt4/SocketCallback.cpp b/src/frontends/qt4/SocketCallback.cpp
new file mode 100644 (file)
index 0000000..83971ed
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * \file io_callback.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author João Luis M. Assirati
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "SocketCallback.h"
+
+
+namespace lyx {
+
+SocketCallback::SocketCallback(QObject * parent,
+               int fd, boost::function<void()> func)
+       : QObject(parent), func_(func)
+{
+       sn_ = new QSocketNotifier(fd, QSocketNotifier::Read, this);
+       connect(sn_, SIGNAL(activated(int)), this, SLOT(dataReceived()));
+}
+
+
+void SocketCallback::dataReceived()
+{
+       func_();
+}
+
+} // namespace lyx
+
+#include "SocketCallback_moc.cpp"
diff --git a/src/frontends/qt4/SocketCallback.h b/src/frontends/qt4/SocketCallback.h
new file mode 100644 (file)
index 0000000..1c6b463
--- /dev/null
@@ -0,0 +1,55 @@
+// -*- C++ -*-
+/**
+ * \file io_callback.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author João Luis M. Assirati
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef SOCKET_CALLBACK_H
+#define SOCKET_CALLBACK_H
+
+#include <QObject>
+#include <QSocketNotifier>
+
+#include <boost/function.hpp>
+
+
+namespace lyx {
+
+/**
+ * socket_callback - a simple wrapper for asynchronous socket notification
+ *
+ * This is used by the lyxsocket to notice the socket is ready to be
+ * connected/read.
+ *
+ * FIXME: this code apparently will not work on Windows.
+ */
+
+class SocketCallback : public QObject
+{
+       Q_OBJECT
+
+public:
+       /// connect a connection notification from the LyXServerSocket
+       SocketCallback(QObject * parent, int fd, boost::function<void()> func);
+
+public Q_SLOTS:
+       void dataReceived();
+
+private:
+       /// Our notifier
+       QSocketNotifier * sn_;
+       /// The callback function
+       boost::function<void()> func_;
+};
+
+
+} // namespace lyx
+
+#endif // SOCKET_CALLBACK_H
diff --git a/src/frontends/qt4/socket_callback.cpp b/src/frontends/qt4/socket_callback.cpp
deleted file mode 100644 (file)
index d3ae298..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * \file io_callback.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- * \author João Luis M. Assirati
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "socket_callback.h"
-
-
-namespace lyx {
-
-socket_callback::socket_callback(int fd, boost::function<void()> func)
-       : func_(func)
-{
-       sn_.reset(new QSocketNotifier(fd, QSocketNotifier::Read, this));
-       connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received()));
-}
-
-
-void socket_callback::data_received()
-{
-       func_();
-}
-
-} // namespace lyx
-
-#include "socket_callback_moc.cpp"
diff --git a/src/frontends/qt4/socket_callback.h b/src/frontends/qt4/socket_callback.h
deleted file mode 100644 (file)
index 7c5b694..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// -*- C++ -*-
-/**
- * \file io_callback.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- * \author João Luis M. Assirati
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef SOCKET_CALLBACK_H
-#define SOCKET_CALLBACK_H
-
-
-#include <QObject>
-#include <QSocketNotifier>
-
-#include <boost/scoped_ptr.hpp>
-#include <boost/function.hpp>
-
-
-namespace lyx {
-
-
-/**
- * socket_callback - a simple wrapper for asynchronous socket notification
- *
- * This is used by the lyxsocket to notice the socket is ready to be
- * connected/read.
- *
- * FIXME: this code apparently will not work on Windows.
- */
-class socket_callback : public QObject {
-       Q_OBJECT
-public:
-       /// connect a connection notification from the LyXServerSocket
-       socket_callback(int fd, boost::function<void()> func);
-public Q_SLOTS:
-       void data_received();
-private:
-       /// our notifier
-       boost::scoped_ptr<QSocketNotifier> sn_;
-       /// The callback function
-       boost::function<void()> func_;
-};
-
-
-} // namespace lyx
-
-#endif // SOCKET_CALLBACK_H