lib/App/TimeTracker/Gtk2TrayIcon.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« script/tracker_gtk_trayicon.pl ↑ Summary
1 package App::TimeTracker::Gtk2TrayIcon;
2 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 our $VERSION = "1.002";
6 # ABSTRACT: Show TimeTracker status in a GTK tray applet
7  
8 0 ▶use Gtk2;
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use AnyEvent;
10 use App::TimeTracker::Proto;
11 use App::TimeTracker::Data::Task;
12 use Gtk2::TrayIcon;
13 use FindBin qw($Bin);
14 use File::ShareDir qw(dist_file);
15  
16 sub init {
17 my ($class, $run) = @_;
18 my $storage_location = App::TimeTracker::Proto->new->home;
19  
20 my $lazy =
21 -e 'share/lazy.png'
22 ? 'share/lazy.png'
23 : dist_file( 'App-TimeTracker-Gtk2TrayIcon', 'lazy.png' );
24 my $busy =
25 -e 'share/busy.png'
26 ? 'share/busy.png'
27 : dist_file( 'App-TimeTracker-Gtk2TrayIcon', 'busy.png' );
28 Gtk2->init;
29 my $img = Gtk2::Image->new_from_file($lazy);
30 my $window = Gtk2::TrayIcon->new(__PACKAGE__);
31 my $eventbox = Gtk2::EventBox->new;
32 $eventbox->add($img);
33  
34 my $current;
35 my $t = AnyEvent->timer(
36 after => 0,
37 interval => 5,
38 cb => sub {
39 my $task =
40 App::TimeTracker::Data::Task->current($storage_location);
41 if ($task) {
42 $img->set_from_file($busy);
43 $current = $task->say_project_tags;
44 }
45 else {
46 $img->set_from_file($lazy);
47 $current = 'nothing';
48 }
49 } );
50 $eventbox->signal_connect(
51 'enter-notify-event' => sub {
52 unless ( $current eq 'nothing' ) {
53 my $dialog =
54 Gtk2::MessageDialog->new( $window,
55 [qw/modal destroy-with-parent/],
56 'other', 'none', $current );
57  
58 $dialog->set_decorated(0);
59 $dialog->set_gravity('south-west');
60  
61 my $t = AnyEvent->timer(
62 after => 5,
63 cb => sub {
64 $dialog->destroy;
65 } );
66 my $retval = $dialog->run;
67 $dialog->destroy;
68 }
69 } );
70 $window->add($eventbox);
71 $window->show_all;
72 Gtk2->main if $run;
73 }
74  
75 1;
76  
77  
78  
79 =pod
80  
81 =head1 NAME
82  
83 App::TimeTracker::Gtk2TrayIcon - Show TimeTracker status in a GTK tray applet
84  
85 =head1 VERSION
86  
87 version 1.002
88  
89 =head1 DESCRIPTION
90  
91 Backend for L<tracker_gtk_trayicon.pl>
92  
93 =head1 METHODS
94  
95 =head2 init
96  
97 Initialize the GTK app.
98  
99 =head1 AUTHOR
100  
101 Thomas Klausner <domm@cpan.org>
102  
103 =head1 COPYRIGHT AND LICENSE
104  
105 This software is copyright (c) 2011 by Thomas Klausner.
106  
107 This is free software; you can redistribute it and/or modify it under
108 the same terms as the Perl 5 programming language system itself.
109  
110 =cut
111  
112  
113 __END__
« script/tracker_gtk_trayicon.pl ↑ Summary