2006-01-12 18:40:47 +00:00
|
|
|
/*
|
2006-01-25 16:55:45 +00:00
|
|
|
Copyright (c) 2005-2006 Joshua Elsasser. All rights reserved.
|
2006-01-12 18:40:47 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2006-01-12 19:00:58 +00:00
|
|
|
#include <assert.h>
|
2006-01-12 18:40:47 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2006-02-04 18:03:05 +00:00
|
|
|
#include <glib/gi18n.h>
|
2006-01-12 18:40:47 +00:00
|
|
|
|
|
|
|
#include "conf.h"
|
2006-01-30 16:05:18 +00:00
|
|
|
#include "dialogs.h"
|
2006-01-12 18:40:47 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct prefdata {
|
|
|
|
GtkSpinButton *port;
|
2006-04-07 14:14:40 +00:00
|
|
|
GtkCheckButton *use_dlimit;
|
|
|
|
GtkSpinButton *dlimit;
|
|
|
|
GtkCheckButton *use_ulimit;
|
|
|
|
GtkSpinButton *ulimit;
|
2006-01-25 16:55:45 +00:00
|
|
|
GtkFileChooser *dir;
|
2006-01-12 18:40:47 +00:00
|
|
|
GtkWindow *parent;
|
|
|
|
tr_handle_t *tr;
|
|
|
|
};
|
|
|
|
|
2006-01-12 18:55:27 +00:00
|
|
|
struct addcb {
|
|
|
|
add_torrent_func_t addfunc;
|
|
|
|
GtkWindow *parent;
|
|
|
|
torrents_added_func_t donefunc;
|
2006-03-23 12:39:39 +00:00
|
|
|
void *data;
|
2006-01-12 18:55:27 +00:00
|
|
|
gboolean autostart;
|
|
|
|
gboolean usingaltdir;
|
|
|
|
GtkFileChooser *altdir;
|
|
|
|
GtkButtonBox *altbox;
|
|
|
|
};
|
|
|
|
|
2006-02-05 17:33:57 +00:00
|
|
|
static void
|
|
|
|
windclosed(GtkWidget *widget SHUTUP, gpointer gdata);
|
2006-01-12 18:40:47 +00:00
|
|
|
static void
|
|
|
|
clicklimitbox(GtkWidget *widget, gpointer gdata);
|
|
|
|
static void
|
|
|
|
clickdialog(GtkWidget *widget, int resp, gpointer gdata);
|
2006-01-12 18:55:27 +00:00
|
|
|
static void
|
|
|
|
autoclick(GtkWidget *widget, gpointer gdata);
|
|
|
|
static void
|
|
|
|
dirclick(GtkWidget *widget, gpointer gdata);
|
|
|
|
static void
|
|
|
|
addresp(GtkWidget *widget, gint resp, gpointer gdata);
|
2006-01-12 18:40:47 +00:00
|
|
|
|
|
|
|
void
|
2006-02-05 17:33:57 +00:00
|
|
|
makeprefwindow(GtkWindow *parent, tr_handle_t *tr, gboolean *opened) {
|
2006-02-04 18:03:05 +00:00
|
|
|
char *title = g_strdup_printf(_("%s Preferences"), g_get_application_name());
|
2006-01-25 16:55:45 +00:00
|
|
|
GtkWidget *wind = gtk_dialog_new_with_buttons(title, parent,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
|
|
|
|
GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
|
2006-04-07 14:14:40 +00:00
|
|
|
const unsigned int rowcount = 6;
|
|
|
|
GtkWidget *table = gtk_table_new(rowcount, 2, FALSE);
|
2006-01-12 18:40:47 +00:00
|
|
|
GtkWidget *portnum = gtk_spin_button_new_with_range(1, 0xffff, 1);
|
2006-02-05 17:33:57 +00:00
|
|
|
GtkWidget *dirstr = gtk_file_chooser_button_new(
|
2006-04-25 08:14:37 +00:00
|
|
|
_("Choose a download directory"),
|
2006-01-25 16:55:45 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
2006-01-12 18:40:47 +00:00
|
|
|
GtkWidget *label;
|
2006-01-25 16:55:45 +00:00
|
|
|
GtkWidget **array;
|
2006-01-12 18:40:47 +00:00
|
|
|
const char *pref;
|
|
|
|
struct prefdata *data = g_new0(struct prefdata, 1);
|
2006-04-15 03:22:04 +00:00
|
|
|
struct { GtkWidget *on; GtkWidget *num; GtkWidget *label; gboolean defuse;
|
2006-04-07 14:14:40 +00:00
|
|
|
const char *usepref; const char *numpref; long def; } lim[] = {
|
|
|
|
{ gtk_check_button_new_with_mnemonic(_("_Limit download speed")),
|
|
|
|
gtk_spin_button_new_with_range(0, G_MAXLONG, 1),
|
|
|
|
gtk_label_new_with_mnemonic(_("Maximum _download speed:")),
|
2006-04-15 03:22:04 +00:00
|
|
|
DEF_USEDOWNLIMIT, PREF_USEDOWNLIMIT, PREF_DOWNLIMIT, DEF_DOWNLIMIT, },
|
2006-04-07 14:14:40 +00:00
|
|
|
{ gtk_check_button_new_with_mnemonic(_("Li_mit upload speed")),
|
|
|
|
gtk_spin_button_new_with_range(0, G_MAXLONG, 1),
|
|
|
|
gtk_label_new_with_mnemonic(_("Maximum _upload speed:")),
|
2006-04-15 03:22:04 +00:00
|
|
|
DEF_USEUPLIMIT, PREF_USEUPLIMIT, PREF_UPLIMIT, DEF_UPLIMIT, },
|
2006-04-07 14:14:40 +00:00
|
|
|
};
|
|
|
|
unsigned int ii;
|
2006-01-12 18:40:47 +00:00
|
|
|
|
2006-02-05 17:33:57 +00:00
|
|
|
*opened = TRUE;
|
|
|
|
|
2006-01-25 16:55:45 +00:00
|
|
|
g_free(title);
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_widget_set_name(wind, "TransmissionDialog");
|
2006-04-29 16:29:04 +00:00
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(table), 8);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(table), 8);
|
2006-01-25 16:55:45 +00:00
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(wind), GTK_RESPONSE_OK);
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(table), 6);
|
|
|
|
gtk_window_set_resizable(GTK_WINDOW(wind), FALSE);
|
2006-01-25 16:55:45 +00:00
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
data->port = GTK_SPIN_BUTTON(portnum);
|
2006-04-07 14:14:40 +00:00
|
|
|
data->use_dlimit = GTK_CHECK_BUTTON(lim[0].on);
|
|
|
|
data->dlimit = GTK_SPIN_BUTTON(lim[0].num);
|
|
|
|
data->use_ulimit = GTK_CHECK_BUTTON(lim[1].on);
|
|
|
|
data->ulimit = GTK_SPIN_BUTTON(lim[1].num);
|
2006-01-25 16:55:45 +00:00
|
|
|
data->dir = GTK_FILE_CHOOSER(dirstr);
|
2006-01-12 18:40:47 +00:00
|
|
|
data->parent = parent;
|
|
|
|
data->tr = tr;
|
|
|
|
|
2006-04-07 14:14:40 +00:00
|
|
|
#define RN(n) (n), (n) + 1
|
|
|
|
|
|
|
|
for(ii = 0; ii < ALEN(lim); ii++) {
|
|
|
|
/* limit checkbox */
|
|
|
|
pref = cf_getpref(lim[ii].usepref);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lim[ii].on),
|
2006-04-15 03:22:04 +00:00
|
|
|
(NULL == pref ? lim[ii].defuse : strbool(pref)));
|
2006-04-07 14:14:40 +00:00
|
|
|
array = g_new(GtkWidget*, 2);
|
|
|
|
g_signal_connect_data(lim[ii].on, "clicked", G_CALLBACK(clicklimitbox),
|
|
|
|
array, (GClosureNotify)g_free, 0);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), lim[ii].on, 0, 2, RN(ii*2));
|
|
|
|
|
|
|
|
/* limit label and entry */
|
|
|
|
gtk_label_set_mnemonic_widget(GTK_LABEL(lim[ii].label), lim[ii].num);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(lim[ii].label), 0, .5);
|
|
|
|
pref = cf_getpref(lim[ii].numpref);
|
|
|
|
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(lim[ii].num), TRUE);
|
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(lim[ii].num),
|
|
|
|
(NULL == pref ? lim[ii].def : strtol(pref, NULL, 10)));
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), lim[ii].label, 0,1,RN(ii*2+1));
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), lim[ii].num, 1,2,RN(ii*2+1));
|
|
|
|
array[0] = lim[ii].label;
|
|
|
|
array[1] = lim[ii].num;
|
|
|
|
clicklimitbox(lim[ii].on, array);
|
|
|
|
}
|
|
|
|
ii *= 2;
|
2006-01-12 18:40:47 +00:00
|
|
|
|
2006-01-25 16:55:45 +00:00
|
|
|
/* directory label and chooser */
|
2006-04-07 14:14:40 +00:00
|
|
|
label = gtk_label_new_with_mnemonic(_("Download di_rectory:"));
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_label_set_mnemonic_widget(GTK_LABEL(label), dirstr);
|
2006-01-25 16:55:45 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, .5);
|
2006-01-12 18:40:47 +00:00
|
|
|
if(NULL != (pref = cf_getpref(PREF_DIR)))
|
2006-01-25 16:55:45 +00:00
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dirstr), pref);
|
2006-04-07 14:14:40 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, RN(ii));
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), dirstr, 1, 2, RN(ii));
|
|
|
|
ii++;
|
2006-02-05 17:33:57 +00:00
|
|
|
|
|
|
|
/* port label and entry */
|
|
|
|
label = gtk_label_new_with_mnemonic(_("Listening _port:"));
|
|
|
|
gtk_label_set_mnemonic_widget(GTK_LABEL(label), portnum);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, .5);
|
|
|
|
pref = cf_getpref(PREF_PORT);
|
|
|
|
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(portnum), TRUE);
|
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(portnum),
|
|
|
|
(NULL == pref ? TR_DEFAULT_PORT : strtol(pref, NULL, 10)));
|
2006-04-07 14:14:40 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, RN(ii));
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), portnum, 1, 2, RN(ii));
|
|
|
|
ii++;
|
|
|
|
|
|
|
|
#undef RN
|
|
|
|
assert(rowcount == ii);
|
2006-01-12 18:40:47 +00:00
|
|
|
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(wind)->vbox), table);
|
2006-01-25 16:55:45 +00:00
|
|
|
g_signal_connect_data(wind, "response", G_CALLBACK(clickdialog),
|
|
|
|
data, (GClosureNotify)g_free, 0);
|
2006-02-05 17:33:57 +00:00
|
|
|
g_signal_connect(wind, "destroy", G_CALLBACK(windclosed), opened);
|
2006-01-12 18:40:47 +00:00
|
|
|
gtk_widget_show_all(wind);
|
|
|
|
}
|
|
|
|
|
2006-02-05 17:33:57 +00:00
|
|
|
static void
|
|
|
|
windclosed(GtkWidget *widget SHUTUP, gpointer gdata) {
|
|
|
|
gboolean *preachy_gcc = gdata;
|
|
|
|
|
|
|
|
*preachy_gcc = FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
static void
|
|
|
|
clicklimitbox(GtkWidget *widget, gpointer gdata) {
|
2006-01-25 16:55:45 +00:00
|
|
|
GtkWidget **widgets = gdata;
|
|
|
|
int ii;
|
2006-01-12 18:40:47 +00:00
|
|
|
|
2006-01-25 16:55:45 +00:00
|
|
|
for(ii = 0; 2 > ii; ii++)
|
|
|
|
gtk_widget_set_sensitive(widgets[ii],
|
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
|
2006-01-12 18:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clickdialog(GtkWidget *widget, int resp, gpointer gdata) {
|
|
|
|
struct prefdata *data = gdata;
|
|
|
|
int intval;
|
|
|
|
const char *strval;
|
2006-01-12 18:56:00 +00:00
|
|
|
char *strnum, *errstr;
|
2006-04-07 14:14:40 +00:00
|
|
|
gboolean bval;
|
2006-01-12 18:40:47 +00:00
|
|
|
|
2006-02-05 17:33:57 +00:00
|
|
|
if(GTK_RESPONSE_APPLY == resp || GTK_RESPONSE_OK == resp) {
|
2006-01-12 18:40:47 +00:00
|
|
|
/* check directory */
|
2006-01-25 16:55:45 +00:00
|
|
|
if(NULL != (strval = gtk_file_chooser_get_current_folder(data->dir))) {
|
|
|
|
if(!mkdir_p(strval, 0777)) {
|
2006-02-04 18:03:05 +00:00
|
|
|
errmsg(data->parent,
|
2006-02-05 17:33:57 +00:00
|
|
|
_("Failed to create the directory %s:\n%s"),
|
2006-01-25 16:55:45 +00:00
|
|
|
strval, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save dir pref */
|
|
|
|
cf_setpref(PREF_DIR, strval);
|
2006-01-12 18:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* save port pref */
|
|
|
|
strnum = g_strdup_printf("%i",
|
|
|
|
gtk_spin_button_get_value_as_int(data->port));
|
2006-01-25 16:55:45 +00:00
|
|
|
cf_setpref(PREF_PORT, strnum);
|
2006-01-12 18:40:47 +00:00
|
|
|
g_free(strnum);
|
|
|
|
|
2006-04-07 14:14:40 +00:00
|
|
|
/* save usedownlimit pref */
|
|
|
|
bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->use_dlimit));
|
|
|
|
cf_setpref(PREF_USEDOWNLIMIT, (bval ? "yes" : "no"));
|
2006-01-12 18:40:47 +00:00
|
|
|
|
2006-04-07 14:14:40 +00:00
|
|
|
/* save downlimit pref */
|
|
|
|
intval = gtk_spin_button_get_value_as_int(data->dlimit);
|
2006-01-12 18:40:47 +00:00
|
|
|
strnum = g_strdup_printf("%i", intval);
|
2006-04-07 14:14:40 +00:00
|
|
|
cf_setpref(PREF_DOWNLIMIT, strnum);
|
|
|
|
|
|
|
|
/* save useuplimit pref */
|
|
|
|
bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->use_ulimit));
|
|
|
|
cf_setpref(PREF_USEUPLIMIT, (bval ? "yes" : "no"));
|
|
|
|
|
|
|
|
/* save downlimit pref */
|
|
|
|
intval = gtk_spin_button_get_value_as_int(data->ulimit);
|
|
|
|
strnum = g_strdup_printf("%i", intval);
|
|
|
|
cf_setpref(PREF_UPLIMIT, strnum);
|
2006-01-25 16:55:45 +00:00
|
|
|
|
|
|
|
/* save prefs */
|
|
|
|
if(!cf_saveprefs(&errstr)) {
|
2006-01-12 18:56:00 +00:00
|
|
|
errmsg(data->parent, "%s", errstr);
|
2006-01-12 18:40:47 +00:00
|
|
|
g_free(strnum);
|
2006-01-12 18:56:00 +00:00
|
|
|
g_free(errstr);
|
2006-01-12 18:40:47 +00:00
|
|
|
}
|
2006-01-12 18:56:00 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
/* XXX would be nice to have errno strings, are they printed to stdout? */
|
2006-01-25 17:20:21 +00:00
|
|
|
tr_setBindPort(data->tr, gtk_spin_button_get_value_as_int(data->port));
|
2006-01-12 18:56:00 +00:00
|
|
|
setlimit(data->tr);
|
2006-01-12 18:40:47 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 17:33:57 +00:00
|
|
|
if(GTK_RESPONSE_APPLY != resp)
|
|
|
|
gtk_widget_destroy(widget);
|
2006-01-12 18:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setlimit(tr_handle_t *tr) {
|
2006-04-07 14:14:40 +00:00
|
|
|
struct { void (*func)(tr_handle_t*, int);
|
2006-04-15 03:22:04 +00:00
|
|
|
const char *use; const char *num; gboolean defuse; long def; } lim[] = {
|
|
|
|
{tr_setDownloadLimit, PREF_USEDOWNLIMIT, PREF_DOWNLIMIT,
|
|
|
|
DEF_USEDOWNLIMIT, DEF_DOWNLIMIT},
|
|
|
|
{tr_setUploadLimit, PREF_USEUPLIMIT, PREF_UPLIMIT,
|
|
|
|
DEF_USEUPLIMIT, DEF_UPLIMIT},
|
2006-04-07 14:14:40 +00:00
|
|
|
};
|
2006-04-15 03:22:04 +00:00
|
|
|
const char *pref;
|
2006-04-07 14:14:40 +00:00
|
|
|
unsigned int ii;
|
2006-01-12 18:40:47 +00:00
|
|
|
|
2006-04-07 14:14:40 +00:00
|
|
|
for(ii = 0; ii < ALEN(lim); ii++) {
|
2006-04-15 03:22:04 +00:00
|
|
|
pref = cf_getpref(lim[ii].use);
|
|
|
|
if(!(NULL == pref ? lim[ii].defuse : strbool(pref)))
|
2006-04-07 14:14:40 +00:00
|
|
|
lim[ii].func(tr, -1);
|
2006-04-15 03:22:04 +00:00
|
|
|
else {
|
|
|
|
pref = cf_getpref(lim[ii].num);
|
|
|
|
lim[ii].func(tr, (NULL == pref ? lim[ii].def : strtol(pref, NULL, 10)));
|
|
|
|
}
|
2006-04-07 14:14:40 +00:00
|
|
|
}
|
2006-01-12 18:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-03-23 12:39:39 +00:00
|
|
|
makeaddwind(GtkWindow *parent, add_torrent_func_t addfunc,
|
|
|
|
torrents_added_func_t donefunc, void *cbdata) {
|
2006-02-04 18:03:05 +00:00
|
|
|
GtkWidget *wind = gtk_file_chooser_dialog_new(_("Add a Torrent"), parent,
|
2006-01-12 18:55:27 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
|
|
|
|
struct addcb *data = g_new(struct addcb, 1);
|
2006-01-25 16:55:45 +00:00
|
|
|
GtkWidget *vbox = gtk_vbox_new(FALSE, 3);
|
2006-01-12 18:55:27 +00:00
|
|
|
GtkWidget *bbox = gtk_hbutton_box_new();
|
2006-02-05 17:33:57 +00:00
|
|
|
GtkWidget *autocheck = gtk_check_button_new_with_mnemonic(
|
|
|
|
_("Automatically _start torrent"));
|
|
|
|
GtkWidget *dircheck = gtk_check_button_new_with_mnemonic(
|
|
|
|
_("Use alternate _download directory"));
|
2006-01-12 18:55:27 +00:00
|
|
|
GtkFileFilter *filter = gtk_file_filter_new();
|
|
|
|
GtkFileFilter *unfilter = gtk_file_filter_new();
|
|
|
|
GtkWidget *getdir = gtk_file_chooser_button_new(
|
2006-02-04 18:03:05 +00:00
|
|
|
_("Choose a download directory"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
2006-01-12 18:55:27 +00:00
|
|
|
const char *pref;
|
|
|
|
|
|
|
|
data->addfunc = addfunc;
|
|
|
|
data->parent = parent;
|
|
|
|
data->donefunc = donefunc;
|
2006-03-23 12:39:39 +00:00
|
|
|
data->data = cbdata;
|
2006-01-12 18:55:27 +00:00
|
|
|
data->autostart = TRUE;
|
|
|
|
data->usingaltdir = FALSE;
|
|
|
|
data->altdir = GTK_FILE_CHOOSER(getdir);
|
|
|
|
data->altbox = GTK_BUTTON_BOX(bbox);
|
|
|
|
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_EDGE);
|
2006-01-12 18:55:27 +00:00
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(bbox), dircheck);
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(bbox), getdir);
|
|
|
|
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), autocheck);
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), bbox);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autocheck), TRUE);
|
|
|
|
if(NULL != (pref = cf_getpref(PREF_DIR)))
|
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(getdir), pref);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dircheck), FALSE);
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_widget_set_sensitive(getdir, FALSE);
|
2006-01-12 18:55:27 +00:00
|
|
|
|
2006-02-04 18:03:05 +00:00
|
|
|
gtk_file_filter_set_name(filter, _("Torrent files"));
|
2006-01-12 18:55:27 +00:00
|
|
|
gtk_file_filter_add_pattern(filter, "*.torrent");
|
2006-02-04 18:03:05 +00:00
|
|
|
gtk_file_filter_set_name(unfilter, _("All files"));
|
2006-01-12 18:55:27 +00:00
|
|
|
gtk_file_filter_add_pattern(unfilter, "*");
|
|
|
|
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(wind), filter);
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(wind), unfilter);
|
|
|
|
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(wind), TRUE);
|
|
|
|
gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(wind), vbox);
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(autocheck), "clicked", G_CALLBACK(autoclick),data);
|
|
|
|
g_signal_connect(G_OBJECT(dircheck), "clicked", G_CALLBACK(dirclick), data);
|
|
|
|
g_signal_connect(G_OBJECT(wind), "response", G_CALLBACK(addresp), data);
|
|
|
|
|
|
|
|
gtk_widget_show_all(wind);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
autoclick(GtkWidget *widget, gpointer gdata) {
|
|
|
|
struct addcb *data = gdata;
|
|
|
|
|
|
|
|
data->autostart = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dirclick(GtkWidget *widget, gpointer gdata) {
|
|
|
|
struct addcb *data = gdata;
|
|
|
|
|
|
|
|
data->usingaltdir = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(data->altdir), data->usingaltdir);
|
2006-01-12 18:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
addresp(GtkWidget *widget, gint resp, gpointer gdata) {
|
|
|
|
struct addcb *data = gdata;
|
|
|
|
GSList *files, *ii;
|
|
|
|
gboolean added = FALSE;
|
|
|
|
char *dir = NULL;
|
|
|
|
|
|
|
|
if(GTK_RESPONSE_ACCEPT == resp) {
|
|
|
|
if(data->usingaltdir)
|
|
|
|
dir = gtk_file_chooser_get_filename(data->altdir);
|
|
|
|
files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(widget));
|
|
|
|
for(ii = files; NULL != ii; ii = ii->next)
|
2006-03-23 12:39:39 +00:00
|
|
|
if(data->addfunc(data->data, ii->data, dir,
|
|
|
|
/* XXX need to group errors here */
|
2006-02-05 17:33:57 +00:00
|
|
|
!data->autostart, NULL))
|
2006-01-12 18:55:27 +00:00
|
|
|
added = TRUE;
|
|
|
|
if(added)
|
2006-03-23 12:39:39 +00:00
|
|
|
data->donefunc(data->data);
|
2006-01-12 18:55:27 +00:00
|
|
|
if(NULL != dir)
|
|
|
|
g_free(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy(widget);
|
2006-01-12 18:40:47 +00:00
|
|
|
}
|
2006-01-12 19:00:58 +00:00
|
|
|
|
|
|
|
#define INFOLINE(tab, ii, nam, val) \
|
|
|
|
do { \
|
2006-02-04 18:03:05 +00:00
|
|
|
char *txt = g_markup_printf_escaped("<b>%s</b>", nam); \
|
2006-01-12 19:00:58 +00:00
|
|
|
GtkWidget *wid = gtk_label_new(NULL); \
|
2006-04-29 16:29:04 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(wid), 0, .5); \
|
2006-02-04 18:03:05 +00:00
|
|
|
gtk_label_set_markup(GTK_LABEL(wid), txt); \
|
2006-01-12 19:00:58 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(tab), wid, 0, 1, ii, ii + 1); \
|
|
|
|
wid = gtk_label_new(val); \
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_label_set_selectable(GTK_LABEL(wid), TRUE); \
|
2006-01-12 19:00:58 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(wid), 0, .5); \
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(tab), wid, 1, 2, ii, ii + 1); \
|
|
|
|
ii++; \
|
2006-02-04 18:03:05 +00:00
|
|
|
g_free(txt); \
|
2006-02-05 17:33:57 +00:00
|
|
|
} while(0)
|
2006-01-12 19:00:58 +00:00
|
|
|
|
|
|
|
#define INFOLINEF(tab, ii, fmt, nam, val) \
|
|
|
|
do { \
|
|
|
|
char *buf = g_strdup_printf(fmt, val); \
|
|
|
|
INFOLINE(tab, ii, nam, buf); \
|
|
|
|
g_free(buf); \
|
2006-02-05 17:33:57 +00:00
|
|
|
} while(0)
|
2006-01-12 19:00:58 +00:00
|
|
|
|
|
|
|
#define INFOLINEA(tab, ii, nam, val) \
|
|
|
|
do { \
|
|
|
|
char *buf = val; \
|
|
|
|
INFOLINE(tab, ii, nam, buf); \
|
|
|
|
g_free(buf); \
|
2006-02-05 17:33:57 +00:00
|
|
|
} while(0)
|
2006-01-12 19:00:58 +00:00
|
|
|
|
|
|
|
#define INFOSEP(tab, ii) \
|
|
|
|
do { \
|
|
|
|
GtkWidget *wid = gtk_hseparator_new(); \
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(tab), wid, 0, 2, ii, ii + 1); \
|
|
|
|
ii++; \
|
2006-02-05 17:33:57 +00:00
|
|
|
} while(0)
|
2006-01-12 19:00:58 +00:00
|
|
|
|
|
|
|
void
|
2006-03-23 12:39:39 +00:00
|
|
|
makeinfowind(GtkWindow *parent, tr_torrent_t *tor) {
|
2006-01-12 19:00:58 +00:00
|
|
|
tr_stat_t *sb;
|
2006-03-23 12:39:39 +00:00
|
|
|
tr_info_t *in;
|
2006-02-05 17:33:57 +00:00
|
|
|
GtkWidget *wind, *label;
|
2006-01-12 19:00:58 +00:00
|
|
|
int ii;
|
|
|
|
char *str;
|
2006-02-07 17:15:16 +00:00
|
|
|
const int rowcount = 14;
|
2006-02-05 17:33:57 +00:00
|
|
|
GtkWidget *table = gtk_table_new(rowcount, 2, FALSE);
|
2006-01-12 19:00:58 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
sb = tr_torrentStat(tor);
|
|
|
|
in = tr_torrentInfo(tor);
|
|
|
|
str = g_strdup_printf(_("%s Properties"), in->name);
|
2006-01-12 19:00:58 +00:00
|
|
|
wind = gtk_dialog_new_with_buttons(str, parent,
|
2006-01-25 16:55:45 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
|
2006-01-12 19:00:58 +00:00
|
|
|
g_free(str);
|
|
|
|
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_widget_set_name(wind, "TransmissionDialog");
|
2006-01-25 16:55:45 +00:00
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(table), 12);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(table), 12);
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(wind), GTK_RESPONSE_ACCEPT);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(table), 6);
|
|
|
|
gtk_window_set_resizable(GTK_WINDOW(wind), FALSE);
|
2006-01-12 19:00:58 +00:00
|
|
|
|
|
|
|
label = gtk_label_new(NULL);
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_label_set_selectable(GTK_LABEL(label), TRUE);
|
2006-03-23 12:39:39 +00:00
|
|
|
str = g_markup_printf_escaped("<big>%s</big>", in->name);
|
2006-01-12 19:00:58 +00:00
|
|
|
gtk_label_set_markup(GTK_LABEL(label), str);
|
|
|
|
g_free(str);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 0, 1);
|
|
|
|
|
|
|
|
ii = 1;
|
|
|
|
|
|
|
|
INFOSEP(table, ii);
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
if(80 == in->trackerPort)
|
2006-02-05 17:33:57 +00:00
|
|
|
INFOLINEA(table, ii, _("Tracker:"), g_strdup_printf("http://%s",
|
2006-03-23 12:39:39 +00:00
|
|
|
in->trackerAddress));
|
2006-02-05 17:33:57 +00:00
|
|
|
else
|
|
|
|
INFOLINEA(table, ii, _("Tracker:"), g_strdup_printf("http://%s:%i",
|
2006-03-23 12:39:39 +00:00
|
|
|
in->trackerAddress, in->trackerPort));
|
|
|
|
INFOLINE(table, ii, _("Announce:"), in->trackerAnnounce);
|
|
|
|
INFOLINEA(table, ii, _("Piece Size:"), readablesize(in->pieceSize));
|
|
|
|
INFOLINEF(table, ii, "%i", _("Pieces:"), in->pieceCount);
|
|
|
|
INFOLINEA(table, ii, _("Total Size:"), readablesize(in->totalSize));
|
|
|
|
if(0 > sb->seeders)
|
2006-02-10 05:58:08 +00:00
|
|
|
INFOLINE(table, ii, _("Seeders:"), _("?"));
|
|
|
|
else
|
2006-03-23 12:39:39 +00:00
|
|
|
INFOLINEF(table, ii, "%i", _("Seeders:"), sb->seeders);
|
|
|
|
if(0 > sb->leechers)
|
2006-02-10 05:58:08 +00:00
|
|
|
INFOLINE(table, ii, _("Leechers:"), _("?"));
|
|
|
|
else
|
2006-03-23 12:39:39 +00:00
|
|
|
INFOLINEF(table, ii, "%i", _("Leechers:"), sb->leechers);
|
2006-01-12 19:00:58 +00:00
|
|
|
|
|
|
|
INFOSEP(table, ii);
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
INFOLINE(table, ii, _("Directory:"), tr_torrentGetFolder(tor));
|
|
|
|
INFOLINEA(table, ii, _("Downloaded:"), readablesize(sb->downloaded));
|
|
|
|
INFOLINEA(table, ii, _("Uploaded:"), readablesize(sb->uploaded));
|
2006-01-12 19:00:58 +00:00
|
|
|
|
2006-01-25 16:55:45 +00:00
|
|
|
INFOSEP(table, ii);
|
|
|
|
|
2006-01-12 19:00:58 +00:00
|
|
|
assert(rowcount == ii);
|
|
|
|
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(wind)->vbox), table);
|
|
|
|
g_signal_connect(G_OBJECT(wind), "response",
|
|
|
|
G_CALLBACK(gtk_widget_destroy), NULL);
|
|
|
|
gtk_widget_show_all(wind);
|
|
|
|
}
|