kuuko pushed a commit to branch master.

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

commit f834a16b24e53f2a506a1fe3429a38af2c3ca081
Author: Kai Huuhko <kai.huu...@gmail.com>
Date:   Wed Apr 15 18:03:33 2015 +0300

    Simplify the torrent add dialog
---
 epour/gui/TorrentSelector.py | 146 ++++++++++++++++++++++++++-----------------
 1 file changed, 87 insertions(+), 59 deletions(-)

diff --git a/epour/gui/TorrentSelector.py b/epour/gui/TorrentSelector.py
index df478e0..6472c0f 100644
--- a/epour/gui/TorrentSelector.py
+++ b/epour/gui/TorrentSelector.py
@@ -26,7 +26,8 @@ from libtorrent import add_torrent_params_flags_t
 
 from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL
 from efl import elementary as elm
-from efl.elementary.window import StandardWindow
+from efl.elementary.window import StandardWindow, Window, ELM_WIN_DIALOG_BASIC
+from efl.elementary.background import Background
 from efl.elementary.button import Button
 from efl.elementary.box import Box
 from efl.elementary.frame import Frame
@@ -55,6 +56,7 @@ log = logging.getLogger("epour.gui")
 
 
 class TorrentSelector(StandardWindow):
+
     def __init__(self, parent, session, t_uri=None):
         StandardWindow.__init__(
             self, "epour", "Epour - Add Torrent",
@@ -64,69 +66,52 @@ class TorrentSelector(StandardWindow):
         self.add_dict = {}
 
         scrol = Scroller(
-            self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH
-            )
+            self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
         self.resize_object_add(scrol)
 
         box = Box(
-            scrol, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH
-            )
+            scrol, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
+            align=(0.5, 0.0))
 
         scrol.content = box
 
-        sf = Frame(
-            box, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
-            text=u"Select torrent file \u25BC", autocollapse=True
-            )
-        t_sel = Fileselector(
-            sf, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
-            expandable=False, buttons_ok_cancel=False, is_save=False
-            )
-        if elm.need_efreet():
-            t_sel.mime_types_filter_append(
-                ["application/x-bittorrent"], "Torrent files")
-            t_sel.mime_types_filter_append(
-                ["*"], "All files")
-
-        if t_uri and os.path.isfile(t_uri):
-            t_sel.selected = t_uri
-            t_uri = None
-        else:
-            t_sel.path = os.path.expanduser("~")
+        hbox = Box(box, size_hint_weight=EXPAND_HORIZ, 
size_hint_align=FILL_HORIZ, horizontal=True)
+        box.pack_end(hbox)
+        hbox.show()
 
