aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-05-23 07:00:00 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-05-23 07:00:00 +0000
commit4de3bf7e2d642919f72c87b6613e306fa6f2308b (patch)
tree3827379e0904cc8346abef466483aebbd75fdac0
parent712d73a94ee8c8fd79141c1019d082a056a6bb29 (diff)
reimplemented MimeView with GtkTreeView.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@275 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog7
-rw-r--r--ChangeLog.ja7
-rw-r--r--src/mainwindow.c6
-rw-r--r--src/mimeview.c431
-rw-r--r--src/mimeview.h13
-rw-r--r--src/summaryview.c3
-rw-r--r--src/textview.c2
7 files changed, 291 insertions, 178 deletions
diff --git a/ChangeLog b/ChangeLog
index 7d56a746..f3b92d39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-05-23
+
+ * src/textview.c
+ src/mimeview.[ch]
+ src/summaryview.c
+ src/mainwindow.c: reimplemented MimeView with GtkTreeView.
+
2005-05-20
* src/summaryview.c: summary_show(): fixed the selection state on
diff --git a/ChangeLog.ja b/ChangeLog.ja
index 1d29f200..1f6b7415 100644
--- a/ChangeLog.ja
+++ b/ChangeLog.ja
@@ -1,3 +1,10 @@
+2005-05-23
+
+ * src/textview.c
+ src/mimeview.[ch]
+ src/summaryview.c
+ src/mainwindow.c: MimeView を GtkTreeView で再実装。
+
2005-05-20
* src/summaryview.c: summary_show(): 更新時の選択状態を修正。
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 91c23a70..89827960 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -2630,7 +2630,7 @@ static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
MessageView *messageview = mainwin->messageview;
if (messageview_get_selected_mime_part(messageview) &&
- GTK_WIDGET_HAS_FOCUS(messageview->mimeview->ctree))
+ GTK_WIDGET_HAS_FOCUS(messageview->mimeview->treeview))
mimeview_save_as(messageview->mimeview);
else
summary_save_as(mainwin->summaryview);
@@ -3030,7 +3030,7 @@ static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
MessageView *messageview = mainwin->messageview;
if (messageview_get_selected_mime_part(messageview) &&
- GTK_WIDGET_HAS_FOCUS(messageview->mimeview->ctree) &&
+ GTK_WIDGET_HAS_FOCUS(messageview->mimeview->treeview) &&
mimeview_step(messageview->mimeview, GTK_SCROLL_STEP_BACKWARD))
return;
@@ -3042,7 +3042,7 @@ static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
MessageView *messageview = mainwin->messageview;
if (messageview_get_selected_mime_part(messageview) &&
- GTK_WIDGET_HAS_FOCUS(messageview->mimeview->ctree) &&
+ GTK_WIDGET_HAS_FOCUS(messageview->mimeview->treeview) &&
mimeview_step(messageview->mimeview, GTK_SCROLL_STEP_FORWARD))
return;
diff --git a/src/mimeview.c b/src/mimeview.c
index fdc41417..40d2fb14 100644
--- a/src/mimeview.c
+++ b/src/mimeview.c
@@ -27,7 +27,10 @@
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkscrolledwindow.h>
-#include <gtk/gtkctree.h>
+#include <gtk/gtktreestore.h>
+#include <gtk/gtktreeview.h>
+#include <gtk/gtktreeselection.h>
+#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtkvpaned.h>
#include <gtk/gtksignal.h>
@@ -35,6 +38,7 @@
#include <gtk/gtkdnd.h>
#include <gtk/gtkselection.h>
#include <gtk/gtknotebook.h>
+#include <gtk/gtkvbbox.h>
#include <stdio.h>
#include <unistd.h>
@@ -52,23 +56,23 @@
#include "gtkutils.h"
#include "prefs_common.h"
#include "rfc2015.h"
-#include "gtksctree.h"
-typedef enum
+enum
{
- COL_MIMETYPE = 0,
- COL_SIZE = 1,
- COL_NAME = 2
-} MimeViewColumnPos;
-
-#define N_MIMEVIEW_COLS 3
+ COL_MIMETYPE,
+ COL_SIZE,
+ COL_NAME,
+ COL_MIME_INFO,
+ N_COLS
+};
static void mimeview_set_multipart_tree (MimeView *mimeview,
MimeInfo *mimeinfo,
- GtkCTreeNode *parent);
-static GtkCTreeNode *mimeview_append_part (MimeView *mimeview,
+ GtkTreeIter *parent);
+static gboolean mimeview_append_part (MimeView *mimeview,
MimeInfo *partinfo,
- GtkCTreeNode *parent);
+ GtkTreeIter *iter,
+ GtkTreeIter *parent);
static void mimeview_show_message_part (MimeView *mimeview,
MimeInfo *partinfo);
static void mimeview_show_image_part (MimeView *mimeview,
@@ -82,14 +86,9 @@ static void mimeview_show_signature_part (MimeView *mimeview,
static void mimeview_change_view_type (MimeView *mimeview,
MimeViewType type);
-static void mimeview_selected (GtkCTree *ctree,
- GtkCTreeNode *node,
- gint column,
- MimeView *mimeview);
-static void mimeview_start_drag (GtkWidget *widget,
- gint button,
- GdkEvent *event,
- MimeView *mimeview);
+static void mimeview_selection_changed (GtkTreeSelection *selection,
+ MimeView *mimeview);
+
static gint mimeview_button_pressed (GtkWidget *widget,
GdkEventButton *event,
MimeView *mimeview);
@@ -97,6 +96,12 @@ static gint mimeview_key_pressed (GtkWidget *widget,
GdkEventKey *event,
MimeView *mimeview);
+static void mimeview_drag_begin (GtkWidget *widget,
+ GdkDragContext *drag_context,
+ MimeView *mimeview);
+static void mimeview_drag_end (GtkWidget *widget,
+ GdkDragContext *drag_context,
+ MimeView *mimeview);
static void mimeview_drag_data_get (GtkWidget *widget,
GdkDragContext *drag_context,
GtkSelectionData *selection_data,
@@ -137,48 +142,83 @@ MimeView *mimeview_create(void)
GtkWidget *paned;
GtkWidget *scrolledwin;
- GtkWidget *ctree;
+ GtkWidget *treeview;
+ GtkTreeStore *store;
+ GtkTreeSelection *selection;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *renderer;
GtkWidget *mime_vbox;
GtkWidget *popupmenu;
GtkItemFactory *popupfactory;
- gchar *titles[N_MIMEVIEW_COLS];
gint n_entries;
- gint i;
debug_print(_("Creating MIME view...\n"));
mimeview = g_new0(MimeView, 1);
- titles[COL_MIMETYPE] = _("MIME Type");
- titles[COL_SIZE] = _("Size");
- titles[COL_NAME] = _("Name");
-
scrolledwin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
+ GTK_SHADOW_IN);
gtk_widget_set_size_request(scrolledwin, -1, 80);
- ctree = gtk_sctree_new_with_titles(N_MIMEVIEW_COLS, 0, titles);
- gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
- gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_NONE);
- gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_SIZE,
- GTK_JUSTIFY_RIGHT);
- gtk_clist_set_column_width(GTK_CLIST(ctree), COL_MIMETYPE, 240);
- gtk_clist_set_column_width(GTK_CLIST(ctree), COL_SIZE, 64);
- for (i = 0; i < N_MIMEVIEW_COLS; i++)
- GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
- GTK_CAN_FOCUS);
- gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
-
- g_signal_connect(G_OBJECT(ctree), "tree_select_row",
- G_CALLBACK(mimeview_selected), mimeview);
- g_signal_connect(G_OBJECT(ctree), "button_press_event",
+ store = gtk_tree_store_new(N_COLS, G_TYPE_STRING, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_POINTER);
+
+ treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+ g_object_unref(G_OBJECT(store));
+ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE);
+ gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
+ gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), COL_NAME);
+ gtk_tree_view_set_reorderable(GTK_TREE_VIEW(treeview), FALSE);
+
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
+ gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
+
+ gtk_container_add(GTK_CONTAINER(scrolledwin), treeview);
+
+ renderer = gtk_cell_renderer_text_new();
+ g_object_set(renderer, "ypad", 0, NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ (_("MIME Type"), renderer, "text", COL_MIMETYPE, NULL);
+ gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+ gtk_tree_view_column_set_resizable(column, TRUE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ renderer = gtk_cell_renderer_text_new();
+ g_object_set(renderer, "xalign", 1.0, "ypad", 0, NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Size"), renderer, "text", COL_SIZE, NULL);
+ gtk_tree_view_column_set_alignment(column, 1.0);
+ gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+ gtk_tree_view_column_set_resizable(column, TRUE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ renderer = gtk_cell_renderer_text_new();
+ g_object_set(renderer, "ypad", 0, NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Name"), renderer, "text", COL_NAME, NULL);
+ gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+ gtk_tree_view_column_set_resizable(column, TRUE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ gtk_tree_view_enable_model_drag_source
+ (GTK_TREE_VIEW(treeview), 0, mimeview_mime_types, 1,
+ GDK_ACTION_COPY);
+
+ g_signal_connect(G_OBJECT(selection), "changed",
+ G_CALLBACK(mimeview_selection_changed), mimeview);
+ g_signal_connect(G_OBJECT(treeview), "button_press_event",
G_CALLBACK(mimeview_button_pressed), mimeview);
- g_signal_connect(G_OBJECT(ctree), "key_press_event",
+ g_signal_connect(G_OBJECT(treeview), "key_press_event",
G_CALLBACK(mimeview_key_pressed), mimeview);
- g_signal_connect(G_OBJECT (ctree),"start_drag",
- G_CALLBACK (mimeview_start_drag), mimeview);
- g_signal_connect(G_OBJECT(ctree), "drag_data_get",
+
+ g_signal_connect_after(G_OBJECT (treeview),"drag-begin",
+ G_CALLBACK (mimeview_drag_begin), mimeview);
+ g_signal_connect(G_OBJECT (treeview),"drag-end",
+ G_CALLBACK (mimeview_drag_end), mimeview);
+ g_signal_connect(G_OBJECT(treeview), "drag-data-get",
G_CALLBACK(mimeview_drag_data_get), mimeview);
mime_vbox = gtk_vbox_new(FALSE, 0);
@@ -195,7 +235,9 @@ MimeView *mimeview_create(void)
mimeview->paned = paned;
mimeview->scrolledwin = scrolledwin;
- mimeview->ctree = ctree;
+ mimeview->treeview = treeview;
+ mimeview->store = store;
+ mimeview->selection = selection;
mimeview->mime_vbox = mime_vbox;
mimeview->popupmenu = popupmenu;
mimeview->popupfactory = popupfactory;
@@ -257,15 +299,16 @@ static void set_unchecked_signature(MimeInfo *mimeinfo)
g_free(signedinfo[1]->sigstatus_full);
signedinfo[1]->sigstatus_full = NULL;
- g_free(signedinfo);
+ g_free(signedinfo);
}
#endif /* USE_GPGME */
void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
const gchar *file)
{
- GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
- GtkCTreeNode *node;
+ GtkTreeModel *model = GTK_TREE_MODEL(mimeview->store);
+ GtkTreeIter iter;
+ gboolean valid;
mimeview_clear(mimeview);
textview_clear(mimeview->messageview->textview);
@@ -292,19 +335,22 @@ void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
#endif
g_signal_handlers_block_by_func
- (G_OBJECT(ctree), G_CALLBACK(mimeview_selected), mimeview);
+ (G_OBJECT(mimeview->selection),
+ G_CALLBACK(mimeview_selection_changed), mimeview);
mimeview_set_multipart_tree(mimeview, mimeinfo, NULL);
+ gtk_tree_view_expand_all(GTK_TREE_VIEW(mimeview->treeview));
g_signal_handlers_unblock_by_func
- (G_OBJECT(ctree), G_CALLBACK(mimeview_selected), mimeview);
+ (G_OBJECT(mimeview->selection),
+ G_CALLBACK(mimeview_selection_changed), mimeview);
/* search first text part */
- for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
- node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
+ for (valid = gtk_tree_model_get_iter_first(model, &iter); valid;
+ valid = gtkut_tree_model_next(model, &iter)) {
MimeInfo *partinfo;
- partinfo = gtk_ctree_node_get_row_data(ctree, node);
+ gtk_tree_model_get(model, &iter, COL_MIME_INFO, &partinfo, -1);
if (partinfo &&
(partinfo->mime_type == MIME_TEXT ||
partinfo->mime_type == MIME_TEXT_HTML))
@@ -312,28 +358,31 @@ void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
}
textview_show_message(mimeview->messageview->textview, mimeinfo, file);
- if (!node)
- node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
+ if (!valid)
+ valid = gtk_tree_model_get_iter_first(model, &iter);
+
+ if (valid) {
+ GtkTreePath *path;
- if (node) {
- gtk_ctree_select(ctree, node);
- gtkut_ctree_set_focus_row(ctree, node);
+ path = gtk_tree_model_get_path(model, &iter);
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(mimeview->treeview),
+ path, NULL, FALSE);
+ gtk_tree_path_free(path);
if (mimeview_get_selected_part(mimeview))
- gtk_widget_grab_focus(mimeview->ctree);
+ gtk_widget_grab_focus(mimeview->treeview);
}
}
void mimeview_clear(MimeView *mimeview)
{
- GtkCList *clist = GTK_CLIST(mimeview->ctree);
-
procmime_mimeinfo_free_all(mimeview->mimeinfo);
mimeview->mimeinfo = NULL;
- gtk_clist_clear(clist);
+ gtk_tree_store_clear(mimeview->store);
textview_clear(mimeview->textview);
imageview_clear(mimeview->imageview);
+ gtk_tree_path_free(mimeview->opened);
mimeview->opened = NULL;
g_free(mimeview->file);
@@ -346,48 +395,62 @@ void mimeview_destroy(MimeView *mimeview)
imageview_destroy(mimeview->imageview);
procmime_mimeinfo_free_all(mimeview->mimeinfo);
g_free(mimeview->file);
+ g_free(mimeview->drag_file);
g_free(mimeview);
}
MimeInfo *mimeview_get_selected_part(MimeView *mimeview)
{
+ GtkTreeModel *model = GTK_TREE_MODEL(mimeview->store);
+ GtkTreeIter iter;
+ MimeInfo *partinfo = NULL;
+
+ if (!mimeview->opened)
+ return NULL;
if (gtk_notebook_get_current_page
(GTK_NOTEBOOK(mimeview->messageview->notebook)) == 0)
return NULL;
- return gtk_ctree_node_get_row_data
- (GTK_CTREE(mimeview->ctree), mimeview->opened);
+ if (gtk_tree_model_get_iter(model, &iter, mimeview->opened))
+ gtk_tree_model_get(model, &iter, COL_MIME_INFO, &partinfo, -1);
+
+ return partinfo;
}
gboolean mimeview_step(MimeView *mimeview, GtkScrollType type)
{
- GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
- GtkCTreeNode *node;
+ GtkTreeView *treeview = GTK_TREE_VIEW(mimeview->treeview);
+ GtkTreeModel *model = GTK_TREE_MODEL(mimeview->store);
+ GtkTreeIter iter;
+ gboolean moved;
+
+ if (!mimeview->opened)
+ return FALSE;
+ if (!gtk_tree_model_get_iter(model, &iter, mimeview->opened))
+ return FALSE;
if (type == GTK_SCROLL_STEP_FORWARD) {
- node = gtkut_ctree_node_next(ctree, mimeview->opened);
- if (node)
- gtkut_ctree_expand_parent_all(ctree, node);
+ if (gtkut_tree_model_next(model, &iter))
+ gtkut_tree_view_expand_parent_all(treeview, &iter);
else
return FALSE;
} else {
- if (mimeview->opened) {
- node = GTK_CTREE_NODE_PREV(mimeview->opened);
- if (!node) return FALSE;
- } else
+ if (!gtkut_tree_model_prev(model, &iter))
return FALSE;
}
- g_signal_emit_by_name(G_OBJECT(ctree), "scroll_vertical", type, 0.0);
+ g_signal_emit_by_name(G_OBJECT(treeview), "move-cursor",
+ GTK_MOVEMENT_DISPLAY_LINES,
+ type == GTK_SCROLL_STEP_FORWARD ? 1 : -1, &moved);
return TRUE;
}
static void mimeview_set_multipart_tree(MimeView *mimeview,
MimeInfo *mimeinfo,
- GtkCTreeNode *parent)
+ GtkTreeIter *parent)
{
- GtkCTreeNode *node;
+ GtkTreeIter iter;
g_return_if_fail(mimeinfo != NULL);
@@ -395,15 +458,15 @@ static void mimeview_set_multipart_tree(MimeView *mimeview,
mimeinfo = mimeinfo->children;
while (mimeinfo != NULL) {
- node = mimeview_append_part(mimeview, mimeinfo, parent);
+ mimeview_append_part(mimeview, mimeinfo, &iter, parent);
if (mimeinfo->children)
- mimeview_set_multipart_tree(mimeview, mimeinfo, node);
+ mimeview_set_multipart_tree(mimeview, mimeinfo, &iter);
else if (mimeinfo->sub &&
mimeinfo->sub->mime_type != MIME_TEXT &&
mimeinfo->sub->mime_type != MIME_TEXT_HTML)
mimeview_set_multipart_tree(mimeview, mimeinfo->sub,
- node);
+ &iter);
mimeinfo = mimeinfo->next;
}
}
@@ -423,25 +486,26 @@ static gchar *get_part_name(MimeInfo *partinfo)
return "";
}
-static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
- MimeInfo *partinfo,
- GtkCTreeNode *parent)
+static gboolean mimeview_append_part(MimeView *mimeview, MimeInfo *partinfo,
+ GtkTreeIter *iter, GtkTreeIter *parent)
{
- GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
- GtkCTreeNode *node;
- gchar *str[N_MIMEVIEW_COLS];
-
- str[COL_MIMETYPE] =
- partinfo->content_type ? partinfo->content_type : "";
- str[COL_SIZE] = to_human_readable(partinfo->size);
- str[COL_NAME] = get_part_name(partinfo);
-
- node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
- NULL, NULL, NULL, NULL,
- FALSE, TRUE);
- gtk_ctree_node_set_row_data(ctree, node, partinfo);
+ gchar *mime_type;
+ gchar *size;
+ gchar *name;
+
+ mime_type = partinfo->content_type ? partinfo->content_type : "";
+ size = to_human_readable(partinfo->size);
+ name = get_part_name(partinfo);
+
+ gtk_tree_store_append(mimeview->store, iter, parent);
+ gtk_tree_store_set(mimeview->store, iter,
+ COL_MIMETYPE, mime_type,
+ COL_SIZE, size,
+ COL_NAME, name,
+ COL_MIME_INFO, partinfo,
+ -1);
- return node;
+ return TRUE;
}
static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
@@ -671,25 +735,38 @@ static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
mimeview->type = type;
}
-static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
- MimeView *mimeview)
+static void mimeview_selection_changed(GtkTreeSelection *selection,
+ MimeView *mimeview)
{
+ GtkTreeModel *model = GTK_TREE_MODEL(mimeview->store);
+ GtkTreeIter iter;
+ GtkTreePath *path;
MimeInfo *partinfo;
- if (mimeview->opened == node) return;
- mimeview->opened = node;
- gtk_ctree_node_moveto(ctree, node, -1, 0.5, 0);
+ if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) {
+ if (mimeview->opened) {
+ gtk_tree_path_free(mimeview->opened);
+ mimeview->opened = NULL;
+ }
+ return;
+ }
- partinfo = gtk_ctree_node_get_row_data(ctree, node);
- if (!partinfo) return;
+ path = gtk_tree_model_get_path(model, &iter);
- /* ungrab the mouse event */
- if (GTK_WIDGET_HAS_GRAB(ctree)) {
- gtk_grab_remove(GTK_WIDGET(ctree));
- if (gdk_pointer_is_grabbed())
- gdk_pointer_ungrab(GDK_CURRENT_TIME);
+ if (mimeview->opened &&
+ gtk_tree_path_compare(mimeview->opened, path) == 0) {
+ gtk_tree_path_free(path);
+ return;
}
+ gtk_tree_path_free(mimeview->opened);
+ mimeview->opened = path;
+ path = NULL;
+
+ gtk_tree_model_get(model, &iter, COL_MIME_INFO, &partinfo, -1);
+ if (!partinfo)
+ return;
+
switch (partinfo->mime_type) {
case MIME_TEXT:
case MIME_TEXT_HTML:
@@ -713,40 +790,22 @@ static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
}
}
-static void mimeview_start_drag(GtkWidget *widget, gint button,
- GdkEvent *event, MimeView *mimeview)
-{
- GtkTargetList *list;
- GdkDragContext *context;
- MimeInfo *partinfo;
-
- g_return_if_fail(mimeview != NULL);
-
- partinfo = mimeview_get_selected_part(mimeview);
- if (partinfo->filename == NULL && partinfo->name == NULL) return;
-
- list = gtk_target_list_new(mimeview_mime_types, 1);
- context = gtk_drag_begin(widget, list,
- GDK_ACTION_COPY, button, event);
- gtk_drag_set_icon_default(context);
-}
-
static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
MimeView *mimeview)
{
- GtkCList *clist = GTK_CLIST(widget);
+ GtkTreeView *treeview = GTK_TREE_VIEW(widget);
MimeInfo *partinfo;
- gint row, column;
if (!event) return FALSE;
if (event->button == 2 || event->button == 3) {
- if (!gtk_clist_get_selection_info(clist, event->x, event->y,
- &row, &column))
+ GtkTreePath *path;
+
+ if (!gtk_tree_view_get_path_at_pos(treeview, event->x, event->y,
+ &path, NULL, NULL, NULL))
return FALSE;
- gtk_clist_unselect_all(clist);
- gtk_clist_select_row(clist, row, column);
- gtkut_clist_set_focus_row(clist, row);
+ gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
+ gtk_tree_path_free(path);
}
if (event->button == 2 ||
@@ -789,25 +848,28 @@ static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
void mimeview_pass_key_press_event(MimeView *mimeview, GdkEventKey *event)
{
- mimeview_key_pressed(mimeview->ctree, event, mimeview);
+ mimeview_key_pressed(mimeview->treeview, event, mimeview);
}
#define BREAK_ON_MODIFIER_KEY() \
if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
#define KEY_PRESS_EVENT_STOP() \
- g_signal_stop_emission_by_name(G_OBJECT(ctree), "key_press_event");
+ g_signal_stop_emission_by_name(G_OBJECT(treeview), "key_press_event");
static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
MimeView *mimeview)
{
SummaryView *summaryview = NULL;
- GtkCTree *ctree = GTK_CTREE(widget);
- GtkCTreeNode *node;
+ GtkTreeView *treeview = GTK_TREE_VIEW(widget);
+ GtkTreeModel *model = GTK_TREE_MODEL(mimeview->store);
+ GtkTreeIter iter;
gboolean mod_pressed;
if (!event) return FALSE;
if (!mimeview->opened) return FALSE;
+ if (!gtk_tree_model_get_iter(model, &iter, mimeview->opened))
+ return FALSE;
if (mimeview->messageview->mainwin)
summaryview = mimeview->messageview->mainwin->summaryview;
@@ -819,10 +881,12 @@ static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
if (textview_scroll_page(mimeview->textview, mod_pressed))
return TRUE;
- node = GTK_CTREE_NODE_NEXT(mimeview->opened);
- if (node) {
- gtk_sctree_unselect_all(GTK_SCTREE(ctree));
- gtk_sctree_select(GTK_SCTREE(ctree), node);
+ if (gtkut_tree_model_next(model, &iter)) {
+ GtkTreePath *path;
+
+ path = gtk_tree_model_get_path(model, &iter);
+ gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
+ gtk_tree_path_free(path);
return TRUE;
}
if (summaryview)
@@ -855,15 +919,11 @@ static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
return FALSE;
}
-static void mimeview_drag_data_get(GtkWidget *widget,
- GdkDragContext *drag_context,
- GtkSelectionData *selection_data,
- guint info,
- guint time,
- MimeView *mimeview)
+static void mimeview_drag_begin(GtkWidget *widget, GdkDragContext *drag_context,
+ MimeView *mimeview)
{
- gchar *filename, *uriname;
- const gchar *bname;
+ gchar *filename;
+ gchar *bname = NULL;
MimeInfo *partinfo;
if (!mimeview->opened) return;
@@ -871,25 +931,54 @@ static void mimeview_drag_data_get(GtkWidget *widget,
partinfo = mimeview_get_selected_part(mimeview);
if (!partinfo) return;
- if (!partinfo->filename && !partinfo->name) return;
filename = partinfo->filename ? partinfo->filename : partinfo->name;
- bname = g_basename(filename);
- if (*bname == '\0') return;
+ if (filename) {
+ const gchar *bname_;
- filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
- bname, NULL);
+ bname_ = g_basename(filename);
+ bname = conv_filename_from_utf8(bname_);
+ subst_for_filename(bname);
+ }
+ if (!bname || *bname == '\0')
+ filename = procmime_get_tmp_file_name(partinfo);
+ else
+ filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
+ bname, NULL);
- if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
- alertpanel_error
- (_("Can't save the part of multipart message."));
+ if (procmime_get_part(filename, mimeview->file, partinfo) < 0) {
+ g_warning(_("Can't save the part of multipart message."));
+ g_free(filename);
+ } else
+ mimeview->drag_file = filename;
+
+ gtk_drag_set_icon_default(drag_context);
+}
+
+static void mimeview_drag_end(GtkWidget *widget, GdkDragContext *drag_context,
+ MimeView *mimeview)
+{
+ if (mimeview->drag_file) {
+ g_free(mimeview->drag_file);
+ mimeview->drag_file = NULL;
+ }
+}
- uriname = g_strconcat("file://", filename, NULL);
+static void mimeview_drag_data_get(GtkWidget *widget,
+ GdkDragContext *drag_context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ MimeView *mimeview)
+{
+ gchar *uriname;
+
+ if (!mimeview->drag_file) return;
+
+ uriname = g_strconcat("file://", mimeview->drag_file, NULL);
gtk_selection_data_set(selection_data, selection_data->target, 8,
uriname, strlen(uriname));
-
g_free(uriname);
- g_free(filename);
}
static void mimeview_display_as_text(MimeView *mimeview)
@@ -1047,24 +1136,26 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
}
#if USE_GPGME
-static void update_node_name(GtkCTree *ctree, GtkCTreeNode *node,
- gpointer data)
+static gboolean update_node_name_func(GtkTreeModel *model, GtkTreePath *path,
+ GtkTreeIter *iter, gpointer data)
{
MimeInfo *partinfo;
gchar *part_name;
- partinfo = gtk_ctree_node_get_row_data(ctree, node);
- g_return_if_fail(partinfo != NULL);
+ gtk_tree_model_get(model, iter, COL_MIME_INFO, &partinfo, -1);
+ g_return_val_if_fail(partinfo != NULL, FALSE);
part_name = get_part_name(partinfo);
- gtk_ctree_node_set_text(ctree, node, COL_NAME, part_name);
+ gtk_tree_store_set(GTK_TREE_STORE(model), iter, COL_NAME, part_name,
+ -1);
+
+ return FALSE;
}
static void mimeview_update_names(MimeView *mimeview)
{
- GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
-
- gtk_ctree_pre_recursive(ctree, NULL, update_node_name, NULL);
+ gtk_tree_model_foreach(GTK_TREE_MODEL(mimeview->store),
+ update_node_name_func, NULL);
}
static void mimeview_update_signature_info(MimeView *mimeview)
diff --git a/src/mimeview.h b/src/mimeview.h
index 7170243e..72d3f6fd 100644
--- a/src/mimeview.h
+++ b/src/mimeview.h
@@ -23,7 +23,9 @@
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtkwidget.h>
-#include <gtk/gtkctree.h>
+#include <gtk/gtktreemodel.h>
+#include <gtk/gtktreestore.h>
+#include <gtk/gtktreeselection.h>
typedef struct _MimeView MimeView;
@@ -43,7 +45,10 @@ struct _MimeView
GtkWidget *paned;
GtkWidget *scrolledwin;
- GtkWidget *ctree;
+ GtkWidget *treeview;
+
+ GtkTreeStore *store;
+ GtkTreeSelection *selection;
GtkWidget *mime_vbox;
@@ -52,7 +57,7 @@ struct _MimeView
GtkWidget *popupmenu;
GtkItemFactory *popupfactory;
- GtkCTreeNode *opened;
+ GtkTreePath *opened;
TextView *textview;
ImageView *imageview;
@@ -62,6 +67,8 @@ struct _MimeView
MimeInfo *mimeinfo;
gchar *file;
+
+ gchar *drag_file;
};
MimeView *mimeview_create (void);
diff --git a/src/summaryview.c b/src/summaryview.c
index 91fc8e32..a2618736 100644
--- a/src/summaryview.c
+++ b/src/summaryview.c
@@ -2082,7 +2082,7 @@ static void summary_display_msg_full(SummaryView *summaryview,
val = messageview_show(msgview, msginfo, all_headers);
if (msgview->type == MVIEW_TEXT ||
(msgview->type == MVIEW_MIME &&
- (GTK_CLIST(msgview->mimeview->ctree)->row_list == NULL ||
+ (msgview->mimeview->opened == NULL ||
gtk_notebook_get_current_page
(GTK_NOTEBOOK(msgview->notebook)) == 0)))
gtk_widget_grab_focus(summaryview->treeview);
@@ -2227,6 +2227,7 @@ gboolean summary_step(SummaryView *summaryview, GtkScrollType type)
if (messageview_is_visible(summaryview->messageview))
summaryview->display_msg = TRUE;
+ gtk_widget_grab_focus(summaryview->treeview);
g_signal_emit_by_name(G_OBJECT(summaryview->treeview), "move-cursor",
GTK_MOVEMENT_DISPLAY_LINES,
type == GTK_SCROLL_STEP_FORWARD ? 1 : -1,
diff --git a/src/textview.c b/src/textview.c
index 55713019..4cf3a533 100644
--- a/src/textview.c
+++ b/src/textview.c
@@ -1577,7 +1577,7 @@ static gboolean textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
gtk_widget_grab_focus(summaryview->treeview);
else if (messageview->type == MVIEW_MIME &&
textview == messageview->mimeview->textview)
- gtk_widget_grab_focus(messageview->mimeview->ctree);
+ gtk_widget_grab_focus(messageview->mimeview->treeview);
break;
case GDK_n:
case GDK_N: