#!/usr/bin/perl -w
################################################################################
# Mandrake First Time Wizard                                                   #
#                                                                              #
# Copyright (C) 2001 MandrakeSoft - Daouda Lo <daouda@mandrakesoft.com>        #
#                                                                              #
# This program is free software; you can redistribute it and/or modify         #
# it under the terms of the GNU General Public License Version 2 as            #
# published by the Free Software Foundation.                                   #
#                                                                              #
# 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.   #
################################################################################

use POSIX;
use Gtk;
use Sys::Hostname;
use lib qw(/usr/lib/libDrakX);
use interactive;
use Config;
init Gtk;
Gtk->set_locale;
use MDK::Common;
use c;

#-------------------------------------------------------------
# i18n routines
# IMPORTANT: next two routines have to be redefined here to
#         get correct namespace (drakfw instead of libDrakX)
#         (This version is now UTF8 compliant - Sg 2001-08-31)
#-------------------------------------------------------------

sub _ {
    my $s = shift @_; my $t = translate($s);
    sprintf $t, @_;
}

sub translate {
    my ($s) = @_;
    $s ? c::dgettext('drakfw', $s) : '';
}

my $nb_pages=6;
my $page;
my $sharepath="/usr/share/drakfirsttime";
my $xpm_path="$sharepath/pixmaps";
my $html_link = "http://www.mandrakeexpert.com/index2.php";
my $check_custid;
my $true=1;
my $false=0;

require Gtk;
require Gtk::Gdk::ImlibImage;

Gtk::Gdk::ImlibImage->init;
my $pixmaps='pixmaps';

my @list_country= (
	_("United States"),
	_("Afghanistan"),
	_("Albania"),
	_("Algeria"),
	_("American Samoa"),
	_("Andorra"),
	_("Angola"),
	_("Anguilla"),
	_("Antarctica"),
	_("Antigua and Barbuda"),
	_("Argentina"),
	_("Armenia"),
	_("Aruba"),
	_("Australia"),
	_("Austria"),
	_("Azerbaijan"),
	_("Bahamas"),
	_("Bahrain"),
	_("Bangladesh"),
	_("Barbados"),
	_("Belarus"),
	_("Belgium"),
	_("Belize"),
	_("Benin"),
	_("Bermuda"),
	_("Bhutan"),
	_("Bolivia"),
	_("Bosnia and Herzegovina"),
	_("Botswana"),
	_("Bouvet Island"),
	_("Brazil"),
	_("British Indian Ocean Territory"),
	_("Brunei Darussalam"),
	_("Bulgaria"),
	_("Burkina Faso"),
	_("Burundi"),
	_("Cambodia"),
	_("Cameroon"),
	_("Canada"),
	_("Cape Verde"),
	_("Cayman Islands"),
	_("Central African Republic"),
	_("Chad"),
	_("Chile"),
	_("China"),
	_("Christmas Island"),
	_("Cocos (Keeling) Islands"),
	_("Colombia"),
	_("Comoros"),
	_("Congo"),
	_("Cook Islands"),
	_("Costa Rica"),
	_("Cote d'Ivoire"),
	_("Croatia"),
	_("Cuba"),
	_("Cyprus"),
	_("Czech Republic"),
	_("Denmark"),
	_("Djibouti"),
	_("Dominica"),
	_("Dominican Republic"),
	_("East Timor"),
	_("Ecuador"),
	_("Egypt"),
	_("El Salvador"),
	_("Equatorial Guinea"),
	_("Eritrea"),
	_("Estonia"),
	_("Ethiopia"),
	_("Falkland Islands (Malvinas)"),
	_("Faroe Islands"),
	_("Fiji"),
	_("Finland"),
	_("France"),
	_("France, Metropolitan"),
	_("French Guiana"),
	_("French Polynesia"),
	_("French Southern Territories"),
	_("Gabon"),
	_("Gambia"),
	_("Georgia"),
	_("Germany"),
	_("Ghana"),
	_("Gibraltar"),
	_("Greece"),
	_("Greenland"),
	_("Grenada"),
	_("Guadeloupe"),
	_("Guam"),
	_("Guatemala"),
	_("Guinea"),
	_("Guinea-Bissau"),
	_("Guyana"),
	_("Haiti"),
	_("Heard Island and McDonald Islands"),
	_("Honduras"),
	_("Hong Kong"),
	_("Hungary"),
	_("Iceland"),
	_("India"),
	_("Indonesia"),
	_("Iran (Islamic Republic of)"),
	_("Iraq"),
	_("Ireland"),
	_("Israel"),
	_("Italy"),
	_("Jamaica"),
	_("Japan"),
	_("Jordan"),
	_("Kazakhstan"),
	_("Kenya"),
	_("Kiribati"),
	_("Korea, Democratic People's Republic of"),
	_("Korea, Republic of"),
	_("Kuwait"),
	_("Kyrgyzstan"),
	_("Lao People's Democratic Republic"),
	_("Latin America"),
	_("Latvia"),
	_("Lebanon"),
	_("Lesotho"),
	_("Liberia"),
	_("Libyan Arab Jamahiriya"),
	_("Liechtenstein"),
	_("Lithuania"),
	_("Luxembourg"),
	_("Macau"),
	_("Macedonia"),
	_("Madagascar"),
	_("Malawi"),
	_("Malaysia"),
	_("Maldives"),
	_("Mali"),
	_("Malta"),
	_("Marshall Islands"),
	_("Martinique"),
	_("Mauritania"),
	_("Mauritius"),
	_("Mayotte"),
	_("Mexico"),
	_("Micronesia (Federated States of)"),
	_("Moldova"),
	_("Monaco"),
	_("Mongolia"),
	_("Montserrat"),
	_("Morocco"),
	_("Mozambique"),
	_("Myanmar"),
	_("Namibia"),
	_("Nauru"),
	_("Nepal"),
	_("Netherlands"),
	_("Netherlands Antilles"),
	_("New Caledonia"),
	_("New Zealand"),
	_("Nicaragua"),
	_("Niger"),
	_("Nigeria"),
	_("Niue"),
	_("Norfolk Island"),
	_("Northern Mariana Islands"),
	_("Norway"),
	_("Oman"),
	_("Pakistan"),
	_("Palau"),
	_("Panama"),
	_("Papua New Guinea"),
	_("Paraguay"),
	_("Peru"),
	_("Philippines"),
	_("Pitcairn"),
	_("Poland"),
	_("Portugal"),
	_("Puerto Rico"),
	_("Qatar"),
	_("Reunion"),
	_("Romania"),
	_("Russian Federation"),
	_("Rwanda"),
	_("Saint Helena"),
	_("Saint Kitts and Nevis"),
	_("Saint Lucia"),
	_("Saint Pierre and Miquelon"),
	_("Saint Vincent and the Grenadines"),
	_("Samoa"),
	_("San Marino"),
	_("Sao Tome and Principe"),
	_("Saudi Arabia"),
	_("Senegal"),
	_("Seychelles"),
	_("Sierra Leone"),
	_("Singapore"),
	_("Slovakia"),
	_("Slovenia"),
	_("Solomon Islands"),
	_("Somalia"),
	_("South Africa"),
	_("South Georgia and the South Sandwich Island"),
	_("Spain"),
	_("Sri Lanka"),
	_("Sudan"),
	_("Suriname"),
	_("Svalbard and Jan Mayen Islands"),
	_("Swaziland"),
	_("Sweden"),
	_("Switzerland"),
	_("Syrian Arab Republic"),
	_("Taiwan, Republic of China"),
	_("Tajikistan"),
	_("Tanzania, United Republic of"),
	_("Thailand"),
	_("Togo"),
	_("Tokelau"),
	_("Tonga"),
	_("Trinidad and Tobago"),
	_("Tunisia"),
	_("Turkey"),
	_("Turkmenistan"),
	_("Turks and Caicos Islands"),
	_("Tuvalu"),
	_("Uganda"),
	_("Ukraine"),
	_("United Arab Emirates"),
	_("United Kingdom"),
	_("United States Minor Outlying Islands"),
	_("Uruguay"),
	_("Uzbekistan"),
	_("Vanuatu"),
	_("Vatican City State (Holy See)"),
	_("Venezuela"),
	_("Viet Nam"),
	_("Virgin Islands (British)"),
	_("Virgin Islands (U.S.)"),
	_("Wallis and Futuna Islands"),
	_("Western Sahara"),
	_("Yemen"),
	_("Yugoslavia"),
	_("Zaire"),
	_("Zambia"),
	_("Zimbabwe")
);

