#!/usr/bin/perl -w
#
# A Gnome TV show viewer
#

# XMLTVHandler

package XMLTVHandler;
use strict;
use warnings;
use threads;
use threads::shared;
use utf8;
use Encode qw/decode/;
use LWP::Simple qw/get/;
use XMLTV;

my $lock : shared = 1;

my $DEBUG = 0;

# XMLTV

my $encoding;
my $credits;

my %chan_map             : shared;
my %program_title_map    : shared;
my %program_channel_map  : shared;
my %program_start_map    : shared;
my %program_stop_map     : shared;
my %program_desc_map     : shared;
my %program_category_map : shared;
my %date_map             : shared;
my $file                 : shared;
my $imagedir             : shared;
my $load_images          : shared = 0;

my $maxvalue   : shared = undef;
my $value      : shared = undef;
my $imagemax   : shared = 0;
my $imagevalue : shared = 0;

my $imagemap;

sub new {
  $file = shift;

  my $self = {};
  bless $self;

  print "XMLTVHandler: new()\n" if ($DEBUG);
  my $start = time;
  $self->{thread} = threads->new(\&main, $self);
  my $stop  = time;
  print "XMLTVHandler: Thread creation took " . ($stop - $start) . " seconds.\n" if ($DEBUG);
  return $self;
}

sub trigger {
  my $self = shift;

  my $command = shift;

  if (defined ($command)) {
    $lock = $command;
  }

  lock $lock;
  cond_signal($lock);
}

sub stop {
  my $self = shift;

  $lock = 0;
  trigger();
  $self->{thread}->join();
}

sub set_file {
  my $self = shift;
  $file    = shift;
}

sub set_imagedir {
  my $self     = shift;
  $imagedir    = shift;
}

sub set_load_images {
  my $self     = shift;
  $load_images = shift;
}

sub main {
  my $self = shift;
  print "XMLTVHandler: Started.\n" if ($DEBUG);

  while (1) {
    print "XMLTVHandler: Taking a lock.\n" if ($DEBUG);
    lock $lock;
    print "XMLTVHandler: Waiting for signal.\n" if ($DEBUG);
    cond_wait $lock;

    if ($lock == 0) {
      print "XMLTVHandler: Got a stop signal.\n" if ($DEBUG);
      return;
    }

    print "XMLTVHandler: Got a job.\n" if ($DEBUG);

    if ($lock == 1) {
      parse_xmltvfile();

      if (defined ($load_images) && $load_images) {
	get_images();
      }
    } elsif ($lock == 2) {
      if (defined ($load_images) && $load_images) {
	get_images();
      }
      $lock = 1;
    }

    print "XMLTVHandler: Performed a job.\n" if ($DEBUG);
  }

  print "XMLTVHandler: Stopped.\n" if ($DEBUG);
}

# XMLTV xml file parser

sub parse_xmltvfile {
  my $document  = "";

  %chan_map            = ();
  %program_title_map   = ();
  %program_channel_map = ();
  %program_start_map   = ();
  %program_stop_map    = ();
  %program_desc_map    = ();
  $imagemap            = undef;

  my $start = time;

  if (defined ($file) && open (READ, $file)) {
    while (<READ>) {
      $document = $document . $_;
    }
    $value    = 0;
    $maxvalue = 0;

    while ($document =~ /<programme/go) {
      $maxvalue++;
    }

    print "XMLTVHandler: programme count is $maxvalue\n" if ($DEBUG);

    XMLTV::parse_callback($document, \&encoding_cb, \&credits_cb,
			  \&channel_cb, \&programme_cb);
    $value = 0;
    $maxvalue = 0;
    print "XMLTVHandler: Got " . (keys %chan_map) . " channels\n" if ($DEBUG);
  } else {
    print "XMLTVHandler: couldn't open file $file\n" if ($DEBUG);
  }
  my $stop = time;

  print "XMLTVHandler: Parsing xmltv file took " . ($stop - $start) ." seconds.\n" if ($DEBUG);
}

sub encoding_cb( $ ) { $encoding = shift }
sub credits_cb( $ )  { $credits  = shift }

# The callback for each channel populates this hash.

sub channel_cb( $ ) {
  my $c = shift;

  my $d = decodestr($c->{'display-name'}->[0]->[0]);

  $chan_map{$c->{id}} = $d;

  my $icon = $c->{icon}->[0]->{src};

  if (defined ($icon)) {
    my $pre = $imagedir . $c->{id};
    my $pic = myglob($pre . ".*");

    unless (defined ($pic)) {
      $imagemap->{$c->{id}}->{id}   = $c->{id};
      $imagemap->{$c->{id}}->{file} = $pre;
      $imagemap->{$c->{id}}->{url}  = $icon;
    } else {
      print "XMLTVHandler: not fetching icon " . $c->{id} . " since it already exists.\n" if ($DEBUG);
    }
  } else {
    print "XMLTVHandler: no icon defined.\n" if ($DEBUG);
  }
}

sub programme_cb( $ ) {
  my $p = shift;

  my $title   = undef;
  my $channel = undef;
  my $start   = undef;
  my $stop    = undef;
  my $desc    = undef;
  my $cat     = undef;

  {
    no warnings;

    $title   = decodestr($p->{'title'}->[0]->[0]);
    $channel = decodestr($p->{'channel'});
    $start   = defined ($p->{'start'}) ? decodestr(substr($p->{'start'}, 0, 14)) : undef;
    $stop    = defined ($p->{'stop'}) ? decodestr(substr($p->{'stop'}, 0, 14)) : undef;
    $desc    = decodestr($p->{'desc'}->[0]->[0]);
    $cat     = decodestr($p->{'category'}->[0]->[0]);

    if (defined ($p->{'sub-title'}->[0]->[0])) {
      $title = $title . " : " . decodestr($p->{'sub-title'}->[0]->[0]);
    }
  }

  my $id = $channel . "." . $start;

  $program_title_map{$id}    = $title;
  $program_channel_map{$id}  = $channel;
  $program_start_map{$id}    = $start;
  $program_stop_map{$id}     = $stop;
  $program_desc_map{$id}     = $desc;
  $program_category_map{$id} = $cat;

  my $date = substr($start, 0, 8);
  unless (defined ($date_map{$date})) {
    $date_map{$date} = $date;
  }

  $value++;
  threads->yield();
}

sub decodestr {
  if ( $encoding ) { return decode($encoding, $_[0]) } else { return $_[0] };
};

sub get_value {
  return $value;
}

sub get_max_value {
  return $maxvalue;
}

sub get_channel_map {
  return %chan_map;
}

sub get_dates {
  keys %date_map;
}

sub get_imagevalue {
  $imagevalue;
}
sub get_imagemax {
  $imagemax;
}

sub get_program_tree {
  my $program_tree = {};

  my $title   = undef;
  my $channel = undef;
  my $start   = undef;
  my $stop    = undef;
  my $desc    = undef;
  my $id      = undef;
  my $cat     = undef;

  foreach $id (keys %program_title_map) {
    $title = $program_title_map{$id};
    $desc  = $program_desc_map{$id};
    $start = $program_start_map{$id};
    $stop  = $program_stop_map{$id};
    $channel = $program_channel_map{$id};
    $cat     = $program_category_map{$id};

    my $p = {
	     title => $title,
	     desc  => $desc,
	     start => $start,
	     stop  => $stop,
	     channel => $channel,
	     category => $cat
	    };
    my $date = substr($start,0,8);
    $program_tree->{$channel}->{$date}->{$channel . "." . $start} = $p;
  }
  return $program_tree;
}

sub myglob {
  my $glob = shift;

  my ($res) = glob $glob;

  return $res;
}

sub get_images {
  $imagemax   = scalar keys %$imagemap;
  $imagevalue = 0;

  if (! -e $imagedir) {mkdir($imagedir)};

  foreach my $c (values %$imagemap) {
    print "XMLTVHandler: getting icon for channel " . $c->{id} . " $c->{url}\n" if ($DEBUG);
    my $content = get($c->{url});

    if (defined ($content)) {
      $c->{url} =~ /.*(\.[^\.]+)/;
	
      unless (open (WRITE, ">" . $c->{file} . $1)) {
	print "XMLTVHandler: can't write image $c->{file}.$1\n" if ($DEBUG);
      } else {
	print WRITE $content;
	close WRITE;
      }
    } else {
      print "XMLTVHandler: can't fetch icon $c->{url}\n" if ($DEBUG);
    }
    $imagevalue++;
  }
  %$imagemap  = ();
  $imagevalue = 0;
  $imagemax   = 0;
}


package main;

# XMLTV Handler for parsing the XMLTV xml file.
my $xmltvhandler = XMLTVHandler->new();

use strict;
use warnings;

use Glib qw(TRUE FALSE);
use Gtk2 qw/-init -threads-init/;

die "Glib::Object thread safetly failed"
  unless Glib::Object->set_threadsafe (TRUE);

use Gtk2::GladeXML;
use Gtk2::SimpleList;
use Gnome2;
use Locale::gettext;
use POSIX;
use utf8;
use Encode;
use Time::Local;

# Set up translation domain

textdomain("gshowtv");
bind_textdomain_codeset("gshowtv", "UTF-8");

##################################################################
# Determine system locale and convert encodings
##################################################################

# Locale variables can be used to select language or region preferred by the user

my $syslocale   = setlocale(LC_MESSAGES);
my $sysencoding = undef;
my $syslanguage = undef;
my $syscountry  = undef;

if ($syslocale =~ m/\./ ) {
  ($sysencoding = $syslocale) =~ s/.*\.//;
  $syslocale =~ s/\..*//;
}

if ( $syslocale =~ m/_/ ) {
  ($syslanguage = $syslocale) =~ s/_.*//;
  ($syscountry = $syslocale) =~ s/.*_//;
} else {
  $syslanguage = $syslocale;
}

sub getperltext ($) {
  decode("UTF-8", gettext($_[0]));
}

##################################################################

my $SPOOL_DIR  = "/var/lib/gshowtv/";

## Configuration holders

my $initial_size  = undef;
my $xmltvfile     = undef;
my $showdir       = undef;
my $recordcommand = undef;
my $cancelcommand = undef;
my $viewpastshows = FALSE;
my $loadimages    = FALSE;
my $tablocation   = undef;
my $hpanepos      = undef;
my $vpanepos      = undef;

## Configuration dir and file

my $confdir  = "/home/".$ENV{"USER"}."/.gshowtv";
my $conffile = $confdir . "/config";

my $favouritesfile = $confdir . "/favourites";

## Application state information

my $current_channel = undef;                    # Current channel id
my $current_program = undef;                    # Current program struct
my $current_date    = time2str ("%Y%m%d",time); # Current date

my $xml_modified_since = undef; # When was the XMLTV file last modified

# Program name and version

my $name      = "GShowTV";
my $version   = "0.4.5";

## Channel and program information

my %channel_map;                 # Map of all channels.                CHANNEL ID => CHANNEL NAME
my %channel_map_reverse;         # Map of all channels.                CHANNEL NAME => CHANNEL ID
my %channel_lists;               # Map of all channel's program lists. CHANNEL ID => Gtk2::SimpleList
my %channel_day_labels;          # Map of all channel's day labels.    CHANNEL ID => LABEL
my @notebook_channels;           # List of all notebook channels
my @fav_patterns;                # List of patterns to match programs
my @dates;                       # List of all dates currently known
my @channel_order;               # Container for channels' order       nth => {'name', 'id', 'selected'}

# Our own data type for the program data is as follows:
#
# my $program = { title    => 'title',
#                 desc     => 'desc',
#                 channel  => 'channel.id',
#                 start    => 'start',
#                 stop     => 'stop',
#                 category => 'category',
#                 file     => 'filename' };
#
# The key used is 'channel.id'.'start'

# Container for all programs within the xmltv listing. pid = program id
#
# tree => channel => date => pid => program

my $program_tree;

# Container for all programs that are on disk (i.e. recorded shows).
# Standard program id key is used.

my %extra_program_map;

# My weekdays

my @weekdays = (getperltext("Sunday"   ),
		getperltext("Monday"   ),
		getperltext("Tuesday"  ),
		getperltext("Wednesday"),
		getperltext("Thursday" ),
		getperltext("Friday"   ),
		getperltext("Saturday" ),
		getperltext("Sunday"   ));

# GTK Components

my ($application, $notebook, $label, $status, $rightnotebook, $informationlabel, $recordingtreeview,$recordedtreeview, $favtreeview, $favpatternstreeview, $faventry, $configdialog, $favdialog, $aboutdialog, $xmltvfileentry, $showdirentry, $recordcommandentry, $cancelcommandentry, $viewpastshowscheck, $viewmenu, $todaymenuitem, $channelconftreeview, $channelconfdialog, $progressdialog, $progress, $progresslabel, $tablocationcheck, $hpaned1, $vpaned1, $loadimagescheck);

my $glade;


##################################################################
# Configuration IO functions
##################################################################

