[geary/wip/composer-folks: 17/22] Clean up context objects passed to ComposerWidget's constructor
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/composer-folks: 17/22] Clean up context objects passed to ComposerWidget's constructor
- Date: Sat, 15 Jun 2019 14:32:19 +0000 (UTC)
commit ef54509350c86c3361c0233e2e5150dd1fbb4017
Author: Michael Gratton <mike vee net>
Date: Sat Jun 15 00:04:39 2019 +1000
Clean up context objects passed to ComposerWidget's constructor
Pass an instance of GearyApplication to ComposerWidget instead of just
the config object. This allows removing a number of uses of both the
app and engine singleton properties and will provide a means of
accessing the app's contact store for addresss completion (i.e. Folks).
src/client/application/application-controller.vala | 4 +-
src/client/components/main-window.vala | 4 +-
src/client/composer/composer-widget.vala | 106 +++++++++++++--------
src/client/composer/composer-window.vala | 19 ++--
4 files changed, 79 insertions(+), 54 deletions(-)
---
diff --git a/src/client/application/application-controller.vala
b/src/client/application/application-controller.vala
index d41a5c2e..31e2803e 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -2011,11 +2011,11 @@ public class Application.Controller : Geary.BaseObject {
ComposerWidget widget;
if (mailto != null) {
widget = new ComposerWidget.from_mailto(
- current_account, mailto, application.config
+ this.application, current_account, mailto
);
} else {
widget = new ComposerWidget(
- current_account, compose_type, application.config
+ this.application, current_account, compose_type
);
}
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 0db53889..e66a11ff 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -131,9 +131,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
public void open_composer_for_mailbox(Geary.RFC822.MailboxAddress to) {
Application.Controller controller = this.application.controller;
ComposerWidget composer = new ComposerWidget(
- this.current_folder.account,
- NEW_MESSAGE,
- this.application.config
+ this.application, this.current_folder.account, NEW_MESSAGE
);
composer.to = to.to_full_display();
controller.add_composer(composer);
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 838292ea..d29a110d 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -238,8 +238,6 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
public string window_title { get; set; }
- public Configuration config { get; set; }
-
private string body_html = "";
[GtkChild]
@@ -385,6 +383,8 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
private Gspell.Checker subject_spell_checker = new Gspell.Checker(null);
private Gspell.Entry subject_spell_entry;
+ private GearyApplication application;
+
/** Fired when the current saved draft's id has changed. */
public signal void draft_id_changed(Geary.EmailIdentifier? id);
@@ -396,12 +396,12 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
public signal void subject_changed(string new_subject);
- public ComposerWidget(Geary.Account account,
- ComposeType compose_type,
- Configuration config) {
+ public ComposerWidget(GearyApplication application,
+ Geary.Account initial_account,
+ ComposeType compose_type) {
base_ref();
- this.account = account;
- this.config = config;
+ this.application = application;
+ this.account = initial_account;
this.compose_type = compose_type;
if (this.compose_type == ComposeType.NEW_MESSAGE)
this.state = ComposerState.PANED;
@@ -412,7 +412,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
this.state = ComposerState.INLINE_COMPACT;
this.header = new ComposerHeaderbar(
- config,
+ application.config,
this.state == ComposerState.INLINE_COMPACT
);
this.header.expand_composer.connect(() => {
@@ -458,7 +458,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
);
update_subject_spell_checker();
- this.editor = new ComposerWebView(config);
+ this.editor = new ComposerWebView(application.config);
this.editor.set_hexpand(true);
this.editor.set_vexpand(true);
this.editor.content_loaded.connect(on_editor_content_loaded);
@@ -482,14 +482,12 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
embed_header();
// Listen to account signals to update from menu.
- Geary.Engine.instance.account_available.connect(() => {
- update_from_field();
- });
- Geary.Engine.instance.account_unavailable.connect(() => {
- if (update_from_field()) {
- on_from_changed();
- }
- });
+ this.application.engine.account_available.connect(
+ on_account_available
+ );
+ this.application.engine.account_unavailable.connect(
+ on_account_unavailable
+ );
// TODO: also listen for account updates to allow adding identities while writing an email
this.from = new Geary.RFC822.MailboxAddresses.single(account.information.primary_mailbox);
@@ -545,13 +543,21 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
}
if (this.draft_manager != null)
close_draft_manager_async.begin(null);
+
+ this.application.engine.account_available.disconnect(
+ on_account_available
+ );
+ this.application.engine.account_unavailable.disconnect(
+ on_account_unavailable
+ );
+
base.destroy();
}
- public ComposerWidget.from_mailto(Geary.Account account,
- string mailto,
- Configuration config) {
- this(account, ComposeType.NEW_MESSAGE, config);
+ public ComposerWidget.from_mailto(GearyApplication application,
+ Geary.Account initial_account,
+ string mailto) {
+ this(application, account, ComposeType.NEW_MESSAGE);
Gee.HashMultiMap<string, string> headers = new Gee.HashMultiMap<string, string>();
if (mailto.length > Geary.ComposedEmail.MAILTO_SCHEME.length) {
@@ -765,7 +771,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
this.subject = reply_subject;
this.references = Geary.RFC822.Utils.reply_references(referred);
referred_quote = Util.Email.quote_email_for_reply(referred, quote,
- config.clock_format,
+ this.application.config.clock_format,
Geary.RFC822.TextFormat.HTML);
if (!Geary.String.is_empty(quote)) {
this.top_posting = false;
@@ -828,7 +834,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
foreach (SimpleActionGroup entries_users in composer_action_entries_users) {
entries_users.change_action_state(ACTION_SHOW_EXTENDED, false);
entries_users.change_action_state(
- ACTION_COMPOSE_AS_HTML, this.config.compose_as_html
+ ACTION_COMPOSE_AS_HTML, this.application.config.compose_as_html
);
}
@@ -1000,11 +1006,12 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
this.last_quote = quote;
// Always use reply styling, since forward styling doesn't work for inline quotes
this.editor.insert_html(
- Util.Email.quote_email_for_reply(referred,
- quote,
- config.clock_format,
- Geary.RFC822.TextFormat.HTML)
-
+ Util.Email.quote_email_for_reply(
+ referred,
+ quote,
+ this.application.config.clock_format,
+ Geary.RFC822.TextFormat.HTML
+ )
);
if (!referred_ids.contains(referred.id)) {
@@ -1199,8 +1206,10 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
// conversation back in the main window. The workaround here
// sets a new menu model and hence the menu_button constructs
// a new popover.
- this.composer_actions.change_action_state(ACTION_COMPOSE_AS_HTML,
- GearyApplication.instance.config.compose_as_html);
+ this.composer_actions.change_action_state(
+ ACTION_COMPOSE_AS_HTML,
+ this.application.config.compose_as_html
+ );
this.state = ComposerWidget.ComposerState.DETACHED;
this.header.detached();
@@ -1829,7 +1838,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
this.editor.set_rich_text(compose_as_html);
- GearyApplication.instance.config.compose_as_html = compose_as_html;
+ this.application.config.compose_as_html = compose_as_html;
}
private void on_show_extended_toggled(SimpleAction? action, Variant? new_state) {
@@ -1959,7 +1968,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
if (!this.editor.is_rich_text)
append_menu_section(context_menu, section);
} else if (section == this.context_menu_inspector) {
- if (this.config.enable_inspector)
+ if (this.application.config.enable_inspector)
append_menu_section(context_menu, section);
} else {
append_menu_section(context_menu, section);
@@ -2000,11 +2009,12 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
private void on_select_dictionary(SimpleAction action, Variant? param) {
if (this.spell_check_popover == null) {
+ Configuration config = this.application.config;
this.spell_check_popover = new SpellCheckPopover(
- this.select_dictionary_button, this.config
+ this.select_dictionary_button, config
);
this.spell_check_popover.selection_changed.connect((active_langs) => {
- this.config.spell_check_languages = active_langs;
+ config.spell_check_languages = active_langs;
update_subject_spell_checker();
});
}
@@ -2095,7 +2105,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
Gee.Map<string, Geary.AccountInformation> accounts;
try {
- accounts = Geary.Engine.instance.get_accounts();
+ accounts = this.application.engine.get_accounts();
} catch (Error e) {
warning("Could not fetch account info: %s", e.message);
return false;
@@ -2132,7 +2142,8 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
if (this.compose_type == ComposeType.NEW_MESSAGE) {
foreach (Geary.AccountInformation info in accounts.values) {
try {
- Geary.Account a = Geary.Engine.instance.get_account_instance(info);
+ Geary.Account a =
+ this.application.engine.get_account_instance(info);
if (a != this.account)
set_active = add_account_emails_to_from_list(a, set_active);
} catch (Error e) {
@@ -2201,7 +2212,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
private void update_subject_spell_checker() {
Gspell.Language? lang = null;
- string[] langs = this.config.spell_check_languages;
+ string[] langs = this.application.config.spell_check_languages;
if (langs.length == 1) {
lang = Gspell.Language.lookup(langs[0]);
} else {
@@ -2313,7 +2324,8 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
// so the user can still select text with a link in it,
// without the popover immediately appearing and raining on
// their text selection parade.
- if (this.pointer_url != null && this.config.compose_as_html) {
+ if (this.pointer_url != null &&
+ this.application.config.compose_as_html) {
Gdk.EventButton? button = (Gdk.EventButton) event;
Gdk.Rectangle location = Gdk.Rectangle();
location.x = (int) button.x;
@@ -2368,7 +2380,9 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
}
private void on_add_attachment() {
- AttachmentDialog dialog = new AttachmentDialog(this.container.top_window, this.config);
+ AttachmentDialog dialog = new AttachmentDialog(
+ this.container.top_window, this.application.config
+ );
if (dialog.run() == Gtk.ResponseType.ACCEPT) {
dialog.hide();
foreach (File file in dialog.get_files()) {
@@ -2392,7 +2406,9 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
}
private void on_insert_image(SimpleAction action, Variant? param) {
- AttachmentDialog dialog = new AttachmentDialog(this.container.top_window, this.config);
+ AttachmentDialog dialog = new AttachmentDialog(
+ this.container.top_window, this.application.config
+ );
Gtk.FileFilter filter = new Gtk.FileFilter();
// Translators: This is the name of the file chooser filter
// when inserting an image in the composer.
@@ -2452,4 +2468,14 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
update_cursor_actions();
}
+ private void on_account_available() {
+ update_from_field();
+ }
+
+ private void on_account_unavailable() {
+ if (update_from_field()) {
+ on_from_changed();
+ }
+ }
+
}
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index d11fbcb1..4ca5872a 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -14,6 +14,11 @@ public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
private const string DEFAULT_TITLE = _("New Message");
+ public new GearyApplication application {
+ get { return (GearyApplication) base.get_application(); }
+ set { base.set_application(value); }
+ }
+
public Gtk.ApplicationWindow top_window {
get { return this; }
}
@@ -25,19 +30,15 @@ public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
private bool closing = false;
public ComposerWindow(ComposerWidget composer) {
- Object(type: Gtk.WindowType.TOPLEVEL);
+ Object(application: application, type: Gtk.WindowType.TOPLEVEL);
this.composer = composer;
- // Make sure it gets added to the GtkApplication, to get the window-specific
- // composer actions to work properly.
- GearyApplication.instance.add_window(this);
-
// XXX Bug 764622
set_property("name", "GearyComposerWindow");
add(this.composer);
- if (composer.config.desktop_environment == Configuration.DesktopEnvironment.UNITY) {
+ if (application.config.desktop_environment == Configuration.DesktopEnvironment.UNITY) {
composer.embed_header();
} else {
composer.header.show_close_button = true;
@@ -59,7 +60,7 @@ public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
if (monitor == null) {
monitor = display.get_monitor_at_point(1, 1);
}
- int[] size = GearyApplication.instance.config.composer_window_size;
+ int[] size = this.application.config.composer_window_size;
//check if stored values are reasonable
if (monitor != null &&
size[0] >= 0 && size[0] <= monitor.geometry.width &&
@@ -87,7 +88,7 @@ public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
// Only store if the values are reasonable-looking.
if (width > 0 && width <= monitor.geometry.width &&
height > 0 && height <= monitor.geometry.height) {
- GearyApplication.instance.config.composer_window_size = {
+ this.application.config.composer_window_size = {
width, height
};
}
@@ -126,7 +127,7 @@ public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
subject = DEFAULT_TITLE;
}
- switch (this.composer.config.desktop_environment) {
+ switch (this.application.config.desktop_environment) {
case Configuration.DesktopEnvironment.UNITY:
this.title = subject;
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]