1 # This file is part of Email-Reminder.
3 # Email-Reminder is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License as
5 # published by the Free Software Foundation; either version 3 of the
6 # License, or (at your option) any later version.
8 # Email-Reminder is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with Email-Reminder; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 package EmailReminder
::EventStore
;
20 # Base class for all of the event stores.
22 # This class should never be used directly, use a derived class instead.
28 use Glib
::Object
::Subclass
30 interfaces
=> [ Gtk2
::TreeModel
:: ],
40 $self->{NB_EVENTS
} = 0;
46 my ($self, $event) = @_;
47 push (@
{$self->{EVENTS
}}, $event);
48 my $path = Gtk2
::TreePath
->new_from_string($#{$self->{EVENTS}});
49 my $iter = $self->get_iter($path);
50 $self->row_inserted($path, $iter);
57 my ($self, $path) = @_;
58 my $index = $path->get_indices();
60 $self->{EVENTS
}->[$index]->unlink_event();
61 splice(@
{$self->{EVENTS
}}, $index, 1);
64 # Send the necessary signals
65 $self->row_deleted($path);
66 if ($self->{NB_EVENTS
} > 0) {
67 my $iter = $self->get_iter($path);
68 return unless defined($iter);
70 $iter = $self->iter_next($iter);
71 while (defined($iter)) {
72 my $path = $self->get_path($iter);
73 $self->row_changed($path, $iter);
74 $iter = $self->iter_next($iter);
83 return $self->{NB_EVENTS
};
88 my ($self, $path) = @_;
89 my $index = $path->get_indices();
90 return $self->{EVENTS
}->[$index];
96 return $self->{EVENTS
};
101 my ($self, $event, $col) = @_;
103 if ($col == $ID_INDEX) {
104 return $event->get_id();
107 warn "Column '$col' is not a valid column.\n";
114 my ($self, $event, $col, $new_value) = @_;
115 if ($col == $ID_INDEX) {
116 warn "The ID column is read-only.\n";
119 warn "Column '$col' is not a valid column for value '$new_value'.\n";
126 my ($self, $path, $column, $new_value) = @_;
127 my $row_index = $path->get_indices();
128 my $event = $self->{EVENTS
}->[$row_index];
129 $self->set_event_column($event, $column, $new_value);
133 ########################
134 # Tree Model Interface #
135 ########################
145 return $self->{NB_COLUMNS
};
150 return 'Glib::String';
155 my ($self, $path) = @_;
157 my $index = $path->get_indices();
158 my $iter = [ $index, $index, undef, undef ];
160 # Find the first non-deleted item
161 unless (exists($self->{EVENTS
}->[$index])) {
162 $iter = $self->ITER_NEXT($iter);
170 my ($self, $iter) = @_;
171 return Gtk2
::TreePath
->new($iter->[1]);
176 my ($self, $iter, $column) = @_;
177 my $index = $iter->[1];
178 my $event = $self->{EVENTS
}->[$index];
179 return "(missing)" unless defined($event); # TODO: remove this
180 my $value = $self->get_event_column($event, $column);
181 return defined($value) ?
$value : "";
186 my ($self, $iter) = @_;
187 my $index = $iter->[1] + 1;
189 # Skip over deleted items
190 while ($index < @
{$self->{EVENTS
}}) {
191 if (exists($self->{EVENTS
}->[$index])) {
192 return [ $index, $index, undef, undef ];
200 # This is a list store, there are no children