sub read_config {
  if (open (READ, "<:utf8", $conffile)) {
    while (<READ>) {
      chomp();

      if (/^xmltvfile\s*=\s*(.*)/) {
	$xmltvfile = $1;
      }
      elsif (/^showdir\s*=\s*(.*)/) {
	$showdir = $1;
      }
      elsif (/^recordcommand\s*=\s*(.*)/) {
	$recordcommand = $1;
      }
      elsif (/^cancelcommand\s*=\s*(.*)/) {
	$cancelcommand = $1;
      }
      elsif (/^viewpastshows\s*=\s*(.*)/) {
	$viewpastshows = $1;
      }
      elsif (/^initial_size\s*=\s*(.*)/) {
	$initial_size = $1;
      }
      elsif (/^tablocation\s*=\s*(.*)/) {
	$tablocation = $1;
      }
      elsif (/^hpanepos\s*=\s*(.*)/) {
	$hpanepos = $1;
      }
      elsif (/^vpanepos\s*=\s*(.*)/) {
	$vpanepos = $1;
      }
      elsif (/^loadimages\s*=\s*(.*)/) {
	$loadimages = $1;
      }
    }
    close READ;
  }

  if (!defined($xmltvfile) && !defined($initial_size)) {
    unless (my $return = do $conffile) {
      print "Using default values for all configuration items because configuration file not found or not ok:\n" if ($DEBUG);
      my $err = $!;

      if ($err != 2) { # ENOENT 'No such file or directory'
	if ($@) {
	  warn "Couldn't parse $conffile: $@" .($err);
	} elsif (!defined($return)) {
	  warn "Couldn't do $conffile: $!" . ($err);
	}
      }
    } else {
      no warnings;

      $xmltvfile     = $::xmltvfile;
      $showdir       = $::showdir;
      $recordcommand = $::recordcommand;
      $cancelcommand = $::cancelcommand;
      $viewpastshows = $::viewpastshows;
      $initial_size  = $::initial_size;
      $tablocation   = $::tablocation;
    }
  }

  unless (defined ($viewpastshows)) {
    $viewpastshows = FALSE;
  }
  unless (defined ($recordcommand)) {
    $recordcommand = "/usr/share/doc/gshowtv/examples/record";
  }
  unless (defined ($cancelcommand)) {
    $cancelcommand = "/usr/share/doc/gshowtv/examples/cancel";
  }
  unless (defined ($tablocation)) {
    $tablocation = "top";
  }

  if ($DEBUG) {
    print "Using configuration\n";
    print "XMLTV file:      $xmltvfile\n";
    print "Showdir:         $showdir\n";
    print "Record command:  $recordcommand\n";
    print "Cancel command:  $cancelcommand\n";
    print "View past shows: $viewpastshows\n";
    print "Tab position:    $tablocation\n";
    print "HPane position:  $hpanepos\n";
    print "VPane position:  $vpanepos\n";
    print "Load images:     $loadimages\n";
    print "\n";
  }
}

sub write_config {
  if (! -e $confdir) {
    mkdir($confdir);
  }

  if (open (WRITE, ">:utf8" , $conffile)) {
    if (defined ($xmltvfile)) {
      print WRITE "xmltvfile     = $xmltvfile\n";
    }
    if (defined ($showdir)) {
      print WRITE "showdir       = $showdir\n";
    }
    if (defined ($recordcommand)) {
      print WRITE "recordcommand = $recordcommand\n";
    }
    if (defined ($cancelcommand)) {
      print WRITE "cancelcommand = $cancelcommand\n";
    }
    if ($viewpastshows == TRUE) {
      print WRITE "viewpastshows = $viewpastshows\n";
    }
    if (defined ($initial_size)) {
      print WRITE "initial_size  = $initial_size\n";
    }
    if (defined ($tablocation)) {
      print WRITE "tablocation   = $tablocation\n";
    }
    if (defined ($hpanepos)) {
      print WRITE "hpanepos      = $hpanepos\n";
    }
    if (defined ($vpanepos)) {
      print WRITE "vpanepos      = $vpanepos\n";
    }
    if (defined ($loadimages)) {
      print WRITE "loadimages    = $loadimages\n";
    }
    close WRITE;
  }
}

sub read_favourites {
  if (open (READ, "<:utf8", $favouritesfile)) {
    while (<READ>) {
      chomp();
      push @fav_patterns, $_;
      print "Favourite pattern: $_\n" if ($DEBUG);

    }
    close READ;
  }
}

sub write_favourites {
  if (open (WRITE, ">:utf8" , $favouritesfile)) {
    foreach $_ (@fav_patterns) {
      print WRITE $_ ."\n";
    }
    close WRITE;
  } else {
    quick_message(sprintf(getperltext("Cannot open favourites file for writing! \n\n%s"), $favouritesfile));
  }
}

sub count_valid_channels {
  my (@array, $count);

  $count = 0;

  my $c;

  foreach $c (@channel_order) {
    if ($c->{selected} == TRUE) {
      push @array, $c;
    }
  }

  if (scalar (@array) == 0) {
    foreach $c (@channel_order) {
      push @array, $c;
    }
  }

  return scalar (@array);
}

sub myglob {
  my $glob = shift;

  my ($res) = glob $glob;

  return $res;
}

##################################################################
# GTK2 Event handlers
##################################################################

sub on_recordbutton_clicked {
  my (@args) = @_;

  print "on_recordbutton_clicked:\n" if ($DEBUG);

  unless (defined ($current_program)) {
    update_status(getperltext("No program selected!"));
    return;
  }

  unless (defined ($recordcommand)) {
    update_status(getperltext("No record command configured, please configure."));
    return;
  }

  my ($start, $stop);

  if (defined ($current_program->{'start'})) {
    $start = $current_program->{'start'};

    if (is_old_date($start)) {
      update_status(getperltext("Cannot set recording, this show has already started."));
      return;
    }
  } else {
    update_status(getperltext("Cannot set recording. Start time is not known."));
    return;
  }

  if (defined ($current_program->{'stop'})) {
    $stop = $current_program->{'stop'};
  } else {
    update_status(getperltext("Cannot set recording. Stop time is not known."));
    return;
  }

  $start =~ s/\s.*//;
  $stop  =~ s/\s.*//;

  my $command = $recordcommand . " " . $current_program->{'channel'} . " " .
    $start . " " . $stop . " " .
      " \"" . $current_program->{'title'} . "\"";

  my $file = $SPOOL_DIR . "/recording/" . $current_program->{'channel'} . "." . $start . "." . $stop;

  print "on_record_button_clicked: exec: $command $file\n"  if ($DEBUG);
  my $status = system ($recordcommand,
		       ($current_program->{'channel'},
			$start,
			$stop,
			$current_program->{'title'},
			$file));

  if ($status == 1) {
    quick_message(getperltext("The recording cannot be initialized, due to overlapping tv shows."));
    return;
  }

  if (! -e $file) {
    quick_message(getperltext("The recording command didn't function properly, \n" .
			  "recording failed. \n\n" . 
			  "Reason: The record script didn't produce a datafile."));
    return;
  } else {
    my $res = `wc -l $file`;
    $res =~ s/ .*//;
    if ($res != 1) {
      quick_message(getperltext("The recording command didn't function properly, \n" .
			    "recording failed. \n\n" .
			    "Reason: The datafile produced isn't one line long."));
      return;
    }
  }

  if (open (WRITE, ">>:utf8" , $file)) {
    print WRITE $current_program->{'title'} . "\n";
    print WRITE $current_program->{'desc'} . "\n";
    close WRITE;
  }

  update_status(sprintf (getperltext("Recorder set up for %s") , $current_program->{'title'}));
  update_recording_list();
  clean_recordings();
}

sub on_cancelbutton_clicked {
  my (@args) = @_;

  print "on_cancelbutton_clicked:\n" if ($DEBUG);

  unless (defined ($cancelcommand)) {
    update_status(getperltext("No cancel command configured, please configure."));
    return;
  }

  my @selection = $recordingtreeview->get_selected_indices();

  unless (defined($selection[0])) {
    update_status(getperltext("No program selected from the recording list"));
    return;
  }

  my $date    = $recordingtreeview->{'data'}[$selection[0]][0];
  my $channel = $recordingtreeview->{'data'}[$selection[0]][1];

  $date =~ s/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d)-.*/$1$2$3$4$5/;
  $date = $date ."00";

  my $cid     = $channel_map_reverse{$channel};
  my $command = $cancelcommand . " $date.".$cid;
  my $glob    = $SPOOL_DIR . "/recording/" . $cid . ".". $date . ".*";
  my $file    = myglob($glob);

  print "on_cancelbutton_clicked: glob: $glob -> $file\n" if ($DEBUG);
  print "on_cancelbutton_clicked: exec: $command\n" if ($DEBUG);

  system($cancelcommand, ($cid, $date));

  if (defined ($file)) {
    print "on_cancelbutton_clicked: Unlinking file: $file\n"  if ($DEBUG);
    unlink ($file);
    update_status(getperltext("Recorder cancelled"));
  }
  update_recording_list();
}

sub on_channel_close {
  @channel_order = ();
  my $i = 0;

  for ($i = 0 ; $i < @{$channelconftreeview->{'data'}}; $i++) {
    my %channelinfo = ( 'id'       => $channel_map_reverse{$channelconftreeview->{'data'}[$i][1]},
			'name'     => $channelconftreeview->{'data'}[$i][1],
			'selected' => $channelconftreeview->{'data'}[$i][0] );
    push @channel_order, \%channelinfo;

#    if ($channelconftreeview->{'data'}[$i][0] == 1) {
#      print "Channel is selected: " . $channelconftreeview->{'data'}[$i][1] ."\n";
#    } else {
#      print "Channel is not selected: " . $channelconftreeview->{'data'}[$i][1] ."\n";
#    }
  }
  save_channel_order();

  update_state();
  $channelconfdialog->hide();
}

sub save_channel_order {
  if (! -e $confdir) {
    mkdir($confdir);
  }

  if (open (WRITE, ">:utf8", $confdir . "/channels.conf")) {
    foreach my $ref (@channel_order) {
      print WRITE $ref->{'selected'}.":".$ref->{'id'}.":".$ref->{'name'}."\n";
    }
    close WRITE;
  }
}

sub read_channel_order {
  @channel_order = ();
  my @ch   = ();

  if (open (READ, "<:utf8", $confdir."/channels.conf")) {
    while (<READ>) {
      chomp;
      my @tmp = split (/:/, $_);
      if (scalar @tmp == 3) {
        my %hash = ('id'       => $tmp[1],
		    'name'     => $tmp[2],
		    'selected' => $tmp[0]);
        push @ch, \%hash;
      }
    }
    close READ;
  }

  my %existing = ();

  # Let's go through the channel list and remove all channels that
  # don't exist anymore in the XMLTV database

  foreach my $c (@ch) {
    if (defined($channel_map{$c->{'id'}})) {
      $existing{$c->{'id'}} = 1;
      push @channel_order, $c;
    }
  }

  # Let's go through the XMLTV channels and see if there are new
  # channels that don't yet exist in our configuration.

  foreach my $c (keys %channel_map) {
    unless (defined ($existing{$c})) {
      my %hash = ('id'       => $c,
		  'name'     => $channel_map{$c},
		  'selected' => 1);
      push @channel_order, \%hash;
    }
  }
}


sub on_cursor_changed {
  my ($list, @args) = @_;

  # Clear the selections of right notebook lists

  if ($list == $recordingtreeview) {
    $recordedtreeview->get_selection->unselect_all;
    $favtreeview->get_selection->unselect_all;
  } elsif ($list == $recordedtreeview) {
    $recordingtreeview->get_selection->unselect_all;
    $favtreeview->get_selection->unselect_all;
  } elsif ($list == $favtreeview) {
    $recordedtreeview->get_selection->unselect_all;
    $recordingtreeview->get_selection->unselect_all;
  } else {
    $recordedtreeview->get_selection->unselect_all;
    $favtreeview->get_selection->unselect_all;
    $recordingtreeview->get_selection->unselect_all;
  }

  # Clear the selections of the TV Guide lists

  foreach my $ch (keys %channel_lists) {
    my $l = $channel_lists{$ch};
    unless ($l == $list) {
      $l->get_selection->unselect_all;
    }
  }

  my (@indices) = $list->get_selected_indices();

  foreach my $indice (@indices) {
    print "on_cursor_changed: indice -> $indice\n" if ($DEBUG);

    my $pid = undef;

    if ($list == $recordingtreeview ||
	$list == $recordedtreeview  ||
	$list == $favtreeview) {

      $pid = $list->{'data'}[$indice][3];

      print "on_cursor_changed: Right notebook: $pid\n" if ($DEBUG);

      $current_program = $extra_program_map{$pid};
      unless (defined ($current_program)) {
	my $ch = substr($pid, 0, rindex($pid, "."));
	my $d  = substr($pid, length($ch) + 1, 8);
	
	$current_program = $program_tree->{$ch}->{$d}->{$pid};
      }
    } else {
      print "on_cursor_changed: Left notebook\n"  if ($DEBUG);

      my $pid = $list->{'data'}[$indice][2];

      $current_program = $program_tree->{$current_channel}->{$current_date}->{$pid};
    }
  }

  my $desc = $current_program->{'desc'};

  if (defined ($current_program->{'category'})) {
    $desc = $desc . "\n\n" . $current_program->{'category'};
  }

  $label->set_text($desc);
  print "on_cursor_changed: Current program changed to: " . $current_program->{'title'} . " " . (defined ($current_program->{'file'}) ? $current_program->{'file'} : "") . "\n"  if ($DEBUG);
  update_status(undef);
}

sub on_change_current_page {
  my ($book, $gpointer, $index, @args) = @_;

  my $ch = $notebook_channels[$index];

  $current_channel = $ch;
  print "on_change_current_page: Channel changed to $ch\n"  if ($DEBUG);
  update_status(undef);
  $current_program = undef;
}

sub on_radioitem_activate {
  my ($radioitem, @args) = @_;

  my $date = $radioitem->get_name();

#  print "on_today_activate: $date\n";

  if ($date eq "today") {
    $date = time2str ("%Y%m%d", time);
  } elsif ($date eq "tomorrow") {
    $date = time2str ("%Y%m%d", time + 60 * 60 * 24);
  }

  if ($date eq $current_date) {
#    print "on_today_activate: nothing changed\n";
    return;
  }

  $current_date = $date;

  print "on_radioitem_activate: Current date is now $current_date\n" if ($DEBUG);

  update_program_lists();
  update_current_day_label();
  update_status(undef);
}

