Philipp Hörist pushed to branch master at gajim / gajim


Commits:
e638b523 by Philipp Hörist at 2019-12-26T19:31:40Z
Add async read/write file helpers

- - - - -
e17ad155 by Philipp Hörist at 2019-12-26T20:31:38Z
PluginManager: Call disconnect handler when removing extension point

Previously we called the disconnect handler only when a plugin was deactivated.

- - - - -


2 changed files:

- gajim/common/helpers.py
- gajim/plugins/pluginmanager.py


Changes:

=====================================
gajim/common/helpers.py
=====================================
@@ -1738,3 +1738,51 @@ class Observable:
                 self._callbacks[signal_name].remove(func)
                 continue
             func()(self, signal_name, *args, **kwargs)
+
+
+def write_file_async(path, data, callback, user_data=None):
+    file = Gio.File.new_for_path(str(path))
+    file.create_async(Gio.FileCreateFlags.PRIVATE,
+                          GLib.PRIORITY_DEFAULT,
+                          None,
+                          _on_file_created,
+                          (callback, data, user_data))
+
+def _on_file_created(file, result, user_data):
+    callback, data, user_data = user_data
+    try:
+        outputstream = file.create_finish(result)
+    except GLib.Error as error:
+        callback(False, error, user_data)
+        return
+
+    outputstream.write_all_async(data,
+                                 GLib.PRIORITY_DEFAULT,
+                                 None,
+                                 _on_write_finished,
+                                 (callback, user_data))
+
+def _on_write_finished(outputstream, result, user_data):
+    callback, user_data = user_data
+    try:
+        successful, _bytes_written = outputstream.write_all_finish(result)
+    except GLib.Error as error:
+        callback(False, error, user_data)
+    else:
+        callback(successful, None, user_data)
+
+
+def load_file_async(path, callback, user_data=None):
+    file = Gio.File.new_for_path(str(path))
+    file.load_contents_async(None,
+                             _on_load_finished,
+                             (callback, user_data))
+
+def _on_load_finished(file, result, user_data):
+    callback, user_data = user_data
+    try:
+        _successful, contents, _etag = file.load_contents_finish(result)
+    except GLib.Error as error:
+        callback(None, error, user_data)
+    else:
+        callback(contents, None, user_data)


=====================================
gajim/plugins/pluginmanager.py
=====================================
@@ -328,6 +328,13 @@ class PluginManager(metaclass=Singleton):
                     self.gui_extension_points[gui_extpoint_name].remove(
                         ext_point)
 
+        if gui_extpoint_name not in self.gui_extension_points_handlers:
+            return
+
+        for handlers in self.gui_extension_points_handlers[gui_extpoint_name]:
+            disconnect_handler = handlers[1]
+            if disconnect_handler is not None:
+                disconnect_handler(args[0])
 
     @log_calls('PluginManager')
     def _add_gui_extension_point_call_to_list(self, gui_extpoint_name, *args):



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/compare/d4b9b823b6b0ec2c46c051d28a2d63ad5d4704cf...e17ad1554b44bafd3ec23d43069118d288fd4094

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/compare/d4b9b823b6b0ec2c46c051d28a2d63ad5d4704cf...e17ad1554b44bafd3ec23d43069118d288fd4094
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to