Class FileMonitor
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
FileMonitor.FileMonitor$Impl
To obtain a GFileMonitor for a file or directory, use
File.monitor(java.util.Set<org.gnome.gio.FileMonitorFlags>, org.gnome.gio.Cancellable), File.monitorFile(java.util.Set<org.gnome.gio.FileMonitorFlags>, org.gnome.gio.Cancellable), or
File.monitorDirectory(java.util.Set<org.gnome.gio.FileMonitorFlags>, org.gnome.gio.Cancellable).
To get informed about changes to the file or directory you are
monitoring, connect to the Gio.FileMonitor::changed signal. The
signal will be emitted in the thread-default main context (see
MainContext.pushThreadDefault()) of the thread that the monitor
was created in (though if the global default main context is blocked, this
may cause notifications to be blocked even if the thread-default
context is still running).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFileMonitor.Builder<B extends FileMonitor.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theChangedCallbackcallback.static classThe FileMonitor$Impl type represents a native instance of the abstract FileMonitor class.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new FileMonitor.FileMonitor(MemorySegment address) Create a FileMonitor proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected FileMonitorasParent()Returns this instance as if it were its parent type.booleancancel()Cancels a file monitor.protected voidchanged(File file, File otherFile, FileMonitorEvent eventType) voidemitChanged(@Nullable File file, @Nullable File otherFile, FileMonitorEvent eventType) Emits the "changed" signal.voidemitEvent(File child, @Nullable File otherFile, FileMonitorEvent eventType) Emits theGFileMonitor::changed signal if a change has taken place.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the FileMonitor classbooleanReturns whether the monitor is canceled.onChanged(FileMonitor.ChangedCallback handler) Emitted whenfilehas been changed.voidsetRateLimit(int limitMsecs) Sets the rate limit to which the this FileMonitor will report consecutive change events to the same file.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, builder, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
FileMonitor
Create a FileMonitor proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
FileMonitor
public FileMonitor()Creates a new FileMonitor.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
cancel
public boolean cancel()Cancels a file monitor.- Returns:
- always
true
-
emitEvent
Emits theGFileMonitor::changed signal if a change has taken place. Should be called from file monitor implementations only.Implementations are responsible to call this method from the thread-default main context (see
MainContext.pushThreadDefault()) of the thread that the monitor was created in.- Parameters:
child- aGFile.otherFile- aGFile, ornull.eventType- a set ofGFileMonitorEventflags.
-
isCancelled
public boolean isCancelled()Returns whether the monitor is canceled.- Returns:
trueif monitor is canceled.falseotherwise.
-
setRateLimit
public void setRateLimit(int limitMsecs) Sets the rate limit to which the this FileMonitor will report consecutive change events to the same file.- Parameters:
limitMsecs- a non-negative integer with the limit in milliseconds to poll for changes
-
changed
-
onChanged
Emitted whenfilehas been changed.If using
FileMonitorFlags.WATCH_MOVESon a directory monitor, and the information is available (and if supported by the backend),eventTypemay beFileMonitorEvent.RENAMED,FileMonitorEvent.MOVED_INorFileMonitorEvent.MOVED_OUT.In all cases
filewill be a child of the monitored directory. For renames,filewill be the old name andotherFileis the new name. For "moved in" events,fileis the name of the file that appeared andotherFileis the old name that it was moved from (in another directory). For "moved out" events,fileis the name of the file that used to be in this directory andotherFileis the name of the file at its new location.It makes sense to treat
FileMonitorEvent.MOVED_INas equivalent toFileMonitorEvent.CREATEDandFileMonitorEvent.MOVED_OUTas equivalent toFileMonitorEvent.DELETED, with extra information.FileMonitorEvent.RENAMEDis equivalent to a delete/create pair. This is exactly how the events will be reported in the case that theFileMonitorFlags.WATCH_MOVESflag is not in use.If using the deprecated flag
FileMonitorFlags.SEND_MOVEDflag andeventTypeisFileMonitorEvent.MOVED,filewill be set to aGFilecontaining the old path, andotherFilewill be set to aGFilecontaining the new path.In all the other cases,
otherFilewill be set toNULL.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChanged
Emits the "changed" signal. SeeonChanged(org.gnome.gio.FileMonitor.ChangedCallback).
-