sub on_config_close {
  my $oldfile          = $xmltvfile;
  my $oldviewpastshows = $viewpastshows;
  my $oldloadimages    = $loadimages;
  my $oldtablocation   = $tablocation;

  $xmltvfile     = $xmltvfileentry->get_text();
  $showdir       = $showdirentry->get_text();
  $recordcommand = $recordcommandentry->get_text();
  $cancelcommand = $cancelcommandentry->get_text();
  $viewpastshows = $viewpastshowscheck->get_active();
  $tablocation   = $tablocationcheck->get_active() ? "left" : "top";
  $loadimages    = $loadimagescheck->get_active();

  print "on_saveconfigbutton_clicked: $xmltvfile $showdir $recordcommand $cancelcommand $viewpastshows\n" if ($DEBUG);

  if ($xmltvfile eq "") {
    $xmltvfile = undef;
  }
  if ($showdir eq "") {
    $showdir = undef;
  }
  if ($recordcommand eq "") {
    $recordcommand = undef;
  }
  if ($cancelcommand eq "") {
    $cancelcommand = undef;
  }
  if ($viewpastshows eq "") {
    $viewpastshows = FALSE;
  }

  write_config();
  $xmltvhandler->set_load_images($loadimages);

  unless (defined ($xmltvfile) && -e $xmltvfile) {
    update_status(getperltext("XMLTV file configuration is crucial."));
    $configdialog->hide;
    return;
  }

  if (!defined($oldfile) || $oldfile ne $xmltvfile) {
    $xmltvhandler->set_file($xmltvfile);
    $xmltvhandler->trigger();
  } elsif ($oldloadimages != $loadimages) {
    $xmltvhandler->trigger(2);
  } elsif ($oldviewpastshows != $viewpastshows) {
    update_state();
  } elsif ($oldtablocation ne $tablocation) {
    $notebook->set_tab_pos($tablocation);
  }

  update_status(getperltext("Configuration saved"));
  $configdialog->hide;
}


sub update_state {
  copy_xmltv_data();

  read_channel_order();
  update_notebook();
  update_view_menu();

  if (count_valid_channels() != 0) {
    update_program_lists();
  }

  update_recording_list();
  update_recorded_list();
  update_view_menu();
  update_favourites_list();

  update_status(sprintf(getperltext("Currently in XMLTV db: %s tv shows, %s channels."), scalar values %$program_tree, scalar keys %channel_map));
}

sub on_nautilusbutton_clicked {
  print "on_nautilusbutton_clicked:\n" if ($DEBUG);

  system("nautilus $showdir");
}

sub on_deletebutton_clicked {
  my $index = ($recordedtreeview->get_selected_indices())[0];

  unless (defined ($index)) {
    update_status(getperltext("No show selected from recorded shows list."));
    return;
  }

  my $date    = $recordedtreeview->{'data'}[$index][0];
  my $channel = $recordedtreeview->{'data'}[$index][1];

  $date =~ s/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d)-.*/$1$2$3$4$5/;
  $date = $date . "00";

  my $cid     = $channel_map_reverse{$channel};
  my $command = $cancelcommand . " $date ".$cid;
  my $glob    = $SPOOL_DIR . "/ondisk/" . $cid . ".". $date . ".*";
  my $file    = myglob($glob);

  if (defined ($file)) {
    print "Unlinking file: $file\n" if ($DEBUG);
    unlink ($file);
    update_status(getperltext("Information about the show removed."));
  }
  update_recorded_list();
}


sub on_watchbutton_clicked {
  my (@indices) = $recordedtreeview->get_selected_indices();

  unless (defined ($indices[0])) {
    quick_message(getperltext("No file selected from 'On Disk' list"));
    return;
  }

  if (defined ($current_program->{'file'}) &&
      -e $current_program->{'file'}) {
    print "Opening file: '" . $current_program->{'file' } ."'\n" if ($DEBUG);
    if (system("gnome-open \"" . $current_program->{'file'} . "\"")) {
      quick_message(sprintf (getperltext("Failed to open file %s."), $current_program->{'file'}));
    }
  } else {
    quick_message(sprintf (getperltext("File '%s' does not exist."), $current_program->{'file'}));
  }
}

sub on_quit {
  $application->hide_all;
  Gtk2->main_iteration;
  print "on_quite: GTK2->main_iteration() called.\n" if ($DEBUG);
  write_config();
  $xmltvhandler->stop();
  exit;
}

sub quick_message {
  my $message = shift;
  my $dialog = Gtk2::Dialog->new ('Message', $application,
				  'destroy-with-parent',
				  'gtk-ok' => 'none');
  my $label = Gtk2::Label->new ($message);
  $dialog->vbox->pack_start($label,0,0,4);

  # Ensure that the dialog box is destroyed when the user responds.
  $dialog->signal_connect (response => sub { $_[0]->destroy });

  $dialog->show_all;
}

sub on_preferences_activate {
  $configdialog->show_all;
}

sub on_favourites_activate {
  $favdialog->show_all;
}

sub on_information_activate {
  print "on_information_activate:\n" if ($DEBUG);

#  Gnome2::Help->display ("gshowtv", undef);
  system("gnome-help /usr/share/gnome/help/gshowtv/C/gshowtv.xml &");
}

sub on_about_activate {
  my @authors   = ("Petri Vakevainen <Petri.Vakevainen\@hut.fi>");
  my $comments  = getperltext("GShowTV is a program for viewing TV Show information and recording them. GShowTV can be configured to use any video recording backend and together with the backend GShowTV is a complete PVR solution.");
  my $copyright = "Copyright © 2004 Petri Väkeväinen";

  my $translator_credits = getperltext("translator_credits");
  $translator_credits = undef if ($translator_credits eq "translator_credits");
  $aboutdialog = Gnome2::About->new($name, $version, $copyright, $comments, @authors, undef, $translator_credits, undef);
  $aboutdialog->show;
}

sub on_addbutton_clicked {
  $favdialog->show;
}

sub on_addfavbutton_clicked {
  print "on_addfavbutton_clicked:\n" if ($DEBUG);

  print "on_addfavbutton_clicked: new FAV: " . $faventry->get_text() ."\n" if ($DEBUG);

  if ($faventry->get_text()) {
    push @fav_patterns, $faventry->get_text();
    push @{$favpatternstreeview->{data}}, [$faventry->get_text()];
  }
  $faventry->set_text("");
}

sub on_removefavbutton_clicked {
  print "on_removefavbutton_clicked:\n" if ($DEBUG);

  my $i = ($favpatternstreeview->get_selected_indices())[0];

  if (defined ($i)) {
    splice @{ $favpatternstreeview->{data} }, $i, 1;
    splice @fav_patterns, $i, 1;
  }
}


##################################################################
# Application data update method
##################################################################

sub set_basic_treeinfo {
  foreach my $list (@_) {
    $list->set_rules_hint(TRUE);
    $list->set_headers_clickable(TRUE);

    my $i = 0;
    while (defined ($list->get_column($i))) {
      my $column = $list->get_column($i);
      $column->set_sort_column_id($i++);
    }

    $list->set_search_column(0);
  }
}

sub update_current_day_label {
  $current_date =~ m/^(\d\d\d\d)(\d\d)(\d\d)/;

  my $s = $1 . "-" . $2 ."-" . $3;

  foreach my $ch (keys %channel_map) {
    my $label = $channel_day_labels{$ch};
    if (defined ($label)) {
      $label->set_text($s . " " . time2str("%A", str2time("%Y%m%d", $current_date)));
    }
  }
}

sub update_view_menu {
  foreach my $child ($viewmenu->get_children()) {
    next if ($child->get_name() eq "today"     ||
	     $child->get_name() eq "tomorrow"  ||
	     $child->get_name() eq "separator");
    $child->hide;
    $viewmenu->remove($child);
  }

  foreach $_ (sort @dates) {
    /(\d\d\d\d)(\d\d)(\d\d)/;

    my $menuitem = Gtk2::RadioMenuItem->new_from_widget($todaymenuitem, "$1-$2-$3 " . time2str("%A", str2time("%Y%m%d", $_)));
    $menuitem->set_name($_);
    $menuitem->signal_connect("activate" => \&on_radioitem_activate);
    $viewmenu->add($menuitem);
    $menuitem->show();
  }
}

sub update_program_lists {
  my $start = time;
  foreach my $ch (keys %channel_map) {
    my $list = $channel_lists{$ch};

    unless (defined ($list)) {
      next;
    }

    @{$list->{data}} = ();

    my $i = 0;
    my $ref = $program_tree->{$ch}->{$current_date};

    foreach my $p (sort { $a->{'start'} cmp $b->{'start'} } values %$ref) {
      next if ($viewpastshows == 0 && is_old_date($p->{'stop'}));

      if ($p->{'channel'} eq $ch) {
	push @{$list->{data}}, [format_left_notebooktime($p), $p->{'title'}, $p->{'channel'} . "." . $p->{'start'}];
      }
    }
  }
  my $end = time;

  print "update_program_lists: took " . ($end - $start) . " time.\n" if ($DEBUG);
}

sub update_status {
  my ($msg, @args) = @_;

  print "update_status: $msg\n" if (defined ($msg) && $DEBUG);
  print "update_status: \n" if (!defined ($msg) && $DEBUG);

  if (defined ($msg)) {
    $status->push(0, $msg);
  } else {
    $status->push(0, "");
  }
}

