Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
folder_survey.c File Reference
#include "common/folder_survey.h"
#include "common/darktable.h"
#include "common/datetime.h"
#include "common/file_location.h"
#include "common/imageio.h"
#include "control/conf.h"
#include "control/control.h"
#include "control/jobs.h"
#include "control/jobs/import_jobs.h"
#include "gui/gtk.h"
#include "views/view.h"
#include <gio/gio.h>
+ Include dependency graph for folder_survey.c:

Go to the source code of this file.

Data Structures

struct  dt_folder_survey_entry_t
 
struct  dt_folder_survey_observation_t
 
struct  dt_folder_survey_job_t
 
struct  dt_folder_survey_t
 

Macros

#define DT_FOLDER_SURVEY_STATE_FILE   "folder-survey-state.ini"
 

Typedefs

typedef enum dt_folder_survey_file_state_t dt_folder_survey_file_state_t
 
typedef struct dt_folder_survey_entry_t dt_folder_survey_entry_t
 
typedef struct dt_folder_survey_observation_t dt_folder_survey_observation_t
 
typedef struct dt_folder_survey_job_t dt_folder_survey_job_t
 
typedef struct dt_folder_survey_t dt_folder_survey_t
 

Enumerations

enum  dt_folder_survey_file_state_t {
  DT_FOLDER_SURVEY_FILE_PENDING = 0 ,
  DT_FOLDER_SURVEY_FILE_QUEUED ,
  DT_FOLDER_SURVEY_FILE_DONE
}
 

Functions

static int _folder_survey_save_locked ()
 Persist the complete survey baseline while the survey lock is held.
 
static int _folder_survey_load_locked ()
 Load the previous file list and convert interrupted imports to retries.
 
static int _folder_survey_collect (const char *folder, GHashTable *observed)
 Recursively collect supported images and their stability metadata.
 
static GList * _folder_survey_styles_for_import ()
 Read the ordered auto-apply style list from conf.
 
static void _folder_survey_imported (const char *source, const gboolean success, gpointer user_data)
 Update one persisted entry when its asynchronous import completes.
 
static int32_t _folder_survey_job_run (dt_job_t *job)
 Compare the current directory contents with the prior survey loop.
 
static void _folder_survey_job_cleanup (void *data)
 Release one scan job and allow the next periodic scan to start.
 
static gboolean _folder_survey_scan (gpointer user_data)
 Queue one background scan without overlapping the previous scan.
 
static gboolean _folder_survey_scan_once (gpointer user_data)
 Run the immediate post-configuration scan only once.
 
static void _folder_survey_reschedule ()
 Recreate the periodic source after a frequency or state change.
 
static void _folder_survey_deactivate ()
 Stop periodic scans without discarding the persisted comparison state.
 
char * dt_folder_survey_destination_preview ()
 Build the expanded destination path of a sample file from the current configuration, for GUI preview purposes.
 
gboolean dt_folder_survey_can_start (const char **message)
 Check, without any side effect, whether the persisted configuration has everything dt_folder_survey_start() requires to succeed.
 
void dt_folder_survey_init ()
 Initialize the folder survey state from the persisted configuration.
 
static void _folder_survey_offer_pending_import ()
 Ask whether images already sitting in the source folder should be imported right away, instead of being silently absorbed into the baseline.
 
int dt_folder_survey_start ()
 Validate the persisted configuration and start monitoring.
 
void dt_folder_survey_halt ()
 User-requested stop: end monitoring and clear the persisted session marker so the next application start does not propose to resume.
 
gboolean dt_folder_survey_is_active ()
 TRUE while the periodic folder scan is running.
 
gboolean dt_folder_survey_session_was_active ()
 TRUE when the previous application session quit while monitoring.
 
int dt_folder_survey_count_new_files ()
 Count files in the surveyed folder that are unknown to the persisted baseline, i.e. files that appeared while the application was closed.
 
void dt_folder_survey_absorb_new_files ()
 Record every file currently in the surveyed folder as already handled, so restarting the survey will not import them.
 
gboolean dt_folder_survey_propose_resume ()
 Propose to resume an interrupted studio session at application start.
 
void dt_folder_survey_cleanup ()
 Release folder survey state after control workers have stopped.
 
void dt_folder_survey_stop ()
 Stop new scans before control workers begin shutting down.
 

Variables

static dt_folder_survey_t _folder_survey = { 0 }
 

Macro Definition Documentation

◆ DT_FOLDER_SURVEY_STATE_FILE

#define DT_FOLDER_SURVEY_STATE_FILE   "folder-survey-state.ini"