my @list_states=(
	_("Non US/Canada"),
	_("Alabama"),
	_("Alaska"),
	_("Arizona"),
	_("Arkansas"),
	_("California"),
	_("Colorado"),
	_("Connecticut"),
	_("Delaware"),
	_("District of Columbia"),
	_("Florida"),
	_("Georgia"),
	_("Hawaii"),
	_("Idaho"),
	_("Illinois"),
	_("Indiana"),
	_("Iowa"),
	_("Kansas"),
	_("Kentucky"),
	_("Louisiana"),
	_("Maine"),
	_("Maryland"),
	_("Massachusetts"),
	_("Michigan"),
	_("Minnesota"),
	_("Mississippi"),
	_("Missouri"),
	_("Montana"),
	_("Nebraska"),
	_("Nevada"),
	_("New Hampshire"),
	_("New Jersey"),
	_("New Mexico"),
	_("New York"),
	_("North Carolina"),
	_("North Dakota"),
	_("Ohio"),
	_("Oklahoma"),
	_("Oregon"),
	_("Pennsylvania"),
	_("Rhode Island"),
	_("South Carolina"),
	_("South Dakota"),
	_("Tennessee"),
	_("Texas"),
	_("Utah"),
	_("Vermont"),
	_("Virginia"),
	_("Washington"),
	_("West Virginia"),
	_("Wisconsin"),
	_("Wyoming"),
	_("American Samoa"),
	_("Armed Forces(AA)"),
	_("Armed Forces(AE)"),
	_("Armed Forces(AP)"),
	_("Guam"),
	_("Marshall Islands"),
	_("Micronesia"),
	_("Northern Marianas"),
	_("Palau"),
	_("Puerto Rico"),
	_("Trust Territories"),
	_("Virgin Islands"),
	_("Alberta"),
	_("British Columbia"),
	_("Manitoba"),
	_("New Brunswick"),
	_("Newfoundland"),
	_("Northwest Territory"),
	_("Nova Scotia"),
	_("Ontario"),
	_("Prince Edward Island"),
	_("Quebec"),
	_("Saskatchewan"),
	_("Yukon Territory")
);

my $Main_Window = new Gtk::Window -toplevel;
$Main_Window->set_policy($false,$false,$true);
$Main_Window->set_position( 1 );
$Main_Window->border_width( 5 );
$Main_Window->set_title(_("First Time Wizard"));
$Main_Window->set_usize(540, 430);
$Main_Window->realize();
$Main_Window->signal_connect( "delete_event", \&gtk_main_quit);

