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

Add code for MTP URI detection

parent b6e20cff
Pipeline #85684 passed with stage
in 23 minutes and 42 seconds
......@@ -37,7 +37,7 @@
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="sync_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
......@@ -45,6 +45,7 @@
<property name="halign">center</property>
<property name="image">image1</property>
<property name="relief">none</property>
<signal name="clicked" handler="_on_sync_button_clicked" swapped="no"/>
<style>
<class name="no-padding"/>
</style>
......
......@@ -68,7 +68,7 @@
<property name="vexpand">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkToggleButton" id="settings-button">
<object class="GtkToggleButton" id="appmenu_button">
<property name="can_focus">True</property>
<property name="visible">True</property>
<property name="receives_default">True</property>
......
......@@ -458,7 +458,7 @@ class Application(Gtk.Application):
elif options.contains("prev"):
self.player.prev()
elif options.contains("emulate-phone"):
self.__window.container.add_fake_phone()
self.__window.toolbar.end.appmenu_popover.add_fake_phone()
elif len(args) > 1:
uris = []
pls = []
......
......@@ -377,6 +377,7 @@ class CollectionScanner(GObject.GObject, TagReader):
data["discnumber"], data["discname"], data["year"],
data["timestamp"], -1, data["track_popularity"],
data["track_rate"], data["track_loved"], 0, "", 0)
infos.close(None)
except Exception as e:
Logger.error("CollectionScanner::__import_web_tracks(): %s", e)
......@@ -423,6 +424,7 @@ class CollectionScanner(GObject.GObject, TagReader):
else:
mtime = get_mtime(info)
files.append((mtime, child_uri))
infos.close(None)
# Only happens if files passed as args
else:
mtime = get_mtime(info)
......
......@@ -41,6 +41,23 @@ class AppMenuPopover(Gtk.Popover):
self.__add_device(mount)
self.add(builder.get_object("widget"))
def add_fake_phone(self):
"""
Add a fake phone device
"""
name = "Librem phone"
uri = "file:///tmp/librem/"
d = Gio.File.new_for_uri(uri + "Internal Memory")
if not d.query_exists():
d.make_directory_with_parents()
d = Gio.File.new_for_uri(uri + "SD Card")
if not d.query_exists():
d.make_directory_with_parents()
widget = DeviceWidget(name, uri)
widget.show()
self.__listbox.add(widget)
self.__listbox.show()
#######################
# PROTECTED #
#######################
......@@ -69,7 +86,13 @@ class AppMenuPopover(Gtk.Popover):
@param mount as Gio.Mount
"""
if is_device(mount):
widget = DeviceWidget(mount)
name = mount.get_name()
uri = mount.get_default_location().get_uri()
if mount.get_volume() is not None:
icon = mount.get_volume().get_symbolic_icon()
else:
icon = None
widget = DeviceWidget(name, uri, icon)
widget.show()
self.__listbox.add(widget)
self.__listbox.show()
......
......@@ -31,11 +31,11 @@ class ToolbarEnd(Gtk.Bin):
Gtk.Bin.__init__(self)
self.set_hexpand(True)
self.__search_popover = None
self.__app_menu_popover = None
self.__appmenu_popover = None
self.__timeout_id = None
builder = Gtk.Builder()
builder.add_from_resource("/org/gnome/Lollypop/ToolbarEnd.ui")
self.__appmenu_button = builder.get_object("appmenu_button")
self.__party_submenu = builder.get_object("party_submenu")
self.add(builder.get_object("end"))
......@@ -138,6 +138,18 @@ class ToolbarEnd(Gtk.Bin):
self.__on_search_button_cancelled()
self.__search_popover.set_text(search)
@property
def appmenu_popover(self):
"""
Get application menu Popover
@return AppMenuPopover
"""
if self.__appmenu_popover is None:
self.__appmenu_popover = AppMenuPopover()
self.__appmenu_popover.connect(
"closed", self.__on_popover_closed, self.__appmenu_button)
return self.__appmenu_popover
@property
def home_button(self):
"""
......@@ -222,12 +234,8 @@ class ToolbarEnd(Gtk.Bin):
@param button as Gtk.MenuButton
"""
if button.get_active():
if self.__app_menu_popover is None:
self.__app_menu_popover = AppMenuPopover()
self.__app_menu_popover.connect(
"closed", self.__on_popover_closed, button)
self.__app_menu_popover.set_relative_to(button)
self.__app_menu_popover.popup()
self.appmenu_popover.set_relative_to(button)
self.appmenu_popover.popup()
self.__next_popover.hide()
self.__next_popover.inhibit(True)
else:
......
......@@ -24,21 +24,22 @@ class DeviceWidget(Gtk.ListBoxRow):
A device widget for sync
"""
def __init__(self, mount):
def __init__(self, name, uri, icon=None):
"""
Init widget
@param mount as Gio.Mount
@param name as str
@param uri as str
@param icon as Gio.Icon
"""
Gtk.ListBoxRow.__init__(self)
self.get_style_context().add_class("background")
self.__name = mount.get_name()
self.__uri = mount.get_default_location().get_uri()
self.__name = name
self.__uri = uri
builder = Gtk.Builder()
builder.add_from_resource("/org/gnome/Lollypop/DeviceWidget.ui")
self.__progress = builder.get_object("progress")
builder.get_object("name").set_label(self.__name)
if mount.get_volume() is not None:
icon = mount.get_volume().get_symbolic_icon()
if icon is not None:
device_symbolic = builder.get_object("device-symbolic")
device_symbolic.set_from_gicon(icon, Gtk.IconSize.MENU)
self.add(builder.get_object("widget"))
......@@ -56,10 +57,63 @@ class DeviceWidget(Gtk.ListBoxRow):
#######################
# PROTECTED #
#######################
def _on_sync_button_clicked(self, button):
"""
Sync music on device
@param button as Gtk.Button
"""
uri = self.__get_best_uri_for_sync()
if uri is None:
return
#######################
# PRIVATE #
#######################
def __get_best_uri_for_sync(self):
"""
Get best URI for synchronization:
- A folder with lollypop sync DB
- A SD Card
@return str
"""
uris = []
try:
# First test we have a normal Music folder at root
# We try to create one, MTP will fail
music_uri = "%s/Music" % self.__uri
music_dir = Gio.File.new_for_uri(music_uri)
try:
music_dir.make_directory_with_parents()
except:
pass
if music_dir.query_exists():
return music_uri
# Search for previous sync or for SD CARD
d = Gio.File.new_for_uri(self.__uri)
infos = d.enumerate_children(
"standard::name,standard::type",
Gio.FileQueryInfoFlags.NONE,
None)
for info in infos:
if info.get_file_type() != Gio.FileType.DIRECTORY:
continue
f = infos.get_child(info)
uri = f.get_uri() + "/Music"
previous_sync = Gio.File.new_for_uri("%s/unsync" % uri)
if previous_sync.query_exists():
uris.insert(0, uri)
elif info.get_name().lower().startswith("SD"):
sync = Gio.File.new_for_uri(uri)
sync.make_directory_with_parents()
uris.append(uri)
infos.close(None)
return uris
except Exception as e:
Logger.error("DeviceManagerView::_get_files: %s: %s" % (uri, e))
return uris[0] if uris else None
def __calculate_free_space(self):
"""
Calculate free space on device
......
rm -fr /usr/local/lib/python3.7/site-packages/lollypop/
ninja -C build install
echo "Running lollypop"
lollypop
lollypop -e
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