Commit a27a0cf2 authored by Jim Nelson's avatar Jim Nelson

#2229: Event name is now a date range for events spanning multiple days. ...

#2229: Event name is now a date range for events spanning multiple days.  #2599: If an event is named, the date (or date range) appears in its tooltip along with its name.  Both courtesy Wolfgang Steitz.
parent 76304ef3
......@@ -29,9 +29,9 @@ Louis-Francis Ratté-Boulianne <louis-francis@ratte-boulianne.com>
Martin Robinson <martin.james.robinson@gmail.com>
Clinton Rogers <clinton@yorba.org>
Elliott S <quantum.analyst@gmail.com>
Wolfgang Steitz <wolfer7@web.de>
Marcel Stimberg <stimberg@users.sourceforge.net>
Shan Xiong <shan.xiong@gmail.com>
wolfer <wolfer7@web.de>
Translations courtesy of:
......
......@@ -673,11 +673,28 @@ public class Event : EventSource, ContainerSource, Proxyable {
return get_raw_name();
// if no name, pretty up the start time
string? datestring = get_formatted_daterange();
return !is_string_empty(datestring) ? datestring : _("Event %s").printf(event_id.id.to_string());
}
public string? get_formatted_daterange() {
time_t start_time = get_start_time();
time_t end_time = get_end_time();
if (end_time == 0 && start_time == 0)
return null;
return (start_time != 0)
? format_local_date(Time.local(start_time))
: _("Event %s").printf(event_id.id.to_string());
if (end_time == 0 && start_time != 0)
return format_local_date(Time.local(start_time));
Time start = Time.local(start_time);
Time end = Time.local(end_time);
if (start.day == end.day && start.month == end.month && start.day == end.day)
return format_local_date(Time.local(start_time));
return format_local_datespan(start, end);
}
public string? get_raw_name() {
......@@ -809,4 +826,3 @@ public class Event : EventSource, ContainerSource, Proxyable {
base.destroy();
}
}
......@@ -72,8 +72,12 @@ class EventDirectoryItem : CheckerboardItem {
else
count_text = ngettext("%d Photo", "%d Photos", count).printf(count);
return "<b>%s</b>\n%s".printf(guarded_markup_escape_text(event.get_name()),
guarded_markup_escape_text(count_text));
if (event.has_name())
return "<b>%s</b>\n%s\n%s".printf(guarded_markup_escape_text(event.get_name()),
guarded_markup_escape_text(count_text), event.get_formatted_daterange());
else
return "<b>%s</b>\n%s".printf(guarded_markup_escape_text(event.get_name()),
guarded_markup_escape_text(count_text));
}
public override void exposed() {
......@@ -417,6 +421,12 @@ public class EventPage : CollectionPage {
return event.get_name();
}
public override string get_tooltip() {
return (event.has_name())
? String.strip_leading_zeroes("%s - %s".printf(event.get_name(), event.get_formatted_daterange()))
: event.get_formatted_daterange();
}
public override bool is_renameable() {
return (event != null);
}
......
......@@ -16,6 +16,10 @@ public abstract class PageStub : Object, SidebarPage {
public abstract string get_name();
public virtual string get_tooltip() {
return (page != null) ? page.get_tooltip() : get_name();
}
public virtual bool is_renameable() {
return false;
}
......@@ -314,6 +318,10 @@ public abstract class Page : Gtk.ScrolledWindow, SidebarPage {
return page_name;
}
public string get_tooltip() {
return page_name;
}
public void set_marker(SidebarMarker marker) {
this.marker = marker;
}
......@@ -2465,4 +2473,3 @@ public class DragAndDropHandler {
exporter = null;
}
}
......@@ -41,6 +41,8 @@ public class SidebarMarker : Object {
public interface SidebarPage : Object {
public abstract string get_sidebar_text();
public abstract string get_tooltip();
public abstract SidebarMarker? get_marker();
public abstract void set_marker(SidebarMarker marker);
......@@ -65,9 +67,26 @@ public interface SidebarPage : Object {
}
public class Sidebar : Gtk.TreeView {
// store = (page name, page, Icon, icon, expander-closed icon, expander-open icon)
private Gtk.TreeStore store = new Gtk.TreeStore(6, typeof(string), typeof(SidebarMarker),
typeof(GLib.Icon?), typeof(Gdk.Pixbuf?), typeof(Gdk.Pixbuf?), typeof(Gdk.Pixbuf?));
private enum Columns {
NAME,
TOOLTIP,
MARKER,
ICON,
PIXBUF,
CLOSED_PIXBUF,
OPEN_PIXBUF,
N_COLUMNS
}
private Gtk.TreeStore store = new Gtk.TreeStore(Columns.N_COLUMNS,
typeof(string), // NAME
typeof(string), // TOOLTIP
typeof(SidebarMarker), // MARKER
typeof(GLib.Icon?), // ICON
typeof(Gdk.Pixbuf?), // PIXBUF
typeof(Gdk.Pixbuf?), // CLOSED_PIXBUF
typeof(Gdk.Pixbuf?) // OPEN_PIXBUF
);
public signal void drop_received(Gdk.DragContext context, int x, int y,
Gtk.SelectionData selection_data, uint info, uint time, Gtk.TreePath? path, SidebarPage? page);
......@@ -89,14 +108,14 @@ public class Sidebar : Gtk.TreeView {
text_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED);
icon = new Gtk.CellRendererPixbuf();
text_column.pack_start(icon, false);
text_column.add_attribute(icon, "pixbuf", 3);
text_column.add_attribute(icon, "pixbuf_expander_closed", 4);
text_column.add_attribute(icon, "pixbuf_expander_open", 5);
text_column.add_attribute(icon, "pixbuf", Columns.PIXBUF);
text_column.add_attribute(icon, "pixbuf_expander_closed", Columns.CLOSED_PIXBUF);
text_column.add_attribute(icon, "pixbuf_expander_open", Columns.OPEN_PIXBUF);
text = new Gtk.CellRendererText();
text.editing_canceled.connect(on_editing_canceled);
text.editing_started.connect(on_editing_started);
text_column.pack_start(text, true);
text_column.add_attribute(text, "markup", 0);
text_column.add_attribute(text, "markup", Columns.NAME);
append_column(text_column);
Gtk.CellRendererText invisitext = new Gtk.CellRendererText();
......@@ -112,7 +131,7 @@ public class Sidebar : Gtk.TreeView {
set_reorderable(false);
set_enable_tree_lines(false);
set_grid_lines(Gtk.TreeViewGridLines.NONE);
set_tooltip_column(0);
set_tooltip_column(Columns.TOOLTIP);
Gtk.TreeSelection selection = get_selection();
selection.set_mode(Gtk.SelectionMode.BROWSE);
......@@ -236,7 +255,7 @@ public class Sidebar : Gtk.TreeView {
private void set_iter_icon(Gtk.TreeIter iter, GLib.Icon icon) {
// keep icon for theme change, some items have no page to request name from
store.set(iter, 2, icon);
store.set(iter, Columns.ICON, icon);
Gdk.Pixbuf? closed = null;
Gdk.Pixbuf? open = null;
......@@ -249,9 +268,9 @@ public class Sidebar : Gtk.TreeView {
if (closed == null) {
// icon_name is null OR icon not found, dont show an icon
store.set(iter, 3, null);
store.set(iter, 4, null);
store.set(iter, 5, null);
store.set(iter, Columns.PIXBUF, null);
store.set(iter, Columns.CLOSED_PIXBUF, null);
store.set(iter, Columns.OPEN_PIXBUF, null);
} else {
try {
if (icon.equal(icon_folder_closed))
......@@ -263,14 +282,14 @@ public class Sidebar : Gtk.TreeView {
if (open == null) {
// no expander-open icon, only load one icon
store.set(iter, 3, closed);
store.set(iter, 4, null);
store.set(iter, 5, null);
store.set(iter, Columns.PIXBUF, closed);
store.set(iter, Columns.CLOSED_PIXBUF, null);
store.set(iter, Columns.OPEN_PIXBUF, null);
} else {
// load expander-open and expander-closed icons
store.set(iter, 3, null);
store.set(iter, 4, closed);
store.set(iter, 5, open);
store.set(iter, Columns.PIXBUF, null);
store.set(iter, Columns.CLOSED_PIXBUF, closed);
store.set(iter, Columns.OPEN_PIXBUF, open);
}
}
}
......@@ -283,7 +302,7 @@ public class Sidebar : Gtk.TreeView {
public void reload_iter_and_child_icons(Gtk.TreeIter iter) {
GLib.Icon? icon;
store.get(iter, 2, out icon);
store.get(iter, Columns.ICON, out icon);
set_iter_icon(iter, icon);
Gtk.TreeIter child;
......@@ -312,8 +331,9 @@ public class Sidebar : Gtk.TreeView {
page.set_marker(marker);
// set up the columns
store.set(iter, 0, guarded_markup_escape_text(page.get_sidebar_text()));
store.set(iter, 1, marker);
store.set(iter, Columns.NAME, guarded_markup_escape_text(page.get_sidebar_text()));
store.set(iter, Columns.TOOLTIP, guarded_markup_escape_text(page.get_tooltip()));
store.set(iter, Columns.MARKER, marker);
set_iter_icon(iter, page.get_icon());
return marker;
......@@ -328,8 +348,9 @@ public class Sidebar : Gtk.TreeView {
SidebarMarker marker = new SidebarMarker(store, store.get_path(iter), position);
// set up the columns
store.set(iter, 0, guarded_markup_escape_text(name));
store.set(iter, 1, marker);
store.set(iter, Columns.NAME, guarded_markup_escape_text(name));
store.set(iter, Columns.TOOLTIP, guarded_markup_escape_text(name));
store.set(iter, Columns.MARKER, marker);
set_iter_icon(iter, icon);
return marker;
......@@ -347,7 +368,7 @@ public class Sidebar : Gtk.TreeView {
return null;
Value val;
store.get_value(iter, 1, out val);
store.get_value(iter, Columns.MARKER, out val);
return (SidebarMarker) val;
}
......@@ -620,7 +641,7 @@ public class Sidebar : Gtk.TreeView {
// set up the columns
Gtk.TreeIter iter;
store.get_iter(out iter, marker.get_path());
store.set(iter, 0, guarded_markup_escape_text(name));
store.set(iter, Columns.NAME, guarded_markup_escape_text(name));
}
public SidebarPage? get_parent_page(SidebarPage page) {
......
......@@ -279,19 +279,15 @@ public Gdk.Rectangle get_adjustment_page(Gtk.Adjustment hadj, Gtk.Adjustment vad
return rect;
}
public string format_local_datespan(Time from_date, Time to_date) {
string from_format = (from_date.year == to_date.year)? _("%a %b %d") : _("%a %b %d, %Y");
return String.strip_leading_zeroes("%s - %s".printf(from_date.format(from_format),
to_date.format(_("%a %b %d, %Y"))));
}
public string format_local_date(Time date) {
string date_string = date.format(_("%a %b %d, %Y"));
StringBuilder date_string_stripped = new StringBuilder("");
bool pre_is_space = true;
for (int i = 0; i < date_string.length; i++) {
if (pre_is_space && (date_string[i] == '0')) {
pre_is_space = false;
} else {
date_string_stripped.append_unichar(date_string[i]);
pre_is_space = date_string[i].isspace();
}
}
return date_string_stripped.str;
return String.strip_leading_zeroes(date.format(_("%a %b %d, %Y")));
}
// Verifies that only the mask bits are set in the modifier field, disregarding mouse and
......@@ -553,4 +549,3 @@ public bool is_twentyfour_hr_time_system() {
public string get_window_manager() {
return Gdk.x11_screen_get_window_manager_name(AppWindow.get_instance().get_screen());
}
......@@ -121,3 +121,23 @@ string asciify_string(string s) {
return b.str;
}
namespace String {
// Note that this method currently turns a word of all zeros into empty space ("000" -> "")
public string strip_leading_zeroes(string str) {
StringBuilder stripped = new StringBuilder();
bool prev_is_space = true;
for (unowned string iter = str; iter.get_char() != 0; iter = iter.next_char()) {
unichar ch = iter.get_char();
if (!prev_is_space || ch != '0') {
stripped.append_unichar(ch);
prev_is_space = ch.isspace();
}
}
return stripped.str;
}
}
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