my $Button_Next= new Gtk::Button(_("  Next  > "));
my $Button_End= new Gtk::Button(_("  Finish "));
my $Button_SkipWiz= new Gtk::Button(_(" Cancel "));
my $Button_Prev= new Gtk::Button(_(" <  Back  "));
my $notebook_global = new Gtk::Notebook;
$Button_End->show();
$notebook_global->set_show_border($false);
$notebook_global->set_show_tabs($false);
$page=$notebook_global->get_current_page();
my $vbox = new Gtk::VBox(0,0);
$Main_Window->add($vbox);
$vbox->pack_start($notebook_global,1,1,0);
$vbox->pack_start(new Gtk::HSeparator, 0, 0, 1);
my $hbox= new Gtk::HBox(0,5);
$vbox->pack_start($hbox, 0, 0, 1);
$hbox->pack_end($Button_Next, 0, 1, 0);
$hbox->pack_end($Button_Prev, 0, 1, 0);
$hbox->pack_start($Button_SkipWiz, 0, 1, 0);
my $first_name =new Gtk::Entry();
my $last_name  =new Gtk::Entry();
my $email=new Gtk::Entry();
$email->set_usize(250,undef);
my $company=new Gtk::Entry();
my $job_title=new Gtk::Entry();
my $address1=new Gtk::Entry();
$address1->set_usize(300,undef);
my $city=new Gtk::Entry();
my $zip_code=new Gtk::Entry();
my $state_prov=new Gtk::Combo;
$state_prov->set_popdown_strings(sort @list_states );
my $country=new Gtk::Combo;
$country->set_popdown_strings(sort @list_country);
my $phone=new Gtk::Entry();
my $fax=new Gtk::Entry();
my @wm;
my $desktop_combo=new Gtk::Combo();
$desktop_combo->set_popdown_strings(get_wm());
$desktop_combo->set_use_arrows_always( $true); 
my $kde1_rad= new Gtk::RadioButton _("Default KDE");
my $kde2_rad= new Gtk::RadioButton _("KDE Redmond"), $kde1_rad ;
my $kde3_rad= new Gtk::RadioButton _("KDE Platinum"), $kde1_rad;
my $kde4_rad= new Gtk::RadioButton _("KDE Sunshine"), $kde1_rad;
my $gnome_rad1= new Gtk::RadioButton _("Default Gnome"), $kde1_rad;
my $gnome_rad2= new Gtk::RadioButton _("Cheese Sawtech"), $kde1_rad;
my $gnome_rad3= new Gtk::RadioButton _("Brushed Gtk"), $kde1_rad;
my $gnome_rad4= new Gtk::RadioButton _("Helix"), $kde1_rad;
my $checked= new Gtk::RadioButton;
my $drop_mail=new Gtk::Combo();
$drop_mail->set_usize(40,undef);
$drop_mail->set_popdown_strings(get_mail());
my $login=new Gtk::Entry();
my $serv_type=new Gtk::Combo();
$serv_type->set_usize(40,undef);
$serv_type->set_popdown_strings("POP","IMAP");
my $mail_address=new Gtk::Entry();
my $ou_serv_name=new Gtk::Entry();
my $in_serv_name=new Gtk::Entry();
my $news_serv=new Gtk::Entry();

my %actions = ( 
		0 =>\&t,
		1 =>\&set_themes,
		3 =>\&set_personal_info,
		4 =>\&set_mail,
		5 =>\&start_wm,
		);

init_ui();

$Main_Window->show_all;

Gtk->main_iteration while Gtk->events_pending;
Gtk->main;

sub init_ui {
    step_wizard();
    if ($page <= 0) {
	$Button_Prev->set_sensitive(0);
    }
    $Button_Next->signal_connect(clicked =>\&on_next_clicked);
    $Button_Prev->signal_connect(clicked =>\&on_prev_clicked);
    $Button_SkipWiz->signal_connect( clicked => \&start_wm);
    $Button_End->signal_connect(clicked =>\&start_wm);
}

sub on_next_clicked {
    $page=$notebook_global->get_current_page();
    print "$page\n" ;
    $Button_Prev->set_sensitive(1);
    if ( $actions{$page} ) {
	$actions{$page}->();
    } else {
	$notebook_global->next_page();
    }
    $page=$notebook_global->get_current_page();
    print "$page\n" ;
    # change "Next" to "Finish" in the last page
    if ($page == $nb_pages - 1) {
	$hbox->remove($Button_Prev);
	$hbox->remove($Button_Next);
	$hbox->pack_end($Button_End, 0, 1, 0);
	$hbox->pack_end($Button_Prev, 0, 1, 0);
    }
}

sub on_prev_clicked {
    $page=$notebook_global->get_current_page();
    if ($page==1) {
	$Button_Prev->set_sensitive(0);
    }
    $notebook_global->prev_page();
    if ($page == $nb_pages - 1) {
	$hbox->remove($Button_Prev);
	$hbox->remove($Button_End);
	$hbox->pack_end($Button_Next, 0, 1, 0);
	$hbox->pack_end($Button_Prev, 0, 1, 0);
    }
}

