summaryrefslogtreecommitdiff
path: root/lib/LDFM/MainController.pm
blob: 9c81ecd09bd37a776e241538ad239128b5823773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package LDFM::MainController; 
use utf8;
use warnings;
use strict;
use base 'Gtk2::GladeXML::Simple';
use Gtk2::Ex::Simple::List;
use Readonly;
use Path::Class;
 
our $VERSION = '0.01';
 
sub new {
    my ($class,%params)=@_;
 
    my $self=$class->SUPER::new($params{glade_file});
 
    # cambio le liste con qualcosa di più comodo 
    $self->simplify_list('left');
    $self->simplify_list('right');
 
    # imposto i path 
    $self->update_list_with_path('left',$ENV{HOME});
    $self->update_list_with_path('right','/');
 
    return $self;
}
 
sub simplify_list {
    my ($self,$side)=@_;
 
    my $list_name="${side}_list";
 
    $self->{$list_name}=Gtk2::Ex::Simple::List->new_from_treeview(
        $self->{$list_name},
        'File' => 'text',
        'Type' => 'text',
        'Size' => 'int',
    );
 
    $self->{"${side}_data"}=$self->{$list_name}->{data};
 
    return;
}
 
sub update_list_with_path {
    my ($self,$side,$path)=@_;
 
    my $curpath=dir($path)->absolute;
    $self->{"cur_${side}_path"}=$curpath;
    $self->{"${side}_path"}->set_text($curpath->stringify);
 
    my @dir_list=();
    for my $item ($curpath->children(all=>1)) {
        my @row=($item->relative($curpath)->stringify);
        if ($item->isa('Class::Path::Dir')) {
            push @row,'DIR',0;
        }
        else {
            push @row,'FILE',-s $item;
        }
        push @dir_list,[@row];
    }
 
    @{$self->{"${side}_data"}}=@dir_list;
}
 
sub quit {
    Gtk2->main_quit;
}
 
1;