Definition at line 31 of file folder_survey.c.

Typedef Documentation

◆ dt_folder_survey_entry_t

◆ dt_folder_survey_file_state_t

◆ dt_folder_survey_job_t

◆ dt_folder_survey_observation_t

◆ dt_folder_survey_t

Enumeration Type Documentation

◆ dt_folder_survey_file_state_t

Enumerator
DT_FOLDER_SURVEY_FILE_PENDING 
DT_FOLDER_SURVEY_FILE_QUEUED 
DT_FOLDER_SURVEY_FILE_DONE 

Definition at line 33 of file folder_survey.c.

Function Documentation

◆ _folder_survey_collect()

static int _folder_survey_collect ( const char *  folder,
GHashTable *  observed 
)
static

Recursively collect supported images and their stability metadata.

The loop looks only for regular image files. Directories are traversed in place so a selected ingest root behaves like selecting a folder in Import.

Definition at line 195 of file folder_survey.c.

References dt_free, dt_supported_image(), error(), IS_NULL_PTR, dt_folder_survey_observation_t::mtime, dt_folder_survey_observation_t::size, and type.

Referenced by _folder_survey_job_run(), dt_folder_survey_absorb_new_files(), and dt_folder_survey_count_new_files().

◆ _folder_survey_deactivate()

static void _folder_survey_deactivate ( )
static

Stop periodic scans without discarding the persisted comparison state.

Imports already queued are allowed to finish. Starting again in the same session resumes comparison from the last saved file list.

Definition at line 579 of file folder_survey.c.

References _folder_survey, _folder_survey_save_locked(), dt_folder_survey_t::active, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::immediate_scan, dt_folder_survey_t::lock, and dt_folder_survey_t::timer.

Referenced by dt_folder_survey_halt().

◆ _folder_survey_imported()

static void _folder_survey_imported ( const char *  source,
const gboolean  success,
gpointer  user_data 
)
static

◆ _folder_survey_job_cleanup()

static void _folder_survey_job_cleanup ( void data)
static

Release one scan job and allow the next periodic scan to start.

Definition at line 475 of file folder_survey.c.

References _folder_survey, dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, and dt_folder_survey_t::scan_running.

Referenced by _folder_survey_scan().

◆ _folder_survey_job_run()

◆ _folder_survey_load_locked()

◆ _folder_survey_offer_pending_import()

static void _folder_survey_offer_pending_import ( )
static

Ask whether images already sitting in the source folder should be imported right away, instead of being silently absorbed into the baseline.

Runs every time monitoring starts: a plain Start on a never-before- surveyed folder would otherwise treat its existing content as the baseline without importing it, and a resumed session would otherwise import files that appeared while the application was closed without asking. Declining absorbs every currently observed file into the baseline so a later scan does not import it behind the user's back. Accepting on a folder with no baseline yet seeds an initialized, empty one so the next scan treats those files as new pending imports instead of silently absorbing them.

Definition at line 826 of file folder_survey.c.

References _folder_survey, _folder_survey_save_locked(), dt_folder_survey_t::baseline_initialized, darktable, dt_conf_get_bool(), dt_conf_set_bool(), dt_folder_survey_absorb_new_files(), dt_folder_survey_count_new_files(), DT_GUI_BOX_SPACING, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_ui_main_window(), FALSE, darktable_t::gui, dt_folder_survey_t::lock, TRUE, and dt_gui_gtk_t::ui.

Referenced by dt_folder_survey_start().

◆ _folder_survey_reschedule()

◆ _folder_survey_save_locked()

◆ _folder_survey_scan()

◆ _folder_survey_scan_once()

static gboolean _folder_survey_scan_once ( gpointer  user_data)
static

Run the immediate post-configuration scan only once.

Definition at line 541 of file folder_survey.c.

References _folder_survey, _folder_survey_scan(), and dt_folder_survey_t::immediate_scan.

Referenced by _folder_survey_reschedule().

◆ _folder_survey_styles_for_import()

static GList * _folder_survey_styles_for_import ( )
static

Read the ordered auto-apply style list from conf.

Styles are a Studio Capture feature, the survey runs in the background regardless of the active view, so styles are applied even if the user has switched away from Studio Capture while a session keeps monitoring.

Definition at line 278 of file folder_survey.c.

References darktable, dt_conf_get_string(), DT_FOLDER_SURVEY_STYLES_CONF_KEY, DT_FOLDER_SURVEY_STYLES_SEPARATOR, dt_free, dt_view_manager_get_current_view(), IS_NULL_PTR, name, view(), and darktable_t::view_manager.

