raster pushed a commit to branch master.

http://git.enlightenment.org/apps/epour.git/commit/?id=ef8ebed4f5d7b320e0b7dd3ad6446650caa1ba5e

commit ef8ebed4f5d7b320e0b7dd3ad6446650caa1ba5e
Author: rafspiny <[email protected]>
Date:   Fri Oct 15 08:21:50 2021 +0100

    The app was not able to add a torrent.
    
    Summary:
    Plus, the app was crashing when the Dialog to add a torrent was being 
closed.
    This is due to some not very clear memory issue in freeing the Dialog box.
    Unable to identify the root cause, I moved the .delete() of the Dialog at 
the shutdown of the application.
    
    Fixes #T8885
    
    Reviewers: raster
    
    Differential Revision: https://phab.enlightenment.org/D12297
---
 epour/gui/TorrentSelector.py | 37 ++++++++++++++++++++++++++-----------
 epour/gui/__init__.py        | 11 +++++++++--
 2 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/epour/gui/TorrentSelector.py b/epour/gui/TorrentSelector.py
index c6c8993..88ab09e 100644
--- a/epour/gui/TorrentSelector.py
+++ b/epour/gui/TorrentSelector.py
@@ -40,6 +40,7 @@ from efl.elementary import Spinner
 #     ELM_SEL_FORMAT_TEXT
 
 from .Widgets import UnitSpinner
+from ..session import lt_version_post_breaking_change
 
 EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
 EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0
@@ -139,9 +140,13 @@ seed, this flag has no effect.'''
     def __init__(self, parent, session, t_uri=None):
         DialogWindow.__init__(
             self, parent, "addtorrent", _("Add Torrent"),
-            size=(scale * 400, scale * 400), autodel=True
+            size=(scale * 400, scale * 400), autodel=False
             )
 
+        def _cb_close(self):
+            self.hide()
+
+        self.callback_delete_request_add(lambda o: _cb_close(o))
         self.add_dict = {}
 
         scrol = Scroller(
@@ -160,20 +165,20 @@ seed, this flag has no effect.'''
         box.pack_end(hbox)
         hbox.show()
 
-        uri_entry = Entry(
+        self.uri_entry = Entry(
             box, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ,
             single_line=True, scrollable=True
             )
-        uri_entry.part_text_set("guide", _("Enter torrent file path / magnet 
URI / info hash"))
+        self.uri_entry.part_text_set("guide", _("Enter torrent file path / 
magnet URI / info hash"))
 
         if t_uri:
-            uri_entry.entry = utf8_to_markup(t_uri)
+            self.uri_entry.entry = utf8_to_markup(t_uri)
 
-        hbox.pack_end(uri_entry)
-        uri_entry.show()
+        hbox.pack_end(self.uri_entry)
+        self.uri_entry.show()
 
         fsb = Button(box, text=_("Select file"))
-        fsb.callback_clicked_add(lambda x: TorrentFs(self, uri_entry))
+        fsb.callback_clicked_add(lambda x: TorrentFs(self, self.uri_entry))
         hbox.pack_end(fsb)
         fsb.show()
 
@@ -239,7 +244,12 @@ seed, this flag has no effect.'''
                 flags = flags ^ 
int(add_torrent_params_flags_t.flag_auto_managed)
             self.add_dict["flags"] = flags
 
-        for name, flag in sorted(add_torrent_params_flags_t.names.items()):
+        if lt_version_post_breaking_change:
+            items = sorted(add_torrent_params_flags_t.__dict__.items())
+            flags_list = [flag for flag in items if not 
flag[0].startswith("_")]
+        else:
+            flags_list = sorted(add_torrent_params_flags_t.names.items())
+        for name, flag in flags_list:
             if not int(flag) in self.names.keys():
                 continue
             c = Check(
@@ -312,6 +322,9 @@ seed, this flag has no effect.'''
         box.show()
         scrol.show()
 
+        def del_dialog_cb(btn):
+            self.hide()
+
         def add_torrent_cb(btn, uri_entry, session, add_dict):
             uri = uri_entry.entry
 
@@ -323,11 +336,13 @@ seed, this flag has no effect.'''
             session.fill_add_dict_based_on_uri(add_dict, uri)
             session.add_torrent_with_dict(add_dict)
 
-            self.delete()
+            self.hide()
+            # self.delete()
 
         ok_btn.callback_clicked_add(
-            add_torrent_cb, uri_entry, session, self.add_dict)
-        cancel_btn.callback_clicked_add(lambda x: self.delete())
+            add_torrent_cb, self.uri_entry, session, self.add_dict)
+        cancel_btn.callback_clicked_add(del_dialog_cb)
+        # cancel_btn.callback_clicked_add(lambda x: self.delete())
 
         self.show()
 
diff --git a/epour/gui/__init__.py b/epour/gui/__init__.py
index 548e7ce..770b8eb 100644
--- a/epour/gui/__init__.py
+++ b/epour/gui/__init__.py
@@ -89,6 +89,7 @@ if not theme_file:
 class MainInterface(object):
 
     def __init__(self, parent, session):
+        self.add_torrent_dialog: Window = None
         self._session = session
         self.itc = TorrentClass(self._session, "torrent")
 
@@ -295,8 +296,12 @@ class MainInterface(object):
             "torrent_finished_alert", torrent_finished_cb))
 
     def add_torrent(self, t_uri=None):
-        from .TorrentSelector import TorrentSelector
-        TorrentSelector(self.win, self._session, t_uri)
+        if not self.add_torrent_dialog:
+            from .TorrentSelector import TorrentSelector
+            self.add_torrent_dialog = TorrentSelector(self.win, self._session, 
t_uri)
+        else:
+            self.add_torrent_dialog.uri_entry.entry_set("")
+            self.add_torrent_dialog.show()
 
     def run_mainloop(self):
         self.win.show()
@@ -309,6 +314,8 @@ class MainInterface(object):
         elm.run()
 
     def stop_mainloop(self):
+        if self.add_torrent_dialog:
+            self.add_torrent_dialog.delete()
         elm.exit()
 
     def update(self):

-- 


Reply via email to