sync with 0.7.4cvs
authorPaul Mangan <paul@claws-mail.org>
Sun, 28 Apr 2002 10:31:35 +0000 (10:31 +0000)
committerPaul Mangan <paul@claws-mail.org>
Sun, 28 Apr 2002 10:31:35 +0000 (10:31 +0000)
src/folderview.c
src/utils.c
src/utils.h

index 5df6dbf..0522975 100644 (file)
@@ -1743,6 +1743,7 @@ static void folderview_new_folder_cb(FolderView *folderview, guint action,
        FolderItem *item;
        FolderItem *new_item;
        gchar *new_folder;
+       gchar *name, *name_;
        GtkCTreeNode *node;
 
        if (!folderview->selected) return;
@@ -1765,18 +1766,20 @@ static void folderview_new_folder_cb(FolderView *folderview, guint action,
                }
        }
 
+       name_ = trim_string(new_folder, 32);
+       Xstrdup_a(name, name_, {g_free(new_folder); return;});
+       g_free(name_);
+
        /* find whether the directory already exists */
        if (folderview_find_by_name(ctree, folderview->selected, new_folder)) {
-               alertpanel_error(_("The folder `%s' already exists."),
-                                new_folder);
+               alertpanel_error(_("The folder `%s' already exists."), name);
                g_free(new_folder);
                return;
        }
 
        new_item = item->folder->create_folder(item->folder, item, new_folder);
        if (!new_item) {
-               alertpanel_error(_("The folder `%s' could not be created."), 
-                                new_folder);
+               alertpanel_error(_("Can't create the folder `%s'."), name);
                g_free(new_folder);
                return;
        } 
@@ -1855,6 +1858,7 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
        gchar *new_folder;
+       gchar *name, *name_;
        gchar *message;
        gchar *old_path;
        gchar *old_id;
@@ -1867,8 +1871,10 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->path != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       message = g_strdup_printf(_("Input new name for `%s':"),
-                                 g_basename(item->path));
+       name_ = trim_string(item->name, 32);
+       Xstrdup_a(name, name_, return);
+       g_free(name_);
+       message = g_strdup_printf(_("Input new name for `%s':"), name);
        new_folder = input_dialog(_("Rename folder"), message,
                                  g_basename(item->path));
        g_free(message);
@@ -1884,8 +1890,9 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
        if (folderview_find_by_name
                (ctree, GTK_CTREE_ROW(folderview->selected)->parent,
                 new_folder)) {
-               alertpanel_error(_("The folder `%s' already exists."),
-                                new_folder);
+               name = trim_string(new_folder, 32);
+               alertpanel_error(_("The folder `%s' already exists."), name);
+               g_free(name);
                g_free(new_folder);
                return;
        }
@@ -1994,7 +2001,7 @@ static void folderview_delete_folder_cb(FolderView *folderview, guint action,
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
-       gchar *message;
+       gchar *message, *name, *name_;
        AlertValue avalue;
        gchar *old_path;
        gchar *old_id;
@@ -2006,10 +2013,12 @@ static void folderview_delete_folder_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->path != NULL);
        g_return_if_fail(item->folder != NULL);
 
+       name_ = trim_string(item->name, 32);
+       Xstrdup_a(name, name_, return);
+       g_free(name_);
        message = g_strdup_printf
                (_("All folder(s) and message(s) under `%s' will be deleted.\n"
-                  "Do you really want to delete?"),
-                g_basename(item->path));
+                  "Do you really want to delete?"), name);
        avalue = alertpanel(_("Delete folder"), message,
                            _("Yes"), _("+No"), NULL);
        g_free(message);
