0.8.8claws27
authorChristoph Hohmann <reboot@gmx.ch>
Tue, 31 Dec 2002 00:11:12 +0000 (00:11 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Tue, 31 Dec 2002 00:11:12 +0000 (00:11 +0000)
* src/addrbook.c
* src/addrindex.c
* src/folder.c
* src/matcher.c
* src/prefs_account.c
* src/prefs_actions.c
* src/prefs_customheader.c
* src/prefs_display_header.c
* src/prefs_gtk.c
* src/procmime.c
* src/toolbar.c
* src/xmlprops.c
* src/common/prefs.[ch]
        extend prefs file handling for reading and automatic handling
        of blocks. When reading prefs_set_block_label will automatically
        move on to the block. When writing it will copy all other blocks
        automatically

* src/common/plugin.c
        Now loading plugin filenames from [Plugins] block in
        sylpheed rc file

17 files changed:
ChangeLog.claws
configure.in
src/addrbook.c
src/addrindex.c
src/common/plugin.c
src/common/prefs.c
src/common/prefs.h
src/folder.c
src/matcher.c
src/prefs_account.c
src/prefs_actions.c
src/prefs_customheader.c
src/prefs_display_header.c
src/prefs_gtk.c
src/procmime.c
src/toolbar.c
src/xmlprops.c

index 0d2107c..0d96508 100644 (file)
@@ -1,3 +1,27 @@
+2002-12-31 [christoph] 0.8.8claws27
+
+       * src/addrbook.c
+       * src/addrindex.c
+       * src/folder.c
+       * src/matcher.c
+       * src/prefs_account.c
+       * src/prefs_actions.c
+       * src/prefs_customheader.c
+       * src/prefs_display_header.c
+       * src/prefs_gtk.c
+       * src/procmime.c
+       * src/toolbar.c
+       * src/xmlprops.c
+       * src/common/prefs.[ch]
+               extend prefs file handling for reading and automatic handling
+               of blocks. When reading prefs_set_block_label will automatically
+               move on to the block. When writing it will copy all other blocks
+               automatically
+
+       * src/common/plugin.c
+               Now loading plugin filenames from [Plugins] block in
+               sylpheed rc file
+
 2002-12-30 [christoph] 0.8.8claws26
 
        * src/common/hooks.[ch]
index cd65aed..87abc86 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=8
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws26
+EXTRA_VERSION=claws27
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index ed53f6e..0af9e01 100644 (file)
@@ -1113,7 +1113,7 @@ gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
 #ifdef DEV_STANDALONE
                fclose(fp);
 #else
-               if (prefs_write_close( pfile ) < 0)
+               if (prefs_file_close( pfile ) < 0)
                        book->retVal = MGU_ERROR_WRITE;
 #endif
        }
index 373929c..fd5de33 100644 (file)
@@ -1187,7 +1187,7 @@ gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile ) {
 #ifdef DEV_STANDALONE
                fclose( fp );
 #else
-               if( prefs_write_close( pfile ) < 0 ) {
+               if( prefs_file_close( pfile ) < 0 ) {
                        addrIndex->retVal = MGU_ERROR_WRITE;
                }
 #endif
index 07c00f3..c704aca 100644 (file)
@@ -48,8 +48,9 @@ void plugin_save_list()
        GSList *cur;
        Plugin *plugin;
 
-       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "pluginsrc", NULL);
-       if ((pfile = prefs_write_open(rcpath)) == NULL) {
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
+       if ((pfile = prefs_write_open(rcpath)) == NULL ||
+           (prefs_set_block_label(pfile, "Plugins") < 0)) {
                g_warning("failed to write plugin list\n");
                g_free(rcpath);
                return;
@@ -61,7 +62,7 @@ void plugin_save_list()
                fprintf(pfile->fp, "%s\n", plugin->filename);
        }
 
-       if (prefs_write_close(pfile) < 0)
+       if (prefs_file_close(pfile) < 0)
                g_warning("failed to write plugin list\n");
 
        g_free(rcpath); 
@@ -139,23 +140,27 @@ void plugin_load_all()
 {
        gchar *rcpath;
        gchar buf[BUFFSIZE];
-       FILE *fp;
+       PrefFile *pfile;
+       gchar *error;
 
-       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "pluginsrc", NULL);       
-       if ((fp = fopen(rcpath, "rb")) != NULL) {
-               gchar *error;
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); 
+       if ((pfile = prefs_read_open(rcpath)) == NULL ||
+           (prefs_set_block_label(pfile, "Plugins") < 0)) {
+               g_free(rcpath);
+               return;
+       }
 
-               while(fgets(buf, sizeof(buf), fp) != NULL) {
-                       g_strstrip(buf);
+       while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
+               if (buf[0] == '[')
+                       break;
                        
-                       if (plugin_load(buf, &error) < 0) {
-                               debug_print("plugin loading error: %s\n", error);
-                               g_free(error);
-                       }
-               }
-
-               fclose(fp);
+               g_strstrip(buf);
+               if (plugin_load(buf, &error) < 0) {
+                       debug_print("plugin loading error: %s\n", error);
+                       g_free(error);
+               }                                                       
        }
+       prefs_file_close(pfile);
 
        g_free(rcpath);
 }
