~elementary-apps/pantheon-files/trunk

« back to all changes in this revision

Viewing changes to src/gof-monitor.c

  • Committer: am.monkeyd at gmail
  • Date: 2010-11-08 13:17:02 UTC
  • Revision ID: am.monkeyd@gmail.com-20101108131702-rqeywh4r5pyx2ycz
let's roll

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
 
2
 
 
3
   nautilus-monitor.c: file and directory change monitoring for nautilus
 
4
 
 
5
   Copyright (C) 2000, 2001 Eazel, Inc.
 
6
  
 
7
   This program is free software; you can redistribute it and/or
 
8
   modify it under the terms of the GNU General Public License as
 
9
   published by the Free Software Foundation; either version 2 of the
 
10
   License, or (at your option) any later version.
 
11
  
 
12
   This program is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
   General Public License for more details.
 
16
  
 
17
   You should have received a copy of the GNU General Public
 
18
   License along with this program; if not, write to the
 
19
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
   Boston, MA 02111-1307, USA.
 
21
  
 
22
   Authors: Seth Nickell <seth@eazel.com>
 
23
            Darin Adler <darin@bentspoon.com>
 
24
            Alex Graveley <alex@ximian.com>
 
25
*/
 
26
 
 
27
#include <config.h>
 
28
#include "gof-monitor.h"
 
29
//#include "nautilus-file-changes-queue.h"
 
30
//#include "nautilus-file-utilities.h"
 
31
 
 
32
#include <gio/gio.h>
 
33
#include <stdio.h>
 
34
 
 
35
struct GOFMonitor {
 
36
        GFileMonitor *monitor;
 
37
};
 
38
 
 
39
static void
 
40
dir_changed (GFileMonitor* monitor,
 
41
             GFile *child,
 
42
             GFile *other_file,
 
43
             GFileMonitorEvent event_type,
 
44
             gpointer user_data)
 
45
{
 
46
        char *uri, *to_uri;
 
47
        
 
48
        uri = g_file_get_uri (child);
 
49
        to_uri = NULL;
 
50
        if (other_file) {
 
51
                to_uri = g_file_get_uri (other_file);
 
52
        }
 
53
 
 
54
        switch (event_type) {
 
55
        default:
 
56
        case G_FILE_MONITOR_EVENT_CHANGED:
 
57
                /* ignore */
 
58
                break;
 
59
        case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
 
60
        case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
 
61
                //nautilus_file_changes_queue_file_changed (child);
 
62
                printf ("file changed %s\n", uri);
 
63
                break;
 
64
        case G_FILE_MONITOR_EVENT_DELETED:
 
65
                //nautilus_file_changes_queue_file_removed (child);
 
66
                printf ("file deleted %s\n", uri);
 
67
                break;
 
68
        case G_FILE_MONITOR_EVENT_CREATED:
 
69
                //nautilus_file_changes_queue_file_added (child);
 
70
                printf ("file added %s\n", uri);
 
71
                break;
 
72
                
 
73
        case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
 
74
                /* TODO: Do something */
 
75
                break;
 
76
        case G_FILE_MONITOR_EVENT_UNMOUNTED:
 
77
                /* TODO: Do something */
 
78
                break;
 
79
        }
 
80
 
 
81
        g_free (uri);
 
82
        g_free (to_uri);
 
83
}
 
84
 
 
85
GOFMonitor *
 
86
gof_monitor_directory (GFile *location)
 
87
{
 
88
        GFileMonitor *dir_monitor;
 
89
        GOFMonitor *ret;
 
90
 
 
91
        dir_monitor = g_file_monitor_directory (location, G_FILE_MONITOR_WATCH_MOUNTS, NULL, NULL);
 
92
        /* TODO: implement GCancellable * */
 
93
        //dir_monitor = g_file_monitor_directory (location, G_FILE_MONITOR_SEND_MOVED, NULL, NULL);
 
94
        ret = g_new0 (GOFMonitor, 1);
 
95
        ret->monitor = dir_monitor;
 
96
 
 
97
        if (ret->monitor) {
 
98
                g_signal_connect (ret->monitor, "changed", (GCallback)dir_changed, ret);
 
99
        }
 
100
 
 
101
        return ret;
 
102
}
 
103
 
 
104
void 
 
105
gof_monitor_cancel (GOFMonitor *monitor)
 
106
{
 
107
        if (monitor->monitor != NULL) {
 
108
                g_signal_handlers_disconnect_by_func (monitor->monitor, dir_changed, monitor);
 
109
                g_file_monitor_cancel (monitor->monitor);
 
110
                g_object_unref (monitor->monitor);
 
111
        }
 
112
 
 
113
        g_free (monitor);
 
114
}