2001-07-13 18:51:28 +00:00
|
|
|
/* -*- mode: c; style: linux -*- */
|
|
|
|
|
|
|
|
/* capplet-util.c
|
|
|
|
* Copyright (C) 2001 Ximian, Inc.
|
|
|
|
*
|
|
|
|
* Written by Bradford Hovinen <hovinen@ximian.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-07-17 18:58:02 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2001-07-25 03:10:58 +00:00
|
|
|
/* For stat */
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2008-10-24 19:42:26 +00:00
|
|
|
#include <glib/gi18n.h>
|
2008-10-24 23:22:41 +00:00
|
|
|
#include <stdlib.h>
|
2001-07-25 03:10:58 +00:00
|
|
|
|
2001-07-13 18:51:28 +00:00
|
|
|
#include "capplet-util.h"
|
|
|
|
|
|
|
|
static void
|
2002-06-18 18:55:14 +00:00
|
|
|
capplet_error_dialog (GtkWindow *parent, char const *msg, GError *err)
|
|
|
|
{
|
|
|
|
if (err != NULL) {
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
msg, err->message);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (dialog),
|
|
|
|
"response",
|
|
|
|
G_CALLBACK (gtk_widget_destroy), NULL);
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
g_error_free (err);
|
|
|
|
}
|
|
|
|
}
|
2002-06-27 18:30:15 +00:00
|
|
|
|
2002-05-27 02:53:33 +00:00
|
|
|
/**
|
|
|
|
* capplet_help :
|
|
|
|
* @parent :
|
|
|
|
* @helpfile :
|
|
|
|
* @section :
|
|
|
|
*
|
|
|
|
* A quick utility routine to display help for capplets, and handle errors in a
|
|
|
|
* Havoc happy way.
|
|
|
|
**/
|
|
|
|
void
|
2008-10-24 19:42:26 +00:00
|
|
|
capplet_help (GtkWindow *parent, char const *section)
|
2002-05-27 02:53:33 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2008-10-24 19:42:26 +00:00
|
|
|
char *uri;
|
|
|
|
GdkScreen *screen;
|
2002-05-27 02:53:33 +00:00
|
|
|
|
|
|
|
g_return_if_fail (section != NULL);
|
|
|
|
|
2008-10-24 19:42:26 +00:00
|
|
|
if (!parent)
|
2008-10-26 10:26:11 +00:00
|
|
|
screen = gdk_screen_get_default ();
|
2008-10-24 19:42:26 +00:00
|
|
|
else
|
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (parent));
|
2008-10-26 10:26:11 +00:00
|
|
|
|
2008-10-24 19:42:26 +00:00
|
|
|
uri = g_strdup_printf ("ghelp:user-guide#%s", section);
|
2008-10-26 10:26:11 +00:00
|
|
|
|
|
|
|
if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error)) {
|
2008-10-24 19:42:26 +00:00
|
|
|
capplet_error_dialog (
|
2008-10-26 10:26:11 +00:00
|
|
|
parent,
|
2002-05-27 02:53:33 +00:00
|
|
|
_("There was an error displaying help: %s"),
|
2002-06-18 18:55:14 +00:00
|
|
|
error);
|
2008-10-24 19:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (uri);
|
2002-05-27 02:53:33 +00:00
|
|
|
}
|
2002-06-27 18:30:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* capplet_set_icon :
|
|
|
|
* @window :
|
|
|
|
* @file_name :
|
|
|
|
*
|
|
|
|
* A quick utility routine to avoid the cut-n-paste of bogus code
|
|
|
|
* that caused several bugs.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
capplet_set_icon (GtkWidget *window, char const *icon_file_name)
|
|
|
|
{
|
2007-06-26 23:29:58 +00:00
|
|
|
/* Make sure that every window gets an icon */
|
|
|
|
gtk_window_set_default_icon_name (icon_file_name);
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (window), icon_file_name);
|
2002-06-27 18:30:15 +00:00
|
|
|
}
|
2008-07-27 23:32:35 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
directory_delete_recursive (GFile *directory, GError **error)
|
|
|
|
{
|
|
|
|
GFileEnumerator *enumerator;
|
|
|
|
GFileInfo *info;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
enumerator = g_file_enumerate_children (directory,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_NAME ","
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, error);
|
|
|
|
if (enumerator == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (success &&
|
|
|
|
(info = g_file_enumerator_next_file (enumerator, NULL, NULL))) {
|
|
|
|
GFile *child;
|
|
|
|
|
|
|
|
child = g_file_get_child (directory, g_file_info_get_name (info));
|
|
|
|
|
|
|
|
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
|
|
|
|
success = directory_delete_recursive (child, error);
|
2008-11-27 19:52:54 +00:00
|
|
|
} else {
|
|
|
|
success = g_file_delete (child, NULL, error);
|
2008-07-27 23:32:35 +00:00
|
|
|
}
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
g_file_enumerator_close (enumerator, NULL, NULL);
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
success = g_file_delete (directory, NULL, error);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* capplet_file_delete_recursive :
|
|
|
|
* @file :
|
|
|
|
* @error :
|
|
|
|
*
|
|
|
|
* A utility routine to delete files and/or directories,
|
|
|
|
* including non-empty directories.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
capplet_file_delete_recursive (GFile *file, GError **error)
|
|
|
|
{
|
|
|
|
GFileInfo *info;
|
|
|
|
GFileType type;
|
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
info = g_file_query_info (file,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, error);
|
|
|
|
if (info == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
type = g_file_info_get_file_type (info);
|
|
|
|
g_object_unref (info);
|
|
|
|
|
|
|
|
if (type == G_FILE_TYPE_DIRECTORY)
|
|
|
|
return directory_delete_recursive (file, error);
|
|
|
|
else
|
|
|
|
return g_file_delete (file, NULL, error);
|
|
|
|
}
|
|
|
|
|
2008-10-24 22:22:58 +00:00
|
|
|
void
|
|
|
|
capplet_init (GOptionContext *context,
|
|
|
|
int *argc,
|
|
|
|
char ***argv)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
2008-10-26 10:26:11 +00:00
|
|
|
|
2008-10-24 22:22:58 +00:00
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain (GETTEXT_PACKAGE);
|
|
|
|
#endif
|
2008-10-26 10:26:11 +00:00
|
|
|
|
2008-10-24 22:39:00 +00:00
|
|
|
if (context) {
|
2008-10-24 22:29:43 +00:00
|
|
|
#if GLIB_CHECK_VERSION (2, 12, 0)
|
2008-10-24 22:39:00 +00:00
|
|
|
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
|
2008-10-24 22:29:43 +00:00
|
|
|
#endif
|
2008-10-24 22:22:58 +00:00
|
|
|
g_option_context_add_group (context, gtk_get_option_group (TRUE));
|
2008-10-26 10:26:11 +00:00
|
|
|
|
2008-10-24 22:22:58 +00:00
|
|
|
if (!g_option_context_parse (context, argc, argv, &err)) {
|
|
|
|
g_printerr ("%s\n", err->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
2008-10-26 10:26:11 +00:00
|
|
|
|
2008-10-24 22:22:58 +00:00
|
|
|
gtk_init (argc, argv);
|
|
|
|
}
|