index 0238fb0..29483a2 100644 (file)
 #  include "config.h"
 #endif
 
+#include "defs.h"
+
 #include <glib.h>
 
 #include "prefs.h"
 #include "utils.h"
 
+PrefFile *prefs_read_open(const gchar *path)
+{
+       PrefFile *pfile;
+       gchar *tmppath;
+       FILE *fp;
+
+       g_return_val_if_fail(path != NULL, NULL);
+
+       if ((fp = fopen(path, "rb")) == NULL) {
+               FILE_OP_ERROR(tmppath, "fopen");
+               return NULL;
+       }
+
+       pfile = g_new(PrefFile, 1);
+       pfile->fp = fp;
+       pfile->orig_fp = NULL;
+       pfile->path = g_strdup(path);
+       pfile->writing = FALSE;
+
+       return pfile;
+}
+
 PrefFile *prefs_write_open(const gchar *path)
 {
        PrefFile *pfile;
@@ -53,24 +77,58 @@ PrefFile *prefs_write_open(const gchar *path)
 
        pfile = g_new(PrefFile, 1);
        pfile->fp = fp;
+       pfile->orig_fp = NULL;
        pfile->path = g_strdup(path);
+       pfile->writing = TRUE;
 
        return pfile;
 }
 
-gint prefs_write_close(PrefFile *pfile)
+gint prefs_file_close(PrefFile *pfile)
 {
-       FILE *fp;
+       FILE *fp, *orig_fp;
        gchar *path;
        gchar *tmppath;
        gchar *bakpath = NULL;
+       gchar buf[BUFFSIZE];
 
        g_return_val_if_fail(pfile != NULL, -1);
 
        fp = pfile->fp;
+       orig_fp = pfile->orig_fp;
        path = pfile->path;
        g_free(pfile);
 
+       if (!pfile->writing) {
+               fclose(fp);
+               return 0;
+       }
+
+       if (orig_fp) {
+               while (fgets(buf, sizeof(buf), orig_fp) != NULL) {
+                       /* next block */
+                       if (buf[0] == '[') {
+                               if (fputs(buf, fp)  == EOF) {
+                                       g_warning("failed to write configuration to file\n");
+                                       fclose(orig_fp);
+                                       prefs_file_close_revert(pfile);
+                               
+                                       return -1;
+                               }
+                               break;
+                       }
+               }
+               
+               while (fgets(buf, sizeof(buf), orig_fp) != NULL)
+                       if (fputs(buf, fp) == EOF) {
+                               g_warning("failed to write configuration to file\n");
+                               fclose(orig_fp);
+                               prefs_file_close_revert(pfile);                 
+                               
+                               return -1;
+                       }
+       }
+
        tmppath = g_strconcat(path, ".tmp", NULL);
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmppath, "fclose");
@@ -107,16 +165,21 @@ gint prefs_write_close(PrefFile *pfile)
        return 0;
 }
 
-gint prefs_write_close_revert(PrefFile *pfile)
+gint prefs_file_close_revert(PrefFile *pfile)
 {
        gchar *tmppath;
 
        g_return_val_if_fail(pfile != NULL, -1);
 
-       tmppath = g_strconcat(pfile->path, ".tmp", NULL);
+       if (pfile->orig_fp)
+               fclose(pfile->orig_fp);
+       if (pfile->writing)
+               tmppath = g_strconcat(pfile->path, ".tmp", NULL);
        fclose(pfile->fp);
-       if (unlink(tmppath) < 0) FILE_OP_ERROR(tmppath, "unlink");
-       g_free(tmppath);
+       if (pfile->writing) {
+               if (unlink(tmppath) < 0) FILE_OP_ERROR(tmppath, "unlink");
+               g_free(tmppath);
+       }
        g_free(pfile->path);
        g_free(pfile);
 
@@ -145,3 +208,65 @@ gboolean prefs_rc_is_readonly(const gchar * rcfile)
 
        return result;
 }
