Class FileMonitor

All Implemented Interfaces:
Proxy
Direct Known Subclasses:
FileMonitor.FileMonitor$Impl

@Generated("org.javagi.JavaGI") public abstract class FileMonitor extends GObject

Monitors a file or directory for changes.

To obtain a GFileMonitor for a file or directory, use File.monitor(Set, Cancellable), File.monitorFile(Set, Cancellable), or File.monitorDirectory(Set, 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).

  • Constructor Details

    • FileMonitor

      public FileMonitor(MemorySegment address)
      Create a FileMonitor instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • FileMonitor

      public FileMonitor()
      Create a new FileMonitor.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the FileMonitor class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected FileMonitor asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • cancel

      public boolean cancel()
      Cancels a file monitor.
      Returns:
      always true
    • emitEvent

      public void emitEvent(File child, @Nullable File otherFile, FileMonitorEvent eventType)

      Emits the GFileMonitor::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 - a GFile.
      otherFile - a GFile, or null.
      eventType - a set of GFileMonitorEvent 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

      protected void changed(File file, File otherFile, FileMonitorEvent eventType)
    • onChanged

      Emitted when file 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 be FileMonitorEvent.RENAMED, FileMonitorEvent.MOVED_IN or FileMonitorEvent.MOVED_OUT.

      In all cases file will be a child of the monitored directory. For renames, file will be the old name and otherFile is the new name. For "moved in" events, file is the name of the file that appeared and otherFile 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 and otherFile is the name of the file at its new location.

      It makes sense to treat FileMonitorEvent.MOVED_IN as equivalent to FileMonitorEvent.CREATED and FileMonitorEvent.MOVED_OUT as equivalent to FileMonitorEvent.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 the FileMonitorFlags.WATCH_MOVES flag is not in use.

      If using the deprecated flag FileMonitorFlags.SEND_MOVED flag and eventType is FileMonitorEvent.MOVED, file will be set to a GFile containing the old path, and otherFile will be set to a GFile containing the new path.

      In all the other cases, otherFile will be set to NULL.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      public void emitChanged(@Nullable File file, @Nullable File otherFile, FileMonitorEvent eventType)
      Emits the "changed" signal. See onChanged(FileMonitor.ChangedCallback).