sub step_wizard {
    gtkset_mousecursor_normal();
    my $vbox_welc= new Gtk::VBox(0,0);
    write_on_pixmaps($vbox_welc,"welcome.png",_("Welcome to First Time Wizard"),540,100);
    my $label_welc = new Gtk::Label(_("This is the Mandrake First Time Wizard. This assistant will help you configure\nthe basic setup of your desktop in very few steps.\n If you have an internet connection you'll be able to register for \nMandrake services.\n\nIf you don't want to use this wizard you can press Cancel right now \n and you'll be logged into the default environment\n"));
    $label_welc->set_uposition(20,150);
    $vbox_welc->pack_start($label_welc,0,0,1);
    $notebook_global->append_page($vbox_welc,new Gtk::Label _("welcome"));
    my $vbox_app = new Gtk::VBox(0,0);
    write_on_pixmaps($vbox_app,"appearence.png",_("Desktop Appearence"),540,100);
    $vbox_app->pack_start(new Gtk::Label(_("\nNow you can choose your Desktop and the theme you want to be set\n")), 0,0,1); 
    my ($theme_kde1, $tk1_mask) = gtkcreate_png("$xpm_path/theme_kde_default.png");
    my ($theme_kde2, $tk2_mask) = gtkcreate_png("$xpm_path/theme_kde_redmond.png");
    my ($theme_kde3, $tk3_mask) = gtkcreate_png("$xpm_path/theme_kde_platinum.png");
    my ($theme_kde4, $tk4_mask) = gtkcreate_png("$xpm_path/theme_kde_sunshine.png");
    my ($theme_gnome1, $tg1_mask) = gtkcreate_png("$xpm_path/theme_gnome_default.png");
    my ($theme_gnome2, $tg2_mask) = gtkcreate_png("$xpm_path/theme_gnome_Cheese_Sawtech.png");
    my ($theme_gnome3, $tg3_mask) = gtkcreate_png("$xpm_path/theme_gnome_brushedgtk.png");
    my ($theme_gnome4, $tg4_mask) = gtkcreate_png("$xpm_path/theme_gnome_Helix.png");
    my $pixmap=new Gtk::Pixmap($theme_kde1,$tk1_mask);
    gtkpack__(my $hbox_app=new Gtk::HBox(0,0),
	      gtkpack__(new Gtk::VBox(0,5),
			$desktop_combo,
			gtkadd(new Gtk::Frame(_("Themes")),
			       gtkpack__( new Gtk::VBox(0,0),
					  gtksignal_connect ($kde1_rad,clicked => sub{$pixmap->set($theme_kde1, $tk1_mask);$checked=$kde1_rad}),
					  gtksignal_connect ($kde2_rad,clicked => sub{$pixmap->set($theme_kde2, $tk2_mask);$checked=$kde2_rad}),
					  gtksignal_connect ($kde3_rad,clicked => sub{$pixmap->set($theme_kde3, $tk3_mask);$checked=$kde3_rad}),
					  gtksignal_connect ($kde4_rad,clicked => sub{$pixmap->set($theme_kde4, $tk4_mask);$checked=$kde4_rad}),
					  gtksignal_connect ($gnome_rad1,clicked => sub{$pixmap->set($theme_gnome1, $tg1_mask);$checked=$gnome_rad1;}),
					  gtksignal_connect ($gnome_rad2,clicked => sub{$pixmap->set($theme_gnome2, $tg2_mask);$checked=$gnome_rad2;}),
					  gtksignal_connect ($gnome_rad3,clicked => sub{$pixmap->set($theme_gnome3, $tg3_mask);$checked=$gnome_rad3;}),
					  gtksignal_connect ($gnome_rad4,clicked => sub{$pixmap->set($theme_gnome4, $tg4_mask);$checked=$gnome_rad4;}),
					  $lab1=new Gtk::Label(_("No themes available")),
					  $lab2=new Gtk::Label(_("Select desktop first")),
					  ),
			       ),
			),
	      gtkpack__($pixmap),
	      );
    $desktop_combo->entry->signal_connect ('changed', sub { 
								if ($desktop_combo->entry->get_text() eq 'KDE') { 
									set_bg_themes(0);
								} elsif ($desktop_combo->entry->get_text() eq 'Gnome'){
									set_bg_themes(1);
								    } else {
								    set_bg_themes(2);
								}
							    });
    $vbox_app->pack_start($hbox_app,0,0,1);
    $notebook_global->append_page($vbox_app,new Gtk::Label("appearence"));
    my $vbox_priv=new Gtk::VBox(0,0);
    write_on_pixmaps($vbox_priv,"privacy.png",_("Mandrake Privacy Policy"),540,100);
    get_on_privacy($vbox_priv);
    $notebook_global->append_page($vbox_priv,new Gtk::Label("privacy"));
    my $vbox_id = new Gtk::VBox(0,2);
    write_on_pixmaps($vbox_id,"identity.png",_("Personal Identity"),540,100);
    map {
	pack_table_identity($vbox_id,$_->[0],$_->[1],$_->[2],$_->[3]);
    } ([_("First Name:"),_("Last Name:"),$first_name,$last_name], [_("Job title:"),_("Company:"), $job_title, $company]); 
    map {
	pack_box_identity($vbox_id,$_->[0],$_->[1],$->[2]);
    } ([_("Email:"),$email,40], 
       [_("Address:"),$address1,10], [_("Zip Code:"),$zip_code,10], 
       [_("State/Province:"),$state_prov,30],[_("Country:"),$country,40],);
    $state_prov->entry->set_text(_("Non US/Canada"));
    if ($country->entry->get_text() eq _("United States")) {
	$state_prov->set_sensitive(1);
    }else {
	$state_prov->set_sensitive(0);
    }
    $country->entry->signal_connect ('changed', sub {
	if ($country->entry->get_text() eq _("United States") || $country->entry->get_text() eq _("Canada"),) {
	    $state_prov->set_sensitive(1);
	}else {
	    $state_prov->set_sensitive(0);
	}
	});
    pack_table_identity($vbox_id,_("Phone:"),_("Fax:"),$phone,$fax);
    $notebook_global->append_page($vbox_id,new Gtk::Label("identity"));
    my $vbox_mail=new Gtk::VBox(0,0);
    write_on_pixmaps($vbox_mail,"mailnews.png",_("Mail configuration"),540,100);
    $vbox_mail->pack_start(new Gtk::Label(_("\nYou can configure your client mailer there")), 0,0,1);
    my $mail_frame=new Gtk::Frame(_("Mail Parameters"));
    $vbox_mail->pack_start($mail_frame,1,0,1);
    my $news_frame= new Gtk::Frame(_("News Parameters"));
    $vbox_mail->pack_start($news_frame,1,0,1);
    my $vbox_m1 = new Gtk::VBox(0,10);
    my $vbox_m2 = new Gtk::VBox(0,10);
    map {
	pack_table_identity($vbox_m1,$_->[0],$_->[1],$_->[2],$_->[3]);
    } ([_("Mail client:"),_("Server type:"),$drop_mail,$serv_type]); 
    map {
	pack_box_identity($vbox_m1,$_->[0],$_->[1],$->[2]);
    } ([_("Mail Address:"),$mail_address,40],[_("Incoming Server name(POP/IMAP):"),$in_serv_name,10], 
       [_("Outgoing server name(SMTP):"),$ou_serv_name,30],[_("Login:"),$login,40],);
    $mail_frame->add($vbox_m1);
        map {
	pack_box_identity($vbox_m2,$_->[0],$_->[1],$->[2]);
    } ([_("News Server:"),$news_serv,40]);
    $news_frame->add($vbox_m2);
    $notebook_global->append_page($vbox_mail,new Gtk::Label("mail"));
    my $vbox_club = new Gtk::VBox(0,0);
    write_on_pixmaps($vbox_club,"welcome.png",_(""),540,100);
    my $label_club = new Gtk::Label(_("Congratulations for using Mandrake Linux\n The ideal Operating System for beginers and experts. We hope that \nit will give you complete satisfaction.\n\n MandrakeOnline: Discover also MandrakeSoft's new online services to easily \nkeep your system up to date with security and updated softwares.\n"));
    $label_club->set_uposition(20,150);
    $vbox_club->pack_start($label_club,0,0,1);
    $notebook_global->append_page($vbox_club,new Gtk::Label("club"));
}

