Skip to content

Commit

Permalink
Messages page improvements.
Browse files Browse the repository at this point in the history
  - Handling `Stop` button action better.
  - Naive handling of `on loading` to avoid trigger any actions
  while an action is running.
  • Loading branch information
Miguel Aranha Baldi Horlle committed Apr 18, 2024
1 parent 6ac45e6 commit 6d55208
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/component/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ impl Component for AppModel {
messages_page,
settings_page,
};

widgets.load_window_size();
ComponentParts { model, widgets }
}
Expand Down
24 changes: 21 additions & 3 deletions src/component/messages/messages_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,30 @@ impl Component for MessagesPageModel {
set_orientation: gtk::Orientation::Horizontal,
set_halign: gtk::Align::Start,
set_hexpand: true,
#[name(btn_get_messages)]
gtk::Button {
set_icon_name: "media-playback-start-symbolic",
connect_clicked[sender] => move |_| {
sender.input(MessagesPageMsg::GetMessages);
},
},
#[name(btn_stop_messages)]
gtk::Button {
set_icon_name: "media-playback-stop-symbolic",
set_margin_start: 5,
connect_clicked[sender] => move |_| {
sender.input(MessagesPageMsg::StopGetMessages);
},
},
#[name(cache_refresh)]
#[name(btn_cache_refresh)]
gtk::Button {
set_icon_name: "media-playlist-repeat-symbolic",
set_margin_start: 5,
connect_clicked[sender] => move |_| {
sender.input(MessagesPageMsg::RefreshMessages);
},
},
#[name(cache_toggle)]
#[name(btn_cache_toggle)]
gtk::ToggleButton {
set_margin_start: 5,
set_label: "Cache",
Expand Down Expand Up @@ -515,7 +517,7 @@ impl Component for MessagesPageModel {
.unwrap_or_default();
widgets.cache_timestamp.set_label(&cache_ts);
widgets.cache_timestamp.set_visible(true);
widgets.cache_toggle.set_active(toggled);
widgets.btn_cache_toggle.set_active(toggled);
widgets.pag_total_entry.set_text("");
widgets.pag_current_entry.set_text("");
widgets.pag_last_entry.set_text("");
Expand All @@ -525,6 +527,7 @@ impl Component for MessagesPageModel {
}
MessagesPageMsg::GetMessages => {
STATUS_BROKER.send(StatusBarMsg::Start);
on_loading(widgets, false);
let mode = self.mode;
self.mode = match self.mode {
MessagesMode::Cached { refresh: _ } => MessagesMode::Cached { refresh: false },
Expand Down Expand Up @@ -565,6 +568,7 @@ impl Component for MessagesPageModel {
}
MessagesPageMsg::GetNextMessages => {
STATUS_BROKER.send(StatusBarMsg::Start);
on_loading(widgets, false);
let mode = self.mode;
let topic = self.topic.clone().unwrap();
let conn = self.connection.clone().unwrap();
Expand Down Expand Up @@ -615,6 +619,7 @@ impl Component for MessagesPageModel {
}
MessagesPageMsg::GetPreviousMessages => {
STATUS_BROKER.send(StatusBarMsg::Start);
on_loading(widgets, false);
let mode = self.mode;
let topic = self.topic.clone().unwrap();
let conn = self.connection.clone().unwrap();
Expand Down Expand Up @@ -667,6 +672,10 @@ impl Component for MessagesPageModel {
MessagesPageMsg::StopGetMessages => {
info!("cancelling get messages...");
self.token.cancel();
on_loading(widgets, true);
STATUS_BROKER.send(StatusBarMsg::StopWithInfo {
text: Some("Operation cancelled!".to_string()),
});
}
MessagesPageMsg::UpdateMessage(message) => {
self.messages_wrapper.append(MessageListItem::new(message));
Expand Down Expand Up @@ -709,6 +718,7 @@ impl Component for MessagesPageModel {
.unwrap_or(String::default());
widgets.cache_timestamp.set_label(&cache_ts);
widgets.cache_timestamp.set_visible(true);
on_loading(widgets, true);
STATUS_BROKER.send(StatusBarMsg::StopWithInfo {
text: Some(format!("{} messages loaded!", self.messages_wrapper.len())),
});
Expand Down Expand Up @@ -761,6 +771,14 @@ impl Component for MessagesPageModel {
}
}

fn on_loading(widgets: &mut MessagesPageModelWidgets, enabled: bool,) {
widgets.btn_next_page.set_sensitive(enabled);
widgets.btn_previous_page.set_sensitive(enabled);
widgets.btn_get_messages.set_sensitive(enabled);
widgets.btn_cache_refresh.set_sensitive(enabled);
widgets.btn_cache_toggle.set_sensitive(enabled);
}

fn fill_pagination(
page_op: PageOp,
widgets: &mut MessagesPageModelWidgets,
Expand Down

0 comments on commit 6d55208

Please sign in to comment.