Class FileMonitor
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
FileMonitor.FileMonitorImpl
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
Modifier and TypeClassDescriptionstatic class
FileMonitor.Builder<B extends FileMonitor.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theChangedCallback
callback.static class
static class
The FileMonitorImpl type represents a native instance of the abstract FileMonitor class.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionFileMonitor
(MemorySegment address) Create a FileMonitor proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected FileMonitor
asParent()
Returns this instance as if it were its parent type.static FileMonitor.Builder
<? extends FileMonitor.Builder> builder()
AFileMonitor.Builder
object constructs aFileMonitor
with the specified properties.boolean
cancel()
Cancels a file monitor.protected void
changed
(File file, File otherFile, FileMonitorEvent eventType) void
emitChanged
(File file, @Nullable File otherFile, FileMonitorEvent eventType) Emits the "changed" signal.void
emitEvent
(File child, File otherFile, FileMonitorEvent eventType) Emits theGFileMonitor
::changed signal if a change has taken place.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the FileMonitor classboolean
Returns whether the monitor is canceled.onChanged
(FileMonitor.ChangedCallback handler) Emitted whenfile
has been changed.void
setRateLimit
(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, 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.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
-
-
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 Javasuper
keyword, 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][g-main-context-push-thread-default] of the thread that the monitor was created in.
- Parameters:
child
- aGFile
.otherFile
- aGFile
.eventType
- a set ofGFileMonitorEvent
flags.
-
isCancelled
public boolean isCancelled()Returns whether the monitor is canceled.- Returns:
true
if monitor is canceled.false
otherwise.
-
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 whenfile
has been changed.If using
FileMonitorFlags.WATCH_MOVES
on a directory monitor, and the information is available (and if supported by the backend),eventType
may beFileMonitorEvent.RENAMED
,FileMonitorEvent.MOVED_IN
orFileMonitorEvent.MOVED_OUT
.In all cases
file
will be a child of the monitored directory. For renames,file
will be the old name andotherFile
is the new name. For "moved in" events,file
is the name of the file that appeared andotherFile
is the old name that it was moved from (in another directory). For "moved out" events,file
is the name of the file that used to be in this directory andotherFile
is the name of the file at its new location.It makes sense to treat
FileMonitorEvent.MOVED_IN
as equivalent toFileMonitorEvent.CREATED
andFileMonitorEvent.MOVED_OUT
as equivalent toFileMonitorEvent.DELETED
, with extra information.FileMonitorEvent.RENAMED
is equivalent to a delete/create pair. This is exactly how the events will be reported in the case that theFileMonitorFlags.WATCH_MOVES
flag is not in use.If using the deprecated flag
FileMonitorFlags.SEND_MOVED
flag andeventType
isFileMonitorEvent.MOVED
,file
will be set to aGFile
containing the old path, andotherFile
will be set to aGFile
containing the new path.In all the other cases,
otherFile
will 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)
. -
builder
AFileMonitor.Builder
object constructs aFileMonitor
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withFileMonitor.Builder.build()
.
-