diff --git a/blueman/gui/applet/PluginDialog.py b/blueman/gui/applet/PluginDialog.py
index d541ef20c..65f20f5d0 100644
--- a/blueman/gui/applet/PluginDialog.py
+++ b/blueman/gui/applet/PluginDialog.py
@@ -284,50 +284,36 @@ def on_toggled(self, _toggle: Gtk.CellRendererToggle, path: str) -> None:
deps = self.applet.Plugins.get_dependencies()[name]
loaded = self.applet.Plugins.get_loaded()
- to_unload = []
- for dep in deps:
- if dep in loaded:
- to_unload.append(dep)
+ to_unload = [dep for dep in deps if dep in loaded]
if to_unload:
- dialog = Gtk.MessageDialog(parent=self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
- dialog.props.secondary_use_markup = True
- dialog.props.icon_name = "blueman"
- dialog.props.text = _("Dependency issue")
- dialog.props.secondary_text = \
+ if not self._ask_unload(
_("Plugin \"%(0)s\" depends on %(1)s. Unloading %(1)s will also unload "
"\"%(0)s\".\nProceed?") % {"0": ", ".join(to_unload), "1": name}
-
- resp = dialog.run()
- if resp != Gtk.ResponseType.YES:
- dialog.destroy()
+ ):
return
+ else:
+ conflicts = self.applet.Plugins.get_conflicts()[name]
+ to_unload = [conf for conf in conflicts if conf in loaded]
- dialog.destroy()
-
- conflicts = self.applet.Plugins.get_conflicts()[name]
- to_unload = []
- for conf in conflicts:
- if conf in loaded:
- to_unload.append(conf)
-
- if to_unload:
- dialog = Gtk.MessageDialog(parent=self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
- dialog.props.secondary_use_markup = True
- dialog.props.icon_name = "blueman"
- dialog.props.text = _("Dependency issue")
- dialog.props.secondary_text = \
+ if to_unload and not self._ask_unload(
_("Plugin %(0)s conflicts with %(1)s. Loading %(1)s will unload %(0)s."
"\nProceed?") % {"0": ", ".join(to_unload), "1": name}
-
- resp = dialog.run()
- if resp != Gtk.ResponseType.YES:
- dialog.destroy()
+ ):
return
- dialog.destroy()
-
- for p in to_unload:
- self.applet.Plugins.set_config(p, False)
+ for p in to_unload:
+ self.applet.Plugins.set_config(p, False)
self.applet.Plugins.set_config(name, name not in self.applet.Plugins.get_loaded())
+
+ def _ask_unload(self, text: str) -> bool:
+ dialog = Gtk.MessageDialog(parent=self, type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO)
+ dialog.props.secondary_use_markup = True
+ dialog.props.icon_name = "blueman"
+ dialog.props.text = _("Dependency issue")
+ dialog.props.secondary_text = text
+
+ resp = dialog.run()
+ dialog.destroy()
+ return resp == Gtk.ResponseType.YES