sub check_network () {
    $is_network=gethostbyname("mandrakesoft.com") ? 1 : 0;
    if ($is_network) {
	`netscape $html_link` if -e "/usr/bin/netscape";
	$notebook_global->next_page();
    } else {
	system("/usr/sbin/draknet");
    }	
}

sub t {
    $kde1_rad->hide();$kde2_rad->hide();$kde3_rad->hide();$kde4_rad->hide();$gnome_rad1->hide(); $gnome_rad2->hide(); $gnome_rad3->hide(); $gnome_rad4->hide(); $lab1->hide();$lab2->show();
    $notebook_global->next_page();
}

sub set_personal_info (){
    my ($fn,$ln,$ea,$jt,$add,,$comp,$zc,$sp,$count,$tel);
    $fn=$first_name->get_chars(0,-1);$ln=$last_name->get_chars(0,-1);
    $ea=$email->get_chars(0,-1); $comp=$company->get_chars(0,-1);
    $jt=$job_title->get_chars(0,-1); $add=$address1->get_chars(0,-1);
    $zc=$zip_code->get_chars(0,-1);  $sp=$state_prov->entry->get_text();
    $count=$country->entry->get_text(); $tel=$phone->get_chars(0,-1);
    $fx=$fax->get_chars(0,-1);
    if ($fn ne '') {
    output_p "$ENV{HOME}/.info_perso",
qq(
FIRSTNAME=$fn
LASTNAME=$ln
MAIL=$ea
COMPANY=$comp
JOBTITLE=$jt
ADDRESS=$add
ZIPCODE=$zc
STATEPROV=$sp
COUNTRY=$count
TEL=$tel 
FAX=$fx
  );
}
    $notebook_global->next_page();   
}

sub set_mail () {
    my ($mailer,$mail_type,$fn,$ln,$ea,$isn,$osn,$l,$comp,$sendmail,$ns);
    $mailer=$drop_mail->entry->get_text();
    $mail_type=$serv_type->entry->get_text();
    $fn=$first_name->get_chars(0,-1);
    $ln=$last_name->get_chars(0,-1);
    $ea=$mail_address->get_chars(0,-1);
    $isn=$in_serv_name->get_chars(0,-1);
    $osn=$ou_serv_name->get_chars(0,-1);
    $l=$login->get_chars(0,-1);
    $comp=$company->get_chars(0,-1);
    $ns=$news_serv->get_chars(0,-1);
    if ($mailer eq "KMail" ) {
	if ($mail_type eq "POP") {
	    output_p "$ENV{HOME}/.kde/share/config/kmailrc",
qq([Account 1]
Folder=inbox
Name=$fn $ln
Type=pop
host=$isn
login=$l
passwd=
port=110

[General]
accounts=1

[Identity]
Email Address=$ea
Name=$fn $ln
Organization=$comp

[sending mail]
Immmediate=true
Mailer=/usr/sbin/sendmail
Method=smtp
Smtp Host=$osn
Smtp Port=25
);

} elsif ($mail_type eq "IMAP") {
    output_p "$ENV{HOME}/.kde/share/config/kmailrc",
qq([Account 1]
Folder=inbox
Name=$fn $ln
Type=imap
host=$isn
login=$l
passwd=
port=143
prefix=/

[Folder-$fn $ln.imap]
Compactable=true

[General]
accounts=1

[Identity}
Email Address=$ea
Name=$fn $ln
Organization=$comp

[sending mail]
Immediate=true
Mailer=/usr/sbin/sendmail
Method=smtp
Smtp Host=$osn
Smtp Port=25
4    );
}
if ($ns ne '' && -e "/usr/bin/knode") {
    output_p "$ENV{HOME}/.kde/share/apps/knode/nntp.1/info",
qq(
Email=$ea
Name=$fn $ln
Org=$comp
id=1
name=_("My news")
needsLogon=true
pass=
port=119
server=$ns
user=$l
    );
my $vers_knode=`knode -v |awk -F: '/^KNode/'|cut -d: f2`;
    output_p "$ENV{HOME}/.kde/share/config/knoderc",
qq(
[GENERAL]
Version=$vers_knode

[IDENTITY]
Email=$ea
Name=$fn $ln
Org=$comp
    );
}
	}elsif ($mailer eq _("Netscape")) {
		if ($mail_type eq "POP") { 
     output_p "$ENV{HOME}/.netscape/preferences.js",
qq(// Netscape User Preferences
// This is a generated file!  Do not edit.

user_pref("mail.identity.defaultdomain", "$isn");
user_pref("mail.identity.organization", "$comp");
user_pref("mail.identity.useremail", "$ea");
user_pref("mail.identity.username", "$fn $ln");
user_pref("mail.imap.root_dir", "$ENV{HOME}/ns_imap/");
user_pref("mail.pop_name", "$l");
user_pref("network.hosts.pop_server", "$isn");
user_pref("network.hosts.smtp_server", "$osn");
);
		    
		}elsif($mail_type eq "IMAP") {
    output_p "$ENV{HOME}/.netscape/preferences.js",
qq(// Netscape User Preferences
// This is a generated file! Do not edit.

user_pref("mail.identity.defaultdomain", "$isn");
user_pref("mail.identity.useremail", "$ea");
user_pref("mail.identity.organization", "$comp");
user_pref("mail.identity.username", "$fn $ln");
user_pref("mail.imap.root_dir", "$ENV{HOME}/ns_imap/");
user_pref("mail.imap.server.mandrakesoft.com.userName", "$l");
user_pref("mail.pop_name", "$l");
user_pref("mail.server_type", 1);
user_pref("network.hosts.imap_servers", "$isn");
user_pref("network.hosts.pop_server", "$isn");
user_pref("network.hosts.smtp_server", "$osn");
   );
}
if ($ns ne '') {
    output_p "$ENV{HOME}/.netscape/xover-cache/host-$ns/hostinfo.dat",
qq(# Netscape newshost information file.
# This is a generated file!  Do not edit.

version=1
newsrcname=$ns

begingroups
);
	    }
}
    check_network();
}

