Commit fa306184 authored by Cédric Bellegarde's avatar Cédric Bellegarde

Merge container and progressbar

parent a47ffc9a
Pipeline #49943 passed with stage
in 7 minutes and 59 seconds
......@@ -36,7 +36,7 @@ class CollectionImporter:
"""
Add uris to collection
"""
GLib.idle_add(App().window.container.pulse, True)
GLib.idle_add(App().window.container.progress.pulse, True)
walk_uris = list(uris)
while walk_uris:
uri = walk_uris.pop(0)
......@@ -67,7 +67,7 @@ class CollectionImporter:
Logger.info("Not an audio file %s" % uri)
except Exception as e:
Logger.error("CollectionImporter::add(): %s" % e)
GLib.idle_add(App().window.container.pulse, False)
GLib.idle_add(App().window.container.progress.pulse, False)
#######################
# PRIVATE #
......
......@@ -81,8 +81,6 @@ class CollectionScanner(GObject.GObject, TagReader):
uris = App().settings.get_music_uris()
if not uris:
return
# Add a progress bar
App().window.container.progress.add(self)
# Launch scan in a separate thread
self.__thread = Thread(target=self.__scan, args=(uris, saved))
self.__thread.daemon = True
......@@ -197,6 +195,8 @@ class CollectionScanner(GObject.GObject, TagReader):
self.__history = History()
(files, dirs) = self.__get_objects_for_uris(uris)
# Add a progress bar
App().window.container.progress.add(self)
self.__add_monitor(dirs)
new_tracks = self.__scan_files(files, saved)
......
......@@ -17,15 +17,15 @@ from lollypop.view import View
from lollypop.adaptive import AdaptiveStack
from lollypop.container_device import DeviceContainer
from lollypop.container_donation import DonationContainer
from lollypop.container_progress import ProgressContainer
from lollypop.container_scanner import ScannerContainer
from lollypop.container_playlists import PlaylistsContainer
from lollypop.container_lists import ListsContainer
from lollypop.container_views import ViewsContainer
from lollypop.progressbar import ProgressBar
class Container(Gtk.Overlay, DeviceContainer, DonationContainer,
ProgressContainer, ScannerContainer, PlaylistsContainer,
ScannerContainer, PlaylistsContainer,
ListsContainer, ViewsContainer):
"""
Main view management
......@@ -38,7 +38,6 @@ class Container(Gtk.Overlay, DeviceContainer, DonationContainer,
Gtk.Overlay.__init__(self)
DeviceContainer.__init__(self)
DonationContainer.__init__(self)
ProgressContainer.__init__(self)
ScannerContainer.__init__(self)
PlaylistsContainer.__init__(self)
ListsContainer.__init__(self)
......@@ -157,6 +156,14 @@ class Container(Gtk.Overlay, DeviceContainer, DonationContainer,
"""
return self.__paned_two
@property
def progress(self):
"""
Progress bar
@return ProgressBar
"""
return self.__progress
############
# PRIVATE #
############
......@@ -174,7 +181,9 @@ class Container(Gtk.Overlay, DeviceContainer, DonationContainer,
vgrid.set_orientation(Gtk.Orientation.VERTICAL)
vgrid.add(self._stack)
vgrid.add(self._progress)
self.__progress = ProgressBar()
self.__progress.set_property("hexpand", True)
vgrid.add(self.__progress)
vgrid.show()
self.__paned_two.add1(self._list_two)
......
# Copyright (c) 2014-2018 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import GLib
from lollypop.progressbar import ProgressBar
from lollypop.define import App
class ProgressContainer:
"""
Progress bar management for main view
"""
def __init__(self):
"""
Init container
"""
self.__pulse_timeout = None
self._progress = ProgressBar()
self._progress.set_property("hexpand", True)
def pulse(self, pulse):
"""
Make progress bar visible/pulse if pulse is True
@param pulse as bool
"""
if pulse and not self._progress.is_visible():
self._progress.show()
if self.__pulse_timeout is None:
self.__pulse_timeout = GLib.timeout_add(500, self.__pulse)
else:
if self.__pulse_timeout is not None:
GLib.source_remove(self.__pulse_timeout)
self.__pulse_timeout = None
self._progress.hide()
@property
def progress(self):
"""
Progress bar
@return ProgressBar
"""
return self._progress
############
# PRIVATE #
############
def __pulse(self):
"""
Make progress bar pulse while visible
@param pulse as bool
"""
if self._progress.is_visible() and not App().scanner.is_locked():
self._progress.pulse()
return True
else:
self._progress.set_fraction(0.0, self)
self.__pulse_timeout = None
return False
......@@ -524,7 +524,7 @@ class Player(BinPlayer, QueuePlayer, PlaylistPlayer, RadioPlayer,
On stream start, set next and previous track
"""
if not App().scanner.is_locked():
App().window.container.pulse(False)
App().window.container.progress.pulse(False)
if self._current_track.id is not None and self._current_track.id >= 0:
ShufflePlayer._on_stream_start(self, bus, message)
if self.track_in_queue(self._current_track):
......
......@@ -338,7 +338,7 @@ class BinPlayer(BasePlayer):
@param message as Gst.Message
"""
Logger.info("Player::_on_bus_error(): %s" % message.parse_error()[1])
App().window.container.pulse(False)
App().window.container.progress.pulse(False)
if self.__codecs.is_missing_codec(message):
self.__codecs.install()
App().scanner.stop()
......
......@@ -43,7 +43,7 @@ class RadioPlayer(BasePlayer):
if Gio.NetworkMonitor.get_default().get_network_available():
try:
if not App().scanner.is_locked():
App().window.container.pulse(True)
App().window.container.progress.pulse(True)
self.__current = track
parser = TotemPlParser.Parser.new()
parser.connect("entry-parsed", self.__on_entry_parsed,
......@@ -80,7 +80,7 @@ class RadioPlayer(BasePlayer):
self.emit("status-changed")
else:
self.emit("current-changed")
App().window.container.pulse(False)
App().window.container.progress.pulse(False)
def __on_parse_finished(self, parser, result, track, play):
"""
......@@ -93,7 +93,7 @@ class RadioPlayer(BasePlayer):
# Only start playing if context always True
if self.__current == track:
self.__start_playback(track, play)
App().window.container.pulse(False)
App().window.container.progress.pulse(False)
def __on_entry_parsed(self, parser, uri, metadata, track, play):
"""
......
......@@ -26,6 +26,7 @@ class ProgressBar(Gtk.ProgressBar):
Gtk.ProgressBar.__init__(self)
self.__callers = []
self.__fraction = 0.0
self.__pulse_timeout = None
self.__progress_running = False
def add(self, caller):
......@@ -51,6 +52,24 @@ class ProgressBar(Gtk.ProgressBar):
self.__progress_running = True
self.__progress_update(caller)
def pulse(self, pulse):
"""
Make progress bar visible/pulse if pulse is True
@param pulse as bool
"""
# Only pulse if nobody is using the progressbar
if self.__callers:
return
if pulse:
self.show()
if self.__pulse_timeout is None:
self.__pulse_timeout = GLib.timeout_add(500, self.__pulse)
else:
self.hide()
if self.__pulse_timeout is not None:
GLib.source_remove(self.__pulse_timeout)
self.__pulse_timeout = None
#######################
# PRIVATE #
#######################
......@@ -65,6 +84,19 @@ class ProgressBar(Gtk.ProgressBar):
self.__progress_running = False
self.__callers.remove(caller)
def __pulse(self):
"""
Make progress bar pulse while visible
@param pulse as bool
"""
if self.is_visible():
Gtk.ProgressBar.pulse(self)
return True
else:
Gtk.ProgressBar.set_fraction(self, 0.0)
self.__pulse_timeout = None
return False
def __progress_update(self, caller):
"""
Update progressbar smoothly
......
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