summaryrefslogtreecommitdiffstats
path: root/perl-install/pkgs.pm
Commit message (Expand)AuthorAgeFilesLines
* kill some "used undefined variable" warningsPascal Rigaux2007-09-141-1/+1
* re-sync after the big svn lossPascal Rigaux2007-05-181-1486/+31
* re-sync after the big svn lossPascal Rigaux2007-05-181-0/+1598
* re-sync after the big svn lossPascal Rigaux2007-04-251-1598/+0
* fix selected_leaves() dropping all packages in a circular referencePascal Rigaux2006-01-241-6/+11
* package lsb is requiring many locales though we don't want it to be installedPascal Rigaux2005-12-131-2/+9
* (bestKernelPackage) install i586 kernel flavor for live systemsThierry Vignaud2005-12-071-0/+1
* fix rpmsrate negations when not installing a live systemOlivier Blin2005-11-211-4/+4
* (read_rpmsrate) do not match CAT_(KDE|GNOME|...) and ignore ! whileThierry Vignaud2005-11-211-5/+4
* (read_rpmsrate) let "build_live_system" mode be selected by auto config fileThierry Vignaud2005-11-211-1/+1
* (read_rpmsrate) install all hardware related packages when building a live sy...Thierry Vignaud2005-11-211-0/+1
* Fix test for dangling symlinkRafael Garcia-Suarez2005-10-201-1/+1
* Comment fixRafael Garcia-Suarez2005-09-261-1/+1
* don't warn lisa (which is installed by default)Pascal Rigaux2005-09-201-1/+4
* URPM/Resolve.pm diff 1.109: "Remove the return value of compute_installed_fla...Pascal Rigaux2005-09-161-1/+9
* - call installCallback() on "open" tooPascal Rigaux2005-09-151-0/+2
* add upgrade script for conectivaPascal Rigaux2005-09-141-10/+21
* do have all useful info in selected leaves, including base packages,Pascal Rigaux2005-09-141-1/+1
* do log the prefered choice (esp. to debug lilo vs grub)Pascal Rigaux2005-09-141-1/+1
* have same rpm config as when installing pkgsPascal Rigaux2005-09-091-1/+4
* At some point, an empty hashref is autovivified in $packages->{medium}.Rafael Garcia-Suarez2005-09-051-1/+2
* - new functionality: upgrade_by_removing_pkgs, enabled when upgrading redhat ...Pascal Rigaux2005-09-021-0/+81
* Workaround : Don't call method directlyRafael Garcia-Suarez2005-09-021-1/+1
* rename pkgs::rpmDbOpenForInstall() to pkgs::open_rpm_db_rw()Pascal Rigaux2005-09-021-3/+3
* allow verbose removing of packagesPascal Rigaux2005-09-021-1/+1
* opening rpm db in selectPackage(), so remove some rpmDbOpen()Pascal Rigaux2005-09-021-0/+2
* new function select_by_package_names()Pascal Rigaux2005-09-021-0/+9
* create remove_raw(), remove() now retries with option noscriptsPascal Rigaux2005-09-011-4/+14
* preferred packages:Pascal Rigaux2005-09-011-1/+1
* help debugging packageCallbackChoices()Pascal Rigaux2005-09-011-2/+3
* instead of dirtying pkgs::installCallback, use install_steps::installCallbackPascal Rigaux2005-08-311-9/+9
* fix typoPascal Rigaux2005-08-311-1/+1
* create remove_marked_ask_remove() and use itPascal Rigaux2005-08-311-26/+21
* on 2002/07/10 (1.347), selected_leaves() behaviour was broken, listing all pa...Pascal Rigaux2005-08-291-4/+11
* remove now unused variable (cf previous commit)Pascal Rigaux2005-08-251-1/+0
* don't kill "runaway" processes anymore, it should not be needed for ejecting ...Pascal Rigaux2005-08-251-14/+0
* Strange typing bug workaroundRafael Garcia-Suarez2005-08-251-1/+2
* for bestKernelPackage(), sort kernels to have higher version firstPascal Rigaux2005-08-231-1/+3
* update naughtyServers for new distroPascal Rigaux2005-08-181-6/+15
* (naughtyServers_list): those packages don't exist anymorePascal Rigaux2005-08-181-8/+0
* don't fork anymore to install rpmsPascal Rigaux2005-08-171-71/+25
* during install, use "nofsync" for rpm database (=> speedup x2)Pascal Rigaux2005-08-171-0/+1
* cleanupPascal Rigaux2005-08-171-8/+8
* on upgrade, have not only the upgraded packages, but also the installed packa...Pascal Rigaux2005-08-101-1/+1
* move is_xbox from common to detect_devicesOlivier Blin2005-08-051-1/+1
* This function was renamedRafael Garcia-Suarez2005-06-301-1/+1
* Remove dependency of c::stuff on rpmlibRafael Garcia-Suarez2005-06-301-7/+6
* try to cleanup fs.pmPascal Rigaux2005-06-281-1/+1
* Fix install_urpmi with nfs suppl mediaRafael Garcia-Suarez2005-06-281-1/+2
* Remove DB logs before doing an install.Rafael Garcia-Suarez2005-06-241-0/+6
id='n588' href='#n588'>588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
#!/usr/bin/perl 
#
# Copyright (C) 2001-2002 by MandrakeSoft
#                            DUPONT Sebastien
#                            dchaumette@mandrakesoft.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# drakfont Future Overview
#         - Fonts import:
#                 pfb ( Adobe Type 1 binary )
#                 pfa ( Adobe Type 1 ASCII )
#                 ttf ( True-Type  )
#                 pcf.gz
#                 Speedo
#                 and Bitmap (PCF, BDF, and SNF)
#         - Features
#                 - Install fonts from any directory
#                 - Get windows fonts on any vfat partitions
#                 - Get fonts on any partitions.
#                 - UN-installation of any fonts (even if not installed through drakfont)
#         - Support
#               - Xfs
#               - ghostscript & printer
#               - Staroffice & printer
#               - abiword
#		- netscape
#               - Koffice, Gnumeric, ... studying
#               - all fonts supported by printer
#               - anti-aliases by RENDER in Xfree86 .... 
# 				supported by KDE.
# 				will be supported by gnome 1.2.
# Visual Interface:
#         Window interface:
#           - Fontselectiondialog widget
#           - Command buttons under Fontselectiondialog (like the actual frontend).
#         Commands buttons:
#           - import from windows partition.
#                 import from all fat32 partitions and look for winnt/windows/font
#                 and import all (delete doubles) but don't import if they already exist.
#           - import from directory
#                 look to see if each font exists and do not delete the original.
#                 (replace all, no, none)
#                 expert options:
#                         specify the directory, and look to see if it exists before
#                         if it exists ask: (replace all, no, none)
#           - uninstall with list per font type
#         Expert additional switch
#           - option support:   ghostscript, Staroffice, etc...
#                 check-button. (by default all check)
#           - Printer Application Fonts Support...
#                 check-button. (by default all check)
#
# TODO:
#     - abiword, Koffice, Gnumeric, ...  
#     - Speedo  and Bitmap (PCF, BDF, and SNF)
#     - option strong: strong verification with ttmkfdir -c ?
#                
# REQUIRE:
#     - font-tools.*.mdk.i586.rpm
#
# USING:
#    -  pfm2afm:   by Ken Borgendale: Convert a Windows .pfm  file to a .afm (Adobe Font Metrics)
#    -  type1inst: by James Macnicol: type1inst generates files fonts.dir fonts.scale & Fontmap.
#    -  ttf2pt1:   by Andrew Weeks, Frank Siegert, Thomas Henlich, Sergey Babkin  convert ttf font files to afm and pfb fonts
#
#
# directory to install fonts /usr/X11R6/lib/X11/fonts/
# -->> /usr/X11R6/lib/X11/fonts/drakfont

