| 1 | use Renard::Incunabula::Common::Setup; | ||
| 2 | package Renard::Curie::Component::DocumentPropertiesWindow; | ||
| 3 | # ABSTRACT: Component that implements a dialog with document metadata | ||
| 4 | $Renard::Curie::Component::DocumentPropertiesWindow::VERSION = '0.005'; | ||
| 5 | use Moo; | ||
| 6 | use Glib 'TRUE', 'FALSE'; | ||
| 7 | use Intertangle::API::Gtk3::Helper; | ||
| 8 | use Renard::Incunabula::Common::Types qw(InstanceOf); | ||
| 9 | use Renard::Incunabula::Document::Types qw(DocumentModel); | ||
| 10 | use Renard::Block::Format::PDF::InformationDictionary; | ||
| 11 | |||
| 12 | has document => ( | ||
| 13 | is => 'ro', | ||
| 14 | isa => DocumentModel, | ||
| 15 | required => 1, | ||
| 16 | ); | ||
| 17 | |||
| 18 | has _pdf_information_dictionary => ( | ||
| 19 | is => 'lazy', | ||
| 20 | isa => InstanceOf['Renard::Block::Format::PDF::InformationDictionary'], | ||
| 21 | ); | ||
| 22 | |||
| 23 | method _build__pdf_information_dictionary() { | ||
| 24 | my $filename = $self->document->filename; | ||
| 25 | |||
| 26 | Renard::Block::Format::PDF::InformationDictionary->new( | ||
| 27 | filename => $filename, | ||
| 28 | ); | ||
| 29 | } | ||
| 30 | |||
| 31 | method BUILD(@) { | ||
| 32 | my $log_win = $self->builder->get_object('prop-window'); | ||
| 33 | my $title = sprintf "Properties for %s", $self->document->filename; | ||
| 34 | $log_win->set_title($title); | ||
| 35 | $log_win->set_default_size(300, 300); | ||
| 36 | |||
| 37 | my $prop_grid = $self->builder->get_object('prop-grid'); | ||
| 38 | $prop_grid->set_column_spacing(5); | ||
| 39 | |||
| 40 | my $props = $self->_pdf_information_dictionary->default_properties; | ||
| 41 | my $row = 0; | ||
| 42 | for my $prop_key (@$props) { | ||
| 43 | my $prop_value = $self->_pdf_information_dictionary->$prop_key(); | ||
| 44 | my $label_key = Gtk3::Label->new( | ||
| 45 | "<b>$prop_key</b>" | ||
| 46 | ); | ||
| 47 | $label_key->set_use_markup(TRUE); | ||
| 48 | my $label_value = Gtk3::Label->new( | ||
| 49 | $prop_value | ||
| 50 | ); | ||
| 51 | |||
| 52 | for my $label ($label_key, $label_value) { | ||
| 53 | $label->set_line_wrap(TRUE); | ||
| 54 | if( $label->can('set_xalign' ) ) { | ||
| 55 | # for Gtk3 >= 3.16 | ||
| 56 | $label->set_xalign(0.0); | ||
| 57 | $label->set_yalign(0.0); | ||
| 58 | } else { | ||
| 59 | # for Gtk3 <= 3.14 | ||
| 60 | $label->set_alignment(0.0, 0.0); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | $label_value->set_selectable(TRUE); | ||
| 64 | |||
| 65 | $prop_grid->attach($label_key, 0, $row, 1, 1); | ||
| 66 | $prop_grid->attach($label_value, 1, $row, 1, 1); | ||
| 67 | |||
| 68 | $row++; | ||
| 69 | } | ||
| 70 | |||
| 71 | $self->builder->get_object('prop-ok-button')->signal_connect( | ||
| 72 | clicked => sub { $log_win->destroy } | ||
| 73 | ); | ||
| 74 | |||
| 75 | $self->builder->get_object('prop-ok-button')->grab_focus; | ||
| 76 | } | ||
| 77 | |||
| 78 | method show_all() { | ||
| 79 | $self->builder->get_object('prop-window')->show_all; | ||
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | with qw( | ||
| 84 | Intertangle::API::Gtk3::Component::Role::FromBuilder | ||
| 85 | Intertangle::API::Gtk3::Component::Role::UIFileFromPackageName | ||
| 86 | ); | ||
| 87 | |||
| 88 | |||
| 89 | 1; | ||
| 90 | |||
| 91 | __END__ |