| 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__ | ||
| 85 | |||
| 86 | =for stopwords RawLatest | ||
| 87 | |||
| 88 | =head1 NAME | ||
| 89 | |||
| 90 | App::Chart::Gtk2::RawLatest -- raw latest quote data display widget | ||
| 91 | |||
| 92 | =head1 SYNOPSIS | ||
| 93 | |||
| 94 | use App::Chart::Gtk2::RawLatest; | ||
| 95 | my $raw = App::Chart::Gtk2::RawLatest->new (symbol => 'FOO'); | ||
| 96 | |||
| 97 | =head1 WIDGET HIERARCHY | ||
| 98 | |||
| 99 | C<App::Chart::Gtk2::RawLatest> is a subclass of C<Gtk2::Label>. | ||
| 100 | |||
| 101 | Gtk2::Widget | ||
| 102 | Gtk2::Misc | ||
| 103 | Gtk2::Label | ||
| 104 | App::Chart::Gtk2::RawLatest | ||
| 105 | |||
| 106 | =head1 DESCRIPTION | ||
| 107 | |||
| 108 | A C<App::Chart::Gtk2::RawLatest> widget displays a raw latest record for a | ||
| 109 | given symbol. It updates with new latest records. | ||
| 110 | |||
| 111 | =head1 FUNCTIONS | ||
| 112 | |||
| 113 | =over 4 | ||
| 114 | |||
| 115 | =item C<< App::Chart::Gtk2::RawLatest->new (key=>value,...) >> | ||
| 116 | |||
| 117 | Create and return a new RawLatest widget. | ||
| 118 | |||
| 119 | =back | ||
| 120 | |||
| 121 | =head1 PROPERTIES | ||
| 122 | |||
| 123 | =over 4 | ||
| 124 | |||
| 125 | =item C<symbol> (string, default none) | ||
| 126 | |||
| 127 | The stock symbol whose latest record to display. | ||
| 128 | |||
| 129 | =back | ||
| 130 | |||
| 131 | =head1 SEE ALSO | ||
| 132 | |||
| 133 | L<App::Chart::Gtk2::RawDialog> | ||
| 134 | |||
| 135 | =cut |