Mercurial > pidgin.yaz
annotate plugins/history.c @ 11091:5e29428077fc
[gaim-migrate @ 13112]
Kevin says "whoops"
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Mon, 11 Jul 2005 07:57:19 +0000 |
parents | 5290afac047c |
children | f854402837ba |
rev | line source |
---|---|
3598 | 1 /* Puts last 4k of log in new conversations a la Everybuddy (and then |
2 * stolen by Trillian "Pro") */ | |
3 | |
9791 | 4 #include "internal.h" |
5 #include "gtkgaim.h" | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
6 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
7 #include "conversation.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
8 #include "debug.h" |
7433 | 9 #include "log.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
10 #include "prefs.h" |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
11 #include "signals.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
12 #include "util.h" |
9943 | 13 #include "version.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
14 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
15 #include "gtkconv.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
16 #include "gtkimhtml.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
17 #include "gtkplugin.h" |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4113
diff
changeset
|
18 |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6063
diff
changeset
|
19 #define HISTORY_PLUGIN_ID "gtk-history" |
3598 | 20 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
21 #define HISTORY_SIZE (4 * 1024) |
3598 | 22 |
8913 | 23 static gboolean _scroll_imhtml_to_end(gpointer data) |
24 { | |
25 GtkIMHtml *imhtml = data; | |
26 gtk_imhtml_scroll_to_end(GTK_IMHTML(imhtml)); | |
27 g_object_unref(G_OBJECT(imhtml)); | |
28 return FALSE; | |
29 } | |
30 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
31 static void historize(GaimConversation *c) |
3598 | 32 { |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
33 GaimAccount *account = gaim_conversation_get_account(c); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
34 const char *name = gaim_conversation_get_name(c); |
8898 | 35 GaimConversationType convtype; |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
36 GList *logs = NULL; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
37 const char *alias = name; |
7440 | 38 guint flags; |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
39 char *history; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
40 GaimGtkConversation *gtkconv; |
3602 | 41 GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS; |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
42 time_t tm; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
43 char day[64]; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
44 char *header; |
8898 | 45 |
46 convtype = gaim_conversation_get_type(c); | |
47 if (convtype == GAIM_CONV_IM) | |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
48 { |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
49 GSList *buddies; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
50 GSList *cur; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
51 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
52 /* Find buddies for this conversation. */ |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
53 buddies = gaim_find_buddies(account, name); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
54 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
55 /* If we found at least one buddy, save the first buddy's alias. */ |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
56 if (buddies != NULL) |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
57 alias = gaim_buddy_get_contact_alias((GaimBuddy *)buddies->data); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
58 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
59 for (cur = buddies; cur != NULL; cur = cur->next) |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
60 { |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
61 GaimBlistNode *node = cur->data; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
62 if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL))) |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
63 { |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
64 GaimBlistNode *node2; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
65 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
66 alias = gaim_buddy_get_contact_alias((GaimBuddy *)node); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
67 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
68 /* We've found a buddy that matches this conversation. It's part of a |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
69 * GaimContact with more than one GaimBuddy. Loop through the GaimBuddies |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
70 * in the contact and get all the logs. */ |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
71 for (node2 = node->parent->child ; node2 != NULL ; node2 = node2->next) |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
72 { |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
73 logs = g_list_concat( |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
74 gaim_log_get_logs(GAIM_LOG_IM, |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
75 gaim_buddy_get_name((GaimBuddy *)node2), |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
76 gaim_buddy_get_account((GaimBuddy *)node2)), |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
77 logs); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
78 } |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
79 break; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
80 } |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
81 } |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
82 g_slist_free(buddies); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
83 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
84 if (logs == NULL) |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
85 logs = gaim_log_get_logs(GAIM_LOG_IM, name, account); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
86 else |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
87 logs = g_list_sort(logs, gaim_log_compare); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
88 } |
8898 | 89 else if (convtype == GAIM_CONV_CHAT) |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
90 logs = gaim_log_get_logs(GAIM_LOG_CHAT, name, account); |
7440 | 91 |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
92 if (logs == NULL) |
3598 | 93 return; |
8898 | 94 |
7433 | 95 history = gaim_log_read((GaimLog*)logs->data, &flags); |
96 gtkconv = GAIM_GTK_CONVERSATION(c); | |
97 if (flags & GAIM_LOG_READ_NO_NEWLINE) | |
3602 | 98 options |= GTK_IMHTML_NO_NEWLINE; |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
99 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
100 tm = ((GaimLog *)logs->data)->time; |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
101 gaim_strftime(day, sizeof(day), "%c", localtime(&tm)); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
102 header = g_strdup_printf("<b>Conversation with %s on %s:</b><br>", alias, day); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
103 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), header, options); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
104 g_free(header); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
105 |
7433 | 106 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), history, options); |
107 g_free(history); | |
8898 | 108 |
11051
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
109 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<hr>", options); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
110 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
111 g_object_ref(G_OBJECT(gtkconv->imhtml)); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
112 g_idle_add(_scroll_imhtml_to_end, gtkconv->imhtml); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
113 |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
114 g_list_foreach(logs, (GFunc)gaim_log_free, NULL); |
5290afac047c
[gaim-migrate @ 12989]
Richard Laager <rlaager@wiktel.com>
parents:
10764
diff
changeset
|
115 g_list_free(logs); |
3598 | 116 } |
117 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
118 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
119 plugin_load(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
120 { |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
121 gaim_signal_connect(gaim_conversations_get_handle(), |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
122 "conversation-created", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
123 plugin, GAIM_CALLBACK(historize), NULL); |
3598 | 124 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
125 return TRUE; |
3598 | 126 } |
127 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
128 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
129 { |
9943 | 130 GAIM_PLUGIN_MAGIC, |
131 GAIM_MAJOR_VERSION, | |
132 GAIM_MINOR_VERSION, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
133 GAIM_PLUGIN_STANDARD, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
134 GAIM_GTK_PLUGIN_TYPE, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
135 0, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
136 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
137 GAIM_PRIORITY_DEFAULT, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
138 HISTORY_PLUGIN_ID, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
139 N_("History"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
140 VERSION, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
141 N_("Shows recently logged conversations in new conversations."), |
7666 | 142 N_("When a new conversation is opened this plugin will insert the last conversation into the current conversation."), |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
143 "Sean Egan <bj91704@binghamton.edu>", |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6063
diff
changeset
|
144 GAIM_WEBSITE, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
145 plugin_load, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
146 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
147 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
148 NULL, |
8993 | 149 NULL, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
150 NULL |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
151 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
152 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
153 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
154 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
155 { |
3598 | 156 } |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5114
diff
changeset
|
157 |
6063 | 158 GAIM_INIT_PLUGIN(history, init_plugin, info) |