| 1 | #!/usr/local/bin/perl -w | ||
| 2 | # Copyright 2005 Jean-Michel Fayard jmfayard_at_gmail.com | ||
| 3 | # Put into the public domain. | ||
| 4 | # | ||
| 5 | # Example on how to use the Image::Kimdaba.pm module | ||
| 6 | # to parse the image database made by the beautiful | ||
| 7 | # Image::Kimdaba available on http://ktown.kde.org/kimdaba | ||
| 8 | # Copy paste from this to start your own script. | ||
| 9 | # | ||
| 10 | # To use it, run $ kimdaba -demo, | ||
| 11 | # or launch the demo from the Image::Kimdaba help menu | ||
| 12 | # and run it as | ||
| 13 | # ./kim_example.pl /tmp/kimdaba-demo-$user | ||
| 14 | # (or whereever the pictures of the demo are stored ) | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | use diagnostics; | ||
| 18 | use Image::Kimdaba; | ||
| 19 | use English qw( -no_match_vars ) ; | ||
| 20 | |||
| 21 | my @ListOfPictures; | ||
| 22 | |||
| 23 | my $folder=getRootFolder(); | ||
| 24 | parseDB( "$folder" ); | ||
| 25 | # parse the xml file and create three hashes: | ||
| 26 | # %imageattributes : HASH OF (url of the picture, REF. HASH OF (attribute, value) ) | ||
| 27 | # %imageoptions : HASH of (url, REF. HASH OF (optoin, REF. LIST OF value) ) | ||
| 28 | # %alloptions : HASH of (option, REF. LIST of values) | ||
| 29 | # %kimdabaconfig : HASH of (attributes, values) | ||
| 30 | # [attributes of the config element in index.xml] | ||
| 31 | # %membergroups : HASH : (Locations => REF (HASH : USA => [ Chicago, Los Angeles ] ) ) | ||
| 32 | # | ||
| 33 | # note : the reading of man:/perllol is highly recommended | ||
| 34 | |||
| 35 | |||
| 36 | print "Your actual Kimdaba settings are :\n"; | ||
| 37 | while( my ($attr, $value) = each %kimdabaconfig) | ||
| 38 | { | ||
| 39 | print "\t$attr => $value\n"; | ||
| 40 | } | ||
| 41 | print "\n"; | ||
| 42 | |||
| 43 | my $nb1= scalar keys %imageattributes; | ||
| 44 | my $nb2= scalar keys %imageoptions; | ||
| 45 | print "Following options were present in your $nb1 pictures :\n"; | ||
| 46 | while( my ($option,$r_values) = each %alloptions ) | ||
| 47 | { | ||
| 48 | my $nb = scalar @$r_values; | ||
| 49 | print "\t$nb $option\n"; | ||
| 50 | } | ||
| 51 | print "\n"; | ||
| 52 | |||
| 53 | local $, = "\n" ; # print bla,bla prints "bla\nbla" | ||
| 54 | |||
| 55 | print "\n\n== NO Keywords (ten first) ==\n"; | ||
| 56 | @ListOfPictures=matchAnyOption( "Keywords" => [] ); | ||
| 57 | print sort(@ListOfPictures[0..9]); | ||
| 58 | |||
| 59 | print "\n\n== Holiday ==\n"; | ||
| 60 | @ListOfPictures=matchAnyOption( "Keywords" => [ "holiday" ] ); | ||
| 61 | print sort(@ListOfPictures); | ||
| 62 | |||
| 63 | print "\n\n== ANNE HELENE ==\n"; | ||
| 64 | @ListOfPictures=matchAnyOption( "Persons" => [ "Anne Helene" ] ); | ||
| 65 | print sort(@ListOfPictures); | ||
| 66 | |||
| 67 | print "\n\n== ANY OF (JESPER, ANNE HELEN) ==\n"; | ||
| 68 | @ListOfPictures=matchAnyOption( "Persons" => [ "Jesper" , "Anne Helene" ] ); | ||
| 69 | print sort(@ListOfPictures); | ||
| 70 | |||
| 71 | print "\n\n== ALL OF (JESPER, ANNE HELEN) ==\n"; | ||
| 72 | @ListOfPictures=matchAllOptions( "Persons" => [ "Jesper" , "Anne Helene" ] ); | ||
| 73 | print sort(@ListOfPictures); | ||
| 74 | |||
| 75 | print "\n\n== PERSONS=Jesper, Locations=Mallorca ==\n"; | ||
| 76 | @ListOfPictures=matchAllOptions( | ||
| 77 | "Persons" => [ "Jesper" ], | ||
| 78 | "Locations" => [ "Mallorca" ] | ||
| 79 | ); | ||
| 80 | print sort(@ListOfPictures); | ||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | $, = "" ; # print bla,bla prints "blabla" | ||
| 85 | |||
| 86 | print "\n\nMember-groups\n"; | ||
| 87 | my %loop; | ||
| 88 | &print_membergroup; # Note this is not part of the API, | ||
| 89 | # it's a sub defined at the bottom that show how to use the %membergroups hash | ||
| 90 | |||
| 91 | print "\n\n==Print all infos known about specific pictures\n"; | ||
| 92 | print "\n\n== Drag&Drop pictures from Kimdaba ==\n"; | ||
| 93 | @ListOfPictures=letMeDraganddropPictures(); | ||
| 94 | printImage( $_ ) foreach @ListOfPictures; | ||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | |||
| 99 | |||
| 100 | # For the fun, print recursively the member-groups, | ||
| 101 | # But remember to avoid loops ;-) | ||
| 102 | sub print_membergroup | ||
| 103 | { | ||
| 104 | while( my ($category, $r_hash) = each %membergroups ) | ||
| 105 | { | ||
| 106 | print "|-- $category\n"; | ||
| 107 | while( my ($groupname, $r_members) = each %$r_hash ) | ||
| 108 | { | ||
| 109 | %loop = ( $groupname => 1); | ||
| 110 | my $prefix="| "; | ||
| 111 | continue_print_membergroup($prefix, $category, $groupname, $r_members); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | print "\n"; | ||
| 115 | |||
| 116 | } | ||
| 117 | |||
| 118 | sub continue_print_membergroup | ||
| 119 | { | ||
| 120 | my ($prefix, $category,$groupname,$r_members) = @_; | ||
| 121 | print "$prefix|-- $groupname\n"; | ||
| 122 | for my $member (@$r_members) | ||
| 123 | { | ||
| 124 | print "$prefix| |-- $member\n"; | ||
| 125 | if ( | ||
| 126 | exists( $membergroups{$category}{$member} ) | ||
| 127 | ) | ||
| 128 | { | ||
| 129 | if ( exists( $loop{$member} )) | ||
| 130 | { | ||
| 131 | print "$prefix| | |-- <LOOP AVOIDED>\n"; | ||
| 132 | } else { | ||
| 133 | $loop{$member} = 1; | ||
| 134 | continue_print_membergroup( "| ".$prefix, $category, $member, $membergroups{$category}{$member} ); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | |||
| 141 | |||
| 142 |