/**
 * infinoted_directory_sync_new:
 * @directory: A #InfdDirectory.
 * @sync_directory: The directory on the file system to sync documents to.
 * @sync_interval: The interval in which to save documents to @sync_directory,
 * in seconds.
 *
 * Creates a new #InfinotedDirectorySync object which will save all documents
 * in @directory every @sync_interval into the file system at @sync_directory.
 * If @sync_directory does not exist it will be created.
 *
 * Returns: A new #InfinotedDirectorySync.
 */
InfinotedDirectorySync*
infinoted_directory_sync_new(InfdDirectory* directory,
                             const gchar* sync_directory,
                             unsigned int sync_interval)
{
  InfinotedDirectorySync* dsync;
  InfdDirectoryIter iter;

  dsync = g_slice_new(InfinotedDirectorySync);

  dsync->directory = directory;
  dsync->sync_directory = g_strdup(sync_directory);
  dsync->sync_interval = sync_interval;
  dsync->sessions = NULL;
  g_object_ref(directory);

  g_signal_connect_after(
    G_OBJECT(directory),
    "add-session",
    G_CALLBACK(infinoted_directory_sync_directory_add_session_cb),
    dsync
  );

  g_signal_connect_after(
    G_OBJECT(directory),
    "remove-session",
    G_CALLBACK(infinoted_directory_sync_directory_remove_session_cb),
    dsync
  );

  infd_directory_iter_get_root(directory, &iter);
  infinoted_directory_sync_walk_directory(dsync, &iter);
  return dsync;
}
Exemple #2
0
/**
 * infinoted_autosave_new:
 * @directory: A #InfdDirectory.
 * @autosave_interval: The interval in which to save documents in @directory,
 * in seconds.
 *
 * Creates a new #InfinotedAutosave object which will save all documents
 * in @directory every @autosave_interval seconds into the directory's
 * background storage.
 *
 * Returns: A new #InfinotedAutosave.
 */
InfinotedAutosave*
infinoted_autosave_new(InfdDirectory* directory,
                       unsigned int autosave_interval)
{
  InfinotedAutosave* autosave;
  InfdDirectoryIter iter;

  autosave = g_slice_new(InfinotedAutosave);

  autosave->directory = directory;
  autosave->autosave_interval = autosave_interval;
  autosave->sessions = NULL;
  g_object_ref(directory);

  g_signal_connect_after(
    G_OBJECT(directory),
    "add-session",
    G_CALLBACK(infinoted_autosave_directory_add_session_cb),
    autosave
  );

  g_signal_connect_after(
    G_OBJECT(directory),
    "remove-session",
    G_CALLBACK(infinoted_autosave_directory_remove_session_cb),
    autosave
  );

  infd_directory_iter_get_root(directory, &iter);
  infinoted_autosave_walk_directory(autosave, &iter);
  return autosave;
}