Revert bad changes to IconButton; fix issue with switching servers being totally broken

This commit is contained in:
Sumner Evans
2020-06-07 00:33:09 -06:00
parent 3f72a7641f
commit be9644376f
4 changed files with 41 additions and 52 deletions

View File

@@ -741,6 +741,7 @@ class SublimeMusicApp(Gtk.Application):
self.on_play_pause()
self.loading_state = True
self.player.reset()
AdapterManager.reset(self.app_config, self.on_song_download_progress)
self.loading_state = False
# Update the window according to the new server configuration.
@@ -945,10 +946,16 @@ class SublimeMusicApp(Gtk.Application):
provider_id = dialog.provider_config.id
self.app_config.providers[provider_id] = dialog.provider_config
# Switch to the new provider.
self.app_config.current_provider_id = provider_id
self.app_config.save()
self.update_window(force=True)
if provider_id == self.app_config.current_provider_id:
# Just update the window.
self.update_window()
else:
# Switch to the new provider.
if self.app_config.state.playing:
self.on_play_pause()
self.app_config.current_provider_id = provider_id
self.app_config.save()
self.update_window(force=True)
dialog.destroy()

View File

@@ -304,9 +304,7 @@ class AlbumsPanel(Gtk.Box):
self.populate_genre_combo(app_config, force=force)
# At this point, the current query should be totally updated.
self.grid_order_token = self.grid.update_params(
self.current_query, self.offline_mode
)
self.grid_order_token = self.grid.update_params(app_config)
self.grid.update(self.grid_order_token, app_config, force=force)
def _get_opposite_sort_dir(self, sort_dir: str) -> str:
@@ -521,14 +519,23 @@ class AlbumsGrid(Gtk.Overlay):
next_page_fn = None
provider_id: Optional[str] = None
def update_params(self, query: AlbumSearchQuery, offline_mode: bool) -> int:
def update_params(self, app_config: AppConfiguration) -> int:
# If there's a diff, increase the ratchet.
if self.current_query.strhash() != query.strhash():
if (
self.current_query.strhash()
!= (search_query := app_config.state.current_album_search_query).strhash()
):
self.order_ratchet += 1
self.current_query = query
if offline_mode != self.offline_mode:
self.current_query = search_query
if self.offline_mode != (offline_mode := app_config.offline_mode):
self.order_ratchet += 1
self.offline_mode = offline_mode
self.offline_mode = offline_mode
if self.provider_id != (provider_id := app_config.current_provider_id):
self.order_ratchet += 1
self.provider_id = provider_id
return self.order_ratchet
def __init__(self, *args, **kwargs):
@@ -620,11 +627,6 @@ class AlbumsGrid(Gtk.Overlay):
self.page_size = app_config.state.album_page_size
self.page = app_config.state.album_page
assert app_config.provider
if self.provider_id != app_config.provider.id:
self.order_ratchet += 1
self.provider_id = app_config.provider.id
self.update_grid(
order_token,
use_ground_truth_adapter=force,
@@ -651,7 +653,7 @@ class AlbumsGrid(Gtk.Overlay):
force_grid_reload_from_master = (
force_grid_reload_from_master
or use_ground_truth_adapter
or self.latest_applied_order_ratchet < self.order_ratchet
or self.latest_applied_order_ratchet < order_token
)
def do_update_grid(selected_index: Optional[int]):
@@ -669,7 +671,7 @@ class AlbumsGrid(Gtk.Overlay):
# Don't override more recent results
if order_token < self.latest_applied_order_ratchet:
return
self.latest_applied_order_ratchet = self.order_ratchet
self.latest_applied_order_ratchet = order_token
is_partial = False
try:
@@ -681,6 +683,7 @@ class AlbumsGrid(Gtk.Overlay):
if self.error_dialog:
self.spinner.hide()
return
# TODO (#122): make this non-modal
self.error_dialog = Gtk.MessageDialog(
transient_for=self.get_toplevel(),
message_type=Gtk.MessageType.ERROR,
@@ -732,10 +735,7 @@ class AlbumsGrid(Gtk.Overlay):
)
do_update_grid(selected_index)
if (
use_ground_truth_adapter
or self.latest_applied_order_ratchet < self.order_ratchet
):
if force_grid_reload_from_master:
albums_result = AdapterManager.get_albums(
self.current_query, use_ground_truth_adapter=use_ground_truth_adapter
)

View File

@@ -16,42 +16,22 @@ class IconButton(Gtk.Button):
Gtk.Button.__init__(self, **kwargs)
self.icon_size = icon_size
self.box = Gtk.Box(
orientation=Gtk.Orientation.HORIZONTAL, name="icon-button-box"
)
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, name="icon-button-box")
self.image = None
self.has_icon = False
if icon_name:
self.image = Gtk.Image.new_from_icon_name(icon_name, self.icon_size)
self.has_icon = True
self.box.pack_start(self.image, False, False, 0)
self.image = Gtk.Image.new_from_icon_name(icon_name, self.icon_size)
box.pack_start(self.image, False, False, 0)
if label is not None:
self.box.add(Gtk.Label(label=label))
box.add(Gtk.Label(label=label))
if not relief:
self.props.relief = Gtk.ReliefStyle.NONE
self.add(self.box)
self.add(box)
self.set_tooltip_text(tooltip_text)
def set_icon(self, icon_name: Optional[str]):
if icon_name:
if self.image is None:
self.image = Gtk.Image.new_from_icon_name(icon_name, self.icon_size)
else:
self.image.set_from_icon_name(icon_name, self.icon_size)
if not self.has_icon:
self.box.pack_start(self.image, False, False, 0)
self.show_all()
self.has_icon = True
else:
if self.has_icon:
self.box.remove(self.image)
self.has_icon = False
self.image.set_from_icon_name(icon_name, self.icon_size)
class IconToggleButton(Gtk.ToggleButton):

View File

@@ -51,6 +51,7 @@ class ConfigureProviderDialog(Gtk.Dialog):
self.header.pack_start(self.cancel_back_button)
self.next_add_button = Gtk.Button(label="Edit" if self.editing else "Next")
self.next_add_button.get_style_context().add_class("suggested-action")
self.next_add_button.connect("clicked", self._on_next_add_clicked)
self.header.pack_end(self.next_add_button)
@@ -138,8 +139,6 @@ class ConfigureProviderDialog(Gtk.Dialog):
def _on_next_add_clicked(self, *args):
if self.stage == DialogStage.SELECT_ADAPTER:
# TODO make the next button the primary action
index = self.adapter_options_list.get_selected_row().get_index()
if index != self._current_index:
for c in self.configure_box.get_children():
@@ -174,12 +173,15 @@ class ConfigureProviderDialog(Gtk.Dialog):
form.connect("config-valid-changed", self._on_config_form_valid_changed)
self.configure_box.pack_start(form, True, True, 0)
self.configure_box.show_all()
self._adapter_config_is_valid = False
self.stack.set_visible_child_name("configure")
self.stage = DialogStage.CONFIGURE_ADAPTER
self.cancel_back_button.set_label("Change Type" if self.editing else "Back")
self.next_add_button.set_label("Edit" if self.editing else "Add")
self.next_add_button.set_sensitive(index == self._current_index)
self.next_add_button.set_sensitive(
index == self._current_index and self._adapter_config_is_valid
)
self._current_index = index
else:
if self.provider_config is None: