comparison plugins/history.c @ 11051:5290afac047c

[gaim-migrate @ 12989] This started out as Patch #1230845 from sadrul, which "makes the history-plugin show the date the log was created on." I changed the message added by the patch to match the title line in the log viewer. I also cleaned up the code a bit. Then, I discovered that it wasn't contactized. So, I fixed that. It should now show the most recent conversation with that contact (person) regardless of which buddy the conversation window was created for. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sun, 03 Jul 2005 05:00:26 +0000
parents c3b709d6d1e7
children f854402837ba
comparison
equal deleted inserted replaced
11050:ed397b13f4d7 11051:5290afac047c
28 return FALSE; 28 return FALSE;
29 } 29 }
30 30
31 static void historize(GaimConversation *c) 31 static void historize(GaimConversation *c)
32 { 32 {
33 GaimAccount *account = gaim_conversation_get_account(c);
34 const char *name = gaim_conversation_get_name(c);
35 GaimConversationType convtype;
36 GList *logs = NULL;
37 const char *alias = name;
38 guint flags;
39 char *history;
33 GaimGtkConversation *gtkconv; 40 GaimGtkConversation *gtkconv;
34 GaimConversationType convtype;
35 char *history = NULL;
36 guint flags;
37 GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS; 41 GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS;
38 GList *logs = NULL; 42 time_t tm;
43 char day[64];
44 char *header;
39 45
40 convtype = gaim_conversation_get_type(c); 46 convtype = gaim_conversation_get_type(c);
41 if (convtype == GAIM_CONV_IM) 47 if (convtype == GAIM_CONV_IM)
42 logs = gaim_log_get_logs(GAIM_LOG_IM, 48 {
43 gaim_conversation_get_name(c), gaim_conversation_get_account(c)); 49 GSList *buddies;
50 GSList *cur;
51
52 /* Find buddies for this conversation. */
53 buddies = gaim_find_buddies(account, name);
54
55 /* If we found at least one buddy, save the first buddy's alias. */
56 if (buddies != NULL)
57 alias = gaim_buddy_get_contact_alias((GaimBuddy *)buddies->data);
58
59 for (cur = buddies; cur != NULL; cur = cur->next)
60 {
61 GaimBlistNode *node = cur->data;
62 if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL)))
63 {
64 GaimBlistNode *node2;
65
66 alias = gaim_buddy_get_contact_alias((GaimBuddy *)node);
67
68 /* We've found a buddy that matches this conversation. It's part of a
69 * GaimContact with more than one GaimBuddy. Loop through the GaimBuddies
70 * in the contact and get all the logs. */
71 for (node2 = node->parent->child ; node2 != NULL ; node2 = node2->next)
72 {
73 logs = g_list_concat(
74 gaim_log_get_logs(GAIM_LOG_IM,
75 gaim_buddy_get_name((GaimBuddy *)node2),
76 gaim_buddy_get_account((GaimBuddy *)node2)),
77 logs);
78 }
79 break;
80 }
81 }
82 g_slist_free(buddies);
83
84 if (logs == NULL)
85 logs = gaim_log_get_logs(GAIM_LOG_IM, name, account);
86 else
87 logs = g_list_sort(logs, gaim_log_compare);
88 }
44 else if (convtype == GAIM_CONV_CHAT) 89 else if (convtype == GAIM_CONV_CHAT)
45 logs = gaim_log_get_logs(GAIM_LOG_CHAT, 90 logs = gaim_log_get_logs(GAIM_LOG_CHAT, name, account);
46 gaim_conversation_get_name(c), gaim_conversation_get_account(c));
47 91
48 if (!logs) 92 if (logs == NULL)
49 return; 93 return;
50 94
51 history = gaim_log_read((GaimLog*)logs->data, &flags); 95 history = gaim_log_read((GaimLog*)logs->data, &flags);
52 gtkconv = GAIM_GTK_CONVERSATION(c); 96 gtkconv = GAIM_GTK_CONVERSATION(c);
53 if (flags & GAIM_LOG_READ_NO_NEWLINE) 97 if (flags & GAIM_LOG_READ_NO_NEWLINE)
54 options |= GTK_IMHTML_NO_NEWLINE; 98 options |= GTK_IMHTML_NO_NEWLINE;
55 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<br>", options); 99
100 tm = ((GaimLog *)logs->data)->time;
101 gaim_strftime(day, sizeof(day), "%c", localtime(&tm));
102 header = g_strdup_printf("<b>Conversation with %s on %s:</b><br>", alias, day);
103 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), header, options);
104 g_free(header);
105
56 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), history, options); 106 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), history, options);
107 g_free(history);
108
57 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<hr>", options); 109 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<hr>", options);
110
58 g_object_ref(G_OBJECT(gtkconv->imhtml)); 111 g_object_ref(G_OBJECT(gtkconv->imhtml));
59 g_idle_add(_scroll_imhtml_to_end, gtkconv->imhtml); 112 g_idle_add(_scroll_imhtml_to_end, gtkconv->imhtml);
60 g_free(history);
61 113
62 while (logs) { 114 g_list_foreach(logs, (GFunc)gaim_log_free, NULL);
63 GaimLog *log = logs->data; 115 g_list_free(logs);
64 GList *logs2;
65 gaim_log_free(log);
66 logs2 = logs->next;
67 g_list_free_1(logs);
68 logs = logs2;
69 }
70 } 116 }
71 117
72 static gboolean 118 static gboolean
73 plugin_load(GaimPlugin *plugin) 119 plugin_load(GaimPlugin *plugin)
74 { 120 {