summaryrefslogtreecommitdiff
path: root/lib/LDFM/MainController.pm
blob: 63f981accbbe1f09c0967b810d86c4969c777509 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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 $newpath;
    if ($path eq '..') {
        $newpath=$self->{"cur_${side}_path"}->parent;
    }
    else {
        $newpath=dir($path)->absolute($self->{"cur_${side}_path"})->cleanup;
    }
 
    return unless -d $newpath;
 
    $self->{"cur_${side}_path"}=$newpath;
    $self->{"${side}_path"}->set_text($newpath->stringify);
 
    my @dir_list=();
    for my $item ($newpath->children(all=>1)) {
        my @row=($item->relative($newpath)->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 set_left_path {
    my ($self,$widget)=@_;
 
    $self->update_list_with_path('left',$widget->get_text());
 
    return;
}
 
sub set_right_path {
    my ($self,$widget)=@_;
 
    $self->update_list_with_path('right',$widget->get_text());
 
    return;
}
 
sub use_a_row {
    my ($self,$side,$tree_path)=@_;
 
    #my $row_ref=$widget->get_row_data_from_path($tree_path); 
    my ($row_num)=$tree_path->get_indices();
    my $row_ref=$self->{"${side}_data"}->[$row_num];
    my $relpath=$row_ref->[0];
 
    $self->update_list_with_path($side,$relpath);
}
 
sub use_left_row {
    my ($self,$widget,$tree_path)=@_;
 
    $self->use_a_row('left',$tree_path);
 
    return;
}
 
sub use_right_row {
    my ($self,$widget,$tree_path)=@_;
 
    $self->use_a_row('right',$tree_path);
 
    return;
}
 
sub quit {
    Gtk2->main_quit;
}
 
1;