2012-04-01 [colin] 3.8.0cvs36
[claws.git] / src / textview.c
index 3aa5feb7111355034f97601b5bfc26a489b94c29..823e0035e93ddddf48767422f106db0cc295675a 100644 (file)
 #include "html.h"
 #include "enriched.h"
 #include "compose.h"
-#include "addressbook.h"
+#ifndef USE_NEW_ADDRBOOK
+       #include "addressbook.h"
+       #include "addrindex.h"
+#else
+       #include "addressbook-dbus.h"
+       #include "addressadd.h"
+#endif
 #include "displayheader.h"
 #include "account.h"
 #include "mimeview.h"
@@ -67,7 +73,6 @@
 #include "inputdialog.h"
 #include "timing.h"
 #include "tags.h"
-#include "addrindex.h"
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
@@ -370,7 +375,6 @@ TextView *textview_create(void)
        textview->text               = text;
        textview->uri_list           = NULL;
        textview->body_pos           = 0;
-       textview->show_all_headers   = FALSE;
        textview->last_buttonpress   = GDK_NOTHING;
        textview->image              = NULL;
        return textview;
@@ -504,7 +508,6 @@ void textview_init(TextView *textview)
                watch_cursor = gdk_cursor_new(GDK_WATCH);
 
        textview_reflect_prefs(textview);
-       textview_set_all_headers(textview, FALSE);
        textview_set_font(textview, NULL);
        textview_create_tags(GTK_TEXT_VIEW(textview->text), textview);
 }
@@ -864,6 +867,24 @@ void textview_show_error(TextView *textview)
        textview_show_icon(textview, GTK_STOCK_DIALOG_ERROR);
 }
 
+void textview_show_info(TextView *textview, const gchar *info_str)
+{
+       GtkTextView *text;
+       GtkTextBuffer *buffer;
+       GtkTextIter iter;
+
+       textview_set_font(textview, NULL);
+       textview_clear(textview);
+
+       text = GTK_TEXT_VIEW(textview->text);
+       buffer = gtk_text_view_get_buffer(text);
+       gtk_text_buffer_get_start_iter(buffer, &iter);
+
+       TEXTVIEW_INSERT(info_str);
+       textview_show_icon(textview, GTK_STOCK_DIALOG_INFO);
+       textview_cursor_normal(textview);
+}
+
 void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
 {
        GtkTextView *text;
@@ -1671,11 +1692,6 @@ void textview_destroy(TextView *textview)
        g_free(textview);
 }
 
-void textview_set_all_headers(TextView *textview, gboolean all_headers)
-{
-       textview->show_all_headers = all_headers;
-}
-
 #define CHANGE_TAG_FONT(tagname, font) { \
        tag = gtk_text_tag_table_lookup(tags, tagname); \
        if (tag) \
@@ -1797,7 +1813,7 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
 
        cm_return_val_if_fail(fp != NULL, NULL);
 
-       if (textview->show_all_headers) {
+       if (prefs_common.show_all_headers) {
                headers = procheader_get_header_array_asis(fp);
                sorted_headers = g_ptr_array_new();
                for (i = 0; i < headers->len; i++) {
@@ -1927,6 +1943,7 @@ void textview_show_icon(TextView *textview, const gchar *stock_id)
 #if HAVE_LIBCOMPFACE
 static void textview_show_xface(TextView *textview)
 {
+       GtkAllocation allocation;
        MsgInfo *msginfo = textview->messageview->msginfo;
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
        int x = 0;
@@ -1959,7 +1976,8 @@ static void textview_show_xface(TextView *textview)
 
        gtk_widget_show(textview->image);
        
-       x = textview->text->allocation.width - WIDTH -5;
+       gtk_widget_get_allocation(textview->text, &allocation);
+       x = allocation.width - WIDTH -5;
 
        gtk_text_view_add_child_in_window(text, textview->image, 
                GTK_TEXT_WINDOW_TEXT, x, 5);
@@ -1977,6 +1995,7 @@ bail:
 
 static void textview_save_contact_pic(TextView *textview)
 {
+#ifndef USE_NEW_ADDRBOOK
        MsgInfo *msginfo = textview->messageview->msginfo;
        gchar *filename = NULL;
        GError *error = NULL;
@@ -2000,11 +2019,14 @@ static void textview_save_contact_pic(TextView *textview)
                }
        }
        g_free(filename);
+#else
+       /* new address book */
+#endif
 }
 
 static void textview_show_contact_pic(TextView *textview)
 {
-       GtkAllocation allocation;
+#ifndef USE_NEW_ADDRBOOK
        MsgInfo *msginfo = textview->messageview->msginfo;
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
        int x = 0;
@@ -2056,8 +2078,7 @@ static void textview_show_contact_pic(TextView *textview)
 
        gtk_widget_show(textview->image);
        
-       gtk_widget_get_allocation(textview->text, &allocation);
-       x = allocation.width - WIDTH -5;
+       x = textview->text->allocation.width - WIDTH -5;
 
        gtk_text_view_add_child_in_window(text, textview->image, 
                GTK_TEXT_WINDOW_TEXT, x, 5);
@@ -2069,7 +2090,9 @@ bail:
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        textview->image = NULL;
-       
+#else
+       /* new address book */
+#endif 
 }
 
 static gint textview_tag_cmp_list(gconstpointer a, gconstpointer b)
@@ -2262,6 +2285,23 @@ gboolean textview_scroll_page(TextView *textview, gboolean up)
        return gtkutils_scroll_page(GTK_WIDGET(text), vadj, up);
 }
 
+void textview_scroll_max(TextView *textview, gboolean up)
+{
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
+       GtkTextIter iter;
+       
+       if (up) {
+               gtk_text_buffer_get_start_iter(buffer, &iter);
+               gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview->text),
+                                               &iter, 0.0, TRUE, 0.0, 1.0);
+       
+       } else {
+               gtk_text_buffer_get_end_iter(buffer, &iter);
+               gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview->text),
+                                               &iter, 0.0, TRUE, 0.0, 0.0);
+       }
+}
+
 #define KEY_PRESS_EVENT_STOP() \
        g_signal_stop_emission_by_name(G_OBJECT(widget), \
                                       "key_press_event");
@@ -2279,17 +2319,19 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
 
        switch (event->keyval) {
        case GDK_KEY_Tab:
-       case GDK_KEY_Home:
        case GDK_KEY_Left:
        case GDK_KEY_Up:
        case GDK_KEY_Right:
        case GDK_KEY_Down:
        case GDK_KEY_Page_Up:
        case GDK_KEY_Page_Down:
-       case GDK_KEY_End:
        case GDK_KEY_Control_L:
        case GDK_KEY_Control_R:
                return FALSE;
+       case GDK_KEY_Home:
+       case GDK_KEY_End:
+               textview_scroll_max(textview,(event->keyval == GDK_KEY_Home));
+               return TRUE;
        case GDK_KEY_space:
                if (summaryview)
                        summary_pass_key_press_event(summaryview, event);
@@ -3034,6 +3076,7 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        GtkWidget *image = NULL;
        GdkPixbuf *picture = NULL;
        gboolean use_picture = FALSE;
+
        if (uri == NULL)
                return;
 
@@ -3066,7 +3109,13 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        if (image)
                picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
 
+#ifndef USE_NEW_ADDRBOOK
        addressbook_add_contact( fromname, fromaddress, NULL, picture);
+#else
+       if (addressadd_selection(fromname, fromaddress, NULL, picture)) {
+               debug_print( "addressbook_add_contact - added\n" );
+       }
+#endif
 
        g_free(fromaddress);
        g_free(fromname);