Debian Codegraph @

lib/csharp/MonoExample/NewStationNotify/Notification.cs

raw
1 // License: BSD
2 // Copyright (C) 2011-2018 Thomas d'Otreppe
3 using System;
4 using System.Collections.Generic;
5 using NDesk.DBus;
6 using org.freedesktop;
7
8 namespace NewStationNotify
9 {
10 public class Notification
11 {
12 public Notification ()
13 {
14 }
15
16 /// <summary>
17 /// Shows a notification on the screen. This has been tested on a N900 and will probably not work with anything else but it can be used as a base.
18 /// </summary>
19 public static void Notify(String BSSID, String staMac) {
20 Bus bus = Bus.Session;
21
22 Notifications nf = bus.GetObject<Notifications> ("org.freedesktop.Notifications", new ObjectPath ("/org/freedesktop/Notifications"));
23
24 Dictionary<string,object> hints = new Dictionary<string,object> ();
25
26 if (string.IsNullOrEmpty(BSSID)) {
27
28 nf.Notify ("Notification", 0, "control_bluetooth_paired", "New unassociated station", staMac, new string[0], hints, 0);
29 } else {
30 nf.Notify ("Notification", 0, "control_bluetooth_paired", "New associated station", staMac + " (AP: " + BSSID + ")", new string[0], hints, 0);
31 }
32 /*
33 // Ugly hack for the N900 to notify the user since this can't be done with dbus-send
34 // because it does not support empty array.
35 StreamWriter sw = new StreamWriter("/home/user/notify.py");
36 if (string.IsNullOrEmpty(BSSID)) {
37
38 sw.WriteLine("import dbus\n" +
39 "bus = dbus.SessionBus()\n" +
40 "proxy = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')\n" +
41 "interface = dbus.Interface(proxy,dbus_interface='org.freedesktop.Notifications')\n" +
42 "interface.Notify('Notification', 0, 'control_bluetooth_paired', 'New unassociated station', '{0}', [], {{}}, 0)", staMac);
43 } else {
44 sw.WriteLine("import dbus\n" +
45 "bus = dbus.SessionBus()\n" +
46 "proxy = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')\n" +
47 "interface = dbus.Interface(proxy,dbus_interface='org.freedesktop.Notifications')\n" +
48 "interface.Notify('Notification', 0, 'control_bluetooth_paired', 'New associated station', '{0} is associated to {1}', [], {{}}, 0)", staMac, BSSID);
49 }
50 sw.Close();
51 Process p = new Process();
52 p.StartInfo.UseShellExecute = false;
53 p.StartInfo.FileName = "/usr/bin/python";
54 p.StartInfo.Arguments = "/home/user/notify.py";
55 p.Start();
56 p.WaitForExit();
57 FileInfo f = new FileInfo("/home/user/notify.py");
58 f.Delete();
59 */
60 }
61 }
62 }
63