From 5b097c30761e392ab120f723fdff252a0b44f491 Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Mon, 17 Aug 2020 09:48:09 +1000 Subject: [PATCH] client: Port client codebase to handy-1 --- .../application/application-client.vala | 3 +- .../components-preferences-window.vala | 62 ++++++++++++++++--- .../components-problem-report-info-bar.vala | 3 +- .../components/components-search-bar.vala | 4 +- src/client/components/main-toolbar.vala | 4 +- .../dialogs-problem-details-dialog.vala | 2 +- ui/components-inspector-error-view.ui | 4 +- ui/components-inspector-system-view.ui | 4 +- ui/problem-details-dialog.ui | 5 +- 9 files changed, 67 insertions(+), 24 deletions(-) diff --git a/src/client/application/application-client.vala b/src/client/application/application-client.vala index ff7b15b5..43002728 100644 --- a/src/client/application/application-client.vala +++ b/src/client/application/application-client.vala @@ -390,6 +390,7 @@ public class Application.Client : Gtk.Application { // Calls Gtk.init(), amongst other things base.startup(); + Hdy.init(); this.engine = new Geary.Engine(get_resource_directory()); this.config = new Configuration(SCHEMA_ID); @@ -967,7 +968,7 @@ public class Application.Client : Gtk.Application { this, new Geary.ProblemReport(err) ); - dialog.run(); + dialog.show(); } if (mutex_token != Geary.Nonblocking.Mutex.INVALID_TOKEN) { diff --git a/src/client/components/components-preferences-window.vala b/src/client/components/components-preferences-window.vala index 65edae64..2fcb8ca9 100644 --- a/src/client/components/components-preferences-window.vala +++ b/src/client/components/components-preferences-window.vala @@ -35,7 +35,7 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow { this.title = plugin.get_name(); this.subtitle = plugin.get_description(); this.activatable_widget = this.sw; - this.add_action(this.sw); + this.add(this.sw); plugins.plugin_activated.connect((info) => { if (this.plugin == info) { @@ -124,7 +124,7 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow { autoselect_row.title = _("_Automatically select next message"); autoselect_row.use_underline = true; autoselect_row.activatable_widget = autoselect; - autoselect_row.add_action(autoselect); + autoselect_row.add(autoselect); var display_preview = new Gtk.Switch(); display_preview.valign = CENTER; @@ -134,7 +134,7 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow { display_preview_row.title = _("_Display conversation preview"); display_preview_row.use_underline = true; display_preview_row.activatable_widget = display_preview; - display_preview_row.add_action(display_preview); + display_preview_row.add(display_preview); var three_pane_view = new Gtk.Switch(); three_pane_view.valign = CENTER; @@ -144,7 +144,7 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow { three_pane_view_row.title = _("Use _three pane view"); three_pane_view_row.use_underline = true; three_pane_view_row.activatable_widget = three_pane_view; - three_pane_view_row.add_action(three_pane_view); + three_pane_view_row.add(three_pane_view); var single_key_shortucts = new Gtk.Switch(); single_key_shortucts.valign = CENTER; @@ -157,7 +157,7 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow { ); single_key_shortucts_row.use_underline = true; single_key_shortucts_row.activatable_widget = single_key_shortucts; - single_key_shortucts_row.add_action(single_key_shortucts); + single_key_shortucts_row.add(single_key_shortucts); var startup_notifications = new Gtk.Switch(); startup_notifications.valign = CENTER; @@ -171,7 +171,7 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow { "Geary will keep running after all windows are closed" ); startup_notifications_row.activatable_widget = startup_notifications; - startup_notifications_row.add_action(startup_notifications); + startup_notifications_row.add(startup_notifications); var group = new Hdy.PreferencesGroup(); /// Translators: Preferences group title @@ -188,8 +188,6 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow { /// Translators: Preferences page title page.title = _("Preferences"); page.icon_name = "preferences-other-symbolic"; - page.propagate_natural_height = true; - page.propagate_natural_width = true; page.add(group); page.show_all(); @@ -251,13 +249,59 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow { /// Translators: Preferences page title page.title = _("Plugins"); page.icon_name = "application-x-addon-symbolic"; - page.propagate_natural_width = true; page.add(group); page.show_all(); add(page); } + private Hdy.ActionRow new_plugin_row(Peas.PluginInfo plugin) { + var @switch = new Gtk.Switch(); + @switch.active = plugin.is_loaded(); + @switch.notify["active"].connect_after( + () => enable_plugin(plugin, switch) + ); + @switch.valign = CENTER; + + var row = new Hdy.ActionRow(); + row.title = plugin.get_name(); + row.subtitle = plugin.get_description(); + row.activatable_widget = @switch; + row.add(@switch); + + return row; + } + + private void enable_plugin(Peas.PluginInfo plugin, Gtk.Switch @switch) { + if (@switch.active && !plugin.is_loaded()) { + bool loaded = false; + try { + loaded = this.plugins.load_optional(plugin); + } catch (GLib.Error err) { + warning( + "Plugin %s not able to be loaded: %s", + plugin.get_name(), err.message + ); + } + if (!loaded) { + @switch.active = false; + } + } else if (!@switch.active && plugin.is_loaded()) { + bool unloaded = false; + try { + unloaded = this.plugins.unload_optional(plugin); + } catch (GLib.Error err) { + warning( + "Plugin %s not able to be loaded: %s", + plugin.get_name(), err.message + ); + } + if (!unloaded) { + @switch.active = true; + } + } + } + private void on_close() { close(); } diff --git a/src/client/components/components-problem-report-info-bar.vala b/src/client/components/components-problem-report-info-bar.vala index 63a6dfa1..d2042f8c 100644 --- a/src/client/components/components-problem-report-info-bar.vala +++ b/src/client/components/components-problem-report-info-bar.vala @@ -113,8 +113,7 @@ public class Components.ProblemReportInfoBar : InfoBar { main.application, this.report ); - dialog.run(); - dialog.destroy(); + dialog.show(); } } diff --git a/src/client/components/components-search-bar.vala b/src/client/components/components-search-bar.vala index 3988a2aa..c5f1076a 100644 --- a/src/client/components/components-search-bar.vala +++ b/src/client/components/components-search-bar.vala @@ -39,8 +39,8 @@ public class SearchBar : Hdy.SearchBar { this.entry.placeholder_text = DEFAULT_SEARCH_TEXT; this.entry.has_focus = true; - var column = new Hdy.Column(); - column.maximum_width = 450; + var column = new Hdy.Clamp(); + column.maximum_size = 450; column.add(this.entry); connect_entry(this.entry); diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala index 2a160f8b..31f87df6 100644 --- a/src/client/components/main-toolbar.vala +++ b/src/client/components/main-toolbar.vala @@ -95,13 +95,13 @@ public class MainToolbar : Gtk.Box { public void set_conversation_header(Gtk.HeaderBar header) { conversation_header.hide(); - this.header_group.add_header_bar(header); + this.header_group.add_gtk_header_bar(header); pack_start(header, true, true); } public void remove_conversation_header(Gtk.HeaderBar header) { remove(header); - this.header_group.remove_header_bar(header); + this.header_group.remove_gtk_header_bar(header); conversation_header.show(); } diff --git a/src/client/dialogs/dialogs-problem-details-dialog.vala b/src/client/dialogs/dialogs-problem-details-dialog.vala index 2dcfcb0c..34e4cb9c 100644 --- a/src/client/dialogs/dialogs-problem-details-dialog.vala +++ b/src/client/dialogs/dialogs-problem-details-dialog.vala @@ -9,7 +9,7 @@ * Displays technical details when a problem has been reported. */ [GtkTemplate (ui = "/org/gnome/Geary/problem-details-dialog.ui")] -public class Dialogs.ProblemDetailsDialog : Hdy.Dialog { +public class Dialogs.ProblemDetailsDialog : Gtk.Dialog { private const string ACTION_CLOSE = "problem-details-close"; diff --git a/ui/components-inspector-error-view.ui b/ui/components-inspector-error-view.ui index 13340235..78df053e 100644 --- a/ui/components-inspector-error-view.ui +++ b/ui/components-inspector-error-view.ui @@ -7,15 +7,13 @@ True False - + True False 16 16 32 32 - 500 - 1 True diff --git a/ui/components-inspector-system-view.ui b/ui/components-inspector-system-view.ui index 8ef50dc4..e470f9d5 100644 --- a/ui/components-inspector-system-view.ui +++ b/ui/components-inspector-system-view.ui @@ -19,15 +19,13 @@ True False - + True False 16 16 32 32 - 500 - 1 True diff --git a/ui/problem-details-dialog.ui b/ui/problem-details-dialog.ui index 5e667fed..bb3e0306 100644 --- a/ui/problem-details-dialog.ui +++ b/ui/problem-details-dialog.ui @@ -3,8 +3,11 @@ -