1
/* vi:set et ai sw=2 sts=2 ts=2: */
3
3
* Copyright (c) 2005-2007 Benedikt Meurer <benny@xfce.org>
4
* Copyright (c) 2009-2010 Jannis Pohlmann <jannis@xfce.org>
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the Free
8
* Software Foundation; either version 2 of the License, or (at your option)
11
* This program is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
* You should have received a copy of the GNU General Public License along with
17
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18
* Place, Suite 330, Boston, MA 02111-1307 USA
4
* Copyright (c) 2009-2011 Jannis Pohlmann <jannis@xfce.org>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of
9
* the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public
17
* License along with this program; if not, write to the Free
18
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
21
22
#ifdef HAVE_CONFIG_H
1253
1254
gboolean called_from_job,
1254
1255
GError **error)
1256
GFile *previous_file;
1257
GFile *renamed_file;
1259
GFile *previous_file;
1260
GFile *renamed_file;
1260
1263
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
1261
1264
_thunar_return_val_if_fail (g_utf8_validate (name, -1, NULL), FALSE);
1262
1265
_thunar_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
1263
1266
_thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1265
/* remember the previous file */
1266
previous_file = g_object_ref (file->gfile);
1268
/* try to rename the file */
1269
renamed_file = g_file_set_display_name (file->gfile, name, cancellable, error);
1271
/* check if we succeeded */
1272
if (renamed_file != NULL)
1268
/* check if this file is a desktop entry */
1269
if (thunar_file_is_desktop_file (file))
1274
/* set the new file */
1275
file->gfile = renamed_file;
1277
/* reload file information */
1278
thunar_file_load (file, NULL, NULL);
1280
/* need to re-register the monitor handle for the new uri */
1281
watch_count = THUNAR_FILE_GET_WATCH_COUNT (file);
1282
if (G_LIKELY (watch_count > 0))
1284
/* drop the watch_count temporary */
1285
THUNAR_FILE_SET_WATCH_COUNT (file, 1);
1287
/* drop the previous handle (with the old path) */
1288
thunar_file_unwatch (file);
1290
/* register the new handle (with the new path) */
1291
thunar_file_watch (file);
1293
/* reset the watch count */
1294
THUNAR_FILE_SET_WATCH_COUNT (file, watch_count);
1297
G_LOCK (file_cache_mutex);
1299
/* drop the previous entry from the cache */
1300
g_hash_table_remove (file_cache, previous_file);
1302
/* drop the reference on the previous file */
1303
g_object_unref (previous_file);
1305
/* insert the new entry */
1306
g_hash_table_insert (file_cache, g_object_ref (file->gfile), file);
1308
G_UNLOCK (file_cache_mutex);
1310
if (!called_from_job)
1312
/* tell the associated folder that the file was renamed */
1313
thunarx_file_info_renamed (THUNARX_FILE_INFO (file));
1315
/* emit the file changed signal */
1316
thunar_file_changed (file);
1271
/* try to load the desktop entry into a key file */
1272
key_file = thunar_g_file_query_key_file (file->gfile, cancellable, &err);
1273
if (key_file == NULL)
1275
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
1276
_("Failed to parse the desktop file: %s"), err->message);
1281
/* change the Name field of the desktop entry */
1282
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1283
G_KEY_FILE_DESKTOP_KEY_NAME, name);
1285
/* write the changes back to the file */
1286
if (thunar_g_file_write_key_file (file->gfile, key_file, cancellable, &err))
1288
/* reload file information */
1289
thunar_file_load (file, NULL, NULL);
1291
if (!called_from_job)
1293
/* tell the associated folder that the file was renamed */
1294
thunarx_file_info_renamed (THUNARX_FILE_INFO (file));
1296
/* notify everybody that the file has changed */
1297
thunar_file_changed (file);
1300
/* release the key file and return with success */
1301
g_key_file_free (key_file);
1306
/* propagate the error message and return with failure */
1307
g_propagate_error (error, err);
1308
g_key_file_free (key_file);
1323
g_object_unref (previous_file);
1314
/* remember the previous file */
1315
previous_file = g_object_ref (file->gfile);
1317
/* try to rename the file */
1318
renamed_file = g_file_set_display_name (file->gfile, name, cancellable, error);
1320
/* check if we succeeded */
1321
if (renamed_file != NULL)
1323
/* set the new file */
1324
file->gfile = renamed_file;
1326
/* reload file information */
1327
thunar_file_load (file, NULL, NULL);
1329
/* need to re-register the monitor handle for the new uri */
1330
watch_count = THUNAR_FILE_GET_WATCH_COUNT (file);
1331
if (G_LIKELY (watch_count > 0))
1333
/* drop the watch_count temporary */
1334
THUNAR_FILE_SET_WATCH_COUNT (file, 1);
1336
/* drop the previous handle (with the old path) */
1337
thunar_file_unwatch (file);
1339
/* register the new handle (with the new path) */
1340
thunar_file_watch (file);
1342
/* reset the watch count */
1343
THUNAR_FILE_SET_WATCH_COUNT (file, watch_count);
1346
G_LOCK (file_cache_mutex);
1348
/* drop the previous entry from the cache */
1349
g_hash_table_remove (file_cache, previous_file);
1351
/* drop the reference on the previous file */
1352
g_object_unref (previous_file);
1354
/* insert the new entry */
1355
g_hash_table_insert (file_cache, g_object_ref (file->gfile), file);
1357
G_UNLOCK (file_cache_mutex);
1359
if (!called_from_job)
1361
/* tell the associated folder that the file was renamed */
1362
thunarx_file_info_renamed (THUNARX_FILE_INFO (file));
1364
/* emit the file changed signal */
1365
thunar_file_changed (file);
1372
g_object_unref (previous_file);