diff src/prpl.c @ 2050:ddd696ccb46b

[gaim-migrate @ 2060] oh yes. revenge shall be mine. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 17 Jun 2001 20:25:36 +0000
parents 948a67a691a6
children 424a40f12a6c
line wrap: on
line diff
--- a/src/prpl.c	Sun Jun 17 20:22:34 2001 +0000
+++ b/src/prpl.c	Sun Jun 17 20:25:36 2001 +0000
@@ -20,6 +20,9 @@
  */
 
 #include "prpl.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include "pixmaps/ok.xpm"
 #include "pixmaps/cancel.xpm"
@@ -476,3 +479,122 @@
 		}
 	}
 }
+
+struct ft_req {
+	struct gaim_connection *gc;
+	gboolean send;
+	gboolean multiple;
+	guint size;
+	char *name;
+	ft_callback cb;
+	gpointer data;
+	GtkWidget *fd;
+};
+
+static void ftrrno(gpointer w, struct ft_req *fr)
+{
+	if (fr->fd && (w != fr->fd)) {
+		gtk_widget_destroy(fr->fd);
+		return;
+	}
+	if (fr->cb)
+		fr->cb(fr->gc, NULL, TRUE, fr->data);
+	if (fr->name)
+		g_free(fr->name);
+	g_free(fr);
+}
+
+static void do_exist_dialog(const char *name, unsigned long size, struct ft_req *fr)
+{
+	/*
+	GtkWidget *window;
+	GtkWidget *vbox;
+	GtkWidget *label;
+	GtkWidget *hbox;
+	GtkWidget *button;
+	char buf[8192];
+
+	g_snprintf(buf, sizeof(buf), "It appears that %s already exists. Do you want to "
+			"overwrite the file%s or cancel the transfer?", name,
+			(size <= fr->size) ? ", resume the download," : "");
+
+	window = gtk_window_new(GTK_WINDOW_DIALOG);
+	*/
+}
+
+static void ftgotfile(gpointer w, struct ft_req *fr)
+{
+	const char *fname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(fr->fd));
+	if (!fr->multiple && file_is_dir(fname, fr->fd))
+		return;
+
+	if (!fr->multiple && !fr->send) {
+		struct stat st;
+		if (stat(fname, &st) == 0) {
+			do_exist_dialog(fname, st.st_size, fr);
+			return;
+		}
+	}
+
+	fr->cb(fr->gc, fname, FT_EXIST_DNE, fr->data);
+	fr->cb = NULL;
+
+	gtk_widget_destroy(fr->fd);
+}
+
+static void ftrrok(gpointer w, struct ft_req *ft)
+{
+	/* ft is going to be free'd as soon as we leave this function, so we'll copy it */
+	struct ft_req *fr = g_memdup(ft, sizeof(struct ft_req));
+	char buf[256];
+
+	if (fr->send)
+		fr->fd = gtk_file_selection_new(_("Gaim - Select File"));
+	else
+		fr->fd = gtk_file_selection_new(_("Gaim - Send File"));
+
+	g_snprintf(buf, sizeof(buf), "%s/%s", g_get_home_dir(), fr->name ? fr->name : "");
+	gtk_file_selection_set_filename(GTK_FILE_SELECTION(fr->fd), buf);
+
+	gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fr->fd)->ok_button), "clicked",
+			   GTK_SIGNAL_FUNC(ftgotfile), fr);
+	gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fr->fd)->cancel_button), "clicked",
+			   GTK_SIGNAL_FUNC(ftrrno), fr);
+	gtk_signal_connect(GTK_OBJECT(fr->fd), "destroy", GTK_SIGNAL_FUNC(ftrrno), fr);
+
+	gtk_widget_show(fr->fd);
+}
+
+void ft_receive_request(struct gaim_connection *gc, const char *who, gboolean send, gboolean multiple,
+		char *name, guint size, ft_callback cb, gpointer data)
+{
+	char buf[8192];
+	struct ft_req *fr = g_new0(struct ft_req, 1);
+
+	fr->gc = gc;
+	fr->send = send;
+	fr->multiple = multiple;
+	fr->size = size;
+	if (name)
+		fr->name = g_strdup(name);
+	fr->cb = cb;
+	fr->data = data;
+
+	if (send)
+		g_snprintf(buf, sizeof(buf), "%s has just asked %s to send a file.",
+				who, gc->username);
+	else if (multiple)
+		g_snprintf(buf, sizeof(buf), "%s has just asked %s to receive some files.",
+				who, gc->username);
+	else if (name && size)
+		g_snprintf(buf, sizeof(buf), "%s has just asked %s to receive %s (%d bytes).",
+				who, gc->username, name, size);
+	else if (name)
+		g_snprintf(buf, sizeof(buf), "%s has just asked %s to receive %s.",
+				who, gc->username, name);
+	else
+		g_snprintf(buf, sizeof(buf), "%s has just asked %s to receive a file.",
+				who, gc->username);
+
+	do_ask_dialog(buf, fr, ftrrok, ftrrno);
+}