sub start_wm {
    my ($wm);
    chomp($wm=$desktop_combo->entry->get_text());
    if ($wm ne _("Choose desktop")) {
	output "$ENV{HOME}/.wmrc",
qq($wm
);
	output_p "$ENV{HOME}/.gnome/gdm",
qq(
[session]
last=$wm
    );
    Gtk->main_iteration while Gtk->events_pending;
    main_quit Gtk; 
    exec("/etc/X11/Xsession","$wm");
} else {
    main_quit Gtk; 
    exec("/etc/X11/Xsession","default");
}
}

sub set_themes (){
    my %themes_kde = (
		      _("Default KDE")  => "default.themerc",
		      _("KDE Redmond")  => "qtwindows.themerc",
		      _("KDE Platinum") => "qtplatinum.themerc",
		      _("KDE Sunshine") => "qtmotif.themerc",
		      );
    my %themes_gnome =(
		       _("Default Gnome") => "Mandrake",
		       _("Cheese Sawtech") => "Cheese",
		       _("Brushed Gtk") => "Brushed",
		       _("Helix") => "HeliX",
		       );
    if ($desktop_combo->entry->get_text() eq 'KDE') {
	my $c=$checked->child->get();
	cp_af("/usr/share/apps/kstyle/themes/$themes_kde{$c}","$ENV{HOME}/.kde/share/config/kstylerc");
	if ($c eq _("Default KDE")){
	    output "$ENV{HOME}/.gtkrc",
qq(# -- THEME AUTO-WRITTEN DO NOT EDIT
include "/usr/share/themes/Mandrake/gtk/gtkrc"

include "$ENV{HOME}/.gtkrc.mine"

# -- THEME AUTO-WRITTEN DO NOT EDIT
);
	}elsif ($c eq _("KDE Redmond")){
	    output_p "$ENV{HOME}/.kde/share/config/kdeglobals",
qq([General]
background=197,194,197
buttonBackground=197,194,197
buttonForeground=0,0,0
foreground=0,0,0
linkColor=0,0,192
selectBackground=10,95,137
selectForeground=255,255,255
visitedLinkColor=128,0,128
windowBackground=255,255,255
windowForeground=0,0,0

[KDE]
AntiAliasing=false
EffectAnimateCombo=false
EffectFadeMenu=false
EffectFadeTooltip=false
SingleClick=true
colorScheme=/usr/share/apps/kdisplay/color-schemes/Windows2000.kcsrc
contrast=7
currentTheme=/usr/share/apps/kstyle/themes/qtwindows.themerc
macStyle=false
widgetStyle=Windows 95
widgetStyleName=Qt Windows

[WM]
activeBackground=0,0,131
activeBlend=197,194,197
activeFont=helvetica,12,5,iso8859-15,75,0
activeForeground=255,255,255
activeTitleBtnBg=197,194,197
inactiveBackground=131,129,131
inactiveBlend=197,194,197
inactiveForeground=0,0,0
inactiveTitleBtnBg=197,194,197
   );
	}elsif ($c eq _("KDE Platinum")){
	    output_p "$ENV{HOME}/.kde/share/config/kdeglobals",
qq([General]
background=230,222,220
buttonBackground=228,228,228
buttonForeground=0,0,0
foreground=0,0,0
linkColor=0,0,192
selectBackground=10,95,137
selectForeground=255,255,255
visitedLinkColor=128,0,128
windowBackground=255,255,255
windowForeground=0,0,0

[KDE]
AntiAliasing=false
EffectAnimateCombo=false
EffectFadeMenu=false
EffectFadeTooltip=false
SingleClick=true
colorScheme=/usr/share/apps/kdisplay/color-schemes/EveX.kcsrc
contrast=7
currentTheme=/usr/share/apps/kstyle/themes/qtplatinum.themerc
macStyle=false
widgetStyle=Platinum
widgetStyleName=Qt Platinum

[WM]
activeBackground=233,233,233
activeBlend=233,233,233
activeForeground=2,2,2
activeTitleBtnBg=220,220,220
inactiveBackground=150,167,202
inactiveBlend=157,176,208
inactiveForeground=93,112,145
inactiveTitleBtnBg=220,220,220
   );
	}elsif ($c eq _("KDE Sunshine")){
	    output_p "$ENV{HOME}/.kde/share/config/kdeglobals",
qq([General]
background=174,178,195
buttonBackground=174,178,195
buttonForeground=0,0,0
foreground=0,0,0
linkColor=0,0,255
selectBackground=113,139,165
selectForeground=255,255,255
visitedLinkColor=192,255,255
windowBackground=147,151,165
windowForeground=0,0,0

[KDE]
AntiAliasing=false
EffectAnimateCombo=false
EffectFadeMenu=false
EffectFadeTooltip=false
SingleClick=true
colorScheme=/usr/share/apps/kdisplay/color-schemes/SolarisCDE.kcsrc
contrast=7
currentTheme=/usr/share/apps/kstyle/themes/qtmotif.themerc
macStyle=false
widgetStyle=Motif
widgetStyleName=Qt Motif

[WM]
activeBackground=178,77,122
activeBlend=174,178,195
activeFont=helvetica,12,5,iso8859-15,75,0
activeForeground=255,255,255
activeTitleBtnBg=174,178,195
inactiveBackground=174,178,195
inactiveBlend=174,178,195
inactiveForeground=0,0,0
inactiveTitleBtnBg=174,178,195
    );
} 
    }elsif ($desktop_combo->entry->get_text() eq 'Gnome') {
	my $c=$checked->child->get();
	output_p "$ENV{HOME}/.gnome/theme-switcher-capplet",
qq(
[settings]
auto=true
theme=$themes_gnome{$c};
);
       output "$ENV{HOME}/.gtkrc",
qq(# -- THEME AUTO-WRITTEN DO NOT EDIT
include "/usr/share/themes/$themes_gnome{$c}/gtk/gtkrc"

include "$ENV{HOME}/.gtkrc.mine"

# -- THEME AUTO-WRITTEN DO NOT EDIT
);
      }else {
	output "$ENV{HOME}/.gtkrc",
qq(# -- THEME AUTO-WRITTEN DO NOT EDIT
include "/usr/share/themes/Mandrake/gtk/gtkrc"

include "$ENV{HOME}/.gtkrc.mine"

# -- THEME AUTO-WRITTEN DO NOT EDIT
);
    }
$notebook_global->next_page();
}

