[go: up one dir, main page]

Menu

[r1]: / lib / PACTray.pm  Maximize  Restore  History

Download this file

179 lines (137 with data), 4.8 kB

  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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package PACTray;
###################################################################
# This file is part of PAC( Perl Auto Connector)
#
# Copyright (C) 2010 David Torrejon Vaquerizas
#
# This program 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 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
###################################################################
$|++;
###################################################################
# Import Modules
# Standard
use strict;
use warnings;
use FindBin qw ( $RealBin $Bin $Script );
#use Data::Dumper;
# GTK2
use Gtk2 '-init';
use Gtk2::Ex::Simple::List;
use Gtk2::GladeXML;
# PAC modules
use PACUtils;
# END: Import Modules
###################################################################
###################################################################
# Define GLOBAL CLASS variables
my $APPNAME = $PACUtils::APPNAME;
my $APPVERSION = $PACUtils::APPVERSION;
my $APPICON = $RealBin . '/res/pac64x64.png';
my $TRAYICON = $RealBin . '/res/pac_tray.png';
# END: Define GLOBAL CLASS variables
###################################################################
###################################################################
# START: Define PUBLIC CLASS methods
sub new
{
my $class = shift;
my $self = {};
$self -> {_MAIN} = shift;
$self -> {_TRAY} = undef;
$TRAYICON = $RealBin . '/res/pac_tray' . ( $$self{_MAIN}{_CFG}{defaults}{'use bw icon'} ? '_bw.png' : '.png' );
# Build the GUI
_initGUI( $self ) or return 0;
# Setup callbacks
_setupCallbacks( $self );
bless( $self, $class );
return $self;
}
# DESTRUCTOR
sub DESTROY
{
my $self = shift;
undef $self;
return 1;
}
# END: Define PUBLIC CLASS methods
###################################################################
###################################################################
# START: Define PRIVATE CLASS functions
sub _initGUI
{
my $self = shift;
##############################################
# Build a Tray Icon
##############################################
$$self{_TRAY} = Gtk2::StatusIcon -> new_from_file( $TRAYICON ) or die "ERROR: Could not create tray icon: $!";
$$self{_TRAY} -> set_property( 'tooltip-markup', "<b>$APPNAME</b> (v.$APPVERSION)" );
return 1;
}
sub _setupCallbacks
{
my $self = shift;
$$self{_TRAY} -> signal_connect( 'button_press_event' => sub
{
my ( $widget, $event ) = @_;
# Left click: show/hide main window
if ( $event -> button eq 1 )
{
if ( $$self{_MAIN}{_GUI}{main} -> visible )
{
$$self{_MAIN}{_GUI}{main} -> hide;
}
else
{
$$self{_MAIN}{_GUI}{main} -> present;
}
return 1;
}
# Skip middle-click
elsif ( $event -> button ne 3 )
{
return 1;
}
# Right click: show the configured connections
$self -> _trayMenu( $widget, $event );
return 1;
} );
# Set a timer to control trayicon's tooltip
Glib::Timeout -> add( 750, sub { return $self -> _updateGUI; } );
return 1;
}
sub _updateGUI
{
my $self = shift;
$$self{_TRAY} -> set_property( 'tooltip-markup', "<b>$APPNAME</b> (v$APPVERSION): <b>" . ( scalar( keys %PACMain::RUNNING ) ) . "</b> terminal(s) opened" );
return 1;
}
sub _trayMenu
{
my $self = shift;
my $widget = shift;
my $event = shift;
my $tray_menu_items = _menuAvailableConnections;
push( @{$tray_menu_items}, { separator => 1 } );
push( @{$tray_menu_items}, { label => 'Preferences...', stockicon => 'gtk-preferences', code => sub { $$self{_MAIN}{_CONFIG} -> show; } } );
push( @{$tray_menu_items}, { label => 'Clusters...', stockicon => 'gtk-justify-fill', code => sub { $$self{_MAIN}{_CLUSTER} -> show; } } );
push( @{$tray_menu_items}, { label => 'Show Window', stockicon => 'gtk-home', code => sub { $$self{_MAIN}{_GUI}{main} -> present(); } } );
push( @{$tray_menu_items}, { separator => 1 } );
push( @{$tray_menu_items}, { label => 'About', stockicon => 'gtk-about', code => sub { $$self{_MAIN} -> _showAboutWindow; } } );
push( @{$tray_menu_items}, { label => 'Exit', stockicon => 'gtk-quit', code => sub { $$self{_MAIN} -> _quitProgram; } } );
_wPopUpMenu( $tray_menu_items, $event, 'below calling widget' );
return 1;
}
# END: Define PRIVATE CLASS functions
###################################################################
1;