package Gtk2::Ex::Email::AttachmentVBox;

use warnings;
use strict;
use File::MimeInfo;
use Gtk2;
use Gtk2::SimpleList;

=head1 NAME

Gtk2::Ex::Email::AttachmentVBox - Creates a VBox for handling attachments.

=head1 VERSION

Version 0.0.1


our $VERSION = '0.0.1';


    use Gtk2::Ex::Email::AttachmentVBox;
    use Gtk2;
    use Data::Dumper;
    #init it
    my $avb=Gtk2::Ex::Email::AddressVBox->new();
    #get the VBox and add it
    my $vbox=Gtk2::VBox->new;
    my $vbox2=$avb->vbox;
    $vbox->pack_start($vbox2, 1, 1, 1);
    #adds a button that calls getFiles
    my $button=Gtk2::Button->new;
    my $buttonLabel=Gtk2::Label->new('get files');
    $vbox->pack_start($button, 1, 1, 1);
	    								my @files=$avb->getFiles;
		    							print Dumper(\@files);
    #add the VBox to the window
    my $window=Gtk2::Window->new;
    #run it

=head1 METHODS

=head2 new

This initiates the object.

    my $avb=Gtk2::Ex::Email::AttachmentVBox->new();


sub new{
	my $self={error=>undef,
	bless $self;
	return $self;

=head2 addFile

This adds a file to the list.

One arguement is required and it is the file to add.

If it fails, it returns undef, otherwise '1'.

    my $returned=$avb->addFile($someFile);
        print "Error!\n";


sub addFile{
	my $self=$_[0];
	my $file=$_[1];
	my $function='addFile';

	#make sure we have a file
	if (!defined($file)) {
		warn($self->{module}.' '.$function.': No file specified');
		return undef;

	#make sure it exists
	if (! -e $file) {
		warn($self->{module}.' '.$function.': The file does not exist');
		return undef;

	#gets the mime type
	my $mimetype=mimetype($file);
	if (!defined($mimetype)) {
		warn($self->{module}.' '.$function.': Unable to get mime type');
		return undef;		

	my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($file);

	my @topush;
	push(@topush, $mimetype);
	push(@topush, $size);
	push(@topush, $file);

	#adds the new entry
	push(@{$self->{gui}{list}->{data}}, \@topush);

	return 1;

=head2 addFileDialog

This calls Gtk2::FileChooserDialog and the file
to the list.

A return of undef means the user canceled. A return of
'1' means a file was added.

    my $returned=$avb->addFileDialog;
        print "added a file\n";
        print "user canceled\n";


sub addFileDialog{
	my $self=$_[0];

	my $file_chooser =  Gtk2::FileChooserDialog->new (
													  'Select a file to attach...',
													  'gtk-cancel' => 'cancel',
													  'gtk-ok' => 'ok'

	if ('ok' ne $file_chooser->run){
		print "test\n";
		return undef;

	my $filename = $file_chooser->get_filename;



	return 1;

=head2 getFiles

Gets a list of the files that should be attached.

    my @files=$avb->getFiles;


sub getFiles{
	my $self=$_[0];

	my @files;

	my $int=0;
	while (defined( $self->{gui}{list}->{data}[$int][2] )) {
		push( @files, $self->{gui}{list}->{data}[$int][2] );
	#unfortunately the defined check will add a new row
	#so there for we remove it

	return @files;

=head2 removeSelected

This removes the currently selected file from the list.

    my $returned=$avb->removeSelected;
        print "removed\n";
        print "nothing selected\n";


sub removeSelected{
	my $self=$_[0];

	my @selected=$self->{gui}{list}->get_selected_indices;

	#nothing selected
	if (!defined($selected[0])) {
		return undef;

	#removes it

	return 1;

=head2 vbox

This creates the VBox that contains the widgets.

One arguement is taken and it is a array of files
to initially attach.



sub vbox{
	my $self=$_[0];
	my @files;
		@files= @{$_[1]};

	#the vbox

	#holds the buttons
	$self->{gui}{vbox}->pack_start($self->{gui}{buttonHB}, 0, 1, 1);

	#the add button
	$self->{gui}{addLabel}=Gtk2::Label->new('Add Attachment');
	$self->{gui}{buttonHB}->pack_start($self->{gui}{add}, 0, 1, 1);

	#the remove button
	$self->{gui}{removeLabel}=Gtk2::Label->new('Remove Attachment');
	$self->{gui}{buttonHB}->pack_start($self->{gui}{remove}, 0, 1, 1);

	#the SW window that will hold attachment list
	$self->{gui}{vbox}->pack_start($self->{gui}{attachmentSW}, 1, 1, 1);

	#the list that will hold the attachmentlist
											 'Mime Type'=>'text',

	#add any files if asked to
	if (defined( $files[0] )) {
		my $int=0;
		while (defined( $files[$int] )) {



	return $self->{gui}{vbox};

=head1 AUTHOR

Zane C. Bowers-Hadley, C<< <vvelox at> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-gtk2-ex-email-attachmentvbox at>, or through
the web interface at L<>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Gtk2::Ex::Email::AttachmentVBox

You can also look for information at:

=over 4

=item * RT: CPAN's request tracker


=item * AnnoCPAN: Annotated CPAN documentation


=item * CPAN Ratings


=item * Search CPAN




ANDK, #51565, notified be about a missing dependency


Copyright 2011 Zane C. Bowers-Hadley, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


1; # End of Gtk2::Ex::Email::AttachmentVBox