sub gtkadd($@) {
    my $w = shift;
    foreach (@_) {
	my $l = $_;
	ref $l or $l = new Gtk::Label($l);
	$w->add($l);
	$l->show;
    }
    $w
}

sub gtkpack__($@) {
    my $box = shift;
    gtkpack_($box, map {; 0, $_ } @_);
}

sub gtkpack_($@) {
    my $box = shift;
    for (my $i = 0; $i < @_; $i += 2) {
	my $l = $_[$i + 1];
	ref $l or $l = new Gtk::Label($l);
	$box->pack_start($l, $_[$i], 1, 0);
	$l->show;
    }
    $box
}

sub gtkpack($@) {
    my $box = shift;
    gtkpack_($box, map {; 1, $_ } @_);
}

sub pack_box_identity {
    my ($vbox,$label,$entry,$spacing)=@_;
    my $table = new Gtk::Table( 1, 2, $true );
    $table->set_col_spacings($spacing);
    my $Label_wg=new Gtk::Label($label);
    $Label_wg->set_justify('left');
    $table->attach_defaults( $Label_wg, 0, 1, 0, 1);
    $table->attach_defaults( $entry, 1, 2, 0, 1 );
    $vbox->pack_start($table,$true,$true,1);
}

sub pack_table_identity {
    my ($vbox,$label1,$label2,$entry1,$entry2)=@_;
    my $Label_wg1=new Gtk::Label($label1);
    my $Label_wg2=new Gtk::Label($label2);
    my $table = new Gtk::Table( 1, 4, 0);
    $table->set_col_spacings(20);
    $table->attach_defaults($Label_wg1,0,1,0,1);
    $table->attach_defaults($entry1,1,2,0,1);
    $table->attach_defaults($Label_wg2,2,3,0,1);
    $table->attach_defaults($entry2,3,4,0,1);
    $vbox->pack_start($table,$true,$true,0);
}
 
sub splash_warning { 
    my $label = @_;
    my $win_about = new Gtk::Dialog();
    $win_about->set_position(1);
    
    my $bbox1 = new Gtk::HButtonBox;
    $win_about->action_area->pack_start($bbox1,0,0,0);
    
    my $button = new Gtk::Button(_("Close"));
    $button->signal_connect_object('clicked',$Main_Window => 'destroy');
    $bbox1->add($button);
    
    my $lab = new Gtk::Label($label);
    my $style1 = new Gtk::Style;
    $win_about->vbox->pack_start($lab, 1, 1, 0);

    $win_about->show_all();
    $win_about->set_modal(1);
}

sub gtksignal_connect($@) {
    my $w = shift;
    $w->signal_connect(@_);
    $w
}

sub load_text {
    my $line;
    my ($text,$file)=@_;
    open( FILE, $file ) or die "load_text: missing file $file";
    foreach $line ( <FILE> )
    {
	$text->insert( $fixed_font, undef, undef, $line );
    }
    
    close( FILE );
}

sub get_wm {
    @wm = (split (' ', `/usr/sbin/chksession -l`));
    unshift (@wm, _("Choose desktop"));
    @wm;
}

sub get_mail {
    my @mc;
    push(@mc,_("KMail")) if -e "/usr/bin/kmail";
    push(@mc,_("Netscape")) if -e "/usr/bin/netscape-communicator";
    unshift(@mc, _("None"));
    @mc;
}

