2006-03-06 Robert Love <rml@novell.com>

* gnome/applet/Makefile.am: Define AUTOSTARTDIR.
	* gnome/applet/applet.c: Add 'Remove' option to the right click menu,
	  to exit the applet.  As a sweet side-effect, idea courtesy of Chris
	  Rivera, detect if the applet was auto-started.  If so, ask the user
	  if he or she would like to stop automatically running the applet on
	  login.  If so, disable autostart.


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1561 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Robert Love 2006-03-07 20:29:20 +00:00 committed by Robert Love
parent 6be7176a14
commit 7bfae91c04
3 changed files with 121 additions and 24 deletions

View file

@ -1,3 +1,12 @@
2006-03-06 Robert Love <rml@novell.com>
* gnome/applet/Makefile.am: Define AUTOSTARTDIR.
* gnome/applet/applet.c: Add 'Remove' option to the right click menu,
to exit the applet. As a sweet side-effect, idea courtesy of Chris
Rivera, detect if the applet was auto-started. If so, ask the user
if he or she would like to stop automatically running the applet on
login. If so, disable autostart.
2006-03-06 Robert Love <rml@novell.com>
* NetworkManager.pc.in: Provide an -I to the NetworkManager include

View file

@ -6,28 +6,29 @@ INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils -I${top_srcdir}/include -I${top
bin_PROGRAMS = nm-applet
nm_applet_CPPFLAGS = \
$(DBUS_CFLAGS) \
$(GTHREAD_CFLAGS) \
$(HAL_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
$(GLADE_CFLAGS) \
$(GTK_CFLAGS) \
$(GCONF_CFLAGS) \
$(LIBGNOMEUI_CFLAGS) \
$(PANEL_APPLET_CFLAGS) \
$(GNOME_KEYRING_CFLAGS) \
-DICONDIR=\""$(datadir)/pixmaps"\" \
-DGLADEDIR=\""$(gladedir)"\" \
-DBINDIR=\""$(bindir)"\" \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
nm_applet_CPPFLAGS = \
$(DBUS_CFLAGS) \
$(GTHREAD_CFLAGS) \
$(HAL_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
$(GLADE_CFLAGS) \
$(GTK_CFLAGS) \
$(GCONF_CFLAGS) \
$(LIBGNOMEUI_CFLAGS) \
$(PANEL_APPLET_CFLAGS) \
$(GNOME_KEYRING_CFLAGS) \
-DICONDIR=\""$(datadir)/pixmaps"\" \
-DGLADEDIR=\""$(gladedir)"\" \
-DBINDIR=\""$(bindir)"\" \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
-DAUTOSTARTDIR=\""$(datadir)/gnome/autostart"\" \
-DVPN_NAME_FILES_DIR=\""$(sysconfdir)/NetworkManager/VPN"\" \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DG_DISABLE_DEPRECATED \
-DGDK_DISABLE_DEPRECATED \
-DGNOME_DISABLE_DEPRECATED \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DG_DISABLE_DEPRECATED \
-DGDK_DISABLE_DEPRECATED \
-DGNOME_DISABLE_DEPRECATED \
-DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
-DVERSION=\"$(VERSION)\" \
-DVERSION=\"$(VERSION)\" \
$(NULL)
if WITH_NOTIFY

View file

@ -78,11 +78,11 @@
static GObject * nma_constructor (GType type, guint n_props, GObjectConstructParam *construct_props);
static gboolean nma_icons_init (NMApplet *applet);
static void nma_icons_free (NMApplet *applet);
static void nma_about_cb (NMApplet *applet);
static void nma_context_menu_update (NMApplet *applet);
static GtkWidget * nma_get_instance (NMApplet *applet);
static void nma_update_state (NMApplet *applet);
static void nma_dropdown_menu_deactivate_cb (GtkWidget *menu, NMApplet *applet);
static void nma_destroy (NMApplet *applet);
static GType nma_get_type (void); /* for G_DEFINE_TYPE */
G_DEFINE_TYPE(NMApplet, nma, EGG_TYPE_TRAY_ICON)
@ -291,7 +291,7 @@ static void about_dialog_activate_link_cb (GtkAboutDialog *about,
gnome_url_show (url, NULL);
}
static void nma_about_cb (NMApplet *applet)
static void nma_about_cb (GtkMenuItem *mi, NMApplet *applet)
{
static const gchar *authors[] =
{
@ -373,6 +373,87 @@ static void nma_about_cb (NMApplet *applet)
#endif
}
#define AUTOSTART_ENABLE_STR "X-GNOME-Autostart-enabled=true"
#define AUTOSTART_ENABLE_STR_LEN 30
#define AUTOSTART_DISABLE_STR "X-GNOME-Autostart-enabled=false"
#define AUTOSTART_DISABLE_STR_LEN 31
static void G_GNUC_NORETURN nma_remove_cb (GtkMenuItem *mi, NMApplet *applet)
{
char *src;
char *dir;
char *file;
const char *sub;
gsize src_len;
GtkWidget *dialog;
/*
* Give the user the option of disabling autostart, if it is enabled. Autostart is in
* use if there is an nm-applet.desktop in either the system wide or the per-user
* autostart directory and it has "X-GNOME-Autostart-enabled" set to "true". To disable
* autostart, we (re)write the autostart file to the per-user location, with the
* autostart option set to "false".
*/
dir = g_strdup_printf ("%s/.config/autostart", g_get_home_dir ());
file = g_strdup_printf ("%s/nm-applet.desktop", dir);
/*
* Figure out what our source file is. Try to use the user's nm-applet.desktop, first.
* If it does not exist, we use the system-wide autostart file.
*/
if (!g_file_get_contents (file, &src, &src_len, NULL))
if (!g_file_get_contents (AUTOSTARTDIR"/nm-applet.desktop", &src, &src_len, NULL))
goto out_free_file;
/* If autostart is explicitly disabled or not explicitly enabled, we are done. */
if (strstr (src, AUTOSTART_DISABLE_STR))
goto out_free_src;
sub = strstr (src, AUTOSTART_ENABLE_STR);
if (!sub)
goto out_free_src;
dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
"<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
_("Stop automatically running the networking applet?"),
_("The networking applet will now terminate, but will automatically launch the next time you login. Would you like to stop automatically running the networking applet on login?"));
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
{
char *dst;
gsize dst_len;
gsize sub_len;
src_len += 1;
dst_len = src_len + 1;
dst = g_malloc (dst_len);
sub_len = sub - src;
/* memcpy the first chunk, write in our updated string, and memcpy the remaining bytes */
memcpy (dst, src, sub_len);
g_strlcpy (dst + sub_len, AUTOSTART_DISABLE_STR, dst_len - sub_len);
memcpy (dst + sub_len + AUTOSTART_DISABLE_STR_LEN,
sub + AUTOSTART_ENABLE_STR_LEN,
src_len - sub_len - AUTOSTART_ENABLE_STR_LEN);
dst[dst_len-1] = '\0';
g_mkdir_with_parents (dir, 0750);
g_file_set_contents (file, dst, dst_len, NULL);
g_free (dst);
}
gtk_widget_destroy (dialog);
out_free_src:
g_free (src);
out_free_file:
g_free (file);
g_free (dir);
nma_destroy (applet);
}
#ifndef ENABLE_NOTIFY
/*
* nma_show_vpn_failure_dialog
@ -2202,6 +2283,13 @@ static GtkWidget *nma_context_menu_create (NMApplet *applet)
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
/* Quit */
menu_item = gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (nma_remove_cb), applet);
image = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show_all (menu);
return menu;
@ -2440,8 +2528,7 @@ static void nma_gconf_vpn_connections_notify_callback (GConfClient *client, guin
* Destroy the applet and clean up its data
*
*/
static void G_GNUC_NORETURN
nma_destroy (NMApplet *applet, gpointer user_data)
static void G_GNUC_NORETURN nma_destroy (NMApplet *applet)
{
if (applet->dropdown_menu)
nma_dropdown_menu_clear (applet->dropdown_menu);