8810
|
1 /**
|
|
2 * @file history.c MSN history functions
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22 #include "msn.h"
|
|
23 #include "history.h"
|
|
24
|
|
25 MsnHistory *
|
|
26 msn_history_new(void)
|
|
27 {
|
|
28 MsnHistory *history = g_new0(MsnHistory, 1);
|
|
29
|
|
30 history->trId = 1;
|
|
31
|
|
32 history->queue = g_queue_new();
|
|
33
|
|
34 return history;
|
|
35 }
|
|
36
|
|
37 void
|
|
38 msn_history_destroy(MsnHistory *history)
|
|
39 {
|
|
40 MsnTransaction *trans;
|
|
41
|
|
42 while ((trans = g_queue_pop_head(history->queue)) != NULL)
|
|
43 msn_transaction_destroy(trans);
|
|
44
|
|
45 g_queue_free(history->queue);
|
|
46 g_free(history);
|
|
47 }
|
|
48
|
|
49 MsnTransaction *
|
|
50 msn_history_find(MsnHistory *history, unsigned int trId)
|
|
51 {
|
|
52 MsnTransaction *trans;
|
|
53 GList *list;
|
|
54
|
|
55 for (list = history->queue->head; list != NULL; list = list->next)
|
|
56 {
|
|
57 trans = list->data;
|
|
58 if (trans->trId == trId)
|
|
59 return trans;
|
|
60 }
|
|
61
|
|
62 return NULL;
|
|
63 }
|
|
64
|
|
65 void
|
|
66 msn_history_add(MsnHistory *history, MsnTransaction *trans)
|
|
67 {
|
|
68 GQueue *queue = history->queue;
|
|
69
|
|
70 trans->trId = history->trId++;
|
|
71
|
|
72 g_queue_push_tail(queue, trans);
|
|
73
|
|
74 if (queue->length > MSN_HIST_ELEMS)
|
|
75 {
|
|
76 trans = g_queue_pop_head(queue);
|
|
77 msn_transaction_destroy(trans);
|
|
78 }
|
|
79 }
|