sub set_bg_themes {
    my ($choice)=@_;
    my %desk_png= ( "BlackBox" => "bb_desktop.png",
		    "Enlightenment" => "E_desktop.png",
		    "Fvwm1" => "fvwm1_desktop.png",
		    "Fvwm2" => "fvwm2_desktop.png",
		    "IceWM" => "icewm_desktop.png",
		    "WindowMaker" => "wmaker_desktop.png",
		    );
    if($choice==0) {
	$kde1_rad->show();$kde2_rad->show();$kde3_rad->show();$kde4_rad->show();$gnome_rad1->hide();$gnome_rad2->hide();$gnome_rad3->hide();$gnome_rad4->hide();$lab1->hide();$lab2->hide();
	$kde1_rad->set_active( $true );
	$checked=$kde1_rad;
	system("qiv \\\-z $xpm_path/kde_desktop.png");
    } elsif($choice==1) {
	$kde1_rad->hide();$kde2_rad->hide();$kde3_rad->hide();$kde4_rad->hide();$gnome_rad1->show();$gnome_rad2->show();$gnome_rad3->show();$gnome_rad4->show();$lab1->hide();$lab2->hide();
	$gnome_rad1->set_active( $true );
	$checked=$gnome_rad1;
	system("qiv \\\-z $xpm_path/gnome_desktop.png");
    } else {
	$kde1_rad->hide();$kde2_rad->hide();$kde3_rad->hide();$kde4_rad->hide();$gnome_rad1->hide();$gnome_rad2->hide();$gnome_rad3->hide();$gnome_rad4->hide();$lab1->show();$lab2->hide();
	if ($choice==2) {
	    system("qiv \\\-z $xpm_path/$desk_png{$desktop_combo->entry->get_text()}");
	}
    }
}

sub get_on_privacy {
    my ($vbox)=@_;
    my $table=new Gtk::Table( 1, 2, $false );
    my $text=new Gtk::Text(undef,undef);
    $text->set_editable($false);
    $table->attach( $text, 0, 1, 0, 1,
                       [ 'expand', 'shrink', 'fill' ],
                       [ 'expand', 'shrink', 'fill' ],
                       0, 0 );
    my $vscrollbar = new Gtk::VScrollbar( $text->vadj );
    $table->attach( $vscrollbar, 1, 2, 0, 1, 'fill',
                       [ 'expand', 'shrink', 'fill' ], 0, 0 );
    if ($ENV{LANG} eq "fr") {
	load_text($text,"$sharepath/privacy-fr.txt");
    }elsif ($ENV{LANG} eq "de") {
	load_text($text,"$sharepath/privacy-de.txt");
    }elsif ($ENV{LANG} eq "es") {
	load_text($text,"$sharepath/privacy-es.txt");
    }else {
	load_text($text,"$sharepath/privacy.txt");
    }

    $vbox->pack_start( $table, $true, $true, 0 );
    
}    

#sub confirm_quit {
 #   my $window_about = new Gtk::Dialog();
 #   $window_about->set_position(1);
  #  my $bbox1 = new Gtk::HButtonBox;
   # $window_about->action_area->pack_start($bbox1,0,0,0);
#
 #   my $button_cancel = new Gtk::Button(_("Cancel"));
  #  $button_cancel->signal_connect_object("clicked",$window_about => 'destroy');
   # $bbox1->add($button_cancel);
#
 #   my $button_quit = new Gtk::Button(_("Quit"));
  #  $button_quit->signal_connect_object("clicked",\&startwm);
   # $bbox1->add($button_quit);
    #my $label = new Gtk::Label(_("Do you really want to abort the First Time Wizard?\nTo return to the Wizard press 'Cancel'\nTo really quit it press 'Quit'" ));
    #my $style1 = new Gtk::Style;
    #$style1->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--14-*-100-100-p-*-iso8859-*,*-r-*")));
    #$label->set_style($style1); 
    #$window_about->set_title(_("Really abort? - First Time Wizard"));
    #$window_about->vbox->pack_start( $label, 1, 1, 0 );
    #$window_about->show_all();
    #$window_about->set_modal(1);
#}

sub gtk_main_quit {
    print _("Quitting Wizard\n");
    Gtk->main_iteration while Gtk->events_pending;
    main_quit Gtk;
}

sub gtk_widget_hide {
    shift->hide();
}

sub write_on_pixmaps {
    my ($vbox, $pix_name, $step_label, $width, $height)=@_;
    my $darea= new Gtk::DrawingArea();
    $darea->set_usize($width,$height);
    $vbox->pack_start($darea,0,0,0);
    my ($pix1,$pix_mask1) = gtkcreate_png("$xpm_path/$pix_name");
    my ($y1, $x1) = $pix1->get_size;
    my $style= new Gtk::Style;
    $style->font(Gtk::Gdk::Font->fontset_load(_("-adobe-times-bold-r-normal--17-*-100-100-p-*-iso8859-*,*-r-*")));
    my $w = $style->font->string_width(_("Welcome"));
    $darea->signal_connect('expose_event' => sub {
	my $i;
	for ($i=0;$i<($width/$y1);$i++) {
	    $darea->window->draw_pixmap ($darea->style->bg_gc('normal'),
					  $pix1, 0, 0, 0, $y1*$i,
					  $x1 , $y1 );
	    $darea->window->draw_string(
					 $style->font,
					 $darea->style->white_gc,
 					 80+(380-$w)/2, 62,
					 $step_label );
	}
    });
}

sub gtkpng { new Gtk::Pixmap(gtkcreate_png(@_)) }

sub gtkcreate_png {
    my ($f) = @_;
    $f =~ m|.png$| or $f="$f.png";
    if ( $f !~ /\//) { -e "$_/$f" and $f="$_/$f", last foreach $ENV{SHARE_PATH}, "$pixmaps", "pixmaps" }
    my $im = Gtk::Gdk::ImlibImage->load_image($f) or die "gtkcreate_png: missing png file $f";
    $im->render($im->rgb_width, $im->rgb_height);
    ($im->move_image(), $im->move_mask);
}

sub gtkroot {
    Gtk->init;
    Gtk->set_locale;
    Gtk::Gdk::Window->new_foreign(Gtk::Gdk->ROOT_WINDOW);
}

sub gtkset_mousecursor {
    my ($type, $w) = @_;
    ($w || gtkroot())->set_cursor(Gtk::Gdk::Cursor->new($type));
}
sub gtkset_mousecursor_normal { gtkset_mousecursor(68, @_) }
sub gtkset_mousecursor_wait   { gtkset_mousecursor(150, @_) }
