AnyEvent

 view release on metacpan or  search on metacpan

lib/AnyEvent/Impl/Qt.pm  view on Meta::CPAN


=cut

package AnyEvent::Impl::Qt::Io;

use Qt;
use Qt::isa qw(Qt::SocketNotifier); # Socket? what where they smoking
use Qt::slots cb => [];

sub NEW {
   my ($class, $fh, $mode, $cb) = @_;
   shift->SUPER::NEW (fileno $fh, $mode);
   this->{fh} = $fh;
   this->{cb} = $cb;
   this->connect (this, SIGNAL "activated(int)", SLOT "cb()");
}

sub cb {
   this->setEnabled (0); # required according to the docs. heavy smoking required.
   this->{cb}->();
   this->setEnabled (1);
}

package AnyEvent::Impl::Qt::Timer;

use Qt;
use Qt::isa qw(Qt::Timer);
use Qt::slots cb => [];

# having to go through these contortions just to get a timer event is
# considered an advantage over other gui toolkits how?

sub NEW {
   my ($class, $after, $interval, $cb) = @_;
   shift->SUPER::NEW ();
   this->{interval} = $interval;
   this->{cb}       = $cb;
   this->connect (this, SIGNAL "timeout()", SLOT "cb()");
   this->start ($after, 1);
}

sub cb {
   this->start (this->{interval}, 1) if defined this->{interval};
   this->{cb}->();
}

package AnyEvent::Impl::Qt;

use AnyEvent (); BEGIN { AnyEvent::common_sense }
use Qt;

use AnyEvent::Impl::Qt::Timer;
use AnyEvent::Impl::Qt::Io;

our $app = Qt::Application \@ARGV; # REQUIRED!

sub io {
   my ($class, %arg) = @_;

   # work around these bugs in Qt:
   # - adding a callback might destroy other callbacks
   # - only one callback per fd/poll combination
   my ($fh, $qt) = AnyEvent::_dupfh $arg{poll}, $arg{fh},
                      Qt::SocketNotifier::Read (), Qt::SocketNotifier::Write ();

   AnyEvent::Impl::Qt::Io $fh, $qt, $arg{cb}
}

sub timer {
   my ($class, %arg) = @_;
   
   # old Qt treats 0 timeout as "idle"
   AnyEvent::Impl::Qt::Timer
      $arg{after} * 1000 || 1,
      $arg{interval} ? $arg{interval} * 1000 || 1 : undef,
      $arg{cb}
}

# newer Qt have no idle mode for timers anymore...
#sub idle {
#   my ($class, %arg) = @_;
#   
#   AnyEvent::Impl::Qt::Timer 0, 0, $arg{cb}
#}

#sub loop {
#   Qt::app->exec;
#}

sub _poll {
   Qt::app->processOneEvent;
}

sub AnyEvent::CondVar::Base::_wait {
   Qt::app->processOneEvent until exists $_[0]{_ae_sent};
}

=head1 SEE ALSO

L<AnyEvent>, L<Qt>.

=head1 AUTHOR

   Marc Lehmann <schmorp@schmorp.de>
   http://anyevent.schmorp.de

=cut

1



( run in 0.801 second using v1.01-cache-2.11-cpan-39bf76dae61 )