use strict;
use diagnostics;

use lib qw(/usr/lib/libDrakX);

use standalone;    #- warning, standalone must be loaded very first, for 'explanations'

use interactive;
use ugtk2 qw(:helpers :wrappers :create);
use common;


my $in = 'interactive'->vnew('su', 'network');

#   global variables needed by each functions
my $xlsfonts = 0;
my $windows  = 0;
my $strong;
my $replace;
my $application;
my $install;
my $uninstall;
my $so      = 1;
my $gs      = 1;
my $abi     = 1;
my $printer = 1;
my $mode    = -1;
my @application;
my @install;
my @uninstall;
my $interactive;
my $text;
my $vscrollbar;
my $check4;
my $check1;
my $check2;
my $check3;
my $pbar;
my $pbar1;
my $pbar2;
my $pbar3;
my $font_box;
my $central_widget;
my $label1;
my $label2;
my $label3;
my $label4;
my $list_path;
my $path_list;
my $current_path;
my $model;
my $list;
my $list_all_font_path;
my $left_list;
my $right_list;
my $left_model;
my $right_model;

foreach (@ARGV) {
    /--list|-l/            and $list_all_font_path = 1, $mode = -1;
    /--xls_fonts/          and $xlsfonts           = 1, $mode = -1;
    /--windows_import|-wi/ and $windows            = 1, $mode = -1;
    /--strong|-s/          and $strong             = 1, $mode = -1;
    /--replace|-r/         and $replace            = 1, $mode = -1;
    /--application/        and $mode               = 0, next;
    $mode == 0 and push @application, $_;
    /--install/ and $mode = 1, next;
    $mode == 1 and push @install, $_;
    /--uninstall/ and $mode = 2, next;
    $mode == 2 and push @uninstall, $_;
}

foreach my $i (@application) {
    if ($i =~ /so/i) {
        if ($gs != 2) { $gs = 0 }
        $so = 2;
    }
    if ($i =~ /gs/i) {
        if ($so != 2) { $so = 0 }
        $gs = 2;
    }
}

# PATH and binary full path
my $xfs_conffile = '/etc/fonts/fonts.conf';
my $drakfont_dir = '/usr/X11R6/lib/X11/fonts/drakfont';
my $ttf2pt1      = '/usr/sbin/ttf2pt1';
my $pfm2afm      = '/usr/sbin/pfm2afm';
my $type1inst    = '/usr/sbin/type1inst';
my $chkfontpath  = '/usr/sbin/chkfontpath';
# mkttfdir only knows about iso-8859-1, using ttmkfdir instead
my $mkttfdir     = '/usr/X11R6/bin/mkttfdir';
my $ttmkfdir     = '/usr/sbin/ttmkfdir';
my $fccache      = '/usr/bin/fc-cache';
my $ghostscript;