sub update_recording_list {
  @{$recordingtreeview->{data}} = ();

  my $i = 0;

  while (<$SPOOL_DIR/recording/*>) {
    m/.*\/(.*)\.(\d{14})\.(\d{14})/;

    my $cid   = $1;
    my $sdate = $2;
    my $edate = $3;
    my $file  = undef;
    my $name  = undef;
    my $desc  = "";

    if (open (READ, "<:utf8", $_)) {
      $file = <READ>;
      $name = <READ>;
      chomp($name);

      while (<READ>) {
	$desc = $desc . $_;
      }
      close READ;
    }

    my $prog = {
		title   => $name,
		channel => $cid,
		start   => $sdate,
		stop    => $edate,
		desc    => $desc,
		file    => $file
	       };

    $extra_program_map{$cid . "." . $sdate} = $prog;

    push @{$recordingtreeview->{data}},
      [
       format_right_notebooktime($prog), $channel_map{$cid}, $name, $prog->{channel} . "." . $prog->{start}
      ];
  }
}

sub update_recorded_list {
  @{$recordedtreeview->{data}} = ();

  my $i = 0;

  while (<$SPOOL_DIR/ondisk/*>) {
    m/.*\/(.*)\.(\d{14})\.(\d{14})/;

    my $cid   = $1;
    my $sdate = $2;
    my $edate = $3;
    my $file  = undef;
    my $name  = undef;
    my $desc  = "";

    if (open (READ, $_)) {
      $file = <READ>;
      chomp($file);
      $name = <READ>;
      chomp($name);

      while (<READ>) {
	$desc = $desc . $_;
      }
      close READ;
    }

    my $prog = {
		title   => $name,
		channel => $cid,
		start   => $sdate,
		stop    => $edate,
		desc    => $desc,
		file    => $file
	       };
    $extra_program_map{$cid . "." . $sdate} = $prog;

    push @{$recordedtreeview->{data}},
      [
       format_right_notebooktime($prog), $channel_map{$cid}, $name, $prog->{channel} . "." . $prog->{start}
      ];
  }
}

sub update_favourites_list {
  @{$favtreeview->{data}}         = ();
  @{$favpatternstreeview->{data}} = ();

  my @title_matches = ();
  my @desc_matches  = ();

  my ($c, $d, $p);

  foreach $c (values %$program_tree) {
    foreach $d (values %$c) {
      foreach $p (values %$d) {
	foreach my $fav (@fav_patterns) {
	  if ($p->{'title'} =~ m/$fav/i) {
	    push @title_matches, $p;
	  } elsif (defined ($p->{'desc'}) && $p->{'desc'} =~ m/$fav/) {
	    push @desc_matches, $p;
	  }
	}
      }
    }
  }

  push @title_matches, @desc_matches;

  foreach $p (sort { $a->{start} cmp $b->{start} } @title_matches) {
    push @{$favtreeview->{data}},
      [
       format_right_notebooktime($p), $channel_map{$p->{'channel'}}, $p->{'title'}, $p->{channel} . "." . $p->{start}
      ];
  }

  foreach $p (@fav_patterns) {
    push @{$favpatternstreeview->{data}}, [$p];
  }
}

sub copy_xmltv_data {
  %channel_map_reverse = ();
  %channel_map         = $xmltvhandler->get_channel_map();
  $program_tree        = $xmltvhandler->get_program_tree();
  @dates               = $xmltvhandler->get_dates();

  my ($id, $name);

  foreach $id (keys %channel_map) {
    $name = $channel_map{$id};
    $channel_map_reverse{$name} = $id;
  }
}

sub format_left_notebooktime {
  my $p = shift;

  my $str;

  if (defined $p->{'start'}) {
    $p->{'start'} =~ /\d{8}(\d\d)(\d\d)\d\d/;
    $str = $1 . ":" . $2;
  } else {
    $str = "??:??";
  }

  if (defined $p->{'stop'}) {
    $p->{'stop'} =~ /\d{8}(\d\d)(\d\d)\d\d/;
    $str .= "-" . $1 . ":" . $2;
  } else {
    $str .= "-??:??";
  }

  $str;
}

sub format_right_notebooktime {
  my $p = shift;

  my $str;

  if (defined $p->{'start'}) {
    $p->{'start'} =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\d\d/;
    $str = $1 . "-" . $2 . "-" . $3 . " " . $4 . ":" . $5;
  } else {
    $str = "??-??-?? ??:??";
  }

  if (defined $p->{'stop'}) {
    $p->{'stop'} =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\d\d/;
    $str = $str . "-" . $4 . ":" . $5;
  } else {
    $str = $str . "-??:??";
  }

  $str;
}

sub parse_right_notebooktime {
  my $str = shift;

  $str =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d)-(\d\d):(\d\d)/;
  $str = $1. $2 . $3. $4 . $5 . "00";
  $str;
}

sub compare_datestrings {
  my ($s1, $s2) = @_;

  $s1 =~ m/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;

  my $y1 = $1;
  my $m1 = $2;
  my $d1 = $3;
  my $h1 = $4;
  my $M1 = $5;

  $s2 =~ m/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;

  my $y2 = $1;
  my $m2 = $2;
  my $d2 = $3;
  my $h2 = $4;
  my $M2 = $5;

#  print "cmp: Y:$y1 M:$m1 D:$d1 H:$h1 M:$M1 != Y:$y2 M:$m2 D:$d2 H:$h2 M:$M2\n";

  return 1 if ($y1 > $y2);
  return -1 if ($y1 < $y2);
  return 1 if ($m1 > $m2);
  return -1 if ($m1 < $m2);
  return 1 if ($d1 > $d2);
  return -1 if ($d1 < $d2);
  return 1 if ($h1 > $h2);
  return -1 if ($h1 < $h2);
  return 1 if ($M1 > $M2);
  return -1 if ($M1 < $M2);
  return 0;
}

sub is_old_date {
  my ($str, @args) = @_;

  if (defined ($str)) {
    my ($y, $m, $d, $h, $M) = (localtime)[5,4,3,2,1];

    $y += 1900;
    $m++;

    my $now = $y .
      ($m < 10 ? "0". $m : $m) .
	($d < 10 ? "0" . $d : $d) .
	  ($h < 10 ? "0" . $h : $h) .
	    ($M < 10 ? "0" . $M : $M);

    #  print "Comparing dates: $now $str\n";
    if (compare_datestrings($now, $str) == 1) {
      return 1;
    }
  }
  return undef;
}

sub time2str {
  # Our own implementation of this method, one less dependency, though IGNORE FORMAT
  my ($format, $time) = @_;

  die "Cannot use other time formats except '%Y%m%d' or '%A'." unless ($format eq "%Y%m%d" || $format eq "%A");

  my @t = localtime $time;

  if ($format eq "%Y%m%d") {
    "" .
      ($t[5] + 1900) .
	($t[4] < 9 ? ("0" . ($t[4] + 1)) : ($t[4] + 1)).
	  ($t[3] < 10 ? ("0" . ($t[3])) : ($t[3]));
  } elsif ($format eq "%A") {
#    print "time2str: $format $time ($t[6], $weekdays[$t[6]]).\n";
    "" . $weekdays[$t[6]];
  }
}

sub str2time {
  my ($format, $str) = @_;

  die "Cannot use other time formats except '%Y%m%d'." unless ($format eq "%Y%m%d");

  $str =~/(\d\d\d\d)(\d\d)(\d\d)/;

#  print "str2time: $str\n";
  timelocal(0, 0, 0, $3, $2 - 1, $1 - 1900);
}

sub clean_recordings {
  my $cleaned = undef;

  while (<$SPOOL_DIR/recording/*>) {
    m/.*\.(\d{12})\d\d/;

    if (is_old_date($1)) {
      my $file = $_;
      my $newfile = $_;
      $newfile =~ s/recording/ondisk/;
      print "clean_record: $file -> $newfile\n" if ($DEBUG);
      rename($file, $newfile);
      $cleaned = 1;
    }
  }
  if (defined ($cleaned)) {
    update_recording_list();
    update_recorded_list();
  }
}

##################################################################
# Initialize the GTK2 elements in the Notebook
##################################################################

sub update_notebook {
  # Remove the pages from the notebook

  my @ar = $notebook->get_children();
  $notebook->set_current_page(0);

  print "update_notebook: removing current children (" . @ar . ").\n" if ($DEBUG);

  for (my $i = @ar; $i > 1 ; $i--) {
    $notebook->remove_page($i-1);
  }

  # Clear these
  %channel_lists      = ();
  %channel_day_labels = ();
  @notebook_channels  = ();

  $current_date =~ m/^(\d\d\d\d)(\d\d)(\d\d)/;
  my $s = $1 . "-" . $2 ."-" . $3;

  print "update_notebook: going through channels.\n" if ($DEBUG);

  foreach my $c (@channel_order) {
    my $ch_name = $c->{name};
    my $ch      = $c->{id};

    if ($c->{selected} == FALSE) {
      print "update_notebook: skipping $ch.\n" if ($DEBUG);
      next;
    }

    print "update_notebook: got channel $ch.\n" if ($DEBUG);

    my $alignment = Gtk2::Alignment->new(0.5,0.5,1.0,1.0);
    $alignment->set_padding(2, 2, 2, 2); 

    my $vbox = Gtk2::VBox->new(0,0);
    $alignment->add($vbox);

    my $hbox = Gtk2::HBox->new(0,0);
    $vbox->pack_start($hbox,0,0,4);

    my $pic  = myglob ($confdir . "/images/" . $ch .".*");

    unless (defined ($pic) && -e $pic) {
      $pic = "/usr/share/gshowtv/undefined.png";
    }

    print "update_notebook: Using image $pic to view channel $ch\n" if ($DEBUG);

    my $image = Gtk2::Image->new_from_file($pic);

    $image->set_alignment (0.0, 0.5);
    $hbox->pack_start($image, 0,0,4);

    my $label       = Gtk2::Label->new($s . " " . time2str("%A", str2time("%Y%m%d", $current_date)));
    $hbox->pack_start($label, 0,0, 10);

    my $scrolledwindow = Gtk2::ScrolledWindow->new (undef, undef);

    $scrolledwindow->set_policy("automatic", "automatic");
    $scrolledwindow->set_shadow_type('GTK_SHADOW_IN'); 
    $vbox->add($scrolledwindow);

    my $slist = Gtk2::SimpleList->new(getperltext("Time")    => 'text',
				      getperltext("Program") => 'text',
				      'program'              => 'hidden');
    $scrolledwindow->add($slist);

    $slist->set_rules_hint (TRUE);
    $slist->signal_connect("cursor-changed" => \&on_cursor_changed );

    $notebook->append_page($alignment, $ch_name);

    $channel_lists{$ch}      = $slist;
    $channel_day_labels{$ch} = $label;

    push @notebook_channels, $ch;
  }

  if (scalar (@notebook_channels) > 0) {
    $notebook->remove_page(0);
  }

  $notebook->set_tab_pos($tablocation);
  $notebook->show_all;
}

sub setup_channel_configuration {
  @{$channelconftreeview->{data}} = ();

  my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file("/usr/share/gshowtv/undefined.png");

  foreach my $c (@channel_order) {
    my $ch_pix = $pixbuf;
    my $pic    = myglob ($confdir . "/images/" . $c->{id} .".*");

    if (defined ($pic) && -e $pic) {
      $ch_pix = Gtk2::Gdk::Pixbuf->new_from_file($pic);
    }

    push @{$channelconftreeview->{data}}, [$c->{'selected'}, $c->{'name'}, $ch_pix];
  }

  $channelconfdialog->show;
}

sub on_channel_configuration_activate {
  setup_channel_configuration();
}

sub on_fav_close {
  $favdialog->hide;
  write_favourites();
  update_favourites_list();
}

sub on_debug {
  my (@args) = @_;

  print "on_debug: " if ($DEBUG);
  foreach my $m (@args) {
      print " $m,";
  }
  print "\n";
}

sub init_gtk {
  Gnome2::Program->init ($name, $version);

  # Get the Glade

  my $xml;
  {
    local $/ = undef;
    $xml = <DATA>;
  }

#  $glade = Gtk2::GladeXML->new("gshowtv.glade");
  $glade = Gtk2::GladeXML->new_from_buffer($xml);

#  print "Acquired glade..\n";

  $glade->signal_autoconnect_from_package('main');

  $application        = $glade->get_widget('application');
  $notebook           = $glade->get_widget('notebook');
  $label              = $glade->get_widget('label');
  $status             = $glade->get_widget('statusbar');

  $rightnotebook      = $glade->get_widget('rightnotebook');
  $informationlabel   = $glade->get_widget('informationlabel');
  $viewmenu           = $glade->get_widget('view_menu');
  $todaymenuitem      = $glade->get_widget("today");
  $progress           = $glade->get_widget('progress');
  $progresslabel      = $glade->get_widget('progresslabel');

  # Right Treeviews

  $recordingtreeview  = Gtk2::SimpleList->new_from_treeview($glade->get_widget("recordingtreeview"),
							    getperltext("Date")    => 'text',
							    getperltext("Channel") => 'text',
							    getperltext("Program") => 'text',
							    'program'              => 'hidden');
  $recordedtreeview   = Gtk2::SimpleList->new_from_treeview($glade->get_widget("recordedtreeview"),
							    getperltext("Date")    => 'text',
							    getperltext("Channel") => 'text',
							    getperltext("Program") => 'text',
							    'program'              => 'hidden');
  $favtreeview        = Gtk2::SimpleList->new_from_treeview($glade->get_widget("favouritestreeview"),
							    getperltext("Date")    => 'text',
							    getperltext("Channel") => 'text',
							    getperltext("Program") => 'text',
							    'program'              => 'hidden');
  $favpatternstreeview   = Gtk2::SimpleList->new_from_treeview($glade->get_widget("favpatterntreeview"),
							       getperltext("Pattern")    => 'text');
  $faventry              = $glade->get_widget('faventry');
  set_basic_treeinfo($recordingtreeview, $recordedtreeview, $favtreeview, $favpatternstreeview);

  $recordingtreeview->signal_connect("cursor-changed" => \&on_cursor_changed );
  $recordedtreeview->signal_connect("cursor-changed"  => \&on_cursor_changed );
  $favtreeview->signal_connect("cursor-changed"       => \&on_cursor_changed );

  $channelconftreeview = Gtk2::SimpleList->new_from_treeview($glade->get_widget("channelconftreeview"),
							     "1" => 'bool',
							     "3" => 'text',
							     "4" => 'pixbuf');


  # Dialogs

  $configdialog      = $glade->get_widget('configdialog');
  $favdialog         = $glade->get_widget('favdialog');
  $channelconfdialog = $glade->get_widget('channelconfdialog');
  $progressdialog    = $glade->get_widget('progresswindow');

  # Config components

  $xmltvfileentry     = $glade->get_widget('xmltvfileentry');
  $showdirentry       = $glade->get_widget('showdirentry');
  $recordcommandentry = $glade->get_widget('recordcommandentry');
  $cancelcommandentry = $glade->get_widget('cancelcommandentry');
  $viewpastshowscheck = $glade->get_widget('viewpastshowscheckbutton');
  $tablocationcheck   = $glade->get_widget('tablocationcheckbutton');
  $loadimagescheck    = $glade->get_widget('loadimagescheckbutton');
  $application->signal_connect (destroy => sub { on_quit(); Gtk2->main_quit; });

  $application->signal_connect (size_request => sub {
				  my ($x, $y)   = $application->get_size();
				  $initial_size = $x."x".$y;
				  $hpanepos = $hpaned1->get_position;
				  $vpanepos = $vpaned1->get_position;
				});
  # Panes

  $hpaned1 = $glade->get_widget("hpaned1");
  $vpaned1 = $glade->get_widget("vpaned1");

  if (defined ($initial_size)) {
    $initial_size =~ m/(\d+)x(\d+)/;
    $application->resize($1,$2);
  }

  if (defined ($hpanepos)) {
    $hpaned1->set_position($hpanepos);
  }
  if (defined ($vpanepos)) {
    $vpaned1->set_position($vpanepos);
  }
}

##################################################################
# Application state initialization
##################################################################

read_config();
read_favourites();
init_gtk();

#########################################################################
# Initialize the left notebook
#########################################################################

$notebook->signal_connect("switch-page" => \&on_change_current_page);

$label->set_text(getperltext("Select a show from the list to view the show's description."));

if (defined ($xmltvfile)) {
  $xmltvfileentry->set_text($xmltvfile);
}
if (defined ($showdir)) {
  $showdirentry->set_text($showdir);
}
if (defined ($recordcommand)) {
  $recordcommandentry->set_text($recordcommand);
}
if (defined ($cancelcommand)) {
  $cancelcommandentry->set_text($cancelcommand);
}
if (defined ($tablocation) && $tablocation ne "top" && $tablocation ne "GTK_POS_TOP") {
  $tablocationcheck->set_active(TRUE);
}
$viewpastshowscheck->set_active($viewpastshows);
$loadimagescheck->set_active($loadimages);

# Autoupdater
Glib::Timeout->add(10 * 60 * 1000,
		   sub {
		     my $since = (stat $xmltvfile)[9];

		     if (defined ($xml_modified_since) && $since > $xml_modified_since) {
		       print "XMLTV file changed, rereading..\n" if ($DEBUG);
		       $xmltvhandler->trigger();
		     } else {
		       print "XMLTV file wasn't updated..\n" if ($DEBUG);
		     }
		     $xml_modified_since = $since;
		     1;
		   });

# Progressbar
Glib::Timeout->add(500, sub {
		     if (!defined ($xmltvhandler->get_value())) {
		       1;
		     } elsif ($xmltvhandler->get_value() != $xmltvhandler->get_max_value()) {
		       if (!$progressdialog->visible()) {
			 print "Setting visible.\n" if ($DEBUG);
			 $progressdialog->show_all;
		       }
		       $progresslabel->set_text(getperltext("Reading XMLTV file"));
		       $progress->set_fraction($xmltvhandler->get_value() / $xmltvhandler->get_max_value());
		       $progress->set_text(int ($xmltvhandler->get_value() / $xmltvhandler->get_max_value() * 100) . "%");
		     } elsif ($xmltvhandler->get_imagemax() != 0) {
		       if (!$progressdialog->visible()) {
			 print "Setting visible.\n" if ($DEBUG);
			 $progressdialog->show_all;
		       }
		       $progresslabel->set_text(getperltext("Fetching images"));
		       $progress->set_fraction($xmltvhandler->get_imagevalue() / $xmltvhandler->get_imagemax());
		       $progress->set_text(int ($xmltvhandler->get_imagevalue() / $xmltvhandler->get_imagemax() * 100) . "%");
		     } else {
		       if ($progressdialog->visible()) {
			 print "Setting hidden.\n" if ($DEBUG);
			 $progressdialog->hide_all;
			
			 if (is_old_date($current_date)) {
			   $current_date = time2str ("%Y%m%d",time);
			   update_current_day_label();
			 }

			 update_state();

			 if (!$application->visible()) {
			   $application->show_all();
			 }
		       }
		     }
		     1;
		   });

clean_recordings();

$xmltvhandler->set_file($xmltvfile);
$xmltvhandler->set_imagedir($confdir . "/images/");
$xmltvhandler->set_load_images($loadimages);
$xmltvhandler->trigger();

if (defined ($xmltvfile)) {
  $xml_modified_since = (stat $xmltvfile)[9];
}

$configdialog->hide;
$favdialog->hide;
$channelconfdialog->hide;

unless (defined ($xmltvfile)) {
  $progressdialog->hide;
  $application->show_all;
  $configdialog->show;
}

Gtk2->main;


__DATA__
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>
<requires lib="gnome"/>

<widget class="GtkDialog" id="configdialog">
  <property name="title" translatable="yes">TV Shows - Configuration</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">True</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="has_separator">False</property>

  <child internal-child="vbox">
    <widget class="GtkVBox" id="dialog-vbox2">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">5</property>

      <child internal-child="action_area">
	<widget class="GtkHButtonBox" id="dialog-action_area2">
	  <property name="visible">True</property>
	  <property name="layout_style">GTK_BUTTONBOX_END</property>

	  <child>
	    <widget class="GtkButton" id="button26">
	      <property name="visible">True</property>
	      <property name="can_default">True</property>
	      <property name="can_focus">True</property>
	      <property name="label">gtk-close</property>
	      <property name="use_stock">True</property>
	      <property name="relief">GTK_RELIEF_NORMAL</property>
	      <property name="focus_on_click">True</property>
	      <property name="response_id">-7</property>
	      <signal name="clicked" handler="on_config_close" last_modification_time="Mon, 16 May 2005 06:15:53 GMT"/>
	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">True</property>
	  <property name="pack_type">GTK_PACK_END</property>
	</packing>
      </child>

      <child>
	<widget class="GtkAlignment" id="alignment12">
	  <property name="visible">True</property>
	  <property name="xalign">0.5</property>
	  <property name="yalign">0.5</property>
	  <property name="xscale">1</property>
	  <property name="yscale">1</property>
	  <property name="top_padding">2</property>
	  <property name="bottom_padding">5</property>
	  <property name="left_padding">5</property>
	  <property name="right_padding">5</property>

	  <child>
	    <widget class="GtkVBox" id="vbox5">
	      <property name="visible">True</property>
	      <property name="homogeneous">False</property>
	      <property name="spacing">0</property>

		  <child>
		    <widget class="GtkLabel" id="label17">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">&lt;b&gt;TV Show configuration&lt;/b&gt;</property>
		      <property name="use_underline">False</property>
		      <property name="use_markup">True</property>
		      <property name="justify">GTK_JUSTIFY_LEFT</property>
		      <property name="wrap">False</property>
		      <property name="selectable">False</property>
		      <property name="xalign">0</property>
		      <property name="yalign">0</property>
		      <property name="xpad">10</property>
		      <property name="ypad">10</property>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkAlignment" id="alignment7">
		      <property name="visible">True</property>
		      <property name="xalign">0.5</property>
		      <property name="yalign">0.5</property>
		      <property name="xscale">1</property>
		      <property name="yscale">1</property>
		      <property name="top_padding">0</property>
		      <property name="bottom_padding">5</property>
		      <property name="left_padding">20</property>
		      <property name="right_padding">10</property>

		      <child>
			<widget class="GtkTable" id="table1">
			  <property name="visible">True</property>
			  <property name="n_rows">4</property>
			  <property name="n_columns">2</property>
			  <property name="homogeneous">False</property>
			  <property name="row_spacing">5</property>
			  <property name="column_spacing">5</property>

			  <child>
			    <widget class="GtkLabel" id="label19">
			      <property name="visible">True</property>
			      <property name="label" translatable="yes">XMLTV xml file </property>
			      <property name="use_underline">False</property>
			      <property name="use_markup">False</property>
			      <property name="justify">GTK_JUSTIFY_LEFT</property>
			      <property name="wrap">False</property>
			      <property name="selectable">False</property>
			      <property name="xalign">0</property>
			      <property name="yalign">0.5</property>
			      <property name="xpad">0</property>
			      <property name="ypad">0</property>
			    </widget>
			    <packing>
			      <property name="left_attach">0</property>
			      <property name="right_attach">1</property>
			      <property name="top_attach">0</property>
			      <property name="bottom_attach">1</property>
			      <property name="x_options">fill</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GnomeFileEntry" id="fileentry1">
			      <property name="visible">True</property>
			      <property name="max_saved">10</property>
			      <property name="directory_entry">False</property>
			      <property name="modal">False</property>
			      <property name="use_filechooser">True</property>
			      <property name="filechooser_action">GTK_FILE_CHOOSER_ACTION_OPEN</property>

			      <child internal-child="entry">
				<widget class="GtkEntry" id="xmltvfileentry">
				  <property name="visible">True</property>
				  <property name="can_focus">True</property>
				  <property name="editable">True</property>
				  <property name="visibility">True</property>
				  <property name="max_length">0</property>
				  <property name="text" translatable="yes"></property>
				  <property name="has_frame">True</property>
				  <property name="invisible_char">*</property>
				  <property name="activates_default">False</property>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="left_attach">1</property>
			      <property name="right_attach">2</property>
			      <property name="top_attach">0</property>
			      <property name="bottom_attach">1</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GtkCheckButton" id="viewpastshowscheckbutton">
			      <property name="visible">True</property>
			      <property name="tooltip" translatable="yes">If selected the tv show displays will show only future programs, not the ones already gone today.</property>
			      <property name="can_focus">True</property>
			      <property name="label" translatable="yes">View past shows</property>
			      <property name="use_underline">True</property>
			      <property name="relief">GTK_RELIEF_NONE</property>
			      <property name="focus_on_click">True</property>
			      <property name="active">False</property>
			      <property name="inconsistent">False</property>
			      <property name="draw_indicator">True</property>
			    </widget>
			    <packing>
			      <property name="left_attach">0</property>
			      <property name="right_attach">2</property>
			      <property name="top_attach">1</property>
			      <property name="bottom_attach">2</property>
			      <property name="x_options">fill</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GtkCheckButton" id="tablocationcheckbutton">
			      <property name="visible">True</property>
			      <property name="tooltip" translatable="yes">If selected the channel tabs are located on the left.</property>
			      <property name="can_focus">True</property>
			      <property name="label" translatable="yes">Tabs on left</property>
			      <property name="use_underline">True</property>
			      <property name="relief">GTK_RELIEF_NORMAL</property>
			      <property name="focus_on_click">True</property>
			      <property name="active">False</property>
			      <property name="inconsistent">False</property>
			      <property name="draw_indicator">True</property>
			    </widget>
			    <packing>
			      <property name="left_attach">0</property>
			      <property name="right_attach">2</property>
			      <property name="top_attach">2</property>
			      <property name="bottom_attach">3</property>
			      <property name="x_options">fill</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GtkCheckButton" id="loadimagescheckbutton">
			      <property name="visible">True</property>
			      <property name="tooltip" translatable="yes">Autoloads channel images if they are present in the XMLTV file.</property>
			      <property name="can_focus">True</property>
			      <property name="label" translatable="yes">Autoload channel images</property>
			      <property name="use_underline">True</property>
			      <property name="relief">GTK_RELIEF_NORMAL</property>
			      <property name="focus_on_click">True</property>
			      <property name="active">False</property>
			      <property name="inconsistent">False</property>
			      <property name="draw_indicator">True</property>
			    </widget>
			    <packing>
			      <property name="left_attach">0</property>
			      <property name="right_attach">2</property>
			      <property name="top_attach">3</property>
			      <property name="bottom_attach">4</property>
			      <property name="x_options">fill</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>
			</widget>
		      </child>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkLabel" id="label18">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">&lt;b&gt;Recording configuration&lt;/b&gt;</property>
		      <property name="use_underline">False</property>
		      <property name="use_markup">True</property>
		      <property name="justify">GTK_JUSTIFY_LEFT</property>
		      <property name="wrap">False</property>
		      <property name="selectable">False</property>
		      <property name="xalign">0</property>
		      <property name="yalign">0</property>
		      <property name="xpad">10</property>
		      <property name="ypad">10</property>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkAlignment" id="alignment8">
		      <property name="visible">True</property>
		      <property name="xalign">0.5</property>
		      <property name="yalign">0.5</property>
		      <property name="xscale">1</property>
		      <property name="yscale">1</property>
		      <property name="top_padding">0</property>
		      <property name="bottom_padding">5</property>
		      <property name="left_padding">20</property>
		      <property name="right_padding">10</property>

		      <child>
			<widget class="GtkTable" id="table2">
			  <property name="visible">True</property>
			  <property name="n_rows">3</property>
			  <property name="n_columns">2</property>
			  <property name="homogeneous">False</property>
			  <property name="row_spacing">5</property>
			  <property name="column_spacing">5</property>

			  <child>
			    <widget class="GtkLabel" id="label21">
			      <property name="visible">True</property>
			      <property name="label" translatable="yes">Show directory</property>
			      <property name="use_underline">False</property>
			      <property name="use_markup">False</property>
			      <property name="justify">GTK_JUSTIFY_LEFT</property>
			      <property name="wrap">False</property>
			      <property name="selectable">False</property>
			      <property name="xalign">0</property>
			      <property name="yalign">0.5</property>
			      <property name="xpad">2</property>
			      <property name="ypad">0</property>
			    </widget>
			    <packing>
			      <property name="left_attach">0</property>
			      <property name="right_attach">1</property>
			      <property name="top_attach">0</property>
			      <property name="bottom_attach">1</property>
			      <property name="x_options">fill</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GnomeFileEntry" id="fileentry2">
			      <property name="visible">True</property>
			      <property name="max_saved">10</property>
			      <property name="directory_entry">True</property>
			      <property name="modal">False</property>
			      <property name="use_filechooser">False</property>
			      <property name="filechooser_action">GTK_FILE_CHOOSER_ACTION_OPEN</property>

			      <child internal-child="entry">
				<widget class="GtkEntry" id="showdirentry">
				  <property name="visible">True</property>
				  <property name="can_focus">True</property>
				  <property name="editable">True</property>
				  <property name="visibility">True</property>
				  <property name="max_length">0</property>
				  <property name="text" translatable="yes">/tmp/</property>
				  <property name="has_frame">True</property>
				  <property name="invisible_char">*</property>
				  <property name="activates_default">False</property>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="left_attach">1</property>
			      <property name="right_attach">2</property>
			      <property name="top_attach">0</property>
			      <property name="bottom_attach">1</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GtkLabel" id="label22">
			      <property name="visible">True</property>
			      <property name="label" translatable="yes">Record command</property>
			      <property name="use_underline">False</property>
			      <property name="use_markup">False</property>
			      <property name="justify">GTK_JUSTIFY_LEFT</property>
			      <property name="wrap">False</property>
			      <property name="selectable">False</property>
			      <property name="xalign">0</property>
			      <property name="yalign">0.5</property>
			      <property name="xpad">2</property>
			      <property name="ypad">0</property>
			    </widget>
			    <packing>
			      <property name="left_attach">0</property>
			      <property name="right_attach">1</property>
			      <property name="top_attach">1</property>
			      <property name="bottom_attach">2</property>
			      <property name="x_options">fill</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GnomeFileEntry" id="fileentry3">
			      <property name="visible">True</property>
			      <property name="max_saved">10</property>
			      <property name="directory_entry">False</property>
			      <property name="modal">False</property>
			      <property name="use_filechooser">False</property>
			      <property name="filechooser_action">GTK_FILE_CHOOSER_ACTION_OPEN</property>

			      <child internal-child="entry">
				<widget class="GtkEntry" id="recordcommandentry">
				  <property name="visible">True</property>
				  <property name="can_focus">True</property>
				  <property name="editable">True</property>
				  <property name="visibility">True</property>
				  <property name="max_length">0</property>
				  <property name="text" translatable="yes"></property>
				  <property name="has_frame">True</property>
				  <property name="invisible_char">*</property>
				  <property name="activates_default">False</property>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="left_attach">1</property>
			      <property name="right_attach">2</property>
			      <property name="top_attach">1</property>
			      <property name="bottom_attach">2</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GtkLabel" id="label23">
			      <property name="visible">True</property>
			      <property name="label" translatable="yes">Cancel command</property>
			      <property name="use_underline">False</property>
			      <property name="use_markup">False</property>
			      <property name="justify">GTK_JUSTIFY_LEFT</property>
			      <property name="wrap">False</property>
			      <property name="selectable">False</property>
			      <property name="xalign">0</property>
			      <property name="yalign">0.5</property>
			      <property name="xpad">2</property>
			      <property name="ypad">0</property>
			    </widget>
			    <packing>
			      <property name="left_attach">0</property>
			      <property name="right_attach">1</property>
			      <property name="top_attach">2</property>
			      <property name="bottom_attach">3</property>
			      <property name="x_options">fill</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GnomeFileEntry" id="fileentry4">
			      <property name="visible">True</property>
			      <property name="max_saved">10</property>
			      <property name="directory_entry">False</property>
			      <property name="modal">False</property>
			      <property name="use_filechooser">False</property>
			      <property name="filechooser_action">GTK_FILE_CHOOSER_ACTION_OPEN</property>

			      <child internal-child="entry">
				<widget class="GtkEntry" id="cancelcommandentry">
				  <property name="visible">True</property>
				  <property name="can_focus">True</property>
				  <property name="editable">True</property>
				  <property name="visibility">True</property>
				  <property name="max_length">0</property>
				  <property name="text" translatable="yes"></property>
				  <property name="has_frame">True</property>
				  <property name="invisible_char">*</property>
				  <property name="activates_default">False</property>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="left_attach">1</property>
			      <property name="right_attach">2</property>
			      <property name="top_attach">2</property>
			      <property name="bottom_attach">3</property>
			      <property name="y_options"></property>
			    </packing>
			  </child>
			</widget>
		      </child>
		    </widget>
		  </child>

	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">True</property>
	  <property name="fill">True</property>
	</packing>
      </child>
    </widget>
  </child>
</widget>

<widget class="GtkDialog" id="favdialog">
  <property name="title" translatable="yes">TV Shows - Favourites</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="default_width">450</property>
  <property name="default_height">330</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">True</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="has_separator">False</property>

  <child internal-child="vbox">
    <widget class="GtkVBox" id="dialog-vbox3">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child internal-child="action_area">
	<widget class="GtkHButtonBox" id="dialog-action_area3">
	  <property name="visible">True</property>
	  <property name="layout_style">GTK_BUTTONBOX_END</property>

	  <child>
	    <widget class="GtkButton" id="okbutton2">
	      <property name="visible">True</property>
	      <property name="can_default">True</property>
	      <property name="can_focus">True</property>
	      <property name="label">gtk-close</property>
	      <property name="use_stock">True</property>
	      <property name="relief">GTK_RELIEF_NORMAL</property>
	      <property name="focus_on_click">True</property>
	      <property name="response_id">-7</property>
	      <signal name="clicked" handler="on_fav_close" last_modification_time="Mon, 16 May 2005 06:16:07 GMT"/>
	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">True</property>
	  <property name="pack_type">GTK_PACK_END</property>
	</packing>
      </child>

	  <child>
	    <widget class="GtkAlignment" id="alignment13">
	      <property name="visible">True</property>
	      <property name="xalign">0.5</property>
	      <property name="yalign">0.5</property>
	      <property name="xscale">1</property>
	      <property name="yscale">1</property>
	      <property name="top_padding">8</property>
	      <property name="bottom_padding">10</property>
	      <property name="left_padding">10</property>
	      <property name="right_padding">10</property>

	      <child>
		<widget class="GtkVBox" id="vbox7">
		  <property name="visible">True</property>
		  <property name="homogeneous">False</property>
		  <property name="spacing">0</property>

	  <child>
	    <widget class="GtkLabel" id="label29">
	      <property name="visible">True</property>
	      <property name="label" translatable="yes">&lt;b&gt;Favourites configuration&lt;/b&gt;</property>
	      <property name="use_underline">False</property>
	      <property name="use_markup">True</property>
	      <property name="justify">GTK_JUSTIFY_LEFT</property>
	      <property name="wrap">False</property>
	      <property name="selectable">False</property>
	      <property name="xalign">0</property>
	      <property name="yalign">0</property>
	      <property name="xpad">0</property>
	      <property name="ypad">2</property>
	    </widget>
	    <packing>
	      <property name="padding">0</property>
	      <property name="expand">False</property>
	      <property name="fill">False</property>
	    </packing>
	  </child>

		  <child>
		    <widget class="GtkScrolledWindow" id="scrolledwindow8">
		      <property name="visible">True</property>
		      <property name="can_focus">True</property>
		      <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
		      <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
		      <property name="shadow_type">GTK_SHADOW_IN</property>
		      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

		      <child>
			<widget class="GtkTreeView" id="favpatterntreeview">
			  <property name="visible">True</property>
			  <property name="can_focus">True</property>
			  <property name="headers_visible">False</property>
			  <property name="rules_hint">False</property>
			  <property name="reorderable">False</property>
			  <property name="enable_search">True</property>
			</widget>
		      </child>
		    </widget>
		    <packing>
		      <property name="padding">5</property>
		      <property name="expand">True</property>
		      <property name="fill">True</property>
		    </packing>
		  </child>

		  <child>
		    <widget class="GtkHBox" id="hbox10">
		      <property name="visible">True</property>
		      <property name="homogeneous">False</property>
		      <property name="spacing">5</property>

		      <child>
			<widget class="GtkEntry" id="faventry">
			  <property name="visible">True</property>
			  <property name="can_focus">True</property>
			  <property name="editable">True</property>
			  <property name="visibility">True</property>
			  <property name="max_length">0</property>
			  <property name="text" translatable="yes"></property>
			  <property name="has_frame">True</property>
			  <property name="invisible_char">*</property>
			  <property name="activates_default">False</property>
			</widget>
			<packing>
			  <property name="padding">0</property>
			  <property name="expand">True</property>
			  <property name="fill">True</property>
			</packing>
		      </child>

		      <child>
			<widget class="GtkButton" id="addfavbutton">
			  <property name="visible">True</property>
			  <property name="can_focus">True</property>
			  <property name="label">gtk-add</property>
			  <property name="use_stock">True</property>
			  <property name="relief">GTK_RELIEF_NORMAL</property>
			  <property name="focus_on_click">True</property>
			  <signal name="clicked" handler="on_addfavbutton_clicked" last_modification_time="Fri, 02 Jul 2004 07:42:41 GMT"/>
			</widget>
			<packing>
			  <property name="padding">0</property>
			  <property name="expand">False</property>
			  <property name="fill">False</property>
			</packing>
		      </child>

		      <child>
			<widget class="GtkButton" id="removefavbutton">
			  <property name="visible">True</property>
			  <property name="can_focus">True</property>
			  <property name="label">gtk-remove</property>
			  <property name="use_stock">True</property>
			  <property name="relief">GTK_RELIEF_NORMAL</property>
			  <property name="focus_on_click">True</property>
			  <signal name="clicked" handler="on_removefavbutton_clicked" last_modification_time="Fri, 02 Jul 2004 07:42:49 GMT"/>
			</widget>
			<packing>
			  <property name="padding">0</property>
			  <property name="expand">False</property>
			  <property name="fill">False</property>
			</packing>
		      </child>
		    </widget>
		    <packing>
		      <property name="padding">0</property>
		      <property name="expand">False</property>
		      <property name="fill">False</property>
		    </packing>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>
	  
    </widget>
  </child>
</widget>

<widget class="GtkWindow" id="application">
  <property name="title" translatable="yes">TV Shows</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="default_width">720</property>
  <property name="default_height">500</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>

  <child>
    <widget class="GtkVBox" id="vbox8">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child>
	<widget class="GtkMenuBar" id="menubar">
	  <property name="visible">True</property>

	  <child>
	    <widget class="GtkMenuItem" id="file1">
	      <property name="visible">True</property>
	      <property name="stock_item">GNOMEUIINFO_MENU_FILE_TREE</property>

	      <child>
		<widget class="GtkMenu" id="file1_menu">

		  <child>
		    <widget class="GtkImageMenuItem" id="quit">
		      <property name="visible">True</property>
		      <property name="stock_item">GNOMEUIINFO_MENU_EXIT_ITEM</property>
		      <signal name="activate" handler="on_quit" last_modification_time="Tue, 29 Jun 2004 08:09:18 GMT"/>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>

	  <child>
	    <widget class="GtkMenuItem" id="view">
	      <property name="visible">True</property>
	      <property name="stock_item">GNOMEUIINFO_MENU_VIEW_TREE</property>

	      <child>
		<widget class="GtkMenu" id="view_menu">

		  <child>
		    <widget class="GtkRadioMenuItem" id="today">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">Today</property>
		      <property name="use_underline">True</property>
		      <property name="active">True</property>
		      <signal name="activate" handler="on_radioitem_activate" last_modification_time="Tue, 29 Jun 2004 07:30:02 GMT"/>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkRadioMenuItem" id="tomorrow">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">Tomorrow</property>
		      <property name="use_underline">True</property>
		      <property name="active">False</property>
		      <property name="group">today</property>
		      <signal name="activate" handler="on_radioitem_activate" last_modification_time="Tue, 29 Jun 2004 07:30:09 GMT"/>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkSeparatorMenuItem" id="separator">
		      <property name="visible">True</property>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>

	  <child>
	    <widget class="GtkMenuItem" id="settings2">
	      <property name="visible">True</property>
	      <property name="stock_item">GNOMEUIINFO_MENU_SETTINGS_TREE</property>

	      <child>
		<widget class="GtkMenu" id="settings2_menu">

		  <child>
		    <widget class="GtkImageMenuItem" id="preferences1">
		      <property name="visible">True</property>
		      <property name="stock_item">GNOMEUIINFO_MENU_PREFERENCES_ITEM</property>
		      <signal name="activate" handler="on_preferences_activate" last_modification_time="Thu, 01 Jul 2004 12:39:36 GMT"/>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkMenuItem" id="favourites1">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">_Favourites</property>
		      <property name="use_underline">True</property>
		      <signal name="activate" handler="on_favourites_activate" last_modification_time="Thu, 01 Jul 2004 12:39:29 GMT"/>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkMenuItem" id="channels">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">Channels</property>
		      <property name="use_underline">True</property>
		      <signal name="activate" handler="on_channel_configuration_activate" last_modification_time="Thu, 10 Feb 2005 10:05:42 GMT"/>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>

	  <child>
	    <widget class="GtkMenuItem" id="help1">
	      <property name="visible">True</property>
	      <property name="stock_item">GNOMEUIINFO_MENU_HELP_TREE</property>

	      <child>
		<widget class="GtkMenu" id="help1_menu">

		  <child>
		    <widget class="GtkMenuItem" id="information2">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">_Information</property>
		      <property name="use_underline">True</property>
		      <signal name="activate" handler="on_information_activate" last_modification_time="Thu, 01 Jul 2004 13:15:35 GMT"/>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkImageMenuItem" id="about">
		      <property name="visible">True</property>
		      <property name="stock_item">GNOMEUIINFO_MENU_ABOUT_ITEM</property>
		      <signal name="activate" handler="on_about_activate" last_modification_time="Mon, 28 Jun 2004 18:47:20 GMT"/>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>

      <child>
	<widget class="GtkVBox" id="vbox1">
	  <property name="visible">True</property>
	  <property name="homogeneous">False</property>
	  <property name="spacing">0</property>

	  <child>
	    <widget class="GtkHPaned" id="hpaned1">
	      <property name="visible">True</property>
	      <property name="can_focus">True</property>
	      <property name="position">400</property>

	      <child>
		<widget class="GtkNotebook" id="notebook">
		  <property name="visible">True</property>
		  <property name="can_focus">True</property>
		  <property name="show_tabs">True</property>
		  <property name="show_border">True</property>
		  <property name="tab_pos">GTK_POS_TOP</property>
		  <property name="scrollable">True</property>
		  <property name="enable_popup">True</property>

		  <child>
		    <widget class="GtkLabel" id="infolabel">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">Please configure</property>
		      <property name="use_underline">False</property>
		      <property name="use_markup">False</property>
		      <property name="justify">GTK_JUSTIFY_LEFT</property>
		      <property name="wrap">False</property>
		      <property name="selectable">False</property>
		      <property name="xalign">0.5</property>
		      <property name="yalign">0.5</property>
		      <property name="xpad">0</property>
		      <property name="ypad">0</property>
		    </widget>
		    <packing>
		      <property name="tab_expand">False</property>
		      <property name="tab_fill">True</property>
		    </packing>
		  </child>

		  <child>
		    <widget class="GtkLabel" id="label7">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">Channel notebook</property>
		      <property name="use_underline">False</property>
		      <property name="use_markup">False</property>
		      <property name="justify">GTK_JUSTIFY_LEFT</property>
		      <property name="wrap">False</property>
		      <property name="selectable">False</property>
		      <property name="xalign">0.5</property>
		      <property name="yalign">0.5</property>
		      <property name="xpad">0</property>
		      <property name="ypad">0</property>
		    </widget>
		    <packing>
		      <property name="type">tab</property>
		    </packing>
		  </child>
		</widget>
		<packing>
		  <property name="shrink">True</property>
		  <property name="resize">False</property>
		</packing>
	      </child>

	      <child>
		<widget class="GtkVPaned" id="vpaned1">
		  <property name="visible">True</property>
		  <property name="can_focus">True</property>
		  <property name="position">410</property>

		  <child>
		    <widget class="GtkNotebook" id="rightnotebook">
		      <property name="visible">True</property>
		      <property name="can_focus">True</property>
		      <property name="show_tabs">True</property>
		      <property name="show_border">True</property>
		      <property name="tab_pos">GTK_POS_TOP</property>
		      <property name="scrollable">True</property>
		      <property name="enable_popup">True</property>

		      <child>
			<widget class="GtkVBox" id="vbox3">
			  <property name="visible">True</property>
			  <property name="homogeneous">False</property>
			  <property name="spacing">0</property>

			  <child>
			    <widget class="GtkHButtonBox" id="hbuttonbox1">
			      <property name="border_width">4</property>
			      <property name="visible">True</property>
			      <property name="layout_style">GTK_BUTTONBOX_END</property>
			      <property name="spacing">4</property>

			      <child>
				<widget class="GtkButton" id="cancelbutton">
				  <property name="visible">True</property>
				  <property name="tooltip" translatable="yes">Cancel a preprogrammed recording.</property>
				  <property name="can_default">True</property>
				  <property name="can_focus">True</property>
				  <property name="label">gtk-cancel</property>
				  <property name="use_stock">True</property>
				  <property name="relief">GTK_RELIEF_NORMAL</property>
				  <property name="focus_on_click">True</property>
				  <signal name="clicked" handler="on_cancelbutton_clicked" last_modification_time="Wed, 30 Jun 2004 13:39:57 GMT"/>
				</widget>
			      </child>

			      <child>
				<widget class="GtkButton" id="recordbutton">
				  <property name="visible">True</property>
				  <property name="tooltip" translatable="yes">Record a show</property>
				  <property name="can_default">True</property>
				  <property name="can_focus">True</property>
				  <property name="relief">GTK_RELIEF_NORMAL</property>
				  <property name="focus_on_click">True</property>
				  <signal name="clicked" handler="on_recordbutton_clicked" last_modification_time="Wed, 30 Jun 2004 13:39:36 GMT"/>

				  <child>
				    <widget class="GtkAlignment" id="alignment5">
				      <property name="visible">True</property>
				      <property name="xalign">0.5</property>
				      <property name="yalign">0.5</property>
				      <property name="xscale">0</property>
				      <property name="yscale">0</property>
				      <property name="top_padding">0</property>
				      <property name="bottom_padding">0</property>
				      <property name="left_padding">0</property>
				      <property name="right_padding">0</property>

				      <child>
					<widget class="GtkHBox" id="hbox4">
					  <property name="visible">True</property>
					  <property name="homogeneous">False</property>
					  <property name="spacing">2</property>

					  <child>
					    <widget class="GtkImage" id="image4">
					      <property name="visible">True</property>
					      <property name="stock">gtk-save</property>
					      <property name="icon_size">4</property>
					      <property name="xalign">0.5</property>
					      <property name="yalign">0.5</property>
					      <property name="xpad">0</property>
					      <property name="ypad">0</property>
					    </widget>
					    <packing>
					      <property name="padding">0</property>
					      <property name="expand">False</property>
					      <property name="fill">False</property>
					    </packing>
					  </child>

					  <child>
					    <widget class="GtkLabel" id="label15">
					      <property name="visible">True</property>
					      <property name="label" translatable="yes">_Record</property>
					      <property name="use_underline">True</property>
					      <property name="use_markup">False</property>
					      <property name="justify">GTK_JUSTIFY_LEFT</property>
					      <property name="wrap">False</property>
					      <property name="selectable">False</property>
					      <property name="xalign">0.5</property>
					      <property name="yalign">0.5</property>
					      <property name="xpad">0</property>
					      <property name="ypad">0</property>
					    </widget>
					    <packing>
					      <property name="padding">0</property>
					      <property name="expand">False</property>
					      <property name="fill">False</property>
					    </packing>
					  </child>
					</widget>
				      </child>
				    </widget>
				  </child>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="padding">0</property>
			      <property name="expand">False</property>
			      <property name="fill">False</property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GtkScrolledWindow" id="scrolledwindow4">
			      <property name="border_width">2</property>
			      <property name="visible">True</property>
			      <property name="can_focus">True</property>
			      <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
			      <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
			      <property name="shadow_type">GTK_SHADOW_IN</property>
			      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

			      <child>
				<widget class="GtkTreeView" id="recordingtreeview">
				  <property name="visible">True</property>
				  <property name="can_focus">True</property>
				  <property name="headers_visible">True</property>
				  <property name="rules_hint">False</property>
				  <property name="reorderable">True</property>
				  <property name="enable_search">True</property>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="padding">0</property>
			      <property name="expand">True</property>
			      <property name="fill">True</property>
			    </packing>
			  </child>
			</widget>
			<packing>
			  <property name="tab_expand">False</property>
			  <property name="tab_fill">True</property>
			</packing>
		      </child>

		      <child>
			<widget class="GtkLabel" id="label10">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">Recording</property>
			  <property name="use_underline">False</property>
			  <property name="use_markup">False</property>
			  <property name="justify">GTK_JUSTIFY_LEFT</property>
			  <property name="wrap">False</property>
			  <property name="selectable">False</property>
			  <property name="xalign">0.5</property>
			  <property name="yalign">0.5</property>
			  <property name="xpad">0</property>
			  <property name="ypad">0</property>
			</widget>
			<packing>
			  <property name="type">tab</property>
			</packing>
		      </child>

		      <child>
			<widget class="GtkVBox" id="vbox2">
			  <property name="visible">True</property>
			  <property name="homogeneous">False</property>
			  <property name="spacing">0</property>

			  <child>
			    <widget class="GtkHButtonBox" id="hbuttonbox5">
			      <property name="border_width">4</property>
			      <property name="visible">True</property>
			      <property name="layout_style">GTK_BUTTONBOX_END</property>
			      <property name="spacing">4</property>

			      <child>
				<widget class="GtkButton" id="button25">
				  <property name="visible">True</property>
				  <property name="can_default">True</property>
				  <property name="can_focus">True</property>
				  <property name="label">gtk-preferences</property>
				  <property name="use_stock">True</property>
				  <property name="relief">GTK_RELIEF_NORMAL</property>
				  <property name="focus_on_click">True</property>
				  <signal name="clicked" handler="on_addbutton_clicked" last_modification_time="Fri, 02 Jul 2004 05:57:18 GMT"/>
				</widget>
			      </child>

			      <child>
				<widget class="GtkButton" id="button17">
				  <property name="visible">True</property>
				  <property name="tooltip" translatable="yes">Record a show</property>
				  <property name="can_default">True</property>
				  <property name="can_focus">True</property>
				  <property name="relief">GTK_RELIEF_NORMAL</property>
				  <property name="focus_on_click">True</property>
				  <signal name="clicked" handler="on_recordbutton_clicked" last_modification_time="Wed, 30 Jun 2004 13:39:36 GMT"/>

				  <child>
				    <widget class="GtkAlignment" id="alignment11">
				      <property name="visible">True</property>
				      <property name="xalign">0.5</property>
				      <property name="yalign">0.5</property>
				      <property name="xscale">0</property>
				      <property name="yscale">0</property>
				      <property name="top_padding">0</property>
				      <property name="bottom_padding">0</property>
				      <property name="left_padding">0</property>
				      <property name="right_padding">0</property>

				      <child>
					<widget class="GtkHBox" id="hbox9">
					  <property name="visible">True</property>
					  <property name="homogeneous">False</property>
					  <property name="spacing">2</property>

					  <child>
					    <widget class="GtkImage" id="image8">
					      <property name="visible">True</property>
					      <property name="stock">gtk-save</property>
					      <property name="icon_size">4</property>
					      <property name="xalign">0.5</property>
					      <property name="yalign">0.5</property>
					      <property name="xpad">0</property>
					      <property name="ypad">0</property>
					    </widget>
					    <packing>
					      <property name="padding">0</property>
					      <property name="expand">False</property>
					      <property name="fill">False</property>
					    </packing>
					  </child>

					  <child>
					    <widget class="GtkLabel" id="label27">
					      <property name="visible">True</property>
					      <property name="label" translatable="yes">_Record</property>
					      <property name="use_underline">True</property>
					      <property name="use_markup">False</property>
					      <property name="justify">GTK_JUSTIFY_LEFT</property>
					      <property name="wrap">False</property>
					      <property name="selectable">False</property>
					      <property name="xalign">0.5</property>
					      <property name="yalign">0.5</property>
					      <property name="xpad">0</property>
					      <property name="ypad">0</property>
					    </widget>
					    <packing>
					      <property name="padding">0</property>
					      <property name="expand">False</property>
					      <property name="fill">False</property>
					    </packing>
					  </child>
					</widget>
				      </child>
				    </widget>
				  </child>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="padding">0</property>
			      <property name="expand">False</property>
			      <property name="fill">False</property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GtkScrolledWindow" id="scrolledwindow3">
			      <property name="border_width">2</property>
			      <property name="visible">True</property>
			      <property name="can_focus">True</property>
			      <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
			      <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
			      <property name="shadow_type">GTK_SHADOW_IN</property>
			      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

			      <child>
				<widget class="GtkTreeView" id="favouritestreeview">
				  <property name="visible">True</property>
				  <property name="can_focus">True</property>
				  <property name="headers_visible">True</property>
				  <property name="rules_hint">True</property>
				  <property name="reorderable">False</property>
				  <property name="enable_search">True</property>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="padding">0</property>
			      <property name="expand">True</property>
			      <property name="fill">True</property>
			    </packing>
			  </child>
			</widget>
			<packing>
			  <property name="tab_expand">False</property>
			  <property name="tab_fill">True</property>
			</packing>
		      </child>

		      <child>
			<widget class="GtkLabel" id="label11">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">Favourites</property>
			  <property name="use_underline">False</property>
			  <property name="use_markup">False</property>
			  <property name="justify">GTK_JUSTIFY_LEFT</property>
			  <property name="wrap">False</property>
			  <property name="selectable">False</property>
			  <property name="xalign">0.5</property>
			  <property name="yalign">0.5</property>
			  <property name="xpad">0</property>
			  <property name="ypad">0</property>
			</widget>
			<packing>
			  <property name="type">tab</property>
			</packing>
		      </child>

		      <child>
			<widget class="GtkVBox" id="vbox4">
			  <property name="visible">True</property>
			  <property name="homogeneous">False</property>
			  <property name="spacing">0</property>

			  <child>
			    <widget class="GtkHButtonBox" id="hbuttonbox2">
			      <property name="border_width">4</property>
			      <property name="visible">True</property>
			      <property name="layout_style">GTK_BUTTONBOX_END</property>
			      <property name="spacing">4</property>

			      <child>
				<widget class="GtkButton" id="nautilusbutton">
				  <property name="visible">True</property>
				  <property name="tooltip" translatable="yes">Open file manager window to recorded shows directory.</property>
				  <property name="can_default">True</property>
				  <property name="can_focus">True</property>
				  <property name="relief">GTK_RELIEF_NORMAL</property>
				  <property name="focus_on_click">True</property>
				  <signal name="clicked" handler="on_nautilusbutton_clicked" last_modification_time="Thu, 01 Jul 2004 08:52:42 GMT"/>

				  <child>
				    <widget class="GtkAlignment" id="alignment9">
				      <property name="visible">True</property>
				      <property name="xalign">0.5</property>
				      <property name="yalign">0.5</property>
				      <property name="xscale">0</property>
				      <property name="yscale">0</property>
				      <property name="top_padding">0</property>
				      <property name="bottom_padding">0</property>
				      <property name="left_padding">0</property>
				      <property name="right_padding">0</property>

				      <child>
					<widget class="GtkHBox" id="hbox6">
					  <property name="visible">True</property>
					  <property name="homogeneous">False</property>
					  <property name="spacing">2</property>

					  <child>
					    <widget class="GtkImage" id="image6">
					      <property name="visible">True</property>
					      <property name="stock">gtk-open</property>
					      <property name="icon_size">4</property>
					      <property name="xalign">0.5</property>
					      <property name="yalign">0.5</property>
					      <property name="xpad">0</property>
					      <property name="ypad">0</property>
					    </widget>
					    <packing>
					      <property name="padding">0</property>
					      <property name="expand">False</property>
					      <property name="fill">False</property>
					    </packing>
					  </child>

					  <child>
					    <widget class="GtkLabel" id="label25">
					      <property name="visible">True</property>
					      <property name="label" translatable="yes">_Nautilus</property>
					      <property name="use_underline">True</property>
					      <property name="use_markup">False</property>
					      <property name="justify">GTK_JUSTIFY_LEFT</property>
					      <property name="wrap">False</property>
					      <property name="selectable">False</property>
					      <property name="xalign">0.5</property>
					      <property name="yalign">0.5</property>
					      <property name="xpad">0</property>
					      <property name="ypad">0</property>
					    </widget>
					    <packing>
					      <property name="padding">0</property>
					      <property name="expand">False</property>
					      <property name="fill">False</property>
					    </packing>
					  </child>
					</widget>
				      </child>
				    </widget>
				  </child>
				</widget>
			      </child>

			      <child>
				<widget class="GtkButton" id="watchbutton">
				  <property name="visible">True</property>
				  <property name="tooltip" translatable="yes">Open the recorded show file.</property>
				  <property name="can_default">True</property>
				  <property name="can_focus">True</property>
				  <property name="relief">GTK_RELIEF_NORMAL</property>
				  <property name="focus_on_click">True</property>
				  <signal name="clicked" handler="on_watchbutton_clicked" last_modification_time="Wed, 30 Jun 2004 13:40:52 GMT"/>

				  <child>
				    <widget class="GtkAlignment" id="alignment6">
				      <property name="visible">True</property>
				      <property name="xalign">0.5</property>
				      <property name="yalign">0.5</property>
				      <property name="xscale">0</property>
				      <property name="yscale">0</property>
				      <property name="top_padding">0</property>
				      <property name="bottom_padding">0</property>
				      <property name="left_padding">0</property>
				      <property name="right_padding">0</property>

				      <child>
					<widget class="GtkHBox" id="hbox5">
					  <property name="visible">True</property>
					  <property name="homogeneous">False</property>
					  <property name="spacing">2</property>

					  <child>
					    <widget class="GtkImage" id="image5">
					      <property name="visible">True</property>
					      <property name="stock">gtk-zoom-fit</property>
					      <property name="icon_size">4</property>
					      <property name="xalign">0.5</property>
					      <property name="yalign">0.5</property>
					      <property name="xpad">0</property>
					      <property name="ypad">0</property>
					    </widget>
					    <packing>
					      <property name="padding">0</property>
					      <property name="expand">False</property>
					      <property name="fill">False</property>
					    </packing>
					  </child>

					  <child>
					    <widget class="GtkLabel" id="label16">
					      <property name="visible">True</property>
					      <property name="label" translatable="yes">_Watch</property>
					      <property name="use_underline">True</property>
					      <property name="use_markup">False</property>
					      <property name="justify">GTK_JUSTIFY_LEFT</property>
					      <property name="wrap">False</property>
					      <property name="selectable">False</property>
					      <property name="xalign">0.5</property>
					      <property name="yalign">0.5</property>
					      <property name="xpad">0</property>
					      <property name="ypad">0</property>
					    </widget>
					    <packing>
					      <property name="padding">0</property>
					      <property name="expand">False</property>
					      <property name="fill">False</property>
					    </packing>
					  </child>
					</widget>
				      </child>
				    </widget>
				  </child>
				</widget>
			      </child>

			      <child>
				<widget class="GtkButton" id="deletebutton">
				  <property name="visible">True</property>
				  <property name="tooltip" translatable="yes">Remove show information about a recorded show.</property>
				  <property name="can_default">True</property>
				  <property name="can_focus">True</property>
				  <property name="label">gtk-delete</property>
				  <property name="use_stock">True</property>
				  <property name="relief">GTK_RELIEF_NORMAL</property>
				  <property name="focus_on_click">True</property>
				  <signal name="clicked" handler="on_deletebutton_clicked" last_modification_time="Thu, 01 Jul 2004 08:53:04 GMT"/>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="padding">0</property>
			      <property name="expand">False</property>
			      <property name="fill">False</property>
			    </packing>
			  </child>

			  <child>
			    <widget class="GtkScrolledWindow" id="scrolledwindow5">
			      <property name="border_width">2</property>
			      <property name="visible">True</property>
			      <property name="can_focus">True</property>
			      <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
			      <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
			      <property name="shadow_type">GTK_SHADOW_IN</property>
			      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

			      <child>
				<widget class="GtkTreeView" id="recordedtreeview">
				  <property name="visible">True</property>
				  <property name="can_focus">True</property>
				  <property name="headers_visible">True</property>
				  <property name="rules_hint">False</property>
				  <property name="reorderable">False</property>
				  <property name="enable_search">True</property>
				</widget>
			      </child>
			    </widget>
			    <packing>
			      <property name="padding">0</property>
			      <property name="expand">True</property>
			      <property name="fill">True</property>
			    </packing>
			  </child>
			</widget>
			<packing>
			  <property name="tab_expand">False</property>
			  <property name="tab_fill">True</property>
			</packing>
		      </child>

		      <child>
			<widget class="GtkLabel" id="label13">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">On disk</property>
			  <property name="use_underline">False</property>
			  <property name="use_markup">False</property>
			  <property name="justify">GTK_JUSTIFY_LEFT</property>
			  <property name="wrap">False</property>
			  <property name="selectable">False</property>
			  <property name="xalign">0.5</property>
			  <property name="yalign">0.5</property>
			  <property name="xpad">0</property>
			  <property name="ypad">0</property>
			</widget>
			<packing>
			  <property name="type">tab</property>
			</packing>
		      </child>
		    </widget>
		    <packing>
		      <property name="shrink">True</property>
		      <property name="resize">True</property>
		    </packing>
		  </child>

		  <child>
		    <widget class="GtkFrame" id="frame3">
		      <property name="height_request">90</property>
		      <property name="visible">True</property>
		      <property name="label_xalign">0</property>
		      <property name="label_yalign">0.5</property>
		      <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>

		      <child>
			<widget class="GtkAlignment" id="alignment4">
			  <property name="visible">True</property>
			  <property name="xalign">0</property>
			  <property name="yalign">0.5</property>
			  <property name="xscale">1</property>
			  <property name="yscale">1</property>
			  <property name="top_padding">0</property>
			  <property name="bottom_padding">0</property>
			  <property name="left_padding">12</property>
			  <property name="right_padding">0</property>

			  <child>
			    <widget class="GtkScrolledWindow" id="scrolledwindow2">
			      <property name="visible">True</property>
			      <property name="can_focus">True</property>
			      <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
			      <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
			      <property name="shadow_type">GTK_SHADOW_NONE</property>
			      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

			      <child>
				<widget class="GtkViewport" id="viewport1">
				  <property name="visible">True</property>
				  <property name="shadow_type">GTK_SHADOW_NONE</property>

				  <child>
				    <widget class="GtkLabel" id="label">
				      <property name="visible">True</property>
				      <property name="can_focus">True</property>
				      <property name="label" translatable="yes">Shows description</property>
				      <property name="use_underline">False</property>
				      <property name="use_markup">False</property>
				      <property name="justify">GTK_JUSTIFY_LEFT</property>
				      <property name="wrap">True</property>
				      <property name="selectable">True</property>
				      <property name="xalign">0</property>
				      <property name="yalign">0.5</property>
				      <property name="xpad">0</property>
				      <property name="ypad">0</property>
				    </widget>
				  </child>
				</widget>
			      </child>
			    </widget>
			  </child>
			</widget>
		      </child>

		      <child>
			<widget class="GtkLabel" id="label5">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">Details</property>
			  <property name="use_underline">False</property>
			  <property name="use_markup">True</property>
			  <property name="justify">GTK_JUSTIFY_LEFT</property>
			  <property name="wrap">False</property>
			  <property name="selectable">False</property>
			  <property name="xalign">0.5</property>
			  <property name="yalign">0.5</property>
			  <property name="xpad">0</property>
			  <property name="ypad">0</property>
			</widget>
			<packing>
			  <property name="type">label_item</property>
			</packing>
		      </child>
		    </widget>
		    <packing>
		      <property name="shrink">True</property>
		      <property name="resize">True</property>
		    </packing>
		  </child>
		</widget>
		<packing>
		  <property name="shrink">True</property>
		  <property name="resize">True</property>
		</packing>
	      </child>
	    </widget>
	    <packing>
	      <property name="padding">0</property>
	      <property name="expand">True</property>
	      <property name="fill">True</property>
	    </packing>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">True</property>
	  <property name="fill">True</property>
	</packing>
      </child>

      <child>
	<widget class="GtkStatusbar" id="statusbar">
	  <property name="visible">True</property>
	  <property name="has_resize_grip">True</property>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>
    </widget>
  </child>
</widget>

<widget class="GtkDialog" id="channelconfdialog">
  <property name="title" translatable="yes">TV Shows - Channels</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="default_height">450</property>
  <property name="default_width">400</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="has_separator">False</property>

  <child internal-child="vbox">
    <widget class="GtkVBox" id="dialog-vbox4">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child internal-child="action_area">
	<widget class="GtkHButtonBox" id="dialog-action_area4">
	  <property name="visible">True</property>
	  <property name="layout_style">GTK_BUTTONBOX_END</property>

	  <child>
	    <widget class="GtkButton" id="okbutton3">
	      <property name="visible">True</property>
	      <property name="can_default">True</property>
	      <property name="can_focus">True</property>
	      <property name="label">gtk-close</property>
	      <property name="use_stock">True</property>
	      <property name="relief">GTK_RELIEF_NORMAL</property>
	      <property name="focus_on_click">True</property>
	      <property name="response_id">-7</property>
	      <signal name="clicked" handler="on_channel_close" last_modification_time="Mon, 16 May 2005 06:16:41 GMT"/>
	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">True</property>
	  <property name="pack_type">GTK_PACK_END</property>
	</packing>
      </child>

	  <child>
	    <widget class="GtkLabel" id="label30">
	      <property name="visible">True</property>
	      <property name="label" translatable="yes">&lt;b&gt;Select the channels to show and their order&lt;/b&gt;</property>
	      <property name="use_underline">False</property>
	      <property name="use_markup">True</property>
	      <property name="justify">GTK_JUSTIFY_LEFT</property>
	      <property name="wrap">False</property>
	      <property name="selectable">False</property>
	      <property name="xalign">0</property>
	      <property name="yalign">0</property>
	      <property name="xpad">10</property>
	      <property name="ypad">10</property>
	    </widget>
	    <packing>
	      <property name="padding">0</property>
	      <property name="expand">False</property>
	      <property name="fill">False</property>
	    </packing>
	  </child>

	  <child>
	    <widget class="GtkAlignment" id="alignment14">
	      <property name="visible">True</property>
	      <property name="xalign">0.5</property>
	      <property name="yalign">0.5</property>
	      <property name="xscale">1</property>
	      <property name="yscale">1</property>
	      <property name="top_padding">0</property>
	      <property name="bottom_padding">10</property>
	      <property name="left_padding">10</property>
	      <property name="right_padding">10</property>

	      <child>
		<widget class="GtkScrolledWindow" id="scrolledwindow9">
		  <property name="visible">True</property>
		  <property name="can_focus">True</property>
		  <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
		  <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
		  <property name="shadow_type">GTK_SHADOW_IN</property>
		  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

		  <child>
		    <widget class="GtkTreeView" id="channelconftreeview">
		      <property name="visible">True</property>
		      <property name="can_focus">True</property>
		      <property name="headers_visible">False</property>
		      <property name="rules_hint">False</property>
		      <property name="reorderable">True</property>
		      <property name="enable_search">False</property>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>
    </widget>
  </child>
</widget>

<widget class="GtkWindow" id="progresswindow">
  <property name="visible">True</property>
  <property name="title" translatable="yes"></property>
  <property name="type">GTK_WINDOW_POPUP</property>
  <property name="window_position">GTK_WIN_POS_CENTER</property>
  <property name="modal">True</property>
  <property name="resizable">False</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">False</property>
  <property name="skip_taskbar_hint">True</property>
  <property name="skip_pager_hint">True</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>

  <child>
    <widget class="GtkViewport" id="viewport3">
      <property name="border_width">1</property>
      <property name="visible">True</property>
      <property name="shadow_type">GTK_SHADOW_ETCHED_OUT</property>

      <child>
	<widget class="GtkTable" id="table4">
	  <property name="border_width">1</property>
	  <property name="visible">True</property>
	  <property name="n_rows">1</property>
	  <property name="n_columns">1</property>
	  <property name="homogeneous">False</property>
	  <property name="row_spacing">0</property>
	  <property name="column_spacing">0</property>

	  <child>
	    <widget class="GtkHBox" id="hbox11">
	      <property name="visible">True</property>
	      <property name="homogeneous">False</property>
	      <property name="spacing">0</property>

	      <child>
		<widget class="GtkImage" id="image9">
		  <property name="visible">True</property>
		  <property name="pixbuf">/usr/share/pixmaps/gshowtv.png</property>
		  <property name="xalign">0.5</property>
		  <property name="yalign">0.5</property>
		  <property name="xpad">5</property>
		  <property name="ypad">0</property>
		</widget>
		<packing>
		  <property name="padding">0</property>
		  <property name="expand">True</property>
		  <property name="fill">True</property>
		</packing>
	      </child>

	      <child>
		<widget class="GtkVBox" id="vbox9">
		  <property name="visible">True</property>
		  <property name="homogeneous">False</property>
		  <property name="spacing">0</property>

		  <child>
		    <widget class="GtkLabel" id="progresslabel">
		      <property name="visible">True</property>
		      <property name="label" translatable="yes">Reading XMLTV file</property>
		      <property name="use_underline">False</property>
		      <property name="use_markup">False</property>
		      <property name="justify">GTK_JUSTIFY_LEFT</property>
		      <property name="wrap">False</property>
		      <property name="selectable">False</property>
		      <property name="xalign">0.5</property>
		      <property name="yalign">0.5</property>
		      <property name="xpad">0</property>
		      <property name="ypad">0</property>
		    </widget>
		    <packing>
		      <property name="padding">0</property>
		      <property name="expand">False</property>
		      <property name="fill">False</property>
		    </packing>
		  </child>

		  <child>
		    <widget class="GtkProgressBar" id="progress">
		      <property name="visible">True</property>
		      <property name="orientation">GTK_PROGRESS_LEFT_TO_RIGHT</property>
		      <property name="fraction">0</property>
		      <property name="pulse_step">0.10000000149</property>
		    </widget>
		    <packing>
		      <property name="padding">0</property>
		      <property name="expand">False</property>
		      <property name="fill">False</property>
		    </packing>
		  </child>
		</widget>
		<packing>
		  <property name="padding">0</property>
		  <property name="expand">True</property>
		  <property name="fill">True</property>
		</packing>
	      </child>
	    </widget>
	    <packing>
	      <property name="left_attach">0</property>
	      <property name="right_attach">1</property>
	      <property name="top_attach">0</property>
	      <property name="bottom_attach">1</property>
	    </packing>
	  </child>
	</widget>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>
