2
* Copyright (C) 2009 Jens Georg <mail@jensge.org>.
4
* This file is part of Rygel.
6
* Rygel is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* Rygel 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 Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
public class Rygel.MediaExportRecursiveFileMonitor : Object {
26
private Cancellable cancellable;
27
HashMap<File, FileMonitor> monitors;
29
public MediaExportRecursiveFileMonitor (Cancellable? cancellable) {
30
this.cancellable = cancellable;
31
this.monitors = new HashMap<File, FileMonitor> (GLib.file_hash,
35
public void on_monitor_changed (File file,
37
FileMonitorEvent event_type) {
38
changed (file, other_file, event_type);
41
case FileMonitorEvent.CREATED:
44
case FileMonitorEvent.DELETED:
45
var file_monitor = this.monitors.get (file);
46
if (file_monitor != null) {
47
debug ("Directory %s gone, removing watch",
49
this.monitors.remove (file);
50
file_monitor.cancel ();
51
file_monitor.changed.disconnect (this.on_monitor_changed);
60
private void on_info_ready (Object? source, AsyncResult res) {
61
var file = (File) source;
64
var info = file.query_info_finish (res);
65
if (info.get_file_type () == FileType.DIRECTORY) {
66
var file_monitor = file.monitor_directory (
67
FileMonitorFlags.NONE,
69
this.monitors.set (file, file_monitor);
70
file_monitor.changed.connect (this.on_monitor_changed);
72
} catch (Error error) {
73
warning ("Failed to get file info for %s",
78
public void monitor (File file) {
79
file.query_info_async (FILE_ATTRIBUTE_STANDARD_TYPE,
80
FileQueryInfoFlags.NONE,
86
public void cancel () {
87
if (this.cancellable != null) {
88
this.cancellable.cancel ();
90
foreach (var monitor in this.monitors.get_values ()) {
96
public signal void changed (File file,
98
FileMonitorEvent event_type);