1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* 3 * Pan - A Newsreader for Gtk+ 4 * Copyright (C) 2002-2006 Charles Kerr <charles@rebelbase.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; version 2 of the License. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 #ifndef _BodyPane_h_ 21 #define _BodyPane_h_ 22 23 #include "gtk-compat.h" 24 #include <gmime/gmime.h> 25 #include <pan/general/quark.h> 26 #include <pan/usenet-utils/text-massager.h> 27 #include <pan/data/article.h> 28 #include <pan/data/article-cache.h> 29 #include <pan/data/data.h> 30 #include <pan/gui/header-pane.h> 31 #include "prefs.h" 32 #include "group-prefs.h" 33 34 namespace pan 35 { 36 /** 37 * Body Pane in the main window of Pan's GUI. 38 * @ingroup GUI 39 */ 40 class BodyPane: private Prefs::Listener 41 { 42 43 private: 44 Prefs& _prefs; 45 GroupPrefs& _group_prefs; 46 Queue& _queue; 47 HeaderPane* _header_pane; 48 Data& _data; 49 ArticleCache& _cache; 50 51 static gboolean on_verbose_tooltip_cb(GtkWidget *widget, 52 gint x, 53 gint y, 54 gboolean keyboard_tip, 55 GtkTooltip *tooltip, 56 gpointer data); 57 58 public: 59 BodyPane (Data&, ArticleCache&, Prefs&, GroupPrefs&, Queue&, HeaderPane*); 60 ~BodyPane () ; root()61 GtkWidget* root () { return _root; } get_default_focus_widget()62 GtkWidget* get_default_focus_widget() { return _text; } 63 64 private: 65 virtual void on_prefs_flag_changed (const StringView& key, bool value); on_prefs_int_changed(const StringView & key G_GNUC_UNUSED,int value G_GNUC_UNUSED)66 virtual void on_prefs_int_changed (const StringView& key G_GNUC_UNUSED, int value G_GNUC_UNUSED) { } 67 virtual void on_prefs_string_changed (const StringView& key, const StringView& value); 68 virtual void on_prefs_color_changed (const StringView& key, const GdkColor& color); 69 70 public: 71 void set_article (const Article&); 72 void clear (); read_more()73 bool read_more () { return read_more_or_less(true); } read_less()74 bool read_less () { return read_more_or_less(false); } 75 void rot13_selected_text (); 76 void select_all (); 77 GMimeMessage* create_followup_or_reply (bool is_reply); 78 79 public: get_message_id()80 Quark get_message_id () const { 81 return _article.message_id; 82 } get_message()83 GMimeMessage* get_message () { 84 if (_message) 85 g_object_ref (_message); 86 return _message; 87 } 88 89 90 public: 91 enum MenuSelection 92 { 93 MENU_SAVE_AS, 94 MENU_SAVE_ALL 95 }; 96 97 public: 98 void set_character_encoding (const char * character_encoding); 99 100 public: 101 void set_text_from_message (GMimeMessage*); 102 103 private: 104 void refresh (); 105 void refresh_fonts (); 106 void refresh_colors (); 107 bool read_more_or_less (bool more); 108 char* body_to_utf8 (GMimePart*); 109 void append_part (GMimeObject*, GMimeObject*, GtkAllocation*); 110 static gboolean expander_activated_idle (gpointer self); 111 static void expander_activated_cb (GtkExpander*, gpointer self); 112 static void verbose_clicked_cb (GtkWidget*, GdkEvent *event, gpointer self_gpointer); 113 static void foreach_part_cb (GMimeObject*, GMimeObject*, gpointer self); 114 static void text_size_allocated (GtkWidget*, GtkAllocation*, gpointer); 115 static gboolean text_size_allocated_idle_cb (gpointer p); 116 void text_size_allocated_idle (); 117 void refresh_scroll_visible_state (); 118 static gboolean show_idle_cb (gpointer p); 119 static void show_cb (GtkWidget*, gpointer); 120 static void populate_popup_cb (GtkTextView*, GtkMenu*, gpointer); 121 void populate_popup (GtkTextView*, GtkMenu*); 122 static void copy_url_cb (GtkMenuItem*, gpointer); 123 void copy_url (); 124 125 GtkWidget* create_attachments_toolbar(GtkWidget*); 126 127 private: 128 #ifdef HAVE_WEBKIT 129 void set_html_text (const char* text); 130 GtkWidget* _web_view; 131 #endif 132 private: 133 void add_attachment_to_toolbar (const char* fn); 134 void clear_attachments(); 135 GtkWidget* new_attachment (const char* filename); 136 137 static gboolean mouse_button_pressed_cb (GtkWidget*, GdkEventButton*, gpointer); 138 gboolean mouse_button_pressed (GtkWidget*, GdkEventButton*); 139 void menu_clicked (const MenuSelection& ms); 140 static void menu_clicked_as_cb (GtkWidget* w, gpointer p); 141 static void menu_clicked_all_cb (GtkWidget* w, gpointer p); 142 143 private: 144 std::string _hover_url; 145 GtkWidget * _expander; 146 GtkWidget * _terse; 147 GtkWidget * _verbose; 148 GtkWidget * _headers; 149 GtkWidget * _xface; 150 GtkWidget * _face; 151 GtkTextBuffer * _buffer; 152 GtkWidget * _root; 153 GtkWidget * _text; 154 GtkWidget * _scroll; 155 GtkWidget * _att_toolbar; 156 GtkWidget * _att_box; 157 bool _hscroll_visible; 158 bool _vscroll_visible; 159 Article _article; 160 GMimeMessage * _message; 161 TextMassager _tm; 162 std::string _charset; 163 #ifdef HAVE_GMIME_CRYPTO 164 GPGDecErr _gpgerr; 165 #endif 166 int _attachments; 167 int _cur_col, _cur_row; 168 std::set<char*> _attach_names; 169 MenuSelection _selection; 170 171 bool _cleared; 172 173 public: set_cleared(bool val)174 void set_cleared(bool val) { _cleared = val; } get_cleared()175 bool get_cleared() { return _cleared; } 176 177 public: 178 const char* _current_attachment; 179 180 181 public: 182 GtkWidget* _menu; 183 }; 184 } 185 186 #endif 187