Shared folders support with a GUI.
authorDarko Koruga <darko@users.sourceforge.net>
Mon, 30 Jul 2001 05:49:36 +0000 (05:49 +0000)
committerDarko Koruga <darko@users.sourceforge.net>
Mon, 30 Jul 2001 05:49:36 +0000 (05:49 +0000)
ChangeLog.claws
src/mh.c
src/prefs_folder_item.c
src/prefs_folder_item.h
src/summaryview.c

index f3ba50e3057a543ee1204e366fe440d874cba9fb..e9e2ff32cc6597048c3431fe7210c0b52842a8bf 100644 (file)
@@ -1,3 +1,10 @@
+2001-07-30 [darko]
+
+        * src/mh.c
+        * src/prefs_folder_item.[hc]
+        * src/summaryview.c
+               shared folders support with a GUI
+
 2001-07-29 [paul]
 
        0.5.1claws3
 2001-07-29 [paul]
 
        0.5.1claws3
index 7de12b7f7161daa48475d4d6dd0d925d57cee921..4c860c60f3db52ae259a2020d5ec2ccfb43c6c57 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -183,6 +183,8 @@ gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
        gchar *srcfile;
        gchar *destfile;
        FILE *fp;
        gchar *srcfile;
        gchar *destfile;
        FILE *fp;
+       gint filemode = 0;
+       PrefsFolderItem *prefs;
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(msginfo != NULL, -1);
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(msginfo != NULL, -1);
@@ -197,6 +199,8 @@ gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                if (dest->last_num < 0) return -1;
        }
 
                if (dest->last_num < 0) return -1;
        }
 
+       prefs = dest->prefs;
+
        destdir = folder_item_get_path(dest);
        if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
                g_warning(_("Can't open mark file.\n"));
        destdir = folder_item_get_path(dest);
        if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
                g_warning(_("Can't open mark file.\n"));
@@ -216,6 +220,16 @@ gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                return -1;
        }
 
                return -1;
        }
 
+       if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
+               if (chmod(destfile, prefs->folder_chmod) < 0)
+                       FILE_OP_ERROR(destfile, "chmod");
+
+               /* for mark file */
+               filemode = prefs->folder_chmod;
+               if (filemode & S_IRGRP) filemode |= S_IWGRP;
+               if (filemode & S_IROTH) filemode |= S_IWOTH;
+       }
+
        g_free(srcfile);
        g_free(destfile);
        dest->last_num++;
        g_free(srcfile);
        g_free(destfile);
        dest->last_num++;
@@ -233,6 +247,19 @@ gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                                             MSG_NEW|MSG_UNREAD|MSG_DELETED);
 
                procmsg_write_flags(&newmsginfo, fp);
                                             MSG_NEW|MSG_UNREAD|MSG_DELETED);
 
                procmsg_write_flags(&newmsginfo, fp);
+
+               if (filemode) {
+#if HAVE_FCHMOD
+                       fchmod(fileno(fp), filemode);
+#else
+                       markfile = folder_item_get_mark_file(dest);
+                       if (markfile) {
+                               chmod(markfile, filemode);
+                               g_free(markfile);
+                       }
+#endif
+               }
+
                fclose(fp);
        }
 
                fclose(fp);
        }
 
@@ -247,6 +274,7 @@ gint mh_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
        FILE *fp;
        GSList *cur;
        MsgInfo *msginfo;
        FILE *fp;
        GSList *cur;
        MsgInfo *msginfo;
+       PrefsFolderItem *prefs;
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(msglist != NULL, -1);
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(msglist != NULL, -1);
@@ -256,6 +284,8 @@ gint mh_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
                if (dest->last_num < 0) return -1;
        }
 
                if (dest->last_num < 0) return -1;
        }
 
+       prefs = dest->prefs;
+
        destdir = folder_item_get_path(dest);
        if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
                g_warning(_("Can't open mark file.\n"));
        destdir = folder_item_get_path(dest);
        if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
                g_warning(_("Can't open mark file.\n"));
