void HandleCurrentItemChanged (object o, EventArgs args)
		{
			StopWatcher ();
			
			if (o is FileDockItem) {
				watcher = FileMonitor.File ((o as FileDockItem).OwnedFile, FileMonitorFlags.None, null);
				watcher.Changed += WatcherChanged;
			}
		}
		void StopWatcher ()
		{
			if (watcher != null) {
				watcher.Cancel ();
				watcher.Changed -= WatcherChanged;
				watcher.Dispose ();
				watcher = null;
			}
		}
 static void Changed_cb(IntPtr inst, IntPtr file, IntPtr other_file, int event_type)
 {
     try {
         FileMonitor __obj = GLib.Object.GetObject(inst, false) as FileMonitor;
         __obj.OnChanged(GLib.FileAdapter.GetObject(file, false), GLib.FileAdapter.GetObject(other_file, false), (GLib.FileMonitorEvent)event_type);
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, false);
     }
 }
        void MonitorDesktopFileDirs(GLib.File dir)
        {
            // build a list of all the subdirectories
            List <GLib.File> dirs = new List <GLib.File> ()
            {
                dir
            };

            try {
                dirs = dirs.Union(dir.SubDirs()).ToList();
            } catch {}

            foreach (GLib.File d in dirs)
            {
                GLib.FileMonitor mon = d.Monitor(GLib.FileMonitorFlags.None, null);
                mon.RateLimit = 2500;
                mon.Changed  += delegate(object o, GLib.ChangedArgs args) {
                    // bug in GIO#, calling args.File or args.OtherFile crashes hard
                    GLib.File file      = GLib.FileAdapter.GetObject((GLib.Object)args.Args [0]);
                    GLib.File otherFile = GLib.FileAdapter.GetObject((GLib.Object)args.Args [1]);

                    // according to GLib documentation, the change signal runs on the same
                    // thread that the monitor was created on.  Without running this part on a thread
                    // docky freezes up for about 500-800 ms while the .desktop files are parsed.
                    DockServices.System.RunOnThread(() => {
                        // if a new directory was created, make sure we watch that dir as well
                        if (file.QueryFileType(GLib.FileQueryInfoFlags.NofollowSymlinks, null) == GLib.FileType.Directory)
                        {
                            MonitorDesktopFileDirs(file);
                        }

                        // we only care about .desktop files
                        if (!file.Path.EndsWith(".desktop"))
                        {
                            return;
                        }

                        lock (update_lock) {
                            UpdateDesktopItemsList();
                            DesktopItemsChanged();
                            SaveDesktopItemsCache();
                        }

                        // Make sure to trigger event on main thread
                        DockServices.System.RunOnMainThread(() => {
                            if (DesktopFileChanged != null)
                            {
                                DesktopFileChanged(this, new DesktopFileChangedEventArgs(args.EventType, file, otherFile));
                            }
                        });
                    });
                };
            }
        }
 static bool Cancel_cb(IntPtr inst)
 {
     try {
         FileMonitor __obj = GLib.Object.GetObject(inst, false) as FileMonitor;
         bool        __result;
         __result = __obj.OnCancel();
         return(__result);
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, true);
         // NOTREACHED: above call does not return.
         throw e;
     }
 }
 void MonitorDesktopFileSystemCacheFiles()
 {
     foreach (GLib.File file in DesktopFileSystemCacheFiles)
     {
         GLib.FileMonitor mon = file.Monitor(GLib.FileMonitorFlags.None, null);
         mon.RateLimit = 2500;
         mon.Changed  += delegate(object o, GLib.ChangedArgs args) {
             if (args.EventType == GLib.FileMonitorEvent.ChangesDoneHint)
             {
                 DockServices.System.RunOnThread(() =>
                 {
                     lock (update_lock) {
                         ProcessAndMergeSystemCacheFile(file);
                         DesktopItemsChanged();
                     }
                 });
             }
         };
     }
 }
		private SystemManager ()
		{
			try {
				SystemBus = Bus.System.GetObject<IBus> ("org.freedesktop.DBus", new ObjectPath ("/org/freedesktop/DBus"));
				
				SystemBus.NameOwnerChanged += delegate(string name, string old_owner, string new_owner) {
					if (name != UPowerName && name != SystemdName && name != ConsoleKitName)
						return;

					Log<SystemManager>.Debug ("DBus services changed, reconnecting now");
					
					if (upower != null)
						upower = null;
					
					if (systemd != null)
						systemd = null;

					if (consolekit != null)
						consolekit = null;
					
					Initialize ();
					HandlePowerBusChanged ();
					HandleCapabilitiesChanged ();
				};
				
				Initialize ();
				
				// Set up file monitor to watch for reboot_required file
				GLib.File reboot_required_file = FileFactory.NewForPath ("/var/run/reboot-required");
				reboot_required_monitor = reboot_required_file.Monitor (FileMonitorFlags.None, null);
				reboot_required_monitor.RateLimit = 10000;
				reboot_required_monitor.Changed += HandleRebootRequired;
			} catch (Exception e) {
				Log<SessionManagerItem>.Error (e.Message);
			}
		}
		public BookmarksItemProvider ()
		{
			items = new List<AbstractDockItem> ();

			computer = new NonRemovableItem ("computer://", Catalog.GetString ("Computer"), "computer");
			home = FileDockItem.NewFromUri (string.Format ("file://{0}",
			    Environment.GetFolderPath (Environment.SpecialFolder.Personal)));
		
			UpdateItems ();
			
			watcher = FileMonitor.File (BookmarksFile, FileMonitorFlags.None, null);
			
			watcher.Changed += WatcherChanged;
		}