1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/*
* Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* irc-buffer.c: manages buffers for IRC protocol */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "../../core/weechat.h"
#include "irc.h"
#include "../../core/utf8.h"
#include "../../core/weechat-config.h"
#include "../../gui/gui.h"
/*
* irc_buffer_data_create: create protocol data (for GUI buffer)
*/
t_irc_buffer_data *
irc_buffer_data_create (t_irc_server *server)
{
t_irc_buffer_data *buffer_data;
buffer_data = (t_irc_buffer_data *)malloc (sizeof (t_irc_buffer_data));
if (!buffer_data)
return NULL;
buffer_data->server = server;
buffer_data->channel = NULL;
buffer_data->all_servers = irc_cfg_irc_one_server_buffer;
return buffer_data;
}
/*
* irc_buffer_data_free: free protocol data (in GUI buffer)
*/
void
irc_buffer_data_free (t_gui_buffer *buffer)
{
free ((t_irc_buffer_data *)buffer->protocol_data);
}
/*
* irc_buffer_servers_search: search servers buffer
* (when same buffer is used for all servers)
*/
t_gui_buffer *
irc_buffer_servers_search ()
{
t_gui_buffer *ptr_buffer;
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
{
if (IRC_BUFFER_ALL_SERVERS(ptr_buffer))
return ptr_buffer;
}
/* buffer not found */
return NULL;
}
/*
* irc_buffer_merge_servers: merge server buffers in one buffer
*/
void
irc_buffer_merge_servers (t_gui_window *window)
{
t_gui_buffer *ptr_buffer_server, *ptr_buffer, *new_ptr_buffer;
t_irc_server *ptr_server;
/* new server buffer is the first server buffer found */
for (ptr_buffer_server = gui_buffers; ptr_buffer_server;
ptr_buffer_server = ptr_buffer_server->next_buffer)
{
if ((ptr_buffer_server->protocol == irc_protocol)
&& (IRC_BUFFER_SERVER(ptr_buffer_server))
&& (!IRC_BUFFER_CHANNEL(ptr_buffer_server)))
break;
}
/* no server buffer found */
if (!ptr_buffer_server)
return;
ptr_buffer = gui_buffers;
while (ptr_buffer)
{
if ((ptr_buffer->protocol == irc_protocol)
&& (ptr_buffer != ptr_buffer_server)
&& (IRC_BUFFER_SERVER(ptr_buffer))
&& (!IRC_BUFFER_CHANNEL(ptr_buffer)))
{
ptr_server = IRC_BUFFER_SERVER(ptr_buffer);
/* add (by pointer artefact) lines from buffer found to server buffer */
if (ptr_buffer->lines)
{
if (ptr_buffer_server->lines)
{
ptr_buffer->lines->prev_line =
ptr_buffer_server->last_line;
ptr_buffer_server->last_line->next_line =
ptr_buffer->lines;
ptr_buffer_server->last_line =
ptr_buffer->last_line;
}
else
{
ptr_buffer_server->lines = ptr_buffer->lines;
ptr_buffer_server->last_line = ptr_buffer->last_line;
}
}
/* free buffer but not lines, because they're now used by
our unique server buffer */
new_ptr_buffer = ptr_buffer->next_buffer;
ptr_buffer->lines = NULL;
gui_buffer_free (ptr_buffer, 1);
ptr_buffer = new_ptr_buffer;
/* asociate server with new server buffer */
ptr_server->buffer = ptr_buffer_server;
}
else
ptr_buffer = ptr_buffer->next_buffer;
}
IRC_BUFFER_ALL_SERVERS(ptr_buffer_server) = 1;
gui_window_redraw_buffer (window->buffer);
}
/*
* irc_buffer_split_server: split the server buffer into many buffers (one by server)
*/
void
irc_buffer_split_server (t_gui_window *window)
{
t_gui_buffer *ptr_buffer;
t_irc_server *ptr_server;
char *log_filename;
ptr_buffer = gui_buffer_servers_search ();
if (ptr_buffer)
{
if (IRC_BUFFER_SERVER(ptr_buffer))
{
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->buffer
&& (ptr_server != IRC_BUFFER_SERVER(ptr_buffer))
&& (ptr_server->buffer == ptr_buffer))
{
ptr_server->buffer = NULL;
log_filename = irc_log_get_filename (ptr_server->name,
NULL,
0);
gui_buffer_new (window, 0,
ptr_server->name,
ptr_server->name,
GUI_BUFFER_ATTRIB_TEXT |
GUI_BUFFER_ATTRIB_INPUT |
GUI_BUFFER_ATTRIB_NICKS,
irc_protocol,
irc_buffer_data_create (ptr_server),
&irc_buffer_data_free,
GUI_NOTIFY_LEVEL_DEFAULT,
NULL, ptr_server->nick,
irc_cfg_log_auto_server, log_filename,
0);
if (log_filename)
free (log_filename);
}
}
}
IRC_BUFFER_ALL_SERVERS(ptr_buffer) = 0;
gui_status_draw (window->buffer, 1);
gui_input_draw (window->buffer, 1);
}
}
|