[geary/mjog/email-templates: 16/17] Application.PluginManager: Use AccountContext keys for account impl map
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/email-templates: 16/17] Application.PluginManager: Use AccountContext keys for account impl map
- Date: Wed, 8 Apr 2020 09:23:48 +0000 (UTC)
commit a0225f63a1c265995b55cb42128f1a36dedd752d
Author: Michael Gratton <mike vee net>
Date: Tue Apr 7 17:39:50 2020 +1000
Application.PluginManager: Use AccountContext keys for account impl map
Use AccountContext as keys the Plugin.Application implementation map to
reduce the need for getting instances from the controller.
.../application-email-plugin-context.vala | 20 +++++++++++-----
.../application-email-store-factory.vala | 27 ++++++++++------------
.../application-folder-store-factory.vala | 23 +++++++++---------
.../application-notification-plugin-context.vala | 10 ++++----
.../application/application-plugin-manager.vala | 8 +++----
5 files changed, 47 insertions(+), 41 deletions(-)
---
diff --git a/src/client/application/application-email-plugin-context.vala
b/src/client/application/application-email-plugin-context.vala
index adeb2f4c..1f45a726 100644
--- a/src/client/application/application-email-plugin-context.vala
+++ b/src/client/application/application-email-plugin-context.vala
@@ -68,16 +68,24 @@ internal class Application.EmailPluginContext :
internal void email_displayed(Geary.AccountInformation account,
Geary.Email email) {
- this.email.email_displayed(
- this.email_factory.to_plugin_email(email, account)
- );
+ AccountContext? context =
+ this.application.controller.get_context_for_account(account);
+ if (context != null) {
+ this.email.email_displayed(
+ this.email_factory.to_plugin_email(email, context)
+ );
+ }
}
internal void email_sent(Geary.AccountInformation account,
Geary.Email email) {
- this.email.email_sent(
- this.email_factory.to_plugin_email(email, account)
- );
+ AccountContext? context =
+ this.application.controller.get_context_for_account(account);
+ if (context != null) {
+ this.email.email_sent(
+ this.email_factory.to_plugin_email(email, context)
+ );
+ }
}
internal void destroy() {
diff --git a/src/client/application/application-email-store-factory.vala
b/src/client/application/application-email-store-factory.vala
index 477a12a1..031f08fa 100644
--- a/src/client/application/application-email-store-factory.vala
+++ b/src/client/application/application-email-store-factory.vala
@@ -24,12 +24,12 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
private Controller controller;
- private Gee.Map<Geary.AccountInformation,PluginManager.AccountImpl> accounts;
+ private Gee.Map<AccountContext,PluginManager.AccountImpl> accounts;
public EmailStoreImpl(
Controller controller,
- Gee.Map<Geary.AccountInformation,PluginManager.AccountImpl> accounts
+ Gee.Map<AccountContext,PluginManager.AccountImpl> accounts
) {
this.controller = controller;
this.accounts = accounts;
@@ -45,7 +45,7 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
// group them by account up front. The common case will be
// only a single account, so optimise for that a bit.
- var accounts = new Gee.HashMap<
+ var found_accounts = new Gee.HashMap<
AccountContext, Gee.Set<Geary.EmailIdentifier>
>();
AccountContext? current_account = null;
@@ -55,20 +55,20 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
if (id_impl != null) {
if (id_impl._account.backing != current_account) {
current_account = id_impl._account.backing;
- engine_ids = accounts.get(current_account);
+ engine_ids = found_accounts.get(current_account);
if (engine_ids == null) {
engine_ids = new Gee.HashSet<Geary.EmailIdentifier>();
- accounts.set(current_account, engine_ids);
+ found_accounts.set(current_account, engine_ids);
}
}
engine_ids.add(id_impl.backing);
}
}
- foreach (var context in accounts.keys) {
+ foreach (var context in found_accounts.keys) {
Gee.Collection<Geary.Email> batch =
yield context.emails.list_email_by_sparse_id_async(
- accounts.get(context),
+ found_accounts.get(context),
REQUIRED_FIELDS,
NONE,
context.cancellable
@@ -76,10 +76,7 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
if (batch != null) {
foreach (var email in batch) {
emails.add(
- new EmailImpl(
- email,
- this.accounts.get(context.account.information)
- )
+ new EmailImpl(email, this.accounts.get(context))
);
}
}
@@ -177,7 +174,7 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
private Controller controller;
- private Gee.Map<Geary.AccountInformation,PluginManager.AccountImpl> accounts;
+ private Gee.Map<AccountContext,PluginManager.AccountImpl> accounts;
private Gee.Set<EmailStoreImpl> stores =
new Gee.HashSet<EmailStoreImpl>();
@@ -187,7 +184,7 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
*/
public EmailStoreFactory(
Controller controller,
- Gee.Map<Geary.AccountInformation,PluginManager.AccountImpl> accounts
+ Gee.Map<AccountContext,PluginManager.AccountImpl> accounts
) {
this.controller = controller;
this.accounts = accounts;
@@ -219,7 +216,7 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
public Gee.Collection<Plugin.EmailIdentifier> to_plugin_ids(
Gee.Collection<Geary.EmailIdentifier> engine_ids,
- Geary.AccountInformation account
+ AccountContext account
) {
var plugin_ids = new Gee.HashSet<Plugin.EmailIdentifier>();
foreach (var id in engine_ids) {
@@ -234,7 +231,7 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
}
public Plugin.Email to_plugin_email(Geary.Email engine,
- Geary.AccountInformation account) {
+ AccountContext account) {
return new EmailImpl(engine, this.accounts.get(account));
}
diff --git a/src/client/application/application-folder-store-factory.vala
b/src/client/application/application-folder-store-factory.vala
index 4eb60760..2b7de9ee 100644
--- a/src/client/application/application-folder-store-factory.vala
+++ b/src/client/application/application-folder-store-factory.vala
@@ -140,7 +140,7 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
private Controller controller;
- private Gee.Map<Geary.AccountInformation,PluginManager.AccountImpl> accounts;
+ private Gee.Map<AccountContext,PluginManager.AccountImpl> accounts;
private Gee.Map<Geary.Folder,FolderImpl> folders =
new Gee.HashMap<Geary.Folder,FolderImpl>();
private Gee.Set<FolderStoreImpl> stores =
@@ -151,7 +151,7 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
* Constructs a new factory instance.
*/
public FolderStoreFactory(Controller controller,
- Gee.Map<Geary.AccountInformation,PluginManager.AccountImpl> accounts) {
+ Gee.Map<AccountContext,PluginManager.AccountImpl> accounts) {
this.controller = controller;
this.controller.application.window_added.connect(on_window_added);
foreach (var main in this.controller.application.get_main_windows()) {
@@ -207,24 +207,22 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
added.folders_available.connect(on_folders_available);
added.folders_unavailable.connect(on_folders_unavailable);
added.account.folders_use_changed.connect(on_folders_use_changed);
- add_folders(added.get_folders());
+ add_folders(added, added.get_folders());
}
internal void remove_account(AccountContext removed) {
removed.folders_available.disconnect(on_folders_available);
removed.folders_unavailable.disconnect(on_folders_unavailable);
removed.account.folders_use_changed.disconnect(on_folders_use_changed);
- remove_folders(removed.get_folders());
+ remove_folders(removed, removed.get_folders());
}
- private void add_folders(Gee.Collection<FolderContext> to_add) {
+ private void add_folders(AccountContext account,
+ Gee.Collection<FolderContext> to_add) {
foreach (var context in to_add) {
this.folders.set(
context.folder,
- new FolderImpl(
- context,
- this.accounts.get(context.folder.account.information)
- )
+ new FolderImpl(context, this.accounts.get(account))
);
}
var folder_impls = to_plugin_folders(
@@ -237,7 +235,8 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
}
}
- private void remove_folders(Gee.Collection<FolderContext> to_remove) {
+ private void remove_folders(AccountContext account,
+ Gee.Collection<FolderContext> to_remove) {
foreach (var context in to_remove) {
this.folders.unset(context.folder);
}
@@ -263,12 +262,12 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
private void on_folders_available(AccountContext account,
Gee.Collection<FolderContext> available) {
- add_folders(available);
+ add_folders(account, available);
}
private void on_folders_unavailable(AccountContext account,
Gee.Collection<FolderContext> unavailable) {
- remove_folders(unavailable);
+ remove_folders(account, unavailable);
}
private void on_folders_use_changed(Geary.Account account,
diff --git a/src/client/application/application-notification-plugin-context.vala
b/src/client/application/application-notification-plugin-context.vala
index 915a7fb2..4003cea2 100644
--- a/src/client/application/application-notification-plugin-context.vala
+++ b/src/client/application/application-notification-plugin-context.vala
@@ -244,14 +244,16 @@ internal class Application.NotificationPluginContext :
Gee.Collection<Geary.EmailIdentifier> delta) {
Plugin.Folder folder =
this.folders_factory.get_plugin_folder(info.folder);
- if (arrived) {
+ AccountContext? context =
+ this.application.controller.get_context_for_account(
+ info.folder.account.information
+ );
+ if (arrived && context != null) {
this._total_new_messages += delta.size;
new_messages_arrived(
folder,
info.recent_ids.size,
- this.email_factory.to_plugin_ids(
- delta, info.folder.account.information
- )
+ this.email_factory.to_plugin_ids(delta, context)
);
} else {
this._total_new_messages -= delta.size;
diff --git a/src/client/application/application-plugin-manager.vala
b/src/client/application/application-plugin-manager.vala
index f2e83110..417cf1fd 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -214,8 +214,8 @@ public class Application.PluginManager : GLib.Object {
private bool is_shutdown = false;
private string trusted_path;
- private Gee.Map<Geary.AccountInformation,AccountImpl> plugin_accounts =
- new Gee.HashMap<Geary.AccountInformation,AccountImpl>();
+ private Gee.Map<AccountContext,AccountImpl> plugin_accounts =
+ new Gee.HashMap<AccountContext,AccountImpl>();
private FolderStoreFactory folders_factory;
private EmailStoreFactory email_factory;
@@ -365,13 +365,13 @@ public class Application.PluginManager : GLib.Object {
}
internal void add_account(AccountContext added) {
- this.plugin_accounts.set(added.account.information, new AccountImpl(added));
+ this.plugin_accounts.set(added, new AccountImpl(added));
this.folders_factory.add_account(added);
}
internal void remove_account(AccountContext removed) {
this.folders_factory.remove_account(removed);
- this.plugin_accounts.unset(removed.account.information);
+ this.plugin_accounts.unset(removed);
}
private void on_load_plugin(Peas.PluginInfo info) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]