blib/lib/Gtk2/Ex/Email/Compose.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Gtk2::Ex::Email::Compose;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 0 ▶use Gtk2;
Subroutine BEGIN: called CC=1 SCAR=2.6
6 use Gtk2::Ex::Email::AAnotebook;
7  
8 =head1 NAME
9  
10 Gtk2::Ex::Email::Compose - Presents a email compose window.
11  
12 =head1 VERSION
13  
14 Version 0.1.0
15  
16 =cut
17  
18 our $VERSION = '0.1.0';
19  
20 =head1 SYNOPSIS
21  
22 use Gtk2::Ex::Email::Compose;
23 use Gtk2;
24 use Data::Dumper;
25
26 Gtk2->init;
27
28 my $ecw=Gtk2::Ex::Email::Compose->new;
29
30 my $window=$ecw->window({title=>'some thing'});
31
32 my $addressVBox=$ecw->getAddressVBox;
33 my $attachmentVBox=$ecw->getAttachmentVBox;
34
35 $ecw->setAddressbookCB(sub{
36 use Data::Dumper;
37 print Dumper($_[1]);
38 },
39 {
40 ecw=>$ecw,
41 addresses=>$addressVBox,
42 }
43 );
44
45 $ecw->setCloseCB(sub{
46 use Data::Dumper;
47 print Dumper($_[1]);
48 },
49 {
50 ecw=>$ecw,
51 }
52 );
53
54 $ecw->setDraftCB(sub{
55 use Data::Dumper;
56 print Dumper($_[1]);
57 },
58 {
59 ecw=>$ecw,
60 addresses=>$addressVBox,
61 attachment=>$attachmentVBox
62 }
63 );
64
65 $ecw->setSendCB(sub{
66 use Data::Dumper;
67 print Dumper($_[1]{addresses});
68 },
69 {
70 ecw=>$ecw,
71 addresses=>$addressVBox,
72 attachment=>$attachmentVBox,
73 }
74 );
75
76 $ecw->setSpellcheckCB(sub{
77 use Data::Dumper;
78 print Dumper($_[1]);
79 },
80 {
81 ecw=>$ecw,
82 }
83 );
84
85 Gtk2->main;
86  
87 =head1 METHODS
88  
89 =head2 new
90  
91 This initiates the object.
92  
93 my $ecw=Gtk2::Ex::Email::Compose->new;
94  
95 =cut
96  
97 sub new{
98 my $self={error=>undef,
99 perror=>undef,
100 errorString=>undef,
101 gui=>{},
102 };
103 bless $self;
104
105 return $self;
106 }
107  
108 =head2 getAAnotebook
109  
110 This gets the notebook created by Gtk2::Ex::Email::AAnotebook.
111  
112 my $notebook=$ecw->getAAnotebook;
113  
114 =cut
115  
116 sub getAAnotebook{
117 my $self=$_[0];
118  
119 return $self->{AAnotebook};
120 }
121  
122 =head2 getAddressVBox
123  
124 This gets the Gtk2::Ex::Email::AddressVBox object created
125 by Gtk2::Ex::Email::AAnotebook.
126  
127 my $addressVBox=$ecw->getAddressVBox;
128  
129 =cut
130  
131 sub getAddressVBox{
132 my $self=$_[0];
133  
134 return $self->{AAnotebook}->getAddressVBox;
135 }
136  
137 =head2 getAttachmentVBox
138  
139 This gets the Gtk2::Ex::Email::AttachmentVBox object created
140 by Gtk2::Ex::Email::AAnotebook.
141  
142 my $attachmentVBox=$ecw->getAttachmentVBox;
143  
144 =cut
145  
146 sub getAttachmentVBox{
147 my $self=$_[0];
148  
149 return $self->{AAnotebook}->getAttachmentVBox;
150 }
151  
152 =head2 getBody
153  
154 This gets the body.
155  
156 my $body=$ecw->getBody;
157  
158 =cut
159  
160 sub getBody{
161 my $self=$_[0];
162  
163 return $self->{gui}{bodyBuffer}->get_text;
164 }
165  
166 =head2 getSubject
167  
168 This gets the subject.
169  
170 my $subject=$ecw->getSubject;
171  
172 =cut
173  
174 sub getSubject{
175 my $self=$_[0];
176
177 return $self->{gui}{subject}->get_text;
178 }
179  
180 =head2 setAddressbookCB
181  
182 This sets the callback for when the addressbook button is clicked.
183  
184 Two options are taken. The first is the callback and the
185 second is any data to be passed to the callback.
186  
187 $ecw->setAddressbookCB(sub{
188 use Data::Dumper;
189 print Dumper($_[1]);
190 },
191 {
192 ecw=>$ecw,
193 }
194 );
195  
196 =cut
197  
198 sub setAddressbookCB{
199 my $self=$_[0];
200 my $callback=$_[1];
201 my $data=$_[2];
202  
203 $self->{gui}{close}->signal_connect(clicked=>$callback, $data);
204  
205 }
206  
207 =head2 setBody
208  
209 This sets the body.
210  
211 One arguement is taken and that is the body
212 to set. If it is not defined, '' will be used.
213  
214 $ecw->setBody($body);
215  
216 =cut
217  
218 sub setBody{
219 my $self=$_[0];
220 my $text=$_[1];
221  
222 if (!defined($text)) {
223 $text='';
224 }
225  
226 return $self->{gui}{bodyBuffer}->set_text($text);
227 }
228  
229 =head2 setCloseCB
230  
231 This sets the callback for when the close button is clicked.
232  
233 Two options are taken. The first is the callback and the
234 second is any data to be passed to the callback.
235  
236 $ecw->setCloseCB(sub{
237 use Data::Dumper;
238 print Dumper($_[1]);
239 },
240 {
241 ecw=>$ecw,
242 }
243 );
244  
245 =cut
246  
247 sub setCloseCB{
248 my $self=$_[0];
249 my $callback=$_[1];
250 my $data=$_[2];
251  
252 $self->{gui}{close}->signal_connect(clicked=>$callback, $data);
253  
254 }
255  
256 =head2 setDraftCB
257  
258 This sets the callback for when the draft button is clicked.
259  
260 Two options are taken. The first is the callback and the
261 second is any data to be passed to the callback.
262  
263 $ecw->setDraftCB(sub{
264 use Data::Dumper;
265 print Dumper($_[1]);
266 },
267 {
268 ecw=>$ecw,
269 }
270 );
271  
272 =cut
273  
274 sub setDraftCB{
275 my $self=$_[0];
276 my $callback=$_[1];
277 my $data=$_[2];
278  
279 $self->{gui}{draft}->signal_connect(clicked=>$callback, $data);
280  
281 }
282  
283 =head2 setSendCB
284  
285 This sets the callback for when the send button is clicked.
286  
287 Two options are taken. The first is the callback and the
288 second is any data to be passed to the callback.
289  
290 $ecw->setSendCB(sub{
291 use Data::Dumper;
292 print Dumper($_[1]);
293 },
294 {
295 ecw=>$ecw,
296 }
297 );
298  
299 =cut
300  
301 sub setSendCB{
302 my $self=$_[0];
303 my $callback=$_[1];
304 my $data=$_[2];
305  
306 $self->{gui}{send}->signal_connect(clicked=>$callback, $data);
307  
308 }
309  
310 =head2 setSpellcheckCB
311  
312 This sets the callback for when the spell check button is clicked.
313  
314 Two options are taken. The first is the callback and the
315 second is any data to be passed to the callback.
316  
317 $ecw->setSpellcheckCB(sub{
318 use Data::Dumper;
319 print Dumper($_[1]);
320 },
321 {
322 ecw=>$ecw,
323 }
324 );
325  
326 =cut
327  
328 sub setSpellcheckCB{
329 my $self=$_[0];
330 my $callback=$_[1];
331 my $data=$_[2];
332  
333 $self->{gui}{spellcheck}->signal_connect(clicked=>$callback, $data);
334  
335 }
336  
337 =head2 setSubject
338  
339 This sets the subject.
340  
341 One arguement is taken and that is the subject
342 to set. If it is not defined, '' will be used.
343  
344 my $subject=$ecw->getSubject('some subject');
345  
346 =cut
347  
348 sub setSubject{
349 my $self=$_[0];
350 my $text=$_[1];
351  
352 if (!defined($text)) {
353 $text='';
354 }
355  
356 $self->{gui}{subject}->set_text($text);
357  
358 return 1;
359 }
360  
361 =head2 window
362  
363 This builds the compose window and returns a
364 Gtk2::Window object.
365  
366 One arguement is taken and it is a hash.
367  
368 =head3 hash args
369  
370 =head4 addresses
371  
372 This is the hash that contains the addresses
373 to pass to Gtk2::Ex::Email::AddressVBox->vbox.
374  
375 =head4 displayAddressbook
376  
377 If set to true, it displays the 'Addressbook' button.
378  
379 The default is true.
380  
381 =head4 displayClose
382  
383 If set to true, it displays the 'Close' button.
384  
385 The default is true.
386  
387 =head4 displayDraft
388  
389 If set to true, it displays the 'Draft' button.
390  
391 The default is true.
392  
393 =head4 displaySend
394  
395 If set to true, it displays the 'Send' button.
396  
397 The default is true.
398  
399 =head4 displaySpellcheck
400  
401 If set to true, it displays the 'Spell Check' button.
402  
403 The default is true.
404  
405 =head4 files
406  
407 This is the array that contains the files
408 to pass to Gtk2::Ex::Email::AttachmentVBox->vbox.
409  
410 =head4 subject
411  
412 If this is defined, the subject will be set to it.
413  
414 =head4 title
415  
416 The window title.
417  
418 my $window=$ecm->window(\%args);
419  
420 =cut
421  
422 sub window{
423 my $self=$_[0];
424 my %args;
425 if(defined($_[1])){
426 %args= %{$_[1]};
427 }
428  
429 #sets the defaults
430 if (!defined($args{displaySend})) {
431 $args{displaySend}=1;
432 }
433 if (!defined($args{displayDraft})) {
434 $args{displayDraft}=1;
435 }
436 if (!defined($args{displayClose})) {
437 $args{displayClose}=1;
438 }
439 if (!defined($args{displayAddressbook})) {
440 $args{displayAddressbook}=1;
441 }
442 if (!defined($args{displaySpellcheck})) {
443 $args{displaySpellcheck}=1;
444 }
445  
446 #the the window that will contain it all
447 $self->{gui}{window}=Gtk2::Window->new;
448 $self->{gui}{window}->set_default_size(750, 450);
449 $self->{gui}{window}->show;
450 if (defined($args{title})) {
451 $self->{gui}{window}->set_title($args{title});
452 }
453  
454 #this will hold everything in the window
455 $self->{gui}{vbox}=Gtk2::VBox->new;
456 $self->{gui}{vbox}->show;
457 $self->{gui}{window}->add( $self->{gui}{vbox} );
458  
459 #this will hold the buttons
460 $self->{gui}{buttonHB}=Gtk2::HBox->new;
461 $self->{gui}{buttonHB}->show;
462 $self->{gui}{vbox}->pack_start( $self->{gui}{buttonHB}, 0, 1, 1 );
463  
464 #set up the send button
465 if ($args{displaySend}) {
466 $self->{gui}{send}=Gtk2::Button->new;
467 $self->{gui}{send}->show;
468 $self->{gui}{sendLabel}=Gtk2::Label->new('Send');
469 $self->{gui}{sendLabel}->show;
470 $self->{gui}{send}->add($self->{gui}{sendLabel});
471 $self->{gui}{buttonHB}->pack_start($self->{gui}{send}, 0, 1, 1);
472 }
473  
474 #set up the send button
475 if ($args{displayClose}) {
476 $self->{gui}{close}=Gtk2::Button->new;
477 $self->{gui}{close}->show;
478 $self->{gui}{closeLabel}=Gtk2::Label->new('Close');
479 $self->{gui}{closeLabel}->show;
480 $self->{gui}{close}->add($self->{gui}{closeLabel});
481 $self->{gui}{buttonHB}->pack_start($self->{gui}{close}, 0, 1, 1);
482 }
483  
484 #set up the draft button
485 if ($args{displayDraft}) {
486 $self->{gui}{draft}=Gtk2::Button->new;
487 $self->{gui}{draft}->show;
488 $self->{gui}{draftLabel}=Gtk2::Label->new('Draft');
489 $self->{gui}{draftLabel}->show;
490 $self->{gui}{draft}->add($self->{gui}{draftLabel});
491 $self->{gui}{buttonHB}->pack_start($self->{gui}{draft}, 0, 1, 1);
492 }
493  
494 #set up the draft button
495 if ($args{displayAddressbook}) {
496 $self->{gui}{addressbook}=Gtk2::Button->new;
497 $self->{gui}{addressbook}->show;
498 $self->{gui}{addressbookLabel}=Gtk2::Label->new('Addressbook');
499 $self->{gui}{addressbookLabel}->show;
500 $self->{gui}{addressbook}->add($self->{gui}{addressbookLabel});
501 $self->{gui}{buttonHB}->pack_start($self->{gui}{addressbook}, 0, 1, 1);
502 }
503  
504 #set up the send button
505 if ($args{displaySpellcheck}) {
506 $self->{gui}{spellcheck}=Gtk2::Button->new;
507 $self->{gui}{spellcheck}->show;
508 $self->{gui}{spellcheckLabel}=Gtk2::Label->new('Spell Check');
509 $self->{gui}{spellcheckLabel}->show;
510 $self->{gui}{spellcheck}->add($self->{gui}{spellcheckLabel});
511 $self->{gui}{buttonHB}->pack_start($self->{gui}{spellcheck}, 0, 1, 1);
512 }
513  
514 #the paned seperating the notebook and entry
515 $self->{gui}{vpaned}=Gtk2::VPaned->new;
516 $self->{gui}{vpaned}->show;
517 $self->{gui}{vpaned}->set_position(150);
518 $self->{gui}{vbox}->pack_start( $self->{gui}{vpaned}, 1, 1, 1 );
519  
520 #AA notebook
521 $self->{AAnotebook}=Gtk2::Ex::Email::AAnotebook->new();
522 $self->{gui}{AAnotebook}=$self->{AAnotebook}->notebook( $args{addresses}, $args{files} );
523 $self->{gui}{vpaned}->add1($self->{gui}{AAnotebook});
524  
525 #this vbox holds the stuff for the bottom paned
526 $self->{gui}{bottomHPanedVB}=Gtk2::VBox->new;
527 $self->{gui}{bottomHPanedVB}->show;
528 $self->{gui}{vpaned}->add2( $self->{gui}{bottomHPanedVB} );
529  
530 #the subject
531 $self->{gui}{subjectHB}=Gtk2::HBox->new;
532 $self->{gui}{subjectHB}->show;
533 $self->{gui}{subjectLabel}=Gtk2::Label->new('Subject:');
534 $self->{gui}{subjectLabel}->show;
535 $self->{gui}{subjectHB}->pack_start($self->{gui}{subjectLabel}, 0, 1, 1);
536 $self->{gui}{subject}=Gtk2::Entry->new;
537 $self->{gui}{subject}->show;
538 $self->{gui}{subjectHB}->pack_start($self->{gui}{subject}, 1, 1, 1);
539 if (defined($args{subject})) {
540 $self->{gui}{subject}->set_text($args{text});
541 }
542 $self->{gui}{bottomHPanedVB}->pack_start( $self->{gui}{subjectHB}, 0, 1, 1 );
543  
544 #the final part
545 $self->{gui}{body}=Gtk2::TextView->new;
546 $self->{gui}{body}->show;
547 $self->{gui}{bodyBuffer}=Gtk2::TextBuffer->new;
548 $self->{gui}{body}->set_buffer($self->{gui}{bodyBuffer});
549 $self->{gui}{bottomHPanedVB}->pack_start( $self->{gui}{body}, 1, 1, 1 );
550
551 return $self->{gui}{window};
552 }
553  
554 =head1 AUTHOR
555  
556 Zane C. Bowers, C<< <vvelox at vvelox.net> >>
557  
558 =head1 BUGS
559  
560 Please report any bugs or feature requests to C<bug-gtk2-ex-email-compose at rt.cpan.org>, or through
561 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Gtk2-Ex-Email-Compose>. I will be notified, and then you'll
562 automatically be notified of progress on your bug as I make changes.
563  
564  
565  
566  
567 =head1 SUPPORT
568  
569 You can find documentation for this module with the perldoc command.
570  
571 perldoc Gtk2::Ex::Email::Compose
572  
573  
574 You can also look for information at:
575  
576 =over 4
577  
578 =item * RT: CPAN's request tracker
579  
580 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Gtk2-Ex-Email-Compose>
581  
582 =item * AnnoCPAN: Annotated CPAN documentation
583  
584 L<http://annocpan.org/dist/Gtk2-Ex-Email-Compose>
585  
586 =item * CPAN Ratings
587  
588 L<http://cpanratings.perl.org/d/Gtk2-Ex-Email-Compose>
589  
590 =item * Search CPAN
591  
592 L<http://search.cpan.org/dist/Gtk2-Ex-Email-Compose/>
593  
594 =back
595  
596  
597 =head1 ACKNOWLEDGEMENTS
598  
599  
600 =head1 COPYRIGHT & LICENSE
601  
602 Copyright 2009 Zane C. Bowers, all rights reserved.
603  
604 This program is free software; you can redistribute it and/or modify it
605 under the same terms as Perl itself.
606  
607  
608 =cut
609  
610 1; # End of Gtk2::Ex::Email::Compose
↑ Summary