Merge branch 'mjog/plugin-api-update' into 'mainline'

Plugin API update

See merge request GNOME/geary!478
This commit is contained in:
Michael Gratton 2020-03-30 11:05:12 +00:00
commit 8077941289
13 changed files with 63 additions and 98 deletions

View file

@ -1297,10 +1297,6 @@ internal class Application.Controller : Geary.BaseObject {
/** Notifies plugins of new email being displayed. */
internal void email_loaded(Geary.AccountInformation account,
Geary.Email loaded) {
foreach (NotificationContext plugin in
this.plugins.get_notification_contexts()) {
plugin.email_displayed(account, loaded);
}
foreach (EmailContext plugin in
this.plugins.get_email_contexts()) {
plugin.email_displayed(account, loaded);
@ -1481,10 +1477,6 @@ internal class Application.Controller : Geary.BaseObject {
AccountContext? context = this.accounts.get(service.account);
if (context != null) {
foreach (NotificationContext plugin in
this.plugins.get_notification_contexts()) {
plugin.email_sent(context.account.information, sent);
}
foreach (EmailContext plugin in
this.plugins.get_email_contexts()) {
plugin.email_sent(context.account.information, sent);

View file

@ -27,7 +27,7 @@ internal class Application.EmailContext :
this.action_group_name = action_group_name;
}
public async Plugin.EmailStore get_email()
public async Plugin.EmailStore get_email_store()
throws Plugin.Error.PERMISSION_DENIED {
return this.email;
}

View file

@ -27,7 +27,7 @@ internal class Application.FolderContext :
this.action_group_name = action_group_name;
}
public async Plugin.FolderStore get_folders()
public async Plugin.FolderStore get_folder_store()
throws Plugin.Error.PERMISSION_DENIED {
return this.folders;
}

View file

@ -67,9 +67,7 @@ internal class Application.NotificationContext :
private unowned Client application;
private FolderStoreFactory folders_factory;
private Plugin.FolderStore folders;
private EmailStoreFactory email_factory;
private Plugin.EmailStore email;
internal NotificationContext(Client application,
@ -77,19 +75,7 @@ internal class Application.NotificationContext :
EmailStoreFactory email_factory) {
this.application = application;
this.folders_factory = folders_factory;
this.folders = folders_factory.new_folder_store();
this.email_factory = email_factory;
this.email = email_factory.new_email_store();
}
public async Plugin.EmailStore get_email()
throws Plugin.Error.PERMISSION_DENIED {
return this.email;
}
public async Plugin.FolderStore get_folders()
throws Plugin.Error.PERMISSION_DENIED {
return this.folders;
}
public async Plugin.ContactStore get_contacts_for_folder(Plugin.Folder source)
@ -198,26 +184,10 @@ internal class Application.NotificationContext :
}
internal void destroy() {
this.folders_factory.destroy_folder_store(this.folders);
// Get an array so the loop does not blow up when removing values.
foreach (Geary.Folder monitored in this.folder_information.keys.to_array()) {
remove_folder(monitored);
}
this.email_factory.destroy_email_store(this.email);
}
internal void email_displayed(Geary.AccountInformation account,
Geary.Email email) {
this.email.email_displayed(
this.email_factory.to_plugin_email(email, account)
);
}
internal void email_sent(Geary.AccountInformation account,
Geary.Email email) {
this.email.email_sent(
this.email_factory.to_plugin_email(email, account)
);
}
internal void clear_new_messages(Geary.Folder location,

View file

@ -19,7 +19,11 @@ public void peas_register_types(TypeModule module) {
* Manages standard desktop application notifications.
*/
public class Plugin.DesktopNotifications :
PluginBase, NotificationExtension, TrustedExtension {
PluginBase,
NotificationExtension,
FolderExtension,
EmailExtension,
TrustedExtension {
private const Geary.SpecialFolderType[] MONITORED_TYPES = {
@ -30,6 +34,14 @@ public class Plugin.DesktopNotifications :
get; set construct;
}
public FolderContext folders {
get; set construct;
}
public EmailContext email {
get; set construct;
}
public global::Application.Client client_application {
get; set construct;
}
@ -40,29 +52,29 @@ public class Plugin.DesktopNotifications :
private const string ARRIVED_ID = "email-arrived";
private EmailStore? email = null;
private EmailStore? email_store = null;
private GLib.Notification? arrived_notification = null;
private GLib.Cancellable? cancellable = null;
public override async void activate() throws GLib.Error {
this.cancellable = new GLib.Cancellable();
this.email = yield this.notifications.get_email();
this.email_store = yield this.email.get_email_store();
this.notifications.new_messages_arrived.connect(on_new_messages_arrived);
this.notifications.new_messages_retired.connect(on_new_messages_retired);
FolderStore folders = yield this.notifications.get_folders();
folders.folders_available.connect(
FolderStore folder_store = yield this.folders.get_folder_store();
folder_store.folders_available.connect(
(folders) => check_folders(folders)
);
folders.folders_unavailable.connect(
folder_store.folders_unavailable.connect(
(folders) => check_folders(folders)
);
folders.folders_type_changed.connect(
folder_store.folders_type_changed.connect(
(folders) => check_folders(folders)
);
check_folders(folders.get_folders());
check_folders(folder_store.get_folders());
}
public override async void deactivate(bool is_shutdown) throws GLib.Error {
@ -234,7 +246,7 @@ public class Plugin.DesktopNotifications :
bool notified = false;
try {
Email? message = Geary.Collection.first(
yield this.email.get_email(
yield this.email_store.get_email(
Geary.Collection.single(Geary.Collection.first(added)),
this.cancellable
)

View file

@ -19,7 +19,7 @@ public void peas_register_types(TypeModule module) {
* Manages highlighting folders that have newly delivered mail
*/
public class Plugin.FolderHighlight :
PluginBase, NotificationExtension, TrustedExtension {
PluginBase, NotificationExtension, FolderExtension, TrustedExtension {
private const Geary.SpecialFolderType[] MONITORED_TYPES = {
@ -31,6 +31,10 @@ public class Plugin.FolderHighlight :
get; construct set;
}
public FolderContext folders {
get; construct set;
}
public global::Application.Client client_application {
get; construct set;
}
@ -43,17 +47,17 @@ public class Plugin.FolderHighlight :
this.notifications.new_messages_arrived.connect(on_new_messages_arrived);
this.notifications.new_messages_retired.connect(on_new_messages_retired);
FolderStore folders = yield this.notifications.get_folders();
folders.folders_available.connect(
FolderStore folder_store = yield this.folders.get_folder_store();
folder_store.folders_available.connect(
(folders) => check_folders(folders)
);
folders.folders_unavailable.connect(
folder_store.folders_unavailable.connect(
(folders) => check_folders(folders)
);
folders.folders_type_changed.connect(
folder_store.folders_type_changed.connect(
(folders) => check_folders(folders)
);
check_folders(folders.get_folders());
check_folders(folder_store.get_folders());
}
public override async void deactivate(bool is_shutdown) throws GLib.Error {

View file

@ -16,16 +16,21 @@ public void peas_register_types(TypeModule module) {
}
/** Updates the Unity messaging menu when new mail arrives. */
public class Plugin.MessagingMenu : PluginBase, NotificationExtension {
public class Plugin.MessagingMenu :
PluginBase, NotificationExtension, FolderExtension {
public NotificationContext notifications {
get; set construct;
}
public FolderContext folders {
get; set construct;
}
private global::MessagingMenu.App? app = null;
private FolderStore? folders = null;
private FolderStore? folder_store = null;
public override async void activate() throws GLib.Error {
@ -38,17 +43,17 @@ public class Plugin.MessagingMenu : PluginBase, NotificationExtension {
this.notifications.new_messages_arrived.connect(on_new_messages_changed);
this.notifications.new_messages_retired.connect(on_new_messages_changed);
this.folders = yield this.notifications.get_folders();
folders.folders_available.connect(
this.folder_store = yield this.folders.get_folder_store();
this.folder_store.folders_available.connect(
(folders) => check_folders(folders)
);
folders.folders_unavailable.connect(
this.folder_store.folders_unavailable.connect(
(folders) => check_folders(folders)
);
folders.folders_type_changed.connect(
this.folder_store.folders_type_changed.connect(
(folders) => check_folders(folders)
);
check_folders(folders.get_folders());
check_folders(this.folder_store.get_folders());
}
public override async void deactivate(bool is_shutdown) throws GLib.Error {
@ -89,7 +94,7 @@ public class Plugin.MessagingMenu : PluginBase, NotificationExtension {
private void on_activate_source(string source_id) {
if (this.folders != null) {
foreach (Folder folder in this.folders.get_folders()) {
foreach (Folder folder in this.folder_store.get_folders()) {
if (source_id == get_source_id(folder)) {
this.plugin_application.show_folder(folder);
break;

View file

@ -17,7 +17,7 @@ public void peas_register_types(TypeModule module) {
/** Updates Unity application badge with total new message count. */
public class Plugin.NotificationBadge :
PluginBase, NotificationExtension, TrustedExtension {
PluginBase, NotificationExtension, FolderExtension, TrustedExtension {
private const Geary.SpecialFolderType[] MONITORED_TYPES = {
@ -28,6 +28,10 @@ public class Plugin.NotificationBadge :
get; set construct;
}
public FolderContext folders {
get; set construct;
}
public global::Application.Client client_application {
get; set construct;
}
@ -53,17 +57,17 @@ public class Plugin.NotificationBadge :
global::Application.Client.APP_ID + ".desktop"
);
FolderStore folders = yield this.notifications.get_folders();
folders.folders_available.connect(
FolderStore folder_store = yield this.folders.get_folder_store();
folder_store.folders_available.connect(
(folders) => check_folders(folders)
);
folders.folders_unavailable.connect(
folder_store.folders_unavailable.connect(
(folders) => check_folders(folders)
);
folders.folders_type_changed.connect(
folder_store.folders_type_changed.connect(
(folders) => check_folders(folders)
);
check_folders(folders.get_folders());
check_folders(folder_store.get_folders());
this.notifications.notify["total-new-messages"].connect(on_total_changed);
update_count();

View file

@ -47,7 +47,7 @@ public interface Plugin.EmailContext : Geary.BaseObject {
* @throws Error.PERMISSIONS if permission to access
* this resource was not given
*/
public abstract async EmailStore get_email()
public abstract async EmailStore get_email_store()
throws Error.PERMISSION_DENIED;
/**

View file

@ -47,7 +47,7 @@ public interface Plugin.FolderContext : Geary.BaseObject {
* @throws Error.PERMISSIONS if permission to access
* this resource was not given
*/
public abstract async FolderStore get_folders()
public abstract async FolderStore get_folder_store()
throws Error.PERMISSION_DENIED;
/**

View file

@ -76,28 +76,6 @@ public interface Plugin.NotificationContext : Geary.BaseObject {
public signal void new_messages_retired(Plugin.Folder parent, int total);
/**
* Returns a store to lookup email for notifications.
*
* This method may prompt for permission before returning.
*
* @throws Error.PERMISSIONS if permission to access
* this resource was not given
*/
public abstract async Plugin.EmailStore get_email()
throws Error.PERMISSION_DENIED;
/**
* Returns a store to lookup folders for notifications.
*
* This method may prompt for permission before returning.
*
* @throws Error.PERMISSIONS if permission to access
* this resource was not given
*/
public abstract async Plugin.FolderStore get_folders()
throws Error.PERMISSION_DENIED;
/**
* Returns a store to lookup contacts for notifications.
*

View file

@ -15,10 +15,10 @@ public void peas_register_types(TypeModule module) {
}
/** Plays the desktop sent-mail sound when an email is sent. */
public class Plugin.SentSound : PluginBase, NotificationExtension {
public class Plugin.SentSound : PluginBase, EmailExtension {
public NotificationContext notifications {
public EmailContext email {
get; set construct;
}
@ -31,7 +31,7 @@ public class Plugin.SentSound : PluginBase, NotificationExtension {
this.context = new GSound.Context();
this.context.init();
this.store = yield this.notifications.get_email();
this.store = yield this.email.get_email_store();
this.store.email_sent.connect(on_sent);
}

View file

@ -49,7 +49,7 @@ public class Plugin.SpecialFolders :
public override async void activate() throws GLib.Error {
this.folder_store = yield this.folders.get_folders();
this.folder_store = yield this.folders.get_folder_store();
this.folder_store.folder_selected.connect(on_folder_selected);
this.folder_store.folders_type_changed.connect(on_folders_type_changed);
@ -59,7 +59,7 @@ public class Plugin.SpecialFolders :
this.empty_action.activate.connect(on_empty_activated);
this.plugin_application.register_action(this.empty_action);
this.email_store = yield this.email.get_email();
this.email_store = yield this.email.get_email_store();
this.email_store.email_displayed.connect(on_email_displayed);
}