Referenced by _folder_survey_job_run().

◆ dt_folder_survey_absorb_new_files()

◆ dt_folder_survey_can_start()

gboolean dt_folder_survey_can_start ( const char **  message)

Check, without any side effect, whether the persisted configuration has everything dt_folder_survey_start() requires to succeed.

Parameters
messagereceives a translated, static explanation when the configuration is incomplete or invalid; left untouched otherwise. Safe to display directly in the GUI (e.g. as a status label or tooltip).
Returns
gboolean TRUE when dt_folder_survey_start() would succeed.

Definition at line 691 of file folder_survey.c.

References dt_conf_get_bool(), dt_conf_get_string_const(), dt_datetime_entry_to_exif(), DT_DATETIME_LENGTH, dt_folder_survey_destination_preview(), dt_free, dt_util_test_writable_dir(), FALSE, IS_NULL_PTR, and TRUE.

Referenced by _studio_import_update_state(), and dt_folder_survey_start().

◆ dt_folder_survey_cleanup()

◆ dt_folder_survey_count_new_files()

int dt_folder_survey_count_new_files ( )

◆ dt_folder_survey_destination_preview()

char * dt_folder_survey_destination_preview ( )

Build the expanded destination path of a sample file from the current configuration, for GUI preview purposes.

Returns
char* newly allocated preview path, or NULL when the configuration cannot produce a valid destination. Free with dt_free().

Definition at line 598 of file folder_survey.c.

References dt_build_filename_from_pattern(), dt_conf_get_bool(), dt_conf_get_string(), dt_control_import_data_free(), dt_datetime_entry_to_exif(), DT_DATETIME_LENGTH, dt_free, dt_image_init(), dt_string_to_datetime(), dt_util_test_writable_dir(), dt_control_import_t::imgs, IS_NULL_PTR, and TRUE.

Referenced by _studio_import_update_preview(), and dt_folder_survey_can_start().

◆ dt_folder_survey_halt()

void dt_folder_survey_halt ( )

User-requested stop: end monitoring and clear the persisted session marker so the next application start does not propose to resume.

Definition at line 923 of file folder_survey.c.

References _folder_survey, _folder_survey_deactivate(), dt_folder_survey_t::active, darktable, dt_control_log(), DT_DEBUG_CONTROL_SIGNAL_RAISE, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), DT_SIGNAL_FOLDER_SURVEY_CHANGED, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, and darktable_t::signals.

Referenced by _studio_import_toggle_callback().

◆ dt_folder_survey_init()

◆ dt_folder_survey_is_active()

gboolean dt_folder_survey_is_active ( )

◆ dt_folder_survey_propose_resume()

gboolean dt_folder_survey_propose_resume ( )

Propose to resume an interrupted studio session at application start.

When the previous session quit while monitoring, ask the user whether to resume; on acceptance, switch to the Studio Capture view, then ask whether files that appeared meanwhile should be imported now (with an optional delete-source-after-verified-copy). Call after the GUI and views are ready.

Returns
gboolean always G_SOURCE_REMOVE, so it can be scheduled with g_idle_add().

Definition at line 1038 of file folder_survey.c.

References _folder_survey, _folder_survey_save_locked(), darktable, dt_conf_get_string(), dt_folder_survey_session_was_active(), dt_folder_survey_start(), dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_ui_main_window(), dt_view_manager_switch(), FALSE, darktable_t::gui, dt_folder_survey_t::lock, dt_gui_gtk_t::ui, darktable_t::view_manager, and dt_folder_survey_t::was_active_last_session.

Referenced by dt_init().

◆ dt_folder_survey_session_was_active()

gboolean dt_folder_survey_session_was_active ( )

TRUE when the previous application session quit while monitoring.

Definition at line 949 of file folder_survey.c.

References _folder_survey, dt_folder_survey_t::initialized, and dt_folder_survey_t::was_active_last_session.

Referenced by dt_folder_survey_propose_resume(), and dt_init().

◆ dt_folder_survey_start()

◆ dt_folder_survey_stop()

void dt_folder_survey_stop ( )

Stop new scans before control workers begin shutting down.

The persisted session marker keeps its current state so an active session can be proposed for resume on the next start.

Definition at line 1093 of file folder_survey.c.

References _folder_survey, _folder_survey_save_locked(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::immediate_scan, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, dt_folder_survey_t::shutting_down, dt_folder_survey_t::timer, and TRUE.

Referenced by dt_cleanup(), and dt_folder_survey_cleanup().

Variable Documentation

◆ _folder_survey