Make FolderPath and SpecialFolderType properties of Geary.Folder

A recent commit made Geary.Folder's FolderProperties a property
(rather than available via a getter).  This commit makes its
FolderPath and SpecialFolderType also properties.
This commit is contained in:
Jim Nelson 2013-06-26 15:02:33 -07:00
parent 0198c24a65
commit 668ced74eb
20 changed files with 102 additions and 105 deletions

View file

@ -57,8 +57,8 @@ public class FolderList.AccountBranch : Sidebar.Branch {
FolderEntry entry_a = (FolderEntry) a;
FolderEntry entry_b = (FolderEntry) b;
Geary.SpecialFolderType type_a = entry_a.folder.get_special_folder_type();
Geary.SpecialFolderType type_b = entry_b.folder.get_special_folder_type();
Geary.SpecialFolderType type_a = entry_a.folder.special_folder_type;
Geary.SpecialFolderType type_b = entry_b.folder.special_folder_type;
assert(type_a != Geary.SpecialFolderType.NONE);
assert(type_b != Geary.SpecialFolderType.NONE);
@ -79,7 +79,7 @@ public class FolderList.AccountBranch : Sidebar.Branch {
public void add_folder(Geary.Folder folder) {
Sidebar.Entry? graft_point = null;
FolderEntry folder_entry = new FolderEntry(folder);
Geary.SpecialFolderType special_folder_type = folder.get_special_folder_type();
Geary.SpecialFolderType special_folder_type = folder.special_folder_type;
if (special_folder_type != Geary.SpecialFolderType.NONE) {
if (special_folder_type == Geary.SpecialFolderType.SEARCH)
return; // Don't show search folder under the account.
@ -98,11 +98,11 @@ public class FolderList.AccountBranch : Sidebar.Branch {
graft_point = uncommon_special_group;
break;
}
} else if (folder.get_path().get_parent() == null) {
} else if (folder.path.get_parent() == null) {
// Top-level folders get put in our special user folders group.
graft_point = user_folder_group;
} else {
Sidebar.Entry? entry = folder_entries.get(folder.get_path().get_parent());
Sidebar.Entry? entry = folder_entries.get(folder.path.get_parent());
if (entry != null)
graft_point = entry;
}
@ -121,7 +121,7 @@ public class FolderList.AccountBranch : Sidebar.Branch {
if (graft_point != null) {
graft(graft_point, folder_entry);
folder_entries.set(folder.get_path(), folder_entry);
folder_entries.set(folder.path, folder_entry);
} else {
debug("Could not add folder %s of type %s to folder list", folder.to_string(),
special_folder_type.to_string());
@ -129,13 +129,13 @@ public class FolderList.AccountBranch : Sidebar.Branch {
}
public void remove_folder(Geary.Folder folder) {
Sidebar.Entry? entry = folder_entries.get(folder.get_path());
Sidebar.Entry? entry = folder_entries.get(folder.path);
if(entry == null) {
debug("Could not remove folder %s", folder.to_string());
return;
}
prune(entry);
folder_entries.unset(folder.get_path());
folder_entries.unset(folder.path);
}
}

View file

@ -35,7 +35,7 @@ public class FolderList.FolderEntry : FolderList.AbstractFolderEntry, Sidebar.In
}
public override Icon? get_sidebar_icon() {
switch (folder.get_special_folder_type()) {
switch (folder.special_folder_type) {
case Geary.SpecialFolderType.NONE:
return IconFactory.instance.get_custom_icon("tag", IconFactory.ICON_SIDEBAR);

View file

@ -30,7 +30,7 @@ public class FolderList.InboxesBranch : Sidebar.Branch {
}
public void add_inbox(Geary.Folder inbox) {
assert(inbox.get_special_folder_type() == Geary.SpecialFolderType.INBOX);
assert(inbox.special_folder_type == Geary.SpecialFolderType.INBOX);
InboxFolderEntry folder_entry = new InboxFolderEntry(inbox);
graft(get_root(), folder_entry);

View file

@ -42,7 +42,7 @@ public class FolderList.Tree : Sidebar.Tree {
private FolderEntry? get_folder_entry(Geary.Folder folder) {
AccountBranch? account_branch = account_branches.get(folder.account);
return (account_branch == null ? null :
account_branch.get_entry_for_path(folder.get_path()));
account_branch.get_entry_for_path(folder.path));
}
private void on_entry_selected(Sidebar.SelectableEntry selectable) {
@ -91,7 +91,7 @@ public class FolderList.Tree : Sidebar.Tree {
if (account_branches.size > 1 && !has_branch(inboxes_branch))
graft(inboxes_branch, INBOX_ORDINAL); // The Inboxes branch comes first.
if (folder.get_special_folder_type() == Geary.SpecialFolderType.INBOX)
if (folder.special_folder_type == Geary.SpecialFolderType.INBOX)
inboxes_branch.add_inbox(folder);
folder.account.information.notify["ordinal"].connect(on_ordinal_changed);
@ -104,13 +104,13 @@ public class FolderList.Tree : Sidebar.Tree {
assert(has_branch(account_branch));
// If this is the current folder, unselect it.
Sidebar.Entry? entry = account_branch.get_entry_for_path(folder.get_path());
Sidebar.Entry? entry = account_branch.get_entry_for_path(folder.path);
if (has_branch(inboxes_branch) && (entry == null || !is_selected(entry)))
entry = inboxes_branch.get_entry_for_account(folder.account);
if (entry != null && is_selected(entry))
folder_selected(null);
if (folder.get_special_folder_type() == Geary.SpecialFolderType.INBOX)
if (folder.special_folder_type == Geary.SpecialFolderType.INBOX)
inboxes_branch.remove_inbox(folder.account);
account_branch.remove_folder(folder);

View file

@ -902,7 +902,7 @@ public class GearyController {
}
// monitor the Inbox for notifications
if (folder.get_special_folder_type() == Geary.SpecialFolderType.INBOX &&
if (folder.special_folder_type == Geary.SpecialFolderType.INBOX &&
!inboxes.has_key(folder.account)) {
inboxes.set(folder.account, folder);
Geary.Folder? select_folder = get_initial_selection_folder(folder);
@ -925,7 +925,7 @@ public class GearyController {
if (unavailable != null) {
foreach (Geary.Folder folder in unavailable) {
if (folder.get_special_folder_type() == Geary.SpecialFolderType.INBOX &&
if (folder.special_folder_type == Geary.SpecialFolderType.INBOX &&
inboxes.has_key(folder.account)) {
new_messages_monitor.remove_folder(folder);
}
@ -1107,9 +1107,9 @@ public class GearyController {
}
if (spam_folder != null &&
current_folder.get_special_folder_type() != Geary.SpecialFolderType.DRAFTS &&
current_folder.get_special_folder_type() != Geary.SpecialFolderType.OUTBOX) {
if (current_folder.get_special_folder_type() == Geary.SpecialFolderType.SPAM) {
current_folder.special_folder_type != Geary.SpecialFolderType.DRAFTS &&
current_folder.special_folder_type != Geary.SpecialFolderType.OUTBOX) {
if (current_folder.special_folder_type == Geary.SpecialFolderType.SPAM) {
// We're in the spam folder.
actions.get_action(ACTION_MARK_AS_SPAM).sensitive = true;
actions.get_action(ACTION_MARK_AS_SPAM).label = MARK_AS_NOT_SPAM_LABEL;
@ -1218,7 +1218,7 @@ public class GearyController {
private void on_mark_as_spam() {
Geary.Folder? destination_folder = null;
if (current_folder.get_special_folder_type() != Geary.SpecialFolderType.SPAM) {
if (current_folder.special_folder_type != Geary.SpecialFolderType.SPAM) {
// Move to spam folder.
try {
destination_folder = current_account.get_special_folder(Geary.SpecialFolderType.SPAM);
@ -1252,7 +1252,7 @@ public class GearyController {
return;
set_busy(true);
supports_copy.copy_email_async.begin(ids, destination.get_path(), cancellable_message,
supports_copy.copy_email_async.begin(ids, destination.path, cancellable_message,
on_copy_complete);
}
@ -1274,7 +1274,7 @@ public class GearyController {
return;
set_busy(true);
supports_move.move_email_async.begin(ids, destination.get_path(), cancellable_message,
supports_move.move_email_async.begin(ids, destination.path, cancellable_message,
on_move_complete);
}

View file

@ -39,7 +39,7 @@ public class Libmessagingmenu : NewMessagesIndicator {
}
private string get_source_id(Geary.Folder folder) {
return "new-messages-id-%s-%s".printf(folder.account.information.email, folder.get_path().to_string());
return "new-messages-id-%s-%s".printf(folder.account.information.email, folder.path.to_string());
}
private void on_activate_source(string source_id) {

View file

@ -56,7 +56,7 @@ public class FolderMenu : GtkUtil.ToggleToolbarDropdown {
}
private Gtk.MenuItem build_menu_item(Geary.Folder folder) {
Gtk.MenuItem menu_item = new Gtk.MenuItem.with_label(folder.get_path().to_string());
Gtk.MenuItem menu_item = new Gtk.MenuItem.with_label(folder.path.to_string());
menu_item.activate.connect(() => {
folder_selected(folder);
});
@ -65,7 +65,7 @@ public class FolderMenu : GtkUtil.ToggleToolbarDropdown {
}
private static int folder_sort(Geary.Folder a, Geary.Folder b) {
return a.get_path().compare_to(b.get_path());
return a.path.compare_to(b.path);
}
}

View file

@ -99,7 +99,7 @@ public class FormattedConversationData : Geary.BaseObject {
this.conversation = conversation;
this.account_owner_email = account_owner_email;
use_to = (folder != null) && folder.get_special_folder_type().is_outgoing();
use_to = (folder != null) && folder.special_folder_type.is_outgoing();
// Load preview-related data.
this.date = (preview.date != null)

View file

@ -52,7 +52,7 @@ public class Geary.DBus.Controller {
Geary.Folder? folder = null;
Gee.Collection<Geary.Folder> folders = account.list_matching_folders(null);
foreach(Geary.Folder folder_to_check in folders) {
if(folder_to_check.get_special_folder_type() == Geary.SpecialFolderType.INBOX) {
if(folder_to_check.special_folder_type == Geary.SpecialFolderType.INBOX) {
folder = folder_to_check;
break;
}

View file

@ -66,7 +66,7 @@ public abstract class Geary.AbstractAccount : BaseObject, Geary.Account {
public virtual Geary.Folder? get_special_folder(Geary.SpecialFolderType special) throws Error {
foreach (Folder folder in list_folders()) {
if (folder.get_special_folder_type() == special)
if (folder.special_folder_type == special)
return folder;
}

View file

@ -52,18 +52,16 @@ public abstract class Geary.AbstractFolder : BaseObject, Geary.Folder {
public abstract Geary.FolderProperties properties { get; }
public abstract Geary.FolderPath get_path();
public abstract Geary.FolderPath path { get; }
public abstract Geary.SpecialFolderType get_special_folder_type();
public abstract Geary.SpecialFolderType special_folder_type { get; }
/**
* Default is to display the basename of the Folder's path.
*/
public virtual string get_display_name() {
Geary.SpecialFolderType special_folder_type = get_special_folder_type();
return (special_folder_type == Geary.SpecialFolderType.NONE)
? get_path().basename : special_folder_type.get_display_name();
? path.basename : special_folder_type.get_display_name();
}
public abstract Geary.Folder.OpenState get_open_state();
@ -156,7 +154,7 @@ public abstract class Geary.AbstractFolder : BaseObject, Geary.Folder {
Cancellable? cancellable = null) throws Error;
public virtual string to_string() {
return "%s:%s".printf(account.to_string(), get_path().to_string());
return "%s:%s".printf(account.to_string(), path.to_string());
}
}

View file

@ -108,7 +108,7 @@ public interface Geary.Account : BaseObject {
}
private int folder_path_comparator(Geary.Folder a, Geary.Folder b) {
return a.get_path().compare_to(b.get_path());
return a.path.compare_to(b.path);
}
/**

View file

@ -111,6 +111,10 @@ public interface Geary.Folder : BaseObject {
public abstract Geary.FolderProperties properties { get; }
public abstract Geary.FolderPath path { get; }
public abstract Geary.SpecialFolderType special_folder_type { get; }
/**
* Fired when the folder is successfully opened by a caller.
*
@ -236,13 +240,6 @@ public interface Geary.Folder : BaseObject {
protected abstract void notify_special_folder_type_changed(Geary.SpecialFolderType old_type,
Geary.SpecialFolderType new_type);
public abstract Geary.FolderPath get_path();
/**
* Returns the special folder type of the folder.
*/
public abstract Geary.SpecialFolderType get_special_folder_type();
/**
* Returns a name suitable for displaying to the user.
*/

View file

@ -25,17 +25,30 @@ public class Geary.SearchFolderProperties : Geary.FolderProperties {
/**
* Special folder type used to query and display search results.
*/
public class Geary.SearchFolder : Geary.AbstractLocalFolder {
// Max number of emails that can ever be in the folder.
public static const int MAX_RESULT_EMAILS = 1000;
private weak Account _account;
public override Account account { get { return _account; } }
private SearchFolderProperties _properties = new SearchFolderProperties(0, 0);
public override FolderProperties properties { get { return _properties; } }
private static FolderRoot? path = null;
private FolderPath? _path = null;
public override FolderPath path {
get {
return (_path != null) ? _path : _path = new SearchFolderRoot();
}
}
public override SpecialFolderType special_folder_type {
get {
return Geary.SpecialFolderType.SEARCH;
}
}
private weak Account _account;
private SearchFolderProperties _properties = new SearchFolderProperties(0, 0);
private Gee.HashSet<Geary.FolderPath?> exclude_folders = new Gee.HashSet<Geary.FolderPath?>();
private Geary.SpecialFolderType[] exclude_types = {
Geary.SpecialFolderType.SPAM,
@ -72,7 +85,7 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder {
if (available != null) {
foreach (Geary.Folder folder in available) {
// Exclude it from searching if it's got the right special type.
if (folder.get_special_folder_type() in exclude_types)
if (folder.special_folder_type in exclude_types)
exclude_folder(folder);
}
}
@ -102,7 +115,7 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder {
// list_email_async() etc., but this leads to some more
// complications when redoing the search.
Gee.Collection<Geary.Email>? _new_results = yield account.local_search_async(
keywords, Geary.Email.Field.PROPERTIES, false, get_path(), MAX_RESULT_EMAILS, 0,
keywords, Geary.Email.Field.PROPERTIES, false, path, MAX_RESULT_EMAILS, 0,
exclude_folders, null, cancellable);
if (_new_results == null) {
@ -161,17 +174,6 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder {
throw error;
}
public override Geary.FolderPath get_path() {
if (path == null)
path = new SearchFolderRoot();
return path;
}
public override Geary.SpecialFolderType get_special_folder_type() {
return Geary.SpecialFolderType.SEARCH;
}
public override async Gee.List<Geary.Email>? list_email_async(int low, int count,
Geary.Email.Field required_fields, Folder.ListFlags flags, Cancellable? cancellable = null)
throws Error {
@ -285,7 +287,7 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder {
}
private void exclude_folder(Geary.Folder folder) {
exclude_folders.add(folder.get_path());
exclude_folders.add(folder.path);
}
private void exclude_orphan_emails() {

View file

@ -531,7 +531,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
try {
Geary.Folder? blacklist_folder = folder.account.get_special_folder(type);
if (blacklist_folder != null)
blacklist.add(blacklist_folder.get_path());
blacklist.add(blacklist_folder.path);
} catch (Error e) {
debug("Error finding special folder %s on account %s: %s",
type.to_string(), folder.account.to_string(), e.message);
@ -541,7 +541,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
// Add the current folder so we omit search results we can find through
// folder monitoring. Add "no folders" so we omit results that have
// been deleted permanently from the server.
blacklist.add(folder.get_path());
blacklist.add(folder.path);
blacklist.add(null);
return blacklist;

View file

@ -81,7 +81,7 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics {
throw new EngineError.OPEN_REQUIRED("%s not open", to_string());
}
public Geary.FolderPath get_path() {
public unowned Geary.FolderPath get_path() {
return path;
}

View file

@ -32,13 +32,26 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
}
}
public signal void report_problem(Geary.Account.Problem problem, Error? err);
public override Account account { get { return _account; } }
public override FolderProperties properties { get { return _properties; } }
private FolderPath? _path = null;
public override FolderPath path {
get {
return (_path != null) ? _path : _path = new SmtpOutboxFolderRoot();
}
}
public override SpecialFolderType special_folder_type {
get {
return Geary.SpecialFolderType.OUTBOX;
}
}
// Min and max times between attempting to re-send after a connection failure.
private const uint MIN_SEND_RETRY_INTERVAL_SEC = 4;
private const uint MAX_SEND_RETRY_INTERVAL_SEC = 64;
private static FolderRoot? path = null;
private ImapDB.Database db;
private weak Account _account;
@ -46,9 +59,7 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
private Nonblocking.Mailbox<OutboxRow> outbox_queue = new Nonblocking.Mailbox<OutboxRow>();
private SmtpOutboxFolderProperties _properties = new SmtpOutboxFolderProperties(0, 0);
public override Account account { get { return _account; } }
public override FolderProperties properties { get { return _properties; } }
public signal void report_problem(Geary.Account.Problem problem, Error? err);
// Requires the Database from the get-go because it runs a background task that access it
// whether open or not
@ -192,17 +203,6 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractLocalFolder, Geary.FolderSu
debug("Exiting outbox postman");
}
public override Geary.FolderPath get_path() {
if (path == null)
path = new SmtpOutboxFolderRoot();
return path;
}
public override Geary.SpecialFolderType get_special_folder_type() {
return Geary.SpecialFolderType.OUTBOX;
}
public override Geary.Folder.OpenState get_open_state() {
return is_open() ? Geary.Folder.OpenState.LOCAL : Geary.Folder.OpenState.CLOSED;
}

View file

@ -120,12 +120,12 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
return cmp;
// sort by path to stabilize the sort
return a.get_path().compare_to(b.get_path());
return a.path.compare_to(b.path);
}
// Lower the score, the higher the importance.
private static int score_folder(Folder a) {
switch (a.get_special_folder_type()) {
switch (a.special_folder_type) {
case SpecialFolderType.INBOX:
return -60;

View file

@ -156,7 +156,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
foreach(ImapDB.Folder folder_to_build in folders_to_build) {
GenericFolder folder = new_folder(folder_to_build.get_path(), remote, local, folder_to_build);
folder_map.set(folder.get_path(), folder);
folder_map.set(folder.path, folder);
built_folders.add(folder);
return_folders.add(folder);
}
@ -246,7 +246,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
Gee.HashMap<FolderPath, Geary.Folder> existing_folders = new Gee.HashMap<FolderPath, Geary.Folder>();
foreach (Geary.Folder folder in existing_list)
existing_folders.set(folder.get_path(), folder);
existing_folders.set(folder.path, folder);
// get all remote (server) folder paths
Gee.HashMap<FolderPath, Imap.Folder> remote_folders = yield enumerate_remote_folders_async(null,
@ -386,7 +386,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
// (but only promote, not demote, since getting the special folder type via its
// properties relies on the optional XLIST extension)
// use this iteration to add discovered properties to map
if (generic_folder.get_special_folder_type() == SpecialFolderType.NONE)
if (generic_folder.special_folder_type == SpecialFolderType.NONE)
generic_folder.set_special_folder_type(remote_folder.properties.attrs.get_special_folder_type());
}

View file

@ -15,7 +15,22 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde
Geary.Email.Field.PROPERTIES | ImapDB.Folder.REQUIRED_FOR_DUPLICATE_DETECTION;
public override Account account { get { return _account; } }
public override FolderProperties properties { get { return _properties; } }
public override FolderPath path {
get {
return local_folder.get_path();
}
}
private SpecialFolderType _special_folder_type;
public override SpecialFolderType special_folder_type {
get {
return _special_folder_type;
}
}
internal ImapDB.Folder local_folder { get; protected set; }
internal Imap.Folder? remote_folder { get; protected set; default = null; }
internal EmailPrefetcher email_prefetcher { get; private set; }
@ -25,7 +40,6 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde
private Geary.AggregatedFolderProperties _properties = new Geary.AggregatedFolderProperties();
private Imap.Account remote;
private ImapDB.Account local;
private SpecialFolderType special_folder_type;
private int open_count = 0;
private Nonblocking.ReportingSemaphore<bool>? remote_semaphore = null;
private ReplayQueue? replay_queue = null;
@ -38,7 +52,7 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde
this.remote = remote;
this.local = local;
this.local_folder = local_folder;
this.special_folder_type = special_folder_type;
_special_folder_type = special_folder_type;
_properties.add(local_folder.get_properties());
email_flag_watcher = new EmailFlagWatcher(this);
@ -52,22 +66,8 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde
warning("Folder %s destroyed without closing", to_string());
}
public override Geary.FolderPath get_path() {
return local_folder.get_path();
}
public override Geary.SpecialFolderType get_special_folder_type() {
return special_folder_type;
}
public void set_special_folder_type(SpecialFolderType new_type) {
if (special_folder_type == new_type)
return;
Geary.SpecialFolderType old_type = special_folder_type;
special_folder_type = new_type;
notify_special_folder_type_changed(old_type, new_type);
_special_folder_type = new_type;
}
public override Geary.Folder.OpenState get_open_state() {
@ -112,7 +112,7 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde
// folder)
if (local_properties.uid_next == null || local_properties.uid_validity == null) {
debug("Unable to verify UID next for %s: missing local UID next (%s) and/or validity (%s)",
get_path().to_string(), (local_properties.uid_next == null).to_string(),
path.to_string(), (local_properties.uid_next == null).to_string(),
(local_properties.uid_validity == null).to_string());
return false;
@ -120,7 +120,7 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde
if (remote_properties.uid_next == null || remote_properties.uid_validity == null) {
debug("Unable to verify UID next for %s: missing remote UID next (%s) and/or validity (%s)",
get_path().to_string(), (remote_properties.uid_next == null).to_string(),
path.to_string(), (remote_properties.uid_next == null).to_string(),
(remote_properties.uid_validity == null).to_string());
return false;
@ -133,7 +133,7 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde
//
// see http://tools.ietf.org/html/rfc3501#section-2.3.1.1
if (local_properties.uid_validity.value != remote_properties.uid_validity.value) {
debug("%s UID validity changed, detaching all email: %s -> %s", get_path().to_string(),
debug("%s UID validity changed, detaching all email: %s -> %s", path.to_string(),
local_properties.uid_validity.value.to_string(),
remote_properties.uid_validity.value.to_string());
@ -467,7 +467,7 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde
remote_semaphore = new Geary.Nonblocking.ReportingSemaphore<bool>(false);
// start the replay queue
replay_queue = new ReplayQueue(get_path().to_string(), remote_semaphore);
replay_queue = new ReplayQueue(path.to_string(), remote_semaphore);
try {
yield local_folder.open_async(cancellable);