5
public class PropertyDialog : Granite.Widgets.LightWindow {
7
private Library library;
9
private EventBox cover_box;
10
private bool loading_cover = false;
13
public PropertyDialog(Gtk.Window parent, Library lib, Book b) {
16
set_transient_for (parent);
19
Grid main_grid = new Grid ();
21
Image cover = new Image.from_pixbuf (b.cover);
22
cover_box = new EventBox();
23
cover_box.width_request = LibraryView.ICON_W;
24
cover_box.height_request = LibraryView.ICON_H;
25
cover_box.button_press_event.connect (() => {
26
request_cover_change ();
29
cover_box.add (cover);
30
book.cover_changed.connect (() => {
31
Image new_cover = new Image.from_pixbuf (b.cover);
32
cover_box.remove (cover_box.get_child ());
33
cover_box.add (new_cover);
38
Grid cover_grid = new Grid();
39
cover_grid.attach (cover_box, 1, 1, 1, 1);
40
main_grid.attach (cover_grid, 0, 0, 1, 2);
42
main_grid.attach (make_field (N_("Name")), 1, 0, 1, 1);
43
main_grid.attach (make_field (N_("Author")), 1, 1, 1, 1);
44
Gtk.Separator separator_top_desc = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
45
separator_top_desc.hexpand = true;
46
main_grid.attach (separator_top_desc, 0, 2, 2, 1);
47
main_grid.attach (make_field (N_("Description")), 0, 3, 2, 1);
49
Gtk.Separator separator_bot_desc = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
50
separator_bot_desc.hexpand = true;
51
main_grid.attach (separator_bot_desc, 0, 4, 2, 1);
59
private Grid make_field (string name) {
60
Grid result = new Grid ();
62
Gtk.Grid spanner = new Grid();
63
spanner.hexpand = true;
65
Label label = new Label (_(name));
67
result.attach (label, 1, 0, 1, 1);
69
Widget value_field = null;
72
Entry entry = new Entry ();
73
entry.text = book.name;
74
entry.changed.connect (() => {
75
book.name = entry.text;
78
result.attach (spanner, 0, 0, 1, 1);
80
case N_("Description"):
81
TextView entry = new TextView ();
84
entry.buffer.text = book.desc;
85
entry.buffer.changed.connect (() => {
86
book.desc = entry.buffer.text;
91
Entry entry = new Entry ();
92
entry.text = book.author;
93
entry.changed.connect (() => {
94
book.author = entry.text;
97
result.attach (spanner, 0, 0, 1, 1);
100
result.attach (value_field, 2, 0, 1, 1);
105
public void request_cover_change () {
108
loading_cover = true;
111
string filename = "";
112
var filechooser = new Gtk.FileChooserDialog ("Title", this,
113
Gtk.FileChooserAction.OPEN, Gtk.Stock.CANCEL,
114
Gtk.ResponseType.CANCEL, Gtk.Stock.OPEN, Gtk.ResponseType.OK);
116
if (filechooser.run () == Gtk.ResponseType.OK)
118
filename = filechooser.get_filename ();
120
filechooser.destroy ();
122
if (filename == "") {
123
loading_cover = false;
127
File file1 = File.new_for_path (filename);
128
File file2 = File.new_for_path (BookWorm.get_data_dir()
129
+ "icon_lib/" + book.id.to_string ());
131
Spinner spinner = new Spinner ();
132
spinner.width_request = LibraryView.ICON_W;
133
spinner.height_request = LibraryView.ICON_H;
134
cover_box.remove (cover_box.get_child ());
135
cover_box.add (spinner);
138
file1.copy_async.begin (file2, FileCopyFlags.OVERWRITE, Priority.DEFAULT,
139
null, null, (obj, res) => {
140
book.reload_cover ();
141
loading_cover = false;
144
warning ("Errddor: %s\n", e.message);