Skip to content

Commit 76304ef

Browse files
committed
#3170: Plugins can now be enabled/disabled via the Preferences dialog.
1 parent 2759ed8 commit 76304ef

23 files changed

+1159
-659
lines changed

plugins/shotwell-publishing/FacebookPublishing.vala

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class FacebookService : Object, Spit.Pluggable, Spit.Publishing.Service {
1010
Spit.Publishing.CURRENT_API_VERSION);
1111
}
1212

13-
public string get_id() {
13+
public unowned string get_id() {
1414
return "org.yorba.shotwell.publishing.facebook";
1515
}
1616

17-
public string get_pluggable_name() {
17+
public unowned string get_pluggable_name() {
1818
return "Facebook";
1919
}
2020

@@ -26,6 +26,9 @@ public class FacebookService : Object, Spit.Pluggable, Spit.Publishing.Service {
2626
info.website_url = "http://www.yorba.org";
2727
}
2828

29+
public void activation(bool enabled) {
30+
}
31+
2932
public Spit.Publishing.Publisher create_publisher(Spit.Publishing.PluginHost host) {
3033
return new Publishing.Facebook.FacebookPublisher(this, host);
3134
}

plugins/shotwell-publishing/PicasaPublishing.vala

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class PicasaService : Object, Spit.Pluggable, Spit.Publishing.Service {
1010
Spit.Publishing.CURRENT_API_VERSION);
1111
}
1212

13-
public string get_id() {
13+
public unowned string get_id() {
1414
return "org.yorba.shotwell.publishing.picasa";
1515
}
1616

17-
public string get_pluggable_name() {
17+
public unowned string get_pluggable_name() {
1818
return "Picasa Web Albums";
1919
}
2020

@@ -34,6 +34,9 @@ public class PicasaService : Object, Spit.Pluggable, Spit.Publishing.Service {
3434
return (Spit.Publishing.Publisher.MediaType.PHOTO |
3535
Spit.Publishing.Publisher.MediaType.VIDEO);
3636
}
37+
38+
public void activation(bool enabled) {
39+
}
3740
}
3841

3942
namespace Publishing.Picasa {

plugins/shotwell-publishing/shotwell-publishing.vala

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ private class ShotwellPublishingCoreServices : Object, Spit.Module {
1818
~ShotwellPublishingCoreServices() {
1919
}
2020

21-
public string get_name() {
22-
return "Core Publishing Services";
21+
public unowned string get_module_name() {
22+
return _("Core Publishing Services");
2323
}
2424

25-
public string get_version() {
25+
public unowned string get_version() {
2626
return _VERSION;
2727
}
2828

29-
public string get_id() {
29+
public unowned string get_id() {
3030
return "org.yorba.shotwell.publishing.core_services";
3131
}
3232

33-
public Spit.Pluggable[]? get_pluggables() {
33+
public unowned Spit.Pluggable[]? get_pluggables() {
3434
return pluggables;
3535
}
3636
}
@@ -58,7 +58,7 @@ public unowned Spit.Module? spit_entry_point(int host_min_spit_interface, int ho
5858

5959
public void g_module_unload() {
6060
if (core_services != null)
61-
debug("%s %s unloaded", core_services.get_name(), core_services.get_version());
61+
debug("%s %s unloaded", core_services.get_module_name(), core_services.get_version());
6262
else
6363
debug("core_services unloaded prior to spit_entry_point being called");
6464

plugins/shotwell-transitions/CrumbleEffect.vala

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
using Spit;
99

1010
private class CrumbleEffectDescriptor : ShotwellTransitionDescriptor {
11-
public override string get_id() {
11+
public override unowned string get_id() {
1212
return "org.yorba.shotwell.transitions.crumble";
1313
}
1414

15-
public override string get_pluggable_name() {
15+
public override unowned string get_pluggable_name() {
1616
return _("Crumble");
1717
}
1818

plugins/shotwell-transitions/FadeEffect.vala

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
using Spit;
99

1010
private class FadeEffectDescriptor : ShotwellTransitionDescriptor {
11-
public override string get_id() {
11+
public override unowned string get_id() {
1212
return "org.yorba.shotwell.transitions.fade";
1313
}
1414

15-
public override string get_pluggable_name() {
15+
public override unowned string get_pluggable_name() {
1616
return _("Fade");
1717
}
1818

plugins/shotwell-transitions/SlideEffect.vala

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
using Spit;
99

1010
private class SlideEffectDescriptor : ShotwellTransitionDescriptor {
11-
public override string get_id() {
11+
public override unowned string get_id() {
1212
return "org.yorba.shotwell.transitions.slide";
1313
}
1414

15-
public override string get_pluggable_name() {
15+
public override unowned string get_pluggable_name() {
1616
return _("Slide");
1717
}
1818

plugins/shotwell-transitions/shotwell-transitions.vala

+17-14
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ private class ShotwellTransitions : Object, Spit.Module {
1515
pluggables += new CrumbleEffectDescriptor();
1616
}
1717

18-
public string get_name() {
19-
return "Shotwell Transitions";
18+
public unowned string get_module_name() {
19+
return _("Core Slideshow Transitions");
2020
}
2121

22-
public string get_version() {
22+
public unowned string get_version() {
2323
return _VERSION;
2424
}
2525

26-
public string get_id() {
26+
public unowned string get_id() {
2727
return "org.yorba.shotwell.transitions";
2828
}
2929

30-
public Spit.Pluggable[]? get_pluggables() {
30+
public unowned Spit.Pluggable[]? get_pluggables() {
3131
return pluggables;
3232
}
3333
}
3434

35-
private ShotwellTransitions? spitwad = null;
35+
private ShotwellTransitions? module = null;
3636

3737
// This entry point is required for all SPIT modules.
3838
public unowned Spit.Module? spit_entry_point(int host_min_spit_interface, int host_max_spit_interface,
@@ -42,19 +42,19 @@ public unowned Spit.Module? spit_entry_point(int host_min_spit_interface, int ho
4242
if (module_spit_interface == Spit.UNSUPPORTED_INTERFACE)
4343
return null;
4444

45-
if (spitwad == null)
46-
spitwad = new ShotwellTransitions();
45+
if (module == null)
46+
module = new ShotwellTransitions();
4747

48-
return spitwad;
48+
return module;
4949
}
5050

5151
public void g_module_unload() {
52-
if (spitwad != null)
53-
debug("%s %s unloaded", spitwad.get_name(), spitwad.get_version());
52+
if (module != null)
53+
debug("%s %s unloaded", module.get_module_name(), module.get_version());
5454
else
5555
debug("spitter unloaded prior to spit_entry_point being called");
5656

57-
spitwad = null;
57+
module = null;
5858
}
5959

6060
// This is here to keep valac happy.
@@ -68,9 +68,9 @@ public abstract class ShotwellTransitionDescriptor : Object, Spit.Pluggable, Spi
6868
Spit.Transitions.CURRENT_INTERFACE);
6969
}
7070

71-
public abstract string get_id();
71+
public abstract unowned string get_id();
7272

73-
public abstract string get_pluggable_name();
73+
public abstract unowned string get_pluggable_name();
7474

7575
public void get_info(out Spit.PluggableInfo info) {
7676
info.authors = "Maxim Kartashev, Jim Nelson";
@@ -84,6 +84,9 @@ public abstract class ShotwellTransitionDescriptor : Object, Spit.Pluggable, Spi
8484
info.website_url = "http://www.yorba.org";
8585
}
8686

87+
public void activation(bool enabled) {
88+
}
89+
8790
public abstract Spit.Transitions.Effect create(Spit.HostInterface host);
8891
}
8992

src/Config.vala

+21-2
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,19 @@ public class Config {
269269
return get_int("/apps/shotwell/sharing/picasa/default_size", 3) - 1;
270270
}
271271

272-
private string make_plugin_path(string domain, string id, string key) {
273-
return "%s/%s/%s/%s".printf(PATH_SHOTWELL, domain, id, key);
272+
public static string? clean_plugin_id(string id) {
273+
string cleaned = id.replace("/", "_");
274+
cleaned = cleaned.strip();
275+
276+
return !is_string_empty(cleaned) ? cleaned : null;
277+
}
278+
279+
private static string make_plugin_path(string domain, string id, string key) {
280+
string? cleaned_id = clean_plugin_id(id);
281+
if (cleaned_id == null)
282+
cleaned_id = "default";
283+
284+
return "%s/%s/%s/%s".printf(PATH_SHOTWELL, domain, cleaned_id, key);
274285
}
275286

276287
public bool get_plugin_bool(string domain, string id, string key, bool def) {
@@ -309,6 +320,14 @@ public class Config {
309320
unset(make_plugin_path(domain, id, key));
310321
}
311322

323+
public bool is_plugin_enabled(string id, bool def) {
324+
return get_bool("/apps/shotwell/plugins/%s/enabled".printf(clean_plugin_id(id)), def);
325+
}
326+
327+
public void set_plugin_enabled(string id, bool enabled) {
328+
set_bool("/apps/shotwell/plugins/%s/enabled".printf(clean_plugin_id(id)), enabled);
329+
}
330+
312331
public string? get_publishing_string(string domain, string key, string? default_value = null) {
313332
return get_string("/apps/shotwell/sharing/%s/%s".printf(domain, key), default_value);
314333
}

src/Dialogs.vala

+8-3
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,7 @@ public class PreferencesDialog {
16631663
}
16641664

16651665
private static PreferencesDialog preferences_dialog;
1666+
16661667
private Gtk.Dialog dialog;
16671668
private Gtk.Builder builder;
16681669
private Gtk.Adjustment bg_color_adjustment;
@@ -1681,16 +1682,17 @@ public class PreferencesDialog {
16811682
private GLib.DateTime example_date = new GLib.DateTime.local(2009, 3, 10, 18, 16, 11);
16821683
private Gtk.CheckButton lowercase;
16831684
private Gtk.Button close_button;
1685+
private Plugins.ManifestWidgetMediator plugins_mediator = new Plugins.ManifestWidgetMediator();
16841686

16851687
private PreferencesDialog() {
16861688
builder = AppWindow.create_builder();
1687-
1689+
16881690
dialog = builder.get_object("preferences_dialog") as Gtk.Dialog;
16891691
dialog.set_parent_window(AppWindow.get_instance().get_parent_window());
16901692
dialog.set_transient_for(AppWindow.get_instance());
16911693
dialog.delete_event.connect(on_delete);
16921694
dialog.response.connect(on_close);
1693-
1695+
16941696
bg_color_adjustment = builder.get_object("bg_color_adjustment") as Gtk.Adjustment;
16951697
bg_color_adjustment.set_value(bg_color_adjustment.get_upper() -
16961698
Config.get_instance().get_bg_color().red);
@@ -1726,7 +1728,10 @@ public class PreferencesDialog {
17261728

17271729
lowercase = builder.get_object("lowercase") as Gtk.CheckButton;
17281730
lowercase.toggled.connect(on_lowercase_toggled);
1729-
1731+
1732+
Gtk.Bin plugin_manifest_container = builder.get_object("plugin-manifest-bin") as Gtk.Bin;
1733+
plugin_manifest_container.add(plugins_mediator.widget);
1734+
17301735
populate_preference_options();
17311736

17321737
photo_editor_combo.changed.connect(on_photo_editor_changed);

src/Resources.vala

+8-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ along with Shotwell; if not, write to the Free Software Foundation, Inc.,
6666
public const string ENHANCE = "shotwell-auto-enhance";
6767
public const string CROP_PIVOT_RETICLE = "shotwell-crop-pivot-reticle";
6868
public const string PUBLISH = "applications-internet";
69-
public const string MERGE = "shotwell-merge-events";
69+
public const string MERGE = "shotwell-merge-events";
7070

7171
public const string ICON_APP = "shotwell.svg";
7272
public const string ICON_APP16 = "shotwell-16.svg";
@@ -673,6 +673,13 @@ along with Shotwell; if not, write to the Free Software Foundation, Inc.,
673673
return noninterpretable_badge_pixbuf;
674674
}
675675

676+
public Gtk.IconTheme get_icon_theme_engine() {
677+
Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default();
678+
icon_theme.append_search_path(AppDirs.get_resources_dir().get_child("icons").get_path());
679+
680+
return icon_theme;
681+
}
682+
676683
// This method returns a reference to a cached pixbuf that may be shared throughout the system.
677684
// If the pixbuf is to be modified, make a copy of it.
678685
public Gdk.Pixbuf? get_icon(string name, int scale = DEFAULT_ICON_SCALE) {

src/Sidebar.vala

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ public class Sidebar : Gtk.TreeView {
122122

123123
popup_menu.connect(on_context_menu_keypress);
124124

125-
icon_theme = Gtk.IconTheme.get_default();
126-
icon_theme.append_search_path(AppDirs.get_resources_dir().get_child("icons").get_path());
125+
icon_theme = Resources.get_icon_theme_engine();
127126
icon_theme.changed.connect(on_theme_change);
128127
}
129128

130129
~Sidebar() {
131130
text.editing_canceled.disconnect(on_editing_canceled);
132131
text.editing_started.disconnect(on_editing_started);
132+
icon_theme.changed.disconnect(on_theme_change);
133133
}
134134

135135
public void place_cursor(SidebarPage page) {

src/WebConnectors.vala

+12-5
Original file line numberDiff line numberDiff line change
@@ -1239,16 +1239,23 @@ public class ServiceFactory {
12391239
string, ServiceCapabilities>();
12401240

12411241
private ServiceFactory() {
1242+
load_wrapped_services();
1243+
Publishing.Glue.GlueFactory.get_instance().wrapped_services_changed.connect(
1244+
load_wrapped_services);
1245+
}
1246+
1247+
private void load_wrapped_services() {
1248+
caps_map.clear();
1249+
1250+
// in addition to the baked-in services above, add services dynamically loaded from
1251+
// plugins. since everything involving plugins is written in terms of the new publishing
1252+
// API, we have to use the glue code.
12421253
add_caps(new FlickrConnector.Capabilities());
12431254
add_caps(new YandexConnector.Capabilities());
12441255
add_caps(new YouTubeConnector.Capabilities());
12451256
add_caps(new PiwigoConnector.Capabilities());
12461257

1247-
// in addition to the baked-in services above, add services dynamically loaded from
1248-
// plugins. since everything involving plugins is written in terms of the new publishing
1249-
// API, we have to use the glue code.
1250-
Publishing.Glue.GlueFactory glue_factory = Publishing.Glue.GlueFactory.get_instance();
1251-
ServiceCapabilities[] caps = glue_factory.get_wrapped_services();
1258+
ServiceCapabilities[] caps = Publishing.Glue.GlueFactory.get_instance().get_wrapped_services();
12521259
foreach (ServiceCapabilities current_caps in caps)
12531260
add_caps(current_caps);
12541261
}

0 commit comments

Comments
 (0)