# Global lists, just to manipulate it easily.
# my @font_list                    => list of fonts to install.
# my @installed_fonts;             => list of installed fonts.
# my @installed_fonts_path;        => list of path included in xfs.
# my @fontsdir_to_install;         => list of fonts to uninstall.
# my @fontsdir_to_uninstall;       => path to remove in xfs font file.
# my @installed_fonts_full_path;   => full path list of fonts to uninstall.

my @font_list;
my @installed_fonts;
my @installed_fonts_path;
my @fontsdir_to_install;
my @fontsdir_to_uninstall;
my @installed_fonts_full_path;

sub list_fontpath {
    foreach (grep { /\d+:\s/ } `$chkfontpath -l`) {
        chomp;
        s/\d+:\s//gi;
        s/:\w*$//gi;
        push @installed_fonts_path, $_;
    }
}

sub chk_empty_xfs_path {
    my @temp3;
    foreach my $tmp_path (@installed_fonts_path) {
        @temp3 = ();
        foreach my $temp2 (all($tmp_path)) {
            if (!($temp2 =~ /^fonts/ || $temp2 =~ /^type/)) {
                push @temp3, $temp2;
            }
        }
        if (!(@temp3)) {
            system("chkfontpath -r $tmp_path ")
              or print "PERL::system command failed during chkfontpath\n";
        }
    }
}

sub search_installed_fonts {
    list_fontpath();
    $interactive and progress($pbar, 0.1, N("Search installed fonts"));
    push @installed_fonts, all($_) foreach @installed_fonts_path;
    $interactive and progress($pbar, 0.1, N("Unselect fonts installed"));
}

sub search_installed_fonts_full_path {
    list_fontpath();
    foreach my $i (@installed_fonts_path) {
        foreach my $j (all($i)) {
            push @installed_fonts_full_path, "$i/$j";
        }
    }
}

sub search_windows_font {
    foreach my $fstab_line (grep { /vfat|ntfs/ } cat_('/etc/mtab')) {
        my $win_dir = (split('\s', $fstab_line))[1];
        my @list_fonts_win   = all("$win_dir/windows/fonts");
        my @list_fonts_winnt = all("$win_dir/winnt/fonts");
        my $nb_dir           = @list_fonts_win + @list_fonts_winnt;
        foreach ([ \@list_fonts_win, "windows" ],
            [ \@list_fonts_winnt, "winnt" ])
        {
            foreach my $i (@{ $_->[0] }) {
                if ($interactive) {
                    if ($nb_dir) {
                        progress($pbar, 0.25 / $nb_dir, N("parse all fonts"));
                    }
                    else {
                        display_error(N("no fonts found"));
                        return 0;
                    }
                }
                !$replace && any { /$i/ } @installed_fonts and next;
                grep(/$i$/, @font_list)
                  or push @font_list, "$win_dir/$_->[1]/fonts/$i";
            }
        }
        $interactive && $nb_dir and progress($pbar, 1, N("done"));
    }
    if (!@font_list) {
        print "drakfont:: could not find any font in /win*/fonts \n";
        $interactive
          and display_error(
            N("could not find any font in your mounted partitions"));
        return 0;
    }
    1;
}

sub is_a_font {
    local $_ = $_[0];
         /\.ttf$/i || /\.pfa$/i || /\.pfb$/i || /\.pcf$/i || /\.pcf\.gz$/i || /\.pfm$/i || /\.gsf$/;
}

# Optimisation de cette etape indispensable
sub search_dir_font {
    foreach my $fn (@install) {
        my @font_list_tmp;
        my $dir;
        if (!(-e $fn)) { print "$fn :: no such file or directory \n" }
        else {
            if (-d $fn) {
                $dir = $fn;
                foreach my $i (all($fn)) {
                    if (is_a_font($i)) {
                        push @font_list_tmp, $i;
                        foreach my $i (@font_list_tmp) {
                            !$replace && any { /$i/ } @installed_fonts and next;
                            grep(/$i/, @font_list) or push @font_list, "$fn/$i";
                        }
                    }
                }
            }
            elsif (is_a_font($fn)) {
		!$replace && any { /$fn/ } @installed_fonts and next;
		!grep /$fn/, (@installed_fonts) and push @font_list, $fn;
	    }
        }
        $interactive and progress($pbar, 0.50 / @install, N("Reselect correct fonts"));
    }
    $interactive and progress($pbar, 1, N("done"));
    !@font_list && $interactive and display_error(N("could not find any font.\n"));
}

sub search_dir_font_uninstall {
    my @font_list_tmp;
    my $fn  = $_;
    if (-d $fn) {
        foreach my $i (all($fn)) {
            push @font_list_tmp, $i if is_a_font($i);
        }
    }
    else {
        push @font_list_tmp, $fn if is_a_font($fn);
    }
    foreach my $i (@installed_fonts_full_path) {
        foreach my $j (@font_list_tmp) {
            push @font_list, $i if $i =~ /$j/;
        }
    }
    print "Fonts to uninstal: " . $_ . "\n" foreach @font_list;
}

