Commit 8dac2ea6 authored by Cédric Bellegarde's avatar Cédric Bellegarde

Some tweak in ImagesPopover

parent 93937bc0
Pipeline #60196 passed with stage
in 8 minutes and 1 second
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkGrid" id="widget">
......@@ -38,7 +38,7 @@
<property name="homogeneous">True</property>
<property name="min_children_per_line">3</property>
<property name="max_children_per_line">3</property>
<property name="selection_mode">none</property>
<property name="selection_mode">multiple</property>
</object>
</child>
</object>
......@@ -71,7 +71,6 @@
<object class="GtkButton" id="button">
<property name="label" translatable="yes">Save images</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
......
......@@ -128,8 +128,13 @@ class ImagesPopover(Gtk.Popover):
Save visible images
@param button as Gtk.Button
"""
children = self.__flowbox.get_selected_children() or\
self.__flowbox.get_children()
uris = []
for child in children:
uris.append(child.uri)
task_helper = TaskHelper()
task_helper.run(self.__move_images)
task_helper.run(self.__move_images, uris)
self.__spinner.start()
def _on_button_toggled(self, button):
......@@ -170,9 +175,10 @@ class ImagesPopover(Gtk.Popover):
image.show()
self.__flowbox.add(image)
def __move_images(self):
def __move_images(self, uris):
"""
Move image to download directory
@param uris as [str]
"""
parsed = urlparse(self.__uri)
directory_uri = App().settings.get_value('download-uri').get_string()
......@@ -184,16 +190,16 @@ class ImagesPopover(Gtk.Popover):
directory = Gio.File.new_for_uri(destination_uri)
if not directory.query_exists():
directory.make_directory_with_parents()
for child in self.__flowbox.get_children():
if child.uri.find(self.__filter) != -1:
encoded = sha256(child.uri.encode("utf-8")).hexdigest()
child_basename = child.uri.split("/")[-1]
for uri in uris:
if uri.find(self.__filter) != -1:
encoded = sha256(uri.encode("utf-8")).hexdigest()
basename = uri.split("/")[-1]
filepath = "%s/%s" % (EOLIE_CACHE_PATH, encoded)
s = Gio.File.new_for_path(filepath)
if not s.query_exists():
continue
d = Gio.File.new_for_uri("%s/%s" % (destination_uri,
child_basename))
basename))
try:
s.move(d, Gio.FileCopyFlags.OVERWRITE, None, None, None)
except Exception as e:
......@@ -253,7 +259,6 @@ class ImagesPopover(Gtk.Popover):
uris)
else:
self.__spinner.stop()
self.__button.set_sensitive(True)
def __on_get_images(self, source, result):
"""
......
......@@ -137,17 +137,6 @@ class ToolbarEnd(Gtk.Bin):
filechooser.connect("response", self.__on_save_response)
filechooser.run()
def save_images(self, uri, page_id):
"""
Show a popover with all images for page id
@param uri as str
@param page_id as int
"""
from eolie.popover_images import ImagesPopover
popover = ImagesPopover(uri, page_id, self.__window)
popover.set_relative_to(self.__download_button)
popover.popup()
def save_videos(self, page_id):
"""
Show a popover with videos for page_id
......
......@@ -203,8 +203,11 @@ class WebViewMenuSignals:
@param action as Gio.SimpleAction
@param variant as GLib.Variant
"""
self._window.toolbar.end.save_images(self.uri,
self.get_page_id())
from eolie.popover_images import ImagesPopover
popover = ImagesPopover(self.uri, self.get_page_id(), self._window)
popover.set_relative_to(self._window.toolbar)
popover.set_position(Gtk.PositionType.BOTTOM)
popover.popup()
def __on_save_videos_activate(self, action, variant):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment