[chronojump] News download thread can be cancelled
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] News download thread can be cancelled
- Date: Wed, 20 Jan 2021 11:04:57 +0000 (UTC)
commit bccebc4021d9adfe7a6b3e4bbd15c0fc44fe6ebc
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Jan 20 12:04:41 2021 +0100
News download thread can be cancelled
glade/app1.glade | 55 ++++++++++++++++++++++++++++++++++++++++++++--------
src/gui/app1/news.cs | 23 +++++++++++++++++++++-
2 files changed, 69 insertions(+), 9 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index b1250df7..f3b73ef0 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -42663,19 +42663,24 @@ then click this button.</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <widget class="GtkFrame" id="frame28">
+ <widget class="GtkVBox" id="vbox244">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label_xalign">0</property>
- <property name="label_yalign">1</property>
- <property name="shadow_type">in</property>
+ <property name="spacing">20</property>
<child>
- <widget class="GtkViewport" id="viewport21">
+ <widget class="GtkFrame" id="frame28">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label_xalign">0</property>
+ <property name="label_yalign">1</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <widget class="GtkViewport" id="viewport21">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">4</property>
<child>
- <widget class="GtkVBox" id="vbox244">
+ <widget class="GtkVBox" id="vbox245">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
@@ -42705,12 +42710,46 @@ then click this button.</property>
</child>
</widget>
</child>
+ </widget>
+ </child>
+ <child>
+ <placeholder/>
+ <packing>
+ <property name="type">label_item</property>
+ </packing>
+ </child>
</widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
</child>
<child>
- <placeholder/>
+ <widget class="GtkHButtonBox" id="hbuttonbox16">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <widget class="GtkButton"
id="button_news_cancel">
+ <property name="label">gtk-cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ <signal name="clicked"
handler="on_button_news_cancel_clicked" swapped="no"/>
+ <accelerator key="Escape" signal="clicked"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </widget>
<packing>
- <property name="type">label_item</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
</packing>
</child>
</widget>
diff --git a/src/gui/app1/news.cs b/src/gui/app1/news.cs
index 7d47f590..dd93c362 100644
--- a/src/gui/app1/news.cs
+++ b/src/gui/app1/news.cs
@@ -46,6 +46,7 @@ public partial class ChronoJumpWindow
Pixbuf image_news_pixbuf;
private int currentNewsPos;
+ private bool newsDownloadCancel;
private void newsGetThreadPrepare()
@@ -62,6 +63,7 @@ public partial class ChronoJumpWindow
// 3) get the news on the server
if(preferences.serverNewsDatetime != "" && preferences.serverNewsDatetime !=
preferences.clientNewsDatetime)
{
+ newsDownloadCancel = false;
LogB.Information("newsGet thread will start");
pingThread = new Thread (new ThreadStart (newsGet));
GLib.Idle.Add (new GLib.IdleHandler (pulseNewsGetGTK));
@@ -79,8 +81,19 @@ public partial class ChronoJumpWindow
}
private bool pulseNewsGetGTK ()
{
- if(! pingThread.IsAlive)
+ if(! pingThread.IsAlive || newsDownloadCancel)
{
+ if(newsDownloadCancel)
+ {
+ menus_and_mode_sensitive(true);
+ notebook_sup.CurrentPage = app1s_notebook_sup_entered_from;
+
+ LogB.Information("pulseNewsGetGTK ending here");
+ LogB.ThreadEnded();
+
+ return false;
+ }
+
if(newsAtServer_l != null)
{
// 1) update clientNewsDatetime
@@ -108,6 +121,14 @@ public partial class ChronoJumpWindow
return true;
}
+ private void on_button_news_cancel_clicked (object o, EventArgs args)
+ {
+ newsDownloadCancel = true;
+
+ if(pingThread.IsAlive)
+ pingThread.Abort();
+ }
+
private void newsDisplay()
{
// 1) select
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]