File Coverage

blib/lib/Palm/ToDo.pm
Criterion Covered Total %
statement 44 92 47.8
branch 3 10 30.0
condition n/a
subroutine 7 11 63.6
pod 6 6 100.0
total 60 119 50.4


line stmt bran cond sub pod time code
1             package Palm::ToDo;
2             #
3             # ABSTRACT: Handler for Palm ToDo databases
4             #
5             # Copyright (C) 1999, 2000, Andrew Arensburger.
6             #
7             # This program is free software; you can redistribute it and/or modify
8             # it under the same terms as Perl itself.
9             #
10             # This program is distributed in the hope that it will be useful,
11             # but WITHOUT ANY WARRANTY; without even the implied warranty of
12             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
13             # GNU General Public License or the Artistic License for more details.
14              
15             # XXX - Bug: apparently, the first ToDo item shows up with a category
16             # of "unfiled"
17              
18 2     2   6344 use strict;
  2         3  
  2         60  
19 2     2   463 use Palm::Raw();
  2         367  
  2         27  
20 2     2   392 use Palm::StdAppInfo();
  2         2  
  2         32  
21              
22 2     2   8 use vars qw( $VERSION @ISA );
  2         2  
  2         1171  
23              
24             # One liner, to allow MakeMaker to work.
25             $VERSION = '1.015';
26             # This file is part of Palm 1.015 (February 14, 2015)
27              
28             @ISA = qw( Palm::StdAppInfo Palm::Raw );
29              
30             #'
31              
32             sub import
33             {
34 2     2   16 &Palm::PDB::RegisterPDBHandlers(__PACKAGE__,
35             [ "todo", "DATA" ],
36             );
37             }
38              
39             #'
40              
41             # new
42             # Create a new Palm::ToDo database, and return it
43             sub new
44             {
45 0     0 1 0 my $classname = shift;
46 0         0 my $self = $classname->SUPER::new(@_);
47             # Create a generic PDB. No need to rebless it,
48             # though.
49              
50 0         0 $self->{name} = "ToDoDB"; # Default
51 0         0 $self->{creator} = "todo";
52 0         0 $self->{type} = "DATA";
53 0         0 $self->{attributes}{resource} = 0;
54             # The PDB is not a resource database by
55             # default, but it's worth emphasizing,
56             # since ToDoDB is explicitly not a PRC.
57              
58             # Initialize the AppInfo block
59 0         0 $self->{appinfo} = {
60             dirty_appinfo => undef, # ?
61             sortOrder => undef, # ?
62             };
63              
64             # Add the standard AppInfo block stuff
65 0         0 &Palm::StdAppInfo::seed_StdAppInfo($self->{appinfo});
66              
67             # Give the PDB a blank sort block
68 0         0 $self->{sort} = undef;
69              
70             # Give the PDB an empty list of records
71 0         0 $self->{records} = [];
72              
73 0         0 return $self;
74             }
75              
76              
77             # new_Record
78             # Create a new, initialized record.
79             sub new_Record
80             {
81 0     0 1 0 my $classname = shift;
82 0         0 my $retval = $classname->SUPER::new_Record(@_);
83              
84             # Item has no due date by default.
85 0         0 $retval->{due_day} = undef;
86 0         0 $retval->{due_month} = undef;
87 0         0 $retval->{due_year} = undef;
88              
89 0         0 $retval->{completed} = 0; # Not completed
90 0         0 $retval->{priority} = 1;
91              
92             # Empty description, no note.
93 0         0 $retval->{description} = "";
94 0         0 $retval->{note} = undef;
95              
96 0         0 return $retval;
97             }
98              
99             # ParseAppInfoBlock
100             # Parse the AppInfo block for ToDo databases.
101             sub ParseAppInfoBlock
102             {
103 1     1 1 637 my $self = shift;
104 1         2 my $data = shift;
105 1         2 my $dirtyAppInfo;
106             my $sortOrder;
107 1         3 my $appinfo = {};
108 1         1 my $std_len;
109              
110             # Get the standard parts of the AppInfo block
111 1         5 $std_len = &Palm::StdAppInfo::parse_StdAppInfo($appinfo, $data);
112              
113 1         1 $data = $appinfo->{other}; # Look at the non-category part
114              
115             # Get the rest of the AppInfo block
116 1         2 my $unpackstr = # Argument to unpack()
117             "x2" . # Reserved
118             "n" . # XXX - Dirty AppInfo (what is this?)
119             "Cx"; # Sort order
120              
121 1         2 ($dirtyAppInfo, $sortOrder) = unpack $unpackstr, $data;
122              
123 1         2 $appinfo->{dirty_appinfo} = $dirtyAppInfo;
124 1         2 $appinfo->{sort_order} = $sortOrder;
125              
126 1         3 return $appinfo;
127             }
128              
129             sub PackAppInfoBlock
130             {
131 0     0 1 0 my $self = shift;
132 0         0 my $retval;
133              
134             # Pack the application-specific part of the AppInfo block
135 0         0 $self->{appinfo}{other} = pack("x2 n Cx",
136             $self->{appinfo}{dirty_appinfo},
137             $self->{appinfo}{sort_order});
138              
139             # Pack the AppInfo block
140 0         0 $retval = &Palm::StdAppInfo::pack_StdAppInfo($self->{appinfo});
141              
142 0         0 return $retval;
143             }
144              
145             sub ParseRecord
146             {
147 1     1 1 34 my $self = shift;
148 1         3 my %record = @_;
149 1         2 my $data = $record{data};
150              
151 1         2 delete $record{offset}; # This is useless
152 1         2 delete $record{data}; # No longer necessary
153              
154 1         1 my $date;
155             my $priority;
156              
157 1         3 ($date, $priority) = unpack "n C", $data;
158 1         2 $data = substr $data, 3; # Remove the stuff we've already seen
159              
160 1 50       4 if ($date != 0xffff)
161             {
162 0         0 my $day;
163             my $month;
164 0         0 my $year;
165              
166 0         0 $day = $date & 0x001f; # 5 bits
167 0         0 $month = ($date >> 5) & 0x000f; # 4 bits
168 0         0 $year = ($date >> 9) & 0x007f; # 7 bits (years since 1904)
169 0         0 $year += 1904;
170              
171 0         0 $record{due_day} = $day;
172 0         0 $record{due_month} = $month;
173 0         0 $record{due_year} = $year;
174             }
175              
176 1         2 my $completed; # Boolean
177              
178 1         2 $completed = $priority & 0x80;
179 1         1 $priority &= 0x7f; # Strip high bit
180              
181 1 50       2 $record{completed} = 1 if $completed;
182 1         2 $record{priority} = $priority;
183              
184 1         2 my $description;
185             my $note;
186              
187 1         4 ($description, $note) = split /\0/, $data;
188              
189 1         1 $record{description} = $description;
190 1 50       3 $record{note} = $note unless $note eq "";
191              
192 1         3 return \%record;
193             }
194              
195             sub PackRecord
196             {
197 0     0 1   my $self = shift;
198 0           my $record = shift;
199 0           my $retval;
200             my $rawDate;
201 0           my $priority;
202              
203 0 0         if (defined($record->{due_day}))
204             {
205 0           $rawDate = ($record->{due_day} & 0x001f) |
206             (($record->{due_month} & 0x000f) << 5) |
207             ((($record->{due_year} - 1904) & 0x007f) << 9);
208             } else {
209 0           $rawDate = 0xffff;
210             }
211 0           $priority = $record->{priority} & 0x7f;
212 0 0         $priority |= 0x80 if $record->{completed};
213              
214 0           $retval = pack "n C",
215             $rawDate,
216             $priority;
217 0           $retval .= $record->{description} . "\0";
218 0           $retval .= $record->{note} . "\0";
219              
220 0           return $retval;
221             }
222              
223             1;
224              
225             __END__