@@ -314,6 +344,8 @@ gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
        gchar *srcfile;
        gchar *destfile;
        FILE *fp;
        gchar *srcfile;
        gchar *destfile;
        FILE *fp;
+       gint filemode = 0;
+       PrefsFolderItem *prefs;
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(msginfo != NULL, -1);
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(msginfo != NULL, -1);
@@ -328,6 +360,8 @@ gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                if (dest->last_num < 0) return -1;
        }
 
                if (dest->last_num < 0) return -1;
        }
 
+       prefs = dest->prefs;
+
        destdir = folder_item_get_path(dest);
        if (!is_dir_exist(destdir))
                make_dir_hier(destdir);
        destdir = folder_item_get_path(dest);
        if (!is_dir_exist(destdir))
                make_dir_hier(destdir);
@@ -359,6 +393,16 @@ gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                return -1;
        }
 
                return -1;
        }
 
+       if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
+               if (chmod(destfile, prefs->folder_chmod) < 0)
+                       FILE_OP_ERROR(destfile, "chmod");
+
+               /* for mark file */
+               filemode = prefs->folder_chmod;
+               if (filemode & S_IRGRP) filemode |= S_IWGRP;
+               if (filemode & S_IROTH) filemode |= S_IWOTH;
+       }
+
        g_free(srcfile);
        g_free(destfile);
        dest->last_num++;
        g_free(srcfile);
        g_free(destfile);
        dest->last_num++;
@@ -375,6 +419,19 @@ gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                        MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
                                             MSG_NEW|MSG_UNREAD|MSG_DELETED);
                procmsg_write_flags(&newmsginfo, fp);
                        MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
                                             MSG_NEW|MSG_UNREAD|MSG_DELETED);
                procmsg_write_flags(&newmsginfo, fp);
+
+               if (filemode) {
+#if HAVE_FCHMOD
+                       fchmod(fileno(fp), filemode);
+#else
+                       markfile = folder_item_get_mark_file(dest);
+                       if (markfile) {
+                               chmod(markfile, filemode);
+                               g_free(markfile);
+                       }
+#endif
+               }
+
                fclose(fp);
        }
 
                fclose(fp);
        }
 
index ce5741f4145700ec1bc3c2b4d9bfbdf9c1803316..757928a22a37ff8575c0c4e6bed8cd397881648f 100644 (file)
@@ -34,6 +34,8 @@ struct PrefsFolderItemDialog
        GtkWidget *checkbtn_request_return_receipt;
        GtkWidget *checkbtn_default_to;
        GtkWidget *entry_default_to;
        GtkWidget *checkbtn_request_return_receipt;
        GtkWidget *checkbtn_default_to;
        GtkWidget *entry_default_to;
+       GtkWidget *checkbtn_folder_chmod;
+       GtkWidget *entry_folder_chmod;
 };
 
 static PrefParam param[] = {
 };
 
 static PrefParam param[] = {
@@ -63,6 +65,10 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"default_to", "", &tmp_prefs.default_to, P_STRING,
         NULL, NULL, NULL},
         NULL, NULL, NULL},
        {"default_to", "", &tmp_prefs.default_to, P_STRING,
         NULL, NULL, NULL},
+       {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
+        NULL, NULL, NULL},
+       {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
+        NULL, NULL, NULL},
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
@@ -70,6 +76,8 @@ void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, struct P
 void prefs_folder_item_cancel_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
 void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
 void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
 void prefs_folder_item_cancel_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
 void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
 void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_folder_chmod_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
