[chronojump] Networks: check active Internet devices (show on rfid person popup)
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Networks: check active Internet devices (show on rfid person popup)
- Date: Wed, 29 Jan 2020 16:48:40 +0000 (UTC)
commit b2d27c887e5eab2935b3df4c56fe69bfcbc5cf97
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Jan 29 17:47:59 2020 +0100
Networks: check active Internet devices (show on rfid person popup)
glade/dialog_person_popup.glade | 37 ++++++++++++++++++----------
po/POTFILES.in | 1 +
src/gui/dialogPersonPopup.cs | 5 +++-
src/gui/networks.cs | 12 ++++++---
src/networks.cs | 54 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 91 insertions(+), 18 deletions(-)
---
diff --git a/glade/dialog_person_popup.glade b/glade/dialog_person_popup.glade
index e48e280a..c62f8b60 100644
--- a/glade/dialog_person_popup.glade
+++ b/glade/dialog_person_popup.glade
@@ -49,6 +49,17 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">20</property>
+ <child>
+ <widget class="GtkLabel" id="label_rfid">
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">label</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
<child>
<widget class="GtkHBox" id="hbox3">
<property name="visible">True</property>
@@ -66,6 +77,17 @@
<widget class="GtkVBox" id="vbox7">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <child>
+ <widget class="GtkLabel" id="label_network_devices">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
<child>
<widget class="GtkHBox" id="hbox6">
<property name="visible">True</property>
@@ -98,7 +120,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
@@ -109,7 +131,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
</widget>
@@ -272,17 +294,6 @@
<property name="position">0</property>
</packing>
</child>
- <child>
- <widget class="GtkLabel" id="label_rfid">
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">label</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
</widget>
<packing>
<property name="expand">True</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3ab12bc8..e9c5e7b6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -117,6 +117,7 @@ src/json/compujump.cs
src/json/json.cs
src/jumpsProfile.cs
src/jumpType.cs
+src/networks.cs
src/Mini/chronojump_mini.cs
src/old/server.cs
src/pulseType.cs
diff --git a/src/gui/dialogPersonPopup.cs b/src/gui/dialogPersonPopup.cs
index 95c96cc6..affc26d7 100644
--- a/src/gui/dialogPersonPopup.cs
+++ b/src/gui/dialogPersonPopup.cs
@@ -37,6 +37,7 @@ public class DialogPersonPopup
[Widget] Gtk.Label label_rfid;
[Widget] Gtk.VBox vbox_tasks_parametrized;
+ [Widget] Gtk.Label label_network_devices;
[Widget] Gtk.Label label_server_connected;
[Widget] Gtk.Image image_server_connected_yes;
[Widget] Gtk.Image image_server_connected_no;
@@ -57,7 +58,8 @@ public class DialogPersonPopup
private bool compujumpDjango;
public DialogPersonPopup (int personID, string name, string rfid,
- List<Task> tasks, List<StationCount> stationsCount, bool serverConnected, bool
Autologout,
+ List<Task> tasks, List<StationCount> stationsCount,
+ string networkDevices, bool serverConnected, bool Autologout,
bool compujumpDjango, bool compujumpHideTaskDone)
{
Glade.XML gladeXML;
@@ -89,6 +91,7 @@ public class DialogPersonPopup
pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "gtk-cancel.png");
image_server_connected_no.Pixbuf = pixbuf;
+ label_network_devices.Text = networkDevices;
if(serverConnected)
{
label_server_connected.Text = "Server is connected";
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 98c628f3..5e5d5f5d 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -866,11 +866,15 @@ public partial class ChronoJumpWindow
//3) get other stationsCount
List<StationCount> stationsCount =
json.GetOtherStationsWithPendingTasks(currentPerson.UniqueID, configChronojump.CompujumpStationID);
- //4) show dialog
- showDialogPersonPopup(tasks, stationsCount, json.Connected);
+ //4) check if there are active Internet devices
+ NetworksCheckDevices ncd = new NetworksCheckDevices();
+
+ //5) show dialog
+ showDialogPersonPopup(tasks, stationsCount, ncd.ToString(), json.Connected);
}
- private void showDialogPersonPopup(List<Task> tasks, List<StationCount> stationsCount, bool
serverConnected)
+
+ private void showDialogPersonPopup(List<Task> tasks, List<StationCount> stationsCount, string
networkDevices, bool serverConnected)
{
if(dialogPersonPopup != null)
dialogPersonPopup.DestroyDialog();
@@ -880,7 +884,7 @@ public partial class ChronoJumpWindow
dialogPersonPopup = new DialogPersonPopup(
currentPerson.UniqueID, currentPerson.Name, capturedRFID, tasks,
stationsCount,
- serverConnected, compujumpAutologout.Active,
+ networkDevices, serverConnected, compujumpAutologout.Active,
configChronojump.CompujumpDjango, configChronojump.CompujumpHideTaskDone);
dialogPersonPopup.Fake_button_start_task.Clicked -= new EventHandler(compujumpTaskStart);
diff --git a/src/networks.cs b/src/networks.cs
index 1e0c0f8c..60a04a8e 100644
--- a/src/networks.cs
+++ b/src/networks.cs
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic; //List<T>
using System.IO; //StringReader
+using Mono.Unix;
public class Networks
{
@@ -152,3 +153,56 @@ public class NetworksSendMail
// another option will be use C-sharp methods, see:
//
https://stackoverflow.com/questions/2825950/sending-email-with-attachments-from-c-attachments-arrive-as-part-1-2-in-thunde
}
+
+/*
+ * on Networks to check if eth0 or wifi devices (interfaces) are on
+ * read to see if they are "up":
+ * /sys/class/net/eth0/operstate
+ * /sys/class/net/wlan.../operstate
+*/
+public class NetworksCheckDevices
+{
+ private List<string> devicesUp;
+ private string path = "/sys/class/net/";
+
+ public NetworksCheckDevices ()
+ {
+ devicesUp = new List<string>();
+
+ DirectoryInfo pathDirInfo = new DirectoryInfo(path);
+ DirectoryInfo [] subdirs = pathDirInfo.GetDirectories();
+ foreach (DirectoryInfo dir in subdirs)
+ if( ( dir.Name.StartsWith("eth") || dir.Name.StartsWith("wlan") ) &&
checkDevice(dir.Name))
+ devicesUp.Add(dir.Name);
+ }
+
+ private bool checkDevice(string device)
+ {
+ string filename = path + device + "/operstate";
+ if(File.Exists(filename))
+ {
+ List<string> l = Util.ReadFileAsStringList(filename);
+ foreach(string str in l)
+ if(str.Contains("up"))
+ return true;
+ }
+
+ return false;
+ }
+
+ public override string ToString()
+ {
+ if(devicesUp.Count == 0)
+ return Catalog.GetString("No active Internet devices.");
+ else {
+ string str = Catalog.GetString("Active Internet devices:");
+ string sep = " ";
+ foreach(string device in devicesUp)
+ {
+ str += sep + device;
+ sep = ", ";
+ }
+ return str;
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]