aboutsummaryrefslogtreecommitdiffstats
path: root/Category.pm
blob: fedb849536f4f44739b9a64becbd1c7936a8a882 (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
124
125
126
127
128
129
130
# vim: set et ts=4 sw=4:
#    Copyright 2012 Steven Tucker
#
#    This file is part of AdminPanel
#
#    AdminPanel 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 of the License, or
#    (at your option) any later version.
#
#    AdminPanel 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 AdminPanel.  If not, see <http://www.gnu.org/licenses/>.


#Class Category
package Category;

use strict;
use warnings;
use diagnostics;
use yui;

## Can only add the config file data at constructor
## The Gui elements are added in setupGui inside MainDisplay
sub new {
    my ($class, $newName, $newIcon) = @_;
    my $self = {
        my $name = 0,
        my $button = 0,
        my $icon = 0,
        my $modules = 0
    };
    bless $self, 'Category';

    $self->{name} = $newName;
    $self->{icon} = $newIcon;

    return $self;
}

## Add a new module to the list
sub loadModule {
    my ($self, $module) = @_;
    
    push ( @{$self->{modules}}, $module );

}

## Create and add buttons for each module
sub addButtons {
    my($self, $pane, $factory) = @_;
    my $count = 0;
    my $tmpButton;
    my $currLayout = 0;
    $factory->createVSpacing($pane, 2);
    foreach my $mod (@{$self->{modules}}) {
        if(($count % 2) != 1) {
            $currLayout = $factory->createHBox($pane);
            $factory->createHStretch($currLayout);
        }
        $count++;
        $tmpButton = $factory->createPushButton($currLayout,
                                                $mod->{name});
        $mod->setButton($tmpButton);
        $tmpButton->setLabel($mod->{name});
        $tmpButton->setIcon($mod->{icon});
        $factory->createHStretch($currLayout);
        if(($count % 2) != 1) {
            $factory->createVSpacing($pane, 2);     
        }
    }
    $factory->createVStretch($pane);
}

## Delete the module buttons
sub removeButtons {
    my($self) = @_;

    for(@{$self->{modules}}) {
        $_->removeButton();
    }
}

sub setIcon {
    my($self) = @_;

    $self->{button}->setIcon($self->{icon});
}

1;
__END__ 

=pod

=head1 NAME

       Category - add new category to window

=head1 SYNOPSIS
       
       $category = new Category('Category Name');


=head1 USAGE

       my $display = new MainDisplay();

       my $category = new Category('Network');
       $display->loadCategory($category);

       $display->start();

=head1 FUNCTIONS

=head2 new (name)

       Constructor: creates a new category named Name 

       $category = new Category('Name'); 

=head3 name (String)

       The name of the category

=cut