package Uploader::GUI::DlgCommon;
use strict;

sub SetProperties {
    my ($dlg, $properties ) = @_;
	
	map {
        my $ctrl =$dlg->FindWindow($_);
        #printf("ctrl %s : %s\n", $_, $ctrl);		
        if(defined $ctrl){
		# checkbox, static text
		$ctrl->SetLabel(
           $dlg->properties->{$_}->{label}
		) if exists$dlg->properties->{$_}->{label};

        $ctrl->SetValue(
           $dlg->properties->{$_}->{value}->()
		) if exists$dlg->properties->{$_}->{value};

        # radiobox
        my $labels =$dlg->properties->{$_}->{labels};
		$labels||=[];
		for(my $i=0; $i < scalar @$labels ; $i++){
		    $ctrl->SetItemLabel($i, $labels->[$i]);
		}
		# only works for control with items
		$ctrl->SetSelection(
		    $dlg->properties->{$_}->{selection}->()			
		) if exists $dlg->properties->{$_}->{selection};
		
		}
    }
	keys %$properties;
}

sub GetProperties {
    my ($dlg, $properties ) = @_;

	map {
        my $ctrl =$dlg->FindWindow($_);
        #printf("ctrl %s : %s\n", $_, $ctrl);		
        if(defined $ctrl){
		# checkbox, static text

        $dlg->properties->{$_}->{value}->(
            $ctrl->GetValue()
		) if exists$dlg->properties->{$_}->{value};

        $dlg->properties->{$_}->{selection}->(
		    $ctrl->GetSelection()			
		) if exists $dlg->properties->{$_}->{selection};
		
		}
    }
	keys %$properties;
}
1;