gchar *dt_util_fix_path(const gchar *path) { if(path == NULL || *path == '\0') { return NULL; } gchar *rpath = NULL; /* check if path has a prepended tilde */ if(path[0] == '~') { size_t len = strlen(path); char *user = NULL; int off = 1; /* if the character after the tilde is not a slash we parse * the path until the next slash to extend this part with the * home directory of the specified user * * e.g.: ~foo will be evaluated as the home directory of the * user foo */ if(len > 1 && path[1] != '/') { while(path[off] != '\0' && path[off] != '/') { ++off; } user = g_strndup(path + 1, off - 1); } gchar *home_path = dt_loc_get_home_dir(user); g_free(user); if(home_path == NULL) { return g_strdup(path); } rpath = g_build_filename(home_path, path + off, NULL); g_free(home_path); } else { rpath = g_strdup(path); } return rpath; }
void dt_loc_init_user_config_dir(const char *configdir) { gchar *xdg_config_dir = NULL; gchar *default_config_dir = NULL; const char *xdg_config_home = g_getenv("XDG_CONFIG_HOME"); gchar *homedir = dt_loc_get_home_dir(NULL); if(xdg_config_home) xdg_config_dir = g_strconcat(xdg_config_home, "/darktable", NULL); if(homedir) { default_config_dir = g_strconcat(homedir, "/.config/darktable", NULL); g_free(homedir); } darktable.configdir = dt_loc_init_generic(configdir, xdg_config_dir ? xdg_config_dir : default_config_dir); g_free(xdg_config_dir); g_free(default_config_dir); }
gboolean _variable_get_value(dt_variables_params_t *params, gchar *variable, gchar *value, size_t value_len) { const gchar *file_ext = NULL; gboolean got_value = FALSE; struct tm tim; localtime_r(¶ms->data->time, &tim); const gchar *homedir = dt_loc_get_home_dir(NULL); gchar *pictures_folder = NULL; if(g_get_user_special_dir(G_USER_DIRECTORY_PICTURES) == NULL) pictures_folder = g_build_path(G_DIR_SEPARATOR_S, homedir, "Pictures", (char *)NULL); else pictures_folder = g_strdup(g_get_user_special_dir(G_USER_DIRECTORY_PICTURES)); if(params->filename) { file_ext = (g_strrstr(params->filename, ".") + 1); if(file_ext == (gchar *)1) file_ext = params->filename + strlen(params->filename); } /* image exif time */ gboolean have_exif_tm = FALSE; int exif_iso = 100; char camera_maker[64]; char camera_alias[64]; int version = 0; int stars = 0; struct tm exif_tm = { 0 }; if(params->imgid) { const dt_image_t *img = dt_image_cache_get(darktable.image_cache, params->imgid, 'r'); if(sscanf(img->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &exif_tm.tm_year, &exif_tm.tm_mon, &exif_tm.tm_mday, &exif_tm.tm_hour, &exif_tm.tm_min, &exif_tm.tm_sec) == 6) { exif_tm.tm_year -= 1900; exif_tm.tm_mon--; have_exif_tm = TRUE; } exif_iso = img->exif_iso; g_strlcpy(camera_maker, img->camera_maker, sizeof(camera_maker)); g_strlcpy(camera_alias, img->camera_alias, sizeof(camera_alias)); version = img->version; stars = (img->flags & 0x7); if(stars == 6) stars = -1; dt_image_cache_read_release(darktable.image_cache, img); } else if (params->data->exif_time) { localtime_r(¶ms->data->exif_time, &exif_tm); have_exif_tm = TRUE; } if(g_strcmp0(variable, "$(YEAR)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.4d", tim.tm_year + 1900); else if(g_strcmp0(variable, "$(MONTH)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", tim.tm_mon + 1); else if(g_strcmp0(variable, "$(DAY)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", tim.tm_mday); else if(g_strcmp0(variable, "$(HOUR)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", tim.tm_hour); else if(g_strcmp0(variable, "$(MINUTE)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", tim.tm_min); else if(g_strcmp0(variable, "$(SECOND)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", tim.tm_sec); else if(g_strcmp0(variable, "$(EXIF_YEAR)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.4d", (have_exif_tm ? exif_tm.tm_year : tim.tm_year) + 1900); else if(g_strcmp0(variable, "$(EXIF_MONTH)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", (have_exif_tm ? exif_tm.tm_mon : tim.tm_mon) + 1); else if(g_strcmp0(variable, "$(EXIF_DAY)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", (have_exif_tm ? exif_tm.tm_mday : tim.tm_mday)); else if(g_strcmp0(variable, "$(EXIF_HOUR)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", (have_exif_tm ? exif_tm.tm_hour : tim.tm_hour)); else if(g_strcmp0(variable, "$(EXIF_MINUTE)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", (have_exif_tm ? exif_tm.tm_min : tim.tm_min)); else if(g_strcmp0(variable, "$(EXIF_SECOND)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.2d", (have_exif_tm ? exif_tm.tm_sec : tim.tm_sec)); else if(g_strcmp0(variable, "$(EXIF_ISO)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%d", exif_iso); else if(g_strcmp0(variable, "$(MAKER)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", camera_maker); else if(g_strcmp0(variable, "$(MODEL)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", camera_alias); else if(g_strcmp0(variable, "$(ID)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%d", params->imgid); else if(g_strcmp0(variable, "$(VERSION)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%d", version); else if(g_strcmp0(variable, "$(JOBCODE)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", params->jobcode); else if(g_strcmp0(variable, "$(ROLL_NAME)") == 0 && params->filename && (got_value = TRUE)) { gchar *dirname = g_path_get_dirname(params->filename); gchar *basename = g_path_get_basename(dirname); snprintf(value, value_len, "%s", basename); g_free(basename); g_free(dirname); } else if(g_strcmp0(variable, "$(FILE_DIRECTORY)") == 0 && params->filename && (got_value = TRUE)) { gchar *dirname = g_path_get_dirname(params->filename); snprintf(value, value_len, "%s", dirname); g_free(dirname); } // undocumented : backward compatibility else if(g_strcmp0(variable, "$(FILE_FOLDER)") == 0 && params->filename && (got_value = TRUE)) { gchar *dirname = g_path_get_dirname(params->filename); snprintf(value, value_len, "%s", dirname); g_free(dirname); } else if(g_strcmp0(variable, "$(FILE_NAME)") == 0 && params->filename && (got_value = TRUE)) { gchar *basename = g_path_get_basename(params->filename); snprintf(value, value_len, "%s", basename); g_free(basename); if(g_strrstr(value, ".")) *(g_strrstr(value, ".")) = 0; } else if(g_strcmp0(variable, "$(FILE_EXTENSION)") == 0 && params->filename && (got_value = TRUE)) snprintf(value, value_len, "%s", file_ext); else if(g_strcmp0(variable, "$(SEQUENCE)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%.4d", params->sequence >= 0 ? params->sequence : params->data->sequence); else if(g_strcmp0(variable, "$(USERNAME)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", g_get_user_name()); else if(g_strcmp0(variable, "$(HOME_FOLDER)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", homedir); // undocumented : backward compatibility else if(g_strcmp0(variable, "$(HOME)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", homedir); else if(g_strcmp0(variable, "$(PICTURES_FOLDER)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", pictures_folder); else if(g_strcmp0(variable, "$(DESKTOP_FOLDER)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP)); // undocumented : backward compatibility else if(g_strcmp0(variable, "$(DESKTOP)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%s", g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP)); else if(g_strcmp0(variable, "$(STARS)") == 0 && (got_value = TRUE)) snprintf(value, value_len, "%d", stars); else if(g_strcmp0(variable, "$(LABELS)") == 0 && (got_value = TRUE)) { // TODO: currently we concatenate all the color labels with a ',' as a separator. Maybe it's better to // only use the first/last label? GList *res = dt_metadata_get(params->imgid, "Xmp.darktable.colorlabels", NULL); res = g_list_first(res); if(res != NULL) { GList *labels = NULL; do { labels = g_list_append(labels, (char *)(_(dt_colorlabels_to_string(GPOINTER_TO_INT(res->data))))); } while((res = g_list_next(res)) != NULL); char *str = dt_util_glist_to_str(",", labels); g_list_free(labels); snprintf(value, value_len, "%s", str); g_free(str); } else { snprintf(value, value_len, "%s", _("none")); } g_list_free(res); } else if(g_strcmp0(variable, "$(TITLE)") == 0 && params->filename && (got_value = TRUE)) { GList *res = dt_metadata_get(params->imgid, "Xmp.dc.title", NULL); res = g_list_first(res); if(res != NULL) { snprintf(value, value_len, "%s", (char *)res->data); } else { snprintf(value, value_len, "%s", _("none")); } g_list_free_full(res, &g_free); } else if(g_strcmp0(variable, "$(CREATOR)") == 0 && params->filename && (got_value = TRUE)) { GList *res = dt_metadata_get(params->imgid, "Xmp.dc.creator", NULL); res = g_list_first(res); if(res != NULL) { snprintf(value, value_len, "%s", (char *)res->data); } else { snprintf(value, value_len, "%s", _("none")); } g_list_free_full(res, &g_free); } else if(g_strcmp0(variable, "$(PUBLISHER)") == 0 && params->filename && (got_value = TRUE)) { GList *res = dt_metadata_get(params->imgid, "Xmp.dc.publisher", NULL); res = g_list_first(res); if(res != NULL) { snprintf(value, value_len, "%s", (char *)res->data); } else { snprintf(value, value_len, "%s", _("none")); } g_list_free_full(res, &g_free); } else if(g_strcmp0(variable, "$(RIGHTS)") == 0 && params->filename && (got_value = TRUE)) { GList *res = dt_metadata_get(params->imgid, "Xmp.dc.rights", NULL); res = g_list_first(res); if(res != NULL) { snprintf(value, value_len, "%s", (char *)res->data); } else { snprintf(value, value_len, "%s", _("none")); } g_list_free_full(res, &g_free); } g_free(pictures_folder); g_free((gchar *)homedir); return got_value; }
gboolean _variable_get_value(dt_variables_params_t *params, gchar *variable,gchar *value) { const gchar *file_ext=NULL; gboolean got_value=FALSE; struct tm *tim=localtime(¶ms->data->time); const gchar *homedir = dt_loc_get_home_dir(NULL); gchar *pictures_folder=NULL; if(g_get_user_special_dir(G_USER_DIRECTORY_PICTURES) == NULL) pictures_folder=g_build_path(G_DIR_SEPARATOR_S,homedir,"Pictures",(char *)NULL); else pictures_folder=g_strdup( g_get_user_special_dir(G_USER_DIRECTORY_PICTURES) ); if(params->filename) { file_ext=(g_strrstr(params->filename,".")+1); if(file_ext == (gchar*)1) file_ext = params->filename + strlen(params->filename); } /* image exif time */ gboolean have_exif_tm = FALSE; int exif_iso = 100; struct tm exif_tm= {0}; if (params->imgid) { const dt_image_t *img = dt_image_cache_read_get(darktable.image_cache, params->imgid); if (sscanf (img->exif_datetime_taken,"%d:%d:%d %d:%d:%d", &exif_tm.tm_year, &exif_tm.tm_mon, &exif_tm.tm_mday, &exif_tm.tm_hour, &exif_tm.tm_min, &exif_tm.tm_sec ) == 6 ) { exif_tm.tm_year-=1900; exif_tm.tm_mon--; have_exif_tm = TRUE; } exif_iso = img->exif_iso; dt_image_cache_read_release(darktable.image_cache, img); } if( g_strcmp0(variable,"$(YEAR)") == 0 && (got_value=TRUE) ) sprintf(value,"%.4d",tim->tm_year+1900); else if( g_strcmp0(variable,"$(MONTH)") == 0&& (got_value=TRUE) ) sprintf(value,"%.2d",tim->tm_mon+1); else if( g_strcmp0(variable,"$(DAY)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d",tim->tm_mday); else if( g_strcmp0(variable,"$(HOUR)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d",tim->tm_hour); else if( g_strcmp0(variable,"$(MINUTE)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d",tim->tm_min); else if( g_strcmp0(variable,"$(SECOND)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d",tim->tm_sec); else if( g_strcmp0(variable,"$(EXIF_YEAR)") == 0 && (got_value=TRUE) ) sprintf(value,"%.4d", (have_exif_tm?exif_tm.tm_year:tim->tm_year)+1900); else if( g_strcmp0(variable,"$(EXIF_MONTH)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d", (have_exif_tm?exif_tm.tm_mon:tim->tm_mon)+1); else if( g_strcmp0(variable,"$(EXIF_DAY)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d", (have_exif_tm?exif_tm.tm_mday:tim->tm_mday)); else if( g_strcmp0(variable,"$(EXIF_HOUR)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d", (have_exif_tm?exif_tm.tm_hour:tim->tm_hour)); else if( g_strcmp0(variable,"$(EXIF_MINUTE)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d", (have_exif_tm?exif_tm.tm_min:tim->tm_min)); else if( g_strcmp0(variable,"$(EXIF_SECOND)") == 0 && (got_value=TRUE) ) sprintf(value,"%.2d", (have_exif_tm?exif_tm.tm_sec:tim->tm_sec)); else if( g_strcmp0(variable,"$(EXIF_ISO)") == 0 && (got_value=TRUE) ) sprintf(value,"%d", exif_iso); else if( g_strcmp0(variable,"$(ID)") == 0 && (got_value=TRUE) ) sprintf(value,"%d", params->imgid); else if( g_strcmp0(variable,"$(JOBCODE)") == 0 && (got_value=TRUE) ) sprintf(value,"%s",params->jobcode); else if( g_strcmp0(variable,"$(ROLL_NAME)") == 0 && params->filename && (got_value=TRUE) ) sprintf(value,"%s",g_path_get_basename(g_path_get_dirname(params->filename))); else if( g_strcmp0(variable,"$(FILE_DIRECTORY)") == 0 && params->filename && (got_value=TRUE) ) sprintf(value,"%s",g_path_get_dirname(params->filename)); // undocumented : backward compatibility else if( g_strcmp0(variable,"$(FILE_FOLDER)") == 0 && params->filename && (got_value=TRUE) ) sprintf(value,"%s",g_path_get_dirname(params->filename)); else if( g_strcmp0(variable,"$(FILE_NAME)") == 0 && params->filename && (got_value=TRUE) ) { sprintf(value,"%s",g_path_get_basename(params->filename)); if (g_strrstr(value,".")) *(g_strrstr(value,"."))=0; } else if( g_strcmp0(variable,"$(FILE_EXTENSION)") == 0 && params->filename && (got_value=TRUE) ) sprintf(value,"%s",file_ext); else if( g_strcmp0(variable,"$(SEQUENCE)") == 0 && (got_value=TRUE) ) sprintf(value,"%.4d",params->sequence>=0?params->sequence:params->data->sequence); else if( g_strcmp0(variable,"$(USERNAME)") == 0 && (got_value=TRUE) ) sprintf(value,"%s",g_get_user_name()); else if( g_strcmp0(variable,"$(HOME_FOLDER)") == 0 && (got_value=TRUE) ) sprintf(value,"%s",homedir); // undocumented : backward compatibility else if( g_strcmp0(variable,"$(HOME)") == 0 && (got_value=TRUE) ) sprintf(value,"%s",homedir); else if( g_strcmp0(variable,"$(PICTURES_FOLDER)") == 0 && (got_value=TRUE) ) sprintf(value,"%s",pictures_folder); else if( g_strcmp0(variable,"$(DESKTOP_FOLDER)") == 0 && (got_value=TRUE) ) sprintf(value,"%s",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP)); // undocumented : backward compatibility else if( g_strcmp0(variable,"$(DESKTOP)") == 0 && (got_value=TRUE) ) sprintf(value,"%s",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP)); #if 0 else if( g_strcmp0(variable,"$(VC)") == 0 && (got_value=TRUE) ) { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(darktable.db, "select id from images where filename=?1", &stmt, NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, params->filename); while(sqlite3_step(stmt) == SQLITE_ROW) { if(sqlite3_column_int(stmt) == ) { } } sqlite3_finalize(stmt); sprintf(value,"%s",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP)); }