-        sf.content = t_sel
-        box.pack_end(sf)
-        sf.show()
-        t_sel.show()
-
-        m_entry = Entry(
+        uri_entry = Entry(
             box, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ,
             single_line=True, scrollable=True
             )
-        m_entry.part_text_set("guide", "or enter magnet URI / info hash")
+        uri_entry.part_text_set("guide", "Enter file path / magnet URI / info 
hash")
+        if t_uri:
+            uri_entry.entry = utf8_to_markup(t_uri)
+        hbox.pack_end(uri_entry)
+        uri_entry.show()
+
         if t_uri:
-            m_entry.entry = utf8_to_markup(t_uri)
-        box.pack_end(m_entry)
-        m_entry.show()
+            uri_entry.entry = t_uri
+
+        fsb = Button(box, text="Select torrent file")
+        fsb.callback_clicked_add(lambda x: TorrentFs(self, uri_entry))
+        hbox.pack_end(fsb)
+        fsb.show()
 
         options = Frame(
             self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ,
-            text=u"Options \u25BA", autocollapse=True, collapse=True
+            text=u"Advanced Options \u25BA", collapse=True
             )
         box.pack_end(options)
         options.show()
 
-        def toggler(obj1, obj2):
-            obj2.collapse_go(not obj1.collapse)
-            if obj1.collapse:
-                obj2.text = obj2.text.replace(u"\u25BA", u"\u25BC")
-                obj1.text = obj1.text.replace(u"\u25BC", u"\u25BA")
+        def toggler(obj):
+            if obj.collapse:
+                obj.text = obj.text.replace(u"\u25BA", u"\u25BC")
             else:
-                obj2.text = obj2.text.replace(u"\u25BC", u"\u25BA")
-                obj1.text = obj1.text.replace(u"\u25BA", u"\u25BC")
+                obj.text = obj.text.replace(u"\u25BC", u"\u25BA")
+            obj.collapse_go(not obj.collapse)
 
-        sf.callback_clicked_add(toggler, options)
-        options.callback_clicked_add(toggler, sf)
+        options.callback_clicked_add(toggler)
 
         opt_box = Box(
             options, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH
@@ -233,28 +218,35 @@ class TorrentSelector(StandardWindow):
         box.show()
         scrol.show()
 
-        def add_torrent_cb(btn, t_sel, m_entry, session, add_dict):
-            f = t_sel.selected
-            m = m_entry.entry
+        def add_torrent_cb(btn, uri_entry, session, add_dict):
+            uri = uri_entry.entry
 
-            if f and os.path.isfile(f):
-                log.debug("Adding file: %s", f)
-                session.add_torrent_from_file(add_dict, f)
+            if not uri:
+                return
+
+            uri = markup_to_utf8(uri)
+
+            if uri.startswith("magnet:"):
+                log.debug("Adding torrent from magnet link: %s", uri)
+                session.add_torrent_from_magnet(add_dict, uri)
                 self.delete()
-            elif m:
-                m = markup_to_utf8(m)
-                if m.startswith("magnet:"):
-                    log.debug("Adding torrent from magnet link: %s", m)
-                    session.add_torrent_from_magnet(add_dict, m)
-                else:
-                    log.debug("Adding torrent from info hash: %s", m)
-                    session.add_torrent_from_hash(add_dict, m)
+                return
+            elif uri.startswith("file://"):
+                uri = uri[7:]
+
+            if os.path.isfile(uri):
+                log.debug("Adding file: %s", uri)
+                session.add_torrent_from_file(add_dict, uri)
                 self.delete()
+                return
             else:
+                log.debug("Adding torrent from info hash: %s", uri)
+                session.add_torrent_from_hash(add_dict, uri)
+                self.delete()
                 return
 
         ok_btn.callback_clicked_add(
-            add_torrent_cb, t_sel, m_entry, session, self.add_dict
+            add_torrent_cb, uri_entry, session, self.add_dict
             )
         cancel_btn.callback_clicked_add(lambda x: self.delete())
 
@@ -262,5 +254,41 @@ class TorrentSelector(StandardWindow):
 
 
 class FsEntry(Fileselector, FileselectorEntry):
+
     def __init__(self, parent, **kwargs):
         FileselectorEntry.__init__(self, parent, **kwargs)
+
+
+class TorrentFs(Window):
+
+    def __init__(self, parent, uri_entry):
+
+        super(TorrentFs, self).__init__(
+            "torrentselect", ELM_WIN_DIALOG_BASIC, parent, size=(500, 500),
+            autodel=True)
+
+        bg = Background(self, size_hint_weight=EXPAND_BOTH)
+        self.resize_object_add(bg)
+        bg.show()
+
+        fs = Fileselector(
+            self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
+            expandable=False, is_save=False, path=os.path.expanduser("~")
+            )
+        if elm.need_efreet():
+            fs.mime_types_filter_append(
+                ["application/x-bittorrent"], "Torrent files")
+            fs.mime_types_filter_append(
+                ["*"], "All files")
+
+        self.resize_object_add(fs)
+        fs.show()
+
+        def done_cb(fs, path):
+            if path and os.path.isfile(path):
+                uri_entry.entry_set(path)
+            self.delete()
+
+        fs.callback_done_add(done_cb)
+
+        self.show()

-- 


Reply via email to