[california/wip/725768-colors: 9/9] Further work
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/725768-colors: 9/9] Further work
- Date: Sat, 15 Mar 2014 02:07:26 +0000 (UTC)
commit ad652dc6a9032d8643d5f315b8dcd4ffe0d20242
Author: Jim Nelson <jim yorba org>
Date: Fri Mar 14 19:06:51 2014 -0700
Further work
Buttons in Calendar Manager now display color, active so clicking
will popup color chooser.
src/Makefile.am | 1 +
src/backing/backing-calendar-source.vala | 7 ---
src/backing/backing-source.vala | 26 +++++++++
src/backing/eds/backing-eds-calendar-source.vala | 26 +++-------
src/backing/eds/backing-eds-store.vala | 5 +--
src/manager/manager-calendar-list-item.vala | 19 +++++++
src/rc/calendar-manager-list-item.ui | 20 +++++++
src/util/util-gfx.vala | 62 ++++++++++++++++++++++
src/view/month/month-cell.vala | 2 +-
9 files changed, 137 insertions(+), 31 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4c6ac3b..8f76128 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,6 +74,7 @@ california_VALASOURCES = \
manager/manager-calendar-list-item.vala \
manager/manager-window.vala \
\
+ util/util-gfx.vala \
util/util-memory.vala \
util/util-string.vala \
\
diff --git a/src/backing/backing-calendar-source.vala b/src/backing/backing-calendar-source.vala
index c38eb89..67ddd64 100644
--- a/src/backing/backing-calendar-source.vala
+++ b/src/backing/backing-calendar-source.vala
@@ -14,13 +14,6 @@ namespace California.Backing {
*/
public abstract class CalendarSource : Source {
- /**
- * The suggested color to use when displaying the { link CalendarSource} or information
- * about or from it.
- */
- public Gdk.RGBA color { get; protected set;
- default = Gdk.RGBA() { red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0 }; }
-
protected CalendarSource(string title) {
base (title);
}
diff --git a/src/backing/backing-source.vala b/src/backing/backing-source.vala
index 022c9c6..55ebadc 100644
--- a/src/backing/backing-source.vala
+++ b/src/backing/backing-source.vala
@@ -20,6 +20,7 @@ public abstract class Source : BaseObject {
public const string PROP_IS_AVAILABLE = "is-available";
public const string PROP_TITLE = "title";
public const string PROP_VISIBLE = "visible";
+ public const string PROP_COLOR = "color";
/**
* True if the { link Source} is unavailable for use due to being removed from it's
@@ -49,6 +50,12 @@ public abstract class Source : BaseObject {
*/
public bool visible { get; set; }
+ /**
+ * The suggested color to use when displaying the { link Source} or information about or from
+ * it.
+ */
+ public string color { get; set; }
+
protected Source(string title) {
this.title = title;
}
@@ -65,6 +72,25 @@ public abstract class Source : BaseObject {
is_available = false;
}
+ /**
+ * Returns the current { link color} setting as a Gdk.Color.
+ *
+ * If the color string is unparseable, returns a Gdk.Color that corresponds to "dressy-black".
+ */
+ public Gdk.Color color_as_rgb() {
+ return Gfx.rgb_string_to_rgb(color, Gdk.Color() { red = 0, green = 0, blue = 0 }, null);
+ }
+
+ /**
+ * Returns the current { link color} setting as a Gdk.RGBA.
+ *
+ * If the color string is unparseable, returns a Gdk.RGBA that corresponds to "dressy-black".
+ */
+ public Gdk.RGBA color_as_rgba() {
+ return Gfx.rgb_string_to_rgba(color,
+ Gdk.RGBA() { red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0 }, null);
+ }
+
public override string to_string() {
return title;
}
diff --git a/src/backing/eds/backing-eds-calendar-source.vala
b/src/backing/eds/backing-eds-calendar-source.vala
index 7d627e0..0c9f9bb 100644
--- a/src/backing/eds/backing-eds-calendar-source.vala
+++ b/src/backing/eds/backing-eds-calendar-source.vala
@@ -28,9 +28,11 @@ internal class EdsCalendarSource : CalendarSource {
// use unidirectional bindings so source updates (writing) only occurs when changed from
// within the app
eds_calendar.bind_property("selected", this, PROP_VISIBLE, BindingFlags.SYNC_CREATE);
+ eds_calendar.bind_property("color", this, PROP_COLOR, BindingFlags.SYNC_CREATE);
// when changed within the app, need to write it back out
notify[PROP_VISIBLE].connect(on_visible_changed);
+ notify[PROP_COLOR].connect(on_color_changed);
}
~EdsCalendarSource() {
@@ -46,27 +48,13 @@ internal class EdsCalendarSource : CalendarSource {
schedule_source_write("visible=%s".printf(visible.to_string()));
}
- private void update_calendar_color() {
- Gdk.Color rgb;
- if (!Gdk.Color.parse(eds_calendar.color, out rgb)) {
- debug("Unable to parse calendar color for %s: %s", to_string(), eds_calendar.color.to_string());
-
+ private void on_color_changed() {
+ // only schedule writes if something changed
+ if (eds_calendar.color == color)
return;
- }
-
- Gdk.RGBA rgba = {
- red: conv(rgb.red),
- green: conv(rgb.green),
- blue: conv(rgb.blue),
- alpha: 1.0
- };
- color = rgba;
- }
-
- // compiler error if this calculation is done inline when initializing struct
- private inline double conv(uint16 value) {
- return (double) value / (double) uint16.MAX;
+ eds_calendar.color = color;
+ schedule_source_write("color=%s".printf(color));
}
private void schedule_source_write(string reason) {
diff --git a/src/backing/eds/backing-eds-store.vala b/src/backing/eds/backing-eds-store.vala
index 49b9516..79c7173 100644
--- a/src/backing/eds/backing-eds-store.vala
+++ b/src/backing/eds/backing-eds-store.vala
@@ -52,13 +52,10 @@ internal class EdsStore : Store {
}
private async void add_eds_source_async(E.Source eds_source) {
- if (!eds_source.enabled)
- return;
-
// only interested in calendars for now
E.SourceCalendar? eds_calendar =
eds_source.get_extension(E.SOURCE_EXTENSION_CALENDAR) as E.SourceCalendar;
- if (eds_calendar == null || !eds_calendar.selected)
+ if (eds_calendar == null)
return;
EdsCalendarSource calendar = new EdsCalendarSource(eds_source, eds_calendar);
diff --git a/src/manager/manager-calendar-list-item.vala b/src/manager/manager-calendar-list-item.vala
index 87c1e6c..cae9e95 100644
--- a/src/manager/manager-calendar-list-item.vala
+++ b/src/manager/manager-calendar-list-item.vala
@@ -12,6 +12,8 @@ namespace California.Manager {
[GtkTemplate (ui = "/org/yorba/california/rc/calendar-manager-list-item.ui")]
public class CalendarListItem : Gtk.Grid {
+ private const int COLOR_DIM = 16;
+
public Backing.CalendarSource source { get; private set; }
[GtkChild]
@@ -20,6 +22,9 @@ public class CalendarListItem : Gtk.Grid {
[GtkChild]
private Gtk.Label title_label;
+ [GtkChild]
+ private Gtk.Button color_button;
+
public CalendarListItem(Backing.CalendarSource source) {
this.source = source;
@@ -27,6 +32,20 @@ public class CalendarListItem : Gtk.Grid {
BindingFlags.SYNC_CREATE);
source.bind_property(Backing.Source.PROP_VISIBLE, visible_check_button, "active",
BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+
+ on_color_changed();
+ source.notify[Backing.Source.PROP_COLOR].connect(on_color_changed);
+ }
+
+ private void on_color_changed() {
+ Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(Gdk.Colorspace.RGB, false, 8, COLOR_DIM, COLOR_DIM);
+ pixbuf.fill(Gfx.rgba_to_pixel(source.color_as_rgba()));
+
+ color_button.set_image(new Gtk.Image.from_pixbuf(pixbuf));
+ }
+
+ [GtkCallback]
+ private void on_color_button_clicked() {
}
}
diff --git a/src/rc/calendar-manager-list-item.ui b/src/rc/calendar-manager-list-item.ui
index b081b42..0a8647e 100644
--- a/src/rc/calendar-manager-list-item.ui
+++ b/src/rc/calendar-manager-list-item.ui
@@ -40,6 +40,26 @@
<property name="single_line_mode">True</property>
</object>
<packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="color_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Calendar color</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <signal name="clicked" handler="on_color_button_clicked" object="CaliforniaManagerCalendarListItem"
swapped="no"/>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
diff --git a/src/util/util-gfx.vala b/src/util/util-gfx.vala
new file mode 100644
index 0000000..07b8ec4
--- /dev/null
+++ b/src/util/util-gfx.vala
@@ -0,0 +1,62 @@
+/* Copyright 2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+namespace California.Gfx {
+
+public Gdk.Color rgb_string_to_rgb(string rgb_string, Gdk.Color default_rgb, out bool used_default) {
+ Gdk.Color rgb;
+ if (!Gdk.Color.parse(rgb_string, out rgb)) {
+ debug("Unable to parse calendar color \"%s\"", rgb_string);
+
+ used_default = true;
+
+ return default_rgb;
+ }
+
+ used_default = false;
+
+ return rgb;
+}
+
+public Gdk.RGBA rgb_string_to_rgba(string rgb_string, Gdk.RGBA default_rgba, out bool used_default) {
+ Gdk.Color rgb;
+ if (!Gdk.Color.parse(rgb_string, out rgb)) {
+ debug("Unable to parse calendar color \"%s\"", rgb_string);
+
+ used_default = true;
+
+ return default_rgba;
+ }
+
+ Gdk.RGBA rgba = {
+ red: uint16_to_fp(rgb.red),
+ green: uint16_to_fp(rgb.green),
+ blue: uint16_to_fp(rgb.blue),
+ alpha: 1.0
+ };
+
+ used_default = false;
+
+ return rgba;
+}
+
+// compiler error if this calculation is done inline when initializing struct
+private inline double uint16_to_fp(uint16 value) {
+ return (double) value / (double) uint16.MAX;
+}
+
+public uint32 rgba_to_pixel(Gdk.RGBA rgba) {
+ return (uint32) fp_to_uint8(rgba.red) << 24
+ | (uint32) fp_to_uint8(rgba.green) << 16
+ | (uint32) fp_to_uint8(rgba.blue) << 8
+ | (uint32) fp_to_uint8(rgba.alpha);
+}
+
+private inline uint8 fp_to_uint8(double value) {
+ return (uint8) (value * 255.0);
+}
+
+}
diff --git a/src/view/month/month-cell.vala b/src/view/month/month-cell.vala
index 6264e2c..be85b69 100644
--- a/src/view/month/month-cell.vala
+++ b/src/view/month/month-cell.vala
@@ -255,7 +255,7 @@ public class Cell : Gtk.EventBox {
text = "%s %s".printf(local_start.to_pretty_time_string(PRETTY_TIME_FLAGS), event.summary);
}
- Pango.Layout layout = draw_line_of_text(ctx, line_number, event.calendar_source.color,
+ Pango.Layout layout = draw_line_of_text(ctx, line_number, event.calendar_source.color_as_rgba(),
text);
line_to_event.set(line_number++, event);
event.set_data<string?>(KEY_TOOLTIP, layout.is_ellipsized() ? text : null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]