/** \file * * \author Copyright 2000 Scott Fritzinger * * \par License * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * \par * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * \par * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ #define _DEFAULT_SOURCE #include "config.h" #include #include #include #include #include #include #include #ifdef WIN32 /* Win32 headers may use interface as a define; temporarily correct this */ #define interface struct #include #undef interface #endif /** * Internal struct to store settings. */ typedef struct { /* key = value settings */ char id[256]; char key[256]; char value[256]; } Setting; /* Currently loaded settings */ static int glob_setting_count = 0; static Setting glob_setting[512]; static int save_settings (void); #define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);} static int load_settings (void); /** * \brief Retrieve a specific gphoto setting. * \param id the frontend id of the caller * \param key the key the frontend queries * \param value changed value * \return GPhoto error code * * This function retrieves the setting key for a specific frontend * id and copies the value into the passed value pointer. */ int gp_setting_get (char *id, char *key, char *value) { int x; C_PARAMS (id && key); if (!glob_setting_count) load_settings (); for (x=0; x2) { equals = 0; for (x=0; x2) { buf[strlen(buf)-1] = '\0'; id = strtok(buf, "="); strcpy(glob_setting[glob_setting_count].id,id); key = strtok(NULL, "="); strcpy(glob_setting[glob_setting_count].key,key); value = strtok(NULL, "\0"); if (value) strcpy(glob_setting[glob_setting_count++].value, value); else strcpy(glob_setting[glob_setting_count++].value, ""); } } fclose (f); return (GP_OK); } static int save_settings (void) { FILE *f; char buf[1024]; int x=0; #ifdef WIN32 SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, 0, buf); strcat(buf, "\\.gphoto\\settings"); #else snprintf (buf, sizeof(buf), "%s/.gphoto/settings", getenv ("HOME")); #endif GP_LOG_D ("Saving %i setting(s) to file \"%s\"", glob_setting_count, buf); if ((f=fopen(buf, "w+"))==NULL) { GP_LOG_E ("Can't open settings file for writing."); return(0); } rewind(f); while (x < glob_setting_count) { fwrite(glob_setting[x].id, strlen(glob_setting[x].id),1,f); fputc('=', f); fwrite(glob_setting[x].key, strlen(glob_setting[x].key),1,f); fputc('=', f); fwrite(glob_setting[x].value, strlen(glob_setting[x].value),1,f); fputc('\n', f); x++; } fclose(f); return (GP_OK); } #if 0 static int dump_settings (void) { int x; gp_debug_printf(GP_DEBUG_LOW, "core", "All settings:"); for (x=0; x