1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set expandtab ts=4 shiftwidth=4: */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
6 * Copyright (C) 2007 Sebastian Dröge.
7 * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General
21 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 * Authors: Alexander Larsson <alexl@redhat.com>
24 * John McCutchan <john@johnmccutchan.com>
25 * Sebastian Dröge <slomo@circular-chaos.org>
26 * Lin Ma <lin.ma@sun.com>
31 #include "gfendirectorymonitor.h"
32 #include <gio/giomodule.h>
34 #include "fen-helper.h"
36 struct _GFenDirectoryMonitor
38 GLocalDirectoryMonitor parent_instance;
42 static gboolean g_fen_directory_monitor_cancel (GFileMonitor* monitor);
44 #define g_fen_directory_monitor_get_type _g_fen_directory_monitor_get_type
45 G_DEFINE_TYPE_WITH_CODE (GFenDirectoryMonitor, g_fen_directory_monitor, G_TYPE_LOCAL_DIRECTORY_MONITOR,
46 g_io_extension_point_implement (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME,
52 g_fen_directory_monitor_finalize (GObject *object)
54 GFenDirectoryMonitor *self = G_FEN_DIRECTORY_MONITOR (object);
57 fen_remove (G_LOCAL_DIRECTORY_MONITOR (self)->dirname, self, TRUE);
58 self->enabled = FALSE;
61 if (G_OBJECT_CLASS (g_fen_directory_monitor_parent_class)->finalize)
62 (*G_OBJECT_CLASS (g_fen_directory_monitor_parent_class)->finalize) (object);
66 g_fen_directory_monitor_constructor (GType type,
67 guint n_construct_properties,
68 GObjectConstructParam *construct_properties)
71 GFenDirectoryMonitorClass *klass;
72 GObjectClass *parent_class;
73 GFenDirectoryMonitor *self;
74 const gchar *dirname = NULL;
76 klass = G_FEN_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_FEN_DIRECTORY_MONITOR));
77 parent_class = g_fen_directory_monitor_parent_class;
78 obj = parent_class->constructor (type,
79 n_construct_properties,
80 construct_properties);
82 self = G_FEN_DIRECTORY_MONITOR (obj);
84 dirname = G_LOCAL_DIRECTORY_MONITOR (self)->dirname;
85 g_assert (dirname != NULL);
87 /* Will never fail as is_supported() should be called before instanciating
90 g_assert_not_reached ();
92 /* FIXME: what to do about errors here? we can't return NULL or another
93 * kind of error and an assertion is probably too hard */
94 fen_add (dirname, self, TRUE);
101 g_fen_directory_monitor_is_supported (void)
107 g_fen_directory_monitor_class_init (GFenDirectoryMonitorClass* klass)
109 GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
110 GFileMonitorClass *directory_monitor_class = G_FILE_MONITOR_CLASS (klass);
111 GLocalDirectoryMonitorClass *local_directory_monitor_class = G_LOCAL_DIRECTORY_MONITOR_CLASS (klass);
113 gobject_class->finalize = g_fen_directory_monitor_finalize;
114 gobject_class->constructor = g_fen_directory_monitor_constructor;
115 directory_monitor_class->cancel = g_fen_directory_monitor_cancel;
117 local_directory_monitor_class->mount_notify = TRUE;
118 local_directory_monitor_class->is_supported = g_fen_directory_monitor_is_supported;
122 g_fen_directory_monitor_init (GFenDirectoryMonitor* monitor)
127 g_fen_directory_monitor_cancel (GFileMonitor* monitor)
129 GFenDirectoryMonitor *self = G_FEN_DIRECTORY_MONITOR (monitor);
132 fen_remove (G_LOCAL_DIRECTORY_MONITOR (self)->dirname, self, TRUE);
133 self->enabled = FALSE;
136 if (G_FILE_MONITOR_CLASS (g_fen_directory_monitor_parent_class)->cancel)
137 (*G_FILE_MONITOR_CLASS (g_fen_directory_monitor_parent_class)->cancel) (monitor);