diff --git a/gknowledge/ui/window.py b/gknowledge/ui/window.py index 596d173..e643845 100644 --- a/gknowledge/ui/window.py +++ b/gknowledge/ui/window.py @@ -358,11 +358,18 @@ def _build_sources_pane(self): source_actions = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8) source_actions.append(self.reingest_btn) source_actions.append(self.remove_source_btn) - self.progress = Gtk.ProgressBar(show_text=True, visible=False) + self.progress = Gtk.ProgressBar(show_text=True, visible=False, hexpand=True, + valign=Gtk.Align.CENTER, ellipsize=Pango.EllipsizeMode.END) + self.cancel_ingest_btn = Gtk.Button(label="Cancel", valign=Gtk.Align.CENTER) + self.cancel_ingest_btn.connect("clicked", self._on_cancel_ingest) + progress_row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8) + progress_row.append(self.progress) + progress_row.append(self.cancel_ingest_btn) + self.progress.bind_property("visible", progress_row, "visible", GObject.BindingFlags.SYNC_CREATE) bottom = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8, margin_top=8, margin_bottom=8, margin_start=8, margin_end=8) bottom.append(source_actions) - bottom.append(self.progress) + bottom.append(progress_row) bottom.append(self.ingest_btn) side = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) @@ -821,17 +828,28 @@ def _remove_source(self, source_id: str): self.refresh_all() self.toast(f"Removed source: {source.title}") + def _on_cancel_ingest(self, *_a): + self.ingestion.cancel() + self.cancel_ingest_btn.set_sensitive(False) + self.progress.set_text("Stopping…") + def _on_ingest(self, *_a): if not self.ingestion or self.ingestion.is_running(): return self.progress.set_visible(True) self.progress.set_fraction(0.0) self.ingest_btn.set_sensitive(False) + self.cancel_ingest_btn.set_sensitive(True) + self.progress.set_text("Starting…") + ingestion = self.ingestion def progress(event, job, message): def update(): + if self.ingestion is not ingestion: + return False if event == "start": - self.progress.set_text(f"Ingesting: {message}") + if self.cancel_ingest_btn.get_sensitive(): + self.progress.set_text(f"Ingesting: {message}") self.progress.pulse() elif event == "done": self.progress.pulse() @@ -844,6 +862,11 @@ def update(): def finished(count): def done(): + if self.ingestion is not ingestion: + return False + # The completion callback can run before the worker thread exits. + if ingestion.is_running(): + return True self.progress.set_visible(False) self.refresh_all() self.toast(f"Ingested {count} source(s)")