1
/* -*- mode: c; style: linux -*- */
4
* Copyright (C) 2001 Ximian, Inc.
6
* Written by Bradford Hovinen <hovinen@ximian.com>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2, or (at your option)
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31
#include <sys/types.h>
34
#include <glib/gi18n.h>
37
#include "capplet-util.h"
40
capplet_error_dialog (GtkWindow *parent, char const *msg, GError *err)
45
dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
46
GTK_DIALOG_DESTROY_WITH_PARENT,
51
g_signal_connect (G_OBJECT (dialog),
53
G_CALLBACK (gtk_widget_destroy), NULL);
54
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
55
gtk_widget_show (dialog);
66
* A quick utility routine to display help for capplets, and handle errors in a
70
capplet_help (GtkWindow *parent, char const *section)
76
g_return_if_fail (section != NULL);
79
screen = gdk_screen_get_default ();
81
screen = gtk_widget_get_screen (GTK_WIDGET (parent));
83
uri = g_strdup_printf ("ghelp:user-guide#%s", section);
85
if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error)) {
86
capplet_error_dialog (
88
_("There was an error displaying help: %s"),
100
* A quick utility routine to avoid the cut-n-paste of bogus code
101
* that caused several bugs.
104
capplet_set_icon (GtkWidget *window, char const *icon_file_name)
106
/* Make sure that every window gets an icon */
107
gtk_window_set_default_icon_name (icon_file_name);
108
gtk_window_set_icon_name (GTK_WINDOW (window), icon_file_name);
112
directory_delete_recursive (GFile *directory, GError **error)
114
GFileEnumerator *enumerator;
116
gboolean success = TRUE;
118
enumerator = g_file_enumerate_children (directory,
119
G_FILE_ATTRIBUTE_STANDARD_NAME ","
120
G_FILE_ATTRIBUTE_STANDARD_TYPE,
121
G_FILE_QUERY_INFO_NONE,
123
if (enumerator == NULL)
127
(info = g_file_enumerator_next_file (enumerator, NULL, NULL))) {
130
child = g_file_get_child (directory, g_file_info_get_name (info));
132
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
133
success = directory_delete_recursive (child, error);
135
success = g_file_delete (child, NULL, error);
137
g_object_unref (info);
139
g_file_enumerator_close (enumerator, NULL, NULL);
142
success = g_file_delete (directory, NULL, error);
148
* capplet_file_delete_recursive :
152
* A utility routine to delete files and/or directories,
153
* including non-empty directories.
156
capplet_file_delete_recursive (GFile *file, GError **error)
161
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
163
info = g_file_query_info (file,
164
G_FILE_ATTRIBUTE_STANDARD_TYPE,
165
G_FILE_QUERY_INFO_NONE,
170
type = g_file_info_get_file_type (info);
171
g_object_unref (info);
173
if (type == G_FILE_TYPE_DIRECTORY)
174
return directory_delete_recursive (file, error);
176
return g_file_delete (file, NULL, error);
180
capplet_init (GOptionContext *context,
187
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
188
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
189
textdomain (GETTEXT_PACKAGE);
193
#if GLIB_CHECK_VERSION (2, 12, 0)
194
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
196
g_option_context_add_group (context, gtk_get_option_group (TRUE));
198
if (!g_option_context_parse (context, argc, argv, &err)) {
199
g_printerr ("%s\n", err->message);
204
gtk_init (argc, argv);