[california] Switch Idle and Timeout code to use Scheduled class
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Switch Idle and Timeout code to use Scheduled class
- Date: Tue, 24 Jun 2014 20:33:57 +0000 (UTC)
commit aba1e8e6f10a81caab6f52b2119541c5dfd1d8b4
Author: Jim Nelson <jim yorba org>
Date: Tue Jun 24 13:33:45 2014 -0700
Switch Idle and Timeout code to use Scheduled class
.../activator-google-authenticating-pane.vala | 5 +--
src/backing/eds/backing-eds-calendar-source.vala | 30 +++----------------
src/calendar/calendar-system.vala | 19 ++++--------
src/toolkit/toolkit-button-connector.vala | 27 ++++--------------
src/view/month/month-grid.vala | 5 +--
src/view/week/week-day-pane.vala | 23 ++------------
src/view/week/week-grid.vala | 10 ++----
7 files changed, 29 insertions(+), 90 deletions(-)
---
diff --git a/src/activator/google/activator-google-authenticating-pane.vala
b/src/activator/google/activator-google-authenticating-pane.vala
index 5914081..e950173 100644
--- a/src/activator/google/activator-google-authenticating-pane.vala
+++ b/src/activator/google/activator-google-authenticating-pane.vala
@@ -49,6 +49,7 @@ public class GoogleAuthenticatingPane : Gtk.Grid, Toolkit.Card {
private Gtk.Button again_button;
private Cancellable cancellable = new Cancellable();
+ private Scheduled? scheduled_jump = null;
public GoogleAuthenticatingPane() {
if (app_id == null)
@@ -134,11 +135,9 @@ public class GoogleAuthenticatingPane : Gtk.Grid, Toolkit.Card {
// depending on network conditions, this pane can come and go quite quickly; this brief
// delay gives the user a chance to see what's transpired
- Timeout.add(SUCCESS_DELAY_MSEC, () => {
+ scheduled_jump = new Scheduled.once_after_msec(SUCCESS_DELAY_MSEC, () => {
jump_to_card_by_name(GoogleCalendarListPane.ID, new GoogleCalendarListPane.Message(
credentials.username, own_calendars, all_calendars));
-
- return false;
});
}
diff --git a/src/backing/eds/backing-eds-calendar-source.vala
b/src/backing/eds/backing-eds-calendar-source.vala
index 6e3c0d2..246023f 100644
--- a/src/backing/eds/backing-eds-calendar-source.vala
+++ b/src/backing/eds/backing-eds-calendar-source.vala
@@ -16,7 +16,7 @@ internal class EdsCalendarSource : CalendarSource {
private E.Source eds_source;
private E.SourceCalendar eds_calendar;
private E.CalClient? client = null;
- private uint source_write_id = 0;
+ private Scheduled? scheduled_source_write = null;
private Cancellable? source_write_cancellable = null;
public EdsCalendarSource(E.Source eds_source, E.SourceCalendar eds_calendar) {
@@ -40,10 +40,6 @@ internal class EdsCalendarSource : CalendarSource {
notify[PROP_COLOR].connect(on_color_changed);
}
- ~EdsCalendarSource() {
- cancel_source_write();
- }
-
private void on_title_changed() {
// on schedule write if something changed
if (eds_source.display_name == title)
@@ -72,34 +68,20 @@ internal class EdsCalendarSource : CalendarSource {
}
private void schedule_source_write(string reason) {
- cancel_source_write();
-
debug("Scheduling update of %s due to %s...", to_string(), reason);
source_write_cancellable = new Cancellable();
- source_write_id = Timeout.add(UPDATE_DELAY_MSEC, on_background_write_source, Priority.LOW);
- }
-
- private void cancel_source_write() {
- if (source_write_id != 0) {
- GLib.Source.remove(source_write_id);
- source_write_id = 0;
- }
-
- if (source_write_cancellable != null) {
- source_write_cancellable.cancel();
- source_write_cancellable = null;
- }
+ scheduled_source_write = new Scheduled.once_after_msec(UPDATE_DELAY_MSEC,
+ on_background_write_source, Priority.LOW);
}
- private bool on_background_write_source() {
+ private void on_background_write_source() {
// in essence, say this is no longer scheduled ... for now, allow another write to be
// scheduled while this one is occurring
- source_write_id = 0;
Cancellable? cancellable = source_write_cancellable;
source_write_cancellable = null;
if (cancellable == null || cancellable.is_cancelled())
- return false;
+ return;
try {
debug("Updating EDS source %s...", to_string());
@@ -108,8 +90,6 @@ internal class EdsCalendarSource : CalendarSource {
} catch (Error err) {
debug("Error updating EDS source %s: %s", to_string(), err.message);
}
-
- return false;
}
// Invoked by EdsStore prior to making it available outside of unit
diff --git a/src/calendar/calendar-system.vala b/src/calendar/calendar-system.vala
index fab996a..fce063a 100644
--- a/src/calendar/calendar-system.vala
+++ b/src/calendar/calendar-system.vala
@@ -127,7 +127,7 @@ public class System : BaseObject {
public signal void first_of_week_changed(FirstOfWeek old_fow, FirstOfWeek new_fow);
private GLib.Settings system_clock_format_schema = new GLib.Settings(CLOCK_FORMAT_SCHEMA);
- private uint date_timer_id = 0;
+ private Scheduled scheduled_date_timer;
private System() {
zone = new OlsonZone(timedated_service.timezone);
@@ -153,13 +153,8 @@ public class System : BaseObject {
// this may seem wasteful, but since the date can change for a lot of reasons (user
// intervention, clock drift, NTP, etc.) this is a simple way to stay on top of things
today = new Date.now(Timezone.local);
- date_timer_id = Timeout.add_seconds_full(CHECK_DATE_PRIORITY, next_check_today_interval_sec(),
- check_today_changed);
- }
-
- ~System() {
- if (date_timer_id != 0)
- Source.remove(date_timer_id);
+ scheduled_date_timer = new Scheduled.once_after_sec(next_check_today_interval_sec(),
+ check_today_changed, CHECK_DATE_PRIORITY);
}
internal static void preinit() throws IOError {
@@ -215,14 +210,12 @@ public class System : BaseObject {
}
// See note in constructor for logic behind this SourceFunc
- private bool check_today_changed() {
+ private void check_today_changed() {
update_today();
// reschedule w/ the next interval
- date_timer_id = Timeout.add_seconds_full(CHECK_DATE_PRIORITY, next_check_today_interval_sec(),
- check_today_changed);
-
- return false;
+ scheduled_date_timer = new Scheduled.once_after_sec(next_check_today_interval_sec(),
+ check_today_changed, CHECK_DATE_PRIORITY);
}
private void update_today() {
diff --git a/src/toolkit/toolkit-button-connector.vala b/src/toolkit/toolkit-button-connector.vala
index 19ce292..0549f57 100644
--- a/src/toolkit/toolkit-button-connector.vala
+++ b/src/toolkit/toolkit-button-connector.vala
@@ -27,7 +27,7 @@ public class ButtonConnector : EventConnector {
// The actual ButtonEvent, with some useful functionality for release timeouts
private class InternalButtonEvent : ButtonEvent {
- private uint timeout_id = 0;
+ private Scheduled? scheduled_timeout = null;
public signal void release_timeout();
@@ -35,37 +35,22 @@ public class ButtonConnector : EventConnector {
base (widget, event);
}
- ~InternalButtonEvent() {
- cancel_timeout();
- }
-
- private void cancel_timeout() {
- if (timeout_id == 0)
- return;
-
- Source.remove(timeout_id);
- timeout_id = 0;
- }
-
public override void update_press(Gtk.Widget widget, Gdk.EventButton press_event) {
base.update_press(widget, press_event);
- cancel_timeout();
+ if (scheduled_timeout != null)
+ scheduled_timeout.cancel();
}
public override void update_release(Gtk.Widget widget, Gdk.EventButton release_event) {
base.update_release(widget, release_event);
- cancel_timeout();
- timeout_id = Timeout.add(CLICK_DETERMINATION_DELAY_MSEC, on_timeout, Priority.LOW);
+ scheduled_timeout = new Scheduled.once_after_msec(CLICK_DETERMINATION_DELAY_MSEC,
+ on_timeout, Priority.LOW);
}
- private bool on_timeout() {
- timeout_id = 0;
-
+ private void on_timeout() {
release_timeout();
-
- return false;
}
}
diff --git a/src/view/month/month-grid.vala b/src/view/month/month-grid.vala
index eb59f54..301fe87 100644
--- a/src/view/month/month-grid.vala
+++ b/src/view/month/month-grid.vala
@@ -50,6 +50,7 @@ private class Grid : Gtk.Grid {
private Backing.CalendarSubscriptionManager? subscriptions = null;
private Gdk.EventType button_press_type = Gdk.EventType.NOTHING;
private Gdk.Point button_press_point = Gdk.Point();
+ private Scheduled? scheduled_subscription_update = null;
public Grid(Controller owner, Calendar.MonthOfYear month_of_year) {
this.owner = owner;
@@ -207,10 +208,8 @@ private class Grid : Gtk.Grid {
if (diff < 0)
diff = diff.abs() + 1;
- Timeout.add(300 + (diff * 100), () => {
+ scheduled_subscription_update = new Scheduled.once_after_msec(300 + (diff * 100), () => {
subscriptions.start_async.begin();
-
- return false;
});
}
}
diff --git a/src/view/week/week-day-pane.vala b/src/view/week/week-day-pane.vala
index f579c67..f065910 100644
--- a/src/view/week/week-day-pane.vala
+++ b/src/view/week/week-day-pane.vala
@@ -46,7 +46,7 @@ internal class DayPane : Pane, Common.InstanceContainer {
public Calendar.Span contained_span { get { return date; } }
private Gee.TreeSet<Component.Event> days_events = new Gee.TreeSet<Component.Event>();
- private uint minutes_timeout_id = 0;
+ private Scheduled? scheduled_monitor = null;
public DayPane(Grid owner, Calendar.Date date) {
base (owner, -1);
@@ -64,8 +64,6 @@ internal class DayPane : Pane, Common.InstanceContainer {
~DayPane() {
Calendar.System.instance.is_24hr_changed.disconnect(queue_draw);
Calendar.System.instance.today_changed.disconnect(on_today_changed);
-
- cancel_monitor_minutes();
}
private void on_today_changed(Calendar.Date old_today, Calendar.Date new_today) {
@@ -79,7 +77,7 @@ internal class DayPane : Pane, Common.InstanceContainer {
// If this pane is showing the current date, need to update once a minute to move the horizontal
// minute indicator
private void schedule_monitor_minutes() {
- cancel_monitor_minutes();
+ scheduled_monitor = null;
if (!date.equal_to(Calendar.System.today))
return;
@@ -87,28 +85,15 @@ internal class DayPane : Pane, Common.InstanceContainer {
// find the number of seconds remaining in this minute and schedule an update then
int remaining_sec = (Calendar.WallTime.SECONDS_PER_MINUTE - Calendar.System.now.second).clamp(
0, Calendar.WallTime.SECONDS_PER_MINUTE);
- minutes_timeout_id = Timeout.add_seconds(remaining_sec, on_minute_changed);
+ scheduled_monitor = new Scheduled.once_after_sec(remaining_sec, on_minute_changed);
}
- private bool on_minute_changed() {
- // done this iteration
- minutes_timeout_id = 0;
-
+ private void on_minute_changed() {
// repaint time indicator
queue_draw();
// reschedule
schedule_monitor_minutes();
-
- return false;
- }
-
- private void cancel_monitor_minutes() {
- if (minutes_timeout_id == 0)
- return;
-
- Source.remove(minutes_timeout_id);
- minutes_timeout_id = 0;
}
public void add_event(Component.Event event) {
diff --git a/src/view/week/week-grid.vala b/src/view/week/week-grid.vala
index cdc4cd7..1920b6c 100644
--- a/src/view/week/week-grid.vala
+++ b/src/view/week/week-grid.vala
@@ -54,6 +54,8 @@ internal class Grid : Gtk.Box {
private Gtk.ScrolledWindow scrolled_panes;
private Gtk.Widget right_spacer;
private bool vadj_init = false;
+ private Scheduled? scheduled_update_subscription = null;
+ private Scheduled? scheduled_realloc = null;
public Grid(Controller owner, Calendar.Week week) {
Object(orientation: Gtk.Orientation.VERTICAL, spacing: 0);
@@ -175,10 +177,8 @@ internal class Grid : Gtk.Box {
if (diff != 0)
diff = 300 + (diff * 100);
- Timeout.add(diff, () => {
+ scheduled_update_subscription = new Scheduled.once_after_msec(diff, () => {
subscriptions.start_async.begin();
-
- return false;
});
// watch for vertical adjustment to initialize to set the starting scroll position
@@ -267,10 +267,8 @@ internal class Grid : Gtk.Box {
private void on_realloc_right_spacer() {
// need to do outside of allocation signal due to some mechanism in GTK that prevents resizes
// while resizing
- Idle.add(() => {
+ scheduled_realloc = new Scheduled.once_at_idle(() => {
right_spacer.set_size_request(scrolled_panes.get_vscrollbar().get_allocated_width(), -1);
-
- return false;
});
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]