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
This commit is contained in:
André Pönitz 2007-09-15 17:47:35 +00:00
parent ea0e5ee1d8
commit d348b0183b
8 changed files with 76 additions and 89 deletions

View 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

View 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
''')

View 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.
/**

View File

@ -16,7 +16,7 @@
#include "qt_helpers.h"
#include "GuiImage.h"
#include "socket_callback.h"
#include "SocketCallback.h"
#include "frontends/LyXView.h"
@ -62,26 +62,9 @@
using std::string;
using std::endl;
///////////////////////////////////////////////////////////////
// You can find other X11 specific stuff
// at the end of this file...
///////////////////////////////////////////////////////////////
namespace {
int getDPI()
{
QWidget w;
return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
}
} // namespace anon
namespace lyx {
using support::FileName;
frontend::Application * createApplication(int & argc, char * argv[])
{
return new frontend::GuiApplication(argc, argv);
@ -90,17 +73,39 @@ frontend::Application * createApplication(int & argc, char * argv[])
namespace frontend {
////////////////////////////////////////////////////////////////////////
// Mac specific stuff goes here...
class MenuTranslator : public QTranslator
{
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();
}
};
///////////////////////////////////////////////////////////////
// You can find more platform specific stuff
// at the end of this file...
///////////////////////////////////////////////////////////////
using support::FileName;
GuiApplication * guiApp;
GuiApplication::~GuiApplication()
{
socket_callbacks_.clear();
}
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,6 +163,13 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
}
GuiApplication::~GuiApplication()
{
delete menu_trans_;
socket_callbacks_.clear();
}
Clipboard & GuiApplication::clipboard()
{
return clipboard_;
@ -169,7 +182,7 @@ Selection& GuiApplication::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_);
}

View 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,7 +104,7 @@ 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:
@ -117,7 +115,7 @@ public:
/// Only needed with Qt/Mac.
void addMenuTranslator();
///
boost::scoped_ptr<MenuTranslator> menu_trans_;
MenuTranslator * menu_trans_;
}; // GuiApplication
extern GuiApplication * guiApp;

View 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

View File

@ -12,24 +12,25 @@
#include <config.h>
#include "socket_callback.h"
#include "SocketCallback.h"
namespace lyx {
socket_callback::socket_callback(int fd, boost::function<void()> func)
: func_(func)
SocketCallback::SocketCallback(QObject * parent,
int fd, boost::function<void()> func)
: QObject(parent), func_(func)
{
sn_.reset(new QSocketNotifier(fd, QSocketNotifier::Read, this));
connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received()));
sn_ = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(sn_, SIGNAL(activated(int)), this, SLOT(dataReceived()));
}
void socket_callback::data_received()
void SocketCallback::dataReceived()
{
func_();
}
} // namespace lyx
#include "socket_callback_moc.cpp"
#include "SocketCallback_moc.cpp"

View File

@ -14,17 +14,14 @@
#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
*
@ -33,16 +30,21 @@ namespace lyx {
*
* FIXME: this code apparently will not work on Windows.
*/
class socket_callback : public QObject {
class SocketCallback : public QObject
{
Q_OBJECT
public:
/// connect a connection notification from the LyXServerSocket
socket_callback(int fd, boost::function<void()> func);
SocketCallback(QObject * parent, int fd, boost::function<void()> func);
public Q_SLOTS:
void data_received();
void dataReceived();
private:
/// our notifier
boost::scoped_ptr<QSocketNotifier> sn_;
/// Our notifier
QSocketNotifier * sn_;
/// The callback function
boost::function<void()> func_;
};