sub search_dir_font_uninstall_gi {
    @font_list = @uninstall;
    $interactive and progress($pbar, 1, N("Search for fonts in installed list"));
}

sub print_list {
    print "Font(s) to Install:\n\n";
    print "$_\n" foreach @font_list;
}

sub dir_created {
    -e $drakfont_dir || mkdir_p($drakfont_dir);
    -e $drakfont_dir . "/Type1"     || mkdir_p($drakfont_dir . "/Type1");
    -e $drakfont_dir . "/ttf"       || mkdir_p($drakfont_dir . "/ttf");
    -e $drakfont_dir . "/tmp"       || mkdir_p($drakfont_dir . "/tmp");
    -e $drakfont_dir . "/tmp/ttf"   || mkdir_p($drakfont_dir . "/tmp/ttf");
    -e $drakfont_dir . "/tmp/Type1" || mkdir_p($drakfont_dir . "/tmp/Type1");
    -e $drakfont_dir . "/tmp/tmp"   || mkdir_p($drakfont_dir . "/tmp/tmp");
}

sub put_font_dir {
    my @tmpl;
    -e "/usr/share/ghostscript"
      or $gs = 0 && print "ghostscript is not installed on your system...\n";
    if (@font_list) {
        dir_created();
        foreach my $i (@font_list) {
            cp_af($i, $drakfont_dir . "/tmp/tmp");
            $interactive and progress($pbar1, 1 / @font_list, N("Fonts copy"));
        }
        $interactive and progress($pbar1, 0.01, N("done"));
        $interactive and progress($pbar2, 0.10, N("True Type fonts installation"));
        glob("$drakfont_dir/tmp/tmp/*.TTF") 
	  and system('cd ' . $drakfont_dir . '/tmp/tmp ; for foo in *.TTF; do mv $foo `basename $foo .TTF`.ttf; done');
        system('cd ' . $drakfont_dir . '/tmp/tmp  && cp *.ttf ../../ttf');
        $interactive and progress($pbar2, 0.20, N("please wait during ttmkfdir..."));

        my $ttfdir = $drakfont_dir . "/ttf";
	# mkttfdir only knows about iso-8859-1, using ttmkfdir -u instead -- pablo
        #`$mkttfdir $ttfdir`;
       	system("cd $ttfdir && $fccache && $ttmkfdir -u > fonts.dir");
        $interactive and progress($pbar2, 0.10, N("True Type install done"));
        my $update_chkfontpath = "$chkfontpath -a $drakfont_dir/ttf";

        if ($so && $gs) {
            my @glob_drak = glob("$drakfont_dir/tmp/tmp/*.ttf");
            foreach my $fontname (@glob_drak) {
                system("cd $drakfont_dir/tmp/tmp && $ttf2pt1 -b $fontname");
                $interactive and progress($pbar2, 0.50 / @glob_drak, N("Fonts conversion"));
            }
            system("cd $drakfont_dir/tmp/tmp && mv *.gsf *.pfb *.pfm *.afm ../Type1");
            system("cd $drakfont_dir/tmp/Type1 && $type1inst");
            $interactive and progress($pbar2, 0.10, N("type1inst building"));
            -e "$drakfont_dir/tmp/Type1/Fontmap" 
	      and system("cd $drakfont_dir/tmp/Type1 && cat Fontmap >> `rpm -ql ghostscript | grep Fontmap.GS` ");
            system("cd $drakfont_dir/tmp/Type1 && mv *.pfm *.gsf *.afm *.pfb ../../Type1 ");
            my $type1dir = $drakfont_dir . "/Type1";
            system("cd $type1dir && $fccache && $type1inst");
            $interactive and progress($pbar2, 0.05, N("Ghostscript referencing"));
            $update_chkfontpath .= "; $chkfontpath -a $drakfont_dir/Type1";
        }

        if (!$so && $gs) {
            foreach my $fontname (@tmpl = glob("$/drakfont_dir/tmp/tmp/*.ttf")) {
                system("cd $/drakfont_dir/tmp/tmp && $ttf2pt1 -b $fontname");
                $interactive and progress($pbar2, 0.50 / @tmpl, N("Fonts conversion"));
            }
            system("cd $drakfont_dir/tmp/tmp && mv *.gsf *.pfb *.pfm ../Type1");
            system("cd $drakfont_dir/tmp/Type1 && $type1inst");
            $interactive and progress($pbar2, 0.1, N("type1inst building"));
            system("cd $drakfont_dir/tmp/Type1 && cat Fontmap >> `rpm -ql ghostscript | grep Fontmap.GS` ");
            system("cd $drakfont_dir/tmp/Type1 && mv *.pfm *.afm *.gsf *.pfb ../../Type1 ");
            my $type1dir = $drakfont_dir . "/Type1";
            system("cd $type1dir && $fccache && $type1inst");
            $interactive and progress($pbar2, 0.05, N("Ghostscript referencing"));
            $update_chkfontpath .= "; $chkfontpath -a $drakfont_dir/Type1";
        }

        if ($so && !$gs) {
            foreach my $fontname (@tmpl = glob("$drakfont_dir/tmp/tmp/*.ttf"))
            {
                system("cd $drakfont_dir/tmp/tmp && $ttf2pt1 $fontname");
                $interactive and progress($pbar2, 0.25 / @tmpl, N("ttf fonts conversion"));
            }
            foreach my $fontname (@tmpl = glob("$drakfont_dir/tmp/tmp/*.pfm"))
            {
                system("cd $drakfont_dir/tmp/tmp && $pfm2afm $fontname");
                $interactive and progress($pbar2, 0.25 / @tmpl, N("pfm fonts conversion"));
            }
            system("cd $drakfont_dir/tmp/tmp && mv  *.afm ../Type1");
            system("cd $drakfont_dir/tmp/Type1 && mv *.afm ../../Type1 ");
            my $type1dir = $drakfont_dir . "/Type1";
            system("cd $type1dir && $fccache && $type1inst");
            $interactive and progress($pbar2, 0.14, N("type1inst building"));
            $update_chkfontpath .= "; $chkfontpath -a $drakfont_dir/Type1";
        }

        $interactive and progress($pbar2, 1, N("done"));
        $interactive and progress($pbar3, 0.25, N("Suppress Temporary Files"));
        rm_rf("$drakfont_dir/tmp/");
        print "\n\nretarting xfs......\n";
        $interactive and progress($pbar3, 0.5, N("Restart XFS"));
        system($update_chkfontpath);
        system('/etc/rc.d/init.d/xfs restart');
	system('xset fp rehash');
        $interactive and progress($pbar3, 0.30, N("done"));
    }
}

