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 0d2107cf1c65b87192e9b56a5ce970b1ecda50c7..0d965083d17926315f6307fe3bab6a6a9a22dea7 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 cd65aed930c99e7c831adc8d9b4691c4de44be4b..87abc86b36da579bfaef2371d220f8f316c2b409 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 ed53f6eeebcf75eda84f11d29da5b4cc1225e7bf..0af9e01da7959604f68fa4f2784ec9fd653325f5 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 373929c3c287d73cca2bc84171a25a4eacdd412c..fd5de33a0d0e72d318a7e5454ab2a092947ad34d 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 07c00f39620ef72414136df6d7ca2923dc854d06..c704aca6fe81e9cb83178c6ce3e5e6534a4c5003 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 0238fb01b60afc19d62d64de21200210d1619b39..29483a2199f5b09d2039a38c8260f9fe89f8e885 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 a66b380cd5df13d232f8993525c8f1b9b2e99f99..45c8ecf4d45cf4c94ce521ac92438f2885a847f0 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 f0023644568c1c7118afd871eef43e60b5c5ad35..c2d84ca3ed36ab1be1b2643f1d5d6d7ffb158acc 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 47eadcf2ce01d002259fa51e0471f2de7c525979..de68c28ebf31adc794b860d08f7f927497a94e47 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 b54b383e058e680e9b8985d5ba800675c1b7bd0b..8a78de35593602b55ebc96fb1f26c2074703842e 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 ad2e13284a26044c2b8a11492a0a35c029a120f4..3944e757187921f10380633f7ee8a56630ed26f7 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 de70575335fdea53d24becdcf463292c30f7dee3..35af9d1cd79c2b8bab0f628752b420dcf7ac3e65 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 a210f981e88520ef30ba86ee39f138b420949c3f..f9c18493f79dc636fc279ca0a575f0130414fa16 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 e6330a65e9ddf104360bfddd54fa3fad9a2c582e..7ee423885ebba92e065c325227aeb388aa95f970 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 5b2d5692df01c21b90a8a38d5d11c87a6e03ca3f..d5057e1272cbc64f1ed4b30f57e6405ed7f2b0b9 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 0937cca77b1eb1cadab212e5a3e485dfb7107d04..619340e5e0e8ed53bc04d9ace9fb8e8a0ab7c691 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 b3d3014c2c45008ff1a601c505362c565db42723..ac6be5c19b6dd93eefe99f7d99c9b68a5da7594a 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;
                }
        }