Restructure how we look for Read files slightly.
[fvwm.git] / perllib / FVWM / Tracker / GlobalConfig.pm
blob6cd874701d71eb85abfc3d30c65816eb2dbdb27f
1 # Copyright (c) 2003-2009 Mikhael Goikhman
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.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 package FVWM::Tracker::GlobalConfig;
19 use strict;
21 use FVWM::Tracker qw(base);
23 sub observables ($) {
24 return [
25 "value updated",
29 sub start ($) {
30 my $self = shift;
32 $self->{data} = {};
33 $self->add_handler(M_CONFIG_INFO, sub {
34 my $event = $_[1];
35 $self->calculate_internals($event->args);
36 });
38 $self->request_configinfo_events;
40 my $result = $self->SUPER::start;
42 $self->delete_handlers;
44 $self->add_handler(M_CONFIG_INFO, sub {
45 my $event = $_[1];
46 my $name = $self->calculate_internals($event->args);
47 return unless defined $name;
48 $self->notify("value changed", $name);
49 });
51 return $result;
54 sub calculate_internals ($$) {
55 my $self = shift;
56 my $args = shift;
57 my $data = $self->{data};
59 my $text = $args->{text};
60 $self->internal_die("No 'text' arg in M_CONFIG_INFO")
61 unless defined $text;
62 return undef if $text =~ /^(?:desktopsize|colorset|\*)/i;
64 return undef unless $text =~ /^(desktopname \d+|[^\s]+) (.*)$/i;
65 my $name = $1;
66 my $value = $2;
67 $self->{data}->{$name} = $value;
69 return $name;
72 sub data ($;$) {
73 my $self = shift;
74 my $name = shift;
75 my $data = $self->{data};
76 return $data unless defined $name;
77 return $data->{$name};
80 sub dump ($;$) {
81 my $self = shift;
82 my $name = shift;
83 my $data = $self->{data};
84 my @names = defined $name? ($name): sort keys %$data;
86 my $string = "";
87 foreach (@names) {
88 my $value = $data->{$_};
89 $string .= "$_ $value\n";
91 return $string;
96 __END__
98 =head1 DESCRIPTION
100 This is a subclass of B<FVWM::Tracker> that enables to read the global
101 FVWM configuration.
103 "value updated"
105 =head1 SYNOPSYS
107 Using B<FVWM::Module> $module object:
109 my $config_tracker = $module->track("GlobalConfig");
110 my $config_hash = $config_tracker->data;
111 my $image_path = $config_hash->{'ImagePath'};
115 my $config_tracker = $module->track("GlobalConfig");
116 my $xinerama_info = $config_tracker->data('XineramaConfig');
117 my $desktop2_name = $config_tracker->data('DesktopName 2');
119 =head1 OVERRIDDEN METHODS
121 =over 4
123 =item B<data> [I<key>]
125 Returns either hash ref of all global configuration values, or one value if
126 I<key> is given.
128 =item B<dump> [I<key>]
130 Works similarly to B<data>, but returns debug lines for one or all global
131 configuration values.
133 =back
135 =head1 AUTHOR
137 Mikhael Goikhman <migo@homemail.com>.
139 =head1 SEE ALSO
141 For more information, see L<FVWM::Module> and L<FVWM::Tracker>.
143 =cut