sub remove_gs_fonts {
    my @Fontmap_new;

    if (all("$drakfont_dir/remove")) {
        system(" cd $drakfont_dir/remove && $type1inst");
        my @Fontmap_out = cat_("$drakfont_dir/remove/Fontmap");
        my $FontmapGS   = `rpm -ql ghostscript | grep Fontmap.GS`;
        chomp($FontmapGS);
        my @FontmapGS_list = cat_($FontmapGS);
        foreach my $font_gs (@FontmapGS_list) {
            my @tmp_list = split(' ', $font_gs);
            grep(/$tmp_list[0]/, @Fontmap_out) or push @Fontmap_new, $font_gs;
        }
        print $_ foreach @Fontmap_new;
        output($FontmapGS, @Fontmap_new);
    }

}

sub remove_fonts {
    my @list_dir;
    -e $drakfont_dir . "/remove" || mkdir_p($drakfont_dir . "/remove");
    $interactive and progress($pbar, 1, N("done"));
    foreach my $i (@font_list) {
        $_ = $i;
        if (/.pfb$/ || /.gsf$/ || /.pfm$/ || /.pfa$/) {
            system("mv $_ $drakfont_dir/remove ");
        }
        else {
	    if (/.ttf$/) {
		rm_rf($_);
		# rebuild of the fonts.dir and fc-cache files
       		system("cd `dirname $_` && $fccache && $ttmkfdir -u > fonts.dir");
	    }
            else { rm_rf($i) }
        }
        $i =~ s/\/\w*\.\w*//gi;
        grep($i, (@list_dir)) or push @list_dir, $i;
        $interactive and progress($pbar1, 1 / @font_list, N("Suppress Fonts Files"));
    }
    $interactive and progress($pbar1, 0.01, N("done"));
    -e "/usr/share/ghostscript" and remove_gs_fonts();
    foreach my $i (@list_dir) {
        if (listlength all($i) < 3) {
            system("chkfontpath -r $i") or print "PERL::system command failed during chkfontpath\n";
        }
        else {
            system("cd $i && type1inst") or print "PERL::system command failed during cd or type1inst\n";
        }
        $interactive and progress($pbar2, 1 / @list_dir, N("Suppress Fonts Files"));
    }
    $interactive and progress($pbar2, 0.01, N("xfs restart"));
    system("/etc/rc.d/init.d/xfs restart");
    system('xset fp rehash');
    -e "/usr/share/ghostscript" and rm_rf("$drakfont_dir/remove");
    $interactive and progress($pbar2, 0.01, N("done"));
}

sub license_msg {
    print N("Before installing any fonts, be sure that you have the right to use and install them on your system.\n\n-You can install the fonts the normal way. In rare cases, bogus fonts may hang up your X Server.") . "\n";
}

$list_all_font_path || $xlsfonts || $windows || @install || @uninstall ? backend_mod() : interactive_mode();

sub backend_mod {
    $xlsfonts && system("xlsfonts");
    $list_all_font_path && system($chkfontpath);

    if ($windows) {
        license_msg();
        print "\nWindows fonts Installation........\n";
        search_installed_fonts();
        if (search_windows_font()) {
            print_list();
            put_font_dir();
        }
        print "\nThe End...........................\n";
    }

    if (@install) {
        license_msg();
        print "\nInstall Specifics Fonts...........\n";
        search_installed_fonts();
        search_dir_font();
        print "Font to install: " . $_ . "\n" foreach @font_list;
        put_font_dir();
        print "\nThe End...........................\n";
    }

    if (@uninstall) {
        print "\nUninstall Specifics Fonts.........\n";
        search_installed_fonts_full_path();
        if ($interactive) { search_dir_font_uninstall_gi() }
        else { search_dir_font_uninstall $_ foreach @uninstall }
        remove_fonts();
        print "\nThe End............................\n";
    }
}

sub create_fontsel {
    my $font_sel;
    gtkpack($font_box, $font_sel = new Gtk2::FontSelection,);
    $central_widget = \$font_sel;
}

