[california/wip/727001-remove] Wrap up
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/727001-remove] Wrap up
- Date: Fri, 12 Sep 2014 01:10:40 +0000 (UTC)
commit b5340fa53bcf1155d5248e8fe5463e4dd20f9dc6
Author: Jim Nelson <jim yorba org>
Date: Thu Sep 11 18:10:36 2014 -0700
Wrap up
.../backing-calendar-source-subscription.vala | 2 +-
src/backing/backing-calendar-source.vala | 4 +-
src/backing/backing-source.vala | 24 ++++++++++-
src/backing/backing-store.vala | 15 +++++++
.../backing-eds-calendar-source-subscription.vala | 24 +++++++++++
src/backing/eds/backing-eds-calendar-source.vala | 10 +++--
src/backing/eds/backing-eds-store.vala | 42 +++++++++++++++++++-
src/manager/manager-calendar-list.vala | 12 ++++-
src/manager/manager-remove-calendar.vala | 34 ++++++++++++++-
src/rc/calendar-manager-list.ui | 2 +-
10 files changed, 152 insertions(+), 17 deletions(-)
---
diff --git a/src/backing/backing-calendar-source-subscription.vala
b/src/backing/backing-calendar-source-subscription.vala
index 9286dca..bb3da65 100644
--- a/src/backing/backing-calendar-source-subscription.vala
+++ b/src/backing/backing-calendar-source-subscription.vala
@@ -22,7 +22,7 @@ public abstract class CalendarSourceSubscription : BaseObject {
/**
* The { link CalendarSource} providing this subscription's information.
*/
- public CalendarSource calendar { get; private set; }
+ public unowned CalendarSource calendar { get; private set; }
/**
* The date-time window.
diff --git a/src/backing/backing-calendar-source.vala b/src/backing/backing-calendar-source.vala
index fbfb6dd..aa5755d 100644
--- a/src/backing/backing-calendar-source.vala
+++ b/src/backing/backing-calendar-source.vala
@@ -39,8 +39,8 @@ public abstract class CalendarSource : Source {
ALL
}
- protected CalendarSource(string id, string title) {
- base (id, title);
+ protected CalendarSource(Store store, string id, string title) {
+ base (store, id, title);
}
/**
diff --git a/src/backing/backing-source.vala b/src/backing/backing-source.vala
index 23b8537..26a889f 100644
--- a/src/backing/backing-source.vala
+++ b/src/backing/backing-source.vala
@@ -31,6 +31,11 @@ public abstract class Source : BaseObject, Gee.Comparable<Source> {
public string id { get; private set; }
/**
+ * The { link Store} that owns the { link Source}.
+ */
+ public unowned Store store { get; private set; }
+
+ /**
* True if the { link Source} is unavailable for use due to being removed from it's
* { link Backing.Store}.
*
@@ -64,10 +69,23 @@ public abstract class Source : BaseObject, Gee.Comparable<Source> {
* If true, write operations (create, update, remove) should not be attempted.
*
* It's possible this can change at run-time by the backend.
+ *
+ * @see is_removable
*/
public bool read_only { get; protected set; }
/**
+ * Whether the { link Source} can be removed.
+ *
+ * If true, do not attempt to remove this Source from the { link Store}.
+ *
+ * It's possible this can change at run-time by the backend.
+ *
+ * @see read_only
+ */
+ public bool is_removable { get; protected set; }
+
+ /**
* Whether the { link Source} is local-only or has network backing.
*/
public bool is_local { get; protected set; }
@@ -78,7 +96,8 @@ public abstract class Source : BaseObject, Gee.Comparable<Source> {
*/
public string color { get; set; }
- protected Source(string id, string title) {
+ protected Source(Store store, string id, string title) {
+ this.store = store;
this.id = id;
this.title = title;
}
@@ -92,7 +111,8 @@ public abstract class Source : BaseObject, Gee.Comparable<Source> {
* @see is_unavailable
*/
internal void set_unavailable() {
- is_available = false;
+ if (is_available)
+ is_available = false;
}
/**
diff --git a/src/backing/backing-store.vala b/src/backing/backing-store.vala
index 527b0a2..e29d3a9 100644
--- a/src/backing/backing-store.vala
+++ b/src/backing/backing-store.vala
@@ -72,6 +72,21 @@ public abstract class Store : BaseObject {
internal abstract async void close_async(Cancellable? cancellable) throws Error;
/**
+ * Asynchronously remove the { link Source} from the { link Store}.
+ *
+ * This is a permanent deletion of local data and the Source will no longer be available to the
+ * user. There is no mechanism here for optionally deleting the account or calendar on the
+ * network backend, if any.
+ *
+ * This Store ''must'' be the same as { link Source.store}. INVALID is thrown otherwise.
+ *
+ * This operation is guaranteed not to succeed if { link Source.is_removable} is false.
+ *
+ * The Store must be open before calling this method.
+ */
+ public abstract async void remove_source_async(Source source, Cancellable? cancellable) throws Error;
+
+ /**
* Return a read-ony list of all { link Source}s managed by this { link Store}.
*
* The Sources will be sorted by their titles in lexiographic order.
diff --git a/src/backing/eds/backing-eds-calendar-source-subscription.vala
b/src/backing/eds/backing-eds-calendar-source-subscription.vala
index 963f9c8..dcdf84a 100644
--- a/src/backing/eds/backing-eds-calendar-source-subscription.vala
+++ b/src/backing/eds/backing-eds-calendar-source-subscription.vala
@@ -26,6 +26,8 @@ internal class EdsCalendarSourceSubscription : CalendarSourceSubscription {
this.view = view;
this.sexp = sexp;
+
+ eds_calendar.notify[Source.PROP_IS_AVAILABLE].connect(stop);
}
~EdsCalendarSourceSubscription() {
@@ -72,6 +74,28 @@ internal class EdsCalendarSourceSubscription : CalendarSourceSubscription {
}
}
+ private void stop() {
+ if (!started)
+ return;
+
+ try {
+ // wait for start to complete, for sanity's sake
+ wait_until_started();
+ } catch (Error err) {
+ // call it a day
+ return;
+ }
+
+ try {
+ view.stop();
+ } catch (Error err) {
+ debug("Unable to stop E.CalClientView for %s: %s", to_string(), err.message);
+ }
+
+ started = false;
+ active = false;
+ }
+
private void internal_start(Cancellable? cancellable) throws Error {
// prepare flags and fields of interest .. don't want known events delivered via signals
view.set_fields_of_interest(null);
diff --git a/src/backing/eds/backing-eds-calendar-source.vala
b/src/backing/eds/backing-eds-calendar-source.vala
index 1a38348..d3219fb 100644
--- a/src/backing/eds/backing-eds-calendar-source.vala
+++ b/src/backing/eds/backing-eds-calendar-source.vala
@@ -13,16 +13,17 @@ namespace California.Backing {
internal class EdsCalendarSource : CalendarSource {
private const int UPDATE_DELAY_MSEC = 500;
- private E.Source eds_source;
- private E.SourceCalendar eds_calendar;
+ internal E.Source eds_source;
+ internal E.SourceCalendar eds_calendar;
+
private E.CalClient? client = null;
private Scheduled? scheduled_source_write = null;
private Scheduled? scheduled_source_read = null;
private Gee.HashSet<string> dirty_read_properties = new Gee.HashSet<string>();
private Cancellable? source_write_cancellable = null;
- public EdsCalendarSource(E.Source eds_source, E.SourceCalendar eds_calendar) {
- base (eds_source.uid, eds_source.display_name);
+ public EdsCalendarSource(EdsStore store, E.Source eds_source, E.SourceCalendar eds_calendar) {
+ base (store, eds_source.uid, eds_source.display_name);
this.eds_source = eds_source;
this.eds_calendar = eds_calendar;
@@ -42,6 +43,7 @@ internal class EdsCalendarSource : CalendarSource {
visible = eds_calendar.selected;
color = eds_calendar.color;
is_local = eds_calendar.backend_name == "local";
+ is_removable = eds_source.removable;
// when changed within the app, need to write it back out
notify[PROP_TITLE].connect(on_title_changed);
diff --git a/src/backing/eds/backing-eds-store.vala b/src/backing/eds/backing-eds-store.vala
index 70f8b71..8c192a4 100644
--- a/src/backing/eds/backing-eds-store.vala
+++ b/src/backing/eds/backing-eds-store.vala
@@ -46,6 +46,46 @@ internal class EdsStore : Store, WebCalSubscribable, CalDAVSubscribable {
/**
* @inheritDoc
*/
+ public override async void remove_source_async(Source source, Cancellable? cancellable) throws Error {
+ if (!is_open)
+ throw new BackingError.UNAVAILABLE("EDS not open");
+
+ if (source.store != this) {
+ throw new BackingError.INVALID("Attempted to remove source %s from wrong store %s",
+ source.to_string(), to_string());
+ }
+
+ EdsCalendarSource? calendar_source = source as EdsCalendarSource;
+ if (calendar_source == null)
+ throw new BackingError.INVALID("Unknown EDS source %s", source.to_string());
+
+ //
+ // don't use remove_eds_source because that closes the source in the background; need to
+ // shut it down then remove it from the backing
+ //
+
+ // remove internally
+ if (!sources.unset(calendar_source.eds_source)) {
+ throw new BackingError.INVALID("EDS source %s not registered to store %s", source.to_string(),
+ to_string());
+ }
+
+ // make unavailable; this removes events
+ calendar_source.set_unavailable();
+
+ // report dropped
+ source_removed(calendar_source);
+
+ // close source; this shuts down outstanding subscriptions
+ yield calendar_source.close_async(cancellable);
+
+ // remove from EDS
+ yield calendar_source.eds_source.remove(cancellable);
+ }
+
+ /**
+ * @inheritDoc
+ */
public async void subscribe_webcal_async(string title, Soup.URI uri, string? username, string color,
Cancellable? cancellable) throws Error {
yield subscribe_eds_async(title, uri, username, color, "webcal", cancellable);
@@ -131,7 +171,7 @@ internal class EdsStore : Store, WebCalSubscribable, CalDAVSubscribable {
if (eds_calendar == null)
return;
- EdsCalendarSource calendar = new EdsCalendarSource(eds_source, eds_calendar);
+ EdsCalendarSource calendar = new EdsCalendarSource(this, eds_source, eds_calendar);
try {
yield calendar.open_async(null);
} catch (Error err) {
diff --git a/src/manager/manager-calendar-list.vala b/src/manager/manager-calendar-list.vala
index d27d4e0..78cbf4a 100644
--- a/src/manager/manager-calendar-list.vala
+++ b/src/manager/manager-calendar-list.vala
@@ -52,9 +52,9 @@ internal class CalendarList : Gtk.Grid, Toolkit.Card {
Backing.Manager.instance.notify[Backing.Manager.PROP_IS_OPEN].connect(on_manager_opened_closed);
model.bind_property(Toolkit.ListBoxModel.PROP_SELECTED, edit_button, "sensitive",
- BindingFlags.SYNC_CREATE, transform_selected_to_sensitive);
+ BindingFlags.SYNC_CREATE, transform_selected_to_edit_sensitive);
model.bind_property(Toolkit.ListBoxModel.PROP_SELECTED, remove_button, "sensitive",
- BindingFlags.SYNC_CREATE, transform_selected_to_sensitive);
+ BindingFlags.SYNC_CREATE, transform_selected_to_remove_sensitive);
}
~CalendarList() {
@@ -64,12 +64,18 @@ internal class CalendarList : Gtk.Grid, Toolkit.Card {
Backing.Manager.instance.notify[Backing.Manager.PROP_IS_OPEN].disconnect(on_manager_opened_closed);
}
- private bool transform_selected_to_sensitive(Binding binding, Value source_value, ref Value
target_value) {
+ private bool transform_selected_to_edit_sensitive(Binding binding, Value source_value, ref Value
target_value) {
target_value = model.selected != null && !model.selected.read_only;
return true;
}
+ private bool transform_selected_to_remove_sensitive(Binding binding, Value source_value, ref Value
target_value) {
+ target_value = model.selected != null && model.selected.is_removable;
+
+ return true;
+ }
+
public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message) {
}
diff --git a/src/manager/manager-remove-calendar.vala b/src/manager/manager-remove-calendar.vala
index c4ec626..ba2abbb 100644
--- a/src/manager/manager-remove-calendar.vala
+++ b/src/manager/manager-remove-calendar.vala
@@ -21,17 +21,24 @@ private class RemoveCalendar : Gtk.Grid, Toolkit.Card {
[GtkChild]
private Gtk.Label explanation_label;
+ private Backing.CalendarSource? source = null;
+
public RemoveCalendar() {
}
public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message) {
- Backing.CalendarSource source = message as Backing.CalendarSource;
+ source = message as Backing.CalendarSource;
+ if (source == null) {
+ jump_back();
+
+ return;
+ }
string fmt;
if (source.is_local)
fmt = _("This will remove the %s local calendar from your computer. All associated information
will be deleted permanently.");
else
- fmt = _("This will remove the %s network calendar from your computer. This will not affect the
information stored on the server.");
+ fmt = _("This will remove the %s network calendar from your computer. This will not affect
information stored on the server.");
explanation_label.label = fmt.printf("<b>" + GLib.Markup.escape_text(source.title) + "</b>");
}
@@ -43,7 +50,28 @@ private class RemoveCalendar : Gtk.Grid, Toolkit.Card {
[GtkCallback]
private void on_remove_button_clicked() {
- jump_back();
+ remove_calendar_source.begin();
+ }
+
+ private async void remove_calendar_source() {
+ if (source == null)
+ return;
+
+ Gdk.Cursor? cursor = Toolkit.set_busy(this);
+
+ Error? remove_err = null;
+ try {
+ yield source.store.remove_source_async(source, null);
+ } catch (Error err) {
+ remove_err = err;
+ }
+
+ Toolkit.set_unbusy(this, cursor);
+
+ if (remove_err == null)
+ notify_success();
+ else
+ report_error(_("Unable to remove calendar: %s").printf(remove_err.message));
}
}
diff --git a/src/rc/calendar-manager-list.ui b/src/rc/calendar-manager-list.ui
index ae6e15f..0ac45b8 100644
--- a/src/rc/calendar-manager-list.ui
+++ b/src/rc/calendar-manager-list.ui
@@ -117,7 +117,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <property name="tooltip_text" translatable="yes">Delete calendar</property>
+ <property name="tooltip_text" translatable="yes">Remove calendar</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]