#!/usr/bin/perl ################################################################################# # Application that parses out the XML output from the Gnome Applet "Sticky # Notes" & enables the user to either E-Mail the note using mutt, or install the # memo to their Palm. ########################## Version 0.3 ########################################## ####################### By Daryn Hanright ####################################### ################################################################################# # Perl modules needed for this app use XML::Simple; use Tk; use Data::Dumper; use IO::File; use vars qw/$top/; use Time::localtime; # user changes these variables to match their system $home_dir = "/home/daz/.gnome2/"; $filename = "stickynote.txt"; $temp_dir = "/home/daz/tmp/"; $pilot_port = "/dev/pilot"; $write_file = "$temp_dir$filename"; my $file = $home_dir . 'stickynotes_applet'; # Read in Sticky Notes XML file my $stickynotes = XMLin($file); # print Dumper($stickynotes); # Vars for options to send Sticky Notes $choice_email = "E-Mail - Mutt"; $choice_palm_address = "Palm Address"; $choice_palm_date = "Palm DateBook"; $choice_palm_memo = "Palm MemoPad"; $choice_palm_todo = "Palm ToDo"; $choice_palm_doc = "Palm DOC"; $choice_txt = "Output TXT File"; #$temp_menu = ""; # Create Tk window $top = MainWindow->new(); # Quit button my $var = $top->Button(-text => 'QUIT!', -command => sub{exit} )->pack; # Label for Tk application my(@pl) = qw/-side top -expand yes -pady 2 -anchor w/; $top->Label(-text => 'StickyNotes')->pack(@pl); # Radio Buttons with choices my @pl = qw/-side left -expand 1 -padx .5c -pady .5c/; my $left = $top->Frame->pack(@pl); @pl = qw/-side top -pady 2 -anchor w/; $CHOICE = $choice_email; foreach my $p ($choice_email, $choice_palm_address, $choice_palm_date, $choice_palm_memo, $choice_palm_todo, $choice_palm_doc, $choice_txt) { $left->Radiobutton( -text => "$p", -variable => \$CHOICE, -relief => 'flat', -value => $p, )->pack(@pl); } # Listbox $var->pack(qw/-side bottom -expand 1/); $sticky_list = $top->Listbox("width" => 20, "height" => 10 )->pack(side => 'left', padx => 10); # Populate Listbox foreach my $note (@{$stickynotes->{note}}) { #$count++; $title = $note->{title}; $sticky_list->insert('end', "$title"); } # Scrollbar with Listbox $scroll = $top->Scrollbar(orient => 'vertical', width => 10, command => ['yview', $sticky_list] )->pack(side => 'left', fill => 'y', padx => 10); $sticky_list->configure(yscrollcommand => ['set', $scroll]); # Double-Click on Listbox & initiate apps $sticky_list->bind('', \&sticky_choice); sub sticky_choice { my $sticky = $sticky_list->get('active'); return if (!$sticky); # Return if no list item is active foreach my $note (@{$stickynotes->{note}}) { $title = $note->{title}; $content = $note->{content}; $tm = localtime; ($day, $month, $year) = ($tm->mday, $tm->mon, $tm->year); $year = $year + 1900; $month = $month + 1; open(FH, ">> $write_file") or die $!; sysopen(FH, $write_file, O_WRONLY|O_APPEND|O_CREAT) or die $!; sysopen(FH, $write_file, O_WRONLY|O_APPEND|O_CREAT, 0600) or die $!; if ($title =~ $sticky) { # If choice is E-Mail send info to Mutt if ($CHOICE =~ $choice_email) { print FH "$content\n"; $install = "mutt -s \"$title\" -i $write_file"; system $install; close(FH); unlink($write_file); } # If choice is Palm Address install to Palm as Address if ($CHOICE =~ $choice_palm_address) { print FH "\"Dummy\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"0\"\n"; print FH "\"$title\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"$content\",\"0\"\n"; print "Initiating installation of Sticky Notes as a Palm Address...\n"; $install = "pilot-addresses -p $pilot_port -c Unfiled -r $write_file"; system $install; close(FH); unlink($write_file); } # If choice is Palm Date install to Palm as DateBook if ($CHOICE =~ $choice_palm_date) { $todays_date = "$year/$month/$day"; print FH "$todays_date 0800 GMT+1300 \t $todays_date 0900 GMT+1300 \t 1h \t $title - $content\n"; print "Initiating installation of Sticky Notes as a Palm DateBook...\n"; $install = "install-datebook -p $pilot_port -r $write_file"; system $install; close(FH); unlink($write_file); } # If choice is Palm Memo install to Palm as MemoPad if ($CHOICE =~ $choice_palm_memo) { print FH "$title\n$content\n"; print "Initiating installation of Sticky Notes as a Palm MemoPad...\n"; $install = "install-memo -p $pilot_port -c StickyNotes $write_file"; system $install; close(FH); unlink($write_file); } # If choice is Palm ToDo install to Palm as ToDo if ($CHOICE =~ $choice_palm_todo) { $todays_date = "$month/$day/$year"; print FH "$title - $content\n"; print "Initiating installation of Sticky Notes as a Palm ToDo...\n"; $install = "install-todos -p $pilot_port -f \"$write_file\""; system $install; close(FH); unlink($write_file); } # If choice is Palm DOC install to Palm as DOC if ($CHOICE =~ $choice_palm_doc) { $sub_write_file=substr($write_file,0,-4); print FH "$title\n$content\n"; print "Initiating installation of Sticky Notes as a Palm DOC...\n"; $write_doc = "txt2pdbdoc \"$title\" $write_file $sub_write_file.pdb"; system $write_doc; $install = "pilot-xfer -p $pilot_port -i $sub_write_file.pdb"; system $install; close(FH); unlink($write_file); $remove_pdb = "rm $sub_write_file.pdb"; system $remove_pdb; } if ($CHOICE =~ $choice_txt) { print FH "$title\n$content\n\n"; print "Writing out Sticky Note out to $write_file...\n"; close(FH); } } } } MainLoop();