📄 dccgui.c
字号:
/* X-Chat * Copyright (C) 1998 Peter Zelezny. * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <fcntl.h>#include <time.h>#define WANTSOCKET#define WANTARPA#include "../common/inet.h"#include "fe-gtk.h"#include "../common/xchat.h"#include "../common/xchatc.h"#include "../common/plugin.h"#include "../common/fe.h"#include "../common/util.h"#include "../common/network.h"#include "gtkutil.h"#include "wins.h"#include "palette.h"struct dccwindow{ GtkWidget *window; GtkWidget *list;};struct dcc_send{ struct session *sess; char nick[64]; GtkWidget *freq;};static struct dccwindow dccrwin; /* recv */static struct dccwindow dccswin; /* send */static struct dccwindow dcccwin; /* chat */static voiddcc_send_filereq_done (struct session *sess, char *nick, char *file){ char tbuf[400]; if (file) { dcc_send (sess, tbuf, nick, file); free (file); } free (nick);}voidfe_dcc_send_filereq (struct session *sess, char *nick){ char tbuf[128]; nick = strdup (nick); snprintf (tbuf, sizeof tbuf, _("Send file to %s"), nick); gtkutil_file_req (tbuf, dcc_send_filereq_done, sess, nick, FALSE);}voidfe_dcc_update_recv (struct DCC *dcc){ char pos[14], cps[14], perc[14], eta[14]; gint row; int to_go; float per; if (!dccrwin.window) return; row = gtk_clist_find_row_from_data (GTK_CLIST (dccrwin.list), (gpointer) dcc); /* percentage done */ per = (float) ((dcc->pos * 100.00) / dcc->size); snprintf (pos, sizeof (pos), "%d", dcc->pos); snprintf (cps, sizeof (cps), "%d", dcc->cps); snprintf (perc, sizeof (perc), "%.0f%%", per); gtk_clist_freeze (GTK_CLIST (dccrwin.list)); gtk_clist_set_text (GTK_CLIST (dccrwin.list), row, 0, _(dccstat[(int) dcc->dccstat].name)); gtk_clist_set_text (GTK_CLIST (dccrwin.list), row, 3, pos); gtk_clist_set_text (GTK_CLIST (dccrwin.list), row, 4, perc); gtk_clist_set_text (GTK_CLIST (dccrwin.list), row, 5, cps); if (dcc->cps != 0) { to_go = (dcc->size - dcc->pos) / dcc->cps; snprintf (eta, sizeof (eta), "%.2d:%.2d:%.2d", to_go / 3600, (to_go / 60) % 60, to_go % 60); } else strcpy (eta, "--:--:--"); gtk_clist_set_text (GTK_CLIST (dccrwin.list), row, 6, eta); if (dccstat[(int) dcc->dccstat].color != 1) gtk_clist_set_foreground (GTK_CLIST (dccrwin.list), row, colors + dccstat[(int) dcc->dccstat].color);#ifdef USE_GNOME if (dcc->dccstat == STAT_DONE) gtk_clist_set_text (GTK_CLIST (dccrwin.list), row, 8, (char *) gnome_mime_type_of_file (dcc->destfile));#endif gtk_clist_thaw (GTK_CLIST (dccrwin.list));}voidfe_dcc_update_send (struct DCC *dcc){ char pos[14], cps[14], ack[14], perc[14], eta[14]; gint row; int to_go; float per; if (!dccswin.window) return; row = gtk_clist_find_row_from_data (GTK_CLIST (dccswin.list), (gpointer) dcc); /* percentage ack'ed */ per = (float) ((dcc->ack * 100.00) / dcc->size); snprintf (pos, sizeof (pos), "%d", dcc->pos); snprintf (cps, sizeof (cps), "%d", dcc->cps); snprintf (ack, sizeof (ack), "%d", dcc->ack); snprintf (perc, sizeof (perc), "%.0f%%", per); if (dcc->cps != 0) { to_go = (dcc->size - dcc->ack) / dcc->cps; snprintf (eta, sizeof (eta), "%.2d:%.2d:%.2d", to_go / 3600, (to_go / 60) % 60, to_go % 60); } else strcpy (eta, "--:--:--"); gtk_clist_freeze (GTK_CLIST (dccswin.list)); gtk_clist_set_text (GTK_CLIST (dccswin.list), row, 0, _(dccstat[(int) dcc->dccstat].name)); if (dccstat[(int) dcc->dccstat].color != 1) gtk_clist_set_foreground (GTK_CLIST (dccswin.list), row, colors + dccstat[(int) dcc->dccstat].color); gtk_clist_set_text (GTK_CLIST (dccswin.list), row, 3, pos); gtk_clist_set_text (GTK_CLIST (dccswin.list), row, 4, ack); gtk_clist_set_text (GTK_CLIST (dccswin.list), row, 5, perc); gtk_clist_set_text (GTK_CLIST (dccswin.list), row, 6, cps); gtk_clist_set_text (GTK_CLIST (dccswin.list), row, 7, eta); gtk_clist_thaw (GTK_CLIST (dccswin.list));}static voiddcc_abort (struct DCC *dcc){ if (dcc) { switch (dcc->dccstat) { case STAT_QUEUED: case STAT_CONNECTING: case STAT_ACTIVE: dcc_close (dcc, STAT_ABORTED, FALSE); EMIT_SIGNAL (XP_TE_DCCABORT, dcc->serv->front_session, dcctypes[(int) dcc->type], file_part (dcc->file), dcc->nick, NULL, 0); break; default: dcc_close (dcc, 0, TRUE); } }}static voidclose_dcc_recv_window (void){ dccrwin.window = 0;}voidfe_dcc_update_recv_win (void){ struct DCC *dcc; GSList *list = dcc_list; gchar *nnew[9]; char size[16]; char pos[16]; char cps[16]; char perc[14]; char eta[16]; gint row; int selrow; int to_go; float per; if (!dccrwin.window) return; selrow = gtkutil_clist_selection (dccrwin.list); gtk_clist_clear ((GtkCList *) dccrwin.list); nnew[2] = size; nnew[3] = pos; nnew[4] = perc; nnew[5] = cps; nnew[6] = eta; while (list) { dcc = (struct DCC *) list->data; if (dcc->type == TYPE_RECV) { nnew[0] = _(dccstat[(int) dcc->dccstat].name); nnew[1] = dcc->file; nnew[7] = dcc->nick;#ifdef USE_GNOME if (dcc->dccstat == STAT_DONE) nnew[8] = (char *) gnome_mime_type_of_file (dcc->destfile); else nnew[8] = "";#endif sprintf (size, "%d", dcc->size); if (dcc->dccstat == STAT_QUEUED) sprintf (pos, "%d", dcc->resumable); else sprintf (pos, "%d", dcc->pos); snprintf (cps, sizeof (cps), "%d", dcc->cps); /* percentage recv'ed */ per = (float) ((dcc->pos * 100.00) / dcc->size); snprintf (perc, sizeof (perc), "%.0f%%", per); if (dcc->cps != 0) { to_go = (dcc->size - dcc->pos) / dcc->cps; snprintf (eta, sizeof (eta), "%.2d:%.2d:%.2d", to_go / 3600, (to_go / 60) % 60, to_go % 60); } else strcpy (eta, "--:--:--"); row = gtk_clist_append (GTK_CLIST (dccrwin.list), nnew); gtk_clist_set_row_data (GTK_CLIST (dccrwin.list), row, (gpointer) dcc); if (dccstat[(int) dcc->dccstat].color != 1) gtk_clist_set_foreground (GTK_CLIST (dccrwin.list), row, colors + dccstat[(int) dcc->dccstat].color); } list = list->next; } if (selrow != -1) gtk_clist_select_row ((GtkCList *) dccrwin.list, selrow, 0);}static voiddcc_info (struct DCC *dcc){ char tbuf[256]; snprintf (tbuf, 255, _(" File: %s\n" " To/From: %s\n" " Size: %d\n" " Port: %d\n" " IP Number: %s\n" "Start Time: %s"), dcc->file, dcc->nick, dcc->size, dcc->port, net_ip (dcc->addr), ctime (&dcc->starttime)); gtkutil_simpledialog (tbuf);}static voidresume_clicked (GtkWidget * wid, gpointer none){ int row; struct DCC *dcc; row = gtkutil_clist_selection (dccrwin.list); if (row != -1) { dcc = gtk_clist_get_row_data (GTK_CLIST (dccrwin.list), row); gtk_clist_unselect_row (GTK_CLIST (dccrwin.list), row, 0); dcc_resume (dcc); }}static voidabort_clicked (GtkWidget * wid, gpointer none){ int row; struct DCC *dcc; row = gtkutil_clist_selection (dccrwin.list); if (row != -1) { dcc = gtk_clist_get_row_data (GTK_CLIST (dccrwin.list), row); dcc_abort (dcc); }}static voidaccept_clicked (GtkWidget * wid, gpointer none){ int row; struct DCC *dcc; row = gtkutil_clist_selection (dccrwin.list); if (row != -1) { dcc = gtk_clist_get_row_data (GTK_CLIST (dccrwin.list), row); gtk_clist_unselect_row (GTK_CLIST (dccrwin.list), row, 0); dcc_get (dcc); }}static voidinfo_clicked (GtkWidget * wid, gpointer none){ int row; struct DCC *dcc; row = gtkutil_clist_selection (dccrwin.list); if (row != -1) { dcc = gtk_clist_get_row_data (GTK_CLIST (dccrwin.list), row); if (dcc) dcc_info (dcc); }}#ifdef USE_GNOMEstatic voidopen_clicked (void){ int row; struct DCC *dcc; char *mime_type; char *mime_prog; char *tmp; row = gtkutil_clist_selection (dccrwin.list); if (row != -1) { dcc = gtk_clist_get_row_data (GTK_CLIST (dccrwin.list), row); if (dcc && dcc->dccstat == STAT_DONE) { mime_type = (char *) gnome_mime_type (dcc->destfile); if (mime_type) { mime_prog = (char *) gnome_mime_program (mime_type); if (mime_prog) { mime_prog = strdup (mime_prog); tmp = strstr (mime_prog, "%f"); if (tmp) { tmp[1] = 's'; tmp = malloc (strlen (dcc->destfile) + strlen (mime_prog)); sprintf (tmp, mime_prog, dcc->destfile);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -