| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
#if HAVE_CONFIG_H |
|---|
| 22 |
#include "config.h" |
|---|
| 23 |
#endif |
|---|
| 24 |
|
|---|
| 25 |
#include <glib/gi18n-lib.h> |
|---|
| 26 |
|
|---|
| 27 |
#include "tmut-msg-creator.h" |
|---|
| 28 |
#include "tmut-account-store.h" |
|---|
| 29 |
|
|---|
| 30 |
#include <tny-iterator.h> |
|---|
| 31 |
#include <tny-list.h> |
|---|
| 32 |
#include <tny-simple-list.h> |
|---|
| 33 |
|
|---|
| 34 |
#include <tny-gtk-account-list-model.h> |
|---|
| 35 |
#include <tny-platform-factory.h> |
|---|
| 36 |
#include <tny-camel-mem-stream.h> |
|---|
| 37 |
#include <tny-camel-send-queue.h> |
|---|
| 38 |
#include <tny-camel-mime-part.h> |
|---|
| 39 |
#include <tny-camel-transport-account.h> |
|---|
| 40 |
|
|---|
| 41 |
#include <string.h> |
|---|
| 42 |
|
|---|
| 43 |
static GObjectClass *parent_class = NULL; |
|---|
| 44 |
|
|---|
| 45 |
typedef struct _TMutMsgCreatorPriv TMutMsgCreatorPriv; |
|---|
| 46 |
|
|---|
| 47 |
struct _TMutMsgCreatorPriv { |
|---|
| 48 |
TMutShellWindow *shell; |
|---|
| 49 |
GtkEntry *subject_entry, *to_entry; |
|---|
| 50 |
GtkTextView *message_textview; |
|---|
| 51 |
GtkButton *send_button, *attachments_button; |
|---|
| 52 |
GtkComboBox *accounts_combo; |
|---|
| 53 |
TnyList *attachments; |
|---|
| 54 |
TnyAccountStore *account_store; |
|---|
| 55 |
gint account_created_signal, account_deleted_signal; |
|---|
| 56 |
}; |
|---|
| 57 |
|
|---|
| 58 |
#define TMUT_MSG_CREATOR_GET_PRIVATE(o) \ |
|---|
| 59 |
(G_TYPE_INSTANCE_GET_PRIVATE ((o), TMUT_TYPE_MSG_CREATOR, TMutMsgCreatorPriv)) |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
#define ATTACH_TXT _("%d attached") |
|---|
| 66 |
|
|---|
| 67 |
typedef struct |
|---|
| 68 |
{ |
|---|
| 69 |
TnySendQueue *send_queue; |
|---|
| 70 |
TnyHeader *header; |
|---|
| 71 |
} OnResponseInfo; |
|---|
| 72 |
|
|---|
| 73 |
static GtkWidget *rem_dialog = NULL; |
|---|
| 74 |
|
|---|
| 75 |
static void |
|---|
| 76 |
on_response (GtkDialog *dialog, gint response, gpointer user_data) |
|---|
| 77 |
{ |
|---|
| 78 |
OnResponseInfo *info = (OnResponseInfo *) user_data; |
|---|
| 79 |
|
|---|
| 80 |
if (response == GTK_RESPONSE_YES) { |
|---|
| 81 |
TnyFolder *outbox = tny_send_queue_get_outbox (info->send_queue); |
|---|
| 82 |
tny_folder_remove_msg (outbox, info->header, NULL); |
|---|
| 83 |
tny_folder_sync (outbox, TRUE, NULL); |
|---|
| 84 |
g_object_unref (outbox); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
g_object_unref (info->send_queue); |
|---|
| 88 |
g_object_unref (info->header); |
|---|
| 89 |
|
|---|
| 90 |
gtk_widget_destroy (GTK_WIDGET (dialog)); |
|---|
| 91 |
rem_dialog = NULL; |
|---|
| 92 |
|
|---|
| 93 |
g_slice_free (OnResponseInfo, info); |
|---|
| 94 |
|
|---|
| 95 |
return; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
static void |
|---|
| 100 |
on_send_queue_error_happened (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, GError *err, gpointer user_data) |
|---|
| 101 |
{ |
|---|
| 102 |
if (header) |
|---|
| 103 |
{ |
|---|
| 104 |
gchar *sub = tny_header_dup_subject (header); |
|---|
| 105 |
gchar *str = g_strdup_printf (_("%s.\nDo you want to remove the message (%s)?"), |
|---|
| 106 |
err->message, sub); |
|---|
| 107 |
|
|---|
| 108 |
g_free (sub); |
|---|
| 109 |
|
|---|
| 110 |
if (!rem_dialog) |
|---|
| 111 |
{ |
|---|
| 112 |
OnResponseInfo *info = g_slice_new (OnResponseInfo); |
|---|
| 113 |
|
|---|
| 114 |
rem_dialog = gtk_message_dialog_new (NULL, |
|---|
| 115 |
0, GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, str); |
|---|
| 116 |
g_free (str); |
|---|
| 117 |
|
|---|
| 118 |
info->send_queue = (TnySendQueue *) g_object_ref (self); |
|---|
| 119 |
info->header = (TnyHeader *) g_object_ref (header); |
|---|
| 120 |
|
|---|
| 121 |
g_signal_connect (G_OBJECT (rem_dialog), "response", |
|---|
| 122 |
G_CALLBACK (on_response), info); |
|---|
| 123 |
|
|---|
| 124 |
gtk_widget_show_all (rem_dialog); |
|---|
| 125 |
} |
|---|
| 126 |
} |
|---|
| 127 |
return; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
static TnySendQueue* |
|---|
| 131 |
get_send_queue_for (TnyAccount *account, TMutMsgCreator *self) |
|---|
| 132 |
{ |
|---|
| 133 |
TnySendQueue *retval; |
|---|
| 134 |
|
|---|
| 135 |
if (!send_queues) |
|---|
| 136 |
send_queues = g_hash_table_new (g_direct_hash, g_direct_equal); |
|---|
| 137 |
|
|---|
| 138 |
retval = g_hash_table_lookup (send_queues, (gconstpointer) account); |
|---|
| 139 |
|
|---|
| 140 |
if (!retval) { |
|---|
| 141 |
TnySendQueue *send_queue = tny_camel_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT (account)); |
|---|
| 142 |
g_signal_connect (G_OBJECT (send_queue), "error-happened", |
|---|
| 143 |
G_CALLBACK (on_send_queue_error_happened), NULL); |
|---|
| 144 |
g_hash_table_insert (send_queues, account, send_queue); |
|---|
| 145 |
retval = send_queue; |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
return TNY_SEND_QUEUE (g_object_ref (retval)); |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
typedef struct { |
|---|
| 152 |
TnyAccount *account; |
|---|
| 153 |
TnyStream *stream; |
|---|
| 154 |
TnySendQueue *send_queue; |
|---|
| 155 |
TnyMsg *msg; |
|---|
| 156 |
TnyList *attachments; |
|---|
| 157 |
} CreateAndSendMsgInfo; |
|---|
| 158 |
|
|---|
| 159 |
static gpointer |
|---|
| 160 |
create_and_send_msg_thread (gpointer user_data) |
|---|
| 161 |
{ |
|---|
| 162 |
CreateAndSendMsgInfo *info = (CreateAndSendMsgInfo *) user_data; |
|---|
| 163 |
|
|---|
| 164 |
if (info->attachments && tny_list_get_length (info->attachments) > 0) { |
|---|
| 165 |
TnyIterator *iter = tny_list_create_iterator (info->attachments); |
|---|
| 166 |
TnyMimePart *msg_part = tny_camel_mime_part_new (); |
|---|
| 167 |
|
|---|
| 168 |
tny_mime_part_construct (msg_part, info->stream, "text/plain", "7bit"); |
|---|
| 169 |
tny_mime_part_add_part (TNY_MIME_PART (info->msg), msg_part); |
|---|
| 170 |
g_object_unref (msg_part); |
|---|
| 171 |
|
|---|
| 172 |
while (!tny_iterator_is_done (iter)) { |
|---|
| 173 |
TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter)); |
|---|
| 174 |
tny_mime_part_add_part (TNY_MIME_PART (info->msg), part); |
|---|
| 175 |
g_object_unref (part); |
|---|
| 176 |
tny_iterator_next (iter); |
|---|
| 177 |
} |
|---|
| 178 |
g_object_unref (iter); |
|---|
| 179 |
} else |
|---|
| 180 |
tny_mime_part_construct (TNY_MIME_PART (info->msg), info->stream, "text/plain", "7bit"); |
|---|
| 181 |
|
|---|
| 182 |
tny_send_queue_add (info->send_queue, info->msg, NULL); |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
if (info->attachments) |
|---|
| 186 |
g_object_unref (info->attachments); |
|---|
| 187 |
g_object_unref (info->send_queue); |
|---|
| 188 |
g_object_unref (info->msg); |
|---|
| 189 |
g_object_unref (info->stream); |
|---|
| 190 |
g_object_unref (info->account); |
|---|
| 191 |
|
|---|
| 192 |
g_slice_free (CreateAndSendMsgInfo, info); |
|---|
| 193 |
|
|---|
| 194 |
return NULL; |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
static void |
|---|
| 198 |
on_send_button_clicked (GtkButton *button, gpointer user_data) |
|---|
| 199 |
{ |
|---|
| 200 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (user_data); |
|---|
| 201 |
GtkTreeIter iter; |
|---|
| 202 |
TnyAccount *account = NULL; |
|---|
| 203 |
GtkTreeModel *model = gtk_combo_box_get_model (priv->accounts_combo); |
|---|
| 204 |
gboolean not_ready = FALSE; |
|---|
| 205 |
|
|---|
| 206 |
if (gtk_combo_box_get_active_iter (priv->accounts_combo, &iter)) |
|---|
| 207 |
{ |
|---|
| 208 |
gtk_tree_model_get (model, &iter, |
|---|
| 209 |
TNY_GTK_ACCOUNT_LIST_MODEL_INSTANCE_COLUMN, |
|---|
| 210 |
&account, -1); |
|---|
| 211 |
if (account) |
|---|
| 212 |
{ |
|---|
| 213 |
CreateAndSendMsgInfo *info = g_slice_new0 (CreateAndSendMsgInfo); |
|---|
| 214 |
TnySendQueue *send_queue = get_send_queue_for (account, user_data); |
|---|
| 215 |
GtkTextBuffer *buffer = gtk_text_view_get_buffer (priv->message_textview); |
|---|
| 216 |
GtkTextIter start_iter, end_iter; |
|---|
| 217 |
gchar *text = NULL; |
|---|
| 218 |
TnyStream *stream = tny_camel_mem_stream_new (); |
|---|
| 219 |
TnyMsg *msg = tny_platform_factory_new_msg (platfact); |
|---|
| 220 |
TnyHeader *header = tny_msg_get_header (msg); |
|---|
| 221 |
|
|---|
| 222 |
tny_header_set_subject (header, gtk_entry_get_text (priv->subject_entry)); |
|---|
| 223 |
|
|---|
| 224 |
if (TNY_IS_CAMEL_TRANSPORT_ACCOUNT (account)) { |
|---|
| 225 |
TnyCamelTransportAccount *ta = (TnyCamelTransportAccount *) account; |
|---|
| 226 |
if (tny_camel_transport_account_get_from (ta)) |
|---|
| 227 |
tny_header_set_from (header, tny_camel_transport_account_get_from (ta)); |
|---|
| 228 |
else |
|---|
| 229 |
tny_header_set_from (header, tny_account_get_name (account)); |
|---|
| 230 |
} else |
|---|
| 231 |
tny_header_set_from (header, tny_account_get_name (account)); |
|---|
| 232 |
|
|---|
| 233 |
tny_header_set_to (header, gtk_entry_get_text (priv->to_entry)); |
|---|
| 234 |
|
|---|
| 235 |
g_object_unref (header); |
|---|
| 236 |
|
|---|
| 237 |
gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter); |
|---|
| 238 |
text = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE); |
|---|
| 239 |
tny_stream_write (stream, text, strlen (text)); |
|---|
| 240 |
g_free (text); |
|---|
| 241 |
tny_stream_reset (stream); |
|---|
| 242 |
|
|---|
| 243 |
tny_mime_part_set_header_pair (TNY_MIME_PART (msg), "X-Mailer", "TMut - " VERSION); |
|---|
| 244 |
|
|---|
| 245 |
if (priv->attachments) |
|---|
| 246 |
info->attachments = tny_list_copy (priv->attachments); |
|---|
| 247 |
else |
|---|
| 248 |
info->attachments = NULL; |
|---|
| 249 |
info->send_queue = g_object_ref (send_queue); |
|---|
| 250 |
info->msg = g_object_ref (msg); |
|---|
| 251 |
info->stream = g_object_ref (stream); |
|---|
| 252 |
info->account = g_object_ref (account); |
|---|
| 253 |
|
|---|
| 254 |
g_thread_create (create_and_send_msg_thread, info, FALSE, NULL); |
|---|
| 255 |
|
|---|
| 256 |
g_object_unref (stream); |
|---|
| 257 |
g_object_unref (msg); |
|---|
| 258 |
g_object_unref (send_queue); |
|---|
| 259 |
g_object_unref (account); |
|---|
| 260 |
|
|---|
| 261 |
} else |
|---|
| 262 |
not_ready = TRUE; |
|---|
| 263 |
} else |
|---|
| 264 |
not_ready = TRUE; |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
if (not_ready) { |
|---|
| 268 |
GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (priv->shell), |
|---|
| 269 |
0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
|---|
| 270 |
_("E-mail client not ready for sending E-mails. Configure " |
|---|
| 271 |
"an account that is suitable for sending first.")); |
|---|
| 272 |
gtk_widget_show_all (dialog); |
|---|
| 273 |
} else |
|---|
| 274 |
tmut_shell_window_back (priv->shell); |
|---|
| 275 |
|
|---|
| 276 |
return; |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
static void |
|---|
| 280 |
set_reply_msg_process_part (TnyMimePart *part, GString *str) |
|---|
| 281 |
{ |
|---|
| 282 |
TnyStream *stream = tny_mime_part_get_stream (part); |
|---|
| 283 |
gchar buffer[1024]; |
|---|
| 284 |
gint i = 0, s = 1024; |
|---|
| 285 |
|
|---|
| 286 |
s = tny_stream_read (stream, buffer, 1024); |
|---|
| 287 |
|
|---|
| 288 |
for (i=0; i < s && i < 1024; i++) { |
|---|
| 289 |
if (buffer[i] == '\n') |
|---|
| 290 |
g_string_append (str, "\n> "); |
|---|
| 291 |
else |
|---|
| 292 |
g_string_append_c (str, buffer[i]); |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
g_object_unref (stream); |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
static void |
|---|
| 299 |
set_reply_msg_walk_parts (TnyMimePart *my_part, GString *str) |
|---|
| 300 |
{ |
|---|
| 301 |
TnyIterator *iter; |
|---|
| 302 |
TnyList *parts = tny_simple_list_new (); |
|---|
| 303 |
gboolean end = FALSE; |
|---|
| 304 |
|
|---|
| 305 |
tny_mime_part_get_parts (my_part, parts); |
|---|
| 306 |
|
|---|
| 307 |
iter = tny_list_create_iterator (parts); |
|---|
| 308 |
while (!tny_iterator_is_done (iter) && !end) |
|---|
| 309 |
{ |
|---|
| 310 |
TnyList *nparts = tny_simple_list_new (); |
|---|
| 311 |
|
|---|
| 312 |
TnyMimePart *part = (TnyMimePart *) tny_iterator_get_current (iter); |
|---|
| 313 |
|
|---|
| 314 |
if (tny_mime_part_content_type_is (part, "text/plain")) { |
|---|
| 315 |
set_reply_msg_process_part (part, str); |
|---|
| 316 |
end = TRUE; |
|---|
| 317 |
} |
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
if (!end) |
|---|
| 321 |
set_reply_msg_walk_parts (part, str); |
|---|
| 322 |
|
|---|
| 323 |
g_object_unref (part); |
|---|
| 324 |
tny_iterator_next (iter); |
|---|
| 325 |
} |
|---|
| 326 |
g_object_unref (parts); |
|---|
| 327 |
g_object_unref (iter); |
|---|
| 328 |
|
|---|
| 329 |
return; |
|---|
| 330 |
} |
|---|
| 331 |
|
|---|
| 332 |
static void |
|---|
| 333 |
set_reply_msg (TMutMsgCreator *self, TnyMsg *msg, GString *str) |
|---|
| 334 |
{ |
|---|
| 335 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 336 |
|
|---|
| 337 |
if (tny_mime_part_content_type_is (TNY_MIME_PART (msg), "text/plain")) |
|---|
| 338 |
set_reply_msg_process_part (TNY_MIME_PART (msg), str); |
|---|
| 339 |
else |
|---|
| 340 |
set_reply_msg_walk_parts (TNY_MIME_PART (msg), str); |
|---|
| 341 |
} |
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
void |
|---|
| 345 |
tmut_msg_creator_add_attachment (TMutMsgCreator *self, TnyMimePart *part) |
|---|
| 346 |
{ |
|---|
| 347 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 348 |
gchar *str = NULL; |
|---|
| 349 |
|
|---|
| 350 |
tny_list_prepend (priv->attachments, G_OBJECT (part)); |
|---|
| 351 |
|
|---|
| 352 |
str = g_strdup_printf (ATTACH_TXT, tny_list_get_length (priv->attachments)); |
|---|
| 353 |
gtk_button_set_label (priv->attachments_button, str); |
|---|
| 354 |
g_free (str); |
|---|
| 355 |
|
|---|
| 356 |
return; |
|---|
| 357 |
} |
|---|
| 358 |
|
|---|
| 359 |
void |
|---|
| 360 |
tmut_msg_creator_remove_attachment (TMutMsgCreator *self, TnyMimePart *part) |
|---|
| 361 |
{ |
|---|
| 362 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 363 |
gchar *str = NULL; |
|---|
| 364 |
|
|---|
| 365 |
tny_list_remove (priv->attachments, G_OBJECT (part)); |
|---|
| 366 |
|
|---|
| 367 |
str = g_strdup_printf (ATTACH_TXT, tny_list_get_length (priv->attachments)); |
|---|
| 368 |
gtk_button_set_label (priv->attachments_button, str); |
|---|
| 369 |
g_free (str); |
|---|
| 370 |
|
|---|
| 371 |
return; |
|---|
| 372 |
} |
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
static void |
|---|
| 376 |
on_attachments_button_clicked (GtkButton *button, gpointer user_data) |
|---|
| 377 |
{ |
|---|
| 378 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (user_data); |
|---|
| 379 |
|
|---|
| 380 |
g_print ("ATTACHMENTS EDITOR\n"); |
|---|
| 381 |
|
|---|
| 382 |
return; |
|---|
| 383 |
} |
|---|
| 384 |
|
|---|
| 385 |
void |
|---|
| 386 |
tmut_msg_creator_set_forward_msg (TMutMsgCreator *self, TnyMsg *msg) |
|---|
| 387 |
{ |
|---|
| 388 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 389 |
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer (priv->message_textview); |
|---|
| 390 |
TnyHeader *header = tny_msg_get_header (msg); |
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
gchar *osubject = (gchar *) tny_header_dup_subject (header), |
|---|
| 395 |
*str = g_strdup_printf (_("[Fwd: %s]"), osubject?osubject:_("No subject")); |
|---|
| 396 |
|
|---|
| 397 |
g_free (osubject); |
|---|
| 398 |
|
|---|
| 399 |
gtk_entry_set_text (priv->subject_entry, (const gchar*) str); |
|---|
| 400 |
|
|---|
| 401 |
g_free (str); |
|---|
| 402 |
|
|---|
| 403 |
tmut_msg_creator_add_attachment (self, TNY_MIME_PART (msg)); |
|---|
| 404 |
|
|---|
| 405 |
gtk_text_buffer_set_text (text_buffer, "", 0); |
|---|
| 406 |
|
|---|
| 407 |
return; |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
void |
|---|
| 411 |
tmut_msg_creator_set_reply_msg (TMutMsgCreator *self, TnyMsg *msg) |
|---|
| 412 |
{ |
|---|
| 413 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 414 |
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer (priv->message_textview); |
|---|
| 415 |
TnyHeader *header = tny_msg_get_header (msg); |
|---|
| 416 |
GString *gstr = g_string_new (""); |
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
gchar *osubject = (gchar *) tny_header_dup_subject (header), |
|---|
| 421 |
*str = g_strdup_printf (_("[Re: %s]"), osubject?osubject:_("No subject")); |
|---|
| 422 |
|
|---|
| 423 |
g_free (osubject); |
|---|
| 424 |
|
|---|
| 425 |
gtk_entry_set_text (priv->subject_entry, (const gchar*) str); |
|---|
| 426 |
|
|---|
| 427 |
g_free (str); |
|---|
| 428 |
|
|---|
| 429 |
str = tny_header_dup_from (header); |
|---|
| 430 |
|
|---|
| 431 |
g_string_printf (gstr, _("On %s, %s wrote:\n"), |
|---|
| 432 |
_get_readable_date (tny_header_get_date_sent (header)), |
|---|
| 433 |
str); |
|---|
| 434 |
|
|---|
| 435 |
g_free (str); |
|---|
| 436 |
|
|---|
| 437 |
set_reply_msg (self, msg, gstr); |
|---|
| 438 |
|
|---|
| 439 |
if (str) { |
|---|
| 440 |
gtk_text_buffer_set_text (text_buffer, gstr->str, gstr->len); |
|---|
| 441 |
g_string_free (gstr, TRUE); |
|---|
| 442 |
} |
|---|
| 443 |
|
|---|
| 444 |
return; |
|---|
| 445 |
} |
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
static void |
|---|
| 451 |
on_account_created (TMutAccountStore *store, TnyAccount *account, TMutMsgCreator *self) |
|---|
| 452 |
{ |
|---|
| 453 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 454 |
TnyList *model = TNY_LIST (gtk_combo_box_get_model (priv->accounts_combo)); |
|---|
| 455 |
tny_list_prepend (model, (GObject *) account); |
|---|
| 456 |
} |
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
static void |
|---|
| 460 |
on_account_deleted (TMutAccountStore *store, TnyAccount *account, TMutMsgCreator *self) |
|---|
| 461 |
{ |
|---|
| 462 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 463 |
TnyList *model = TNY_LIST (gtk_combo_box_get_model (priv->accounts_combo)); |
|---|
| 464 |
tny_list_remove (model, (GObject *) account); |
|---|
| 465 |
} |
|---|
| 466 |
|
|---|
| 467 |
static void |
|---|
| 468 |
disconnect_account_store (TMutMsgCreatorPriv *priv) |
|---|
| 469 |
{ |
|---|
| 470 |
g_signal_handler_disconnect (priv->account_store, priv->account_created_signal); |
|---|
| 471 |
g_signal_handler_disconnect (priv->account_store, priv->account_deleted_signal); |
|---|
| 472 |
g_object_unref (priv->account_store); |
|---|
| 473 |
priv->account_store = NULL; |
|---|
| 474 |
} |
|---|
| 475 |
|
|---|
| 476 |
static void |
|---|
| 477 |
tmut_msg_creator_set_account_store (TnyAccountStoreView *self, TnyAccountStore *account_store) |
|---|
| 478 |
{ |
|---|
| 479 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 480 |
TnyList *accounts = TNY_LIST (tny_gtk_account_list_model_new ()); |
|---|
| 481 |
|
|---|
| 482 |
if (priv->account_store) |
|---|
| 483 |
disconnect_account_store (priv); |
|---|
| 484 |
priv->account_store = TNY_ACCOUNT_STORE (g_object_ref (account_store)); |
|---|
| 485 |
|
|---|
| 486 |
tny_account_store_get_accounts (priv->account_store, accounts, |
|---|
| 487 |
TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS); |
|---|
| 488 |
|
|---|
| 489 |
priv->account_created_signal = g_signal_connect (G_OBJECT (priv->account_store), "account_created", |
|---|
| 490 |
G_CALLBACK (on_account_created), self); |
|---|
| 491 |
priv->account_deleted_signal = g_signal_connect (G_OBJECT (priv->account_store), "account_deleted", |
|---|
| 492 |
G_CALLBACK (on_account_deleted), self); |
|---|
| 493 |
|
|---|
| 494 |
gtk_combo_box_set_model (priv->accounts_combo, GTK_TREE_MODEL (accounts)); |
|---|
| 495 |
gtk_combo_box_set_active (priv->accounts_combo, 0); |
|---|
| 496 |
|
|---|
| 497 |
return; |
|---|
| 498 |
} |
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
TMutMsgCreator * |
|---|
| 508 |
tmut_msg_creator_new (void) |
|---|
| 509 |
{ |
|---|
| 510 |
TMutMsgCreator *self = g_object_new (TMUT_TYPE_MSG_CREATOR, NULL); |
|---|
| 511 |
|
|---|
| 512 |
return TMUT_MSG_CREATOR (self); |
|---|
| 513 |
} |
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
static void |
|---|
| 517 |
tmut_msg_creator_instance_init (GTypeInstance *instance, gpointer g_class) |
|---|
| 518 |
{ |
|---|
| 519 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (instance); |
|---|
| 520 |
GtkWidget *vbox1; |
|---|
| 521 |
GtkWidget *table1; |
|---|
| 522 |
GtkWidget *label1; |
|---|
| 523 |
GtkWidget *label2; |
|---|
| 524 |
GtkWidget *scrolledwindow1; |
|---|
| 525 |
GtkCellRenderer *renderer; |
|---|
| 526 |
GtkTreeViewColumn *column; |
|---|
| 527 |
gchar *str = NULL; |
|---|
| 528 |
|
|---|
| 529 |
priv->account_store = NULL; |
|---|
| 530 |
priv->account_created_signal = -1; |
|---|
| 531 |
priv->account_deleted_signal = -1; |
|---|
| 532 |
|
|---|
| 533 |
priv->attachments = tny_simple_list_new (); |
|---|
| 534 |
|
|---|
| 535 |
vbox1 = GTK_WIDGET (instance); |
|---|
| 536 |
|
|---|
| 537 |
table1 = gtk_table_new (4, 2, FALSE); |
|---|
| 538 |
gtk_widget_show (table1); |
|---|
| 539 |
gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, TRUE, 0); |
|---|
| 540 |
gtk_table_set_col_spacings (GTK_TABLE (table1), 2); |
|---|
| 541 |
|
|---|
| 542 |
label1 = gtk_label_new (_("<b>From</b>")); |
|---|
| 543 |
gtk_widget_show (label1); |
|---|
| 544 |
gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1, |
|---|
| 545 |
(GtkAttachOptions) (GTK_FILL), |
|---|
| 546 |
(GtkAttachOptions) (0), 0, 0); |
|---|
| 547 |
gtk_label_set_use_markup (GTK_LABEL (label1), TRUE); |
|---|
| 548 |
gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5); |
|---|
| 549 |
|
|---|
| 550 |
label1 = gtk_label_new (_("<b>To</b>")); |
|---|
| 551 |
gtk_widget_show (label1); |
|---|
| 552 |
gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 1, 2, |
|---|
| 553 |
(GtkAttachOptions) (GTK_FILL), |
|---|
| 554 |
(GtkAttachOptions) (0), 0, 0); |
|---|
| 555 |
gtk_label_set_use_markup (GTK_LABEL (label1), TRUE); |
|---|
| 556 |
gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5); |
|---|
| 557 |
|
|---|
| 558 |
label2 = gtk_label_new (_("<b>Subject</b>")); |
|---|
| 559 |
gtk_widget_show (label2); |
|---|
| 560 |
gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 2, 3, |
|---|
| 561 |
(GtkAttachOptions) (GTK_FILL), |
|---|
| 562 |
(GtkAttachOptions) (0), 0, 0); |
|---|
| 563 |
gtk_label_set_use_markup (GTK_LABEL (label2), TRUE); |
|---|
| 564 |
gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); |
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
label2 = gtk_label_new (_("<b>Attached</b>")); |
|---|
| 568 |
gtk_widget_show (label2); |
|---|
| 569 |
gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 3, 4, |
|---|
| 570 |
(GtkAttachOptions) (GTK_FILL), |
|---|
| 571 |
(GtkAttachOptions) (0), 0, 0); |
|---|
| 572 |
gtk_label_set_use_markup (GTK_LABEL (label2), TRUE); |
|---|
| 573 |
gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); |
|---|
| 574 |
|
|---|
| 575 |
priv->accounts_combo = GTK_COMBO_BOX (gtk_combo_box_new ()); |
|---|
| 576 |
gtk_widget_show (GTK_WIDGET (priv->accounts_combo)); |
|---|
| 577 |
|
|---|
| 578 |
renderer = gtk_cell_renderer_text_new(); |
|---|
| 579 |
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (priv->accounts_combo), renderer, TRUE); |
|---|
| 580 |
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT (priv->accounts_combo), renderer, |
|---|
| 581 |
"text", TNY_GTK_ACCOUNT_LIST_MODEL_NAME_COLUMN, NULL); |
|---|
| 582 |
|
|---|
| 583 |
gtk_table_attach (GTK_TABLE (table1), GTK_WIDGET (priv->accounts_combo), |
|---|
| 584 |
1, 2, 0, 1, |
|---|
| 585 |
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), |
|---|
| 586 |
(GtkAttachOptions) (0), 0, 0); |
|---|
| 587 |
|
|---|
| 588 |
priv->to_entry = GTK_ENTRY (gtk_entry_new ()); |
|---|
| 589 |
gtk_widget_show (GTK_WIDGET (priv->to_entry)); |
|---|
| 590 |
gtk_table_attach (GTK_TABLE (table1), GTK_WIDGET (priv->to_entry), |
|---|
| 591 |
1, 2, 1, 2, |
|---|
| 592 |
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), |
|---|
| 593 |
(GtkAttachOptions) (0), 0, 0); |
|---|
| 594 |
|
|---|
| 595 |
priv->subject_entry = GTK_ENTRY (gtk_entry_new ()); |
|---|
| 596 |
gtk_widget_show (GTK_WIDGET (priv->subject_entry)); |
|---|
| 597 |
gtk_table_attach (GTK_TABLE (table1), GTK_WIDGET (priv->subject_entry), |
|---|
| 598 |
1, 2, 2, 3, |
|---|
| 599 |
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), |
|---|
| 600 |
(GtkAttachOptions) (0), 0, 0); |
|---|
| 601 |
|
|---|
| 602 |
str = g_strdup_printf (ATTACH_TXT, 0); |
|---|
| 603 |
priv->attachments_button = GTK_BUTTON (gtk_button_new_with_label (str)); |
|---|
| 604 |
g_free (str); |
|---|
| 605 |
gtk_widget_show (GTK_WIDGET (priv->attachments_button)); |
|---|
| 606 |
gtk_table_attach (GTK_TABLE (table1), GTK_WIDGET (priv->attachments_button), |
|---|
| 607 |
1, 2, 3, 4, |
|---|
| 608 |
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), |
|---|
| 609 |
(GtkAttachOptions) (0), 0, 0); |
|---|
| 610 |
|
|---|
| 611 |
scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL); |
|---|
| 612 |
gtk_widget_show (scrolledwindow1); |
|---|
| 613 |
gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0); |
|---|
| 614 |
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_SHADOW_IN); |
|---|
| 615 |
|
|---|
| 616 |
priv->message_textview = GTK_TEXT_VIEW (gtk_text_view_new ()); |
|---|
| 617 |
gtk_widget_show (GTK_WIDGET (priv->message_textview)); |
|---|
| 618 |
gtk_container_add (GTK_CONTAINER (scrolledwindow1), GTK_WIDGET (priv->message_textview)); |
|---|
| 619 |
|
|---|
| 620 |
priv->send_button = GTK_BUTTON (gtk_button_new_with_mnemonic (_("Send"))); |
|---|
| 621 |
gtk_widget_show (GTK_WIDGET (priv->send_button)); |
|---|
| 622 |
gtk_box_pack_start (GTK_BOX (vbox1), GTK_WIDGET (priv->send_button), |
|---|
| 623 |
FALSE, FALSE, 0); |
|---|
| 624 |
|
|---|
| 625 |
g_signal_connect (G_OBJECT (priv->send_button), "clicked", |
|---|
| 626 |
G_CALLBACK (on_send_button_clicked), instance); |
|---|
| 627 |
|
|---|
| 628 |
g_signal_connect (G_OBJECT (priv->attachments_button), "clicked", |
|---|
| 629 |
G_CALLBACK (on_attachments_button_clicked), instance); |
|---|
| 630 |
|
|---|
| 631 |
return; |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
static void |
|---|
| 636 |
tmut_msg_creator_finalize (GObject *object) |
|---|
| 637 |
{ |
|---|
| 638 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (object); |
|---|
| 639 |
|
|---|
| 640 |
if (priv->account_store) |
|---|
| 641 |
disconnect_account_store (priv); |
|---|
| 642 |
g_object_unref (priv->attachments); |
|---|
| 643 |
|
|---|
| 644 |
(*parent_class->finalize) (object); |
|---|
| 645 |
|
|---|
| 646 |
return; |
|---|
| 647 |
} |
|---|
| 648 |
|
|---|
| 649 |
static void |
|---|
| 650 |
tny_account_store_view_init (gpointer g, gpointer iface_data) |
|---|
| 651 |
{ |
|---|
| 652 |
TnyAccountStoreViewIface *klass = (TnyAccountStoreViewIface *)g; |
|---|
| 653 |
|
|---|
| 654 |
klass->set_account_store= tmut_msg_creator_set_account_store; |
|---|
| 655 |
|
|---|
| 656 |
return; |
|---|
| 657 |
} |
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 |
static void |
|---|
| 661 |
tmut_msg_creator_class_init (TMutMsgCreatorClass *class) |
|---|
| 662 |
{ |
|---|
| 663 |
GObjectClass *object_class; |
|---|
| 664 |
|
|---|
| 665 |
parent_class = g_type_class_peek_parent (class); |
|---|
| 666 |
object_class = (GObjectClass*) class; |
|---|
| 667 |
|
|---|
| 668 |
object_class->finalize = tmut_msg_creator_finalize; |
|---|
| 669 |
|
|---|
| 670 |
g_type_class_add_private (object_class, sizeof (TMutMsgCreatorPriv)); |
|---|
| 671 |
|
|---|
| 672 |
return; |
|---|
| 673 |
} |
|---|
| 674 |
|
|---|
| 675 |
TMutShellWindow* |
|---|
| 676 |
tmut_msg_creator_get_window (TMutShellChild *self) |
|---|
| 677 |
{ |
|---|
| 678 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 679 |
return priv->shell; |
|---|
| 680 |
} |
|---|
| 681 |
|
|---|
| 682 |
void |
|---|
| 683 |
tmut_msg_creator_set_window (TMutShellChild *self, TMutShellWindow *window) |
|---|
| 684 |
{ |
|---|
| 685 |
TMutMsgCreatorPriv *priv = TMUT_MSG_CREATOR_GET_PRIVATE (self); |
|---|
| 686 |
priv->shell = window; |
|---|
| 687 |
} |
|---|
| 688 |
|
|---|
| 689 |
static void |
|---|
| 690 |
tmut_shell_child_init (gpointer g, gpointer iface_data) |
|---|
| 691 |
{ |
|---|
| 692 |
TMutShellChildIface *klass = (TMutShellChildIface *)g; |
|---|
| 693 |
|
|---|
| 694 |
klass->get_window= tmut_msg_creator_get_window; |
|---|
| 695 |
klass->set_window= tmut_msg_creator_set_window; |
|---|
| 696 |
|
|---|
| 697 |
return; |
|---|
| 698 |
} |
|---|
| 699 |
|
|---|
| 700 |
GType |
|---|
| 701 |
tmut_msg_creator_get_type (void) |
|---|
| 702 |
{ |
|---|
| 703 |
static GType type = 0; |
|---|
| 704 |
|
|---|
| 705 |
if (G_UNLIKELY(type == 0)) |
|---|
| 706 |
{ |
|---|
| 707 |
static const GTypeInfo info = |
|---|
| 708 |
{ |
|---|
| 709 |
sizeof (TMutMsgCreatorClass), |
|---|
| 710 |
NULL, |
|---|
| 711 |
NULL, |
|---|
| 712 |
(GClassInitFunc) tmut_msg_creator_class_init, |
|---|
| 713 |
NULL, |
|---|
| 714 |
NULL, |
|---|
| 715 |
sizeof (TMutMsgCreator), |
|---|
| 716 |
0, |
|---|
| 717 |
tmut_msg_creator_instance_init, |
|---|
| 718 |
NULL |
|---|
| 719 |
}; |
|---|
| 720 |
|
|---|
| 721 |
static const GInterfaceInfo tny_account_store_view_info = |
|---|
| 722 |
{ |
|---|
| 723 |
(GInterfaceInitFunc) tny_account_store_view_init, |
|---|
| 724 |
NULL, |
|---|
| 725 |
NULL |
|---|
| 726 |
}; |
|---|
| 727 |
|
|---|
| 728 |
static const GInterfaceInfo tmut_shell_child_info = |
|---|
| 729 |
{ |
|---|
| 730 |
(GInterfaceInitFunc) tmut_shell_child_init, |
|---|
| 731 |
NULL, |
|---|
| 732 |
NULL |
|---|
| 733 |
}; |
|---|
| 734 |
|
|---|
| 735 |
type = g_type_register_static (GTK_TYPE_VBOX, |
|---|
| 736 |
"TMutMsgCreator", |
|---|
| 737 |
&info, 0); |
|---|
| 738 |
|
|---|
| 739 |
g_type_add_interface_static (type, TNY_TYPE_ACCOUNT_STORE_VIEW, |
|---|
| 740 |
&tny_account_store_view_info); |
|---|
| 741 |
|
|---|
| 742 |
g_type_add_interface_static (type, TMUT_TYPE_SHELL_CHILD, |
|---|
| 743 |
&tmut_shell_child_info); |
|---|
| 744 |
|
|---|
| 745 |
} |
|---|
| 746 |
|
|---|
| 747 |
return type; |
|---|
| 748 |
} |
|---|