File indexing completed on 2024-04-28 15:40:17
0001 #!/usr/bin/perl 0002 # SPDX-FileCopyrightText: 2012-2016 Miika Turkia <miika.turkia@gmail.com> 0003 # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 # 0005 # Try to locate RAW files to open them in external editor from 0006 # GUI application like KPhotoAlbum 0007 0008 my @params; 0009 0010 # Raw extensions you use. If you use Ufraw you might want to add ufraw 0011 # as the first extension in the list 0012 # Using same file format list as KPhotoAlbum from 0013 # http://www.cybercom.net/~dcoffin/dcraw/rawphoto.c 0014 my @rawExt = ( 0015 "3fr","arw","bay","bmq","cine","cr2","crw","cs1","dc2","dcr","dng","erf","fff","hdr","ia","k25","kc2","kdc","mdc","mef","mos","mrw","nef","nrw","orf","pef","pxn","qtk","raf","raw","rdc","rw2","sr2","srf","sti","tif","x3f","jpg" 0016 ); 0017 0018 # The application you use to develop the RAW files 0019 my @raw_converters = ( "/usr/bin/AfterShot2X64", "/usr/bin/AfterShot2", 0020 "/usr/bin/AfterShotPro", "/usr/bin/bibble5", 0021 "/usr/bin/ufraw", "/usr/bin/rt", "/usr/bin/darktable" ); 0022 my @ASP_work = ( "/usr/bin/AfterShot3X64" ); 0023 my $extApp = ""; 0024 my $workApp = ""; 0025 0026 foreach my $app (@ASP_work) { 0027 if ( -e $app ) { 0028 $workApp = $app; 0029 last; 0030 } 0031 } 0032 0033 foreach my $app (@raw_converters) { 0034 if ( -e $app ) { 0035 $extApp = $app; 0036 last; 0037 } 0038 } 0039 0040 # If you want to use specific converter, just assign it below 0041 #$extApp = "/usr/bin/ufraw"; 0042 0043 if ($extApp =~ m/^$/ && $workApp =~ m/^$/) { 0044 my $errMsg = "Could not find RAW developer. If you have one, " . 0045 "script open-raw.pl must be updated."; 0046 exec("notify-send \"$errMsg\""); 0047 } 0048 0049 # A default regular expression for detecting the original RAW file 0050 # We attempt to update this with the one used by KPhotoAlbum later 0051 my $regexp = "(_(v){0,1}([0-9]){1,2}){0,1}\\.(jpg|JPG|tif|TIF|png|PNG)"; 0052 0053 # Attempt to read the KPA's regular expression from configuration file 0054 sub read_config { 0055 open CONFIG, "<", $ENV{"HOME"} . "/.kde/share/config/kphotoalbumrc" or return; 0056 while (<CONFIG>) { 0057 /modifiedFileComponent/ && do { 0058 $regexp = $_; 0059 $regexp =~ s/modifiedFileComponent=//; 0060 $regexp =~ s/\\\\/\\/g; 0061 chomp $regexp; 0062 }; 0063 } 0064 } 0065 0066 sub uniq { 0067 return keys %{{ map { $_ => 1 } @_ }}; 0068 } 0069 0070 read_config(); 0071 0072 # Process the parameters and search for "original" files 0073 foreach my $argnum (0..$#ARGV) { 0074 my $found = 0; 0075 my $file = "$ARGV[$argnum]"; 0076 0077 $file =~ s/$regexp//; 0078 0079 foreach my $ext (@rawExt) { 0080 if (-e "$file.$ext") { 0081 push @params, "$file.$ext"; 0082 $found = 1; 0083 last; 0084 } else { 0085 $ext = uc($ext); 0086 if (-e "$file.$ext") { 0087 push @params, "$file.$ext"; 0088 $found = 1; 0089 last; 0090 } 0091 } 0092 } 0093 push @params, "$ARGV[$argnum]" if not $found; 0094 } 0095 0096 my @uniqParams = uniq(@params); 0097 0098 if ($workApp =~ m/^.+$/) { 0099 my $workFile = "/tmp/kpa-asp-" . $$ . "_" . int(rand(100000)) . ".work"; 0100 0101 srand; 0102 open WORK, ">", $workFile; 0103 0104 foreach my $file (@uniqParams) { 0105 print WORK $file . "\n"; 0106 } 0107 0108 close WORK; 0109 exec "$workApp $workFile"; 0110 exit; 0111 } 0112 0113 exec "$extApp @uniqParams";