From eae1b63a1c9a6aa568ff55c32cd4b59894f3fb7c Mon Sep 17 00:00:00 2001 From: Robert Love Date: Thu, 20 Apr 2006 15:15:37 +0000 Subject: [PATCH] 2006-04-20 Robert Love * gnome/vpn-properties/nm-vpn-properties.c: Satisfy TODO: Ensure that only one copy of nm-vpn-properties is running at a time via the 'ol X selection trick. This prevents the user from opening two "VPN Connections" windows from within the applet, which leads to mass hysteria. * clipboard.c: New file, implementing simple X selection logic. * clipboard.h: New file. * gnome/vpn-properties/Makefile.am: Add clipboard.{c,h} git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1695 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 11 ++++ gnome/vpn-properties/Makefile.am | 6 +- gnome/vpn-properties/clipboard.c | 74 ++++++++++++++++++++++++ gnome/vpn-properties/clipboard.h | 6 ++ gnome/vpn-properties/nm-vpn-properties.c | 4 +- 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 gnome/vpn-properties/clipboard.c create mode 100644 gnome/vpn-properties/clipboard.h diff --git a/ChangeLog b/ChangeLog index 978d95c7a7..117afb50a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-04-20 Robert Love + + * gnome/vpn-properties/nm-vpn-properties.c: Satisfy TODO: Ensure that + only one copy of nm-vpn-properties is running at a time via the 'ol + X selection trick. This prevents the user from opening two "VPN + Connections" windows from within the applet, which leads to mass + hysteria. + * clipboard.c: New file, implementing simple X selection logic. + * clipboard.h: New file. + * gnome/vpn-properties/Makefile.am: Add clipboard.{c,h} + 2006-04-18 Nicolas Trangez * backends/NetworkManagerGentoo.c: Small cleanups and enhancements diff --git a/gnome/vpn-properties/Makefile.am b/gnome/vpn-properties/Makefile.am index d43a861129..a16474f524 100644 --- a/gnome/vpn-properties/Makefile.am +++ b/gnome/vpn-properties/Makefile.am @@ -7,8 +7,10 @@ nm_vpn_properties_HEADERS = \ nm-vpn-ui-interface.h nm_vpn_properties_SOURCES = \ - nm-vpn-properties.c \ - nm-vpn-ui-interface.h + nm-vpn-properties.c \ + clipboard.c \ + clipboard.h \ + nm-vpn-ui-interface.h gladedir = $(datadir)/gnome-vpn-properties glade_DATA = nm-vpn-properties.glade diff --git a/gnome/vpn-properties/clipboard.c b/gnome/vpn-properties/clipboard.c new file mode 100644 index 0000000000..0688d4696a --- /dev/null +++ b/gnome/vpn-properties/clipboard.c @@ -0,0 +1,74 @@ +/* + * src/clipboard.c - X clipboard hack to detect if daemon is running + * + * Elliot Lee + * + * (C) Copyright 1999 Red Hat, Inc. + * + * Licensed under the GNU GPL v2. See COPYING. + */ + +#include "config.h" + +#include +#include +#include + +#include "clipboard.h" + +/* + * clipboard_get_func - dummy get_func for gtk_clipboard_set_with_data () + */ +static void +clipboard_get_func (GtkClipboard *clipboard __attribute__((__unused__)), + GtkSelectionData *selection_data __attribute__((__unused__)), + guint info __attribute__((__unused__)), + gpointer user_data_or_owner __attribute__((__unused__))) +{ +} + +/* + * clipboard_clear_func - dummy clear_func for gtk_clipboard_set_with_data () + */ +static void +clipboard_clear_func (GtkClipboard *clipboard __attribute__((__unused__)), + gpointer user_data_or_owner __attribute__((__unused__))) +{ +} + +#define CLIPBOARD_NAME "VPN_CLIPBOARD_FOO" + +/* + * vpn_get_clipboard - try and get the CLIPBOARD_NAME clipboard + * + * Returns TRUE if successfully retrieved and FALSE otherwise. + */ +gboolean +vpn_get_clipboard (void) +{ + static const GtkTargetEntry targets[] = { {CLIPBOARD_NAME, 0, 0} }; + gboolean retval = FALSE; + GtkClipboard *clipboard; + Atom atom; + + atom = gdk_x11_get_xatom_by_name (CLIPBOARD_NAME); + + XGrabServer (GDK_DISPLAY ()); + + if (XGetSelectionOwner (GDK_DISPLAY (), atom) != None) + goto out; + + clipboard = gtk_clipboard_get (gdk_atom_intern (CLIPBOARD_NAME, FALSE)); + + if (gtk_clipboard_set_with_data (clipboard, targets, + G_N_ELEMENTS (targets), + clipboard_get_func, + clipboard_clear_func, NULL)) + retval = TRUE; + +out: + XUngrabServer (GDK_DISPLAY ()); + gdk_flush (); + + return retval; +} diff --git a/gnome/vpn-properties/clipboard.h b/gnome/vpn-properties/clipboard.h new file mode 100644 index 0000000000..3b07909797 --- /dev/null +++ b/gnome/vpn-properties/clipboard.h @@ -0,0 +1,6 @@ +#ifndef _VPN_PROPERTIES_CLIPBOARD_H +#define _VPN_PROPERTIES_CLIPBOARD_H + +gboolean vpn_get_clipboard (void); + +#endif /* _VPN_PROPERTIES_CLIPBOARD_H */ diff --git a/gnome/vpn-properties/nm-vpn-properties.c b/gnome/vpn-properties/nm-vpn-properties.c index 7711800169..e0aac4025e 100644 --- a/gnome/vpn-properties/nm-vpn-properties.c +++ b/gnome/vpn-properties/nm-vpn-properties.c @@ -43,6 +43,7 @@ #define NM_VPN_API_SUBJECT_TO_CHANGE #include "nm-vpn-ui-interface.h" +#include "clipboard.h" #define NM_GCONF_VPN_CONNECTIONS_PATH "/system/networking/vpn_connections" @@ -926,7 +927,8 @@ init_app (void) GtkWidget *toplevel; GDir *dir; - /* TODO: ensure only one copy of this program is running at any time */ + if (!vpn_get_clipboard ()) + return FALSE; gconf_client = gconf_client_get_default (); gconf_client_add_dir (gconf_client, NM_GCONF_VPN_CONNECTIONS_PATH,