Gtk2-Ex-ICal-Recur
view release on metacpan or search on metacpan
lib/Gtk2/Ex/ICal/Recur.pm view on Meta::CPAN
package Gtk2::Ex::ICal::Recur;
our $VERSION = '0.06';
use strict;
use warnings;
use Gtk2 '-init';
use Gtk2::Ex::Simple::Menu;
use Gtk2::Ex::Simple::List;
use Glib qw /TRUE FALSE/;
use Data::Dumper;
use Gtk2::Ex::ICal::Recur::Selection;
use DateTime::Event::ICal;
use Gtk2::Ex::CalendarButton;
###########################################################
# There are four public methods. The rest are all private #
###########################################################
sub new {
my ($class) = @_;
my $self = {};
$self->{freqspinbutton} = Gtk2::SpinButton->new_with_range(1,100,1);
$self->{freqcombobox} = Gtk2::ComboBox->new_text();
$self->{recurrencepatterntable} = Gtk2::Table->new(1,1,FALSE);
$self->{recurbox}->{hbox} = undef;
$self->{recurbox}->{buttons} = undef;
$self->{freqchoices} = [
{ 'label' => 'Year(s)' , 'code' => 'yearly' },
{ 'label' => 'Month(s)', 'code' => 'monthly' },
{ 'label' => 'Week(s)' , 'code' => 'weekly' },
{ 'label' => 'Day(s)' , 'code' => 'daily' },
];
$self->{exceptionslist} = undef;
$self->{icalselection} = Gtk2::Ex::ICal::Recur::Selection->new;
bless ($self, $class);
$self->{widget} = $self->package_all;
return $self;
}
sub update_preview {
my ($self) = @_;
my $temp = [
['Generating Preview'],
['Please wait...'],
];
my $none= [
['No dates matching'],
['your criteria...'],
];
@{$self->{preview}->{slist}->{data}} = @$temp;
$self->{preview}->{slist}->show_all;
$self->{model} = $self->get_model;
my $date_list = $self->generate_date_list($self->{model});
if ($#{@$date_list} >= 0) {
@{$self->{preview}->{slist}->{data}} = @$date_list;
} else {
@{$self->{preview}->{slist}->{data}} = @$none;
}
}
sub set_model {
my ($self, $model) = @_;
$self->{model} = $model;
$self->{recurbox}->{hbox} = undef;
my $temphash = $self->controller(0, 0);
$self->{recurbox}->{hbox}->[0]->[0] = $self->create_box(0,0,$temphash);
$self->packbox();
lib/Gtk2/Ex/ICal/Recur.pm view on Meta::CPAN
$text = "and $text" if ($count > 0);
$label->set_label($text);
$tooltips->set_tip(
$self->{recurbox}->{buttons}->[$level]->[$count]->{add},
'add another day',
undef
);
$tooltips->set_tip(
$self->{recurbox}->{buttons}->[$level]->[$count]->{remove},
'remove this day',
undef
);
$self->{recurbox}->{buttons}->[$level]->[$count]->{add}->set_sensitive(TRUE);
#$self->{recurbox}->{buttons}->[$level]->[$count]->{next}->set_sensitive(TRUE);
$self->{recurbox}->{buttons}->[$level]->[$count]->{remove}->set_sensitive(TRUE);
};
my $menu_tree = [
'^' => {
item_type => '<Branch>',
children => [
'by day' => {
item_type => '<Branch>',
children => $self->{icalselection}->month_day_by_day($callback),
},
'by week day' => {
item_type => '<Branch>',
children => $self->{icalselection}->month_day_by_week($callback),
},
],
},
];
if ($count > 0) {
# Understand the $count=0 selection
my $brother = $self->{recurbox}->{buttons}->[$level]->[0]->{type};
if ($brother eq 'byday') {
$menu_tree = [
'^' => {
item_type => '<Branch>',
children => [
'by week day' => {
item_type => '<Branch>',
children => $self->{icalselection}->month_day_by_week($callback),
},
],
},
];
} elsif ($brother eq 'bymonthday'){
$menu_tree = [
'^' => {
item_type => '<Branch>',
children => [
'by day' => {
item_type => '<Branch>',
children => $self->{icalselection}->month_day_by_day($callback),
},
],
},
];
}
}
my $menu = Gtk2::Ex::Simple::Menu->new(menu_tree => $menu_tree);
my $temphash = {};
$temphash->{simplemenu} = $menu;
$temphash->{label} = $label;
return $temphash;
}
sub day_of_the_week {
my ($self, $level, $count) = @_;
my $label = Gtk2::Label->new;
$label->set_markup('<span foreground="red">choose a day of the week</span>');
$label->set_alignment(0, 0.5);
my $tooltips = Gtk2::Tooltips->new;
my $callback = sub {
my ($data) = @_;
my $type = $data->[0];
my $text = $data->[1];
my $code = $data->[2];
$self->{recurbox}->{buttons}->[$level]->[$count]->{code} = $code;
$self->{recurbox}->{buttons}->[$level]->[$count]->{type} = $type;
$text = "and $text" if ($count > 0);
$label->set_label($text);
$tooltips->set_tip(
$self->{recurbox}->{buttons}->[$level]->[$count]->{add},
'add another weekday',
undef
);
$tooltips->set_tip(
$self->{recurbox}->{buttons}->[$level]->[$count]->{remove},
'remove this weekday',
undef
);
$self->{recurbox}->{buttons}->[$level]->[$count]->{add}->set_sensitive(TRUE);
#$self->{recurbox}->{buttons}->[$level]->[$count]->{next}->set_sensitive(TRUE);
$self->{recurbox}->{buttons}->[$level]->[$count]->{remove}->set_sensitive(TRUE);
};
my $menu_tree = [
'^' => {
item_type => '<Branch>',
children => $self->{icalselection}->week_day($callback),
},
];
my $menu = Gtk2::Ex::Simple::Menu->new(menu_tree => $menu_tree);
my $temphash = {};
$temphash->{simplemenu} = $menu;
$temphash->{label} = $label;
return $temphash;
}
sub month_or_day_of_the_year {
my ($self, $level, $count) = @_;
my $label = Gtk2::Label->new;
$label->set_markup('<span foreground="red">choose a month/week/day</span>');
$label->set_alignment(0, 0.5);
my $tooltips = Gtk2::Tooltips->new;
my $callback = sub {
my ($data) = @_;
my $type = $data->[0];
my $text = $data->[1];
my $code = $data->[2];
$self->{recurbox}->{buttons}->[$level]->[$count]->{code} = $code;
$self->{recurbox}->{buttons}->[$level]->[$count]->{type} = $type;
$text = "and $text" if ($count > 0);
$label->set_label($text);
if ($type eq 'bymonth') {
$tooltips->set_tip (
$self->{recurbox}->{buttons}->[$level]->[$count]->{add},
'add another month',
undef
);
$tooltips->set_tip (
$self->{recurbox}->{buttons}->[$level]->[$count]->{remove},
'remove this month',
undef
);
if ($#{@{$self->{recurbox}->{hbox}->[$level+1]}} <= 0) {
$self->{recurbox}->{buttons}->[$level]->[$count]->{next}->set_sensitive(TRUE);
}
} elsif ($type eq 'byyearday') {
$tooltips->set_tip(
$self->{recurbox}->{buttons}->[$level]->[$count]->{add},
'add another day',
undef
);
$tooltips->set_tip(
$self->{recurbox}->{buttons}->[$level]->[$count]->{remove},
'remove this day',
undef
);
} elsif ($type eq 'byweekno') {
$tooltips->set_tip(
$self->{recurbox}->{buttons}->[$level]->[$count]->{add},
'add another week',
undef
);
$tooltips->set_tip(
$self->{recurbox}->{buttons}->[$level]->[$count]->{remove},
'remove this week',
undef
);
if ($#{@{$self->{recurbox}->{hbox}->[$level+1]}} <= 0) {
$self->{recurbox}->{buttons}->[$level]->[$count]->{next}->set_sensitive(TRUE);
lib/Gtk2/Ex/ICal/Recur.pm view on Meta::CPAN
},
'by day of the year' => {
item_type => '<Branch>',
children => $self->{icalselection}->day_of_the_year($callback),
},
'by weeknumber of the year' => {
item_type => '<Branch>',
children => $self->{icalselection}->weeknumber_of_the_year($callback),
},
],
},
];
if ($count > 0) {
# Understand the $count=0 selection
my $brother = $self->{recurbox}->{buttons}->[$level]->[0]->{type};
if ($brother eq 'bymonth') {
$label->set_markup('<span foreground="red">choose another month</span>');
$label->set_alignment(0, 0.5);
$menu_tree = [
'^' => {
item_type => '<Branch>',
children => [
'by month of the year' => {
item_type => '<Branch>',
children => $self->{icalselection}->month_of_the_year($callback),
},
],
},
];
} elsif ($brother eq 'byweekno'){
$label->set_markup('<span foreground="red">choose another weeknumber</span>');
$label->set_alignment(0, 0.5);
$menu_tree = [
'^' => {
item_type => '<Branch>',
children => [
'by weeknumber of the year' => {
item_type => '<Branch>',
children => $self->{icalselection}->weeknumber_of_the_year($callback),
},
],
},
];
} elsif ($brother eq 'byyearday'){
$label->set_markup('<span foreground="red">choose another day</span>');
$label->set_alignment(0, 0.5);
$menu_tree = [
'^' => {
item_type => '<Branch>',
children => [
'by day of the year' => {
item_type => '<Branch>',
children => $self->{icalselection}->day_of_the_year($callback),
},
],
},
];
}
}
my $menu = Gtk2::Ex::Simple::Menu->new(menu_tree => $menu_tree);
my $temphash = {};
$temphash->{simplemenu} = $menu;
$temphash->{label} = $label;
return $temphash;
}
1;
__END__
=head1 NAME
Gtk2::Ex::ICal::Recur - A widget for scheduling a recurring
set of 'events' (events in the calendar sense). Like a meeting
appointment for example, on all mondays and thursdays for the next 3
months. Kinda like Evolution or Outlook meeting schedule.
=head1 DESCRIPTION
=head1 SYNOPSIS
my $recur = Gtk2::Ex::ICal::Recur->new;
my $model = {
'dtstart' => {
year => 2000,
month => 6,
day => 20,
},
'count' => 17,
'freq' => 'yearly',
'interval' => '5',
'byweekno' => [1, -1],
'byday' => ['su','fr', 'mo'],
};
$recur->set_model($model);
my $window = Gtk2::Window->new;
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
my $vbox = Gtk2::VBox->new(FALSE);
my $hbox = Gtk2::HBox->new(FALSE);
my $preview = Gtk2::Button->new_from_stock('gtk-preview');
$preview->signal_connect('clicked' =>
sub {
$recur->update_preview;
}
);
my $done = Gtk2::Button->new_from_stock('gtk-done');
$done->signal_connect('clicked' =>
sub {
print Dumper $recur->get_model;
}
);
=head1 METHODS
=head2 Gtk2::Ex::ICal::Recur->new()
Accepts no arguments. Returns the object.
( run in 0.468 second using v1.01-cache-2.11-cpan-39bf76dae61 )