| 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 & update the image database made by the beautiful | ||
| 7 | # 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 Kimdaba help menu | ||
| 12 | # and run it as | ||
| 13 | # ./kim_example_modifyb.pl /tmp/kimdaba-demo-$user | ||
| 14 | # (or whereever the pictures of the demo are stored ) | ||
| 15 | |||
| 16 | # This example shows how to make change in the database | ||
| 17 | # Instead of modifying directly the database (which could easily be dangerous | ||
| 18 | # for your data), you write a kimdaba export file (*.kim) | ||
| 19 | # then you use the import fonction in kimdaba (no dangerous, you are in control) | ||
| 20 | # | ||
| 21 | # A .kim file is a zip archive containning an index.xml file, and | ||
| 22 | # a Thumbnail directory. You just have to create the index.xml file | ||
| 23 | # (say in '/tmp') then you call : | ||
| 24 | # | ||
| 25 | # makeKimFile( "/tmp", "perl_output.kim", @ListOfPictures ); | ||
| 26 | # where /tmp/index.xml is the file created by you | ||
| 27 | # /tmp/perl_output.kim is the resulting kimdaba import ile | ||
| 28 | # @ListOfPictures is a list of urls present in /tmp/index.xml | ||
| 29 | |||
| 30 | |||
| 31 | use strict; | ||
| 32 | use diagnostics; | ||
| 33 | use Image::Kimdaba; | ||
| 34 | use English qw( -no_match_vars ) ; | ||
| 35 | |||
| 36 | my @ListOfPictures; | ||
| 37 | |||
| 38 | my $folder=getRootFolder(); | ||
| 39 | parseDB( "$folder" ); | ||
| 40 | |||
| 41 | print "\n\n== Drag&Drop pictures from Kimdaba ==\n"; | ||
| 42 | @ListOfPictures=letMeDraganddropPictures(); | ||
| 43 | print join("\n", sort(@ListOfPictures)); | ||
| 44 | print "--\n"; | ||
| 45 | |||
| 46 | my $destdir="/tmp"; | ||
| 47 | open( EXPORT, "> ${destdir}/index.xml"); | ||
| 48 | print EXPORT <<FIN | ||
| 49 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 50 | <KimDaBa-export location="external" > | ||
| 51 | FIN | ||
| 52 | ; | ||
| 53 | |||
| 54 | for my $url (@ListOfPictures) | ||
| 55 | { | ||
| 56 | my $description="yeah! I changed the description"; | ||
| 57 | my $md5sum=""; | ||
| 58 | if ( | ||
| 59 | (exists $imageattributes{$url}) | ||
| 60 | && | ||
| 61 | (exists $imageattributes{$url}{'md5sum'}) | ||
| 62 | && | ||
| 63 | (! $imageattributes{$url}{'md5sum'} eq "") | ||
| 64 | ) | ||
| 65 | { | ||
| 66 | $md5sum="md5sum=\"$imageattributes{$url}{'md5sum'}\" "; | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | my $value="Test Add Another Keyword"; | ||
| 71 | print EXPORT <<FIN | ||
| 72 | <image description="$description" $md5sum file="$url" > | ||
| 73 | <options> | ||
| 74 | <option name="Keywords" > | ||
| 75 | <value value="Test Add a keyword" /> | ||
| 76 | <value value="$value" /> | ||
| 77 | </option> | ||
| 78 | </options> | ||
| 79 | </image> | ||
| 80 | FIN | ||
| 81 | ; | ||
| 82 | } | ||
| 83 | |||
| 84 | print EXPORT <<FIN | ||
| 85 | </KimDaBa-export> | ||
| 86 | FIN | ||
| 87 | ; | ||
| 88 | close( EXPORT ); | ||
| 89 | |||
| 90 | |||
| 91 | makeKimFile( $destdir, "perl_export.kim", @ListOfPictures); |