From 50de85396c785a454fe07b77d815c57f3e462282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 15 Sep 2007 20:31:50 +0000 Subject: [PATCH] some remnaming git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20298 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/Application.h | 4 +- src/frontends/qt4/GuiApplication.cpp | 42 ++++++++++++++++----- src/frontends/qt4/GuiApplication.h | 9 +++-- src/frontends/qt4/Makefile.am | 2 - src/frontends/qt4/SocketCallback.cpp | 36 ------------------ src/frontends/qt4/SocketCallback.h | 55 ---------------------------- 6 files changed, 40 insertions(+), 108 deletions(-) diff --git a/src/frontends/Application.h b/src/frontends/Application.h index 3907669f07..90bd21b507 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -203,8 +203,8 @@ public: * add a callback for socket read notification * @param fd socket descriptor (file/socket/etc) */ - virtual void registerSocketCallback( - int fd, boost::function func) = 0; + typedef boost::function SocketCallback; + virtual void registerSocketCallback( int fd, SocketCallback func) = 0; /** * remove a I/O read callback diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index a65f1d0a33..45426165a7 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -16,7 +16,6 @@ #include "qt_helpers.h" #include "GuiImage.h" -#include "SocketCallback.h" #include "frontends/LyXView.h" @@ -45,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -73,12 +73,30 @@ frontend::Application * createApplication(int & argc, char * argv[]) 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) @@ -105,7 +123,7 @@ GuiApplication * guiApp; 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); @@ -165,8 +183,7 @@ GuiApplication::GuiApplication(int & argc, char ** argv) GuiApplication::~GuiApplication() { - delete menu_trans_; - socket_callbacks_.clear(); + socket_notifiers_.clear(); } @@ -321,15 +338,23 @@ void GuiApplication::updateColor(Color_color) } -void GuiApplication::registerSocketCallback(int fd, boost::function func) +void GuiApplication::registerSocketCallback(int fd, SocketCallback func) { - socket_callbacks_[fd] = new SocketCallback(this, fd, 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_notifiers_[fd]->func_(); } void GuiApplication::unregisterSocketCallback(int fd) { - socket_callbacks_.erase(fd); + socket_notifiers_.erase(fd); } @@ -383,8 +408,7 @@ bool GuiApplication::x11EventFilter(XEvent * xev) void GuiApplication::addMenuTranslator() { - menu_trans_ = new MenuTranslator(); - installTranslator(menu_trans_); + installTranslator(new MenuTranslator(this)); } diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 17dfd1a3b5..87b7391e38 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -29,12 +29,12 @@ class QSessionManager; namespace lyx { class BufferView; -class SocketCallback; namespace frontend { class GuiWorkArea; class MenuTranslator; +class SocketNotifier; /// The Qt main application class /** @@ -69,8 +69,7 @@ public: 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 func); + virtual void registerSocketCallback(int fd, SocketCallback func); void unregisterSocketCallback(int fd); //@} @@ -89,6 +88,8 @@ public: private Q_SLOTS: /// void execBatchCommands(); + /// + void socketDataReceived(int fd); private: /// @@ -104,7 +105,7 @@ private: /// QTranslator qt_trans_; /// - std::map socket_callbacks_; + std::map socket_notifiers_; #ifdef Q_WS_X11 public: diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 60e2802bdb..6b3d7bc1db 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -111,7 +111,6 @@ SOURCEFILES = \ LyXFileDialog.cpp \ PanelStack.cpp \ qt_helpers.cpp \ - SocketCallback.cpp \ TocModel.cpp \ TocWidget.cpp \ Validator.cpp @@ -194,7 +193,6 @@ MOCHEADER = \ LyXFileDialog.h \ PanelStack.h \ qlkey.h \ - SocketCallback.h \ TocModel.h \ TocWidget.h \ Validator.h diff --git a/src/frontends/qt4/SocketCallback.cpp b/src/frontends/qt4/SocketCallback.cpp index 83971edd8c..e69de29bb2 100644 --- a/src/frontends/qt4/SocketCallback.cpp +++ b/src/frontends/qt4/SocketCallback.cpp @@ -1,36 +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 - -#include "SocketCallback.h" - - -namespace lyx { - -SocketCallback::SocketCallback(QObject * parent, - int fd, boost::function 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 index 1c6b4633e3..e69de29bb2 100644 --- a/src/frontends/qt4/SocketCallback.h +++ b/src/frontends/qt4/SocketCallback.h @@ -1,55 +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 -#include - -#include - - -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 func); - -public Q_SLOTS: - void dataReceived(); - -private: - /// Our notifier - QSocketNotifier * sn_; - /// The callback function - boost::function func_; -}; - - -} // namespace lyx - -#endif // SOCKET_CALLBACK_H