#!/usr/bin/perl -w
# -*- perl -*-

#
# $Id: bbbikeapplet,v 1.3 2001/03/25 17:12:53 eserte Exp $
# Author: Slaven Rezic
#
# Copyright (C) 2001 Slaven Rezic. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# Mail: eserte@cs.tu-berlin.de
# WWW:  http://user.cs.tu-berlin.de/~eserte/
#

# XXX kann noch nicht aus dem Panel heraus aktiviert werden
# vgl. Sourcen von fish_applet: APPLET_(DE)ACTIVATE müsste irgendwie
# implementiert werden

use Gtk;
use Gnome;
use Getopt::Long;
use FindBin;
use strict;

use vars qw($mw
	    $is_applet $goad_server $goad_fd);
$is_applet = 1;
# XXX is_applet is not actually necessary... try Gnome::Applet with eval
if (!GetOptions("applet!" => \$is_applet,
		"activate-goad-server=s" => \$goad_server,
		"goad-fd=s" => \$goad_fd,
	       )) {
    die "usage";
}

#warn $goad_server;
#warn $goad_fd;

if ($is_applet) {
    Gnome::Panel::AppletWidget->init('BBBike applet');
    $mw = Gnome::Panel::AppletWidget->new('BBBike applet');
    realize $mw;
} else {
    Gtk->init;
    $mw = Gtk::Window->new(-toplevel);
}

$mw->set_title("BBBike applet");

my $vbox = new Gtk::VBox(0,0);
$mw->add($vbox);
my $hbox_start = new Gtk::HBox(0,0);
$vbox->pack_start($hbox_start, 1, 1, 0);
my $hbox_ziel  = new Gtk::HBox(0,0);
$vbox->pack_start($hbox_ziel, 1, 1, 0);

my $sl = new Gtk::Label("Start:");
$hbox_start->pack_start($sl, 1, 1, 0);
my $se = new Gtk::Entry;
$hbox_start->pack_start($se, 1, 1, 0);

my $zl = new Gtk::Label("Ziel:");
$hbox_ziel->pack_start($zl, 1, 1, 0);
my $ze = new Gtk::Entry;
$hbox_ziel->pack_start($ze, 1, 1, 0);

$se->signal_connect('activate', \&set_start);
$ze->signal_connect('activate', \&start_bbbike);

$se->grab_focus;
$mw->show_all;

if ($is_applet) {
    Gnome::Panel::AppletWidget->gtk_main;
} else {
    Gtk->main;
}

sub set_start {
    if (fork == 0) {
	exec $^X, "$FindBin::RealBin/bbbikeclient",
	    "-nostartserver",
	    -from => $se->get_text;
	warn $!;
	CORE::exit();
    }
    $ze->grab_focus;
}

sub start_bbbike {
    if (fork == 0) {
	exec $^X, "$FindBin::RealBin/bbbikeclient",
	    -from => $se->get_text, -to => $ze->get_text;
	warn $!;
	CORE::exit();
    }
    $se->grab_focus;
}

__END__

=head1 NAME

bbbikeapplet - GNOME applet for searching bbbike routes

=head1 SYNOPSIS

    bbbikeapplet [-noapplet]

=head1 DESCRIPTION

=head1 AUTHOR

Slaven Rezic <slaven@rezic.de>

=head1 SEE ALSO

bbbike(1), Gtk(3), Gnome(3)

=cut
