mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-06 16:21:50 +00:00
Remove outdated examples
This commit is contained in:
parent
3f907cb9e3
commit
64af880fd7
|
@ -1,44 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from NetworkManager import NetworkManager
|
||||
import gtk
|
||||
|
||||
class NMTester(NetworkManager):
|
||||
|
||||
def __init__(self):
|
||||
NetworkManager.__init__(self)
|
||||
|
||||
for signal in self.NM_SIGNALS:
|
||||
self.nm_object.connect_to_signal(signal,
|
||||
self.nm_signal_handler)
|
||||
for signal in self.NMI_SIGNALS:
|
||||
self.nmi_object.connect_to_signal(signal,
|
||||
self.nmi_signal_handler)
|
||||
self.print_device_list()
|
||||
|
||||
def print_device_list(self):
|
||||
d_list = self.get_devices()
|
||||
print
|
||||
print "========================================================="
|
||||
print
|
||||
for d in d_list:
|
||||
for k,v in d.iteritems():
|
||||
print "%s: %s" % (k,v)
|
||||
print
|
||||
print "========================================================="
|
||||
print
|
||||
|
||||
def nm_signal_handler(self, interface, signal_name,
|
||||
service, path, message):
|
||||
self.print_device_list()
|
||||
|
||||
def nmi_signal_handler(self, interface, signal_name,
|
||||
service, path, message):
|
||||
print ("Received signal '%s.%s' from object '%s%s' with message %s"
|
||||
% (interface, signal_name, service, path, message))
|
||||
|
||||
if __name__ == "__main__":
|
||||
nmt = NMTester()
|
||||
gtk.main()
|
||||
|
||||
|
|
@ -1,214 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import dbus
|
||||
from dbus_bindings import DBusException
|
||||
|
||||
NM_SERVICE="org.freedesktop.NetworkManager"
|
||||
NM_PATH="/org/freedesktop/NetworkManager"
|
||||
NM_INTERFACE=NM_SERVICE
|
||||
|
||||
# i can append device names like eth0 to this path to get more info
|
||||
NM_PATH_DEVICES="/org/freedesktop/NetworkManager/Devices"
|
||||
NM_INTERFACE_DEVICES="org.freedesktop.NetworkManager.Devices"
|
||||
|
||||
NMI_SERVICE="org.freedesktop.NetworkManagerInfo"
|
||||
NMI_PATH="/org/freedesktop/NetworkManagerInfo"
|
||||
NMI_INTERFACE=NMI_SERVICE
|
||||
|
||||
HAL_SERVICE="org.freedesktop.Hal"
|
||||
HAL_PATH="/org/freedesktop/Hal/Manager"
|
||||
HAL_INTERFACE="org.freedesktop.Hal.Manager"
|
||||
HAL_INTERFACE_DEVICE="org.freedesktop.Hal.Device"
|
||||
|
||||
class NetworkManager:
|
||||
WIRED_DEVICE = 1
|
||||
WIRELESS_DEVICE = 2
|
||||
|
||||
CONNECTED = "connected"
|
||||
CONNECTING = "connecting"
|
||||
DISCONNECTED = "disconnected"
|
||||
|
||||
NM_SIGNALS = [ "DeviceNoLongerActive",
|
||||
"DeviceNowActive",
|
||||
"DeviceActivating",
|
||||
"DevicesChanged",
|
||||
"DeviceIP4AddressChange",
|
||||
"WirelessNetworkDisappeared",
|
||||
"WirelessNetworkAppeared"
|
||||
]
|
||||
|
||||
NMI_SIGNALS = [ "TrustedNetworkUpdate",
|
||||
"PreferredNetworkUpdate"
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
self.__init_dbus__()
|
||||
|
||||
# dictionary of devices
|
||||
self.__devices = {}
|
||||
|
||||
def __init_dbus__(self):
|
||||
try:
|
||||
self._bus = dbus.SystemBus()
|
||||
try:
|
||||
self._nm_service = self._bus.get_service(NM_SERVICE)
|
||||
self.nm_object = self._nm_service.get_object(NM_PATH,
|
||||
NM_INTERFACE)
|
||||
except Exception, e:
|
||||
print "Counldn't get the %s service" % NM_SERVICE
|
||||
print e
|
||||
|
||||
try:
|
||||
self._nmi_service = self._bus.get_service(NMI_SERVICE)
|
||||
self.nmi_object = self._nmi_service.get_object(NMI_PATH,
|
||||
NMI_INTERFACE)
|
||||
except Exception, e:
|
||||
print "Counldn't get the %s service" % NMI_SERVICE
|
||||
print e
|
||||
|
||||
try:
|
||||
self._hal_service = self._bus.get_service(HAL_SERVICE)
|
||||
self._hal_manager = self._hal_service.get_object(HAL_PATH,
|
||||
HAL_INTERFACE)
|
||||
except Exception, e:
|
||||
print "Counldn't get the %s service" % HAL_SERVICE
|
||||
print e
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
"""
|
||||
returns dictionary of the active device information
|
||||
if device does not exist returns get_device failure method
|
||||
"""
|
||||
def get_active_device(self):
|
||||
active_device = self.nm_object.getActiveDevice()
|
||||
return self.get_device(active_device)
|
||||
|
||||
"""
|
||||
pass device string /org/freedesktop/NetworkManager/Device/eth0
|
||||
returns dictionary of device information
|
||||
if device does not exist returns None
|
||||
"""
|
||||
def get_device(self, device):
|
||||
try:
|
||||
nm_dev_obj = self._nm_service.get_object(device,
|
||||
NM_INTERFACE_DEVICES)
|
||||
d = {}
|
||||
d["nm.device"] = device
|
||||
d["nm.name"] = nm_dev_obj.getName(device)
|
||||
d["nm.type"] = nm_dev_obj.getType(device)
|
||||
d["nm.udi"] = nm_dev_obj.getHalUdi(device)
|
||||
d["nm.ip4"] = nm_dev_obj.getIP4Address(device)
|
||||
d["nm.link_active"] = nm_dev_obj.getLinkActive(device)
|
||||
|
||||
try:
|
||||
d["nm.active_network"] = nm_dev_obj.getActiveNetwork(device)
|
||||
d["nm.strength"] = nm_dev_obj.getStrength(device)
|
||||
except DBusException, e:
|
||||
pass
|
||||
|
||||
try:
|
||||
d["nm.networks"] = {}
|
||||
networks = nm_dev_obj.getNetworks(device)
|
||||
for network in networks:
|
||||
nm_network_object = self._nm_service.get_object(network,
|
||||
NM_INTERFACE_DEVICES)
|
||||
n = {}
|
||||
n["network"] = network
|
||||
n["name"] = nm_network_object.getName()
|
||||
n["address"] = nm_network_object.getAddress()
|
||||
n["strength"] = nm_network_object.getStrength()
|
||||
n["frequency"] = nm_network_object.getFrequency()
|
||||
n["rate"] = nm_network_object.getRate()
|
||||
n["encrypted"] = nm_network_object.getEncrypted()
|
||||
|
||||
d["nm.networks"][network] = n
|
||||
|
||||
except DBusException, e:
|
||||
pass
|
||||
|
||||
active_device = self.nm_object.getActiveDevice()
|
||||
|
||||
if device == active_device:
|
||||
d["nm.status"] = self.nm_object.status()
|
||||
else:
|
||||
d["nm.status"] = self.DISCONNECTED
|
||||
|
||||
# we already have this device cached, so just update the status
|
||||
if device in self.__devices:
|
||||
for k,v in d.iteritems():
|
||||
self.__devices[device][k] = v
|
||||
# it's a new device so get the info from HAL
|
||||
else:
|
||||
hal = self._get_hal_info(d["nm.udi"])
|
||||
for k,v in hal.iteritems():
|
||||
d[k] = v
|
||||
self.__devices[device] = d
|
||||
|
||||
return self.__devices[device]
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
return None
|
||||
|
||||
"""
|
||||
Returns list of dictionary objects of all active devices
|
||||
Returns empty list if no active devices
|
||||
"""
|
||||
def get_devices(self):
|
||||
|
||||
active_devices = self.nm_object.getDevices()
|
||||
devices = []
|
||||
|
||||
for device in active_devices:
|
||||
devices.append(self.get_device(device))
|
||||
|
||||
return devices
|
||||
|
||||
"""
|
||||
Returns list of dictionary objects of all devices active or not
|
||||
Returns empty list if no active devices
|
||||
"""
|
||||
def get_all_devices(self):
|
||||
return self.__devices.values()
|
||||
|
||||
def has_type_device (self, type):
|
||||
for device in self.get_devices():
|
||||
if device["nm.type"] == type:
|
||||
return True
|
||||
return False
|
||||
|
||||
def number_device_types(self, type):
|
||||
count = 0
|
||||
for device in self.get_devices():
|
||||
if device["nm.type"] == type:
|
||||
count = count + 1
|
||||
return count
|
||||
|
||||
def number_wired_devices(self):
|
||||
return self.number_device_types(self.WIRED_DEVICE)
|
||||
|
||||
def number_wireless_devices(self):
|
||||
return self.number_device_types(self.WIRELESS_DEVICE)
|
||||
|
||||
def has_wired_device(self):
|
||||
return self.has_type_device(self.WIRED_DEVICE)
|
||||
|
||||
def has_wireless_device(self):
|
||||
return self.has_type_device(self.WIRELESS_DEVICE)
|
||||
|
||||
def _get_hal_info(self, udi):
|
||||
hal_devices = self._hal_manager.FindDeviceStringMatch("info.udi",
|
||||
udi)
|
||||
for hal_device in hal_devices:
|
||||
device_dbus_obj = self._hal_service.get_object(hal_device,
|
||||
HAL_INTERFACE_DEVICE)
|
||||
properties = device_dbus_obj.GetAllProperties()
|
||||
return properties
|
||||
|
||||
if __name__ == "__main__":
|
||||
nm = NetworkManager()
|
||||
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
Python Examples
|
||||
|
||||
You'll need equivalent versions of these packages in order to run most of these examples.
|
||||
|
||||
hal-0.2.97.cvs20040823
|
||||
dbus-0.22-4
|
||||
pygtk2-2.3.96-2
|
||||
python-2.3.4-8
|
||||
gnome-python2-2.0.2-1
|
||||
|
||||
|
||||
NMTester.py
|
||||
===============================================================================
|
||||
|
||||
This is a simple command line program that sub classes the NetworkManager class. The tester prints out the network devices objects that are returned from the NetworkManager class. The code hangs in the gtk.main() loop once run and will listen for any events from the NetworkManager
|
||||
|
||||
|
||||
NetworkManager.py
|
||||
===============================================================================
|
||||
This object hooks into the NetworkManger and HAL service through D-BUS. The get_device_list code will return a python list [] of dictionary objects representing the devices that the NetworkManger services is aware of.
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
# Set the C flags to include the GTK+ and Python libraries
|
||||
CFLAGS = `pkg-config --cflags gtk+-2.0 pygtk-2.0` -I/usr/include/python2.3/ -I.
|
||||
LDFLAGS = `pkg-config --libs gtk+-2.0 pygtk-2.0`
|
||||
|
||||
# Build the shared object
|
||||
trayicon.so: trayicon.o eggtrayicon.o trayiconmodule.o
|
||||
$(CC) $(LDFLAGS) -shared $^ -o $@
|
||||
|
||||
|
||||
# The path to the GTK+ python types
|
||||
DEFS=`pkg-config --variable=defsdir pygtk-2.0`
|
||||
|
||||
# Generate the C wrapper from the defs and our override file
|
||||
trayicon.c: trayicon.defs trayicon.override
|
||||
pygtk-codegen-2.0 --prefix trayicon \
|
||||
--register $(DEFS)/gdk-types.defs \
|
||||
--register $(DEFS)/gtk-types.defs \
|
||||
--override trayicon.override \
|
||||
trayicon.defs > $@
|
||||
|
||||
trayicon.defs: eggtrayicon.h config.h
|
||||
python \
|
||||
/usr/share/pygtk/2.0/codegen/h2def.py \
|
||||
eggtrayicon.h > trayicon.defs
|
||||
|
||||
config.h:
|
||||
touch config.h
|
||||
ln -s ../NetworkManager.py .
|
||||
|
||||
# A rule to clean the generated files
|
||||
clean:
|
||||
rm -f trayicon.so *.o trayicon.c trayicon.defs *~ config.h NetworkManager.py*
|
||||
|
||||
.PHONY: clean
|
|
@ -1,513 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||
/* eggtrayicon.c
|
||||
* Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "eggtrayicon.h"
|
||||
|
||||
#include <gdkconfig.h>
|
||||
#if defined (GDK_WINDOWING_X11)
|
||||
#include <gdk/gdkx.h>
|
||||
#include <X11/Xatom.h>
|
||||
#elif defined (GDK_WINDOWING_WIN32)
|
||||
#include <gdk/gdkwin32.h>
|
||||
#endif
|
||||
|
||||
#ifndef EGG_COMPILATION
|
||||
#ifndef _
|
||||
#define _(x) dgettext (GETTEXT_PACKAGE, x)
|
||||
#define N_(x) x
|
||||
#endif
|
||||
#else
|
||||
#define _(x) x
|
||||
#define N_(x) x
|
||||
#endif
|
||||
|
||||
#define SYSTEM_TRAY_REQUEST_DOCK 0
|
||||
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
|
||||
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
|
||||
|
||||
#define SYSTEM_TRAY_ORIENTATION_HORZ 0
|
||||
#define SYSTEM_TRAY_ORIENTATION_VERT 1
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ORIENTATION
|
||||
};
|
||||
|
||||
static GtkPlugClass *parent_class = NULL;
|
||||
|
||||
static void egg_tray_icon_init (EggTrayIcon *icon);
|
||||
static void egg_tray_icon_class_init (EggTrayIconClass *klass);
|
||||
|
||||
static void egg_tray_icon_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void egg_tray_icon_realize (GtkWidget *widget);
|
||||
static void egg_tray_icon_unrealize (GtkWidget *widget);
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
static void egg_tray_icon_update_manager_window (EggTrayIcon *icon,
|
||||
gboolean dock_if_realized);
|
||||
static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon);
|
||||
#endif
|
||||
|
||||
GType
|
||||
egg_tray_icon_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (our_type == 0)
|
||||
{
|
||||
static const GTypeInfo our_info =
|
||||
{
|
||||
sizeof (EggTrayIconClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) egg_tray_icon_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (EggTrayIcon),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) egg_tray_icon_init
|
||||
};
|
||||
|
||||
our_type = g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info, 0);
|
||||
}
|
||||
|
||||
return our_type;
|
||||
}
|
||||
|
||||
static void
|
||||
egg_tray_icon_init (EggTrayIcon *icon)
|
||||
{
|
||||
icon->stamp = 1;
|
||||
icon->orientation = GTK_ORIENTATION_HORIZONTAL;
|
||||
|
||||
gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK);
|
||||
}
|
||||
|
||||
static void
|
||||
egg_tray_icon_class_init (EggTrayIconClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = (GObjectClass *)klass;
|
||||
GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
gobject_class->get_property = egg_tray_icon_get_property;
|
||||
|
||||
widget_class->realize = egg_tray_icon_realize;
|
||||
widget_class->unrealize = egg_tray_icon_unrealize;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ORIENTATION,
|
||||
g_param_spec_enum ("orientation",
|
||||
_("Orientation"),
|
||||
_("The orientation of the tray."),
|
||||
GTK_TYPE_ORIENTATION,
|
||||
GTK_ORIENTATION_HORIZONTAL,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
#if defined (GDK_WINDOWING_X11)
|
||||
/* Nothing */
|
||||
#elif defined (GDK_WINDOWING_WIN32)
|
||||
g_warning ("Port eggtrayicon to Win32");
|
||||
#else
|
||||
g_warning ("Port eggtrayicon to this GTK+ backend");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
egg_tray_icon_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EggTrayIcon *icon = EGG_TRAY_ICON (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ORIENTATION:
|
||||
g_value_set_enum (value, icon->orientation);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
|
||||
static void
|
||||
egg_tray_icon_get_orientation_property (EggTrayIcon *icon)
|
||||
{
|
||||
Display *xdisplay;
|
||||
Atom type;
|
||||
int format;
|
||||
union {
|
||||
gulong *prop;
|
||||
guchar *prop_ch;
|
||||
} prop = { NULL };
|
||||
gulong nitems;
|
||||
gulong bytes_after;
|
||||
int error, result;
|
||||
|
||||
g_assert (icon->manager_window != None);
|
||||
|
||||
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
|
||||
|
||||
gdk_error_trap_push ();
|
||||
type = None;
|
||||
result = XGetWindowProperty (xdisplay,
|
||||
icon->manager_window,
|
||||
icon->orientation_atom,
|
||||
0, G_MAXLONG, FALSE,
|
||||
XA_CARDINAL,
|
||||
&type, &format, &nitems,
|
||||
&bytes_after, &(prop.prop_ch));
|
||||
error = gdk_error_trap_pop ();
|
||||
|
||||
if (error || result != Success)
|
||||
return;
|
||||
|
||||
if (type == XA_CARDINAL)
|
||||
{
|
||||
GtkOrientation orientation;
|
||||
|
||||
orientation = (prop.prop [0] == SYSTEM_TRAY_ORIENTATION_HORZ) ?
|
||||
GTK_ORIENTATION_HORIZONTAL :
|
||||
GTK_ORIENTATION_VERTICAL;
|
||||
|
||||
if (icon->orientation != orientation)
|
||||
{
|
||||
icon->orientation = orientation;
|
||||
|
||||
g_object_notify (G_OBJECT (icon), "orientation");
|
||||
}
|
||||
}
|
||||
|
||||
if (prop.prop)
|
||||
XFree (prop.prop);
|
||||
}
|
||||
|
||||
static GdkFilterReturn
|
||||
egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data)
|
||||
{
|
||||
EggTrayIcon *icon = user_data;
|
||||
XEvent *xev = (XEvent *)xevent;
|
||||
|
||||
if (xev->xany.type == ClientMessage &&
|
||||
xev->xclient.message_type == icon->manager_atom &&
|
||||
xev->xclient.data.l[1] == icon->selection_atom)
|
||||
{
|
||||
egg_tray_icon_update_manager_window (icon, TRUE);
|
||||
}
|
||||
else if (xev->xany.window == icon->manager_window)
|
||||
{
|
||||
if (xev->xany.type == PropertyNotify &&
|
||||
xev->xproperty.atom == icon->orientation_atom)
|
||||
{
|
||||
egg_tray_icon_get_orientation_property (icon);
|
||||
}
|
||||
if (xev->xany.type == DestroyNotify)
|
||||
{
|
||||
egg_tray_icon_manager_window_destroyed (icon);
|
||||
}
|
||||
}
|
||||
return GDK_FILTER_CONTINUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void
|
||||
egg_tray_icon_unrealize (GtkWidget *widget)
|
||||
{
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
EggTrayIcon *icon = EGG_TRAY_ICON (widget);
|
||||
GdkWindow *root_window;
|
||||
|
||||
if (icon->manager_window != None)
|
||||
{
|
||||
GdkWindow *gdkwin;
|
||||
|
||||
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (widget),
|
||||
icon->manager_window);
|
||||
|
||||
gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
|
||||
}
|
||||
|
||||
root_window = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
|
||||
|
||||
gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon);
|
||||
|
||||
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
|
||||
(* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
|
||||
static void
|
||||
egg_tray_icon_send_manager_message (EggTrayIcon *icon,
|
||||
long message,
|
||||
Window window,
|
||||
long data1,
|
||||
long data2,
|
||||
long data3)
|
||||
{
|
||||
XClientMessageEvent ev;
|
||||
Display *display;
|
||||
|
||||
ev.type = ClientMessage;
|
||||
ev.window = window;
|
||||
ev.message_type = icon->system_tray_opcode_atom;
|
||||
ev.format = 32;
|
||||
ev.data.l[0] = gdk_x11_get_server_time (GTK_WIDGET (icon)->window);
|
||||
ev.data.l[1] = message;
|
||||
ev.data.l[2] = data1;
|
||||
ev.data.l[3] = data2;
|
||||
ev.data.l[4] = data3;
|
||||
|
||||
display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
|
||||
|
||||
gdk_error_trap_push ();
|
||||
XSendEvent (display,
|
||||
icon->manager_window, False, NoEventMask, (XEvent *)&ev);
|
||||
XSync (display, False);
|
||||
gdk_error_trap_pop ();
|
||||
}
|
||||
|
||||
static void
|
||||
egg_tray_icon_send_dock_request (EggTrayIcon *icon)
|
||||
{
|
||||
egg_tray_icon_send_manager_message (icon,
|
||||
SYSTEM_TRAY_REQUEST_DOCK,
|
||||
icon->manager_window,
|
||||
gtk_plug_get_id (GTK_PLUG (icon)),
|
||||
0, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
egg_tray_icon_update_manager_window (EggTrayIcon *icon,
|
||||
gboolean dock_if_realized)
|
||||
{
|
||||
Display *xdisplay;
|
||||
|
||||
if (icon->manager_window != None)
|
||||
return;
|
||||
|
||||
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
|
||||
|
||||
XGrabServer (xdisplay);
|
||||
|
||||
icon->manager_window = XGetSelectionOwner (xdisplay,
|
||||
icon->selection_atom);
|
||||
|
||||
if (icon->manager_window != None)
|
||||
XSelectInput (xdisplay,
|
||||
icon->manager_window, StructureNotifyMask|PropertyChangeMask);
|
||||
|
||||
XUngrabServer (xdisplay);
|
||||
XFlush (xdisplay);
|
||||
|
||||
if (icon->manager_window != None)
|
||||
{
|
||||
GdkWindow *gdkwin;
|
||||
|
||||
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
|
||||
icon->manager_window);
|
||||
|
||||
gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon);
|
||||
|
||||
if (dock_if_realized && GTK_WIDGET_REALIZED (icon))
|
||||
egg_tray_icon_send_dock_request (icon);
|
||||
|
||||
egg_tray_icon_get_orientation_property (icon);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon)
|
||||
{
|
||||
GdkWindow *gdkwin;
|
||||
|
||||
g_return_if_fail (icon->manager_window != None);
|
||||
|
||||
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
|
||||
icon->manager_window);
|
||||
|
||||
gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
|
||||
|
||||
icon->manager_window = None;
|
||||
|
||||
egg_tray_icon_update_manager_window (icon, TRUE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void
|
||||
egg_tray_icon_realize (GtkWidget *widget)
|
||||
{
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
EggTrayIcon *icon = EGG_TRAY_ICON (widget);
|
||||
GdkScreen *screen;
|
||||
GdkDisplay *display;
|
||||
Display *xdisplay;
|
||||
char buffer[256];
|
||||
GdkWindow *root_window;
|
||||
|
||||
if (GTK_WIDGET_CLASS (parent_class)->realize)
|
||||
GTK_WIDGET_CLASS (parent_class)->realize (widget);
|
||||
|
||||
screen = gtk_widget_get_screen (widget);
|
||||
display = gdk_screen_get_display (screen);
|
||||
xdisplay = gdk_x11_display_get_xdisplay (display);
|
||||
|
||||
/* Now see if there's a manager window around */
|
||||
g_snprintf (buffer, sizeof (buffer),
|
||||
"_NET_SYSTEM_TRAY_S%d",
|
||||
gdk_screen_get_number (screen));
|
||||
|
||||
icon->selection_atom = XInternAtom (xdisplay, buffer, False);
|
||||
|
||||
icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False);
|
||||
|
||||
icon->system_tray_opcode_atom = XInternAtom (xdisplay,
|
||||
"_NET_SYSTEM_TRAY_OPCODE",
|
||||
False);
|
||||
|
||||
icon->orientation_atom = XInternAtom (xdisplay,
|
||||
"_NET_SYSTEM_TRAY_ORIENTATION",
|
||||
False);
|
||||
|
||||
egg_tray_icon_update_manager_window (icon, FALSE);
|
||||
egg_tray_icon_send_dock_request (icon);
|
||||
|
||||
root_window = gdk_screen_get_root_window (screen);
|
||||
|
||||
/* Add a root window filter so that we get changes on MANAGER */
|
||||
gdk_window_add_filter (root_window,
|
||||
egg_tray_icon_manager_filter, icon);
|
||||
#endif
|
||||
}
|
||||
|
||||
EggTrayIcon *
|
||||
egg_tray_icon_new_for_screen (GdkScreen *screen, const char *name)
|
||||
{
|
||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
|
||||
|
||||
return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name, NULL);
|
||||
}
|
||||
|
||||
EggTrayIcon*
|
||||
egg_tray_icon_new (const gchar *name)
|
||||
{
|
||||
return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL);
|
||||
}
|
||||
|
||||
guint
|
||||
egg_tray_icon_send_message (EggTrayIcon *icon,
|
||||
gint timeout,
|
||||
const gchar *message,
|
||||
gint len)
|
||||
{
|
||||
guint stamp;
|
||||
|
||||
g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0);
|
||||
g_return_val_if_fail (timeout >= 0, 0);
|
||||
g_return_val_if_fail (message != NULL, 0);
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
if (icon->manager_window == None)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (len < 0)
|
||||
len = strlen (message);
|
||||
|
||||
stamp = icon->stamp++;
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
/* Get ready to send the message */
|
||||
egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE,
|
||||
(Window)gtk_plug_get_id (GTK_PLUG (icon)),
|
||||
timeout, len, stamp);
|
||||
|
||||
/* Now to send the actual message */
|
||||
gdk_error_trap_push ();
|
||||
while (len > 0)
|
||||
{
|
||||
XClientMessageEvent ev;
|
||||
Display *xdisplay;
|
||||
|
||||
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
|
||||
|
||||
ev.type = ClientMessage;
|
||||
ev.window = (Window)gtk_plug_get_id (GTK_PLUG (icon));
|
||||
ev.format = 8;
|
||||
ev.message_type = XInternAtom (xdisplay,
|
||||
"_NET_SYSTEM_TRAY_MESSAGE_DATA", False);
|
||||
if (len > 20)
|
||||
{
|
||||
memcpy (&ev.data, message, 20);
|
||||
len -= 20;
|
||||
message += 20;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy (&ev.data, message, len);
|
||||
len = 0;
|
||||
}
|
||||
|
||||
XSendEvent (xdisplay,
|
||||
icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev);
|
||||
XSync (xdisplay, False);
|
||||
}
|
||||
gdk_error_trap_pop ();
|
||||
#endif
|
||||
|
||||
return stamp;
|
||||
}
|
||||
|
||||
void
|
||||
egg_tray_icon_cancel_message (EggTrayIcon *icon,
|
||||
guint id)
|
||||
{
|
||||
g_return_if_fail (EGG_IS_TRAY_ICON (icon));
|
||||
g_return_if_fail (id > 0);
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE,
|
||||
(Window)gtk_plug_get_id (GTK_PLUG (icon)),
|
||||
id, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
GtkOrientation
|
||||
egg_tray_icon_get_orientation (EggTrayIcon *icon)
|
||||
{
|
||||
g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), GTK_ORIENTATION_HORIZONTAL);
|
||||
|
||||
return icon->orientation;
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||
/* eggtrayicon.h
|
||||
* Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __EGG_TRAY_ICON_H__
|
||||
#define __EGG_TRAY_ICON_H__
|
||||
|
||||
#include <gtk/gtkplug.h>
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
#include <gdk/gdkx.h>
|
||||
#endif
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EGG_TYPE_TRAY_ICON (egg_tray_icon_get_type ())
|
||||
#define EGG_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TRAY_ICON, EggTrayIcon))
|
||||
#define EGG_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TRAY_ICON, EggTrayIconClass))
|
||||
#define EGG_IS_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TRAY_ICON))
|
||||
#define EGG_IS_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TRAY_ICON))
|
||||
#define EGG_TRAY_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TRAY_ICON, EggTrayIconClass))
|
||||
|
||||
typedef struct _EggTrayIcon EggTrayIcon;
|
||||
typedef struct _EggTrayIconClass EggTrayIconClass;
|
||||
|
||||
struct _EggTrayIcon
|
||||
{
|
||||
GtkPlug parent_instance;
|
||||
|
||||
guint stamp;
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
Atom selection_atom;
|
||||
Atom manager_atom;
|
||||
Atom system_tray_opcode_atom;
|
||||
Atom orientation_atom;
|
||||
Window manager_window;
|
||||
#endif
|
||||
GtkOrientation orientation;
|
||||
};
|
||||
|
||||
struct _EggTrayIconClass
|
||||
{
|
||||
GtkPlugClass parent_class;
|
||||
};
|
||||
|
||||
GType egg_tray_icon_get_type (void);
|
||||
|
||||
EggTrayIcon *egg_tray_icon_new_for_screen (GdkScreen *screen,
|
||||
const gchar *name);
|
||||
|
||||
EggTrayIcon *egg_tray_icon_new (const gchar *name);
|
||||
|
||||
guint egg_tray_icon_send_message (EggTrayIcon *icon,
|
||||
gint timeout,
|
||||
const char *message,
|
||||
gint len);
|
||||
void egg_tray_icon_cancel_message (EggTrayIcon *icon,
|
||||
guint id);
|
||||
|
||||
GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon *icon);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __EGG_TRAY_ICON_H__ */
|
|
@ -1,327 +0,0 @@
|
|||
#! /usr/bin/python
|
||||
import pygtk; pygtk.require("2.0")
|
||||
import gtk
|
||||
import gtk.gdk
|
||||
|
||||
try:
|
||||
import trayicon
|
||||
from NetworkManager import NetworkManager
|
||||
except ImportError, e:
|
||||
print e
|
||||
print "type 'make' make the necessary modules to run this example"
|
||||
import sys
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class network_tray:
|
||||
|
||||
def __init__(self):
|
||||
self._make_menu()
|
||||
self._make_tray()
|
||||
|
||||
self._nm = NetworkManager()
|
||||
for signal in self._nm.NM_SIGNALS:
|
||||
self._nm.nm_object.connect_to_signal(signal,
|
||||
self._network_event)
|
||||
|
||||
self._network_event(None, None, None,None,None)
|
||||
|
||||
def _wired_network_cb(self, menuitem, event, device_name):
|
||||
return
|
||||
print menuitem, event, device_name
|
||||
try:
|
||||
self._nm.nm_object.setActiveDevice(device_name)
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
def _wireless_network_cb(self, menuitem, event, device_name, network_name):
|
||||
return
|
||||
print menuitem, event, device_name, network_name
|
||||
try:
|
||||
self._nm.nm_object.setActiveDevice(device_name, network_name)
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
def _add_separator_item(self):
|
||||
sep = gtk.SeparatorMenuItem()
|
||||
sep.show()
|
||||
self._menu.append(sep)
|
||||
|
||||
def _add_label_item(self, label):
|
||||
menuitem = gtk.MenuItem()
|
||||
menuitem.set_sensitive(gtk.FALSE)
|
||||
gtklabel = gtk.Label()
|
||||
|
||||
gtklabel.set_markup("<span size=\"small\" foreground=\"#aaaaaa\" weight=\"ultralight\">%s</span>" % label)
|
||||
gtklabel.set_selectable(gtk.FALSE)
|
||||
hbox = gtk.HBox(homogeneous=gtk.TRUE, spacing=6)
|
||||
hbox.pack_end(gtklabel,expand=gtk.TRUE, fill=gtk.TRUE, padding=0)
|
||||
menuitem.add(hbox)
|
||||
self._menu.append(menuitem)
|
||||
menuitem.show_all()
|
||||
|
||||
def _add_other_wireless_item(self):
|
||||
menuitem = gtk.MenuItem()
|
||||
menuitem.set_sensitive(gtk.TRUE)
|
||||
gtklabel = gtk.Label()
|
||||
gtklabel.set_alignment(0,0)
|
||||
gtklabel.set_label("Other Wireless Networks...")
|
||||
hbox = gtk.HBox(homogeneous=gtk.TRUE, spacing=6)
|
||||
hbox.pack_end(gtklabel,expand=gtk.TRUE, fill=gtk.TRUE, padding=6)
|
||||
menuitem.add(hbox)
|
||||
tt = "Add a wireless network that does not appear on the list"
|
||||
self._tooltips.set_tip(menuitem,tt)
|
||||
self._menu.append(menuitem)
|
||||
menuitem.show_all()
|
||||
|
||||
def _add_wired_device_menu_item(self, device):
|
||||
menuitem = gtk.RadioMenuItem(group=self.__radio_group)
|
||||
if self._is_active(device):
|
||||
menuitem.set_active(1)
|
||||
|
||||
menuitem.connect("button-press-event",self._wired_network_cb,
|
||||
device["nm.device"])
|
||||
|
||||
hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6)
|
||||
hbox.pack_start(self._get_icon(device), expand=gtk.FALSE, fill=gtk.FALSE, padding=6)
|
||||
label = gtk.Label()
|
||||
label.set_justify(gtk.JUSTIFY_LEFT)
|
||||
label.set_text(self._get_device_name(device))
|
||||
hbox.pack_start(label, expand=gtk.FALSE, fill=gtk.FALSE, padding=6)
|
||||
menuitem.add(hbox)
|
||||
hbox.show()
|
||||
self._menu.append(menuitem)
|
||||
try:
|
||||
tt = "IP: %d\nProduct Name: %s\nVendor: %s\nDevice Name: %s" % (device["nm.ip4"], device["pci.product"], device["info.vendor"], device["nm.name"] )
|
||||
self._tooltips.set_tip(menuitem,tt)
|
||||
except:
|
||||
pass
|
||||
menuitem.show_all()
|
||||
|
||||
def _add_wireless_device_menu_item(self, device, generic=gtk.FALSE):
|
||||
menuitem = gtk.MenuItem()
|
||||
|
||||
hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6)
|
||||
hbox.pack_start(self._get_icon(device), expand=gtk.FALSE, fill=gtk.FALSE, padding=6)
|
||||
label = gtk.Label()
|
||||
label.set_justify(gtk.JUSTIFY_LEFT)
|
||||
label.set_markup("<span foreground=\"#aaaaaa\">%s</span>" % self._get_device_name(device))
|
||||
label.set_selectable(gtk.FALSE)
|
||||
hbox.pack_start(label, expand=gtk.FALSE, fill=gtk.FALSE, padding=6)
|
||||
menuitem.add(hbox)
|
||||
hbox.show()
|
||||
self._menu.append(menuitem)
|
||||
try:
|
||||
tt = "IP: %d\nProduct Name: %s\nVendor: %s\nDevice Name: %s" % (device["nm.ip4"], device["pci.product"], device["info.vendor"], device["nm.name"] )
|
||||
self._tooltips.set_tip(menuitem,tt)
|
||||
except:
|
||||
pass
|
||||
menuitem.show_all()
|
||||
|
||||
def _add_vpn_menu_item(self):
|
||||
menuitem = gtk.CheckMenuItem()
|
||||
|
||||
hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6)
|
||||
hbox.pack_start(self._get_vpn_icon(), expand=gtk.FALSE, fill=gtk.FALSE, padding=6)
|
||||
label = gtk.Label()
|
||||
label.set_justify(gtk.JUSTIFY_LEFT)
|
||||
label.set_text("Virtual Private Network")
|
||||
hbox.pack_start(label, expand=gtk.FALSE, fill=gtk.FALSE, padding=6)
|
||||
menuitem.add(hbox)
|
||||
hbox.show()
|
||||
self._menu.append(menuitem)
|
||||
tt = "Use a Virtual Private Network to securely connect to your companies internal system"
|
||||
self._tooltips.set_tip(menuitem,tt)
|
||||
menuitem.show_all()
|
||||
|
||||
def _add_network_menu_item(self, device, network, active_network):
|
||||
menuitem = gtk.RadioMenuItem(group=self.__radio_group)
|
||||
menuitem.set_right_justified(gtk.FALSE)
|
||||
if active_network == gtk.TRUE:
|
||||
menuitem.set_active(1)
|
||||
|
||||
hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6)
|
||||
menuitem.add(hbox)
|
||||
label = gtk.Label(network["name"])
|
||||
label.set_alignment(0.1,0.5)
|
||||
label.show()
|
||||
hbox.pack_start(label,expand=gtk.TRUE, fill=gtk.TRUE)
|
||||
progress = gtk.ProgressBar()
|
||||
progress.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
|
||||
strength = float(network["strength"] * .01)
|
||||
progress.set_fraction(strength)
|
||||
# progress.set_text("%s%%" % int(strength*100))
|
||||
progress.show()
|
||||
hbox.pack_start(progress, expand=gtk.FALSE, fill=gtk.FALSE)
|
||||
icon = self._get_encrypted_icon()
|
||||
if network["encrypted"] == 1:
|
||||
icon.hide()
|
||||
hbox.pack_start(icon,expand=gtk.FALSE, fill=gtk.FALSE)
|
||||
else:
|
||||
icon.show()
|
||||
|
||||
hbox.show()
|
||||
self._menu.append(menuitem)
|
||||
tt = "Name: %s\nEncrypted: %d\nRate: %d\nFrequency: %f\nAddress: %s\nStrength: %1.2f" % (network['name'], network['encrypted'], network['rate'],network['frequency'], network['address'], strength)
|
||||
self._tooltips.set_tip(menuitem,tt)
|
||||
menuitem.connect("button-press-event", self._wireless_network_cb,
|
||||
device["nm.device"], network["network"])
|
||||
menuitem.show()
|
||||
|
||||
def _get_device_name(self, device):
|
||||
|
||||
if self._is_wireless(device):
|
||||
try:
|
||||
if self._nm.number_wireless_devices() > 1:
|
||||
return device["pci.subsys_vendor"]
|
||||
else:
|
||||
return "Wireless Network"
|
||||
except:
|
||||
return "Wireless PCMCIA Card"
|
||||
else:
|
||||
try:
|
||||
if self._nm.number_wired_devices() > 1:
|
||||
return device["info.product"]
|
||||
except:
|
||||
pass
|
||||
return "Wired Network"
|
||||
|
||||
def _is_wireless(self,dev):
|
||||
if dev["nm.type"] == self._nm.WIRELESS_DEVICE:
|
||||
return gtk.TRUE
|
||||
return gtk.FALSE
|
||||
|
||||
def _is_active(self, dev):
|
||||
try:
|
||||
if dev["nm.link_active"] == 1:
|
||||
return gtk.TRUE
|
||||
except:
|
||||
return gtk.FALSE
|
||||
|
||||
def _network_event(self, interface, signal_name,
|
||||
service, path, message):
|
||||
|
||||
for child in self._menu.get_children():
|
||||
self._menu.remove(child)
|
||||
|
||||
devices = self._nm.get_devices()
|
||||
active_device = self._nm.get_active_device()
|
||||
|
||||
def sort_devs(x, y):
|
||||
if x["nm.type"] > y["nm.type"]:
|
||||
return 1
|
||||
elif x["nm.type"] < y["nm.type"]:
|
||||
return -1
|
||||
elif x["nm.link_active"] > y["nm.link_active"]:
|
||||
return 1
|
||||
elif x["nm.link_active"] < y["nm.link_active"]:
|
||||
return -1
|
||||
return 0
|
||||
|
||||
def sort_networks(x, y):
|
||||
if x.lower() < y.lower():
|
||||
return 1
|
||||
return -1
|
||||
|
||||
type = 0
|
||||
devices.sort(sort_devs)
|
||||
for device in devices:
|
||||
|
||||
if self._is_wireless(device):
|
||||
type = device["nm.type"]
|
||||
if self._nm.number_wireless_devices() > 1:
|
||||
self._add_wireless_device_menu_item(device)
|
||||
else:
|
||||
self._add_wireless_device_menu_item(device, gtk.FALSE)
|
||||
|
||||
device["nm.networks"].keys().sort(sort_networks)
|
||||
for name, network in device["nm.networks"].iteritems():
|
||||
try:
|
||||
if device["nm.active_network"] == name:
|
||||
active_network = gtk.TRUE
|
||||
else:
|
||||
active_network = gtk.FALSE
|
||||
except:
|
||||
active_network = gtk.FALSE
|
||||
self._add_network_menu_item(device,network,active_network)
|
||||
|
||||
else:
|
||||
if type == self._nm.WIRELESS_DEVICE:
|
||||
self._add_separator_item()
|
||||
self._add_wired_device_menu_item(device)
|
||||
|
||||
|
||||
self._add_other_wireless_item()
|
||||
# self._add_vpn_menu_item()
|
||||
|
||||
self._current_icon = self._get_icon(active_device)
|
||||
|
||||
self._current_icon.show()
|
||||
self._top_level_menu.show()
|
||||
|
||||
def _get_encrypted_icon(self):
|
||||
pb = gtk.gdk.pixbuf_new_from_file("/usr/share/icons/hicolor/16x16/stock/generic/stock_keyring.png")
|
||||
pb = pb.scale_simple(16,16,gtk.gdk.INTERP_NEAREST)
|
||||
_keyring = gtk.Image()
|
||||
_keyring.set_from_pixbuf(pb)
|
||||
return _keyring
|
||||
|
||||
def _get_vpn_icon(self):
|
||||
return self._get_encrypted_icon()
|
||||
|
||||
def _get_icon(self, active_device):
|
||||
|
||||
if active_device:
|
||||
if active_device["nm.type"] == self._nm.WIRED_DEVICE:
|
||||
pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/icons/nm-device-wired.png")
|
||||
pb = pb.scale_simple(16,16,gtk.gdk.INTERP_NEAREST)
|
||||
_wired_icon = gtk.Image()
|
||||
_wired_icon.set_from_pixbuf(pb)
|
||||
return _wired_icon
|
||||
elif active_device["nm.type"] == self._nm.WIRELESS_DEVICE:
|
||||
pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/icons/nm-device-wireless.png")
|
||||
pb = pb.scale_simple(16,16,gtk.gdk.INTERP_NEAREST)
|
||||
_wireless_icon = gtk.Image()
|
||||
_wireless_icon.set_from_pixbuf(pb)
|
||||
return _wireless_icon
|
||||
else:
|
||||
pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/icons/nm-device-wireless.png")
|
||||
pb = pb.scale_simple(16,16,gtk.gdk.INTERP_NEAREST)
|
||||
_nothing_icon = gtk.Image()
|
||||
_nothing_icon.set_from_pixbuf(pb)
|
||||
return _nothing_icon
|
||||
|
||||
|
||||
def _make_tray(self):
|
||||
self._tray = trayicon.TrayIcon("NetworkManager")
|
||||
|
||||
self._tooltips = gtk.Tooltips()
|
||||
tooltip = "Getting Network Information"
|
||||
self._tooltips.set_tip(self._menu,tooltip)
|
||||
|
||||
self._tray.add(self._menu_bar)
|
||||
self._tray.show()
|
||||
|
||||
def _make_menu(self):
|
||||
self._menu_bar = gtk.MenuBar()
|
||||
|
||||
self._top_level_menu = gtk.MenuItem()
|
||||
self._menu_bar.append(self._top_level_menu)
|
||||
|
||||
self._menu = gtk.Menu()
|
||||
self._top_level_menu.set_submenu(self._menu)
|
||||
|
||||
self._current_icon = self._get_icon(None)
|
||||
self._current_icon.show()
|
||||
|
||||
self._top_level_menu.add(self._current_icon)
|
||||
self._menu_bar.show()
|
||||
self._top_level_menu.show()
|
||||
self._menu.show()
|
||||
|
||||
self.__radio_group = gtk.RadioMenuItem()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
nt = network_tray()
|
||||
gtk.main()
|
|
@ -1,29 +0,0 @@
|
|||
/* -*- Mode: C; c-basic-offset: 4 -*- */
|
||||
%%
|
||||
headers
|
||||
#include <Python.h>
|
||||
|
||||
#include "pygobject.h"
|
||||
#include "eggtrayicon.h"
|
||||
%%
|
||||
modulename trayicon
|
||||
%%
|
||||
import gtk.Plug as PyGtkPlug_Type
|
||||
import gtk.gdk.Screen as PyGdkScreen_Type
|
||||
%%
|
||||
ignore-glob
|
||||
*_get_type
|
||||
%%
|
||||
override egg_tray_icon_send_message kwargs
|
||||
static PyObject*
|
||||
_wrap_egg_tray_icon_send_message(PyGObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
static char *kwlist[] = {"timeout", "message", NULL};
|
||||
int timeout, len, ret;
|
||||
char *message;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is#:TrayIcon.send_message", kwlist, &timeout, &message, &len))
|
||||
return NULL;
|
||||
ret = egg_tray_icon_send_message(EGG_TRAY_ICON(self->obj), timeout, message, len);
|
||||
return PyInt_FromLong(ret);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/* -*- Mode: C; c-basic-offset: 4 -*- */
|
||||
|
||||
/* include this first, before NO_IMPORT_PYGOBJECT is defined */
|
||||
#include <pygobject.h>
|
||||
|
||||
void trayicon_register_classes (PyObject *d);
|
||||
|
||||
extern PyMethodDef trayicon_functions[];
|
||||
|
||||
DL_EXPORT(void)
|
||||
inittrayicon(void)
|
||||
{
|
||||
PyObject *m, *d;
|
||||
|
||||
init_pygobject ();
|
||||
|
||||
m = Py_InitModule ("trayicon", trayicon_functions);
|
||||
d = PyModule_GetDict (m);
|
||||
|
||||
trayicon_register_classes (d);
|
||||
|
||||
if (PyErr_Occurred ()) {
|
||||
Py_FatalError ("can't initialise module trayicon :(");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue