summaryrefslogtreecommitdiff
path: root/lib/gcstar/GCImport.pm
blob: 2ff40d31d2afe00380a4fbde51ed9483b1caf822 (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
131
132
133
134
135
136
137
138
139
package GCImport;

###################################################
#
#  Copyright 2005-2010 Christian Jodar
#
#  This file is part of GCstar.
#
#  GCstar 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.
#
#  GCstar 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 GCstar; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
###################################################

use File::Basename;
use GCUtils 'glob';

use base 'Exporter';
our @EXPORT = qw(@importersArray);

our @importersArray;

sub loadImporters
{
    foreach (glob $ENV{GCS_LIB_DIR}.'/GCImport/*.pm')
    {
        my $import = basename($_, '.pm')."\n";
        next if $import =~ /GCImportBase/;
        eval "use GCImport::$import";
        (my $importer = $import) =~ s/^GCImport/GCImporter/;
        my $obj;
        eval "\$obj = new GCImport::$importer";
        die "Fatal error with importer $import\n$@" if $@;
        push @importersArray, $obj if ! $obj->{errors};
    }
}

use Gtk2;
use GCExportImport;


{
    package GCImportDialog;
    use Glib::Object::Subclass
                Gtk2::Dialog::
    ;
    
    @GCImportDialog::ISA = ('GCExportImportDialog');

    sub addOptions
    {
        my ($self, $options) = @_;
        $options->{newList} = ($self->{newList}->get_active) ? 1 : 0;
        $options->{parent} = $self->{parent};
    }

    sub setModule
    {
        my ($self, $module) = @_;
        
        $self->SUPER::setModule($module);
        $self->{currentList}->set_sensitive(scalar @{$module->getModels} == 0);
        $self->{newList}->set_active(1);
        if ($self->{parent}->{model})
        {
            foreach (@{$module->getModels})
            {
                if ($self->{parent}->{model}->getName eq $_)
                {
                    $self->{currentList}->set_sensitive(1);
                    last;
                }
            }
        }
        if ($self->{fieldsDialog})
        {
            if ($module->wantsIgnoreField)
            {
                $self->{fieldsDialog}->addIgnoreField($self->{parent}->{ignoreString});
            }
            else
            {
                $self->{fieldsDialog}->removeIgnoreField;
            }
        }
    }
    
    sub setModel
    {
        my $self = shift;
        $self->{fieldsDialog} = new GCFieldsSelectionDialog($self,
                                                            $self->{parent}->{lang}->{ImportFieldsTitle});
    }

    sub new
    {
        my ($proto, $parent) = @_;
        my $class = ref($proto) || $proto;
        my $self  = $class->SUPER::new($parent, $parent->{lang}->{ImportListTitle}, 'import');
        bless ($self, $class);

        my $vboxInsert = new Gtk2::VBox(0,0);
        $vboxInsert->set_border_width(0);
        
        $self->{newList} = new Gtk2::RadioButton(undef, $parent->{lang}->{ImportNewList});
        $self->{currentList} = new Gtk2::RadioButton($self->{newList}->get_group, $parent->{lang}->{ImportCurrentList});
                
#        $vboxInsert->pack_start($self->{newList},1,1,0);
#        $vboxInsert->pack_start($self->{currentList},1,1,0);
#        
#        $self->vbox->pack_start(new Gtk2::HSeparator, 1, 1, 5);
#        $self->vbox->pack_start($vboxInsert,0,0,0);

        $self->{dataTable}->resize(4, 2);
        $self->{dataTable}->attach($self->{newList}, 0, 2, 0, 1, 'fill', 'fill', 0, 0);
        $self->{dataTable}->attach($self->{currentList}, 0, 2, 1, 2, 'fill', 'fill', 0, 0);
        $self->{dataTable}->attach($self->{labelFile}, 0, 1, 3, 4, 'fill', 'fill', 0, 0);
        $self->{dataTable}->attach($self->{file}, 1, 2, 3, 4, ['fill', 'expand'], 'fill', 0, 0);

        $self->{fieldsButtonLabel} = $parent->{lang}->{ImportFieldsTitle};
        $self->{fieldsTip} = $parent->{lang}->{ImportFieldsTip};

        return $self;
    }
    
}


1;