void fetchinfo_save_config(void) { PrefFile *pfile; gchar *rcpath; debug_print("Saving Fetchinfo Page\n"); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); pfile = prefs_write_open(rcpath); g_free(rcpath); if (!pfile || (prefs_set_block_label(pfile, "Fetchinfo") < 0)) return; if (prefs_write_param(param, pfile->fp) < 0) { /* i18n: Possible error message during plugin load */ g_warning("failed to write Fetchinfo configuration to file"); prefs_file_close_revert(pfile); return; } if (fprintf(pfile->fp, "\n") < 0) { FILE_OP_ERROR(rcpath, "fprintf"); prefs_file_close_revert(pfile); } else prefs_file_close(pfile); }
static void cm_gdata_save_config(void) { PrefFile *pfile; gchar *rcpath; debug_print("Saving GData plugin configuration...\n"); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); pfile = prefs_write_open(rcpath); g_free(rcpath); if (!pfile || (prefs_set_block_label(pfile, "GDataPlugin") < 0)) return; if (prefs_write_param(cm_gdata_param, pfile->fp) < 0) { debug_print("failed!\n"); g_warning("GData Plugin: Failed to write plugin configuration to file"); prefs_file_close_revert(pfile); return; } if (fprintf(pfile->fp, "\n") < 0) { FILE_OP_ERROR(rcpath, "fprintf"); prefs_file_close_revert(pfile); } else prefs_file_close(pfile); debug_print("done.\n"); }
static void save_rssyl_prefs(PrefsPage *page) { RSSylPrefsPage *prefs_page = (RSSylPrefsPage *)page; PrefFile *pref_file; gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); rssyl_prefs.refresh = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(prefs_page->refresh)); rssyl_prefs.expired = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(prefs_page->expired)); rssyl_prefs.refresh_on_startup = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(prefs_page->refresh_on_startup)); g_free(rssyl_prefs.cookies_path); rssyl_prefs.cookies_path = g_strdup(gtk_entry_get_text( GTK_ENTRY(prefs_page->cookies_path))); pref_file = prefs_write_open(rc_file_path); g_free(rc_file_path); if( !pref_file || prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0 ) return; if( prefs_write_param(param, pref_file->fp) < 0 ) { g_warning("Failed to write RSSyl plugin configuration\n"); prefs_file_close_revert(pref_file); return; } if (fprintf(pref_file->fp, "\n") < 0) { FILE_OP_ERROR(rc_file_path, "fprintf"); prefs_file_close_revert(pref_file); } else prefs_file_close(pref_file); }
void prefs_account_write_config_all(GList *account_list) { GList *cur; gchar *rcpath; PrefFile *pfile; rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL); if ((pfile = prefs_file_open(rcpath)) == NULL) { g_free(rcpath); return; } g_free(rcpath); for (cur = account_list; cur != NULL; cur = cur->next) { tmp_ac_prefs = *(PrefsAccount *)cur->data; if (fprintf(pfile->fp, "[Account: %d]\n", tmp_ac_prefs.account_id) <= 0 || prefs_file_write_param(pfile, param) < 0) { g_warning(_("failed to write configuration to file\n")); prefs_file_close_revert(pfile); return; } if (cur->next) { if (fputc('\n', pfile->fp) == EOF) { FILE_OP_ERROR(rcpath, "fputc"); prefs_file_close_revert(pfile); return; } } } if (prefs_file_close(pfile) < 0) g_warning(_("failed to write configuration to file\n")); }
static gint xmlprops_write_to( XmlProperty *props, const gchar *fileSpec ) { PrefFile *pfile; FILE *fp; HashLoopData data; props->retVal = MGU_OPEN_FILE; pfile = prefs_write_open( fileSpec ); if( pfile ) { fp = pfile->fp; if(fprintf( fp, "<?xml version=\"1.0\"" ) < 0) goto revert; if( props->encoding && *props->encoding ) { if(fprintf( fp, " encoding=\"%s\"", props->encoding ) < 0) goto revert; } if(fprintf( fp, " ?>\n" ) < 0) goto revert; if(xmlprops_write_elem_s( fp, 0, XMLS_ELTAG_PROP_LIST ) < 0) goto revert; if(fputs( ">\n", fp ) == EOF) goto revert; /* Output all properties */ data.fp = fp; data.error = 0; g_hash_table_foreach( props->propertyTable, xmlprops_write_vis, &data ); if (data.error) goto revert; if(xmlprops_write_elem_e( fp, 0, XMLS_ELTAG_PROP_LIST ) < 0) goto revert; props->retVal = MGU_SUCCESS; if( prefs_file_close( pfile ) < 0 ) { props->retVal = MGU_ERROR_WRITE; goto out; } goto out; revert: props->retVal = MGU_ERROR_WRITE; if( prefs_file_close_revert( pfile ) < 0 ) { props->retVal = MGU_ERROR_WRITE; } } out: return props->retVal; }
void prefs_actions_write_config(void) { gchar *rcpath; PrefFile *pfile; GSList *cur; debug_print("Writing actions configuration...\n"); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL); if ((pfile= prefs_write_open(rcpath)) == NULL) { g_warning("Failed to write configuration to file\n"); g_free(rcpath); return; } for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) { gchar *tmp = (gchar *)cur->data; const gchar *src_codeset = CS_UTF_8; const gchar *dest_codeset = conv_get_locale_charset_str(); gchar *act; act = conv_codeset_strdup(tmp, src_codeset, dest_codeset); if (!act) { g_warning("Failed to convert character set of action configuration\n"); act = g_strdup(act); } if (fputs(act, pfile->fp) == EOF || fputc('\n', pfile->fp) == EOF) { FILE_OP_ERROR(rcpath, "fputs || fputc"); prefs_file_close_revert(pfile); g_free(act); g_free(rcpath); return; } g_free(act); } g_free(rcpath); if (prefs_file_close(pfile) < 0) { g_warning("failed to write configuration to file\n"); return; } }
static void prefs_display_header_write_config(void) { gchar *rcpath; PrefFile *pfile; GSList *cur; debug_print("Writing configuration for displaying headers...\n"); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, DISPLAY_HEADER_RC, NULL); if ((pfile = prefs_write_open(rcpath)) == NULL) { g_warning("failed to write configuration to file"); g_free(rcpath); return; } for (cur = prefs_common.disphdr_list; cur != NULL; cur = cur->next) { DisplayHeaderProp *dp = (DisplayHeaderProp *)cur->data; gchar *dpstr; dpstr = display_header_prop_get_str(dp); if (claws_fputs(dpstr, pfile->fp) == EOF || claws_fputc('\n', pfile->fp) == EOF) { FILE_OP_ERROR(rcpath, "claws_fputs || claws_fputc"); prefs_file_close_revert(pfile); g_free(rcpath); g_free(dpstr); return; } g_free(dpstr); } g_free(rcpath); if (prefs_file_close(pfile) < 0) { g_warning("failed to write configuration to file"); return; } }
void vcal_prefs_save(void) { PrefFile *pfile; gchar *rcpath; rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); pfile = prefs_write_open(rcpath); g_free(rcpath); if (!pfile || (prefs_set_block_label(pfile, PREFS_BLOCK_NAME) < 0)) return; if (prefs_write_param(param, pfile->fp) < 0) { g_warning("failed to write vCalendar configuration to file"); prefs_file_close_revert(pfile); return; } if (fprintf(pfile->fp, "\n") < 0) { FILE_OP_ERROR(rcpath, "fprintf"); prefs_file_close_revert(pfile); } else prefs_file_close(pfile); }
static void save_rssyl_prefs(PrefsPage *page) { RPrefsPage *prefs_page = (RPrefsPage *)page; PrefFile *pref_file; gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); /* Grab values from GTK widgets */ rssyl_prefs.refresh_enabled = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(prefs_page->refresh_enabled)); rssyl_prefs.refresh = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(prefs_page->refresh)); rssyl_prefs.refresh_on_startup = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(prefs_page->refresh_on_startup)); g_free(rssyl_prefs.cookies_path); rssyl_prefs.cookies_path = g_strdup(gtk_entry_get_text( GTK_ENTRY(prefs_page->cookies_path))); rssyl_prefs.ssl_verify_peer = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(prefs_page->ssl_verify_peer)); /* Store prefs in rc file */ pref_file = prefs_write_open(rc_file_path); g_free(rc_file_path); if( !pref_file || prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0 ) return; if( prefs_write_param(param, pref_file->fp) < 0 ) { g_warning("Failed to write RSSyl plugin configuration"); prefs_file_close_revert(pref_file); return; } fprintf(pref_file->fp, "\n"); prefs_file_close(pref_file); rssyl_apply_prefs(); }
static void save_fancy_prefs(PrefsPage *page) { PrefFile *pref_file; gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); pref_file = prefs_write_open(rc_file_path); g_free(rc_file_path); if (!(pref_file) || (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0)) return; if (prefs_write_param(param, pref_file->fp) < 0) { g_warning("failed to write Fancy Plugin configuration\n"); prefs_file_close_revert(pref_file); return; } if (fprintf(pref_file->fp, "\n") < 0) { FILE_OP_ERROR(rc_file_path, "fprintf"); prefs_file_close_revert(pref_file); } else prefs_file_close(pref_file); }
void bogofilter_save_config(void) { PrefFile *pfile; gchar *rcpath; debug_print("Saving Bogofilter Page\n"); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); pfile = prefs_write_open(rcpath); g_free(rcpath); if (!pfile || (prefs_set_block_label(pfile, "Bogofilter") < 0)) return; if (prefs_write_param(param, pfile->fp) < 0) { g_warning("Failed to write Bogofilter configuration to file"); prefs_file_close_revert(pfile); return; } if (fprintf(pfile->fp, "\n") < 0) { FILE_OP_ERROR(rcpath, "fprintf"); prefs_file_close_revert(pfile); } else prefs_file_close(pfile); }
static void prefs_custom_header_write_config(PrefsAccount *ac) { gchar *rcpath; PrefFile *pfile; GSList *cur; gchar buf[PREFSBUFSIZE]; FILE * fp; CustomHeader *ch; GSList *all_hdrs = NULL; debug_print("Writing custom header configuration...\n"); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, CUSTOM_HEADER_RC, NULL); if ((fp = g_fopen(rcpath, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); } else { all_hdrs = NULL; while (fgets(buf, sizeof(buf), fp) != NULL) { ch = custom_header_read_str(buf); if (ch) { if (ch->account_id != ac->account_id) all_hdrs = g_slist_append(all_hdrs, ch); else custom_header_free(ch); } } fclose(fp); } if ((pfile = prefs_write_open(rcpath)) == NULL) { g_warning("failed to write configuration to file\n"); g_free(rcpath); return; } for (cur = all_hdrs; cur != NULL; cur = cur->next) { CustomHeader *hdr = (CustomHeader *)cur->data; gchar *chstr; chstr = custom_header_get_str(hdr); if (fputs(chstr, pfile->fp) == EOF || fputc('\n', pfile->fp) == EOF) { FILE_OP_ERROR(rcpath, "fputs || fputc"); prefs_file_close_revert(pfile); g_free(rcpath); g_free(chstr); return; } g_free(chstr); } for (cur = ac->customhdr_list; cur != NULL; cur = cur->next) { CustomHeader *hdr = (CustomHeader *)cur->data; gchar *chstr; chstr = custom_header_get_str(hdr); if (fputs(chstr, pfile->fp) == EOF || fputc('\n', pfile->fp) == EOF) { FILE_OP_ERROR(rcpath, "fputs || fputc"); prefs_file_close_revert(pfile); g_free(rcpath); g_free(chstr); return; } g_free(chstr); } g_free(rcpath); while (all_hdrs != NULL) { ch = (CustomHeader *)all_hdrs->data; all_hdrs = g_slist_remove(all_hdrs, ch); custom_header_free(ch); } if (prefs_file_close(pfile) < 0) { g_warning("failed to write configuration to file\n"); return; } }
/* Save selections in a common xml-file. Called when unloading the plugin. * This is analog to folder.h::folder_write_list. */ void notification_foldercheck_write_array(void) { gchar *path; XMLTag *tag; XMLNode *xmlnode; GNode *rootnode; gint ii; PrefFile *pfile; /* Do nothing if foldercheck is not in use */ if(specific_folder_array_size == 0) return; path = foldercheck_get_array_path(); if((pfile = prefs_write_open(path)) == NULL) { debug_print("Notification Plugin Error: Cannot open " "file " FOLDERCHECK_ARRAY " for writing\n"); return; } /* XML declarations */ xml_file_put_xml_decl(pfile->fp); /* Build up XML tree */ /* root node */ tag = xml_tag_new("foldercheckarray"); xmlnode = xml_node_new(tag, NULL); rootnode = g_node_new(xmlnode); /* branch nodes */ for(ii = 0; ii < specific_folder_array_size; ii++) { GNode *branchnode; GSList *walk; SpecificFolderArrayEntry *entry; entry = foldercheck_get_entry_from_id(ii); tag = xml_tag_new("branch"); xml_tag_add_attr(tag, xml_attr_new("name",entry->name)); xmlnode = xml_node_new(tag, NULL); branchnode = g_node_new(xmlnode); g_node_append(rootnode, branchnode); /* Write out the list as leaf nodes */ for(walk = entry->list; walk != NULL; walk = g_slist_next(walk)) { gchar *identifier; GNode *node; FolderItem *item = (FolderItem*) walk->data; identifier = folder_item_get_identifier(item); tag = xml_tag_new("folderitem"); xml_tag_add_attr(tag, xml_attr_new("identifier", identifier)); g_free(identifier); xmlnode = xml_node_new(tag, NULL); node = g_node_new(xmlnode); g_node_append(branchnode, node); } /* for all list elements in branch node */ } /* for all branch nodes */ /* Actual writing and cleanup */ xml_write_tree(rootnode, pfile->fp); if(prefs_file_close(pfile) < 0) { debug_print("Notification Plugin Error: Failed to write " "file " FOLDERCHECK_ARRAY "\n"); } /* Free XML tree */ xml_free_tree(rootnode); }
static void save_archiver_prefs(PrefsPage * _page) { struct ArchiverPrefsPage *page = (struct ArchiverPrefsPage *) _page; PrefFile *pref_file; gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); archiver_prefs.save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->zip_radiobtn))) archiver_prefs.compression = COMPRESSION_ZIP; else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->bzip_radiobtn))) archiver_prefs.compression = COMPRESSION_BZIP; else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->compress_radiobtn))) archiver_prefs.compression = COMPRESSION_COMPRESS; else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->none_radiobtn))) archiver_prefs.compression = COMPRESSION_NONE; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->tar_radiobtn))) archiver_prefs.format = FORMAT_TAR; else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->shar_radiobtn))) archiver_prefs.format = FORMAT_SHAR; else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->cpio_radiobtn))) archiver_prefs.format = FORMAT_CPIO; else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->pax_radiobtn))) archiver_prefs.format = FORMAT_PAX; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->recursive_chkbtn))) archiver_prefs.recursive = TRUE; else archiver_prefs.recursive = FALSE; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->md5sum_chkbtn))) archiver_prefs.md5sum = TRUE; else archiver_prefs.md5sum = FALSE; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->rename_chkbtn))) archiver_prefs.rename = TRUE; else archiver_prefs.rename = FALSE; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->unlink_chkbtn))) archiver_prefs.unlink = TRUE; else archiver_prefs.unlink = FALSE; pref_file = prefs_write_open(rc_file_path); g_free(rc_file_path); if (!(pref_file) || (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0)) return; if (prefs_write_param(param, pref_file->fp) < 0) { g_warning("failed to write Archiver Plugin configuration\n"); prefs_file_close_revert(pref_file); return; } if (fprintf(pref_file->fp, "\n") < 0) { FILE_OP_ERROR(rc_file_path, "fprintf"); prefs_file_close_revert(pref_file); } else prefs_file_close(pref_file); }