+
+gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
+{
+       gchar *block_label;
+       gchar buf[BUFFSIZE];
+       
+       block_label = g_strdup_printf("[%s]", label);
+       if (!pfile->writing) {
+               while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
+                       gint val;
+                       
+                       val = strncmp(buf, block_label, strlen(block_label));
+                       if (val == 0) {
+                               debug_print("Found %s\n", block_label);
+                               break;
+                       }
+               }
+       } else {
+               if ((pfile->orig_fp = fopen(pfile->path, "rb")) != NULL) {
+                       gboolean block_matched = FALSE;
+
+                       while (fgets(buf, sizeof(buf), pfile->orig_fp) != NULL) {
+                               gint val;
+                               
+                               val = strncmp(buf, block_label, strlen(block_label));
+                               if (val == 0) {
+                                       debug_print("Found %s\n", block_label);
+                                       block_matched = TRUE;
+                                       break;
+                               } else {
+                                       if (fputs(buf, pfile->fp) == EOF) {
+                                               g_warning("failed to write configuration to file\n");
+                                               fclose(pfile->orig_fp);
+                                               prefs_file_close_revert(pfile);
+                                               g_free(block_label);
+                                               
+                                               return -1;
+                                       }
+                               }
+                       }
+                       
+                       if (!block_matched) {
+                               fclose(pfile->orig_fp);
+                               pfile->orig_fp = NULL;
+                       }
+                       
+                       if (fputs(block_label, pfile->fp) == EOF ||
+                           fputc('\n', pfile->fp) == EOF) {
+                               g_warning("failed to write configuration to file\n");
+                               fclose(pfile->orig_fp);
+                               prefs_file_close_revert(pfile);
+                               g_free(block_label);
+                                               
+                               return -1;
+                       }
+               }
+       }
+
+       g_free(block_label);
+
+       return 0;
+}
index a66b380..45c8ecf 100644 (file)
@@ -26,13 +26,18 @@ typedef struct _PrefFile    PrefFile;
 
 struct _PrefFile {
        FILE *fp;
+       FILE *orig_fp;
        gchar *path;
+       gboolean writing;
 };
 
+PrefFile *prefs_read_open      (const gchar    *path);
 PrefFile *prefs_write_open     (const gchar    *path);
-gint prefs_write_close         (PrefFile       *pfile);
-gint prefs_write_close_revert  (PrefFile       *pfile);
+gint prefs_file_close          (PrefFile       *pfile);
+gint prefs_file_close_revert   (PrefFile       *pfile);
 gboolean prefs_is_readonly     (const gchar    *path);
 gboolean prefs_rc_is_readonly  (const gchar    *rcfile);
+gint prefs_set_block_label     (PrefFile       *pfile,
+                                const gchar    *block_label);
 
 #endif
index f002364..c2d84ca 100644 (file)
@@ -417,7 +417,7 @@ void folder_write_list(void)
 
        fputs("</folderlist>\n", pfile->fp);
 
-       if (prefs_write_close(pfile) < 0)
+       if (prefs_file_close(pfile) < 0)
                g_warning("failed to write folder list.\n");
 }
 
index 47eadcf..de68c28 100644 (file)
@@ -1288,7 +1288,7 @@ void prefs_matcher_write_config(void)
 
        g_free(rcpath);
 
-       if (prefs_write_close(pfile) < 0) {
+       if (prefs_file_close(pfile) < 0) {
                g_warning("failed to write configuration to file\n");
                return;
        }
index b54b383..8a78de3 100644 (file)
@@ -582,19 +582,19 @@ void prefs_account_save_config_all(GList *account_list)
                            tmp_ac_prefs.account_id) <= 0 ||
                    prefs_write_param(param, pfile->fp) < 0) {
                        g_warning("failed to write configuration to file\n");
-                       prefs_write_close_revert(pfile);
+                       prefs_file_close_revert(pfile);
                        return;
                }
                if (cur->next) {
                        if (fputc('\n', pfile->fp) == EOF) {
                                FILE_OP_ERROR(rcpath, "fputc");
-                               prefs_write_close_revert(pfile);
+                               prefs_file_close_revert(pfile);
                                return;
                        }
                }
        }
 
-       if (prefs_write_close(pfile) < 0)
+       if (prefs_file_close(pfile) < 0)
                g_warning("failed to write configuration to file\n");
 }
 
