Set Nautilus-Actions as being the actual official product name
[nautilus-actions.git] / src / io-desktop / nadp-utils.c
blob68465b6d255aa3b47f91f614c16382eb8d8788c8
1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
24 * Authors:
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include <errno.h>
36 #include <gio/gio.h>
37 #include <glib/gstdio.h>
38 #include <string.h>
39 #include <uuid/uuid.h>
41 #include <api/na-core-utils.h>
43 #include "nadp-desktop-provider.h"
44 #include "nadp-utils.h"
46 /**
47 * nadp_utils_gslist_remove_from:
48 * @list: the #GSList from which remove the @string.
49 * @string: the string to be removed.
51 * Removes a @string from a string list, then frees the removed @string.
53 GSList *
54 nadp_utils_gslist_remove_from( GSList *list, const gchar *string )
56 GSList *is;
58 for( is = list ; is ; is = is->next ){
59 const gchar *istr = ( const gchar * ) is->data;
60 if( !na_core_utils_str_collate( string, istr )){
61 g_free( is->data );
62 list = g_slist_delete_link( list, is );
63 break;
67 return( list );
70 /**
73 gboolean
74 nadp_utils_uri_delete( const gchar *uri )
76 gboolean deleted;
77 gchar *scheme;
78 gchar *path;
80 deleted = FALSE;
81 scheme = g_uri_parse_scheme( uri );
83 if( !strcmp( scheme, "file" )){
84 path = g_filename_from_uri( uri, NULL, NULL );
86 if( path ){
87 deleted = na_core_utils_file_delete( path );
88 g_free( path );
92 g_free( scheme );
94 return( deleted );
97 /**
98 * nadp_utils_uri_is_writable:
99 * @uri: the URI of the file to be tested.
101 * Returns: %TRUE if the file is writable, %FALSE else.
103 * Please note that this type of test is subject to race conditions,
104 * as the file may become unwritable after a successfull test,
105 * but before the caller has been able to actually write into it.
107 * There is no "super-test". Just try...
109 gboolean
110 nadp_utils_uri_is_writable( const gchar *uri )
112 static const gchar *thisfn = "nadp_utils_uri_is_writable";
113 GFile *file;
114 GError *error = NULL;
115 GFileInfo *info;
116 gboolean writable;
118 if( !uri || !g_utf8_strlen( uri, -1 )){
119 return( FALSE );
122 file = g_file_new_for_uri( uri );
123 info = g_file_query_info( file,
124 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," G_FILE_ATTRIBUTE_STANDARD_TYPE,
125 G_FILE_QUERY_INFO_NONE, NULL, &error );
127 if( error ){
128 g_warning( "%s: g_file_query_info error: %s", thisfn, error->message );
129 g_error_free( error );
130 g_object_unref( file );
131 return( FALSE );
134 writable = g_file_info_get_attribute_boolean( info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE );
135 if( !writable ){
136 g_debug( "%s: %s is not writable", thisfn, uri );
139 g_object_unref( info );
141 return( writable );