+gint prefs_folder_item_chmod_mode(gchar *folder_chmod);
 
 void prefs_folder_item_read_config(FolderItem * item)
 {
 
 void prefs_folder_item_read_config(FolderItem * item)
 {
@@ -151,6 +159,8 @@ PrefsFolderItem * prefs_folder_item_new(void)
        tmp_prefs.request_return_receipt = FALSE;
        tmp_prefs.enable_default_to = FALSE;
        tmp_prefs.default_to = NULL;
        tmp_prefs.request_return_receipt = FALSE;
        tmp_prefs.enable_default_to = FALSE;
        tmp_prefs.default_to = NULL;
+       tmp_prefs.enable_folder_chmod = FALSE;
+       tmp_prefs.folder_chmod = 0;
 
        * prefs = tmp_prefs;
        
 
        * prefs = tmp_prefs;
        
@@ -206,6 +216,8 @@ void prefs_folder_item_create(FolderItem *item) {
        GtkWidget *checkbtn_request_return_receipt;
        GtkWidget *checkbtn_default_to;
        GtkWidget *entry_default_to;
        GtkWidget *checkbtn_request_return_receipt;
        GtkWidget *checkbtn_default_to;
        GtkWidget *entry_default_to;
+       GtkWidget *checkbtn_folder_chmod;
+       GtkWidget *entry_folder_chmod;
 
        dialog = g_new0(struct PrefsFolderItemDialog, 1);
        dialog->item = item;
 
        dialog = g_new0(struct PrefsFolderItemDialog, 1);
        dialog->item = item;
@@ -262,10 +274,43 @@ void prefs_folder_item_create(FolderItem *item) {
        gtk_editable_set_editable(GTK_EDITABLE(entry_default_to), item->prefs->enable_default_to);
        gtk_entry_set_text(GTK_ENTRY(entry_default_to), item->prefs->default_to);
 
        gtk_editable_set_editable(GTK_EDITABLE(entry_default_to), item->prefs->enable_default_to);
        gtk_entry_set_text(GTK_ENTRY(entry_default_to), item->prefs->default_to);
 
+       /* Folder chmod */
+       hbox = gtk_hbox_new(FALSE, 8);
+       gtk_widget_show(hbox);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+       PACK_CHECK_BUTTON(hbox, checkbtn_folder_chmod,
+                          _("Folder chmod: "));
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), item->prefs->enable_folder_chmod);
+       gtk_signal_connect(GTK_OBJECT(checkbtn_folder_chmod), "toggled",
+                           GTK_SIGNAL_FUNC(prefs_folder_item_folder_chmod_cb), dialog);
+
+       entry_folder_chmod = gtk_entry_new();
+       gtk_widget_show(entry_folder_chmod);
+       gtk_box_pack_start(GTK_BOX(hbox), entry_folder_chmod, FALSE, FALSE, 0);
+       gtk_editable_set_editable(GTK_EDITABLE(entry_folder_chmod), item->prefs->enable_folder_chmod);
+       if (item->prefs->folder_chmod) {
+               gint tmp;
+               gint mult;
+               gint count = 0;
+               char buf[64]; /* plenty enough for an integer */
+
+               tmp = item->prefs->folder_chmod;
+               while (tmp && (count < sizeof(buf) - 1)) {
+                       mult = tmp / 8;
+                       buf[count++] = '0' + (tmp - mult * 8);
+                       tmp /= 8;
+               }
+               buf[count] = '\0';
+               gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
+       }
+
        dialog->window = window;
        dialog->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
        dialog->checkbtn_default_to = checkbtn_default_to;
        dialog->entry_default_to = entry_default_to;
        dialog->window = window;
        dialog->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
        dialog->checkbtn_default_to = checkbtn_default_to;
        dialog->entry_default_to = entry_default_to;
+       dialog->checkbtn_folder_chmod = checkbtn_folder_chmod;
+       dialog->entry_folder_chmod = entry_folder_chmod;
 
        gtk_widget_show(window);
 }
 
        gtk_widget_show(window);
 }
@@ -293,6 +338,11 @@ void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *di
        g_free(prefs->default_to);
        prefs->default_to = 
            gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_default_to), 0, -1);
        g_free(prefs->default_to);
        prefs->default_to = 
            gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_default_to), 0, -1);
+       prefs->enable_folder_chmod = 
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod));
+       prefs->folder_chmod = prefs_folder_item_chmod_mode(
+               gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_folder_chmod),
+                                      0, -1));
 
        prefs_folder_item_save_config(dialog->item);
        prefs_folder_item_destroy(dialog);
 
        prefs_folder_item_save_config(dialog->item);
        prefs_folder_item_destroy(dialog);
