aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-05-11 07:59:52 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-05-11 07:59:52 +0000
commit02ecfb2ce6166c0ce44753363d558063bcba8176 (patch)
tree444dce7f35d974cbdea50c23e978c96367f83552 /src
parentd0b069da3ae33f183352e89c5019d3bf509dd68b (diff)
fixed several bugs, and implemented summary_unthread().
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@243 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r--src/defs.h2
-rw-r--r--src/folderview.c79
-rw-r--r--src/mainwindow.c4
-rw-r--r--src/summaryview.c75
-rw-r--r--src/utils.c47
5 files changed, 141 insertions, 66 deletions
diff --git a/src/defs.h b/src/defs.h
index 00392b40..fa705ded 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -103,6 +103,6 @@
#define SESSION_TIMEOUT_INTERVAL 60 /* sec */
#define MAX_HISTORY_SIZE 16
-#define DEFAULT_MESSAGE_FONT "Sans 14"
+#define DEFAULT_MESSAGE_FONT "Monospace 12"
#endif /* __DEFS_H__ */
diff --git a/src/folderview.c b/src/folderview.c
index bb5e7862..3b0df34d 100644
--- a/src/folderview.c
+++ b/src/folderview.c
@@ -567,6 +567,8 @@ static void folderview_select_row_ref(FolderView *folderview,
if (!row) return;
path = gtk_tree_row_reference_get_path(row);
+ if (!path)
+ return;
gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store), &iter, path);
gtk_tree_path_free(path);
@@ -623,6 +625,8 @@ void folderview_select_next_unread(FolderView *folderview)
GtkTreePath *path;
path = gtk_tree_row_reference_get_path(folderview->opened);
+ if (!path)
+ return;
gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_path_free(path);
} else {
@@ -652,6 +656,8 @@ FolderItem *folderview_get_selected_item(FolderView *folderview)
return NULL;
path = gtk_tree_row_reference_get_path(folderview->selected);
+ if (!path)
+ return NULL;
gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store), &iter, path);
gtk_tree_path_free(path);
gtk_tree_model_get(GTK_TREE_MODEL(folderview->store), &iter,
@@ -669,6 +675,8 @@ void folderview_update_opened_msg_num(FolderView *folderview)
return;
path = gtk_tree_row_reference_get_path(folderview->opened);
+ if (!path)
+ return;
gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store), &iter, path);
gtk_tree_path_free(path);
@@ -1540,7 +1548,8 @@ static gboolean folderview_key_pressed(GtkWidget *widget, GdkEventKey *event,
(folderview->opened);
selected = gtk_tree_row_reference_get_path
(folderview->selected);
- if (gtk_tree_path_compare(opened, selected) == 0 &&
+ if (opened && selected &&
+ gtk_tree_path_compare(opened, selected) == 0 &&
(!folderview->summaryview->folder_item ||
folderview->summaryview->folder_item->total == 0))
folderview_select_next_unread(folderview);
@@ -1577,8 +1586,13 @@ static void folderview_selection_changed(GtkTreeSelection *selection,
GtkTreePath *path;
gboolean opened;
- if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
+ if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) {
+ if (folderview->selected) {
+ gtk_tree_row_reference_free(folderview->selected);
+ folderview->selected = NULL;
+ }
return;
+ }
path = gtk_tree_model_get_path(model, &iter);
@@ -1611,7 +1625,7 @@ static void folderview_selection_changed(GtkTreeSelection *selection,
GtkTreePath *open_path = NULL;
open_path = gtk_tree_row_reference_get_path(folderview->opened);
- if (gtk_tree_path_compare(open_path, path) == 0) {
+ if (open_path && gtk_tree_path_compare(open_path, path) == 0) {
gtk_tree_path_free(open_path);
gtk_tree_path_free(path);
return;
@@ -1700,6 +1714,8 @@ static void folderview_popup_close(GtkMenuShell *menu_shell,
if (!folderview->opened) return;
path = gtk_tree_row_reference_get_path(folderview->opened);
+ if (!path)
+ return;
gtk_tree_view_set_cursor(GTK_TREE_VIEW(folderview->treeview), path,
NULL, FALSE);
gtk_tree_path_free(path);
@@ -1908,11 +1924,14 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
sel_path = gtk_tree_row_reference_get_path(folderview->selected);
open_path = gtk_tree_row_reference_get_path(folderview->opened);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store),
- &iter, sel_path);
- folderview_update_row(folderview, &iter);
- if (gtk_tree_path_compare(open_path, sel_path) == 0 ||
- gtk_tree_path_is_ancestor(sel_path, open_path)) {
+ if (sel_path) {
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store),
+ &iter, sel_path);
+ folderview_update_row(folderview, &iter);
+ }
+ if (sel_path && open_path &&
+ (gtk_tree_path_compare(open_path, sel_path) == 0 ||
+ gtk_tree_path_is_ancestor(sel_path, open_path))) {
GtkTreeRowReference *row;
row = gtk_tree_row_reference_copy(folderview->opened);
@@ -1961,11 +1980,13 @@ static void folderview_delete_folder_cb(FolderView *folderview, guint action,
old_id = folder_item_get_identifier(item);
sel_path = gtk_tree_row_reference_get_path(folderview->selected);
+ g_return_if_fail(sel_path != NULL);
open_path = gtk_tree_row_reference_get_path(folderview->opened);
gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store), &iter,
sel_path);
- if (gtk_tree_path_compare(open_path, sel_path) == 0 ||
- gtk_tree_path_is_ancestor(sel_path, open_path)) {
+ if (sel_path && open_path &&
+ (gtk_tree_path_compare(open_path, sel_path) == 0 ||
+ gtk_tree_path_is_ancestor(sel_path, open_path))) {
summary_clear_all(folderview->summaryview);
gtk_tree_row_reference_free(folderview->opened);
folderview->opened = NULL;
@@ -2018,7 +2039,8 @@ static void folderview_empty_trash_cb(FolderView *folderview, guint action,
sel_path = gtk_tree_row_reference_get_path(folderview->selected);
open_path = gtk_tree_row_reference_get_path(folderview->opened);
- if (gtk_tree_path_compare(open_path, sel_path) == 0)
+ if (open_path && sel_path &&
+ gtk_tree_path_compare(open_path, sel_path) == 0)
gtk_widget_grab_focus(folderview->treeview);
gtk_tree_path_free(open_path);
gtk_tree_path_free(sel_path);
@@ -2060,10 +2082,12 @@ static void folderview_remove_mailbox_cb(FolderView *folderview, guint action,
folder_destroy(item->folder);
sel_path = gtk_tree_row_reference_get_path(folderview->selected);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store), &iter,
- sel_path);
- gtk_tree_path_free(sel_path);
- gtk_tree_store_remove(folderview->store, &iter);
+ if (sel_path) {
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store),
+ &iter, sel_path);
+ gtk_tree_path_free(sel_path);
+ gtk_tree_store_remove(folderview->store, &iter);
+ }
folder_write_list();
}
@@ -2108,10 +2132,12 @@ static void folderview_rm_imap_server_cb(FolderView *folderview, guint action,
account_destroy(account);
sel_path = gtk_tree_row_reference_get_path(folderview->selected);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store), &iter,
- sel_path);
- gtk_tree_path_free(sel_path);
- gtk_tree_store_remove(folderview->store, &iter);
+ if (sel_path) {
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store),
+ &iter, sel_path);
+ gtk_tree_path_free(sel_path);
+ gtk_tree_store_remove(folderview->store, &iter);
+ }
account_set_menu();
main_window_reflect_prefs_all();
@@ -2142,6 +2168,7 @@ static void folderview_new_news_group_cb(FolderView *folderview, guint action,
g_return_if_fail(folder->account != NULL);
server_path = gtk_tree_row_reference_get_path(folderview->selected);
+ g_return_if_fail(server_path != NULL);
gtk_tree_model_get_iter(model, &iter, server_path);
gtk_tree_path_free(server_path);
@@ -2234,10 +2261,12 @@ static void folderview_rm_news_group_cb(FolderView *folderview, guint action,
if (avalue != G_ALERTDEFAULT) return;
sel_path = gtk_tree_row_reference_get_path(folderview->selected);
+ g_return_if_fail(sel_path != NULL);
open_path = gtk_tree_row_reference_get_path(folderview->opened);
gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store), &iter,
sel_path);
- if (gtk_tree_path_compare(open_path, sel_path) == 0) {
+ if (open_path && sel_path &&
+ gtk_tree_path_compare(open_path, sel_path) == 0) {
summary_clear_all(folderview->summaryview);
gtk_tree_row_reference_free(folderview->opened);
folderview->opened = NULL;
@@ -2290,10 +2319,12 @@ static void folderview_rm_news_server_cb(FolderView *folderview, guint action,
account_destroy(account);
sel_path = gtk_tree_row_reference_get_path(folderview->selected);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store), &iter,
- sel_path);
- gtk_tree_path_free(sel_path);
- gtk_tree_store_remove(folderview->store, &iter);
+ if (sel_path) {
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(folderview->store),
+ &iter, sel_path);
+ gtk_tree_path_free(sel_path);
+ gtk_tree_store_remove(folderview->store, &iter);
+ }
account_set_menu();
main_window_reflect_prefs_all();
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 617875e6..be7e4ac5 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -2933,11 +2933,11 @@ static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
if (!mainwin->summaryview->folder_item) return;
if (GTK_CHECK_MENU_ITEM(widget)->active) {
- summary_thread_build(mainwin->summaryview);
mainwin->summaryview->folder_item->threaded = TRUE;
+ summary_thread_build(mainwin->summaryview);
} else {
- summary_unthread(mainwin->summaryview);
mainwin->summaryview->folder_item->threaded = FALSE;
+ summary_unthread(mainwin->summaryview);
}
}
diff --git a/src/summaryview.c b/src/summaryview.c
index 0d8b769d..a2bd00b5 100644
--- a/src/summaryview.c
+++ b/src/summaryview.c
@@ -3128,14 +3128,52 @@ void summary_thread_build(SummaryView *summaryview)
#endif
}
+static void summary_unthread_node_recursive(SummaryView *summaryview,
+ GtkTreeIter *iter,
+ GtkTreeIter *sibling)
+{
+ GtkTreeModel *model = GTK_TREE_MODEL(summaryview->store);
+ GtkTreeIter iter_, child;
+ MsgInfo *msginfo;
+ gboolean valid;
+
+ gtk_tree_model_get(model, iter, S_COL_MSG_INFO, &msginfo, -1);
+ gtk_tree_store_insert_after(GTK_TREE_STORE(model), &iter_,
+ NULL, sibling);
+ summary_set_row(summaryview, &iter_, msginfo);
+ *sibling = iter_;
+
+ valid = gtk_tree_model_iter_children(model, &child, iter);
+
+ while (valid) {
+ summary_unthread_node_recursive(summaryview, &child, sibling);
+ valid = gtk_tree_model_iter_next(model, &child);
+ }
+}
+
+static void summary_unthread_node(SummaryView *summaryview, GtkTreeIter *iter)
+{
+ GtkTreeModel *model = GTK_TREE_MODEL(summaryview->store);
+ GtkTreeIter child, sibling, next;
+ gboolean valid;
+
+ sibling = *iter;
+
+ valid = gtk_tree_model_iter_children(model, &next, iter);
+
+ while (valid) {
+ child = next;
+ valid = gtk_tree_model_iter_next(model, &next);
+ summary_unthread_node_recursive(summaryview, &child, &sibling);
+ gtk_tree_store_remove(GTK_TREE_STORE(model), &child);
+ }
+}
+
void summary_unthread(SummaryView *summaryview)
{
-#if 0
- GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
- GtkCTreeNode *node;
- GtkCTreeNode *child;
- GtkCTreeNode *sibling;
- GtkCTreeNode *next_child;
+ GtkTreeModel *model = GTK_TREE_MODEL(summaryview->store);
+ GtkTreeIter iter, next;
+ gboolean valid;
summary_lock(summaryview);
@@ -3143,34 +3181,19 @@ void summary_unthread(SummaryView *summaryview)
STATUSBAR_PUSH(summaryview->mainwin, _("Unthreading..."));
main_window_cursor_wait(summaryview->mainwin);
- g_signal_handlers_block_by_func(G_OBJECT(ctree),
- G_CALLBACK(summary_tree_collapsed),
- summaryview);
- gtk_clist_freeze(GTK_CLIST(ctree));
-
- for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
- node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
- child = GTK_CTREE_ROW(node)->children;
- sibling = GTK_CTREE_ROW(node)->sibling;
+ valid = gtk_tree_model_get_iter_first(model, &next);
- while (child != NULL) {
- next_child = GTK_CTREE_ROW(child)->sibling;
- gtk_ctree_move(ctree, child, NULL, sibling);
- child = next_child;
- }
+ while (valid) {
+ iter = next;
+ valid = gtk_tree_model_iter_next(model, &next);
+ summary_unthread_node(summaryview, &iter);
}
- gtk_clist_thaw(GTK_CLIST(ctree));
- g_signal_handlers_unblock_by_func(G_OBJECT(ctree),
- G_CALLBACK(summary_tree_collapsed),
- summaryview);
-
debug_print(_("done.\n"));
STATUSBAR_POP(summaryview->mainwin);
main_window_cursor_normal(summaryview->mainwin);
summary_unlock(summaryview);
-#endif
}
static gboolean summary_has_invalid_node(GtkTreeModel *model, GtkTreeIter *iter)
diff --git a/src/utils.c b/src/utils.c
index ed067a6f..4d9257d0 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -2070,15 +2070,13 @@ gint remove_expired_files(const gchar *dir, guint hours)
return 0;
}
-gint remove_dir_recursive(const gchar *dir)
+static gint remove_dir_recursive_real(const gchar *dir)
{
struct stat s;
DIR *dp;
struct dirent *d;
gchar *prev_dir;
- /* g_print("dir = %s\n", dir); */
-
if (stat(dir, &s) < 0) {
FILE_OP_ERROR(dir, "stat");
if (ENOENT == errno) return 0;
@@ -2097,15 +2095,6 @@ gint remove_dir_recursive(const gchar *dir)
prev_dir = g_get_current_dir();
/* g_print("prev_dir = %s\n", prev_dir); */
- if (!path_cmp(prev_dir, dir)) {
- g_free(prev_dir);
- if (chdir("..") < 0) {
- FILE_OP_ERROR(dir, "chdir");
- return -1;
- }
- prev_dir = g_get_current_dir();
- }
-
if (chdir(dir) < 0) {
FILE_OP_ERROR(dir, "chdir");
g_free(prev_dir);
@@ -2128,7 +2117,7 @@ gint remove_dir_recursive(const gchar *dir)
/* g_print("removing %s\n", d->d_name); */
if (dirent_is_directory(d)) {
- if (remove_dir_recursive(d->d_name) < 0) {
+ if (remove_dir_recursive_real(d->d_name) < 0) {
g_warning("can't remove directory\n");
return -1;
}
@@ -2156,6 +2145,38 @@ gint remove_dir_recursive(const gchar *dir)
return 0;
}
+gint remove_dir_recursive(const gchar *dir)
+{
+ gchar *cur_dir;
+ gint ret;
+
+ cur_dir = g_get_current_dir();
+
+ if (chdir(dir) < 0) {
+ FILE_OP_ERROR(dir, "chdir");
+ ret = -1;
+ goto leave;
+ }
+ if (chdir("..") < 0) {
+ FILE_OP_ERROR(dir, "chdir");
+ ret = -1;
+ goto leave;
+ }
+
+ ret = remove_dir_recursive_real(dir);
+
+leave:
+ if (is_dir_exist(cur_dir)) {
+ if (chdir(cur_dir) < 0) {
+ FILE_OP_ERROR(cur_dir, "chdir");
+ }
+ }
+
+ g_free(cur_dir);
+
+ return ret;
+}
+
gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
{
FILE *src_fp, *dest_fp;