Add UI to preferences window for managing optional plugins
This commit is contained in:
parent
0c526f6644
commit
c290787284
4 changed files with 89 additions and 2 deletions
|
|
@ -87,6 +87,7 @@ json_glib = dependency('json-glib-1.0', version: '>= 1.0')
|
|||
libhandy = dependency('libhandy-0.0', version: '>= 0.0.10')
|
||||
libmath = cc.find_library('m')
|
||||
libpeas = dependency('libpeas-1.0', version: '>= 1.24.0')
|
||||
libpeas_gtk = dependency('libpeas-gtk-1.0', version: '>= 1.24.0')
|
||||
libsecret = dependency('libsecret-1', version: '>= 0.11')
|
||||
libsoup = dependency('libsoup-2.4', version: '>= 2.48')
|
||||
libunwind_dep = dependency(
|
||||
|
|
|
|||
|
|
@ -632,7 +632,8 @@ public class Application.Client : Gtk.Application {
|
|||
yield this.present();
|
||||
|
||||
Components.PreferencesWindow prefs = new Components.PreferencesWindow(
|
||||
get_active_main_window()
|
||||
get_active_main_window(),
|
||||
this.controller.plugins
|
||||
);
|
||||
prefs.show();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,13 +28,22 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow {
|
|||
set { base.set_application(value); }
|
||||
}
|
||||
|
||||
private Application.PluginManager plugins;
|
||||
|
||||
public PreferencesWindow(Application.MainWindow parent) {
|
||||
|
||||
public PreferencesWindow(Application.MainWindow parent,
|
||||
Application.PluginManager plugins) {
|
||||
Object(
|
||||
application: parent.application,
|
||||
transient_for: parent
|
||||
);
|
||||
this.plugins = plugins;
|
||||
|
||||
add_general_pane();
|
||||
add_plugin_pane();
|
||||
}
|
||||
|
||||
private void add_general_pane() {
|
||||
var autoselect = new Gtk.Switch();
|
||||
autoselect.valign = CENTER;
|
||||
|
||||
|
|
@ -104,6 +113,8 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow {
|
|||
group.add(startup_notifications_row);
|
||||
|
||||
var page = new Hdy.PreferencesPage();
|
||||
/// Translators: Preferences page title
|
||||
page.title = _("Preferences");
|
||||
page.propagate_natural_height = true;
|
||||
page.propagate_natural_width = true;
|
||||
page.add(group);
|
||||
|
|
@ -148,6 +159,79 @@ public class Components.PreferencesWindow : Hdy.PreferencesWindow {
|
|||
this.delete_event.connect(on_delete);
|
||||
}
|
||||
|
||||
private void add_plugin_pane() {
|
||||
var group = new Hdy.PreferencesGroup();
|
||||
/// Translators: Preferences group title
|
||||
//group.title = _("Plugins");
|
||||
/// Translators: Preferences group description
|
||||
//group.description = _("Optional features for Geary");
|
||||
|
||||
Application.Client? application = this.application;
|
||||
if (application != null) {
|
||||
foreach (Peas.PluginInfo plugin in
|
||||
this.plugins.get_optional_plugins()) {
|
||||
group.add(new_plugin_row(plugin));
|
||||
}
|
||||
}
|
||||
|
||||
var page = new Hdy.PreferencesPage();
|
||||
/// Translators: Preferences page title
|
||||
page.title = _("Plugins");
|
||||
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_action(@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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ geary_client_dependencies = [
|
|||
libhandy,
|
||||
libmath,
|
||||
libpeas,
|
||||
libpeas_gtk,
|
||||
libsecret,
|
||||
libsoup,
|
||||
libxml,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue