Sort signalled Folders by path so when traversing parents are

always listed before children.
This commit is contained in:
Jim Nelson 2013-06-11 19:57:43 -07:00
parent 8d21f20c92
commit b091855593
3 changed files with 47 additions and 18 deletions

View file

@ -14,13 +14,13 @@ public abstract class Geary.AbstractAccount : BaseObject, Geary.Account {
this.information = information;
}
protected virtual void notify_folders_available_unavailable(Gee.Collection<Geary.Folder>? available,
Gee.Collection<Geary.Folder>? unavailable) {
protected virtual void notify_folders_available_unavailable(Gee.List<Geary.Folder>? available,
Gee.List<Geary.Folder>? unavailable) {
folders_available_unavailable(available, unavailable);
}
protected virtual void notify_folders_added_removed(Gee.Collection<Geary.Folder>? added,
Gee.Collection<Geary.Folder>? removed) {
protected virtual void notify_folders_added_removed(Gee.List<Geary.Folder>? added,
Gee.List<Geary.Folder>? removed) {
folders_added_removed(added, removed);
}

View file

@ -25,18 +25,31 @@ public interface Geary.Account : BaseObject {
/**
* Fired when folders become available or unavailable in the account.
*
* Folders become available when the account is first opened or when
* they're created later; they become unavailable when the account is
* closed or they're deleted later.
*
* Folders are ordered for the convenience of the caller from the top of the heirarchy to
* lower in the heirarchy. In other words, parents are listed before children, assuming the
* lists are traversed in natural order.
*
* @see sort_by_path
*/
public signal void folders_available_unavailable(Gee.Collection<Geary.Folder>? available,
Gee.Collection<Geary.Folder>? unavailable);
public signal void folders_available_unavailable(Gee.List<Geary.Folder>? available,
Gee.List<Geary.Folder>? unavailable);
/**
* Fired when folders are created or deleted.
*
* Folders are ordered for the convenience of the caller from the top of the heirarchy to
* lower in the heirarchy. In other words, parents are listed before children, assuming the
* lists are traversed in natural order.
*
* @see sort_by_path
*/
public signal void folders_added_removed(Gee.Collection<Geary.Folder>? added,
Gee.Collection<Geary.Folder>? removed);
public signal void folders_added_removed(Gee.List<Geary.Folder>? added,
Gee.List<Geary.Folder>? removed);
/**
* Fired when a Folder's contents is detected having changed.
@ -66,20 +79,36 @@ public interface Geary.Account : BaseObject {
/**
* Signal notification method for subclasses to use.
*/
public abstract void notify_folders_available_unavailable(Gee.Collection<Geary.Folder>? available,
Gee.Collection<Geary.Folder>? unavailable);
protected abstract void notify_folders_available_unavailable(Gee.List<Geary.Folder>? available,
Gee.List<Geary.Folder>? unavailable);
/**
* Signal notification method for subclasses to use.
*/
protected abstract void notify_folders_added_removed(Gee.Collection<Geary.Folder>? added,
Gee.Collection<Geary.Folder>? removed);
protected abstract void notify_folders_added_removed(Gee.List<Geary.Folder>? added,
Gee.List<Geary.Folder>? removed);
/**
* Signal notification method for subclasses to use.
*/
protected abstract void notify_folders_contents_altered(Gee.Collection<Geary.Folder> altered);
/**
* A utility method to sort a Gee.Collection of {@link Folder}s by their {@link FolderPath}s
* to ensure they comport with {@link folders_available_unavailable} and
* {@link folders_added_removed} signals' contracts.
*/
protected Gee.List<Geary.Folder> sort_by_path(Gee.Collection<Geary.Folder> folders) {
Gee.TreeSet<Geary.Folder> sorted = new Gee.TreeSet<Geary.Folder>(folder_path_comparator);
sorted.add_all(folders);
return Collection.to_array_list<Geary.Folder>(sorted);
}
private int folder_path_comparator(Geary.Folder a, Geary.Folder b) {
return a.get_path().compare_to(b.get_path());
}
/**
*
*/

View file

@ -72,7 +72,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
notify_opened();
notify_folders_available_unavailable(local_only.values, null);
notify_folders_available_unavailable(sort_by_path(local_only.values), null);
// schedule an immediate sweep of the folders; once this is finished, folders will be
// regularly enumerated
@ -83,8 +83,8 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
if (!open)
return;
notify_folders_available_unavailable(null, local_only.values);
notify_folders_available_unavailable(null, folder_map.values);
notify_folders_available_unavailable(null, sort_by_path(local_only.values));
notify_folders_available_unavailable(null, sort_by_path(folder_map.values));
local.outbox.report_problem.disconnect(notify_report_problem);
@ -150,7 +150,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
}
if (built_folders.size > 0)
notify_folders_available_unavailable(built_folders, null);
notify_folders_available_unavailable(sort_by_path(built_folders), null);
return return_folders;
}
@ -419,7 +419,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
debug(@"Need to remove folder $folder");
if (engine_added.size > 0)
notify_folders_added_removed(engine_added, null);
notify_folders_added_removed(sort_by_path(engine_added), null);
// report all altered folders
if (altered_paths.size > 0) {