2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer
::windows
::shortcut
;
21 use installer
::exiter
;
23 use installer
::globals
;
24 use installer
::windows
::idtglobal
;
26 ##############################################################
27 # Returning identifier for shortcut table.
28 ##############################################################
30 sub get_shortcut_identifier
34 my $identifier = $shortcut->{'gid'};
39 ##############################################################
40 # Returning directory for shortcut table.
41 ##############################################################
43 sub get_shortcut_directory
45 my ($shortcut, $dirref) = @_;
47 # For shortcuts it is easy to convert the gid_Dir_Abc into the unique name in
48 # the directory table, for instance help_en_simpressidx.
49 # For files (components) this is not so easy, because files can be included
50 # in zip files with subdirectories that are not defined in scp.
53 my $shortcutdirectory = $shortcut->{'Dir'};
57 for ( my $i = 0; $i <= $#{$dirref}; $i++ )
59 $onedir = ${$dirref}[$i];
60 my $directorygid = $onedir->{'Dir'};
62 if ( $directorygid eq $shortcutdirectory )
71 installer
::exiter
::exit_program
("ERROR: Did not find DirectoryID $shortcutdirectory in directory collection for shortcut", "get_shortcut_directory");
74 $directory = $onedir->{'uniquename'};
76 if ($directory eq "") { $directory = "INSTALLLOCATION"; } # Shortcuts in the root directory
81 ##############################################################
82 # Returning name for shortcut table.
83 ##############################################################
87 my ($shortcut, $shortnamesref, $onelanguage) = @_;
91 my $name = $shortcut->{'Name'};
93 my $shortstring = installer
::windows
::idtglobal
::make_eight_three_conform
($name, "shortcut", $shortnamesref);
94 $shortstring =~ s/\s/\_/g; # replacing white spaces with underline
96 if ( $shortstring eq $name ) { $returnstring = $name; } # nothing changed
97 else {$returnstring = $shortstring . "\|" . $name; }
102 ##############################################################
103 # Returning component for shortcut table.
104 ##############################################################
106 sub get_shortcut_component
108 my ($shortcut, $filesref) = @_;
113 my $shortcut_fileid = $shortcut->{'FileID'};
115 my $absolute_filename = 0;
116 if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
117 if ( $styles =~ /\bABSOLUTE_FILENAME\b/ ) { $absolute_filename = 1; } # FileID contains an absolute filename
118 if ( $styles =~ /\bUSE_HELPER_FILENAME\b/ ) { $absolute_filename = 1; } # ComponentIDFile contains id of a helper file
120 # if the FileID contains an absolute filename, therefore the entry for "ComponentIDFile" has to be used.
121 if ( $absolute_filename ) { $shortcut_fileid = $shortcut->{'ComponentIDFile'}; }
123 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
125 $onefile = ${$filesref}[$i];
126 my $filegid = $onefile->{'gid'};
128 if ( $filegid eq $shortcut_fileid )
137 installer
::exiter
::exit_program
("ERROR: Did not find FileID $shortcut_fileid in file collection for shortcut", "get_shortcut_component");
140 $component = $onefile->{'componentname'};
142 # finally saving the componentname in the folderitem collector
144 $shortcut->{'component'} = $component;
149 ##############################################################
150 # Returning target for shortcut table.
151 ##############################################################
153 sub get_shortcut_target
155 my ($shortcut, $filesref) = @_;
159 my $shortcut_fileid = $shortcut->{'FileID'};
162 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
164 $onefile = ${$filesref}[$i];
165 my $filegid = $onefile->{'gid'};
167 if ( $filegid eq $shortcut_fileid )
176 installer
::exiter
::exit_program
("ERROR: Did not find FileID $shortcut_fileid in file collection for shortcut", "get_shortcut_target");
179 if ( $onefile->{'Name'} )
181 $target = $onefile->{'Name'};
184 $target = "\[\#" . $target . "\]"; # format for Non-Advertised shortcuts
189 ##############################################################
190 # Returning arguments for shortcut table.
191 ##############################################################
193 sub get_shortcut_arguments
200 ##############################################################
201 # Returning the localized description for shortcut table.
202 ##############################################################
204 sub get_shortcut_description
206 my ($shortcut, $onelanguage) = @_;
208 my $description = "";
209 if ( $shortcut->{'Tooltip'} ) { $description = $shortcut->{'Tooltip'}; }
210 $description =~ s/\\\"/\"/g; # no more masquerading of '"'
215 ##############################################################
216 # Returning hotkey for shortcut table.
217 ##############################################################
219 sub get_shortcut_hotkey
226 ##############################################################
227 # Returning icon for shortcut table.
228 ##############################################################
230 sub get_shortcut_icon
237 ##############################################################
238 # Returning iconindex for shortcut table.
239 ##############################################################
241 sub get_shortcut_iconindex
248 ##############################################################
249 # Returning show command for shortcut table.
250 ##############################################################
252 sub get_shortcut_showcmd
259 ##############################################################
260 # Returning working directory for shortcut table.
261 ##############################################################
263 sub get_shortcut_wkdir
270 ####################################################################
271 # Returning working directory for shortcut table for FolderItems.
272 ####################################################################
274 sub get_folderitem_wkdir
276 my ($onelink, $dirref) = @_;
278 # For shortcuts it is easy to convert the gid_Dir_Abc into the unique name in
279 # the directory table, for instance help_en_simpressidx.
282 my $workingdirectory = "";
283 if ( $onelink->{'WkDir'} ) { $workingdirectory = $onelink->{'WkDir'}; }
286 if ( $workingdirectory )
290 for ( my $i = 0; $i <= $#{$dirref}; $i++ )
292 $onedir = ${$dirref}[$i];
293 my $directorygid = $onedir->{'Dir'};
295 if ( $directorygid eq $workingdirectory )
304 installer
::exiter
::exit_program
("ERROR: Did not find DirectoryID $workingdirectory in directory collection for FolderItem", "get_folderitem_wkdir");
307 $directory = $onedir->{'uniquename'};
309 if ($directory eq "") { $directory = "INSTALLLOCATION"; }
315 ###################################################################
316 # Returning the directory for a folderitem for shortcut table.
317 ###################################################################
319 sub get_folderitem_directory
323 my $directory = "$installer::globals::officemenufolder"; # default
325 # The default is not correct for the
326 # PREDEFINED folders, like PREDEFINED_AUTOSTART
328 if ( $shortcut->{'FolderID'} eq "PREDEFINED_AUTOSTART" )
330 $directory = $installer::globals
::startupfolder
;
333 if ( $shortcut->{'FolderID'} eq "PREDEFINED_DESKTOP" )
335 $directory = $installer::globals
::desktopfolder
;
336 $installer::globals
::desktoplinkexists
= 1;
339 if ( $shortcut->{'FolderID'} eq "PREDEFINED_STARTMENU" )
341 $directory = $installer::globals
::programmenufolder
;
344 # saving the directory in the folderitems collector
346 $shortcut->{'directory'} = $directory;
351 ########################################################################
352 # Returning the target (feature) for a folderitem for shortcut table.
353 # For non-advertised shortcuts this is a formatted string.
354 ########################################################################
356 sub get_folderitem_target
358 my ($shortcut, $filesref) = @_;
363 my $shortcut_fileid = $shortcut->{'FileID'};
366 my $nonadvertised = 0;
367 my $absolute_filename = 0;
368 if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
369 if ( $styles =~ /\bNON_ADVERTISED\b/ ) { $nonadvertised = 1; } # this is a non-advertised shortcut
370 if ( $styles =~ /\bABSOLUTE_FILENAME\b/ ) { $absolute_filename = 1; } # FileID contains an absolute filename
372 # if the FileID contains an absolute filename this can simply be returned as target for the shortcut table.
373 if ( $absolute_filename )
375 $shortcut->{'target'} = $shortcut_fileid;
376 return $shortcut_fileid;
379 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
381 $onefile = ${$filesref}[$i];
382 my $filegid = $onefile->{'gid'};
384 if ( $filegid eq $shortcut_fileid )
393 installer
::exiter
::exit_program
("ERROR: Did not find FileID $shortcut_fileid in file collection for folderitem", "get_folderitem_target");
396 # Non advertised shortcuts do not return the feature, but the path to the file
397 if ( $nonadvertised )
399 $target = "\[" . $onefile->{'uniquedirname'} . "\]" . "\\" . $onefile->{'Name'};
400 $shortcut->{'target'} = $target;
404 # the rest only for advertised shortcuts, which contain the feature in the shortcut table.
406 if ( $onefile->{'modules'} ) { $target = $onefile->{'modules'}; }
408 # If modules contains a list of modules, only taking the first one.
409 # But this should never be needed
411 if ( $target =~ /^\s*(.*?)\,/ ) { $target = $1; }
413 # Attention: Maximum feature length is 38!
414 installer
::windows
::idtglobal
::shorten_feature_gid
(\
$target);
416 # and finally saving the target in the folderitems collector
418 $shortcut->{'target'} = $target;
423 ########################################################################
424 # Returning the arguments for a folderitem for shortcut table.
425 ########################################################################
427 sub get_folderitem_arguments
433 if ( $shortcut->{'Parameter'} ) { $parameter = $shortcut->{'Parameter'}; }
438 ########################################################################
439 # Returning the icon for a folderitem for shortcut table.
440 # The returned value has to be defined in the icon table.
441 ########################################################################
443 sub get_folderitem_icon
445 my ($shortcut, $filesref, $iconfilecollector) = @_;
448 if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
449 if ( $styles =~ /\bNON_ADVERTISED\b/ ) { return ""; } # no icon for non-advertised shortcuts
451 my $iconfilegid = "";
453 if ( $shortcut->{'IconFile'} ) { $iconfilegid = $shortcut->{'IconFile'}; }
454 else { $iconfilegid = $shortcut->{'FileID'}; }
459 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
461 $onefile = ${$filesref}[$i];
462 my $filegid = $onefile->{'gid'};
464 if ( $filegid eq $iconfilegid )
473 installer
::exiter
::exit_program
("ERROR: Did not find FileID $iconfilegid in file collection", "get_folderitem_icon");
476 $iconfile = $onefile->{'Name'};
478 # collecting all icon files to copy them into the icon directory
480 my $sourcepath = $onefile->{'sourcepath'};
482 if (! grep {$_ eq $sourcepath} @
{$iconfilecollector})
484 push(@
{$iconfilecollector}, $sourcepath);
490 ########################################################################
491 # Returning the iconindex for a folderitem for shortcut table.
492 ########################################################################
494 sub get_folderitem_iconindex
499 if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
500 if ( $styles =~ /\bNON_ADVERTISED\b/ ) { return ""; } # no iconindex for non-advertised shortcuts
504 if ( $shortcut->{'IconID'} ) { $iconid = $shortcut->{'IconID'}; }
509 ########################################################################
510 # Returning the show command for a folderitem for shortcut table.
511 ########################################################################
513 sub get_folderitem_showcmd
520 ###########################################################################################################
521 # Creating the file Shortcut.idt dynamically
523 # Shortcut Directory_ Name Component_ Target Arguments Description Hotkey Icon_ IconIndex ShowCmd WkDir
524 ###########################################################################################################
526 sub create_shortcut_table
528 my ($filesref, $linksref, $folderref, $folderitemsref, $dirref, $basedir, $languagesarrayref, $includepatharrayref, $iconfilecollector) = @_;
530 for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
532 my $onelanguage = ${$languagesarrayref}[$m];
534 my @shortcuttable = ();
536 my @shortnames = (); # to collect all short names
538 installer
::windows
::idtglobal
::write_idt_header
(\
@shortcuttable, "shortcut");
540 # First the links, defined in scp as ShortCut
542 for ( my $i = 0; $i <= $#{$linksref}; $i++ )
544 my $onelink = ${$linksref}[$i];
546 # Controlling the language!
547 # Only language independent folderitems or folderitems with the correct language
548 # will be included into the table
550 if (! (!(( $onelink->{'ismultilingual'} )) || ( $onelink->{'specificlanguage'} eq $onelanguage )) ) { next; }
554 $shortcut{'Shortcut'} = get_shortcut_identifier
($onelink);
555 $shortcut{'Directory_'} = get_shortcut_directory
($onelink, $dirref);
556 $shortcut{'Name'} = get_shortcut_name
($onelink, \
@shortnames, $onelanguage); # localized name
557 $shortcut{'Component_'} = get_shortcut_component
($onelink, $filesref);
558 $shortcut{'Target'} = get_shortcut_target
($onelink, $filesref);
559 $shortcut{'Arguments'} = get_shortcut_arguments
($onelink);
560 $shortcut{'Description'} = get_shortcut_description
($onelink, $onelanguage); # localized description
561 $shortcut{'Hotkey'} = get_shortcut_hotkey
($onelink);
562 $shortcut{'Icon_'} = get_shortcut_icon
($onelink);
563 $shortcut{'IconIndex'} = get_shortcut_iconindex
($onelink);
564 $shortcut{'ShowCmd'} = get_shortcut_showcmd
($onelink);
565 $shortcut{'WkDir'} = get_shortcut_wkdir
($onelink);
567 my $oneline = $shortcut{'Shortcut'} . "\t" . $shortcut{'Directory_'} . "\t" . $shortcut{'Name'} . "\t"
568 . $shortcut{'Component_'} . "\t" . $shortcut{'Target'} . "\t" . $shortcut{'Arguments'} . "\t"
569 . $shortcut{'Description'} . "\t" . $shortcut{'Hotkey'} . "\t" . $shortcut{'Icon_'} . "\t"
570 . $shortcut{'IconIndex'} . "\t" . $shortcut{'ShowCmd'} . "\t" . $shortcut{'WkDir'} . "\n";
572 push(@shortcuttable, $oneline);
575 # Second the entries into the start menu, defined in scp as Folder and Folderitem
576 # These shortcuts will fill the icons table.
578 for ( my $i = 0; $i <= $#{$folderref}; $i++ )
580 my $foldergid = ${$folderref}[$i]->{'gid'};
582 # iterating over all folderitems for this folder
584 for ( my $j = 0; $j <= $#{$folderitemsref}; $j++ )
586 my $onelink = ${$folderitemsref}[$j];
588 # Controlling the language!
589 # Only language independent folderitems or folderitems with the correct language
590 # will be included into the table
592 if (! (!(( $onelink->{'ismultilingual'} )) || ( $onelink->{'specificlanguage'} eq $onelanguage )) ) { next; }
594 # controlling the folder
598 if ( $onelink->{'used'} ) { $localused = $onelink->{'used'}; }
600 if (!($localused == 1)) { $onelink->{'used'} = "0"; } # no resetting
602 if (!( $onelink->{'FolderID'} eq $foldergid )) { next; }
604 $onelink->{'used'} = "1";
608 $shortcut{'Shortcut'} = get_shortcut_identifier
($onelink);
609 $shortcut{'Directory_'} = get_folderitem_directory
($onelink);
610 $shortcut{'Name'} = get_shortcut_name
($onelink, \
@shortnames, $onelanguage); # localized name
611 $shortcut{'Component_'} = get_shortcut_component
($onelink, $filesref);
612 $shortcut{'Target'} = get_folderitem_target
($onelink, $filesref);
613 $shortcut{'Arguments'} = get_folderitem_arguments
($onelink);
614 $shortcut{'Description'} = get_shortcut_description
($onelink, $onelanguage); # localized description
615 $shortcut{'Hotkey'} = get_shortcut_hotkey
($onelink);
616 $shortcut{'Icon_'} = get_folderitem_icon
($onelink, $filesref, $iconfilecollector);
617 $shortcut{'IconIndex'} = get_folderitem_iconindex
($onelink);
618 $shortcut{'ShowCmd'} = get_folderitem_showcmd
($onelink);
619 $shortcut{'WkDir'} = get_folderitem_wkdir
($onelink, $dirref);
621 my $oneline = $shortcut{'Shortcut'} . "\t" . $shortcut{'Directory_'} . "\t" . $shortcut{'Name'} . "\t"
622 . $shortcut{'Component_'} . "\t" . $shortcut{'Target'} . "\t" . $shortcut{'Arguments'} . "\t"
623 . $shortcut{'Description'} . "\t" . $shortcut{'Hotkey'} . "\t" . $shortcut{'Icon_'} . "\t"
624 . $shortcut{'IconIndex'} . "\t" . $shortcut{'ShowCmd'} . "\t" . $shortcut{'WkDir'} . "\n";
626 push(@shortcuttable, $oneline);
630 # The soffice.ico has to be included into the icon table
631 # as icon for the ARP applet
634 my $sofficefile = "soffice.ico";
636 my $sourcepathref = $ENV{'SRCDIR'} . "/sysui/desktop/icons/" . $sofficefile;
638 if (! -f
$sourcepathref) { installer
::exiter
::exit_program
("ERROR: Could not find $sofficefile ($sourcepathref) as icon!", "create_shortcut_table"); }
640 if (! grep {$_ eq $sourcepathref} @
{$iconfilecollector})
642 unshift(@
{$iconfilecollector}, $sourcepathref);
643 $installer::globals
::sofficeiconadded
= 1;
646 my $localinfoline = "Added icon file $sourcepathref for language pack into icon file collector.\n";
647 push(@installer::globals
::logfileinfo
, $localinfoline);
651 my $shortcuttablename = $basedir . $installer::globals
::separator
. "Shortcut.idt" . "." . $onelanguage;
652 installer
::files
::save_file
($shortcuttablename ,\
@shortcuttable);
653 my $infoline = "Created idt file: $shortcuttablename\n";
654 push(@installer::globals
::logfileinfo
, $infoline);