[geary/mjog/mail-merge-plugin: 58/74] Application, Plugin: Make object conversion methods consistent.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/mail-merge-plugin: 58/74] Application, Plugin: Make object conversion methods consistent.
- Date: Fri, 14 Aug 2020 02:09:04 +0000 (UTC)
commit a2614b7fd06523e30425f330a7d850c3d35ab772
Author: Michael Gratton <mike vee net>
Date: Fri Jul 17 17:54:59 2020 +1000
Application, Plugin: Make object conversion methods consistent.
Publicly, get objects for a variant rather than from it since we're
not actually getting the objects from the variant, just looking them
up using the variant as an id.
Internally, use `to_` rather than `get_` when converting between plugin
and engine objects, since its typically just a cast or a lookup to do
so.
src/client/application/application-client.vala | 6 ++---
.../application-email-store-factory.vala | 17 ++++++++-----
.../application-folder-plugin-context.vala | 8 +++---
.../application-folder-store-factory.vala | 16 ++++++------
.../application-notification-plugin-context.vala | 14 +++++------
.../application/application-plugin-manager.vala | 29 +++++++++++++++++-----
.../plugin/email-templates/email-templates.vala | 6 ++---
.../plugin/folder-highlight/folder-highlight.vala | 4 +--
src/client/plugin/mail-merge/mail-merge.vala | 6 ++---
src/client/plugin/plugin-email-store.vala | 4 +--
src/client/plugin/plugin-email.vala | 3 +++
src/client/plugin/plugin-folder-store.vala | 4 +--
src/client/plugin/plugin-folder.vala | 2 +-
.../plugin/special-folders/special-folders.vala | 4 +--
14 files changed, 74 insertions(+), 49 deletions(-)
---
diff --git a/src/client/application/application-client.vala b/src/client/application/application-client.vala
index 75b82c80f..ff7b15b5b 100644
--- a/src/client/application/application-client.vala
+++ b/src/client/application/application-client.vala
@@ -614,9 +614,9 @@ public class Application.Client : Gtk.Application {
MainWindow main = yield this.present();
if (id != null) {
EmailStoreFactory email = this.controller.plugins.globals.email;
- AccountContext? context = email.get_account_from_variant(id);
+ AccountContext? context = email.get_account_for_variant(id);
Geary.EmailIdentifier? email_id =
- email.get_email_identifier_from_variant(id);
+ email.get_email_identifier_for_variant(id);
if (context != null && email_id != null) {
// Determine what folders the email is in
Gee.MultiMap<Geary.EmailIdentifier,Geary.FolderPath>? folders = null;
@@ -694,7 +694,7 @@ public class Application.Client : Gtk.Application {
MainWindow main = yield this.present();
if (id != null) {
Geary.Folder? folder =
- this.controller.plugins.globals.folders.get_folder_from_variant(id);
+ this.controller.plugins.globals.folders.get_folder_for_variant(id);
if (folder != null) {
yield main.select_folder(folder, true);
}
diff --git a/src/client/application/application-email-store-factory.vala
b/src/client/application/application-email-store-factory.vala
index 6816dbaa3..c5c5925e7 100644
--- a/src/client/application/application-email-store-factory.vala
+++ b/src/client/application/application-email-store-factory.vala
@@ -89,11 +89,11 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
return emails;
}
- public Plugin.EmailIdentifier? get_email_identifier_from_variant(
+ public Plugin.EmailIdentifier? get_email_identifier_for_variant(
GLib.Variant variant
) {
- var account = this.factory.get_account_from_variant(variant);
- var id = this.factory.get_email_identifier_from_variant(variant);
+ var account = this.factory.get_account_for_variant(variant);
+ var id = this.factory.get_email_identifier_for_variant(variant);
IdImpl? plugin_id = null;
if (account != null && id != null) {
var plugin_account = this.factory.accounts.get(account);
@@ -306,6 +306,11 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
}
}
+ public Geary.Email? to_engine_email(Plugin.Email plugin) {
+ var impl = plugin as EmailImpl;
+ return (impl != null) ? impl.backing : null;
+ }
+
public Gee.Collection<Plugin.EmailIdentifier> to_plugin_ids(
Gee.Collection<Geary.EmailIdentifier> engine_ids,
AccountContext account
@@ -328,7 +333,7 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
}
/** Returns the account context for the given plugin email id. */
- public AccountContext get_account_from_variant(GLib.Variant target) {
+ public AccountContext get_account_for_variant(GLib.Variant target) {
AccountContext? account = null;
string id = (string) target.get_child_value(0);
foreach (var context in this.accounts.keys) {
@@ -343,9 +348,9 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
/** Returns the engine email id for the given plugin email id. */
public Geary.EmailIdentifier?
- get_email_identifier_from_variant(GLib.Variant target) {
+ get_email_identifier_for_variant(GLib.Variant target) {
Geary.EmailIdentifier? id = null;
- var context = get_account_from_variant(target);
+ var context = get_account_for_variant(target);
if (context != null) {
try {
id = context.account.to_email_identifier(
diff --git a/src/client/application/application-folder-plugin-context.vala
b/src/client/application/application-folder-plugin-context.vala
index 35174a6af..0c095b4fd 100644
--- a/src/client/application/application-folder-plugin-context.vala
+++ b/src/client/application/application-folder-plugin-context.vala
@@ -35,7 +35,7 @@ internal class Application.FolderPluginContext :
public void add_folder_info_bar(Plugin.Folder selected,
Plugin.InfoBar info_bar,
uint priority) {
- Geary.Folder? folder = this.globals.folders.get_engine_folder(selected);
+ Geary.Folder? folder = this.globals.folders.to_engine_folder(selected);
if (folder != null) {
foreach (MainWindow main in this.application.get_main_windows()) {
if (main.selected_folder == folder) {
@@ -53,7 +53,7 @@ internal class Application.FolderPluginContext :
public void remove_folder_info_bar(Plugin.Folder selected,
Plugin.InfoBar info_bar) {
- Geary.Folder? folder = this.globals.folders.get_engine_folder(selected);
+ Geary.Folder? folder = this.globals.folders.to_engine_folder(selected);
if (folder != null) {
foreach (MainWindow main in this.application.get_main_windows()) {
if (main.selected_folder == folder) {
@@ -69,7 +69,7 @@ internal class Application.FolderPluginContext :
public void register_folder_used_as(Plugin.Folder target,
string name,
string icon_name) throws Plugin.Error {
- var context = this.globals.folders.get_folder_context(target);
+ var context = this.globals.folders.to_folder_context(target);
if (context != null) {
try {
context.folder.set_used_as_custom(true);
@@ -85,7 +85,7 @@ internal class Application.FolderPluginContext :
public void unregister_folder_used_as(Plugin.Folder target)
throws Plugin.Error {
- var context = this.globals.folders.get_folder_context(target);
+ var context = this.globals.folders.to_folder_context(target);
if (context != null) {
try {
context.folder.set_used_as_custom(false);
diff --git a/src/client/application/application-folder-store-factory.vala
b/src/client/application/application-folder-store-factory.vala
index 84fdf1a85..e1eb4e6fb 100644
--- a/src/client/application/application-folder-store-factory.vala
+++ b/src/client/application/application-folder-store-factory.vala
@@ -70,7 +70,7 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
Geary.Folder engine = yield account.backing.account.create_personal_folder(
name, NONE, cancellable
);
- var folder = this.factory.get_plugin_folder(engine);
+ var folder = this.factory.to_plugin_folder(engine);
if (folder == null) {
throw new Geary.EngineError.NOT_FOUND(
"No plugin folder found for the created folder"
@@ -79,8 +79,8 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
return folder;
}
- public Plugin.Folder? get_folder_from_variant(GLib.Variant variant) {
- var folder = this.factory.get_folder_from_variant(variant);
+ public Plugin.Folder? get_folder_for_variant(GLib.Variant variant) {
+ var folder = this.factory.get_folder_for_variant(variant);
return this.factory.folders.get(folder);
}
@@ -189,24 +189,24 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
}
/** Returns the plugin folder for the given engine folder. */
- public Plugin.Folder? get_plugin_folder(Geary.Folder engine) {
+ public Plugin.Folder? to_plugin_folder(Geary.Folder engine) {
return this.folders.get(engine);
}
/** Returns the engine folder for the given plugin folder. */
- public Geary.Folder? get_engine_folder(Plugin.Folder plugin) {
+ public Geary.Folder? to_engine_folder(Plugin.Folder plugin) {
FolderImpl? impl = plugin as FolderImpl;
return (impl != null) ? impl.backing.folder : null;
}
/** Returns the folder context for the given plugin folder. */
- public FolderContext get_folder_context(Plugin.Folder plugin) {
+ public FolderContext to_folder_context(Plugin.Folder plugin) {
FolderImpl? impl = plugin as FolderImpl;
return (impl != null) ? impl.backing : null;
}
/** Returns the folder context for the given plugin folder id. */
- public Geary.Folder? get_folder_from_variant(GLib.Variant target) {
+ public Geary.Folder? get_folder_for_variant(GLib.Variant target) {
string id = (string) target.get_child_value(0);
AccountContext? context = null;
foreach (var key in this.accounts.keys) {
@@ -322,7 +322,7 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
if (main != null) {
Geary.Folder? selected = main.selected_folder;
if (selected != null) {
- var plugin = get_plugin_folder(selected);
+ var plugin = to_plugin_folder(selected);
if (plugin != null) {
foreach (FolderStoreImpl store in this.stores) {
store.folder_selected(plugin);
diff --git a/src/client/application/application-notification-plugin-context.vala
b/src/client/application/application-notification-plugin-context.vala
index 55c17d708..2f0b61038 100644
--- a/src/client/application/application-notification-plugin-context.vala
+++ b/src/client/application/application-notification-plugin-context.vala
@@ -80,7 +80,7 @@ internal class Application.NotificationPluginContext :
public async Plugin.ContactStore get_contacts_for_folder(Plugin.Folder source)
throws Plugin.Error.NOT_FOUND, Plugin.Error.PERMISSION_DENIED {
- Geary.Folder? folder = this.globals.folders.get_engine_folder(source);
+ Geary.Folder? folder = this.globals.folders.to_engine_folder(source);
AccountContext? context = null;
if (folder != null) {
context = this.application.controller.get_context_for_account(
@@ -109,7 +109,7 @@ internal class Application.NotificationPluginContext :
// conversations are visible. That is, if there is a main
// window, it's focused, the folder is selected, and the
// conversation list is at the top.
- Geary.Folder? folder = this.globals.folders.get_engine_folder(target);
+ Geary.Folder? folder = this.globals.folders.to_engine_folder(target);
MainWindow? window = this.application.last_active_main_window;
return (
folder != null &&
@@ -130,7 +130,7 @@ internal class Application.NotificationPluginContext :
*/
public int get_new_message_count(Plugin.Folder target)
throws Plugin.Error.NOT_FOUND {
- Geary.Folder? folder = this.globals.folders.get_engine_folder(target);
+ Geary.Folder? folder = this.globals.folders.to_engine_folder(target);
MonitorInformation? info = null;
if (folder != null) {
info = folder_information.get(folder);
@@ -150,7 +150,7 @@ internal class Application.NotificationPluginContext :
* recording new messages for a specific folder.
*/
public void start_monitoring_folder(Plugin.Folder target) {
- Geary.Folder? folder = this.globals.folders.get_engine_folder(target);
+ Geary.Folder? folder = this.globals.folders.to_engine_folder(target);
AccountContext? context =
this.application.controller.get_context_for_account(
folder.account.information
@@ -170,7 +170,7 @@ internal class Application.NotificationPluginContext :
/** Stops monitoring a folder for new messages. */
public void stop_monitoring_folder(Plugin.Folder target) {
- Geary.Folder? folder = this.globals.folders.get_engine_folder(target);
+ Geary.Folder? folder = this.globals.folders.to_engine_folder(target);
if (folder != null) {
remove_folder(folder);
}
@@ -179,7 +179,7 @@ internal class Application.NotificationPluginContext :
/** Determines if a folder is curently being monitored. */
public bool is_monitoring_folder(Plugin.Folder target) {
return this.folder_information.has_key(
- this.globals.folders.get_engine_folder(target)
+ this.globals.folders.to_engine_folder(target)
);
}
@@ -243,7 +243,7 @@ internal class Application.NotificationPluginContext :
bool arrived,
Gee.Collection<Geary.EmailIdentifier> delta) {
Plugin.Folder folder =
- this.globals.folders.get_plugin_folder(info.folder);
+ this.globals.folders.to_plugin_folder(info.folder);
AccountContext? context =
this.application.controller.get_context_for_account(
info.folder.account.information
diff --git a/src/client/application/application-plugin-manager.vala
b/src/client/application/application-plugin-manager.vala
index ce3acdeb5..69e8435ae 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -235,7 +235,7 @@ public class Application.PluginManager : GLib.Object {
}
public void show_folder(Plugin.Folder folder) {
- Geary.Folder? target = this.globals.folders.get_engine_folder(folder);
+ Geary.Folder? target = this.globals.folders.to_engine_folder(folder);
if (target != null) {
MainWindow window = this.backing.get_active_main_window();
window.select_folder.begin(target, true);
@@ -251,7 +251,7 @@ public class Application.PluginManager : GLib.Object {
);
}
- Geary.Folder? target = this.globals.folders.get_engine_folder(folder);
+ Geary.Folder? target = this.globals.folders.to_engine_folder(folder);
if (target != null) {
if (!main.prompt_empty_folder(target.used_as)) {
throw new Plugin.Error.PERMISSION_DENIED(
@@ -369,7 +369,7 @@ public class Application.PluginManager : GLib.Object {
// Ugh
this._save_to = (
(backing.save_to != null)
- ? this.application.globals.folders.get_plugin_folder(
+ ? this.application.globals.folders.to_plugin_folder(
this.backing.save_to
)
: null
@@ -394,7 +394,7 @@ public class Application.PluginManager : GLib.Object {
}
public void save_to_folder(Plugin.Folder? location) {
- var engine = this.application.globals.folders.get_engine_folder(location);
+ var engine = this.application.globals.folders.to_engine_folder(location);
if (engine != null && engine.account == this.backing.sender_context.account) {
this.backing.set_save_to_override.begin(
engine,
@@ -615,9 +615,26 @@ public class Application.PluginManager : GLib.Object {
}
+ /** Returns the client account context for the given plugin account, if any. */
+ public AccountContext? to_client_account(Plugin.Account plugin) {
+ var impl = plugin as AccountImpl;
+ return (impl != null) ? impl.backing : null;
+ }
+
+ /** Returns the engine account for the given plugin account, if any. */
+ public Geary.Account? to_engine_account(Plugin.Account plugin) {
+ var impl = plugin as AccountImpl;
+ return (impl != null) ? impl.backing.account : null;
+ }
+
/** Returns the engine folder for the given plugin folder, if any. */
- public Geary.Folder? get_engine_folder(Plugin.Folder plugin) {
- return this.globals.folders.get_engine_folder(plugin);
+ public Geary.Folder? to_engine_folder(Plugin.Folder plugin) {
+ return this.globals.folders.to_engine_folder(plugin);
+ }
+
+ /** Returns the engine email for the given plugin email, if any. */
+ public Geary.Email? to_engine_email(Plugin.Email plugin) {
+ return this.globals.email.to_engine_email(plugin);
}
public Gee.Collection<Peas.PluginInfo> get_optional_plugins() {
diff --git a/src/client/plugin/email-templates/email-templates.vala
b/src/client/plugin/email-templates/email-templates.vala
index dc6511887..7da99d7dd 100644
--- a/src/client/plugin/email-templates/email-templates.vala
+++ b/src/client/plugin/email-templates/email-templates.vala
@@ -336,7 +336,7 @@ public class Plugin.EmailTemplates :
private void on_new_activated(GLib.Action action, GLib.Variant? target) {
if (this.folder_store != null && target != null) {
- Folder? folder = this.folder_store.get_folder_from_variant(target);
+ Folder? folder = this.folder_store.get_folder_for_variant(target);
if (folder != null) {
this.edit_email.begin(folder, null, false);
}
@@ -346,7 +346,7 @@ public class Plugin.EmailTemplates :
private void on_edit_activated(GLib.Action action, GLib.Variant? target) {
if (this.email_store != null && target != null) {
EmailIdentifier? id =
- this.email_store.get_email_identifier_from_variant(target);
+ this.email_store.get_email_identifier_for_variant(target);
if (id != null) {
this.edit_email.begin(null, id, false);
}
@@ -356,7 +356,7 @@ public class Plugin.EmailTemplates :
private void on_send_activated(GLib.Action action, GLib.Variant? target) {
if (this.email_store != null && target != null) {
EmailIdentifier? id =
- this.email_store.get_email_identifier_from_variant(target);
+ this.email_store.get_email_identifier_for_variant(target);
if (id != null) {
this.edit_email.begin(null, id, true);
}
diff --git a/src/client/plugin/folder-highlight/folder-highlight.vala
b/src/client/plugin/folder-highlight/folder-highlight.vala
index ff4796adc..0960c8160 100644
--- a/src/client/plugin/folder-highlight/folder-highlight.vala
+++ b/src/client/plugin/folder-highlight/folder-highlight.vala
@@ -77,7 +77,7 @@ public class Plugin.FolderHighlight :
private void on_new_messages_arrived(Folder folder,
int total,
Gee.Collection<EmailIdentifier> added) {
- Geary.Folder? engine = this.client_plugins.get_engine_folder(folder);
+ Geary.Folder? engine = this.client_plugins.to_engine_folder(folder);
if (engine != null) {
foreach (global::Application.MainWindow window
in this.client_application.get_main_windows()) {
@@ -87,7 +87,7 @@ public class Plugin.FolderHighlight :
}
private void on_new_messages_retired(Folder folder, int total) {
- Geary.Folder? engine = this.client_plugins.get_engine_folder(folder);
+ Geary.Folder? engine = this.client_plugins.to_engine_folder(folder);
if (engine != null) {
foreach (global::Application.MainWindow window
in this.client_application.get_main_windows()) {
diff --git a/src/client/plugin/mail-merge/mail-merge.vala b/src/client/plugin/mail-merge/mail-merge.vala
index 56b41fcf3..c66bac062 100644
--- a/src/client/plugin/mail-merge/mail-merge.vala
+++ b/src/client/plugin/mail-merge/mail-merge.vala
@@ -336,7 +336,7 @@ public class Plugin.MailMerge :
private void on_edit_activated(GLib.Action action, GLib.Variant? target) {
if (this.email_store != null && target != null) {
EmailIdentifier? id =
- this.email_store.get_email_identifier_from_variant(target);
+ this.email_store.get_email_identifier_for_variant(target);
if (id != null) {
this.edit_email.begin(id);
}
@@ -346,9 +346,9 @@ public class Plugin.MailMerge :
private void on_merge_activated(GLib.Action action, GLib.Variant? target) {
if (this.email_store != null && target != null) {
EmailIdentifier? id =
- this.email_store.get_email_identifier_from_variant(target);
+ this.email_store.get_email_identifier_for_variant(target);
if (id != null) {
- this.merge_email.begin(id);
+ this.merge_email.begin(id, null);
}
}
}
diff --git a/src/client/plugin/plugin-email-store.vala b/src/client/plugin/plugin-email-store.vala
index 89727d3e8..75e6e2b6b 100644
--- a/src/client/plugin/plugin-email-store.vala
+++ b/src/client/plugin/plugin-email-store.vala
@@ -20,7 +20,7 @@ public interface Plugin.EmailStore : Geary.BaseObject {
* The type of variant email identifiers.
*
* @see EmailIdentifier.to_variant
- * @see get_email_identifier_from_variant
+ * @see get_email_identifier_for_variant
*/
public abstract GLib.VariantType email_identifier_variant_type { get; }
@@ -42,6 +42,6 @@ public interface Plugin.EmailStore : Geary.BaseObject {
* @see EmailIdentifier.to_variant
* @see email_identifier_variant_type
*/
- public abstract EmailIdentifier? get_email_identifier_from_variant(GLib.Variant id);
+ public abstract EmailIdentifier? get_email_identifier_for_variant(GLib.Variant id);
}
diff --git a/src/client/plugin/plugin-email.vala b/src/client/plugin/plugin-email.vala
index 1a9656c33..21e4c8fcd 100644
--- a/src/client/plugin/plugin-email.vala
+++ b/src/client/plugin/plugin-email.vala
@@ -89,6 +89,9 @@ public interface Plugin.EmailIdentifier :
*
* This value is suitable to be used as the `show-email`
* application action parameter.
+ *
+ * @see EmailStore.get_email_identifier_from_variant
+ * @see EmailStore.email_identifier_variant_type`
*/
public abstract GLib.Variant to_variant();
diff --git a/src/client/plugin/plugin-folder-store.vala b/src/client/plugin/plugin-folder-store.vala
index 5cd1127f0..4a622cfcc 100644
--- a/src/client/plugin/plugin-folder-store.vala
+++ b/src/client/plugin/plugin-folder-store.vala
@@ -20,7 +20,7 @@ public interface Plugin.FolderStore : Geary.BaseObject {
* The type of variant folder identifiers.
*
* @see Folder.to_variant
- * @see get_folder_from_variant
+ * @see get_folder_for_variant
*/
public abstract GLib.VariantType folder_variant_type { get; }
@@ -61,7 +61,7 @@ public interface Plugin.FolderStore : Geary.BaseObject {
* @see Folder.to_variant
* @see folder_variant_type
*/
- public abstract Folder? get_folder_from_variant(GLib.Variant id);
+ public abstract Folder? get_folder_for_variant(GLib.Variant id);
}
diff --git a/src/client/plugin/plugin-folder.vala b/src/client/plugin/plugin-folder.vala
index bfa43d9ef..167c02e97 100644
--- a/src/client/plugin/plugin-folder.vala
+++ b/src/client/plugin/plugin-folder.vala
@@ -36,7 +36,7 @@ public interface Plugin.Folder : Geary.BaseObject {
* FolderStore}, and is suitable to be used as the `show-folder`
* application action parameter.
*
- * @see FolderStore.get_folder_from_variant
+ * @see FolderStore.get_folder_for_variant
* @see FolderStore.folder_variant_type
*/
public abstract GLib.Variant to_variant();
diff --git a/src/client/plugin/special-folders/special-folders.vala
b/src/client/plugin/special-folders/special-folders.vala
index 97d2b66ab..b65325c1c 100644
--- a/src/client/plugin/special-folders/special-folders.vala
+++ b/src/client/plugin/special-folders/special-folders.vala
@@ -219,7 +219,7 @@ public class Plugin.SpecialFolders :
private void on_edit_activated(GLib.Action action, GLib.Variant? target) {
if (this.email_store != null && target != null) {
- EmailIdentifier? id = this.email_store.get_email_identifier_from_variant(
+ EmailIdentifier? id = this.email_store.get_email_identifier_for_variant(
target
);
if (id != null) {
@@ -232,7 +232,7 @@ public class Plugin.SpecialFolders :
private void on_empty_activated(GLib.Action action, GLib.Variant? target) {
if (this.folder_store != null && target != null) {
- Folder? folder = this.folder_store.get_folder_from_variant(target);
+ Folder? folder = this.folder_store.get_folder_for_variant(target);
if (folder != null) {
this.plugin_application.empty_folder.begin(folder);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]