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.
This commit is contained in:
parent
c252133222
commit
b8bbe53425
14 changed files with 74 additions and 49 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
@ -373,7 +373,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
|
||||
|
|
@ -398,7 +398,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,
|
||||
|
|
@ -621,9 +621,26 @@ public class Application.PluginManager : GLib.Object {
|
|||
this.is_startup = false;
|
||||
}
|
||||
|
||||
/** 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() {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue