Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Oct 2004 08:12:14 +0200 (CEST)
From:      Jean-Yves Lefort <jylefort@brutele.be>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/73063: New port: misc/translator, a GTK+ frontend to the Babelfish translation service
Message-ID:  <20041024061214.53C0F22E09@jsite.lefort.net>
Resent-Message-ID: <200410240620.i9O6KA0i044266@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         73063
>Category:       ports
>Synopsis:       New port: misc/translator, a GTK+ frontend to the Babelfish translation service
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 24 06:20:10 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Jean-Yves Lefort
>Release:        FreeBSD 5.3-BETA6 i386
>Organization:
>Environment:
System: FreeBSD jsite.lefort.net 5.3-BETA6 FreeBSD 5.3-BETA6 #0: Tue Sep 28 00:10:28 CEST 2004 jylefort@jsite.lefort.net:/usr/obj/usr/src/sys/JSITE i386
>Description:
Depends on 73062.
>How-To-Repeat:
>Fix:
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	translator
#	translator/pkg-plist
#	translator/pkg-descr
#	translator/distinfo
#	translator/Makefile
#	translator/files
#	translator/files/patch-translator.pl
#
echo c - translator
mkdir -p translator > /dev/null 2>&1
echo x - translator/pkg-plist
sed 's/^X//' >translator/pkg-plist << 'END-of-translator/pkg-plist'
Xbin/translator
Xshare/gnome/pixmaps/translator.png
Xshare/translator/translator.glade
X@dirrm share/translator
END-of-translator/pkg-plist
echo x - translator/pkg-descr
sed 's/^X//' >translator/pkg-descr << 'END-of-translator/pkg-descr'
XTranslator is a simple front-end to AltaVista's excellent
XBabelfish. It is designed to integrate into the GNOME desktop, and as
Xsuch features an (almost) HIG compliant interface, and support for
XGNOME's HTTP proxy settings.
X
XWWW: http://jodrell.net/projects/translator/
X
X- Jean-Yves Lefort
Xjylefort@brutele.be
END-of-translator/pkg-descr
echo x - translator/distinfo
sed 's/^X//' >translator/distinfo << 'END-of-translator/distinfo'
XMD5 (translator-0.1.0.tar.gz) = abaae4506a2ea366b35423289034eeaf
XSIZE (translator-0.1.0.tar.gz) = 17214
END-of-translator/distinfo
echo x - translator/Makefile
sed 's/^X//' >translator/Makefile << 'END-of-translator/Makefile'
X# New ports collection makefile for:	translator
X# Date created:			24 Oct 2004
X# Whom:				Jean-Yves Lefort <jylefort@brutele.be>
X#
X# $FreeBSD$
X#
X
XPORTNAME=		translator
XPORTVERSION=		0.1.0
XCATEGORIES=		misc
XMASTER_SITES=		http://jodrell.net/files/translator/
X
XMAINTAINER=		jylefort@brutele.be
XCOMMENT=		A GTK+ frontend to the Babelfish translation service
X
XRUN_DEPENDS=		${SITE_PERL}/${PERL_ARCH}/Gtk2.pm:${PORTSDIR}/x11-toolkits/p5-Gtk2 \
X			${SITE_PERL}/${PERL_ARCH}/Gtk2/GladeXML.pm:${PORTSDIR}/x11-toolkits/p5-Glade2 \
X			${SITE_PERL}/${PERL_ARCH}/Gnome2/GConf.pm:${PORTSDIR}/devel/p5-Gnome2-GConf \
X			${SITE_PERL}/WWW/Babelfish.pm:${PORTSDIR}/www/p5-WWW-Babelfish
X
XUSE_X_PREFIX=		yes
XUSE_PERL5=		yes
XNO_BUILD=		yes
X
X.include <bsd.port.pre.mk>
X
X.if ${PERL_LEVEL} < 500800
XIGNORE=			requires Perl 5.8.0 or superior
X.endif
X
Xpre-everything::
X	@if ! ${PERL} -mthreads -e '' >/dev/null 2>&1; then \
X		${ECHO_CMD} "Your installation of Perl does not support threads. The most straightforward "; \
X		${ECHO_CMD} "way to have a threads-enabled Perl is to install the lang/perl5.8 port, "; \
X		${ECHO_CMD} "enabling the WITH_THREADS knob."; \
X		exit 1; \
X	fi
X
Xpost-patch:
X	@${SED} -e \
X		's|share/pixmaps|share/gnome/pixmaps| ; \
X		 s|@PREFIX@|${PREFIX}|' \
X		${WRKSRC}/translator.pl > ${WRKSRC}/translator
X
Xdo-install:
X	${MKDIR} ${PREFIX}/bin
X	${INSTALL_SCRIPT} ${WRKSRC}/translator ${PREFIX}/bin
X	${MKDIR} ${PREFIX}/share/gnome/pixmaps
X	${INSTALL_DATA} ${WRKSRC}/translator.png ${PREFIX}/share/gnome/pixmaps
X	${MKDIR} ${PREFIX}/share/translator
X	${INSTALL_DATA} ${WRKSRC}/translator.glade ${PREFIX}/share/translator
X
X.include <bsd.port.post.mk>
END-of-translator/Makefile
echo c - translator/files
mkdir -p translator/files > /dev/null 2>&1
echo x - translator/files/patch-translator.pl
sed 's/^X//' >translator/files/patch-translator.pl << 'END-of-translator/files/patch-translator.pl'
X--- translator.pl.orig	Fri Dec 19 12:50:02 2003
X+++ translator.pl	Sun Oct 24 08:08:53 2004
X@@ -2,24 +2,22 @@
X # nifty front-end to Altavista's Babel Fish.
X # $Id: translator.pl,v 1.13 2003/12/19 11:50:02 jodrell Exp $
X use WWW::Babelfish;
X-use IO::Scalar;
X use threads;
X use threads::shared;
X+use Thread::Queue;
X use File::Basename qw(basename);
X-use Data::Dumper;
X use strict;
X 
X #
X # these are shared between the main thread and the worker:
X #
X-my @queue	: shared;
X+my $input_queue = new Thread::Queue;
X+my $output_queue = new Thread::Queue;
X+
X my @errors	: shared;
X-my $finished	: shared;
X-my $output	: shared;
X my $source	: shared;
X my $dest	: shared;
X my $running	: shared;
X-my $pending	: shared;
X my $proxy	: shared;
X 
X #
X@@ -30,9 +28,6 @@
X #
X # set up the application:
X #
X-$finished = 0;
X-$pending  = 0;
X-
X my $NAME	= 'Translator';
X my $VERSION	= '0.1.0';
X my $RCFILE	= sprintf('%s/.%src', $ENV{HOME}, lc($NAME));
X@@ -80,24 +75,25 @@
X # places output into the $output array, and we need to keep the entry up to date:
X #
X Glib::Timeout->add(50, sub {
X-	if ($pending == 1) {
X-		$app->get_widget('output')->get_buffer->set_text($output) ;
X-		$pending = 0;
X+	if (defined(my $output = $output_queue->dequeue_nb)) {
X+		$app->get_widget('output')->get_buffer->set_text($output);
X 	}
X-	if ($running == 1) {
X-		$app->get_widget('main_window')->get_root_window->set_cursor($busy);
X-		$app->get_widget('translate_button')->set_sensitive(0);
X-		$app->get_widget('input')->set_editable(0);
X-	} else {
X-		$app->get_widget('main_window')->get_root_window->set_cursor($normal);
X-		$app->get_widget('translate_button')->set_sensitive(1);
X-		$app->get_widget('input')->set_editable(1);
X+
X+	{
X+		lock($running);
X+		$app->get_widget('main_window')->get_root_window->set_cursor($running ? $busy: $normal);
X+		$app->get_widget('translate_button')->set_sensitive(! $running);
X+		$app->get_widget('input')->set_editable(! $running);
X 	}
X-	if (scalar(@errors) > 0) {
X-		my $error_dialog = Gtk2::MessageDialog->new($app->get_widget('main_window'), 'modal', 'error', 'ok', shift(@errors));
X-		$error_dialog->set_icon($app->get_widget('main_window')->get_icon);
X-		$error_dialog->signal_connect('response', sub { $error_dialog->destroy });
X-		$error_dialog->show_all;
X+
X+	{
X+		lock(@errors);
X+		if (scalar(@errors) > 0) {
X+			my $error_dialog = Gtk2::MessageDialog->new($app->get_widget('main_window'), 'modal', 'error', 'ok', shift(@errors));
X+			$error_dialog->set_icon($app->get_widget('main_window')->get_icon);
X+			$error_dialog->signal_connect('response', sub { $error_dialog->destroy });
X+			$error_dialog->show_all;
X+		}
X 	}
X 	return 1;
X });
X@@ -107,46 +103,60 @@
X Gtk2->main;
X 
X sub worker {
X-	my $fish = WWW::Babelfish->new;
X+	my $fish = WWW::Babelfish->new(agent => 'Mozilla/8.0');
X 	$fish->{ua}->timeout(10);
X-	while ($finished == 0) {
X-		if (scalar(@queue) > 0) {
X+	while (my $input = $input_queue->dequeue) {
X+		my $output = '';
X+		{
X+			lock($running);
X 			$running = 1;
X-			$output = '';
X-			my $input = shift(@queue);
X-			my $fh = IO::Scalar->new(\$output);
X+		}
X+		open my $fh, ">", \$output or die;
X+		{
X+			lock($proxy);
X 			if ($proxy ne '') {
X 				$fish->{proxy} = $proxy;
X 				$fish->{ua}->proxy('http', 'http://'.$proxy.'/');
X 			}
X+		}
X+		{
X+			lock($source);
X+			lock($dest);
X 			if (!$fish->translate(
X 				source		=> $source,
X 				destination	=> $dest,
X 				ofh		=> $fh,
X 				text		=> $input,
X 			)) {
X+				lock(@errors);
X 				push(@errors, "Error: $!");
X 			}
X-			$pending = 1;
X-		} else {
X+		}
X+		{
X+			lock($running);
X 			$running = 0;
X-			threads->yield;
X 		}
X+		$output_queue->enqueue($output);
X 	}
X-	return 1;
X }
X 
X sub close_program {
X 	save_options();
X-	$finished = 1;
X+	$input_queue->enqueue(undef);	# terminate the worker thread
X 	Gtk2->main_quit;
X 	$worker->join;	
X 	exit;
X }
X 
X sub translate {
X-	$source = $app->get_widget('from_combo')->entry->get_text;
X-	$dest   = $app->get_widget('to_combo')->entry->get_text;
X+	{
X+		lock($source);
X+		$source = $app->get_widget('from_combo')->entry->get_text;
X+	}
X+	{
X+		lock($dest);
X+		$dest   = $app->get_widget('to_combo')->entry->get_text;
X+	}
X 	my $input = $app->get_widget('input')->get_buffer->get_text(
X 		$app->get_widget('input')->get_buffer->get_start_iter,
X 		$app->get_widget('input')->get_buffer->get_end_iter,
X@@ -159,9 +169,12 @@
X 		} else {
X 			$message = 'Please enter some text to translate.';
X 		}
X-		push(@errors, $message);
X+		{
X+			lock(@errors);
X+			push(@errors, $message);
X+		}
X 	} else {
X-		push(@queue, $input);
X+		$input_queue->enqueue($input);
X 	}
X 	return 1;
X }
X@@ -284,6 +297,7 @@
X }
X 
X sub source_changed {
X+	lock($source);
X 	$source = $app->get_widget('from_combo')->entry->get_text;
X 	return undef if ($source eq '');
X 	$app->get_widget('to_combo')->set_popdown_strings(sort(keys(%{$pairs->{$source}})));
X@@ -292,6 +306,7 @@
X 
X sub set_proxy {
X 	if ($client->get_bool($use_proxy_key) == 1) {
X+		lock($proxy);
X 		$proxy = sprintf(
X 			'%s:%d',
X 			$client->get_string($proxy_host),
END-of-translator/files/patch-translator.pl
exit

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041024061214.53C0F22E09>