| 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::Gtk2::RawLatest; | ||
| 18 | use strict; | ||
| 19 | use warnings; | ||
| 20 | use Gtk2; | ||
| 21 | use List::Util; | ||
| 22 | use Locale::TextDomain ('App-Chart'); | ||
| 23 | |||
| 24 | use Glib::Object::Subclass | ||
| 25 | 'Gtk2::Label', | ||
| 26 | properties => [Glib::ParamSpec->string | ||
| 27 | ('symbol', | ||
| 28 | __('Symbol'), | ||
| 29 | 'Blurb.', | ||
| 30 | '', | ||
| 31 | Glib::G_PARAM_READWRITE), | ||
| 32 | ]; | ||
| 33 | |||
| 34 | |||
| 35 | sub INIT_INSTANCE { | ||
| 36 | my ($self) = @_; | ||
| 37 | $self->set_alignment (0, 0); | ||
| 38 | App::Chart::chart_dirbroadcast()->connect_for_object | ||
| 39 | ('latest-changed', \&_do_latest_changed, $self); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub SET_PROPERTY { | ||
| 43 | my ($self, $pspec, $newval) = @_; | ||
| 44 | my $pname = $pspec->get_name; | ||
| 45 | ### RawLatest SET_PROPERTY: "$pname $newval" | ||
| 46 | |||
| 47 | $self->{$pname} = $newval; # per default GET_PROPERTY | ||
| 48 | |||
| 49 | if ($pname eq 'symbol') { | ||
| 50 | $self->refresh; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | # 'latest-changed' handler | ||
| 55 | sub _do_latest_changed { | ||
| 56 | my ($self, $symbol_hash) = @_; | ||
| 57 | my $symbol = $self->{'symbol'}; | ||
| 58 | if (exists $symbol_hash->{$symbol}) { | ||
| 59 | $self->refresh; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | sub refresh { | ||
| 64 | my ($self) = @_; | ||
| 65 | my $symbol = $self->{'symbol'}; | ||
| 66 | my $str; | ||
| 67 | if (defined $symbol) { | ||
| 68 | ### RawLatest refresh: $symbol | ||
| 69 | require App::Chart::DBI; | ||
| 70 | my $dbh = App::Chart::DBI->instance; | ||
| 71 | my $sth = $dbh->prepare_cached ('SELECT * FROM latest WHERE symbol=?'); | ||
| 72 | my $h = $dbh->selectrow_hashref ($sth, undef, $symbol); | ||
| 73 | |||
| 74 | require Data::Dumper; | ||
| 75 | my $dumper = Data::Dumper->new ([$h],['latest']); | ||
| 76 | $dumper->Sortkeys(1); | ||
| 77 | $dumper->Quotekeys(0); | ||
| 78 | $str = $dumper->Dump; | ||
| 79 | } | ||
| 80 | $self->set_text ($str); | ||
| 81 | } | ||
| 82 | |||
| 83 | 1; | ||
| 84 | __END__ |