@@ -302,3 +352,21 @@ void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDi
        gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_default_to),
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to)));
 }
        gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_default_to),
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to)));
 }
+
+void prefs_folder_item_folder_chmod_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+       gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_folder_chmod),
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod)));
+}
+
+gint prefs_folder_item_chmod_mode(gchar *folder_chmod) {
+       gint newmode = 0;
+       gchar *tmp;
+
+       if (folder_chmod) {
+               newmode = strtol(folder_chmod, &tmp, 8);
+               if (!(*(folder_chmod) && !(*tmp)))
+                       newmode = 0;
+       }
+
+       return newmode;
+}
index a74e8d3ab0755e38ade9033a05f0ad7384464fbe..e06ff6ff4892f91a7289df2ebbd892c9c6f01725 100644 (file)
@@ -47,6 +47,8 @@ struct _PrefsFolderItem {
        gboolean request_return_receipt;
        gboolean enable_default_to;
        gchar *default_to;
        gboolean request_return_receipt;
        gboolean enable_default_to;
        gchar *default_to;
+       gboolean enable_folder_chmod;
+       gint folder_chmod;
 };
 
 typedef struct _PrefsFolderItem PrefsFolderItem;
 };
 
 typedef struct _PrefsFolderItem PrefsFolderItem;
index 7214cd8225ff5fb2a1aa2a51d6f2f4b06e1bbb2e..a737b477a16611a52e25bab0a3b3185e06c167d0 100644 (file)
@@ -45,6 +45,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
+#include <sys/stat.h>
 
 #include "intl.h"
 #include "main.h"
 
 #include "intl.h"
 #include "main.h"
@@ -1943,6 +1944,8 @@ gint summary_write_cache(SummaryView *summaryview)
        gchar *buf;
        gchar *cachefile, *markfile;
        GSList * cur;
        gchar *buf;
        gchar *cachefile, *markfile;
        GSList * cur;
+       gint filemode = 0;
+       PrefsFolderItem *prefs;
 
        if (!summaryview->folder_item || !summaryview->folder_item->path)
                return -1;
 
        if (!summaryview->folder_item || !summaryview->folder_item->path)
                return -1;
@@ -1959,6 +1962,20 @@ gint summary_write_cache(SummaryView *summaryview)
        }
        if (change_file_mode_rw(fps.cache_fp, cachefile) < 0)
                FILE_OP_ERROR(cachefile, "chmod");
        }
        if (change_file_mode_rw(fps.cache_fp, cachefile) < 0)
                FILE_OP_ERROR(cachefile, "chmod");
+
+       prefs = summaryview->folder_item->prefs;
+        if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
+               /* for cache file */
+               filemode = prefs->folder_chmod;
+               if (filemode & S_IRGRP) filemode |= S_IWGRP;
+               if (filemode & S_IROTH) filemode |= S_IWOTH;
+#if HAVE_FCHMOD
+               fchmod(fileno(fps.cache_fp), filemode);
+#else
+               chmod(cachefile, filemode);
+#endif
+        }
+
        g_free(cachefile);
 
        markfile = folder_item_get_mark_file(summaryview->folder_item);
        g_free(cachefile);
 
        markfile = folder_item_get_mark_file(summaryview->folder_item);
@@ -1970,6 +1987,14 @@ gint summary_write_cache(SummaryView *summaryview)
        }
        if (change_file_mode_rw(fps.mark_fp, markfile) < 0)
                FILE_OP_ERROR(markfile, "chmod");
        }
        if (change_file_mode_rw(fps.mark_fp, markfile) < 0)
                FILE_OP_ERROR(markfile, "chmod");
+        if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
+#if HAVE_FCHMOD
+               fchmod(fileno(fps.mark_fp), filemode);
+#else
+               chmod(markfile, filemode);
+#endif
+        }
+
        g_free(markfile);
 
        buf = g_strdup_printf(_("Writing summary cache (%s)..."),
        g_free(markfile);
 
        buf = g_strdup_printf(_("Writing summary cache (%s)..."),