sub display_error {
    my ($message) = @_;
    my $error_box;
    ${$central_widget}->destroy();
    gtkpack($font_box,
	    $error_box = gtkpack_(new Gtk2::VBox(0, 0), 1,
				  new Gtk2::Label($message), 0,
				  gtkadd(gtkset_layout(new Gtk2::HButtonBox, 'spread'),
					 gtksignal_connect(new Gtk2::Button(N("OK")),
							   clicked => sub { ${$central_widget}->destroy(); create_fontsel() }
							  ),
					),
				 )
	   );
    $central_widget = \$error_box;
}

sub interactive_mode {
    my $font_sel;
    $interactive = 1;
    my $window1 = ugtk2->new('drakfont');
    $window1->{rwindow}->signal_connect(delete_event => sub { ugtk2->exit(0) });
    unless ($::isEmbedded) {
        $window1->{rwindow}->set_position('center');
        $window1->{rwindow}->set_title(N("Import Fonts"));
    }

    gtkadd($window1->{window},
	   gtkpack_(new Gtk2::VBox(0, 2), if_(!$::isEmbedded, 0, gtkcreate_img("drakfont.620x57")), 1,
		    gtkpack_(new Gtk2::HBox(0, 2), 1,
			     gtkpack_(new Gtk2::VBox(0, 2), 1,
				      gtkpack($font_box = new Gtk2::VBox(0, 5), $font_sel = new Gtk2::FontSelection,), 1,
				      gtkpack_(new Gtk2::HBox(0, 2), 0,
					       gtkadd(gtkset_layout(new Gtk2::VButtonBox, 'end'),
						      gtksignal_connect(new Gtk2::Button(N("Get Windows Fonts")),
									clicked => sub {
									    ${$central_widget}->destroy();
									    $windows = 1;
									    appli_choice();
									}),
						      gtksignal_connect(new Gtk2::Button(N("Uninstall Fonts")),
									clicked => sub {
									    ${$central_widget}->destroy();
									    uninstall();
									}),
						     ), 0,
					       gtkadd(gtkset_layout(new Gtk2::VButtonBox, 'end'),
						      gtksignal_connect(new Gtk2::Button(N("Advanced Options")),
									clicked => sub {
									    ${$central_widget}->destroy();
									    $windows = 0;
									    advanced_install();
									}),
						      gtksignal_connect(new Gtk2::Button(N("Font List")),
									clicked => sub {
									    ${$central_widget}->destroy();
									    create_fontsel();
									}),
						     ), 1,
					       new Gtk2::HBox(0, 2), 0,
					       gtkadd(gtkset_layout(new Gtk2::VButtonBox, 'end'),
						      gtksignal_connect(new Gtk2::Button(N("About")), clicked => sub { help() }),
						      gtksignal_connect(new Gtk2::Button(N("Close")),
									clicked => sub {
									    $::isEmbedded and kill 'USR1', $::CCPID;
									    Gtk2->main_quit();
									}),
						     ),
					      ),
				     ),
			    ),
		   ),
	  );
    $central_widget = \$font_sel;
    $window1->{rwindow}->show_all;
    $window1->{rwindow}->realize;
    $window1->main;
    ugtk2->exit(0);
}

sub text_view {
    my ($text) = @_;
    my $box;
    gtkpack($font_box,
	    $box = gtkpack_(new Gtk2::VBox(0,10), 1,
			    gtkpack_(new Gtk2::HBox(0,0), 1,
				     create_scrolled_window(gtktext_insert(new Gtk2::TextView, [ [ $text ] ]))
				    ), 0, 
			    gtkadd(gtkset_layout(new Gtk2::HButtonBox, 'spread'),
				   gtksignal_connect(new Gtk2::Button(N("OK")), 
						     clicked => sub { ${$central_widget}->destroy() }),
				  ),
			   )
	   );
    $central_widget = \$box;
    $font_box->show_all();
}

