| 1 | # Copyright 2007, 2008, 2009, 2010, 2011 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | package App::Chart::Weblink; | ||
| 18 | use 5.006; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use Carp; | ||
| 22 | # use Locale::TextDomain ('App-Chart'); | ||
| 23 | |||
| 24 | use App::Chart; | ||
| 25 | |||
| 26 | # uncomment this to run the ### lines | ||
| 27 | #use Smart::Comments; | ||
| 28 | |||
| 29 | our @weblinks_list = (); | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | my ($class, %self) = @_; | ||
| 33 | my $self = bless \%self, $class; | ||
| 34 | require App::Chart::Sympred; | ||
| 35 | App::Chart::Sympred::validate ($self->{'pred'}); | ||
| 36 | if (! ($self->{'url'} || $self->{'proc'})) { | ||
| 37 | croak "Missing weblink url or proc\n"; | ||
| 38 | } | ||
| 39 | if (! $self->{'name'}) { | ||
| 40 | croak "Missing weblink name"; | ||
| 41 | } | ||
| 42 | |||
| 43 | push @weblinks_list, $self; | ||
| 44 | @weblinks_list = sort { $a->{'name'} cmp $b->{'name'} } @weblinks_list; | ||
| 45 | return $self; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub links_for_symbol { | ||
| 49 | my ($class, $symbol) = @_; | ||
| 50 | App::Chart::symbol_setups ($symbol); | ||
| 51 | return grep { $_->{'pred'}->match($symbol) } @weblinks_list; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub url { | ||
| 55 | my ($self, $symbol) = @_; | ||
| 56 | return $self->{'url'} | ||
| 57 | || $self->{'proc'}->($symbol); | ||
| 58 | } | ||
| 59 | |||
| 60 | sub name { | ||
| 61 | my ($self) = @_; | ||
| 62 | return $self->{'name'}; | ||
| 63 | } | ||
| 64 | |||
| 65 | sub sensitive { | ||
| 66 | my ($self, $symbol) = @_; | ||
| 67 | # But should check without any downloading ... | ||
| 68 | return scalar ($self->url ($symbol)); | ||
| 69 | } | ||
| 70 | |||
| 71 | sub open { | ||
| 72 | my ($self, $symbol, $parent) = @_; | ||
| 73 | my $url = $self->url($symbol); | ||
| 74 | require App::Chart::Gtk2::GUI; | ||
| 75 | App::Chart::Gtk2::GUI::browser_open ($url, $parent); | ||
| 76 | } | ||
| 77 | |||
| 78 | 1; | ||
| 79 | __END__ |