1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/* Copyright (C) 2017 Ernestas Kulik <ernestask@gnome.org>
*
* This file is part of Nautilus.
*
* Nautilus 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 of the License, or
* (at your option) any later version.
*
* Nautilus 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 Nautilus. If not, see <https://www.gnu.org/licenses/>.
*/
#include "nautilus-file-changes.h"
#include "nautilus-file.h"
#include "nautilus-signal-utilities.h"
typedef struct
{
NautilusFileChange type;
GFile *location;
} Change;
typedef struct
{
NautilusFileChange type;
GFile *location_from;
GFile *location_to;
} MoveChange;
static void move_change_free (MoveChange *change);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MoveChange, move_change_free)
static void
move_change_free (MoveChange *change)
{
g_clear_object (&change->location_to);
g_clear_object (&change->location_from);
g_free (change);
}
static void
emit_signal_for_change (Change *change)
{
g_autoptr (NautilusFile) file = NULL;
g_autoptr (NautilusFile) parent = NULL;
file = nautilus_file_new (change->location);
if (file == NULL)
{
return;
}
parent = nautilus_file_get_parent (file);
switch (change->type)
{
case NAUTILUS_FILE_CHANGE_RENAMED:
{
g_autoptr (MoveChange) move_change = NULL;
move_change = (MoveChange *) change;
nautilus_emit_signal_in_main_context_by_name (file,
NULL,
"renamed",
move_change->location_to);
if (parent == NULL)
{
break;
}
nautilus_emit_signal_in_main_context_by_name (parent,
NULL,
"children-changed");
}
break;
case NAUTILUS_FILE_CHANGE_MOVED:
{
}
break;
}
}
static void
notify_file_moved_or_renamed (GFile *from,
GFile *to,
gboolean move_is_rename)
{
MoveChange *change;
change = g_new0 (MoveChange, 1);
change->type = move_is_rename? NAUTILUS_FILE_CHANGE_RENAMED
: NAUTILUS_FILE_CHANGE_MOVED;
change->location_from = g_object_ref (from);
change->location_to = g_object_ref (to);
emit_signal_for_change ((Change *) change);
}
void
nautilus_notify_file_renamed (GFile *location,
GFile *new_location)
{
notify_file_moved_or_renamed (location, new_location, TRUE);
}
|