From: André Pönitz Date: Sat, 15 Sep 2007 17:47:35 +0000 (+0000) Subject: Rename class socket_callback into SocketCallback; adjust buidl systems; X-Git-Tag: 1.6.10~8335 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d348b0183bc02752102f50387d07947e1a602986;p=features.git Rename class socket_callback into SocketCallback; adjust buidl systems; prevent double deletion of socket notifier git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20296 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/qmake/qt4/qt4.pro b/development/qmake/qt4/qt4.pro index 649aa6c768..8766ca7164 100644 --- a/development/qmake/qt4/qt4.pro +++ b/development/qmake/qt4/qt4.pro @@ -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 diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 4a9e52335b..d27ce53a23 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -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 ''') diff --git a/src/frontends/Application.h b/src/frontends/Application.h index cb8526cd08..3907669f07 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -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. /** diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index fa3a2bb549..a65f1d0a33 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -16,7 +16,7 @@ #include "qt_helpers.h" #include "GuiImage.h" -#include "socket_callback.h" +#include "SocketCallback.h" #include "frontends/LyXView.h" @@ -62,45 +62,50 @@ 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 func) { - socket_callbacks_[fd] = - boost::shared_ptr(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_); } diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 46a50b45f4..17dfd1a3b5 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -21,8 +21,6 @@ #include "frontends/Application.h" -#include - #include #include @@ -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 > socket_callbacks_; + std::map 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 menu_trans_; + MenuTranslator * menu_trans_; }; // GuiApplication extern GuiApplication * guiApp; diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 63c97c5b17..60e2802bdb 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -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 index 0000000000..83971edd8c --- /dev/null +++ b/src/frontends/qt4/SocketCallback.cpp @@ -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 + +#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 new file mode 100644 index 0000000000..1c6b4633e3 --- /dev/null +++ b/src/frontends/qt4/SocketCallback.h @@ -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 +#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 diff --git a/src/frontends/qt4/socket_callback.cpp b/src/frontends/qt4/socket_callback.cpp deleted file mode 100644 index d3ae2983b5..0000000000 --- a/src/frontends/qt4/socket_callback.cpp +++ /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 - -#include "socket_callback.h" - - -namespace lyx { - -socket_callback::socket_callback(int fd, boost::function 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 index 7c5b69460a..0000000000 --- a/src/frontends/qt4/socket_callback.h +++ /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 -#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 socket_callback : public QObject { - Q_OBJECT -public: - /// connect a connection notification from the LyXServerSocket - socket_callback(int fd, boost::function func); -public Q_SLOTS: - void data_received(); -private: - /// our notifier - boost::scoped_ptr sn_; - /// The callback function - boost::function func_; -}; - - -} // namespace lyx - -#endif // SOCKET_CALLBACK_H