Ubuntu Pastebin

Paste from Andrea at Thu, 2 Jun 2016 09:51:14 +0000

Download as text
 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
Index: gnome-menus-3.13.3/libmenu/menu-monitor.c
===================================================================
--- gnome-menus-3.13.3.orig/libmenu/menu-monitor.c
+++ gnome-menus-3.13.3/libmenu/menu-monitor.c
@@ -52,6 +52,13 @@ typedef struct
   guint                 refcount;
 } MenuMonitorNotify;
 
+typedef struct
+{
+  MenuMonitor      *menu_monitor;
+  GFile            *child;
+  GFileMonitorEvent eflags;
+} MonitorCallbackInfo;
+
 static MenuMonitorNotify *menu_monitor_notify_ref   (MenuMonitorNotify *notify);
 static void               menu_monitor_notify_unref (MenuMonitorNotify *notify);
 
@@ -160,18 +167,25 @@ get_registry_key (const char *path,
 }
 
 static gboolean
-monitor_callback (GFileMonitor      *monitor,
-                  GFile             *child,
-                  GFile             *other_file,
-                  GFileMonitorEvent eflags,
-                  gpointer          user_data)
+monitor_callback_delayed (gpointer user_data)
 {
+  MonitorCallbackInfo  *info;
   MenuMonitorEventInfo *event_info;
   MenuMonitorEvent      event;
-  MenuMonitor          *menu_monitor = (MenuMonitor *) user_data;
+  MenuMonitor          *menu_monitor;
+
+  info = (MonitorCallbackInfo *) user_data;
+  menu_monitor = info->menu_monitor;
+
+  if (!menu_monitor)
+    {
+      g_object_unref (info->child);
+      g_free (info);
+      return TRUE;
+    }
 
   event = MENU_MONITOR_EVENT_INVALID;
-  switch (eflags)
+  switch (info->eflags)
     {
     case G_FILE_MONITOR_EVENT_CHANGED:
       event = MENU_MONITOR_EVENT_CHANGED;
@@ -183,17 +197,43 @@ monitor_callback (GFileMonitor      *mon
       event = MENU_MONITOR_EVENT_DELETED;
       break;
     default:
+      g_object_unref (info->child);
+      g_free (info);
       return TRUE;
     }
 
   event_info = g_new0 (MenuMonitorEventInfo, 1);
 
-  event_info->path    = g_file_get_path (child);
+  event_info->path    = g_file_get_path (info->child);
   event_info->event   = event;
   event_info->monitor = menu_monitor;
 
   menu_monitor_queue_event (event_info);
 
+  g_object_unref (info->child);
+  g_free (info);
+  return TRUE;
+}
+
+static gboolean
+monitor_callback (GFileMonitor      *monitor,
+                  GFile             *child,
+                  GFile             *other_file,
+                  GFileMonitorEvent eflags,
+                  gpointer          user_data)
+{
+  MenuMonitor         *menu_monitor;
+  MonitorCallbackInfo *info;
+
+  menu_monitor = (MenuMonitor *) user_data;
+
+  info = g_new0 (MonitorCallbackInfo, 1);
+  g_object_add_weak_pointer (menu_monitor, &info->menu_monitor);
+  info->child = g_object_ref (child);
+  info->eflags = eflags;
+
+  g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 2, monitor_callback_delayed, info, NULL);
+
   return TRUE;
 }
 
Download as text