| 22 |
22 |
| 23 #include <glib/gi18n-lib.h> |
23 #include <glib/gi18n-lib.h> |
| 24 |
24 |
| 25 #include <purple.h> |
25 #include <purple.h> |
| 26 |
26 |
| 27 #include "pidgin/pidginconversation.h" |
27 #include <talkatu.h> |
| 28 #include "pidgin/pidgininfopane.h" |
28 |
| 29 #include "pidgin/pidginmessage.h" |
29 #include "pidgincolor.h" |
| |
30 #include "pidginconversation.h" |
| |
31 #include "pidgininfopane.h" |
| 30 |
32 |
| 31 #define PIDGIN_CONVERSATION_DATA ("pidgin-conversation") |
33 #define PIDGIN_CONVERSATION_DATA ("pidgin-conversation") |
| 32 |
34 |
| 33 enum { |
35 enum { |
| 34 PROP_0, |
36 PROP_0, |
| 43 PurpleConversation *conversation; |
45 PurpleConversation *conversation; |
| 44 |
46 |
| 45 GtkWidget *info_pane; |
47 GtkWidget *info_pane; |
| 46 GtkWidget *editor; |
48 GtkWidget *editor; |
| 47 GtkWidget *history; |
49 GtkWidget *history; |
| |
50 GtkNoSelection *history_selection; |
| 48 }; |
51 }; |
| 49 |
52 |
| 50 G_DEFINE_TYPE(PidginConversation, pidgin_conversation, GTK_TYPE_BOX) |
53 G_DEFINE_TYPE(PidginConversation, pidgin_conversation, GTK_TYPE_BOX) |
| 51 |
54 |
| 52 /****************************************************************************** |
55 /****************************************************************************** |
| 55 static void |
58 static void |
| 56 pidgin_conversation_set_conversation(PidginConversation *conversation, |
59 pidgin_conversation_set_conversation(PidginConversation *conversation, |
| 57 PurpleConversation *purple_conversation) |
60 PurpleConversation *purple_conversation) |
| 58 { |
61 { |
| 59 if(g_set_object(&conversation->conversation, purple_conversation)) { |
62 if(g_set_object(&conversation->conversation, purple_conversation)) { |
| |
63 GListModel *model = NULL; |
| |
64 |
| 60 if(PURPLE_IS_CONVERSATION(purple_conversation)) { |
65 if(PURPLE_IS_CONVERSATION(purple_conversation)) { |
| 61 g_object_set_data(G_OBJECT(purple_conversation), |
66 g_object_set_data(G_OBJECT(purple_conversation), |
| 62 PIDGIN_CONVERSATION_DATA, conversation); |
67 PIDGIN_CONVERSATION_DATA, conversation); |
| |
68 model = purple_conversation_get_messages(purple_conversation); |
| 63 } |
69 } |
| |
70 |
| |
71 gtk_no_selection_set_model(conversation->history_selection, model); |
| 64 |
72 |
| 65 pidgin_info_pane_set_conversation(PIDGIN_INFO_PANE(conversation->info_pane), |
73 pidgin_info_pane_set_conversation(PIDGIN_INFO_PANE(conversation->info_pane), |
| 66 purple_conversation); |
74 purple_conversation); |
| 67 |
75 |
| 68 g_object_notify_by_pspec(G_OBJECT(conversation), |
76 g_object_notify_by_pspec(G_OBJECT(conversation), |
| 96 if(conversation == us) { |
104 if(conversation == us) { |
| 97 g_object_set_data(G_OBJECT(conversation->conversation), |
105 g_object_set_data(G_OBJECT(conversation->conversation), |
| 98 PIDGIN_CONVERSATION_DATA, NULL); |
106 PIDGIN_CONVERSATION_DATA, NULL); |
| 99 } |
107 } |
| 100 } |
108 } |
| |
109 } |
| |
110 |
| |
111 static PangoAttrList * |
| |
112 pidgin_conversation_get_author_attributes(G_GNUC_UNUSED GObject *self, |
| |
113 PurpleMessage *message, |
| |
114 G_GNUC_UNUSED gpointer data) |
| |
115 { |
| |
116 const char *author = NULL; |
| |
117 const char *custom_color = NULL; |
| |
118 GdkRGBA rgba; |
| |
119 PangoAttrList *attrs = NULL; |
| |
120 gboolean color_valid = FALSE; |
| |
121 |
| |
122 if(!PURPLE_IS_MESSAGE(message)) { |
| |
123 return NULL; |
| |
124 } |
| |
125 |
| |
126 author = purple_message_get_author_alias(message); |
| |
127 if(purple_strempty(author)) { |
| |
128 author = purple_message_get_author(message); |
| |
129 } |
| |
130 |
| |
131 custom_color = purple_message_get_author_name_color(message); |
| |
132 if(!purple_strempty(custom_color)) { |
| |
133 color_valid = gdk_rgba_parse(&rgba, custom_color); |
| |
134 } |
| |
135 |
| |
136 if(!color_valid) { |
| |
137 pidgin_color_calculate_for_text(author, &rgba); |
| |
138 color_valid = TRUE; |
| |
139 } |
| |
140 |
| |
141 attrs = pango_attr_list_new(); |
| |
142 |
| |
143 if(color_valid) { |
| |
144 PangoAttribute *attr = NULL; |
| |
145 |
| |
146 attr = pango_attr_foreground_new(0xFFFF * rgba.red, |
| |
147 0xFFFF * rgba.green, |
| |
148 0xFFFF * rgba.blue); |
| |
149 pango_attr_list_insert(attrs, attr); |
| |
150 } |
| |
151 |
| |
152 return attrs; |
| |
153 } |
| |
154 |
| |
155 static char * |
| |
156 pidgin_converation_get_timestamp_string(G_GNUC_UNUSED GObject *self, |
| |
157 PurpleMessage *message, |
| |
158 G_GNUC_UNUSED gpointer data) |
| |
159 { |
| |
160 GDateTime *timestamp = NULL; |
| |
161 |
| |
162 if(!PURPLE_IS_MESSAGE(message)) { |
| |
163 return NULL; |
| |
164 } |
| |
165 |
| |
166 timestamp = purple_message_get_timestamp(message); |
| |
167 if(timestamp != NULL) { |
| |
168 return g_date_time_format(timestamp, "%I:%M %p"); |
| |
169 } |
| |
170 |
| |
171 return NULL; |
| 101 } |
172 } |
| 102 |
173 |
| 103 /****************************************************************************** |
174 /****************************************************************************** |
| 104 * GObject Implementation |
175 * GObject Implementation |
| 105 *****************************************************************************/ |
176 *****************************************************************************/ |
| 187 info_pane); |
258 info_pane); |
| 188 gtk_widget_class_bind_template_child(widget_class, PidginConversation, |
259 gtk_widget_class_bind_template_child(widget_class, PidginConversation, |
| 189 editor); |
260 editor); |
| 190 gtk_widget_class_bind_template_child(widget_class, PidginConversation, |
261 gtk_widget_class_bind_template_child(widget_class, PidginConversation, |
| 191 history); |
262 history); |
| |
263 gtk_widget_class_bind_template_child(widget_class, PidginConversation, |
| |
264 history_selection); |
| 192 |
265 |
| 193 gtk_widget_class_bind_template_callback(widget_class, |
266 gtk_widget_class_bind_template_callback(widget_class, |
| 194 pidgin_conversation_send_message_cb); |
267 pidgin_conversation_send_message_cb); |
| |
268 gtk_widget_class_bind_template_callback(widget_class, |
| |
269 pidgin_conversation_get_author_attributes); |
| |
270 gtk_widget_class_bind_template_callback(widget_class, |
| |
271 pidgin_converation_get_timestamp_string); |
| 195 } |
272 } |
| 196 |
273 |
| 197 /****************************************************************************** |
274 /****************************************************************************** |
| 198 * API |
275 * API |
| 199 *****************************************************************************/ |
276 *****************************************************************************/ |
| 221 |
298 |
| 222 return conversation->conversation; |
299 return conversation->conversation; |
| 223 } |
300 } |
| 224 |
301 |
| 225 void |
302 void |
| 226 pidgin_conversation_write_message(PidginConversation *conversation, |
|
| 227 PurpleMessage *purple_message) |
|
| 228 { |
|
| 229 PidginMessage *message = NULL; |
|
| 230 |
|
| 231 g_return_if_fail(PIDGIN_IS_CONVERSATION(conversation)); |
|
| 232 g_return_if_fail(PURPLE_IS_MESSAGE(purple_message)); |
|
| 233 |
|
| 234 message = pidgin_message_new(purple_message); |
|
| 235 |
|
| 236 talkatu_history_write_message(TALKATU_HISTORY(conversation->history), |
|
| 237 TALKATU_MESSAGE(message)); |
|
| 238 |
|
| 239 g_clear_object(&message); |
|
| 240 } |
|
| 241 |
|
| 242 void |
|
| 243 pidgin_conversation_close(PidginConversation *conversation) { |
303 pidgin_conversation_close(PidginConversation *conversation) { |
| 244 g_return_if_fail(PIDGIN_IS_CONVERSATION(conversation)); |
304 g_return_if_fail(PIDGIN_IS_CONVERSATION(conversation)); |
| 245 |
305 |
| 246 pidgin_conversation_detach(conversation); |
306 pidgin_conversation_detach(conversation); |
| 247 } |
307 } |