summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakfont
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/standalone/drakfont')
-rwxr-xr-xperl-install/standalone/drakfont1507
1 files changed, 523 insertions, 984 deletions
diff --git a/perl-install/standalone/drakfont b/perl-install/standalone/drakfont
index 998f8c706..8222810a5 100755
--- a/perl-install/standalone/drakfont
+++ b/perl-install/standalone/drakfont
@@ -1,6 +1,10 @@
#!/usr/bin/perl
+# -*- coding: utf-8 -*-
#
-# Copyright (C) 2001-2002 by MandrakeSoft (sdupont@mandrakesoft.com)
+# Copyright (C) 2001-2008 by Mandriva SA
+# DUPONT Sebastien
+# Damien Chaumette
+# Thierry Vignaud
#
# 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
@@ -30,7 +34,6 @@
# - Get fonts on any partitions.
# - UN-installation of any fonts (even if not installed through drakfont)
# - Support
-# - Xfs
# - ghostscript & printer
# - Staroffice & printer
# - abiword
@@ -47,13 +50,13 @@
# Commands buttons:
# - import from windows partition.
# import from all fat32 partitions and look for winnt/windows/font
-# and import all (delete doublon) but don't import if already exist.
+# and import all (delete doubles) but do not import if they already exist.
# - import from directory
-# look for if it exist before for each font and not delete the original.
+# look to see if each font exists and do not delete the original.
# (replace all, no, none)
# expert options:
-# ask the directory, and look for if it exist before
-# if it exist ask: (replace all, no, none)
+# 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...
@@ -62,9 +65,7 @@
# 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
@@ -75,68 +76,56 @@
# - 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
+# directory to install fonts /usr/lib/X11/fonts/
+# -->> /usr/lib/X11/fonts/drakfont
-use lib qw(/usr/lib/libDrakX );
+use strict;
+use diagnostics;
+use utf8;
+
+use lib qw(/usr/lib/libDrakX);
use standalone; #- warning, standalone must be loaded very first, for 'explanations'
-use interactive;
-use my_gtk qw(:helpers :wrappers);
+use mygtk3 qw(gtknew); #- do not import gtkadd which conflicts with ugtk3 version
+use ugtk3 qw(:create :dialogs :helpers :wrappers);
use common;
+use run_program;
-use strict;
-use diagnostics;
-#use Config;
-#use POSIX;
+require_root_capability();
-my $in = 'interactive'->vnew( 'su', 'network' );
+$ugtk3::wm_icon = "drakfont";
# 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 $so = to_bool(-f '/usr/bin/ooffice');
+my $gs = to_bool(-f '/usr/bin/gs');
+my $abi = to_bool(-f '/usr/bin/abiword');
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 $window1;
+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, $_;
@@ -147,46 +136,36 @@ foreach (@ARGV) {
}
foreach my $i (@application) {
- if ( $i =~ /so/i ) {
- if ( $gs != 2 ) { $gs = 0; }
+ if ($i =~ /so/i) {
+ if ($gs != 2) { $gs = 0 }
$so = 2;
}
- if ( $i =~ /gs/i ) {
- if ( $so != 2 ) { $so = 0; }
+ if ($i =~ /gs/i) {
+ if ($so != 2) { $so = 0 }
$gs = 2;
}
}
# PATH and binary full path
-my $xfs_conffile = '/etc/X11/fs/config';
-my $drakfont_dir = '/usr/X11R6/lib/X11/fonts/drakfont';
+my $font_dir = '/usr/share/fonts';
+my $fontpathd_dir = '/etc/X11/fontpath.d/';
+my $drakfont_dir = "$font_dir/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 $xftcache = '/usr/X11R6/bin/xftcache';
-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` ) {
+# mkttfdir only knows about iso-8859-1, using ttmkfdir instead -- pablo
+my $ttmkfdir = '/usr/bin/ttmkfdir';
+my $fccache = '/usr/bin/fc-cache';
+
+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 @installed_fonts_full_path; # full path list of fonts to uninstall
+
+sub list_fontpath() {
+ foreach (uniq((map { expand_symlinks($_) } glob_("$fontpathd_dir/*")),
+ (-x $chkfontpath ? grep { /\d+:\s/ } `$chkfontpath -l` : ()))) {
chomp;
s/\d+:\s//gi;
s/:\w*$//gi;
@@ -194,368 +173,281 @@ sub list_fontpath {
}
}
-sub chk_empty_xfs_path {
- my @temp3;
+sub chk_empty_xfs_path() {
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 ")
+ if (every { /^fonts/ || /^type/ } all($tmp_path)) {
+ system($chkfontpath, '-r', $tmp_path)
or print "PERL::system command failed during chkfontpath\n";
}
}
}
-sub search_installed_fonts {
+sub search_installed_fonts() {
list_fontpath();
- $interactive and progress( $pbar, 0.1, N("Search installed fonts") );
+ interactive_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") );
+ interactive_progress($pbar, 0.1, N("Unselect fonts installed"));
}
-sub search_installed_fonts_full_path {
+sub search_installed_fonts_full_path() {
list_fontpath();
foreach my $i (@installed_fonts_path) {
- foreach my $j ( all($i) ) {
+ 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 && grep( /$i/, @installed_fonts ) and next;
- grep ( /$i$/, @font_list )
- or push @font_list, "$win_dir/$_->[1]/fonts/$i";
+sub search_windows_font() {
+ my @fonts;
+ foreach my $fstab_line (grep { /vfat|smbfs|ntfs|fuse/ } cat_('/etc/mtab')) {
+ my $win_dir = (split('\s', $fstab_line))[1];
+ foreach my $sys_dir (grep { /^win(nt|dows)$/i } all($win_dir)) {
+ foreach my $font_dir (grep { /^fonts$/i } map { all($_) } "$win_dir/$sys_dir") {
+ push @fonts, map { "$win_dir/$sys_dir/$font_dir/$_" } all("$win_dir/$sys_dir/$font_dir");
}
}
- $interactive && $nb_dir and progress( $pbar, 1, N("done") );
+ }
+ my $nb_dir = @fonts;
+ if (!$nb_dir) {
+ err_dialog(N("Error"), N("No fonts found"));
+ return 0;
}
- if ( !@font_list ) {
+ foreach my $font (@fonts) {
+ progress($pbar, 0.25 / $nb_dir, N("parse all fonts")) if $interactive;
+ my $font_name = basename($font);
+ !$replace && any { /^\Q$font_name\E$/ } @installed_fonts and next;
+ any { /^\Q$font_name\E$/ } @font_list or push @font_list, $font;
+ }
+ $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") );
+ and err_dialog(N("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$/;
+my @font_extensions = qw(ttf ttc pfa pfb pcf pcf.gz pfm gsf ttc otf);
+
+sub is_a_font($) {
+ my ($file) = @_;
+ any { $file =~ /\Q.$_\E$/i } @font_extensions;
}
# Optimisation de cette etape indispensable
-sub search_dir_font {
+sub search_dir_font() {
foreach my $fn (@install) {
- my @font_list_tmp = ();
- my @font_list_tmpp = ();
- my $dir;
- if ( !( -e $fn ) ) { print "$_ :: no such file or directory \n" }
+ my @font_list_tmp;
+ 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";
+ if (-d $fn) {
+ foreach my $i (all($fn)) {
+ if (is_a_font($i)) {
+ push @font_list_tmp, $i;
foreach my $i (@font_list_tmp) {
- !$replace && grep( /$i/, @installed_fonts )
- and next;
- grep /$i/, @font_list or push @font_list, "$fn/$i";
+ !$replace && any { /$i/ } @installed_fonts and next;
+ any { /$i/ } @font_list or push @font_list, "$fn/$i";
}
}
}
}
- else {
- if ( is_a_font($fn) ) {
- !$replace && grep( /$fn/, @installed_fonts ) and next;
- !grep /$fn/, (@installed_fonts) and push @font_list, "$fn";
- }
- }
+ elsif (is_a_font($fn)) {
+ !$replace && any { /\Q$fn\E/ } @installed_fonts and next;
+ !any { /\Q$fn\E/ } @installed_fonts and push @font_list, $fn;
+ }
}
- $interactive
- and progress( $pbar, 0.50 / @install, N("Reselect correct fonts") );
+ interactive_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") );
+ interactive_progress($pbar, 1, N("done"));
+ !@font_list && $interactive and err_dialog(N("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) ) {
- if ( is_a_font($i) ) { push @font_list_tmp, "$i"; }
- }
- }
- else {
- if ( is_a_font($fn) ) { push @font_list_tmp, "$fn"; }
- }
- foreach my $i (@installed_fonts_full_path) {
- foreach my $j (@font_list_tmp) {
- if ( $i =~ /$j/ ) { push @font_list, "$i"; }
- }
- }
- print "Fonts to uninstal: " . $_ . "\n" foreach (@font_list);
+ my ($fn) = @_;
+ print "Fonts to uninstal: " . $_ . "\n" foreach uniq(@font_list, -d $fn ? (grep { is_a_font($_) } all($fn)) : if_(is_a_font($fn), $fn));
}
-sub search_dir_font_uninstall_gi {
+sub search_dir_font_uninstall_gi() {
@font_list = @uninstall;
- $interactive and progress( $pbar, 1, N("Search fonts in installed list") );
+ interactive_progress($pbar, 1, N("Search for fonts in installed list"));
}
-sub print_list {
+sub print_list() {
print "Font(s) to Install:\n\n";
- print "$_\n" foreach (@font_list);
+ print "$_\n" foreach @font_list;
+}
+
+sub dir_created() {
+ return if $::testing;
+ foreach (qw(Type1 ttf otf ttc tmp/ttf tmp/Type1 tmp/tmp)) {
+ my $dir = "$drakfont_dir/$_";
+ next if -e $dir;
+ mkdir_p($dir);
+ symlink($dir, "$fontpathd_dir/drakfont_$_:pri=50");
+ }
+}
+
+
+sub convert_fonts {
+ my ($fonts, $converter, $font_type, $o_generate_pfb) = @_;
+ $o_generate_pfb = $o_generate_pfb ? "-b" : "";
+ foreach my $fontname (@$fonts) {
+ system("cd $drakfont_dir/tmp/tmp && $converter $o_generate_pfb $fontname");
+ interactive_progress($pbar2, 0.50 / @$fonts, N("%s fonts conversion", $font_type));
+ }
}
-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 convert_ttf_fonts {
+ my ($fonts, $o_generate_pfb) = @_;
+ convert_fonts($fonts, $ttf2pt1, "TTF", $o_generate_pfb);
}
-sub put_font_dir {
- my @tmpl;
- my @list_ttf;
- -e "/usr/share/ghostscript"
- or $gs = 0 && print "ghostscript is not installed on your system...\n";
+
+sub move_fonts {
+ my ($src_dir, $dest_dir, @extensions) = @_;
+ my @fonts = map { s!.*/!!; $_ } map { glob("$src_dir/*.$_") } @extensions;
+ return if !@fonts;
+ system('mv', "$src_dir/$_", "$src_dir/$dest_dir") foreach @fonts;
+}
+
+sub my_rm_rf {
+ my ($target) = @_;
+ eval { rm_rf(@_) };
+ if (my $err = $@) {
+ warn "cannot remove $target: $err\n";
+ }
+}
+
+sub put_font_dir_real {
+ my ($subdir, $command, $progress, $title) = @_;
+ system("cd $drakfont_dir/$subdir && $fccache && $command");
+ interactive_progress($pbar2, $progress, $title);
+ symlinkf("$drakfont_dir/$subdir", "/etc/X11/fontpath.d/drakfont_$subdir");
+ my_rm_rf("$font_dir/fonts.cache-1");
+}
+
+sub put_font_dir() {
+ -e "/usr/share/ghostscript" or do { $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") );
+ cp_af($i, $drakfont_dir . "/tmp/tmp") if !$::testing;
+ interactive_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 && $xftcache . && $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 && $xftcache . && $type1inst");
- $interactive
- and progress( $pbar2, 0.05, N("Ghostscript referencing") );
- $update_chkfontpath .= "; $chkfontpath -a $drakfont_dir/Type1";
+ interactive_progress($pbar1, 0.01, N("done"));
+ interactive_progress($pbar2, 0.10, N("True Type fonts installation"));
+ my $temp_dir = "$drakfont_dir/tmp/tmp/";
+ foreach my $font (glob("$temp_dir/*.TTF")) {
+ my $newfont = $font;
+ $newfont =~ s/\.TTF$/.ttf/;
+ rename($font, $newfont);
}
+ system('cd ' . $temp_dir . ' && cp *.ttf ../../ttf; chmod 644 ../../ttf/*ttf') if glob("$temp_dir/*.ttf");
+ interactive_progress($pbar2, 0.20, N("please wait during ttmkfdir..."));
+ put_font_dir_real("ttf", "$ttmkfdir > fonts.dir", 0.10, N("True Type install done"));
- 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");
+ if ($gs) {
+ convert_ttf_fonts([ glob("$drakfont_dir/tmp/tmp/*.ttf") ], 1);
+ move_fonts("$drakfont_dir/tmp/tmp", "../Type1", qw(afm gsf pfb pfm));
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 && $xftcache . && $type1inst");
- $interactive
- and progress( $pbar2, 0.05, N("Ghostscript referencing") );
- $update_chkfontpath .= "; $chkfontpath -a $drakfont_dir/Type1";
+ interactive_progress($pbar2, 0.1, N("type1inst building"));
+ if ($so) {
+ -e "$drakfont_dir/tmp/Type1/Fontmap"
+ and system("cd $drakfont_dir/tmp/Type1 && cat Fontmap >> `rpm -ql ghostscript-common | grep Fontmap.GS` ");
+ move_fonts("$drakfont_dir/tmp/Type1", "../../Type1", qw(afm gsf pfb pfm));
+ } else {
+ system("cd $drakfont_dir/tmp/Type1 && cat Fontmap >> `rpm -ql ghostscript-common | grep Fontmap.GS` ");
+ move_fonts("$drakfont_dir/tmp/Type1", "../../Type1", qw(afm gsf pfb pfm));
+ }
+ put_font_dir_real("Type1", $type1inst, 0.05, N("Ghostscript referencing"));
+ } elsif ($so) {
+ convert_ttf_fonts([ glob("$drakfont_dir/tmp/tmp/*.ttf") ]);
+ convert_fonts([ glob("$drakfont_dir/tmp/tmp/*.pfm") ], $pfm2afm, "PFM");
+ move_fonts("$drakfont_dir/tmp/tmp", "../Type1", qw(afm));
+ move_fonts("$drakfont_dir/tmp/Type1", "../../Type1", qw(afm));
+ put_font_dir_real("Type1", $type1inst, 0.14, N("type1inst building"));
}
- 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 && $xftcache . && $type1inst");
- $interactive and progress( $pbar2, 0.14, N("type1inst building") );
- $update_chkfontpath .= "; $chkfontpath -a $drakfont_dir/Type1";
+ foreach my $subdir (qw(otf ttc)) {
+ my $dir = "$drakfont_dir/$subdir";
+ move_fonts("$drakfont_dir/tmp/tmp", "../../$subdir", $subdir);
+ run_program::run($_, $dir) foreach qw(mkfontscale mkfontdir), $fccache;
+ symlinkf($dir, '/etc/X11/fontpath.d/drakfont_' . basename($dir));
}
- $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 ($restart_xfs);
- # system('kill -USR1 `/sbin/pidof xfs` 2&1>/dev/null');
- system('/etc/rc.d/init.d/xfs restart');
- system('xset fp rehash');
- $interactive and progress( $pbar3, 0.30, N("done") );
+ interactive_progress($pbar2, 1, N("done"));
+ interactive_progress($pbar3, 0.25, N("Suppress Temporary Files"));
+ my_rm_rf("$drakfont_dir/tmp/") if !$::testing;
+ system(qw(xset fp rehash));
+ interactive_progress($pbar3, 0.30, N("done"));
}
}
-sub remove_gs_fonts {
+sub remove_gs_fonts() {
my @Fontmap_new;
- if ( all("$drakfont_dir/remove") ) {
+ 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`;
+ my $FontmapGS = `rpm -ql ghostscript-common | 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;
+ my @tmp_list = split(' ', $font_gs);
+ any { /$tmp_list[0]/ } @Fontmap_out or push @Fontmap_new, $font_gs;
}
print $_ foreach @Fontmap_new;
- output( $FontmapGS, @Fontmap_new );
+ output($FontmapGS, @Fontmap_new);
}
}
-sub remove_fonts {
+sub remove_fonts() {
my @list_dir;
- -e $drakfont_dir . "/remove" || mkdir_p( $drakfont_dir . "/remove" );
- $interactive and progress( $pbar, 1, N("done") );
+ -e $drakfont_dir . "/remove" or mkdir_p($drakfont_dir . "/remove") if !$::testing;
+ interactive_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 xftcache files
- system("cd `dirname $_` && $xftcache . && $ttmkfdir -u > fonts.dir");
- }
- else {
- rm_rf($i);
- }
+ local $_ = $i;
+ if (/.pfb$/ || /.gsf$/ || /.pfm$/ || /.pfa$/) {
+ system('mv', $_, "$drakfont_dir/remove");
+ } else {
+ next if $::testing;
+ if (/.ttf$/) {
+ my_rm_rf($_);
+ # rebuild of the fonts.dir and fc-cache files
+ system("cd `dirname $_` && $fccache && $ttmkfdir > fonts.dir");
+ } else { my_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") );
+ $i =~ s!/\w*\.\w*!!gi;
+ any { $i } @list_dir or push @list_dir, $i;
+ interactive_progress($pbar1, 1 / @font_list, N("Suppress Fonts Files"));
}
- $interactive and progress( $pbar1, 0.01, N("done") );
+ interactive_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") );
+ system("cd $i && type1inst") or print "PERL::system command failed during cd or type1inst\n";
+ interactive_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") );
+ system(qw(xset fp rehash));
+ -e "/usr/share/ghostscript" and my_rm_rf("$drakfont_dir/remove") if !$::testing;
+ interactive_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 using the normal way. In rare cases, bogus fonts may hang up your X Server.") . "\n";
+sub license_msg() {
+ N("Before installing any fonts, be sure that you have the right to use and install them on your system.\n\nYou 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 and system("xlsfonts");
-sub backend_mod {
- if ($xlsfonts) {
- system("xlsfonts");
- }
- if ($list_all_font_path) {
- system("$chkfontpath");
- }
if ($windows) {
- license_msg();
+ print license_msg();
print "\nWindows fonts Installation........\n";
search_installed_fonts();
- if ( search_windows_font() ) {
+ if (search_windows_font()) {
print_list();
put_font_dir();
}
@@ -563,11 +455,11 @@ sub backend_mod {
}
if (@install) {
- license_msg();
+ print license_msg();
print "\nInstall Specifics Fonts...........\n";
search_installed_fonts();
- search_dir_font;
- print "Font to install: " . $_ . "\n" foreach (@font_list);
+ search_dir_font();
+ print "Font to install: " . $_ . "\n" foreach @font_list;
put_font_dir();
print "\nThe End...........................\n";
}
@@ -576,677 +468,324 @@ sub backend_mod {
print "\nUninstall Specifics Fonts.........\n";
search_installed_fonts_full_path();
if ($interactive) { search_dir_font_uninstall_gi() }
- else { search_dir_font_uninstall $_ foreach (@uninstall) }
+ 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 Gtk::FontSelection, );
- $central_widget = \$font_sel;
-}
-
-sub display_error {
- my ($message) = @_;
- my $label;
- my $error_box;
- ${$central_widget}->destroy();
- gtkpack(
- $font_box,
- $error_box = gtkpack_(
- new Gtk::VBox( 0, 0 ),
- 1,
- new Gtk::Label($message),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::HButtonBox, -spread ),
- gtksignal_connect(
- new Gtk::Button( N("OK") ),
- clicked =>
- sub { ${$central_widget}->destroy(); create_fontsel() }
- ),
- ),
- )
- );
- $central_widget = \$error_box;
-}
-
-sub interactive_mode {
- my $font_sel;
+sub interactive_mode() {
$interactive = 1;
- my $window1 = my_gtk->new('drakfont');
- $window1->{rwindow}->signal_connect( delete_event => sub { my_gtk->exit(0) } );
- unless ($::isEmbedded) {
- $window1->{rwindow}->set_position(1);
- $window1->{rwindow}->set_title( N("Fonts Importation") );
- }
- $window1->{rwindow}->set_border_width(5);
- my ( $pix_user_map, $pix_user_mask ) = gtkcreate_png("ic-drakfont-48");
- my ( $pix_u_map, $pix_u_mask ) = gtkcreate_png("drakfont.620x57");
-
- gtkadd(
- $window1->{window},
- gtkpack_(
- new Gtk::VBox( 0, 2 ),
- if_(
- !$::isEmbedded, 0, new Gtk::Pixmap( $pix_u_map, $pix_u_mask )
- ),
- 1,
- gtkpack_(
- new Gtk::HBox( 0, 2 ),
- 1,
- gtkpack_(
- new Gtk::VBox( 0, 2 ),
- 1,
- gtkpack(
- $font_box = new Gtk::VBox( 0, 5 ),
- $font_sel = new Gtk::FontSelection,
- ),
- 1,
- gtkpack_(
- new Gtk::HBox( 0, 2 ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::VButtonBox, -end ),
- gtksignal_connect(
- new Gtk::Button( N("Get Windows Fonts") ),
- clicked => sub {
- ${$central_widget}->destroy();
- $windows = 1;
- appli_choice();
- }
- ),
- gtksignal_connect(
- new Gtk::Button( N("Uninstall Fonts") ),
- clicked => sub {
- ${$central_widget}->destroy();
- uninstall();
- }
- ),
- ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::VButtonBox, -end ),
- gtksignal_connect(
- new Gtk::Button( N("Advanced Options") ),
- clicked => sub {
- ${$central_widget}->destroy();
- $windows = 0;
- advanced_install();
- }
- ),
- gtksignal_connect(
- new Gtk::Button( N("Font List") ),
- clicked => sub {
- ${$central_widget}->destroy();
- create_fontsel();
- }
- ),
- ),
- 1,
- new Gtk::HBox( 0, 2 ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::VButtonBox, -end ),
- gtksignal_connect(
- new Gtk::Button( N("Help") ),
- clicked =>
- sub { ${$central_widget}->destroy(); help() }
- ),
- gtksignal_connect(
- new Gtk::Button( N("Close") ),
- clicked => sub {
- $::isEmbedded and kill 'USR1', $::CCPID;
- Gtk->main_quit();
- }
- ),
- ),
- ),
+ $window1 = ugtk3->new(N("Font Installation"));
+ mygtk3::register_main_window($window1->{real_window});
+ $window1->{rwindow}->signal_connect(delete_event => sub { ugtk3->exit(0) });
+ $window1->{rwindow}->set_position('center') if !$::isEmbedded;
+
+ my $button = {};
+ my $disable = sub { my ($b) = @_; $button->{$_}->set_sensitive($_ ne $b) foreach keys %$button };
+
+ local $::Wizard_no_previous = 1;
+ gtkadd($window1->{window},
+ gtkpack_(Gtk3::VBox->new(0, 2),
+ if_(!$::isEmbedded, 0, Gtk3::Banner->new("drakfont", N("DrakFont"))),
+ 0, gtknew('Title2', label => N("Font List")),
+ 1, Gtk3::FontSelection->new,
+ 0, gtkadd(create_hbox(),
+ gtksignal_connect(Gtk3::Button->new(N("Get Windows Fonts")), clicked => sub { $windows = 1; import_status(); $windows = 0 }),
+ ),
+ 0, create_okcancel(my $oc = {
+ ok_clicked => sub { Gtk3->main_quit },
+ },
+ undef, undef, '',
+ if_(0, [ N("About"), \&help, 1 ]),
+ [ N("Options"), \&appli_choice, 1 ],
+ [ N("Uninstall"), \&uninstall, 1 ],
+ [ N("Import"), \&advanced_install, 1 ],
+ ),
),
+ );
+ $oc->{ok}->set_label(N("Close"));
- # 0, gtkpack_(new Gtk::VBox(0,5),
- # 0, new Gtk::VBox(0,0),
- # 0, new Gtk::Pixmap($pix_user_map, $pix_user_mask),
- # 1, new Gtk::VBox(0,0),
- # 1, gtkadd(gtkset_layout(new Gtk::VButtonBox, -end),
- # gtksignal_connect(new Gtk::Button(N("About")), clicked => sub {
- # ${$central_widget}->destroy(); about() }),
- # gtksignal_connect(new Gtk::Button(N(" Help ")), clicked => sub {
- # ${$central_widget}->destroy(); help() }),
- # gtksignal_connect(new Gtk::Button(N("Close")), clicked => sub {
- # $::isEmbedded and kill 'USR1', $::CCPID;
- # Gtk->main_quit() }),
- # ),
- # )
- ),
- ),
- );
- $central_widget = \$font_sel;
+ $disable->('font_list');
$window1->{rwindow}->show_all;
- $font_sel->set_page(1);
- $font_sel->cur_page->child->hide();
- $font_sel->set_page(2);
- $font_sel->cur_page->child->hide();
- $font_sel->set_page(0);
$window1->{rwindow}->realize;
-
- # $window1->{rwindow}->show_all();
$window1->main;
- my_gtk->exit(0);
-}
-
-sub about {
- my $text = new Gtk::Text( undef, undef );
- my $about_box;
- gtkpack(
- $font_box,
- $about_box = gtkpack_(
- new Gtk::VBox( 0, 10 ),
- 1,
- gtkpack_(
- new Gtk::HBox( 0, 0 ),
- 1,
- gtktext_insert(
- gtkset_editable( $text, 1 ), "
- Copyright (C) 2001-2002 by MandrakeSoft
- DUPONT Sebastien sdupont\@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
-
-
-"
- ),
- 0,
- new Gtk::VScrollbar( $text->vadj ),
- ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::HButtonBox, -spread ),
- gtksignal_connect(
- new Gtk::Button( N("OK") ),
- clicked =>
- sub { ${$central_widget}->destroy(); create_fontsel() }
- ),
- ),
- )
- );
- $central_widget = \$about_box;
- $font_box->show_all();
-}
-
-sub help {
- my $text = new Gtk::Text( undef, undef );
- my $help_box;
- gtkpack(
- $font_box,
- $help_box = gtkpack_(
- new Gtk::VBox( 0, 10 ),
- 1,
- gtkpack_(
- new Gtk::HBox( 0, 0 ),
- 1,
- gtktext_insert(
- gtkset_editable( $text, 1 ), "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 doublon) but don't import if already exist.
- - import from directory
- look for if it exist before for each font and not delete the original.
- (replace all, no, none)
- expert options:
- ask the directory, and look for if it exist before
- if it exist 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...
-
-
-"
- ),
- 0,
- new Gtk::VScrollbar( $text->vadj ),
- ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::HButtonBox, -spread ),
- gtksignal_connect(
- new Gtk::Button( N("OK") ),
- clicked =>
- sub { ${$central_widget}->destroy(); create_fontsel() }
- ),
- ),
- )
- );
- $central_widget = \$help_box;
- $font_box->show_all();
-}
-
-sub appli_choice {
- my $choice_box;
- my $text = new Gtk::Text( undef, undef );
- gtkpack(
- $font_box,
- $choice_box = gtkpack_(
- new Gtk::HBox( 0, 10 ),
- 0,
- new Gtk::VBox( 0, 10 ),
- 0,
- new Gtk::VBox( 0, 10 ),
- 1,
- gtkpack_(
- new Gtk::VBox( 0, 10 ),
- 1,
- gtkpack_(
- new Gtk::VBox( 0, 10 ),
- 1,
- gtkpack(
- new Gtk::HBox( 0, 10 ),
- new Gtk::HBox( 0, 10 ),
- N("Choose the applications that will support the fonts:"),
- new Gtk::HBox( 0, 10 ),
- ),
- 0,
- new Gtk::HBox( 0, 10 ),
- 0,
- gtkpack_(
- new Gtk::HBox( 0, 10 ), 0,
- N("Ghostscript"), 1,
- new Gtk::HBox( 0, 10 ), 0,
- my $check11 = new Gtk::CheckButton(),
- ),
- 0,
- gtkpack_(
- new Gtk::HBox( 0, 10 ), 0,
- N("StarOffice"), 1,
- new Gtk::HBox( 0, 10 ), 0,
- my $check22 = new Gtk::CheckButton(),
- ),
- 0,
- gtkpack_(
- new Gtk::HBox( 0, 10 ), 0,
- N("Abiword"), 1,
- new Gtk::HBox( 0, 10 ), 0,
- my $check33 = new Gtk::CheckButton(),
- ),
- 0,
- gtkpack_(
- new Gtk::HBox( 0, 10 ), 0,
- N("Generic Printers"), 1,
- new Gtk::HBox( 0, 10 ), 0,
- my $check44 = new Gtk::CheckButton(),
- ),
- ),
- 0,
- gtkpack_(
- new Gtk::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 using the normal way. In rare cases, bogus fonts may hang up your X Server.")
- ),
- 0,
- new Gtk::VScrollbar( $text->vadj ),
- 0,
- new Gtk::VBox( 0, 10 ),
- ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::HButtonBox, -spread ),
- gtksignal_connect(
- new Gtk::Button( N("OK") ),
- clicked => sub {
- ${$central_widget}->destroy();
- import_status();
- }
- ),
- gtksignal_connect(
- new Gtk::Button( N("Cancel") ),
- clicked => sub {
- ${$central_widget}->destroy();
- create_fontsel();
- }
- ),
- ),
- ),
- 0,
- new Gtk::VBox( 0, 10 ),
- 0,
- new Gtk::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 {
+ ugtk3->exit(0);
+}
+
+$list_all_font_path || $xlsfonts || $windows || @install || @uninstall ? backend_mod() : interactive_mode();
+
+sub help() {
+ my $license = formatAlaTeX(translate($::license));
+ $license =~ s/\n/\n\n/sg; # nicer formatting
+ my $w = gtknew('AboutDialog', name => N("Drakfont"),
+ version => mageia_release_info()->{version},
+ copyright => N("Copyright (C) %s by %s", 'Mandriva', '2001-2008') . "\n" . N("Copyright (C) %s by %s", N("Mageia"), '2011') . "\n",
+ license => $license, wrap_license => 1,
+ comments => N("Font installer."),
+ website => 'http://www.mageia.org',
+ website_label => N("Mageia"),
+ authors => [ 'Sébastien Dupont', 'Damien Chaumette', 'Thierry Vignaud <thierry.vignaud.com>' ],
+ translator_credits =>
+ #-PO: put here name(s) and email(s) of translator(s) (eg: "John Smith <jsmith@nowhere.com>")
+ N("_: Translator(s) name(s) & email(s)\n"),
+ transient_for => $window1->{real_window}, modal => 1, position_policy => 'center-on-parent',
+ );
+ $w->show_all;
+ $w->run;
+}
+
+sub appli_choice() {
+ dialog(N("Options"),
+ [
+ 0, gtknew('Title2', label => N("Choose the applications that will support the fonts:")),
+ 0, Gtk3::WrappedLabel->new(formatAlaTeX(license_msg())),
+ (map {
+ my ($label, $ref) = @$_;
+ (0, gtkpack_(Gtk3::HBox->new,
+ 0, $label,
+ 1, Gtk3::HBox->new,
+ # BUG: that code never had supported canceling
+ 0, gtksignal_connect(gtkset_active(Gtk3::CheckButton->new, $$ref), toggled => sub { $$ref = $$ref ? 0 : 1 }),
+ ),
+ );
+ } ([ N("Ghostscript"), \$gs ],
+ [ N("LibreOffice"), \$so ],
+ [ N("Abiword"), \$abi ],
+ [ N("Generic Printers"), \$printer ],
+ ),
+ ),
+ ],
+ [
+ gtksignal_connect(Gtk3::Button->new(N("Ok")),
+ clicked => \&exitdialog,
+ ),
+ ],
+ );
+}
+
+sub font_choice() {
my $file_dialog;
-
- $file_dialog = gtksignal_connect(
- new Gtk::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->child->set( N("Add") );
- $file_dialog->cancel_button->signal_connect(
- clicked => sub { $file_dialog->destroy() } );
- $file_dialog->cancel_button->child->set( 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 );
- $list->add( gtkshow( new Gtk::ListItem($file_name) ) );
+ my $_select_font_msg = N("Select the font file or directory and click on 'Add'");
+ $file_dialog = Gtk3::FileChooserDialog->new(N("File Selection"), $::main_window, 'open', N("Cancel") => 'cancel', N("Ok") => 'ok'); # 'select_folder'
+ $file_dialog->set_select_multiple(1);
+
+ my $filter = Gtk3::FileFilter->new;
+ $filter->set_name(N("Fonts"));
+ $filter->add_pattern("*.$_") foreach @font_extensions, map { uc($_) } @font_extensions;
+ $file_dialog->add_filter($filter);
+ $file_dialog->set_filter($filter);
+
+ $file_dialog->show;
+ while (my $answer = $file_dialog->run) {
+ if (member($answer, qw(cancel delete-event))) {
+ $file_dialog->destroy;
+ return;
+ } elsif ($answer eq 'ok') {
+ my $files = $file_dialog->get_filenames;
+ foreach my $file_name (difference2($files, \@install)) {
+ push @install, $file_name;
+ $model->append_set(undef, [ 0 => $file_name ]);
+ }
+ $file_dialog->destroy;
+ return;
+ }
}
}
-sub list_remove {
- my ( $widget, $list ) = @_;
- my @to_remove;
- push @to_remove, $list->child_position($_) foreach ( $list->selection );
- splice @install, $_, 1 foreach ( reverse sort @to_remove );
- $list->remove_items( $list->selection );
-}
-
-sub advanced_install {
- my $scrolled_window;
- my $adv_box;
- $list = new Gtk::List();
- $list->set_selection_mode( -extended );
-
- gtkpack(
- $font_box,
- $adv_box = gtkpack_(
- new Gtk::VBox( 0, 10 ),
- 1,
- gtkpack_( new Gtk::HBox( 0, 4 ), 1, createScrolledWindow($list), ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::HButtonBox, -spread ),
- gtksignal_connect(
- new Gtk::Button( N("Add") ),
- clicked => sub { font_choice() }
- ),
- gtksignal_connect(
- new Gtk::Button( N("Remove Selected") ),
- clicked => \&list_remove,
- $list
- ),
- gtksignal_connect(
- new Gtk::Button( N("Install List") ),
- clicked => sub {
- ${$central_widget}->destroy();
- appli_choice();
- }
- ),
- ),
- )
- );
- $central_widget = \$adv_box;
- $adv_box->show_all();
+sub list_remove() { #- TODO : multi-selection
+ my ($treeStore, $iter) = $list->get_selection->get_selected;
+ return unless $iter;
+ 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 exitdialog() { Gtk3->main_quit }
+
+sub dialog {
+ my ($title, $widgets, $buttons, $o_main_loop, $o_options) = @_;
+ $o_options ||= {};
+ my $dialog = _create_dialog($title, { transient => $::main_window });
+ local $::main_window = $dialog;
+ $dialog->signal_connect(delete_event => \&exitdialog);
+ $dialog->set_size_request(@{$o_options->{size}}) if ref $o_options->{size};
+ gtkpack_($dialog->get_child, @$widgets);
+ gtkpack($dialog->get_action_area, @$buttons) if $buttons;
+ $dialog->show_all;
+ if ($o_main_loop) {
+ gtkflush();
+ $o_main_loop->();
+ } else {
+ Gtk3->main;
+ }
+ $dialog->destroy if $dialog;
+ undef $dialog;
+}
+
+sub advanced_install() {
+ my $button;
+ $model = Gtk3::TreeStore->new("Glib::String");
+ $list = Gtk3::TreeView->new_with_model($model);
+ $list->append_column(Gtk3::TreeViewColumn->new_with_attributes('', Gtk3::CellRendererText->new, 'text' => 0));
+ $list->set_headers_visible(0);
+ $list->get_selection->set_mode('browse');
+ $list->set_rules_hint(1);
+ $model->signal_connect("row-inserted" => sub { $button and $button->set_sensitive(1) });
+ $model->signal_connect("row-deleted" => sub { $button and $button->set_sensitive($model->get_iter_first || 0) });
+
+ dialog(N("Import fonts"),
+ [
+ 0, gtknew('Title2', label => N("Font List")),
+ 1, gtknew('HBox', children => [
+ 1, create_scrolled_window($list),
+ 0, gtknew('VBox', children_tight => [
+ gtksignal_connect(Gtk3::Button->new(N("Add")), clicked => \&font_choice),
+ gtksignal_connect(Gtk3::Button->new(N("Remove")), clicked => \&list_remove),
+ ]),
+ ]),
+ ],
+ [
+ gtksignal_connect(Gtk3::Button->new(N("Cancel")), clicked => \&exitdialog),
+ gtksignal_connect($button = gtkset_sensitive(Gtk3::Button->new(N("Install")), 0),
+ clicked => sub {
+ import_status() if @install;
+ }),
+ ],
+ undef,
+ { size => [ 300, 200 ] },
+ );
}
-sub list_to_remove {
- my @number_to_remove;
- my @files_path = grep( !/fonts/, all($current_path) );
- Gtk->main_iteration while Gtk->events_pending;
- push @number_to_remove,
- $path_list->child_position($_) foreach ( $path_list->selection );
- @uninstall = ();
- push @uninstall,
- $current_path . "/" . $files_path[$_] foreach (@number_to_remove);
- ${$central_widget}->destroy();
+sub list_to_remove() {
+ #my @files_path = grep(!/fonts/, all($current_path)); garbage ?
+ gtkflush();
+ my ($indices) = $left_list->get_selection->get_selected_rows;
+ my (@tux) = @$indices; #- get tree & paths
+ push @uninstall, map { $left_model->get($left_model->get_iter($_), 0) } @tux;
+ #push @uninstall, $current_path . "/" . $files_path[$_] foreach @number_to_remove; garbage ?
show_list_to_remove();
}
-sub show_list_to_remove {
- my $show_box;
- my $show_list = new Gtk::List();
- $show_list->add( gtkshow( new Gtk::ListItem($_) ) ) foreach @uninstall;
- gtkpack(
- $font_box,
- $show_box = gtkpack_(
- new Gtk::VBox( 0, 10 ),
- 1,
- gtkpack_(
- new Gtk::HBox( 0, 4 ),
- 1, createScrolledWindow($show_list)
- ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::HButtonBox, -spread ),
- gtksignal_connect(
- new Gtk::Button( N("click here if you are sure.") ),
- clicked => sub {
- ${$central_widget}->destroy();
- import_status_uninstall();
- }
- ),
- gtksignal_connect(
- new Gtk::Button( N("here if no.") ),
- clicked =>
- sub { ${$central_widget}->destroy(); create_fontsel() }
- ),
- ),
- )
- );
- $central_widget = \$show_box;
- $show_box->show_all();
-}
-
-sub uninstall {
- my $scrolled_window;
- my $scrolled_window2;
- my $uninst_box;
+sub show_list_to_remove() {
+ my $model = Gtk3::TreeStore->new("Glib::String");
+ my $list = Gtk3::TreeView->new_with_model($model);
+ $list->append_column(Gtk3::TreeViewColumn->new_with_attributes('', Gtk3::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 sort @uninstall;
+
+ dialog(N("Warning"),
+ [
+ 0, Gtk3::Label->new(N("Are you sure you want to uninstall the following fonts?")),
+ 1, gtkpack_(Gtk3::HBox->new(0, 4), 1, create_scrolled_window($list)),
+ ],
+ [
+ gtksignal_connect(Gtk3::Button->new(N("Yes")),
+ clicked => sub { import_status_uninstall(); exitdialog() }),
+ gtksignal_connect(Gtk3::Button->new(N("No")),
+ clicked => \&exitdialog
+ ),
+ ],
+ );
+}
+
+sub uninstall() { #- TODO : add item to right list with gtksignal_connect
@install = ();
@installed_fonts_path = ();
list_fontpath();
chk_empty_xfs_path();
- $list_path = new Gtk::List();
- $list_path->set_selection_mode( -extended );
-
- foreach (@installed_fonts_path) {
- my $t = $_;
- $list_path->add(
- gtkshow(
- gtksignal_connect(
- new Gtk::ListItem($t),
- select => sub {
- $current_path = $t;
- $path_list->clear_items( 0, -1 );
- $path_list->append_items(
- map {
- /fonts/
- ? ()
- : gtkshow( new Gtk::ListItem($_) )
- } all($t)
- );
- }
- )
- )
- );
- }
- $list_path->set_selection_mode( -single );
- $path_list = new Gtk::List();
- $path_list->set_selection_mode( -extended );
-
- gtkpack(
- $font_box,
- $uninst_box = gtkpack_(
- new Gtk::VBox( 0, 10 ),
- 1,
- gtkpack_(
- new Gtk::HBox( 0, 4 ), 1,
- createScrolledWindow($list_path), 1,
- createScrolledWindow($path_list)
- ),
- 0,
- gtkadd(
- gtkset_layout( new Gtk::HButtonBox, -spread ),
- gtksignal_connect(
- new Gtk::Button( N("Unselected All") ),
- clicked => sub { $path_list->unselect_all(); }
- ),
- gtksignal_connect(
- new Gtk::Button( N("Selected All") ),
- clicked => sub { $path_list->select_all(); }
- ),
- gtksignal_connect(
- new Gtk::Button( N("Remove List") ),
- clicked => sub { list_to_remove() }
- ),
- ),
- )
- );
- $central_widget = \$uninst_box;
- $uninst_box->show_all();
-}
-
-sub import_status {
- my $table;
- $pbar = new Gtk::ProgressBar;
- $pbar1 = new Gtk::ProgressBar;
- $pbar2 = new Gtk::ProgressBar;
- $pbar3 = new Gtk::ProgressBar;
- gtkpack(
- $font_box,
- $table = create_packtable(
- { col_spacings => 10, row_spacings => 50 },
- [ "", "" ],
- [
- N("Initials tests"), $pbar, $pbar->{label} = new Gtk::Label(' ')
- ],
- [
- N("Copy fonts on your system"), $pbar1,
- $pbar1->{label} = new Gtk::Label(' ')
- ],
- [
- N("Install & convert Fonts"), $pbar2,
- $pbar2->{label} = new Gtk::Label(' ')
- ],
- [
- N("Post Install"), $pbar3, $pbar3->{label} = new Gtk::Label(' ')
- ],
- ),
- );
- $central_widget = \$table;
- $font_box->show_all();
- Gtk->main_iteration while Gtk->events_pending;
- backend_mod();
+
+ #- left part
+ $left_model = Gtk3::TreeStore->new("Glib::String");
+ $left_list = Gtk3::TreeView->new_with_model($left_model);
+ $left_list->append_column(Gtk3::TreeViewColumn->new_with_attributes('', Gtk3::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 sort @installed_fonts_path;
+
+ #- right part
+ $right_model = Gtk3::TreeStore->new("Glib::String");
+ $right_list = Gtk3::TreeView->new_with_model($right_model);
+ $right_list->append_column(Gtk3::TreeViewColumn->new_with_attributes('', Gtk3::CellRendererText->new, 'text' => 0));
+ $right_list->set_headers_visible(0);
+ $right_list->get_selection->set_mode('multiple');
+ $right_list->set_rules_hint(1);
+
+ dialog(N("Uninstall"),
+ [
+ 1, gtkpack_(Gtk3::HBox->new(0, 4),
+ 1, create_scrolled_window($left_list),
+ #1, create_scrolled_window($right_list)
+ ),
+ ],
+ [
+ gtksignal_connect(Gtk3::Button->new(N("Unselect All")),
+ clicked => sub { $left_list->get_selection->unselect_all }
+ ),
+ gtksignal_connect(Gtk3::Button->new(N("Select All")),
+ clicked => sub { $left_list->get_selection->select_all }
+ ),
+ gtksignal_connect(Gtk3::Button->new(N("Remove")), clicked => sub { exitdialog(); list_to_remove() }),
+ gtksignal_connect(Gtk3::Button->new(N("Cancel")), clicked => \&exitdialog),
+ ],
+ undef,
+ { size => [ -1, 300 ] }
+
+ );
+}
+
+sub import_status() {
+ $pbar = Gtk3::ProgressBar->new;
+ $pbar1 = Gtk3::ProgressBar->new;
+ $pbar2 = Gtk3::ProgressBar->new;
+ $pbar3 = Gtk3::ProgressBar->new;
+ dialog(N("Importing fonts"),
+ [
+ 0, 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(' ') ],
+ ),
+ ],
+ [],
+ \&backend_mod,
+ );
}
-sub import_status_uninstall {
- my $table;
- $pbar = new Gtk::ProgressBar;
- $pbar1 = new Gtk::ProgressBar;
- $pbar2 = new Gtk::ProgressBar;
- gtkpack(
- $font_box,
- $table = create_packtable(
- { col_spacings => 10, row_spacings => 50 },
- [ "", "" ],
- [ "", "" ],
- [
- N("Initials tests"), $pbar, $pbar->{label} = new Gtk::Label(' ')
- ],
- [
- N("Remove fonts on your system"), $pbar1,
- $pbar1->{label} = new Gtk::Label(' ')
- ],
- [
- N("Post Uninstall"), $pbar2,
- $pbar2->{label} = new Gtk::Label(' ')
- ],
- ),
- );
- $central_widget = \$table;
- $font_box->show_all();
- Gtk->main_iteration while Gtk->events_pending;
- backend_mod();
+sub import_status_uninstall() {
+ $pbar = Gtk3::ProgressBar->new;
+ $pbar1 = Gtk3::ProgressBar->new;
+ $pbar2 = Gtk3::ProgressBar->new;
+ dialog(N("Removing fonts"),
+ [
+ 0, 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(' ') ],
+ ),
+ ],
+ [],
+ \&backend_mod,
+ );
}
sub progress {
- my ( $progressbar, $incr, $label_text ) = @_;
- my ($new_val) = $progressbar->get_current_percentage;
- $new_val += $incr;
- if ( $new_val > 1 ) { $new_val = 1 }
- $progressbar->update($new_val);
- $progressbar->{label}->set($label_text);
- Gtk->main_iteration while Gtk->events_pending;
+ my ($progressbar, $incr, $label_text) = @_;
+ $progressbar->set_fraction(min(1, $progressbar->get_fraction + $incr));
+ $progressbar->set_text($label_text);
+ gtkflush();
}
+sub interactive_progress {
+ $interactive and progress(@_);
+}