sub help {
    ugtk2::create_dialog(N("
 Copyright (C) 2001-2002 by MandrakeSoft 
	DUPONT Sebastien (original version)
        CHAUMETTE Damien <dchaumette\@mandrakesoft.com>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

 Thanks:
    -  pfm2afm:   
	 by Ken Borgendale:
	    Convert a Windows .pfm  file to a .afm (Adobe Font Metrics)
    -  type1inst:
	 by James Macnicol: 
	    type1inst generates files fonts.dir fonts.scale & Fontmap.
    -  ttf2pt1:   
	  by Andrew Weeks, Frank Siegert, Thomas Henlich, Sergey Babkin  
             Convert ttf font files to afm and pfb fonts
"));
}

sub appli_choice {
    my $choice_box;
    my $text = new Gtk2::TextView;
    gtkpack($font_box,
	    $choice_box = gtkpack_(new Gtk2::HBox(0, 10), 0,
				   new Gtk2::VBox(0, 10), 0,
				   new Gtk2::VBox(0, 10), 1,
				   gtkpack_(new Gtk2::VBox(0, 10), 1,
					    gtkpack_(new Gtk2::VBox(0, 10), 1,
						     gtkpack(new Gtk2::HBox(0, 10), 
							     new Gtk2::HBox(0, 10),
							     N("Choose the applications that will support the fonts:"),
							     new Gtk2::HBox(0, 10),
							    ), 0,
						     new Gtk2::HBox(0, 10), 0, 
						     gtkpack_(new Gtk2::HBox(0, 10), 0,
							      N("Ghostscript"), 1,
							      new Gtk2::HBox(0, 10), 0,
							      my $check11 = new Gtk2::CheckButton(),
							     ), 0,
						     gtkpack_(new Gtk2::HBox(0, 10), 0,
							      N("StarOffice"), 1,
							      new Gtk2::HBox(0, 10), 0,
							      my $check22 = new Gtk2::CheckButton(),
							     ), 0,
						     gtkpack_(new Gtk2::HBox(0, 10), 0,
							      N("Abiword"), 1,
							      new Gtk2::HBox(0, 10), 0,
							      my $check33 = new Gtk2::CheckButton(),
							     ), 0,
						     gtkpack_(new Gtk2::HBox(0, 10), 0,
							      N("Generic Printers"), 1,
							      new Gtk2::HBox(0, 10), 0,
							      my $check44 = new Gtk2::CheckButton(),
							     ),
						    ), 0,
					    gtkpack_(new Gtk2::HBox(0, 10), 1,
						     gtktext_insert(gtkset_editable($text, 0),
								    [ [ N("Before installing any fonts, be sure that you have the right to use and install them on your system.\n\n-You can install the fonts the normal way. In rare cases, bogus fonts may hang up your X Server.") ] ]
								   ), 0,
						     new Gtk2::VBox(0, 10),
						    ), 0,
					    gtkadd(gtkset_layout(new Gtk2::HButtonBox, 'spread'),
						   gtksignal_connect(new Gtk2::Button(N("OK")),
								     clicked => sub {
									 ${$central_widget}->destroy();
									 import_status();
								     }),
						   gtksignal_connect(new Gtk2::Button(N("Cancel")),
								     clicked => sub {
									 ${$central_widget}->destroy();
									 create_fontsel();
								     }),
						  ),
					   ), 0,
				   new Gtk2::VBox(0, 10), 0,
				   new Gtk2::VBox(0, 10),
				  ),
	   );
    foreach ([ $check11, \$gs ], [ $check22, \$so ], [ $check33, \$abi ], [ $check44, \$printer ]) {
        my $ref = $_->[1];
        gtksignal_connect(gtkset_active($_->[0], ${$ref}), toggled => sub { ${$ref} = ${$ref} ? 0 : 1 });
    }
    $central_widget = \$choice_box;
    $font_box->show_all();
}

sub font_choice {
    my $file_dialog;
    $file_dialog = gtksignal_connect(new Gtk2::FileSelection(N("File Selection")), destroy => sub { $file_dialog->destroy() });
    $file_dialog->ok_button->signal_connect(clicked => \&file_ok_sel, $file_dialog);
    $file_dialog->ok_button->set_label(N("Add"));
    $file_dialog->cancel_button->signal_connect(clicked => sub { $file_dialog->destroy() });
    $file_dialog->cancel_button->set_label(N("Close"));
    $file_dialog->set_filename(N("Select the font file or directory and click on 'Add'"));
    $file_dialog->show();
}

sub file_ok_sel {
    my ($_widget, $file_selection) = @_;
    my $file_name = $file_selection->get_filename();
    print "-- @install\n";
    if (!member($file_name, @install)) {
        push @install, $file_name;
	$model->append_set(undef, [ 0 => $file_name ]);
    }
}

sub list_remove { #- TODO : multi-selection
    my ($treeStore, $iter) = $list->get_selection->get_selected;
    my $to_remove = $treeStore->_get($iter, 0);
    my ($index) = map_index { if_($_ eq $to_remove, $::i) } @install;
    splice @install, $index, 1;
    $treeStore->remove($iter);
}

sub advanced_install {
    my $adv_box;
    $model = Gtk2::TreeStore->new(Gtk2::GType->STRING);
    $list = Gtk2::TreeView->new_with_model($model);
    $list->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0));
    $list->set_headers_visible(0);
    $list->get_selection->set_mode('browse');
    $list->set_rules_hint(1);

    gtkpack($font_box,
	    $adv_box = gtkpack_(new Gtk2::VBox(0, 10), 1,
				gtkpack_(new Gtk2::HBox(0, 4), 1, create_scrolled_window($list),), 0,
				gtkadd(gtkset_layout(new Gtk2::HButtonBox, 'spread'),
				       gtksignal_connect(new Gtk2::Button(N("Add")), clicked => sub { font_choice() }),
				       gtksignal_connect(new Gtk2::Button(N("Remove Selected")), clicked => \&list_remove),
				       gtksignal_connect(new Gtk2::Button(N("Install List")), 
							 clicked => sub {
							     ${$central_widget}->destroy();
							     appli_choice();
							 })
				      )
			       )
	   );
    $central_widget = \$adv_box;
    $adv_box->show_all();
}

sub list_to_remove {
    #my @files_path = grep(!/fonts/, all($current_path)); garbage ?
    gtkflush();
    my ($tree, @tux) = $left_list->get_selection->get_selected_rows(); #- get tree & paths
    foreach (@tux) { my $iter = $tree->get_iter($_); push @uninstall, $tree->_get($iter, 0) }
    #push @uninstall, $current_path . "/" . $files_path[$_] foreach @number_to_remove; garbage ?
    ${$central_widget}->destroy();
    show_list_to_remove();
}

