[california/wip/calendar-spans: 1/2] Laying the groundwork
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/calendar-spans: 1/2] Laying the groundwork
- Date: Fri, 2 May 2014 00:41:13 +0000 (UTC)
commit 1532ce74d5ea4b9e6e06e478a1032d21d993996b
Author: Jim Nelson <jim yorba org>
Date: Thu May 1 17:39:21 2014 -0700
Laying the groundwork
src/Makefile.am | 4 +
src/view/month/month-controller.vala | 24 +-------
src/view/view-controllable.vala | 11 +---
src/view/week/week-controller.vala | 109 ++++++++++++++++++++++++++++++++++
src/view/week/week-grid.vala | 27 ++++++++
src/view/week/week.vala | 35 +++++++++++
6 files changed, 179 insertions(+), 31 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 30fa900..62dcd01 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -131,6 +131,10 @@ california_VALASOURCES = \
view/month/month-controller.vala \
view/month/month-grid.vala \
\
+ view/week/week.vala \
+ view/week/week-controller.vala \
+ view/week/week-grid.vala \
+ \
$(NULL)
california_SOURCES = \
diff --git a/src/view/month/month-controller.vala b/src/view/month/month-controller.vala
index fb3dec3..7197655 100644
--- a/src/view/month/month-controller.vala
+++ b/src/view/month/month-controller.vala
@@ -161,29 +161,19 @@ public class Controller : BaseObject, View.Controllable {
/**
* @inheritDoc
*/
- public void prev() {
+ public void previous() {
month_of_year = month_of_year.previous();
}
/**
* @inheritDoc
*/
- public Gtk.Widget today() {
+ public void today() {
// since changing the date is expensive in terms of adding/removing subscriptions, only
// update the property if it's actually different
Calendar.MonthOfYear now = Calendar.System.today.month_of_year();
if (!now.equal_to(month_of_year))
month_of_year = now;
-
- // current should be set by the month_of_year being set
- Grid? current_grid = get_current_month_grid();
- assert(current_grid != null);
-
- // this grid better have a cell with this date in it
- Cell? cell = current_grid.get_cell_for_date(Calendar.System.today);
- assert(cell != null);
-
- return cell;
}
/**
@@ -215,16 +205,6 @@ public class Controller : BaseObject, View.Controllable {
current_label = month_of_year.full_name;
update_is_viewing_today();
- // default date is first of month unless displaying current month, in which case it's
- // current date
- try {
- default_date = is_viewing_today ? Calendar.System.today
- : month_of_year.date_for(month_of_year.first_day_of_month());
- } catch (CalendarError calerr) {
- // this should always work
- error("Unable to set default date for %s: %s", month_of_year.to_string(), calerr.message);
- }
-
// set up transition to give appearance of moving chronologically through the pages of
// a calendar
Grid? current_grid = get_current_month_grid();
diff --git a/src/view/view-controllable.vala b/src/view/view-controllable.vala
index db5dc44..4bae0b6 100644
--- a/src/view/view-controllable.vala
+++ b/src/view/view-controllable.vala
@@ -35,11 +35,6 @@ public interface Controllable : Object {
public abstract bool is_viewing_today { get; protected set; }
/**
- * Default { link Calendar.Date} for the calendar unit in view.
- */
- public abstract Calendar.Date default_date { get; protected set; }
-
- /**
* The first day of the week.
*/
public abstract Calendar.FirstOfWeek first_of_week { get; set; }
@@ -78,14 +73,12 @@ public interface Controllable : Object {
/**
* Move backward one calendar unit.
*/
- public abstract void prev();
+ public abstract void previous();
/**
* Jump to calendar unit representing the current date.
- *
- * Returns the Gtk.Widget displaying the current date.
*/
- public abstract Gtk.Widget today();
+ public abstract void today();
/**
* If the view supports a notion of selection, this unselects all selected items.
diff --git a/src/view/week/week-controller.vala b/src/view/week/week-controller.vala
new file mode 100644
index 0000000..2a41e8a
--- /dev/null
+++ b/src/view/week/week-controller.vala
@@ -0,0 +1,109 @@
+/* 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.View.Week {
+
+/**
+ * The { link View.Controllable} for the week view.
+ */
+
+public class Controller : BaseObject, View.Controllable {
+ public const string PROP_WEEK = "week";
+
+ /**
+ * The current week of the year being displayed.
+ */
+ public Calendar.Week week { get; private set; }
+
+ /**
+ * @inheritDoc
+ */
+ public string current_label { get; protected set; }
+
+ /**
+ * @inheritDoc
+ */
+ public bool is_viewing_today { get; protected set; }
+
+ /**
+ * @inheritDoc
+ */
+ public Calendar.FirstOfWeek first_of_week { get; set; }
+
+ private Gtk.Stack stack = new Gtk.Stack();
+
+ public Controller() {
+ // changing these properties drives a lot of the what the view displays
+ notify[View.Controllable.PROP_FIRST_OF_WEEK].connect(on_first_of_week_changed);
+ notify[PROP_WEEK].connect(on_week_changed);
+
+ // set these now that signal handlers are in place
+ first_of_week = Calendar.FirstOfWeek.SUNDAY;
+ week = Calendar.System.today.week_of(first_of_week);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public Gtk.Widget get_container() {
+ return stack;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public void next() {
+ week = week.next();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public void previous() {
+ week = week.previous();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public void today() {
+ week = Calendar.System.today.week_of(first_of_week);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public void unselect_all() {
+ }
+
+ private void on_first_of_week_changed() {
+ // update week to reflect this change
+ week = week.start_date.week_of(first_of_week);
+ }
+
+ private void on_week_changed() {
+ // current_label is Start Date - End Date, Year, unless bounding two years, in which case
+ // Start Date, Year - End Date, Year
+ Calendar.Date.PrettyFlag start_flags = Calendar.Date.PrettyFlag.ABBREV;
+ if (!week.start_date.year.equal_to(week.end_date.year))
+ start_flags |= Calendar.Date.PrettyFlag.INCLUDE_YEAR;
+ Calendar.Date.PrettyFlag end_flags =
+ Calendar.Date.PrettyFlag.ABBREV | Calendar.Date.PrettyFlag.INCLUDE_YEAR;
+
+ // date formatting: "<Start Date> to <End Date>"
+ current_label = _("%s to %s").printf(week.start_date.to_pretty_string(start_flags),
+ week.end_date.to_pretty_string(end_flags));
+
+ is_viewing_today = Calendar.System.today in week;
+ }
+
+ public override string to_string() {
+ return "Week.Controller %s".printf(week.to_string());
+ }
+}
+
+}
+
diff --git a/src/view/week/week-grid.vala b/src/view/week/week-grid.vala
new file mode 100644
index 0000000..77c7eb4
--- /dev/null
+++ b/src/view/week/week-grid.vala
@@ -0,0 +1,27 @@
+/* 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.View.Week {
+
+/**
+ * A Gtk.Grid that holds the various { link Pane}s for each day of thw week.
+ */
+
+public class Grid : Gtk.Grid {
+ public const string PROP_WEEK = "week";
+
+ /**
+ * The calendar { link Week} this { link Grid} displays.
+ */
+ public Calendar.Week week { get; private set; }
+
+ public Grid(Calendar.Week week) {
+ this.week = week;
+ }
+}
+
+}
+
diff --git a/src/view/week/week.vala b/src/view/week/week.vala
new file mode 100644
index 0000000..519b147
--- /dev/null
+++ b/src/view/week/week.vala
@@ -0,0 +1,35 @@
+/* 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.
+ */
+
+/**
+ * Views for displaying calendar information by the week.
+ */
+
+namespace California.View.Week {
+
+private int init_count = 0;
+
+public void init() throws Error {
+ if (!Unit.do_init(ref init_count))
+ return;
+
+ // unit initialization
+ Calendar.init();
+ Backing.init();
+ Component.init();
+}
+
+public void terminate() {
+ if (!Unit.do_terminate(ref init_count))
+ return;
+
+ Component.terminate();
+ Backing.terminate();
+ Calendar.terminate();
+}
+
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]