diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-03-01 09:48:05 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-03-01 09:48:05 +0000 |
commit | d6e4a1d2be97b08699b91c4dbc5b758245ae1133 (patch) | |
tree | 6832d9483ceb4d1c5a0a7ac32cac9c257bc4121b /src | |
parent | 3d37a97aededbe418c1906984d8dd2694176bfc6 (diff) |
improved MimeView and file selection dialog.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@135 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r-- | src/filesel.c | 14 | ||||
-rw-r--r-- | src/mainwindow.c | 14 | ||||
-rw-r--r-- | src/mimeview.c | 244 | ||||
-rw-r--r-- | src/mimeview.h | 5 | ||||
-rw-r--r-- | src/summaryview.c | 21 | ||||
-rw-r--r-- | src/summaryview.h | 4 | ||||
-rw-r--r-- | src/textview.c | 58 | ||||
-rw-r--r-- | src/textview.h | 12 |
8 files changed, 239 insertions, 133 deletions
diff --git a/src/filesel.c b/src/filesel.c index eb11a12e..d480bc92 100644 --- a/src/filesel.c +++ b/src/filesel.c @@ -38,15 +38,21 @@ gchar *filesel_select_file(const gchar *title, const gchar *file, static gchar *cwd = NULL; GtkWidget *dialog; gchar *filename = NULL; + gchar *prev_dir; + + if (!cwd) + cwd = g_strdup(startup_dir); + + prev_dir = g_get_current_dir(); + change_dir(cwd); dialog = filesel_create(title, action); - manage_window_set_transient(GTK_WINDOW(dialog)); + change_dir(prev_dir); + g_free(prev_dir); - if (!cwd) - cwd = g_strdup(startup_dir); + manage_window_set_transient(GTK_WINDOW(dialog)); - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), cwd); if (file) gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), file); diff --git a/src/mainwindow.c b/src/mainwindow.c index 3a609fe6..b89c99f2 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -2990,11 +2990,25 @@ static void update_summary_cb(MainWindow *mainwin, guint action, 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) && + mimeview_step(messageview->mimeview, GTK_SCROLL_STEP_BACKWARD)) + return; + summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD); } 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) && + mimeview_step(messageview->mimeview, GTK_SCROLL_STEP_FORWARD)) + return; + summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD); } diff --git a/src/mimeview.c b/src/mimeview.c index 8f1178dd..a75db773 100644 --- a/src/mimeview.c +++ b/src/mimeview.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -72,6 +72,12 @@ static void mimeview_show_message_part (MimeView *mimeview, MimeInfo *partinfo); static void mimeview_show_image_part (MimeView *mimeview, MimeInfo *partinfo); +static void mimeview_show_mime_part (MimeView *mimeview, + MimeInfo *partinfo); +#if USE_GPGME +static void mimeview_show_signature_part (MimeView *mimeview, + MimeInfo *partinfo); +#endif static void mimeview_change_view_type (MimeView *mimeview, MimeViewType type); @@ -186,6 +192,7 @@ MimeView *mimeview_create(void) G_CALLBACK(mimeview_drag_data_get), mimeview); mime_vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_reallocate_redraws(GTK_CONTAINER(mime_vbox), TRUE); paned = gtk_vpaned_new(); gtk_paned_add1(GTK_PANED(paned), scrolledwin); @@ -372,6 +379,30 @@ MimeInfo *mimeview_get_selected_part(MimeView *mimeview) (GTK_CTREE(mimeview->ctree), mimeview->opened); } +gboolean mimeview_step(MimeView *mimeview, GtkScrollType type) +{ + GtkCTree *ctree = GTK_CTREE(mimeview->ctree); + GtkCTreeNode *node; + + if (type == GTK_SCROLL_STEP_FORWARD) { + node = gtkut_ctree_node_next(ctree, mimeview->opened); + if (node) + gtkut_ctree_expand_parent_all(ctree, node); + else + return FALSE; + } else { + if (mimeview->opened) { + node = GTK_CTREE_NODE_PREV(mimeview->opened); + if (!node) return FALSE; + } else + return FALSE; + } + + g_signal_emit_by_name(G_OBJECT(ctree), "scroll_vertical", type, 0.0); + + return TRUE; +} + static void mimeview_set_multipart_tree(MimeView *mimeview, MimeInfo *mimeinfo, GtkCTreeNode *parent) @@ -490,6 +521,144 @@ static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo) g_free(filename); } +static void save_as_button_clicked(GtkWidget *widget, gpointer data) +{ + MimeView *mimeview = (MimeView *)data; + + mimeview_save_as(mimeview); +} + +static void display_as_text_button_clicked(GtkWidget *widget, gpointer data) +{ + MimeView *mimeview = (MimeView *)data; + + mimeview_display_as_text(mimeview); +} + +static void open_button_clicked(GtkWidget *widget, gpointer data) +{ + MimeView *mimeview = (MimeView *)data; + + mimeview_launch(mimeview); +} + +static void open_with_button_clicked(GtkWidget *widget, gpointer data) +{ + MimeView *mimeview = (MimeView *)data; + + mimeview_open_with(mimeview); +} + +static void mimeview_show_mime_part(MimeView *mimeview, MimeInfo *partinfo) +{ + TextView *textview = mimeview->textview; + GtkTextBuffer *buffer; + GtkTextIter iter; + GtkTextChildAnchor *anchor; + GtkWidget *vbbox; + GtkWidget *button; + gchar buf[BUFFSIZE]; + + if (!partinfo) return; + + textview_set_font(textview, NULL); + textview_clear(textview); + + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text)); + gtk_text_buffer_get_start_iter(buffer, &iter); + + gtk_text_buffer_insert(buffer, &iter, + _("Select an action for the attached file:\n"), + -1); + if (partinfo->filename || partinfo->name) + g_snprintf(buf, sizeof(buf), "[%s %s (%d bytes)]\n\n", + partinfo->filename ? partinfo->filename : + partinfo->name, + partinfo->content_type, partinfo->size); + else + g_snprintf(buf, sizeof(buf), "[%s (%d bytes)]\n\n", + partinfo->content_type, partinfo->size); + gtk_text_buffer_insert(buffer, &iter, buf, -1); + + vbbox = gtk_vbutton_box_new(); + gtk_box_set_spacing(GTK_BOX(vbbox), 5); + + button = gtk_button_new_from_stock(GTK_STOCK_OPEN); + gtk_container_add(GTK_CONTAINER(vbbox), button); + g_signal_connect(button, "clicked", G_CALLBACK(open_button_clicked), + mimeview); + button = gtk_button_new_with_mnemonic(_("Open _with...")); + gtk_container_add(GTK_CONTAINER(vbbox), button); + g_signal_connect(button, "clicked", + G_CALLBACK(open_with_button_clicked), mimeview); + button = gtk_button_new_with_mnemonic(_("_Display as text")); + gtk_container_add(GTK_CONTAINER(vbbox), button); + g_signal_connect(button, "clicked", + G_CALLBACK(display_as_text_button_clicked), mimeview); + button = gtk_button_new_with_mnemonic(_("_Save as...")); + gtk_container_add(GTK_CONTAINER(vbbox), button); + g_signal_connect(button, "clicked", G_CALLBACK(save_as_button_clicked), + mimeview); + + gtk_widget_show_all(vbbox); + + anchor = gtk_text_buffer_create_child_anchor(buffer, &iter); + gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview->text), + vbbox, anchor); +} + +#if USE_GPGME +static void check_signature_button_clicked(GtkWidget *widget, gpointer data) +{ + MimeView *mimeview = (MimeView *)data; + + mimeview_check_signature(mimeview); +} + +static void mimeview_show_signature_part(MimeView *mimeview, + MimeInfo *partinfo) +{ + TextView *textview = mimeview->textview; + GtkTextBuffer *buffer; + GtkTextIter iter; + GtkTextChildAnchor *anchor; + GtkWidget *vbbox; + GtkWidget *button; + + if (!partinfo) return; + + textview_set_font(textview, NULL); + textview_clear(textview); + + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text)); + gtk_text_buffer_get_start_iter(buffer, &iter); + + if (partinfo->sigstatus_full) { + gtk_text_buffer_insert + (buffer, &iter, partinfo->sigstatus_full, -1); + return; + } + + gtk_text_buffer_insert + (buffer, &iter, + _("This signature has not been checked yet.\n\n"), -1); + + vbbox = gtk_vbutton_box_new(); + gtk_box_set_spacing(GTK_BOX(vbbox), 5); + + button = gtk_button_new_with_mnemonic(_("_Check signature")); + gtk_container_add(GTK_CONTAINER(vbbox), button); + g_signal_connect(button, "clicked", + G_CALLBACK(check_signature_button_clicked), mimeview); + + gtk_widget_show_all(vbbox); + + anchor = gtk_text_buffer_create_child_anchor(buffer, &iter); + gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview->text), + vbbox, anchor); +} +#endif /* USE_GPGME */ + static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type) { TextView *textview = mimeview->textview; @@ -558,11 +727,10 @@ static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column, #if USE_GPGME if (g_strcasecmp(partinfo->content_type, "application/pgp-signature") == 0) - textview_show_signature_part(mimeview->textview, - partinfo); + mimeview_show_signature_part(mimeview, partinfo); else #endif - textview_show_mime_part(mimeview->textview, partinfo); + mimeview_show_mime_part(mimeview, partinfo); break; } } @@ -635,9 +803,9 @@ static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event, gtk_menu_popup(GTK_MENU(mimeview->popupmenu), NULL, NULL, NULL, NULL, event->button, event->time); + return TRUE; } -#warning FIXME_GTK2 Is it correct? return FALSE; } @@ -649,32 +817,28 @@ void mimeview_pass_key_press_event(MimeView *mimeview, GdkEventKey *event) #define BREAK_ON_MODIFIER_KEY() \ if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break -#warning FIXME_GTK2 -#if 0 -#define KEY_PRESS_EVENT_STOP() \ - if (gtk_signal_n_emissions_by_name \ - (G_OBJECT(ctree), "key_press_event") > 0) { \ - gtk_signal_emit_stop_by_name(G_OBJECT(ctree), \ - "key_press_event"); \ - } -#else #define KEY_PRESS_EVENT_STOP() \ g_signal_stop_emission_by_name(G_OBJECT(ctree), "key_press_event"); -#endif static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event, MimeView *mimeview) { - SummaryView *summaryview; + SummaryView *summaryview = NULL; GtkCTree *ctree = GTK_CTREE(widget); GtkCTreeNode *node; + gboolean mod_pressed; if (!event) return FALSE; if (!mimeview->opened) return FALSE; + if (mimeview->messageview->mainwin) + summaryview = mimeview->messageview->mainwin->summaryview; + mod_pressed = + ((event->state & (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0); + switch (event->keyval) { case GDK_space: - if (textview_scroll_page(mimeview->textview, FALSE)) + if (textview_scroll_page(mimeview->textview, mod_pressed)) return TRUE; node = GTK_CTREE_NODE_NEXT(mimeview->opened); @@ -683,55 +847,31 @@ static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event, gtk_sctree_select(GTK_SCTREE(ctree), node); return TRUE; } + if (summaryview) + summary_pass_key_press_event(summaryview, event); break; case GDK_BackSpace: textview_scroll_page(mimeview->textview, TRUE); return TRUE; case GDK_Return: - textview_scroll_one_line(mimeview->textview, - (event->state & GDK_MOD1_MASK) != 0); - return TRUE; - case GDK_n: - case GDK_N: - BREAK_ON_MODIFIER_KEY(); - if (!GTK_CTREE_NODE_NEXT(mimeview->opened)) break; - KEY_PRESS_EVENT_STOP(); - - g_signal_emit_by_name(G_OBJECT(ctree), "scroll_vertical", - GTK_SCROLL_STEP_FORWARD, 0.0); - return TRUE; - case GDK_p: - case GDK_P: - BREAK_ON_MODIFIER_KEY(); - if (!GTK_CTREE_NODE_PREV(mimeview->opened)) break; - KEY_PRESS_EVENT_STOP(); - - g_signal_emit_by_name(G_OBJECT(ctree), "scroll_vertical", - GTK_SCROLL_STEP_BACKWARD, 0.0); - return TRUE; - case GDK_y: - BREAK_ON_MODIFIER_KEY(); - KEY_PRESS_EVENT_STOP(); - mimeview_save_as(mimeview); + textview_scroll_one_line(mimeview->textview, mod_pressed); return TRUE; case GDK_t: BREAK_ON_MODIFIER_KEY(); KEY_PRESS_EVENT_STOP(); mimeview_display_as_text(mimeview); return TRUE; - case GDK_l: - BREAK_ON_MODIFIER_KEY(); - KEY_PRESS_EVENT_STOP(); - mimeview_launch(mimeview); - return TRUE; + case GDK_Left: + case GDK_Escape: + case GDK_Delete: + if (summaryview) + summary_pass_key_press_event(summaryview, event); + break; default: break; } - if (!mimeview->messageview->mainwin) return FALSE; - summaryview = mimeview->messageview->mainwin->summaryview; - summary_pass_key_press_event(summaryview, event); - return TRUE; + return FALSE; } static void mimeview_drag_data_get(GtkWidget *widget, @@ -959,7 +1099,7 @@ static void mimeview_update_signature_info(MimeView *mimeview) if (g_strcasecmp(partinfo->content_type, "application/pgp-signature") == 0) { mimeview_change_view_type(mimeview, MIMEVIEW_TEXT); - textview_show_signature_part(mimeview->textview, partinfo); + mimeview_show_signature_part(mimeview, partinfo); } } diff --git a/src/mimeview.h b/src/mimeview.h index e2dfb121..de7bf5ff 100644 --- a/src/mimeview.h +++ b/src/mimeview.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -75,6 +75,9 @@ void mimeview_destroy (MimeView *mimeview); MimeInfo *mimeview_get_selected_part (MimeView *mimeview); +gboolean mimeview_step (MimeView *mimeview, + GtkScrollType type); + void mimeview_pass_key_press_event (MimeView *mimeview, GdkEventKey *event); diff --git a/src/summaryview.c b/src/summaryview.c index 92a75593..36dbe9ee 100644 --- a/src/summaryview.c +++ b/src/summaryview.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -2034,23 +2034,23 @@ void summary_reedit(SummaryView *summaryview) compose_reedit(msginfo); } -void summary_step(SummaryView *summaryview, GtkScrollType type) +gboolean summary_step(SummaryView *summaryview, GtkScrollType type) { GtkCTree *ctree = GTK_CTREE(summaryview->ctree); GtkCTreeNode *node; - if (summary_is_locked(summaryview)) return; + if (summary_is_locked(summaryview)) return FALSE; if (type == GTK_SCROLL_STEP_FORWARD) { node = gtkut_ctree_node_next(ctree, summaryview->selected); if (node) gtkut_ctree_expand_parent_all(ctree, node); else - return; + return FALSE; } else { if (summaryview->selected) { node = GTK_CTREE_NODE_PREV(summaryview->selected); - if (!node) return; + if (!node) return FALSE; } } @@ -2063,6 +2063,8 @@ void summary_step(SummaryView *summaryview, GtkScrollType type) gtk_sctree_set_anchor_row (GTK_SCTREE(ctree), GTK_CTREE_NODE(GTK_CLIST(ctree)->selection->data)); + + return TRUE; } void summary_toggle_view(SummaryView *summaryview) @@ -3822,6 +3824,9 @@ static gboolean summary_key_pressed(GtkWidget *widget, GdkEventKey *event, else textview = messageview->textview; + mod_pressed = + ((event->state & (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0); + switch (event->keyval) { case GDK_space: /* Page down or go to the next */ if (summaryview->displayed != summaryview->selected) { @@ -3829,8 +3834,6 @@ static gboolean summary_key_pressed(GtkWidget *widget, GdkEventKey *event, summaryview->selected); break; } - mod_pressed = - ((event->state & (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0); if (mod_pressed) { if (!textview_scroll_page(textview, TRUE)) summary_select_prev_unread(summaryview); @@ -3848,9 +3851,7 @@ static gboolean summary_key_pressed(GtkWidget *widget, GdkEventKey *event, summaryview->selected); break; } - textview_scroll_one_line - (textview, (event->state & - (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0); + textview_scroll_one_line(textview, mod_pressed); break; case GDK_Delete: BREAK_ON_MODIFIER_KEY(); diff --git a/src/summaryview.h b/src/summaryview.h index b577c0f1..50d90658 100644 --- a/src/summaryview.h +++ b/src/summaryview.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -201,7 +201,7 @@ void summary_redisplay_msg (SummaryView *summaryview); void summary_open_msg (SummaryView *summaryview); void summary_view_source (SummaryView *summaryview); void summary_reedit (SummaryView *summaryview); -void summary_step (SummaryView *summaryview, +gboolean summary_step (SummaryView *summaryview, GtkScrollType type); void summary_toggle_view (SummaryView *summaryview); void summary_set_marks_selected (SummaryView *summaryview); diff --git a/src/textview.c b/src/textview.c index 03fd6885..1f221491 100644 --- a/src/textview.c +++ b/src/textview.c @@ -654,9 +654,6 @@ static void textview_add_parts(TextView *textview, MimeInfo *mimeinfo, FILE *fp) } } -#define TEXT_INSERT(str) \ - gtk_text_buffer_insert(buffer, &iter, str, -1) - void textview_show_error(TextView *textview) { GtkTextBuffer *buffer; @@ -667,60 +664,9 @@ void textview_show_error(TextView *textview) buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text)); gtk_text_buffer_get_start_iter(buffer, &iter); - TEXT_INSERT(_("This message can't be displayed.\n")); -} - -void textview_show_mime_part(TextView *textview, MimeInfo *partinfo) -{ - GtkTextBuffer *buffer; - GtkTextIter iter; - - if (!partinfo) return; - - textview_set_font(textview, NULL); - textview_clear(textview); - - buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text)); - gtk_text_buffer_get_start_iter(buffer, &iter); - - TEXT_INSERT(_("To save this part, pop up the context menu with ")); - TEXT_INSERT(_("right click and select `Save as...', ")); - TEXT_INSERT(_("or press `y' key.\n\n")); - - TEXT_INSERT(_("To display this part as a text message, select ")); - TEXT_INSERT(_("`Display as text', or press `t' key.\n\n")); - - TEXT_INSERT(_("To open this part with external program, select ")); - TEXT_INSERT(_("`Open' or `Open with...', ")); - TEXT_INSERT(_("or double-click, or click the center button, ")); - TEXT_INSERT(_("or press `l' key.")); -} - -#if USE_GPGME -void textview_show_signature_part(TextView *textview, MimeInfo *partinfo) -{ - GtkTextBuffer *buffer; - GtkTextIter iter; - - if (!partinfo) return; - - textview_set_font(textview, NULL); - textview_clear(textview); - - buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text)); - gtk_text_buffer_get_start_iter(buffer, &iter); - - if (partinfo->sigstatus_full == NULL) { - TEXT_INSERT(_("This signature has not been checked yet.\n")); - TEXT_INSERT(_("To check it, pop up the context menu with\n")); - TEXT_INSERT(_("right click and select `Check signature'.\n")); - } else { - TEXT_INSERT(partinfo->sigstatus_full); - } + gtk_text_buffer_insert(buffer, &iter, + _("This message can't be displayed.\n"), -1); } -#endif /* USE_GPGME */ - -#undef TEXT_INSERT static void textview_write_body(TextView *textview, MimeInfo *mimeinfo, FILE *fp, const gchar *charset) diff --git a/src/textview.h b/src/textview.h index 1fcc3ce4..0a017aec 100644 --- a/src/textview.h +++ b/src/textview.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,7 +43,6 @@ struct _TextView GSList *uri_list; gint body_pos; - //gint cur_pos; gboolean show_all_headers; @@ -59,20 +58,17 @@ void textview_show_part (TextView *textview, MimeInfo *mimeinfo, FILE *fp); void textview_show_error (TextView *textview); -void textview_show_mime_part (TextView *textview, - MimeInfo *partinfo); -#if USE_GPGME -void textview_show_signature_part(TextView *textview, - MimeInfo *partinfo); -#endif + void textview_clear (TextView *textview); void textview_destroy (TextView *textview); + void textview_set_all_headers (TextView *textview, gboolean all_headers); void textview_set_font (TextView *textview, const gchar *codeset); void textview_set_position (TextView *textview, gint pos); + void textview_scroll_one_line (TextView *textview, gboolean up); gboolean textview_scroll_page (TextView *textview, |