Skip to content

Commit

Permalink
Handle all HTTP notifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jul 9, 2018
1 parent daf38b4 commit 9157f16
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 24 deletions.
68 changes: 45 additions & 23 deletions src/YQDialog.cc
Expand Up @@ -49,6 +49,8 @@
#include "QY2Styler.h"
#include "QY2StyleEditor.h"

#include <boost/foreach.hpp>

// Include low-level X headers AFTER Qt headers:
// X.h pollutes the global namespace (!!!) with pretty useless #defines
// like "Above", "Below" etc. that clash with some Qt headers.
Expand All @@ -66,7 +68,6 @@ YQDialog::YQDialog( YDialogType dialogType,
: QWidget( chooseParent( dialogType ),
dialogType == YPopupDialog ? YQPopupDialogWFlags : YQMainDialogWFlags )
, YDialog( dialogType, colorMode )
, _notifier(nullptr)
{
setWidgetRep( this );

Expand Down Expand Up @@ -128,10 +129,17 @@ YQDialog::YQDialog( YDialogType dialogType,
QY2Styler::styler()->registerWidget( this );
}

void YQDialog::clearHttpNotifiers() {
BOOST_FOREACH(QSocketNotifier *_notifier, _http_notifiers)
{
delete _notifier;
}
_http_notifiers.clear();
}

YQDialog::~YQDialog()
{
if (_notifier) delete _notifier;
clearHttpNotifiers();

if ( isMainDialog() )
{
Expand Down Expand Up @@ -767,16 +775,8 @@ void
YQDialog::httpData()
{
YUI::server()->process_data();
YUI::server()->process_data();

if (_notifier->socket() != YUI::server()->socket_fd())
{
yuiMilestone() << "Updating notifier" << std::endl;
delete _notifier;
_notifier = new QSocketNotifier( YUI::server()->socket_fd(), QSocketNotifier::Read );
QObject::connect( _notifier, &pclass(_notifier)::activated,
this, &pclass(this)::httpData);
}
createHttpNotifiers();

// process the event loop for a while to redraw the widgets on the screen
_eventLoop->processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 1000);
Expand All @@ -790,6 +790,37 @@ YQDialog::httpData()
// }
}

void YQDialog::createHttpNotifiers()
{
clearHttpNotifiers();

if (YUI::server())
{
YHttpServerSockets sockets = YUI::server()->sockets();

BOOST_FOREACH(int s, sockets.read())
{
QSocketNotifier *_notifier = new QSocketNotifier( s, QSocketNotifier::Read );
QObject::connect( _notifier, &pclass(_notifier)::activated,
this, &pclass(this)::httpData);
}

BOOST_FOREACH(int s, sockets.write())
{
QSocketNotifier *_notifier = new QSocketNotifier( s, QSocketNotifier::Write );
QObject::connect( _notifier, &pclass(_notifier)::activated,
this, &pclass(this)::httpData);
}

BOOST_FOREACH(int s, sockets.exception())
{
QSocketNotifier *_notifier = new QSocketNotifier( s, QSocketNotifier::Exception );
QObject::connect( _notifier, &pclass(_notifier)::activated,
this, &pclass(this)::httpData);
}
}
}

YEvent *
YQDialog::waitForEventInternal( int timeout_millisec )
{
Expand All @@ -810,23 +841,14 @@ YQDialog::waitForEventInternal( int timeout_millisec )

if ( ! _eventLoop->isRunning() )
{
if (YUI::server())
{
_notifier = new QSocketNotifier( YUI::server()->socket_fd(), QSocketNotifier::Read );
QObject::connect( _notifier, &pclass(_notifier)::activated,
this, &pclass(this)::httpData);
}
createHttpNotifiers();

#if VERBOSE_EVENT_LOOP
yuiDebug() << "Executing event loop for " << this << std::endl;
#endif
_eventLoop->exec();

if (_notifier)
{
delete _notifier;
_notifier = nullptr;
}

clearHttpNotifiers();

#if VERBOSE_EVENT_LOOP
yuiDebug() << "Event loop finished for " << this << std::endl;
Expand Down
6 changes: 5 additions & 1 deletion src/YQDialog.h
Expand Up @@ -32,6 +32,8 @@
#include <QPalette>
#include <yui/YDialog.h>

#include <vector>

class YQGenericButton;
class YQWizard;
class QEventLoop;
Expand Down Expand Up @@ -283,6 +285,8 @@ protected slots:
virtual void focusInEvent ( QFocusEvent * event );
virtual void resizeEvent ( QResizeEvent * event );

void clearHttpNotifiers();
void createHttpNotifiers();

//
// Data members
Expand All @@ -300,7 +304,7 @@ protected slots:
QPalette _preHighlightPalette;
bool _preHighlightAutoFill;
QY2StyleEditor* _styleEditor;
QSocketNotifier* _notifier;
std::vector<QSocketNotifier*> _http_notifiers;

};

Expand Down

0 comments on commit 9157f16

Please sign in to comment.