#!/usr/bin/env perl # easytag.wrapper - Launcher for "easytag" main program # License: Creative Commons Attribution-NonCommercial-ShareAlike 2.5 # Revision: 071016 # Note: The license indicated above applies to this file. It doesn't # apply to the official EasyTAG package, or to any file derived from # that package. #--------------------------------------------------------------------- # license information #--------------------------------------------------------------------- # This section may not be modified except as approved by the author or # licensor, or to make non-content changes such as adjustments to par- # agraph formatting or white space. # This version of this software is distributed under the following # license: # # Creative Commons Attribution-NonCommercial-ShareAlike 2.5 # You may use, modify, and redistribute this software without fees or # royalties, but only under the terms and conditions set forth by the # license. In particular, copies and derived works cannot be used for # commercial purposes. Additionally, the license propagates to copies # and derived works. Furthermore, you must provide attribution "in the # manner specified by the author or licensor". The latter point is # discussed below. # The author [and licensor] hereby specifies that attribution must be # handled in the following manner: a. If the software is interactive, # any About or Credits dialog boxes, windows, or output text provided # by the original version must be preserved and readily accessible to # the end user at runtime. b. If the software is non-interactive, or # if it does not provide About or Credits dialog boxes, windows, or # output text, the operating system and/or desktop environment used # must provide attribution that is visible and/or readily accessible # to the end user at runtime. # The following techniques do not meet the attribution requirements: # Attribution through text files, attribution through printed docu- # mentation, verbal attribution, or postings on external web sites # [i.e., web sites that are not an intrinsic local component of the # operating system or desktop environment used]. These examples are # provided for illustrative purposes only. # It should be noted that trademarks are an additional issue. If this # software uses any trademarks, trademark-related restrictions may # apply. # This is not a complete explanation of the terms and conditions in- # volved. For more information, see the Creative Commons Attribution- # NonCommercial-ShareAlike 2.5 license. #--------------------------------------------------------------------- # important note #--------------------------------------------------------------------- # This software is provided on an AS IS basis with ABSOLUTELY NO WAR- # RANTY. The entire risk as to the quality and performance of the # software is with you. Should the software prove defective, you as- # sume the cost of all necessary servicing, repair or correction. In # no event will any of the developers, or any other party, be liable # to anyone for damages arising out of use of the software, or inabil- # ity to use the software. #--------------------------------------------------------------------- # explanation #--------------------------------------------------------------------- # 1. Overview: # This program [easytag.wrapper] is a simple wrapper that starts the # main EasyTAG executable [which must be renamed to "easytag.bin"]. # Presently, three features are implemented: # # a. The wrapper tries to prevent multiple instances. # # b. It displays an FYI dialog that warns the user about EasyTAG's # slow startup procedure. # # c. Additionally, the wrapper overrides EasyTAG's geometry set- # tings [both the default settings and the saved settings, if # any]. In other words, the wrapper determines the dimensions # and position of EasyTAG's main window. This fixes problems # that occur with some displays. #--------------------------------------------------------------------- # 2. Requirements: # At the GUI level, this program requires Perl 5, Perl-Gtk2, LACSUB, # "zenity", and a small utility named "getx11dim". Additionally, some # versions of this program may require "glxinfo". # These components are standard, except for LACSUB and "getx11dim". # You should be able to obtain the latter components from the same # place as this file. Note: "getx11dim" is distributed under a BSD- # style license. LACSUB [like this file] is distributed under a Crea- # tive Commons license. #--------------------------------------------------------------------- # standard module setup #--------------------------------------------------------------------- require 5.6.1; use strict; use Carp; use warnings; # Trap warnings $SIG {__WARN__} = sub { die @_; }; #--------------------------------------------------------------------- # add LACSUB module[s] #--------------------------------------------------------------------- use LACSUB::GUI ( @LACSUB::GUI::EXPORT_OK ); #--------------------------------------------------------------------- # basic constants #--------------------------------------------------------------------- use constant ZERO => 0; # Zero use constant ONE => 1; # One use constant FALSE => 0; # Boolean FALSE use constant TRUE => 1; # Boolean TRUE #--------------------------------------------------------------------- # program parameters #--------------------------------------------------------------------- my $DIR_BASE = '__META_PREFIX__'; my $ALERT_ICON_PATH = "$DIR_BASE/misc/alert.png"; my $TARGET_PROGRAM = "$DIR_BASE/bin/easytag.bin"; #--------------------------------------------------------------------- # main routine #--------------------------------------------------------------------- sub Main { my $data; # Data buffer my $n; # Scratch (integer) my $str; # Scratch (string ) #--------------------------------------------------------------------- # Verify that program isn't running. &VerifyNotRunning ( -icon_path => $ALERT_ICON_PATH , -name => 'easytag' , -pattern_this => ':\d\d\s(perl |)(\S+/|)easytag(|\.wrapper)\s' , -pattern_next => ':\d\d\s(perl |)(\S+/|)easytag\.bin\s' ); #--------------------------------------------------------------------- # Warn the user about EasyTAG's slow startup procedure. my $msg = << 'END'; EasyTAG scans the hard disk on startup. This may take a few minutes. Do you want to proceed? END my $cmd_dialog = << "END"; zenity --question --title="Start EasyTAG" --text="$msg" END $cmd_dialog =~ s@\s+\z@@s; $n = system $cmd_dialog; exit ONE if $n; #--------------------------------------------------------------------- # Adjust configuration-file settings. my $HOME = $ENV {HOME}; if (defined ($HOME) && length ($HOME) && (-d $HOME) && (-r $HOME) && (-w $HOME) && (-x $HOME)) { my $CFG_DIR = "$HOME/.easytag"; my $CFG_FILE = "$CFG_DIR/easytagrc"; system "mkdir -p $CFG_DIR" unless -d $CFG_DIR; system "touch $CFG_FILE" unless -f $CFG_FILE; $str = `getx11dim 2>&1`; $str = "" if !defined $str; my ($DisplayWidth, $DisplayHeight) = $str =~ m@^(\d+)x(\d+)@; if (defined ($DisplayHeight) && open (IFD, "<$CFG_FILE")) { undef $/; binmode IFD; $data = ; $data = "" if !defined $data; close IFD; my $main_x = 15; my $main_y = 70; my $main_w = $DisplayWidth - 30; my $main_h = $DisplayHeight - ($main_y + 90); my $orig_data = $data; $data =~ s@\s*\z@\n@; my $EQWSZ = '[\011\040]*=[\011\040]*'; if ($data !~ s@\b(main_window_width$EQWSZ)\d+@$1$main_w@) { $data .= "main_window_width=$main_w\n"; } if ($data !~ s@\b(main_window_height$EQWSZ)\d+@$1$main_h@) { $data .= "main_window_height=$main_h\n"; } if ($data !~ s@\b(main_window_x$EQWSZ)\d+@$1$main_x@) { $data .= "main_window_x=$main_x\n"; } if ($data !~ s@\b(main_window_y$EQWSZ)\d+@$1$main_y@) { $data .= "main_window_y=$main_y\n"; } if (($data ne $orig_data) && open (OFD, ">$CFG_FILE")) { print OFD $data; close OFD; print "Updated $CFG_FILE\n"; } } } #--------------------------------------------------------------------- # Wrap it up. # Chain to target program exec $TARGET_PROGRAM, @ARGV; exit ONE; # Shouldn't be reached } #--------------------------------------------------------------------- # main program #--------------------------------------------------------------------- &Main(); # Call the main routine exit ONE; # Shouldn't be reached