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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
/*
* xfer-command.c - xfer command
*
* Copyright (C) 2003-2014 Sébastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat 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.
*
* WeeChat 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 WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../weechat-plugin.h"
#include "xfer.h"
#include "xfer-buffer.h"
#include "xfer-chat.h"
#include "xfer-config.h"
/*
* Callback for command "/me": sends a ctcp action to remote host.
*/
int
xfer_command_me (void *data, struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
struct t_xfer *ptr_xfer;
/* make C compiler happy */
(void) data;
(void) argc;
(void) argv;
ptr_xfer = xfer_search_by_buffer (buffer);
if (!ptr_xfer)
{
weechat_printf (NULL,
_("%s%s: can't find xfer for buffer \"%s\""),
weechat_prefix ("error"), XFER_PLUGIN_NAME,
weechat_buffer_get_string (buffer, "name"));
return WEECHAT_RC_OK;
}
if (!XFER_HAS_ENDED(ptr_xfer->status))
{
xfer_chat_sendf (ptr_xfer, "\01ACTION %s\01\n",
(argv_eol[1]) ? argv_eol[1] : "");
weechat_printf_tags (buffer,
"no_highlight",
"%s%s%s %s%s",
weechat_prefix ("action"),
weechat_color ("chat_nick_self"),
ptr_xfer->local_nick,
weechat_color ("chat"),
(argv_eol[1]) ? argv_eol[1] : "");
}
return WEECHAT_RC_OK;
}
/*
* Displays a list of xfer.
*/
void
xfer_command_xfer_list (int full)
{
struct t_xfer *ptr_xfer;
int i;
char date[128];
unsigned long long pct_complete;
struct tm *date_tmp;
if (xfer_list)
{
weechat_printf (NULL, "");
weechat_printf (NULL, _("Xfer list:"));
i = 1;
for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer)
{
/* xfer info */
if (XFER_IS_FILE(ptr_xfer->type))
{
if (ptr_xfer->size == 0)
{
if (ptr_xfer->status == XFER_STATUS_DONE)
pct_complete = 100;
else
pct_complete = 0;
}
else
pct_complete = (unsigned long long)(((float)(ptr_xfer->pos)/(float)(ptr_xfer->size)) * 100);
weechat_printf (NULL,
_("%3d. %s (%s), file: \"%s\" (local: "
"\"%s\"), %s %s, status: %s%s%s "
"(%llu %%)"),
i,
xfer_type_string[ptr_xfer->type],
xfer_protocol_string[ptr_xfer->protocol],
ptr_xfer->filename,
ptr_xfer->local_filename,
(XFER_IS_SEND(ptr_xfer->type)) ?
_("sent to") : _("received from"),
ptr_xfer->remote_nick,
weechat_color (
weechat_config_string (
xfer_config_color_status[ptr_xfer->status])),
_(xfer_status_string[ptr_xfer->status]),
weechat_color ("chat"),
pct_complete);
}
else
{
date[0] = '\0';
date_tmp = localtime (&(ptr_xfer->start_time));
if (date_tmp)
{
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
weechat_printf (NULL,
/* TRANSLATORS: "%s" after "started on" is a date */
_("%3d. %s, chat with %s (local nick: %s), "
"started on %s, status: %s%s"),
i,
xfer_type_string[ptr_xfer->type],
ptr_xfer->remote_nick,
ptr_xfer->local_nick,
date,
weechat_color(
weechat_config_string(
xfer_config_color_status[ptr_xfer->status])),
_(xfer_status_string[ptr_xfer->status]));
}
if (full)
{
/* second line of xfer info */
if (XFER_IS_FILE(ptr_xfer->type))
{
weechat_printf (NULL,
_(" plugin: %s (id: %s), file: %llu "
"bytes (position: %llu), address: "
"%s (port %d)"),
ptr_xfer->plugin_name,
ptr_xfer->plugin_id,
ptr_xfer->size,
ptr_xfer->pos,
ptr_xfer->remote_address_str,
ptr_xfer->port);
date[0] = '\0';
date_tmp = localtime (&(ptr_xfer->start_transfer));
if (date_tmp)
{
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
weechat_printf (NULL,
/* TRANSLATORS: "%s" after "started on" is a date */
_(" fast_send: %s, blocksize: %d, "
"started on %s"),
(ptr_xfer->fast_send) ? _("yes") : _("no"),
ptr_xfer->blocksize,
date);
}
}
i++;
}
}
else
weechat_printf (NULL, _("No xfer"));
}
/*
* Callback for command "/xfer".
*/
int
xfer_command_xfer (void *data, struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
/* make C compiler happy */
(void) data;
(void) buffer;
(void) argv_eol;
if ((argc > 1) && (weechat_strcasecmp (argv[1], "list") == 0))
{
xfer_command_xfer_list (0);
return WEECHAT_RC_OK;
}
if ((argc > 1) && (weechat_strcasecmp (argv[1], "listfull") == 0))
{
xfer_command_xfer_list (1);
return WEECHAT_RC_OK;
}
if (!xfer_buffer)
xfer_buffer_open ();
if (xfer_buffer)
{
weechat_buffer_set (xfer_buffer, "display", "1");
if (argc > 1)
{
if (strcmp (argv[1], "up") == 0)
{
if (xfer_buffer_selected_line > 0)
xfer_buffer_selected_line--;
}
else if (strcmp (argv[1], "down") == 0)
{
if (xfer_buffer_selected_line < xfer_count - 1)
xfer_buffer_selected_line++;
}
}
}
xfer_buffer_refresh (NULL);
return WEECHAT_RC_OK;
}
/*
* Hooks commands.
*/
void
xfer_command_init ()
{
weechat_hook_command (
"me",
N_("send a CTCP action to remote host"),
N_("<message>"),
N_("message: message to send"),
NULL, &xfer_command_me, NULL);
weechat_hook_command (
"xfer",
N_("xfer control"),
"[list|listfull]",
N_(" list: list xfer\n"
"listfull: list xfer (verbose)\n"
"\n"
"Without argument, this command opens buffer with xfer list."),
"list|listfull", &xfer_command_xfer, NULL);
}
|