* add a callback for socket read notification
* @param fd socket descriptor (file/socket/etc)
*/
- virtual void registerSocketCallback(
- int fd, boost::function<void()> func) = 0;
+ typedef boost::function<void()> SocketCallback;
+ virtual void registerSocketCallback( int fd, SocketCallback func) = 0;
/**
* remove a I/O read callback
#include "qt_helpers.h"
#include "GuiImage.h"
-#include "SocketCallback.h"
#include "frontends/LyXView.h"
#include <QLibraryInfo>
#include <QPixmapCache>
#include <QSessionManager>
+#include <QSocketNotifier>
#include <QTextCodec>
#include <QTimer>
#include <QTranslator>
namespace frontend {
+class SocketNotifier : public QSocketNotifier
+{
+public:
+ /// connect a connection notification from the LyXServerSocket
+ SocketNotifier(QObject * parent, int fd, Application::SocketCallback func)
+ : QSocketNotifier(fd, QSocketNotifier::Read, parent), func_(func)
+ {}
+
+public:
+ /// The callback function
+ Application::SocketCallback func_;
+};
+
+
////////////////////////////////////////////////////////////////////////
// Mac specific stuff goes here...
class MenuTranslator : public QTranslator
{
public:
+ MenuTranslator(QObject * parent)
+ : QTranslator(parent)
+ {}
+
QString translate(const char * /*context*/,
const char * sourceText,
const char * /*comment*/ = 0)
GuiApplication::GuiApplication(int & argc, char ** argv)
- : QApplication(argc, argv), Application(argc, argv), menu_trans_(0)
+ : QApplication(argc, argv), Application(argc, argv)
{
// Qt bug? setQuitOnLastWindowClosed(true); does not work
setQuitOnLastWindowClosed(false);
GuiApplication::~GuiApplication()
{
- delete menu_trans_;
- socket_callbacks_.clear();
+ socket_notifiers_.clear();
}
}
-void GuiApplication::registerSocketCallback(int fd, boost::function<void()> func)
+void GuiApplication::registerSocketCallback(int fd, SocketCallback func)
+{
+ SocketNotifier * sn = new SocketNotifier(this, fd, func);
+ socket_notifiers_[fd] = sn;
+ connect(sn, SIGNAL(activated(int)), this, SLOT(socketDataReceived(int)));
+}
+
+
+void GuiApplication::socketDataReceived(int fd)
{
- socket_callbacks_[fd] = new SocketCallback(this, fd, func);
+ socket_notifiers_[fd]->func_();
}
void GuiApplication::unregisterSocketCallback(int fd)
{
- socket_callbacks_.erase(fd);
+ socket_notifiers_.erase(fd);
}
void GuiApplication::addMenuTranslator()
{
- menu_trans_ = new MenuTranslator();
- installTranslator(menu_trans_);
+ installTranslator(new MenuTranslator(this));
}
namespace lyx {
class BufferView;
-class SocketCallback;
namespace frontend {
class GuiWorkArea;
class MenuTranslator;
+class SocketNotifier;
/// The Qt main application class
/**
virtual bool getRgbColor(Color_color col, RGBColor & rgbcol);
virtual std::string const hexName(Color_color col);
virtual void updateColor(Color_color col);
- virtual void registerSocketCallback(
- int fd, boost::function<void()> func);
+ virtual void registerSocketCallback(int fd, SocketCallback func);
void unregisterSocketCallback(int fd);
//@}
private Q_SLOTS:
///
void execBatchCommands();
+ ///
+ void socketDataReceived(int fd);
private:
///
///
QTranslator qt_trans_;
///
- std::map<int, SocketCallback *> socket_callbacks_;
+ std::map<int, SocketNotifier *> socket_notifiers_;
#ifdef Q_WS_X11
public:
LyXFileDialog.cpp \
PanelStack.cpp \
qt_helpers.cpp \
- SocketCallback.cpp \
TocModel.cpp \
TocWidget.cpp \
Validator.cpp
LyXFileDialog.h \
PanelStack.h \
qlkey.h \
- SocketCallback.h \
TocModel.h \
TocWidget.h \
Validator.h
-/**
- * \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"
-// -*- 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