src/PropertyDetailView.vala (4901B) - raw
1 /*
2 * xmpedit
3 * Copyright 2010 Dan Callaghan <djc@djc.id.au>
4 * Released under GPLv2
5 */
6
7 namespace Xmpedit {
8
9 private class DescriptionView : Gtk.Table {
10
11 public Description description { get; construct; }
12
13 public DescriptionView(Description description) {
14 Object(description: description);
15 }
16
17 construct {
18 n_rows = 2;
19 n_columns = 2;
20 homogeneous = false;
21
22 var text_view = new Gtk.TextView();
23 text_view.wrap_mode = Gtk.WrapMode.WORD;
24
25 var label = new Gtk.Label(description.display_name());
26 label.xalign = 0;
27 label.mnemonic_widget = text_view;
28 attach(label,
29 0, 1, 0, 1,
30 Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, 0,
31 0, 0);
32 set_row_spacing(0, 4);
33
34 var lang_hbox = new Gtk.HBox(/* homogeneous */ false, /* spacing */ 4);
35 var lang_entry = new Gtk.Entry(); // XXX make a combo
36 lang_entry.width_chars = 8;
37 var lang_label = new Gtk.Label("Language:");
38 lang_label.xalign = 1;
39 lang_label.mnemonic_widget = lang_entry;
40 lang_hbox.add(lang_label);
41 lang_hbox.add(lang_entry);
42 attach(lang_hbox,
43 1, 2, 0, 1,
44 0, 0,
45 0, 0);
46 set_col_spacing(0, 10);
47
48 var text_scrolled = new Gtk.ScrolledWindow(null, null);
49 text_scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
50 text_scrolled.shadow_type = Gtk.ShadowType.ETCHED_IN;
51 text_scrolled.add(text_view);
52 attach(text_scrolled,
53 0, 2, 1, 2,
54 Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND,
55 0, 0);
56
57
58 text_view.buffer.text = description.value;
59 lang_entry.text = description.lang;
60 text_view.buffer.changed.connect(() => {
61 description.value = text_view.buffer.text;
62 });
63 lang_entry.changed.connect(() => {
64 description.lang = lang_entry.text;
65 });
66 }
67
68 }
69
70 private class CustomMap : OsmGpsMap.Map {
71
72 public CustomMap() {
73 Object(repo_uri: "http://mt#R.google.com/vt/lyrs=m@138&hl=en&x=#X&s=&y=#Y&z=#Z");
74 }
75
76 construct {
77 var osd = new OsmGpsMap.Osd();
78 osd.show_scale = true;
79 osd.show_coordinates = false;
80 layer_add(osd);
81 }
82
83 }
84
85 private class LocationView : Gtk.Table {
86
87 public Location location { get; construct; }
88
89 public LocationView(Location location) {
90 Object(location: location);
91 }
92
93 construct {
94 n_rows = 2;
95 n_columns = 1;
96 homogeneous = false;
97 set_row_spacing(0, 8);
98
99 var map = new CustomMap();
100 attach(map,
101 0, 1, 0, 1,
102 Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND,
103 Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND,
104 0, 0);
105
106 var location_hbox = new Gtk.HBox(/* homogeneous */ false, /* spacing */ 4);
107 var location_entry = new Gtk.Entry(); // XXX make a combo
108 //location_entry.width_chars = 8;
109 var location_label = new Gtk.Label("Location:");
110 location_label.xalign = 0;
111 location_label.mnemonic_widget = location_entry;
112 location_hbox.pack_start(location_label,
113 /* expand */ false, /* fill */ false, /* padding */ 0);
114 location_hbox.pack_start(location_entry,
115 /* expand */ true, /* fill */ true, /* padding */ 0);
116 attach(location_hbox,
117 0, 1, 1, 2,
118 Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, 0,
119 0, 0);
120
121 location_entry.text = location.location;
122 location_entry.changed.connect(() => {
123 location.location = location_entry.text;
124 });
125 }
126
127 }
128
129 public class PropertyDetailView : Gtk.Alignment {
130
131 public MetadataTreeView tree_view { get; construct; }
132
133 public PropertyDetailView.connected_to(ImageMetadata image_metadata, MetadataTreeView tree_view) {
134 Object(tree_view: tree_view);
135 }
136
137 construct {
138 set_padding(0, 10, 10, 10);
139 tree_view.cursor_changed.connect(() => {
140 Gtk.TreeIter iter;
141 tree_view.get_selection().get_selected(null, out iter);
142 Value value;
143 tree_view.model.get_value(iter, 0, out value);
144 var p = (ImageProperty) value.get_object();
145 if (child != null) {
146 remove(child);
147 }
148 add(construct_view(p));
149 child.show_all();
150 });
151 }
152
153 private static Gtk.Widget construct_view(ImageProperty p) {
154 if (p is Description)
155 return new DescriptionView((Description) p);
156 if (p is Location)
157 return new LocationView((Location) p);
158 return_val_if_reached(null);
159 }
160
161 }
162
163 }