sub show_list_to_remove {
    my $show_box;
    my $model = Gtk2::TreeStore->new(Gtk2::GType->STRING);
    my $list = Gtk2::TreeView->new_with_model($model);
    $list->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0));
    $list->set_headers_visible(0);
    $list->get_selection->set_mode('browse');
    $list->set_rules_hint(1);

    $model->append_set(undef, [ 0 => $_ ]) foreach @uninstall;

    gtkpack($font_box,
	    $show_box = gtkpack_(new Gtk2::VBox(0, 10), 1,
				 gtkpack_(new Gtk2::HBox(0, 4), 1, create_scrolled_window($list)), 0,
				 gtkadd(gtkset_layout(new Gtk2::HButtonBox, 'spread'),
					gtksignal_connect(new Gtk2::Button(N("click here if you are sure.")),
							  clicked => sub {
							      ${$central_widget}->destroy();
							      import_status_uninstall();
							  }),
					gtksignal_connect(new Gtk2::Button(N("here if no.")),
							  clicked =>
							  sub { ${$central_widget}->destroy(); create_fontsel() }
							 ),
				       ),
				)
	   );
    $central_widget = \$show_box;
    $show_box->show_all();
}

sub uninstall { #- TODO : add item to right list with gtksignal_connect
    my $uninst_box;
    @install              = ();
    @installed_fonts_path = ();
    list_fontpath();
    chk_empty_xfs_path();
    
    #- left part
    $left_model = Gtk2::TreeStore->new(Gtk2::GType->STRING);
    $left_list = Gtk2::TreeView->new_with_model($left_model);
    $left_list->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0));
    $left_list->set_headers_visible(0);
    $left_list->set_rules_hint(1);
    $left_list->get_selection->set_mode('multiple');

    $left_model->append_set(undef, [ 0 => $_ ]) foreach @installed_fonts_path;

    #- right part
    $right_model = Gtk2::TreeStore->new(Gtk2::GType->STRING);;
    $right_list = Gtk2::TreeView->new_with_model($right_model);
    $right_list->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0));
    $right_list->set_headers_visible(0);
    $right_list->get_selection->set_mode('multiple');
    $right_list->set_rules_hint(1);

    gtkpack($font_box,
	    $uninst_box = gtkpack_(new Gtk2::VBox(0, 10), 1,
				   gtkpack_(new Gtk2::HBox(0, 4), 1,
					    create_scrolled_window($left_list), #1,
					    #create_scrolled_window($right_list)
					   ), 0,
				   gtkadd(gtkset_layout(new Gtk2::HButtonBox, 'spread'),
					  gtksignal_connect(new Gtk2::Button(N("Unselected All")),
							    clicked => sub { $left_list->get_selection->unselect_all() }
							   ),
					  gtksignal_connect(new Gtk2::Button(N("Selected All")),
							    clicked => sub { $left_list->get_selection->select_all() }
							   ),
					  gtksignal_connect(new Gtk2::Button(N("Remove List")), clicked => sub { list_to_remove() }),
					 ),
				  )
	   );
    $central_widget = \$uninst_box;
    $uninst_box->show_all();
}

sub import_status {
    my $table;
    $pbar  = new Gtk2::ProgressBar;
    $pbar1 = new Gtk2::ProgressBar;
    $pbar2 = new Gtk2::ProgressBar;
    $pbar3 = new Gtk2::ProgressBar;
    gtkpack(
        $font_box,
        $table = create_packtable({ col_spacings => 10, row_spacings => 50 },
				  [ "", "" ],
				  [ N("Initial tests"), $pbar, $pbar->set_text(' ') ],
				  [ N("Copy fonts on your system"), $pbar1, $pbar1->set_text(' ') ],
				  [ N("Install & convert Fonts"), $pbar2, $pbar2->set_text(' ') ],
				  [ N("Post Install"), $pbar3, $pbar3->set_text(' ') ],
				 ),
	   );
    $central_widget = \$table;
    $font_box->show_all();
    gtkflush();
    backend_mod();
}

sub import_status_uninstall {
    my $table;
    $pbar  = new Gtk2::ProgressBar;
    $pbar1 = new Gtk2::ProgressBar;
    $pbar2 = new Gtk2::ProgressBar;
    gtkpack(
        $font_box,
        $table = create_packtable({ col_spacings => 10, row_spacings => 50 },
				  [ "", "" ],
				  [ "", "" ],
				  [ N("Initial tests"), $pbar, $pbar->set_text(' ') ],
				  [ N("Remove fonts on your system"), $pbar1, $pbar1->set_text(' ') ],
				  [ N("Post Uninstall"), $pbar2, $pbar2->set_text(' ') ],
				 ),
	   );
    $central_widget = \$table;
    $font_box->show_all();
    gtkflush();
    backend_mod();
}

sub progress {
    my ($progressbar, $incr, $label_text) = @_;
    my ($new_val) = $progressbar->fraction;
    $new_val += $incr;
    if ($new_val > 1) { $new_val = 1 }
    $progressbar->fraction($new_val);
    $progressbar->set_text($label_text);
    gtkflush();
}