index ad2e132..3944e75 100644 (file)
@@ -516,7 +516,7 @@ void prefs_actions_write_config(void)
                if (fputs(act, pfile->fp) == EOF ||
                    fputc('\n', pfile->fp) == EOF) {
                        FILE_OP_ERROR(rcpath, "fputs || fputc");
-                       prefs_write_close_revert(pfile);
+                       prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        return;
                }
@@ -524,7 +524,7 @@ void prefs_actions_write_config(void)
        
        g_free(rcpath);
 
-       if (prefs_write_close(pfile) < 0) {
+       if (prefs_file_close(pfile) < 0) {
                g_warning("failed to write configuration to file\n");
                return;
        }
index de70575..35af9d1 100644 (file)
@@ -396,7 +396,7 @@ void prefs_custom_header_write_config(PrefsAccount *ac)
                if (fputs(chstr, pfile->fp) == EOF ||
                    fputc('\n', pfile->fp) == EOF) {
                        FILE_OP_ERROR(rcpath, "fputs || fputc");
-                       prefs_write_close_revert(pfile);
+                       prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(chstr);
                        return;
@@ -412,7 +412,7 @@ void prefs_custom_header_write_config(PrefsAccount *ac)
                if (fputs(chstr, pfile->fp) == EOF ||
                    fputc('\n', pfile->fp) == EOF) {
                        FILE_OP_ERROR(rcpath, "fputs || fputc");
-                       prefs_write_close_revert(pfile);
+                       prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(chstr);
                        return;
@@ -428,7 +428,7 @@ void prefs_custom_header_write_config(PrefsAccount *ac)
                all_hdrs = g_slist_remove(all_hdrs, ch);
        }
 
-       if (prefs_write_close(pfile) < 0) {
+       if (prefs_file_close(pfile) < 0) {
                g_warning("failed to write configuration to file\n");
                return;
        }
index a210f98..f9c1849 100644 (file)
@@ -425,7 +425,7 @@ void prefs_display_header_write_config(void)
                if (fputs(dpstr, pfile->fp) == EOF ||
                    fputc('\n', pfile->fp) == EOF) {
                        FILE_OP_ERROR(rcpath, "fputs || fputc");
-                       prefs_write_close_revert(pfile);
+                       prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(dpstr);
                        return;
@@ -435,7 +435,7 @@ void prefs_display_header_write_config(void)
 
        g_free(rcpath);
 
-       if (prefs_write_close(pfile) < 0) {
+       if (prefs_file_close(pfile) < 0) {
                g_warning("failed to write configuration to file\n");
                return;
        }
index e6330a6..7ee4238 100644 (file)
@@ -139,7 +139,7 @@ if (!(func)) \
 { \
        g_warning("failed to write configuration to file\n"); \
        if (orig_fp) fclose(orig_fp); \
-       prefs_write_close_revert(pfile); \
+       prefs_file_close_revert(pfile); \
        g_free(rcpath); \
        g_free(block_label); \
        return; \
@@ -209,7 +209,7 @@ void prefs_save_config(PrefParam *param, const gchar *label,
        }
 
        if (orig_fp) fclose(orig_fp);
-       if (prefs_write_close(pfile) < 0)
+       if (prefs_file_close(pfile) < 0)
                g_warning("failed to write configuration to file\n");
        g_free(rcpath);
 
index 5b2d569..d5057e1 100644 (file)
@@ -793,7 +793,7 @@ void renderer_write_config(void)
                        renderer->renderer);
        }
 
-       if (prefs_write_close(pfile) < 0) {
+       if (prefs_file_close(pfile) < 0) {
                g_warning("failed to write configuration to file\n");
                return;
        }
index 0937cca..619340e 100644 (file)
@@ -520,7 +520,7 @@ void toolbar_save_config_file(ToolbarType source)
 
                fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);      
        
-               if (prefs_write_close (pfile) < 0 ) 
+               if (prefs_file_close (pfile) < 0 ) 
                        g_warning("failed to write toolbar configuration to file\n");
        } else
                g_warning("failed to open toolbar configuration file for writing\n");
index b3d3014..ac6be5c 100644 (file)
@@ -170,7 +170,7 @@ static gint xmlprops_write_to( XmlProperty *props, const gchar *fileSpec ) {
 
                xmlprops_write_elem_e( fp, 0, XMLS_ELTAG_PROP_LIST );
                props->retVal = MGU_SUCCESS;
-               if( prefs_write_close( pfile ) < 0 ) {
+               if( prefs_file_close( pfile ) < 0 ) {
                        props->retVal = MGU_ERROR_WRITE;
                }
        }