@@ -2019,8 +2028,7 @@ static void folderview_delete_folder_cb(FolderView *folderview, guint action,
        old_id = folder_item_get_identifier(item);
 
        if (item->folder->remove_folder(item->folder, item) < 0) {
-               alertpanel_error(_("Can't remove the folder `%s'."),
-                                item->path);
+               alertpanel_error(_("Can't remove the folder `%s'."), name);
                if (folderview->opened == folderview->selected)
                        summary_show(folderview->summaryview,
                                     folderview->summaryview->folder_item,
@@ -2058,6 +2066,7 @@ static void folderview_remove_mailbox_cb(FolderView *folderview, guint action,
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        GtkCTreeNode *node;
        FolderItem *item;
+       gchar *name, *name_;
        gchar *message;
        AlertValue avalue;
 
@@ -2068,10 +2077,12 @@ static void folderview_remove_mailbox_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->folder != NULL);
        if (item->parent) return;
 
+       name_ = trim_string(item->folder->name, 32);
+       Xstrdup_a(name, name_, return);
+       g_free(name_);
        message = g_strdup_printf
                (_("Really remove the mailbox `%s' ?\n"
-                  "(The messages are NOT deleted from disk)"),
-                item->folder->name);
+                  "(The messages are NOT deleted from the disk)"), name);
        avalue = alertpanel(_("Remove folder"), message,
                            _("Yes"), _("+No"), NULL);
        g_free(message);
@@ -2093,6 +2104,7 @@ static void folderview_new_imap_folder_cb(FolderView *folderview, guint action,
        FolderItem *item;
        FolderItem *new_item;
        gchar *new_folder;
+       gchar *name, *name_;
        gchar *p;
 
        if (!folderview->selected) return;
@@ -2119,18 +2131,20 @@ static void folderview_new_imap_folder_cb(FolderView *folderview, guint action,
                return;
        }
 
+       name_ = trim_string(new_folder, 32);
+       Xstrdup_a(name, name_, return);
+       g_free(name_);
+
        /* find whether the directory already exists */
        if (folderview_find_by_name(ctree, folderview->selected, new_folder)) {
-               alertpanel_error(_("The folder `%s' already exists."),
-                                new_folder);
+               alertpanel_error(_("The folder `%s' already exists."), name);
                g_free(new_folder);
                return;
        }
 
        new_item = item->folder->create_folder(item->folder, item, new_folder);
        if (!new_item) {
-               alertpanel_error(_("Can't create the folder `%s'."),
-                                new_folder);
+               alertpanel_error(_("Can't create the folder `%s'."), name);
                g_free(new_folder);
                return;
        }
@@ -2158,6 +2172,7 @@ static void folderview_rm_imap_server_cb(FolderView *folderview, guint action,
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
+       gchar *name, *name_;
        gchar *message;
        AlertValue avalue;
 
@@ -2169,8 +2184,10 @@ static void folderview_rm_imap_server_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->folder->type == F_IMAP);
        g_return_if_fail(item->folder->account != NULL);
 
-       message = g_strdup_printf(_("Really delete IMAP4 account `%s'?"),
-                                 item->folder->name);
+       name_ = trim_string(item->folder->name, 32);
+       Xstrdup_a(name, name_, return);
+       g_free(name_);
+       message = g_strdup_printf(_("Really delete IMAP4 account `%s'?"), name);
        avalue = alertpanel(_("Delete IMAP4 account"), message,
                            _("Yes"), _("+No"), NULL);
        g_free(message);
@@ -2289,6 +2306,7 @@ static void folderview_rm_news_group_cb(FolderView *folderview, guint action,
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
+       gchar *name, *name_;
        gchar *message;
        AlertValue avalue;
 
@@ -2300,8 +2318,10 @@ static void folderview_rm_news_group_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->folder->type == F_NEWS);
        g_return_if_fail(item->folder->account != NULL);
 
-       message = g_strdup_printf(_("Really delete newsgroup `%s'?"),
-                                 g_basename(item->path));
+       name_ = trim_string(item->path, 32);
+       Xstrdup_a(name, name_, return);
+       g_free(name_);
+       message = g_strdup_printf(_("Really delete newsgroup `%s'?"), name);
        avalue = alertpanel(_("Delete newsgroup"), message,
                            _("Yes"), _("+No"), NULL);
        g_free(message);
@@ -2322,6 +2342,7 @@ static void folderview_rm_news_server_cb(FolderView *folderview, guint action,
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
+       gchar *name, *name_;
        gchar *message;
        AlertValue avalue;
 
@@ -2333,8 +2354,10 @@ static void folderview_rm_news_server_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->folder->type == F_NEWS);
        g_return_if_fail(item->folder->account != NULL);
 
-       message = g_strdup_printf(_("Really delete news account `%s'?"),
-                                 item->folder->name);
+       name_ = trim_string(item->folder->name, 32);
+       Xstrdup_a(name, name_, return);
+       g_free(name_);
+       message = g_strdup_printf(_("Really delete news account `%s'?"), name);
        avalue = alertpanel(_("Delete news account"), message,
                            _("Yes"), _("+No"), NULL);
        g_free(message);
index 140f5f3..62c3ad8 100644 (file)
@@ -1148,6 +1148,34 @@ gchar *get_abbrev_newsgroup_name(const gchar *group)
        return abbrev_group;
 }
 
+gchar *trim_string(const gchar *str, gint len)
+{
+       const gchar *p = str;
+       gint mb_len;
+       gchar *new_str;
+       gint new_len = 0;
+
+       if (!str) return NULL;
+       if (strlen(str) <= len)
+               return g_strdup(str);
+
+       while (*p != '\0') {
+               mb_len = mblen(p, MB_LEN_MAX);
+               if (mb_len == 0)
+                       break;
+               else if (mb_len < 0)
+                       return g_strdup(str);
+               else if (new_len + mb_len > len)
+                       break;
+               else
+                       new_len += mb_len;
+               p += mb_len;
+       }
+
+       Xstrndup_a(new_str, str, new_len, return g_strdup(str));
+       return g_strconcat(new_str, "...", NULL);
+}
+
 GList *uri_list_extract_filenames(const gchar *uri_list)
 {
        GList *result = NULL;
index f9f93c7..69170f2 100644 (file)
@@ -277,6 +277,8 @@ gchar **strsplit_with_quote         (const gchar    *str,
                                         gint            max_tokens);
 
 gchar *get_abbrev_newsgroup_name       (const gchar    *group);
+gchar *trim_string                     (const gchar    *str,
+                                        gint            len);
 
 GList *uri_list_extract_filenames      (const gchar    *uri_list);
 void decode_uri                                (gchar          *decoded_uri,