Commit ed09d96e authored by Allison Barlow's avatar Allison Barlow

the basic properties display now updates with multiple selection.

parent 39eeb57c
......@@ -836,8 +836,10 @@ public class LibraryWindow : AppWindow {
new_action.set_active(old_action.get_active());
// unsubscribe to the basic properties display signal (new page subscribes below)
// old page unsubscribes to these signals (new page subscribes below)
current_page.selection_changed -= on_selection_changed;
current_page.contents_changed -= on_selection_changed;
current_page.queryable_altered -= on_selection_changed;
}
int pos = get_notebook_pos(page);
......@@ -865,8 +867,10 @@ public class LibraryWindow : AppWindow {
on_selection_changed();
// subscribe to this signal for each event page so basic properties display will update
// subscribe to these signals for each event page so basic properties display will update
current_page.selection_changed += on_selection_changed;
current_page.contents_changed += on_selection_changed;
current_page.queryable_altered += on_selection_changed;
}
private bool is_page_selected(Page page, Gtk.TreePath path) {
......
......@@ -13,6 +13,10 @@ private class BasicProperties : Gtk.HBox {
private Dimensions dimensions;
private uint64 filesize;
private int photo_count;
private int event_count;
string basic_properties_labels;
string basic_properties_info;
bool first_line;
public BasicProperties() {
label.set_justify(Gtk.Justification.RIGHT);
......@@ -23,124 +27,199 @@ private class BasicProperties : Gtk.HBox {
info.set_ellipsize(Pango.EllipsizeMode.END);
}
private void add_line(string label, string info) {
if (!first_line) {
basic_properties_labels += "\n";
basic_properties_info += "\n";
}
basic_properties_labels += label;
basic_properties_info += info;
first_line = false;
}
private string get_prettyprint_time(Time time) {
return "%d:%02d %s".printf((time.hour-1)%12+1, time.minute,
return "%d:%02d %s".printf(((time.hour + 11) % 12) + 1, time.minute,
time.hour < 12 ? "AM" : "PM");
}
private string get_prettyprint_date(Time time) {
return time.format("%a %b") + " %d, %d".printf(time.day, 1900 + time.year);
private string get_prettyprint_date(Time date) {
string date_string = "";
Time today = Time.local(time_t());
if (date.day_of_year == today.day_of_year && date.year == today.year) {
date_string = "Today";
} else if (date.day_of_year == (today.day_of_year - 1) && date.year == today.year) {
date_string = "Yesterday";
} else {
date_string = date.format("%a %b") + " %d, %d".printf(date.day, 1900 + date.year);
}
return date_string;
}
private void set_text(string new_label, string new_info) {
label.set_text(new_label);
info.set_text(new_info);
private void set_text() {
label.set_text(basic_properties_labels);
info.set_text(basic_properties_info);
}
public void clear_properties() {
title = "";
start_time = time_t();
end_time = time_t();
start_time = 0;
end_time = 0;
dimensions = Dimensions(0,0);
filesize = 0;
photo_count = -1;
event_count = -1;
basic_properties_labels = "";
basic_properties_info = "";
first_line = true;
}
private void get_single_properties(Queryable queryable) {
title = queryable.get_name();
if (queryable is PhotoSource) {
PhotoSource photo_source = queryable as PhotoSource;
start_time = photo_source.get_exposure_time();
end_time = start_time;
dimensions = photo_source.get_dimensions();
filesize = photo_source.get_filesize();
} else if (queryable is EventSource) {
EventSource event_source = queryable as EventSource;
start_time = event_source.get_start_time();
end_time = event_source.get_end_time();
filesize = event_source.get_total_filesize();
photo_count = event_source.get_photo_count();
}
}
private void get_multiple_properties(Gee.Iterable<Queryable>? queryables) {
photo_count = 0;
foreach (Queryable queryable in queryables) {
if (queryable is PhotoSource) {
PhotoSource photo_source = queryable as PhotoSource;
time_t exposure_time = photo_source.get_exposure_time();
if (exposure_time != 0) {
if (start_time == 0 || exposure_time < start_time)
start_time = exposure_time;
if (end_time == 0 || exposure_time > end_time)
end_time = exposure_time;
}
filesize += photo_source.get_filesize();
photo_count += 1;
} else if (queryable is EventSource) {
EventSource event_source = queryable as EventSource;
if (event_count == -1)
event_count = 0;
if ((start_time == 0 || event_source.get_start_time() < start_time) &&
event_source.get_start_time() != 0 ) {
start_time = event_source.get_start_time();
}
if ((end_time == 0 || event_source.get_end_time() > end_time) &&
event_source.get_end_time() != 0 ) {
end_time = event_source.get_end_time();
} else if (end_time == 0 || event_source.get_start_time() > end_time) {
end_time = event_source.get_start_time();
}
filesize += event_source.get_total_filesize();
photo_count += event_source.get_photo_count();
event_count += 1;
}
}
}
private void get_properties(Page current_page) {
int count = current_page.get_selected_queryable_count();
Gee.Iterable<Queryable>? queryables = current_page.get_selected_queryables();
if (count == 0) {
count = current_page.get_queryable_count();
queryables = current_page.get_queryables();
}
if (queryables == null || count == 0)
return;
if (count == 1) {
foreach (Queryable queryable in queryables)
get_single_properties(queryable);
} else {
get_multiple_properties(queryables);
}
if (end_time == 0)
end_time = start_time;
if (start_time == 0)
start_time = end_time;
}
public void update_properties(Page current_page) {
clear_properties();
get_properties(current_page);
string basic_properties_labels = "";
string basic_properties_info = "";
if (title != "") {
basic_properties_labels += "Title:";
basic_properties_info += title;
}
if (title != "")
add_line("Title:",title);
if (photo_count >= 0) {
basic_properties_labels += "\nItems:";
basic_properties_info += "\n%d".printf(photo_count);
basic_properties_info += photo_count == 1 ? " Photo" : " Photos";
string label = "Items:";
if (event_count >= 0) {
add_line(label, "%d Event%s".printf(event_count, event_count == 1 ? "" : "s"));
label = "";
}
add_line(label, "%d Photo%s".printf(photo_count, photo_count == 1 ? "" : "s"));
}
if (start_time != time_t()) {
if (start_time != 0) {
string start_date = get_prettyprint_date(Time.local(start_time));
string start_time = get_prettyprint_time(Time.local(start_time));
string end_date = get_prettyprint_date(Time.local(end_time));
string end_time = get_prettyprint_time(Time.local(end_time));
if (start_date == end_date) {
basic_properties_labels += "\nDate:";
basic_properties_info += "\n" + start_date;
if (start_date == end_date && start_time == end_time) {
basic_properties_labels += "\nTime:";
basic_properties_info += "\n" + start_time;
// display only one date if start and end are the same
add_line("Date:", start_date);
if (start_time == end_time) {
// display only one time if start and end are the same
add_line("Time:", start_time);
} else {
basic_properties_labels += "\nTime:\n";
basic_properties_info += "\n" + start_time + " to\n" + end_time;
// display time range
add_line("From:", start_time);
add_line("To:", end_time);
}
} else {
basic_properties_labels += "\nDate:\n";
basic_properties_info += "\n" + start_date + " to\n" + end_date;
}
// display date range
add_line("From:", start_date);
add_line("To:", end_date);
}
}
if (filesize > 0 || (dimensions.width != 0 && dimensions.height != 0)) {
basic_properties_labels += "\nSize:";
if (filesize > 0 || dimensions.has_area()) {
string label = "Size:";
if (filesize > 0 && (dimensions.width != 0 && dimensions.height != 0)) {
basic_properties_labels += "\n";
if (dimensions.has_area()) {
add_line(label, "%d x %d".printf(dimensions.width, dimensions.height));
label = "";
}
if (dimensions.width != 0 && dimensions.height != 0) {
basic_properties_info += "\n%d x %d".printf(dimensions.width, dimensions.height);
}
if (filesize > 0) {
basic_properties_info += "\n" + format_size_for_display((int64) filesize);
}
if (filesize > 0)
add_line(label, format_size_for_display((int64) filesize));
}
set_text(basic_properties_labels, basic_properties_info);
}
private void get_properties(Page current_page) {
int count = current_page.get_selected_queryable_count();
Gee.Iterable<Queryable>? queryables = current_page.get_selected_queryables();
if (queryables == null)
return;
if (count == 1) {
foreach (Queryable queryable in queryables) {
title = queryable.get_name();
if (queryable is PhotoSource) {
PhotoSource photo_source = queryable as PhotoSource;
start_time = photo_source.get_exposure_time();
end_time = start_time;
dimensions = photo_source.get_dimensions();
filesize = photo_source.get_filesize();
} else if (queryable is EventSource) {
EventSource event_source = queryable as EventSource;
start_time = event_source.get_start_time();
end_time = event_source.get_end_time();
if (end_time == 0) {
end_time = start_time;
}
filesize = event_source.get_total_filesize();
photo_count = event_source.get_photo_count();
}
}
} else if (count == 0) {
count = current_page.get_queryable_count();
queryables = current_page.get_queryables();
}
set_text();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment