diff --git a/perl/Gnome-Tomboy/lib/Tomboy.pm b/perl/Gnome-Tomboy/lib/Tomboy.pm index 443103d5ec24369446bd39adffd6bd47f9ce7bb0..6b1aec4ca7a7b468e78199ca1d15d93a5ccbef9d 100644 --- a/perl/Gnome-Tomboy/lib/Tomboy.pm +++ b/perl/Gnome-Tomboy/lib/Tomboy.pm @@ -11,8 +11,8 @@ utility functions to work with Tomboy use Tomboy; - $text2= $Tomboy::link($text); - $text2= $Tomboy::list_item($text); + $text2= Tomboy::link($text); + $text2= Tomboy::list_item($text); =head1 INTERNAL FUNCTIONS @@ -23,6 +23,7 @@ package Tomboy; use strict; use UUID; +use POSIX; sub link { @@ -46,8 +47,9 @@ sub ts_ISO { my $time= shift || time (); my @ts= localtime ($time); - sprintf ("%04d-%02d-%02dT%02d:%02d:%02d.0000000+01:00", - $ts[5]+1900, $ts[4]+1, $ts[3], $ts[2], $ts[1], $ts[0]); +# sprintf ("%04d-%02d-%02dT%02d:%02d:%02d.0000000+01:00", +# $ts[5]+1900, $ts[4]+1, $ts[3], $ts[2], $ts[1], $ts[0]); + strftime ('%FT%T.000000%z', @ts); } sub get_uuid @@ -58,5 +60,21 @@ sub get_uuid $uuid_str; } +sub start_tb +{ + my $what= shift; + my $par= shift; + + if ($what eq 'uuid') + { + my @cmd= ('tomboy', '--open-note', 'note://tomboy/'. $par); + print ">>> ", join (' ', @cmd), "\n"; + + my $pid= fork(); + if ($pid == 0) { exec @cmd; } + print "started pid=[$pid]\n"; + } +} + 1; diff --git a/perl/Gnome-Tomboy/s2.pl b/perl/Gnome-Tomboy/s2.pl index 8ffac7a358e1d0d6fd43fe4cd1f6e0f66d12ebac..e1ebf42cf1e2282c8ed8c80b5a81acca39461eff 100755 --- a/perl/Gnome-Tomboy/s2.pl +++ b/perl/Gnome-Tomboy/s2.pl @@ -10,6 +10,25 @@ Script to play with Tomboy::Directory for testing. Generates a CSV file as TOC (table of contents) which might be useful. +=head1 OPTIONS + + -f ... find-mode + -s ... scan-mode (default) + -d <dir> ... directory where notes are stored; (default: ~/.local/share/tomboy) + -t <toc> ... Table-Of-Contents (TOC) of all notes; (default: Tomboy-TOC.csv) + -e ... start Tomboy; useful with in find-mode + +=head1 MODES + +=head2 scan-mode + +Scan Tomboy notes directory and save a table of contents in a CSV file (fields are TAB separated). + +=head2 find-mode + +Load table of contents from CSV file and find notes which match given find patterns. +If -e is also specified, tell Tomboy to open these notes. + =cut use strict; @@ -22,9 +41,10 @@ $Data::Dumper::Indent= 1; # use Tomboy::Note::Simple; use Tomboy::Directory; +use Tomboy::TOC; -my $toc_file= 'Tomboy-TOC.csv'; -my $note_dir= '~/Tomboy'; +my $toc_file; +my $note_dir= $ENV{'HOME'} . '/.local/share/tomboy'; my $mode= 'scan'; my $start_tb= 0; @@ -35,7 +55,9 @@ while (my $arg= shift (@ARGV)) if ($arg =~ /^-/) { if ($arg eq '-f') { $mode= 'find'; } + elsif ($arg eq '-s') { $mode= 'scan'; } elsif ($arg eq '-d') { $note_dir= shift (@ARGV); } + elsif ($arg eq '-t') { $toc_file= shift (@ARGV); } elsif ($arg eq '-e') { $start_tb= 1; } else { usage(); } } @@ -45,19 +67,20 @@ while (my $arg= shift (@ARGV)) } } -my $bli= new bli('note_dir' => $note_dir, 'toc_file' => $toc_file); -print "bli: ", Dumper ($bli); +$toc_file= join ('/', $note_dir, 'Tomboy-TOC.csv') unless (defined ($toc_file)); +my $toc= new Tomboy::TOC('note_dir' => $note_dir, 'toc_file' => $toc_file); +print "toc: ", Dumper ($toc); if ($mode eq 'scan') { - $bli->scan_dir(); + $toc->scan_dir(); } elsif ($mode eq 'find') { my %uuid; foreach my $pattern (@PAR) { - my @res= $bli->find ($pattern); + my @res= $toc->find ($pattern); foreach my $res (@res) { $uuid{$res->{'uuid'}}= $res; } # TODO: count hits } @@ -65,7 +88,7 @@ elsif ($mode eq 'find') { if ($start_tb) { - start_tb ('uuid', $uuid); + Tomboy::start_tb ('uuid', $uuid); } else { @@ -74,6 +97,14 @@ elsif ($mode eq 'find') } } +exit (0); + +sub usage +{ + system ('perldoc', $0); + exit; +} + =begin comment hmm... starting Tomboy does not work as expected. When tomboy is @@ -84,122 +115,6 @@ Probably it would make sense to do something with D-Bus here... =end comment =cut -sub start_tb -{ - my $what= shift; - my $par= shift; - - if ($what eq 'uuid') - { - my @cmd= ('tomboy', '--open-note', 'note://tomboy/'. $par); - print ">>> ", join (' ', @cmd), "\n"; - - my $pid= fork(); - if ($pid == 0) { exec @cmd; } - print "started pid=[$pid]\n"; - } -} - -exit (0); - -package bli; - -sub new -{ - my $class= shift; - - my $self= {}; - bless $self, $class; - $self->set (@_); - - $self; -} - -sub set -{ - my $self= shift; - my %par= @_; - - foreach my $par (keys %par) { $self->{$par}= $par{$par}; } -} - -sub find -{ - my $self= shift; - my $pattern= shift; - -print "find: pattern=[$pattern]\n"; - my ($mode, $toc, $rows)= $self->load_toc(); - my @res; - foreach my $row (@$rows) - { - next unless ($row->{'title'} =~ m#$pattern#i); - # print "row: ", main::Dumper ($row); - push (@res, $row); - } - @res; -} - -sub scan_dir -{ - my $self= shift; - -print main::Dumper ($self); - my ($note_dir, $toc_file)= map { $self->{$_} } qw(note_dir toc_file); - - $note_dir=~ s#/+$##; - my $tb_d= new Tomboy::Directory (); - # print "tb_d: ", Dumper ($tb_d); - print "scanning [$note_dir]\n"; - - my ($mode, $toc, $rows)= $self->load_toc(); - - my $toc_data= $tb_d->scan_dir ($note_dir, $rows, $mode); - # TODO: if verbose or so print "toc_data: ", Dumper ($toc_data); - - $toc->{'data'}= $toc_data; - # TODO: optionally sort the returned values - $toc->sort ('uuid'); - # print "toc: ", Dumper ($toc); - $toc->save_csv_file ('filename' => $toc_file, 'separator' => "\t", 'UTF8' => 1); -} - -sub load_toc -{ - my $self= shift; - - my $mode= 0; - my $toc; - -print "load_toc\n"; - return (1, $toc, $toc->{'data'}) if (defined ($toc= $self->{'_toc'})); - - my ($toc_file)= map { $self->{$_} } qw(toc_file); -print "load_toc: toc_file=[$toc_file]\n"; - - my $toc= new Util::Simple_CSV ('UTF8' => 1, 'no_array' => 1, 'separator' => "\t", 'UTF8' => 1); - my $rows= []; - if (-f $toc_file) - { - print "loading $toc_file\n"; - $toc->load_csv_file ($toc_file); - - $mode= 1; - $rows= $toc->{'data'}; - print "preparing quick scan, loaded [$toc_file]\n"; - # print "toc: ", Dumper ($toc); - # print "rows: ", Dumper ($rows); - # exit; - } - else - { - $toc->define_columns (Tomboy::Directory::TB_attrs()); - } - $self->{'_toc'}= $toc; - - ($mode, $toc, $rows); -} - __END__ =head1 TODO @@ -213,8 +128,9 @@ __END__ =head2 Directories used by Tomboy on Ubuntu * ~/.cache/tomboy/ ... empty - * ~/.gconf/tomboy/ - %gconf.xml + * ~/.gconf/apps/tomboy/ + %gconf.xml + global_keybindings/%gconf.xml * ~/.config/tomboy/ ... various stuff