1# Copyright (c) 2003-2009 Mikhael Goikhman 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 2 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, see: <http://www.gnu.org/licenses/> 15 16package FVWM::Tracker::GlobalConfig; 17 18use strict; 19 20use FVWM::Tracker qw(base); 21 22sub observables ($) { 23 return [ 24 "value updated", 25 ]; 26} 27 28sub start ($) { 29 my $self = shift; 30 31 $self->{data} = {}; 32 $self->add_handler(M_CONFIG_INFO, sub { 33 my $event = $_[1]; 34 $self->calculate_internals($event->args); 35 }); 36 37 $self->request_configinfo_events; 38 39 my $result = $self->SUPER::start; 40 41 $self->delete_handlers; 42 43 $self->add_handler(M_CONFIG_INFO, sub { 44 my $event = $_[1]; 45 my $name = $self->calculate_internals($event->args); 46 return unless defined $name; 47 $self->notify("value changed", $name); 48 }); 49 50 return $result; 51} 52 53sub calculate_internals ($$) { 54 my $self = shift; 55 my $args = shift; 56 my $data = $self->{data}; 57 58 my $text = $args->{text}; 59 $self->internal_die("No 'text' arg in M_CONFIG_INFO") 60 unless defined $text; 61 return undef if $text =~ /^(?:desktopsize|colorset|\*)/i; 62 63 return undef unless $text =~ /^(desktopname \d+|[^\s]+) (.*)$/i; 64 my $name = $1; 65 my $value = $2; 66 $self->{data}->{$name} = $value; 67 68 return $name; 69} 70 71sub data ($;$) { 72 my $self = shift; 73 my $name = shift; 74 my $data = $self->{data}; 75 return $data unless defined $name; 76 return $data->{$name}; 77} 78 79sub dump ($;$) { 80 my $self = shift; 81 my $name = shift; 82 my $data = $self->{data}; 83 my @names = defined $name? ($name): sort keys %$data; 84 85 my $string = ""; 86 foreach (@names) { 87 my $value = $data->{$_}; 88 $string .= "$_ $value\n"; 89 } 90 return $string; 91} 92 931; 94 95__END__ 96 97=head1 DESCRIPTION 98 99This is a subclass of B<FVWM::Tracker> that enables to read the global 100FVWM configuration. 101 102 "value changed" 103 104=head1 SYNOPSYS 105 106Using B<FVWM::Module> $module object: 107 108 my $config_tracker = $module->track("GlobalConfig"); 109 my $config_hash = $config_tracker->data; 110 my $image_path = $config_hash->{'ImagePath'}; 111 112or: 113 114 my $config_tracker = $module->track("GlobalConfig"); 115 my $xinerama_info = $config_tracker->data('XineramaConfig'); 116 my $desktop2_name = $config_tracker->data('DesktopName 2'); 117 118=head1 OVERRIDDEN METHODS 119 120=over 4 121 122=item B<data> [I<key>] 123 124Returns either hash ref of all global configuration values, or one value if 125I<key> is given. 126 127=item B<dump> [I<key>] 128 129Works similarly to B<data>, but returns debug lines for one or all global 130configuration values. 131 132=back 133 134=head1 AUTHOR 135 136Mikhael Goikhman <migo@homemail.com>. 137 138=head1 SEE ALSO 139 140For more information, see L<FVWM::Module> and L<FVWM::Tracker>. 141 142=cut 143