2006-01-12 18:32:29 +00:00
|
|
|
/*
|
2006-05-29 21:21:23 +00:00
|
|
|
$Id$
|
|
|
|
|
2006-01-25 16:55:45 +00:00
|
|
|
Copyright (c) 2005-2006 Joshua Elsasser. All rights reserved.
|
2006-01-12 18:32:29 +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 18:40:47 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <errno.h>
|
2006-03-23 12:39:39 +00:00
|
|
|
#include <signal.h>
|
2006-01-12 18:32:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2006-02-04 18:03:05 +00:00
|
|
|
#include <glib/gi18n.h>
|
2006-02-10 01:49:10 +00:00
|
|
|
#include <glib/gstdio.h>
|
2006-02-04 18:03:05 +00:00
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
#include "conf.h"
|
2006-01-30 16:05:18 +00:00
|
|
|
#include "dialogs.h"
|
2006-04-25 07:26:27 +00:00
|
|
|
#include "ipc.h"
|
2006-05-03 06:58:16 +00:00
|
|
|
#include "tr_backend.h"
|
|
|
|
#include "tr_torrent.h"
|
|
|
|
#include "tr_cell_renderer_torrent.h"
|
2006-01-12 18:32:29 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2006-05-03 10:09:11 +00:00
|
|
|
/* time in seconds to wait for torrents to stop when exiting */
|
2006-01-12 18:47:30 +00:00
|
|
|
#define TRACKER_EXIT_TIMEOUT 5
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-05-03 10:09:11 +00:00
|
|
|
/* interval in milliseconds to update the torrent list display */
|
|
|
|
#define UPDATE_INTERVAL 500
|
|
|
|
|
|
|
|
/* interval in milliseconds to check for stopped torrents and update display */
|
|
|
|
#define EXIT_CHECK_INTERVAL 500
|
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
struct cbdata {
|
2006-05-03 06:58:16 +00:00
|
|
|
TrBackend *back;
|
2006-01-12 18:40:47 +00:00
|
|
|
GtkWindow *wind;
|
2006-03-23 12:39:39 +00:00
|
|
|
GtkTreeModel *model;
|
2006-01-12 18:32:29 +00:00
|
|
|
GtkTreeView *view;
|
2006-01-12 18:47:30 +00:00
|
|
|
GtkStatusbar *bar;
|
|
|
|
GtkWidget **buttons;
|
2006-01-12 18:32:29 +00:00
|
|
|
guint timer;
|
2006-02-05 17:33:57 +00:00
|
|
|
gboolean prefsopen;
|
2006-05-03 06:58:16 +00:00
|
|
|
GtkWidget *stupidpopuphack;
|
2006-05-31 23:20:59 +00:00
|
|
|
gboolean closing;
|
2006-01-12 18:32:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct exitdata {
|
|
|
|
struct cbdata *cbdata;
|
|
|
|
time_t started;
|
|
|
|
guint timer;
|
|
|
|
};
|
|
|
|
|
2006-04-25 07:26:27 +00:00
|
|
|
GList *
|
|
|
|
readargs(int argc, char **argv);
|
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
void
|
2006-05-03 06:58:16 +00:00
|
|
|
makewind(GtkWidget *wind, TrBackend *back, benc_val_t *state, GList *args);
|
2006-05-03 10:09:11 +00:00
|
|
|
void
|
|
|
|
quittransmission(struct cbdata *data);
|
2006-03-23 12:39:39 +00:00
|
|
|
GtkWidget *
|
|
|
|
makewind_toolbar(struct cbdata *data);
|
|
|
|
GtkWidget *
|
2006-06-18 07:41:36 +00:00
|
|
|
makewind_list(struct cbdata *data, GObject **sizehack);
|
2006-01-12 18:32:29 +00:00
|
|
|
gboolean
|
|
|
|
winclose(GtkWidget *widget, GdkEvent *event, gpointer gdata);
|
|
|
|
gboolean
|
|
|
|
exitcheck(gpointer gdata);
|
2006-01-12 19:04:05 +00:00
|
|
|
void
|
2006-02-06 05:48:26 +00:00
|
|
|
setupdrag(GtkWidget *widget, struct cbdata *data);
|
|
|
|
void
|
|
|
|
gotdrag(GtkWidget *widget, GdkDragContext *dc, gint x, gint y,
|
|
|
|
GtkSelectionData *sel, guint info, guint time, gpointer gdata);
|
2006-01-12 18:56:00 +00:00
|
|
|
static void
|
|
|
|
stylekludge(GObject *obj, GParamSpec *spec, gpointer gdata);
|
2006-01-12 18:47:30 +00:00
|
|
|
void
|
|
|
|
fixbuttons(GtkTreeSelection *sel, gpointer gdata);
|
|
|
|
void
|
|
|
|
dfname(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter, gpointer gdata);
|
|
|
|
void
|
|
|
|
dfprog(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter, gpointer gdata);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
updatemodel(gpointer gdata);
|
|
|
|
gboolean
|
|
|
|
listclick(GtkWidget *widget, GdkEventButton *event, gpointer gdata);
|
|
|
|
gboolean
|
2006-01-12 18:47:30 +00:00
|
|
|
listpopup(GtkWidget *widget, gpointer gdata);
|
2006-01-12 18:32:29 +00:00
|
|
|
void
|
2006-05-03 06:58:16 +00:00
|
|
|
dopopupmenu(GdkEventButton *event, struct cbdata *data);
|
2006-01-12 18:32:29 +00:00
|
|
|
void
|
|
|
|
actionclick(GtkWidget *widget, gpointer gdata);
|
2006-01-12 19:04:05 +00:00
|
|
|
gint
|
|
|
|
intrevcmp(gconstpointer a, gconstpointer b);
|
2006-01-12 19:00:58 +00:00
|
|
|
void
|
|
|
|
doubleclick(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col,
|
|
|
|
gpointer gdata);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
|
|
|
void
|
2006-05-03 06:58:16 +00:00
|
|
|
addtorrents(void *vdata, void *state, GList *files,
|
2006-06-10 06:53:20 +00:00
|
|
|
const char *dir, guint flags);
|
2006-05-03 06:58:16 +00:00
|
|
|
void
|
|
|
|
savetorrents(struct cbdata *data);
|
2006-01-12 19:00:58 +00:00
|
|
|
void
|
|
|
|
orstatus(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
|
|
|
|
gpointer gdata);
|
|
|
|
void
|
2006-05-03 06:58:16 +00:00
|
|
|
istorsel(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
|
|
|
|
gpointer gdata);
|
2006-03-23 12:39:39 +00:00
|
|
|
void
|
2006-04-25 07:26:27 +00:00
|
|
|
safepipe(void);
|
|
|
|
void
|
2006-03-23 12:39:39 +00:00
|
|
|
setupsighandlers(void);
|
|
|
|
void
|
|
|
|
fatalsig(int sig);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
|
|
|
#define LIST_ACTION "torrent-list-action"
|
2006-01-12 18:40:47 +00:00
|
|
|
enum listact { ACT_OPEN, ACT_START, ACT_STOP, ACT_DELETE, ACT_INFO, ACT_PREF };
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-01-12 18:47:30 +00:00
|
|
|
struct { const gchar *name; const gchar *id; enum listact act; gboolean nomenu;
|
|
|
|
int avail; const char *ttext; const char *tpriv; }
|
2006-01-12 18:32:29 +00:00
|
|
|
actionitems[] = {
|
2006-02-04 18:03:05 +00:00
|
|
|
{N_("Add"), GTK_STOCK_ADD, ACT_OPEN, FALSE, 0,
|
|
|
|
N_("Add a new torrent"), "XXX"},
|
|
|
|
{N_("Start"), GTK_STOCK_EXECUTE, ACT_START, FALSE,
|
2006-03-23 12:39:39 +00:00
|
|
|
TR_STATUS_INACTIVE,
|
2006-02-04 18:03:05 +00:00
|
|
|
N_("Start a torrent that is not running"), "XXX"},
|
|
|
|
{N_("Stop"), GTK_STOCK_STOP, ACT_STOP, FALSE,
|
2006-03-23 12:39:39 +00:00
|
|
|
TR_STATUS_ACTIVE,
|
2006-02-04 18:03:05 +00:00
|
|
|
N_("Stop a torrent that is running"), "XXX"},
|
|
|
|
{N_("Remove"), GTK_STOCK_REMOVE, ACT_DELETE, FALSE, ~0,
|
|
|
|
N_("Remove a torrent"), "XXX"},
|
|
|
|
{N_("Properties"), GTK_STOCK_PROPERTIES, ACT_INFO, FALSE, ~0,
|
|
|
|
N_("Show additional information about a torrent"), "XXX"},
|
|
|
|
{N_("Preferences"), GTK_STOCK_PREFERENCES, ACT_PREF, TRUE, 0,
|
|
|
|
N_("Customize application behavior"), "XXX"},
|
2006-01-12 18:32:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CBDATA_PTR "callback-data-pointer"
|
2006-03-23 12:39:39 +00:00
|
|
|
|
|
|
|
#define SIGCOUNT_MAX 3
|
|
|
|
|
|
|
|
static sig_atomic_t global_sigcount = 0;
|
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
|
|
|
GtkWidget *mainwind, *preferr, *stateerr;
|
|
|
|
char *err;
|
2006-05-03 06:58:16 +00:00
|
|
|
TrBackend *back;
|
|
|
|
benc_val_t *state;
|
2006-01-12 18:40:47 +00:00
|
|
|
const char *pref;
|
|
|
|
long intval;
|
2006-04-25 07:26:27 +00:00
|
|
|
GList *argfiles;
|
|
|
|
gboolean didinit, didlock;
|
|
|
|
|
|
|
|
safepipe();
|
|
|
|
|
|
|
|
argfiles = readargs(argc, argv);
|
|
|
|
|
|
|
|
didinit = cf_init(tr_getPrefsDirectory(), NULL);
|
|
|
|
didlock = FALSE;
|
|
|
|
if(NULL != argfiles && didinit && !(didlock = cf_lock(NULL)))
|
|
|
|
return !ipc_sendfiles_blocking(argfiles);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
setupsighandlers();
|
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
|
2006-02-04 18:03:05 +00:00
|
|
|
bindtextdomain("transmission-gtk", LOCALEDIR);
|
2006-04-25 08:14:37 +00:00
|
|
|
bind_textdomain_codeset("transmission-gtk", "UTF-8");
|
2006-02-04 18:03:05 +00:00
|
|
|
textdomain("transmission-gtk");
|
|
|
|
|
|
|
|
g_set_application_name(_("Transmission"));
|
2006-01-25 16:55:45 +00:00
|
|
|
|
2006-02-05 17:33:57 +00:00
|
|
|
gtk_rc_parse_string(
|
|
|
|
"style \"transmission-standard\" {\n"
|
|
|
|
" GtkDialog::action-area-border = 6\n"
|
|
|
|
" GtkDialog::button-spacing = 12\n"
|
|
|
|
" GtkDialog::content-area-border = 6\n"
|
|
|
|
"}\n"
|
|
|
|
"widget \"TransmissionDialog\" style \"transmission-standard\"\n");
|
|
|
|
|
2006-04-25 07:26:27 +00:00
|
|
|
if(didinit || cf_init(tr_getPrefsDirectory(), &err)) {
|
|
|
|
if(didlock || cf_lock(&err)) {
|
2006-05-03 06:58:16 +00:00
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
/* create main window now so any error dialogs can be it's children */
|
|
|
|
mainwind = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
preferr = NULL;
|
|
|
|
stateerr = NULL;
|
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
cf_loadprefs(&err);
|
|
|
|
if(NULL != err) {
|
2006-01-12 18:40:47 +00:00
|
|
|
preferr = errmsg(GTK_WINDOW(mainwind), "%s", err);
|
2006-01-12 18:32:29 +00:00
|
|
|
g_free(err);
|
|
|
|
}
|
2006-05-03 06:58:16 +00:00
|
|
|
state = cf_loadstate(&err);
|
2006-01-12 18:32:29 +00:00
|
|
|
if(NULL != err) {
|
2006-01-12 18:40:47 +00:00
|
|
|
stateerr = errmsg(GTK_WINDOW(mainwind), "%s", err);
|
2006-01-12 18:32:29 +00:00
|
|
|
g_free(err);
|
|
|
|
}
|
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
back = tr_backend_new();
|
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
/* set the upload limit */
|
2006-05-03 06:58:16 +00:00
|
|
|
setlimit(back);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
/* set the listening port */
|
|
|
|
if(NULL != (pref = cf_getpref(PREF_PORT)) &&
|
|
|
|
0 < (intval = strtol(pref, NULL, 10)) && 0xffff >= intval)
|
2006-05-03 06:58:16 +00:00
|
|
|
tr_setBindPort(tr_backend_handle(back), intval);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
makewind(mainwind, back, state, argfiles);
|
|
|
|
|
2006-05-05 20:57:42 +00:00
|
|
|
if(NULL != state)
|
|
|
|
cf_freestate(state);
|
2006-05-03 06:58:16 +00:00
|
|
|
g_object_unref(back);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
|
|
|
if(NULL != preferr)
|
|
|
|
gtk_widget_show_all(preferr);
|
|
|
|
if(NULL != stateerr)
|
|
|
|
gtk_widget_show_all(stateerr);
|
|
|
|
} else {
|
2006-01-12 19:04:05 +00:00
|
|
|
gtk_widget_show(errmsg_full(NULL, (callbackfunc_t)gtk_main_quit,
|
2006-01-12 18:40:47 +00:00
|
|
|
NULL, "%s", err));
|
2006-01-12 18:32:29 +00:00
|
|
|
g_free(err);
|
|
|
|
}
|
|
|
|
} else {
|
2006-01-12 19:04:05 +00:00
|
|
|
gtk_widget_show(errmsg_full(NULL, (callbackfunc_t)gtk_main_quit,
|
2006-01-12 18:40:47 +00:00
|
|
|
NULL, "%s", err));
|
2006-01-12 18:32:29 +00:00
|
|
|
g_free(err);
|
|
|
|
}
|
|
|
|
|
2006-04-25 07:26:27 +00:00
|
|
|
if(NULL != argfiles)
|
|
|
|
freestrlist(argfiles);
|
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-25 07:26:27 +00:00
|
|
|
GList *
|
|
|
|
readargs(int argc, char **argv) {
|
2006-06-11 06:08:58 +00:00
|
|
|
char *name;
|
|
|
|
|
|
|
|
if(NULL == (name = strrchr(argv[0], '/')) || '\0' == *(++name))
|
|
|
|
name = argv[0];
|
|
|
|
|
2006-04-25 07:26:27 +00:00
|
|
|
while(0 < --argc) {
|
|
|
|
argv++;
|
|
|
|
if(0 == strcmp("--", *argv))
|
|
|
|
return checkfilenames(argc - 1, argv + 1);
|
|
|
|
else if('-' != argv[0][0])
|
|
|
|
return checkfilenames(argc, argv);
|
2006-06-11 06:08:58 +00:00
|
|
|
else if(0 == strcmp("-v", *argv) || 0 == strcmp("--version", *argv)) {
|
|
|
|
printf("%s %s (%d) http://transmission.m0k.org/\n",
|
|
|
|
name, VERSION_STRING, VERSION_REVISION);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
else if(0 == strcmp("-h", *argv) || 0 == strcmp("--help", *argv)) {
|
|
|
|
printf("usage: %1$s [-hv] [files...]\n\n"
|
|
|
|
"If %1$s is already running then a second copy will not be\n"
|
|
|
|
"started, any torrents on the command-line will be opened in the first.\n",
|
|
|
|
name);
|
|
|
|
exit(0);
|
|
|
|
}
|
2006-04-25 07:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
void
|
2006-05-03 06:58:16 +00:00
|
|
|
makewind(GtkWidget *wind, TrBackend *back, benc_val_t *state, GList *args) {
|
2006-01-12 18:32:29 +00:00
|
|
|
GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
|
|
|
|
GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL);
|
2006-01-12 18:47:30 +00:00
|
|
|
GtkWidget *status = gtk_statusbar_new();
|
2006-01-12 18:32:29 +00:00
|
|
|
struct cbdata *data = g_new0(struct cbdata, 1);
|
|
|
|
GtkWidget *list;
|
|
|
|
GtkRequisition req;
|
2006-06-18 07:41:36 +00:00
|
|
|
gint width, height;
|
|
|
|
GObject *sizehack;
|
|
|
|
GdkScreen *screen;
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
g_object_ref(G_OBJECT(back));
|
|
|
|
data->back = back;
|
2006-01-12 18:40:47 +00:00
|
|
|
data->wind = GTK_WINDOW(wind);
|
2006-05-03 10:09:11 +00:00
|
|
|
data->timer = 0;
|
2006-01-12 18:32:29 +00:00
|
|
|
/* filled in by makewind_list */
|
|
|
|
data->model = NULL;
|
|
|
|
data->view = NULL;
|
2006-01-12 18:47:30 +00:00
|
|
|
data->bar = GTK_STATUSBAR(status);
|
|
|
|
data->buttons = NULL;
|
2006-02-05 17:33:57 +00:00
|
|
|
data->prefsopen = FALSE;
|
2006-05-03 06:58:16 +00:00
|
|
|
data->stupidpopuphack = NULL;
|
2006-05-31 23:20:59 +00:00
|
|
|
data->closing = FALSE;
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-01-12 18:48:53 +00:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_NEVER,
|
2006-06-19 04:19:13 +00:00
|
|
|
GTK_POLICY_ALWAYS);
|
2006-01-12 18:48:53 +00:00
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), makewind_toolbar(data), FALSE, FALSE, 0);
|
|
|
|
|
2006-06-18 07:41:36 +00:00
|
|
|
sizehack = NULL;
|
|
|
|
list = makewind_list(data, &sizehack);
|
2006-01-12 18:32:29 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(scroll), list);
|
2006-01-12 18:47:30 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
gtk_statusbar_push(GTK_STATUSBAR(status), 0, "");
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), status, FALSE, FALSE, 0);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-05-03 10:09:11 +00:00
|
|
|
gtk_container_set_focus_child(GTK_CONTAINER(vbox), scroll);
|
2006-01-12 18:32:29 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(wind), vbox);
|
2006-01-25 16:55:45 +00:00
|
|
|
gtk_window_set_title(data->wind, g_get_application_name());
|
2006-01-12 18:32:29 +00:00
|
|
|
g_signal_connect(G_OBJECT(wind), "delete_event", G_CALLBACK(winclose), data);
|
|
|
|
|
2006-02-06 05:48:26 +00:00
|
|
|
setupdrag(list, data);
|
|
|
|
|
2006-06-10 06:53:20 +00:00
|
|
|
addtorrents(data, state, args, NULL, addactionflag(cf_getpref(PREF_ADDIPC)));
|
2006-02-05 17:33:57 +00:00
|
|
|
|
2006-05-03 10:09:11 +00:00
|
|
|
data->timer = g_timeout_add(UPDATE_INTERVAL, updatemodel, data);
|
2006-01-12 18:32:29 +00:00
|
|
|
updatemodel(data);
|
2006-01-12 18:48:53 +00:00
|
|
|
|
2006-06-18 07:41:36 +00:00
|
|
|
/* some evil magic to try to get a nice initial window size */
|
2006-01-12 18:48:53 +00:00
|
|
|
gtk_widget_show_all(vbox);
|
|
|
|
gtk_widget_realize(wind);
|
2006-01-25 16:55:45 +00:00
|
|
|
gtk_widget_size_request(list, &req);
|
2006-01-12 18:48:53 +00:00
|
|
|
height = req.height;
|
|
|
|
gtk_widget_size_request(scroll, &req);
|
|
|
|
height -= req.height;
|
2006-01-25 16:55:45 +00:00
|
|
|
gtk_widget_size_request(wind, &req);
|
2006-01-12 18:48:53 +00:00
|
|
|
height += req.height;
|
2006-06-18 07:41:36 +00:00
|
|
|
screen = gtk_widget_get_screen(wind);
|
|
|
|
width = MIN(req.width, gdk_screen_get_width(screen) / 2);
|
|
|
|
height = MIN(height, gdk_screen_get_height(screen) / 5 * 4);
|
|
|
|
if(height > req.width)
|
|
|
|
height = MIN(height, width * 8 / 5);
|
|
|
|
else
|
|
|
|
height = MAX(height, width * 5 / 8);
|
|
|
|
height = (height > req.width ?
|
|
|
|
MIN(height, width * 8 / 5) : MAX(height, width * 5 / 8));
|
|
|
|
g_object_set(sizehack, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
gtk_widget_show_now(wind);
|
|
|
|
gtk_window_resize(GTK_WINDOW(wind), width, height);
|
|
|
|
|
|
|
|
/* set up the ipc socket now that we're ready to get torrents from it */
|
2006-05-03 06:58:16 +00:00
|
|
|
ipc_socket_setup(GTK_WINDOW(wind), addtorrents, data);
|
2006-01-12 18:32:29 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 10:09:11 +00:00
|
|
|
void
|
|
|
|
quittransmission(struct cbdata *data) {
|
|
|
|
g_object_unref(G_OBJECT(data->back));
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(data->wind));
|
|
|
|
if(0 < data->timer)
|
|
|
|
g_source_remove(data->timer);
|
|
|
|
if(NULL != data->stupidpopuphack)
|
|
|
|
gtk_widget_destroy(data->stupidpopuphack);
|
|
|
|
g_free(data->buttons);
|
|
|
|
g_free(data);
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
GtkWidget *
|
|
|
|
makewind_toolbar(struct cbdata *data) {
|
|
|
|
GtkWidget *bar = gtk_toolbar_new();
|
|
|
|
GtkToolItem *item;
|
|
|
|
unsigned int ii;
|
|
|
|
|
|
|
|
gtk_toolbar_set_tooltips(GTK_TOOLBAR(bar), TRUE);
|
|
|
|
gtk_toolbar_set_show_arrow(GTK_TOOLBAR(bar), FALSE);
|
|
|
|
|
|
|
|
data->buttons = g_new(GtkWidget*, ALEN(actionitems));
|
|
|
|
|
|
|
|
for(ii = 0; ii < ALEN(actionitems); ii++) {
|
|
|
|
item = gtk_tool_button_new_from_stock(actionitems[ii].id);
|
|
|
|
data->buttons[ii] = GTK_WIDGET(item);
|
|
|
|
gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),
|
|
|
|
gettext(actionitems[ii].name));
|
|
|
|
gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLBAR(bar)->tooltips,
|
|
|
|
gettext(actionitems[ii].ttext),
|
|
|
|
actionitems[ii].tpriv);
|
|
|
|
g_object_set_data(G_OBJECT(item), LIST_ACTION,
|
|
|
|
GINT_TO_POINTER(actionitems[ii].act));
|
|
|
|
g_signal_connect(G_OBJECT(item), "clicked", G_CALLBACK(actionclick), data);
|
|
|
|
gtk_toolbar_insert(GTK_TOOLBAR(bar), item, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX check for unused data in model */
|
2006-05-03 06:58:16 +00:00
|
|
|
enum {
|
|
|
|
MC_NAME, MC_SIZE, MC_STAT, MC_ERR, MC_TERR,
|
|
|
|
MC_PROG, MC_DRATE, MC_URATE, MC_ETA, MC_PEERS,
|
|
|
|
MC_UPEERS, MC_DPEERS, MC_DOWN, MC_UP,
|
|
|
|
MC_TORRENT, MC_ROW_COUNT,
|
|
|
|
};
|
2006-03-23 12:39:39 +00:00
|
|
|
|
|
|
|
GtkWidget *
|
2006-06-18 07:41:36 +00:00
|
|
|
makewind_list(struct cbdata *data, GObject **sizehack) {
|
2006-03-23 12:39:39 +00:00
|
|
|
GType types[] = {
|
|
|
|
/* info->name, info->totalSize, status, error, trackerError, */
|
|
|
|
G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING,
|
|
|
|
/* progress, rateDownload, rateUpload, eta, peersTotal, */
|
|
|
|
G_TYPE_FLOAT, G_TYPE_FLOAT, G_TYPE_FLOAT, G_TYPE_INT, G_TYPE_INT,
|
2006-05-03 06:58:16 +00:00
|
|
|
/* peersUploading, peersDownloading, downloaded, uploaded */
|
|
|
|
G_TYPE_INT, G_TYPE_INT, G_TYPE_UINT64, G_TYPE_UINT64,
|
|
|
|
/* the torrent object */
|
|
|
|
TR_TORRENT_TYPE};
|
2006-03-23 12:39:39 +00:00
|
|
|
GtkListStore *store;
|
|
|
|
GtkWidget *view;
|
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkCellRenderer *namerend, *progrend;
|
|
|
|
char *str;
|
|
|
|
|
2006-05-03 10:09:11 +00:00
|
|
|
g_assert(MC_ROW_COUNT == ALEN(types));
|
2006-03-23 12:39:39 +00:00
|
|
|
|
|
|
|
store = gtk_list_store_newv(MC_ROW_COUNT, types);
|
|
|
|
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
|
|
|
|
/* XXX do I need to worry about reference counts anywhere else? */
|
|
|
|
g_object_unref(G_OBJECT(store));
|
|
|
|
data->model = GTK_TREE_MODEL(store);
|
|
|
|
data->view = GTK_TREE_VIEW(view);
|
|
|
|
|
|
|
|
namerend = gtk_cell_renderer_text_new();
|
2006-06-18 07:41:36 +00:00
|
|
|
*sizehack = G_OBJECT(namerend);
|
|
|
|
/* note that this renderer is set to ellipsize, just not here */
|
2006-03-23 12:39:39 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes(_("Name"), namerend, NULL);
|
|
|
|
gtk_tree_view_column_set_cell_data_func(col, namerend, dfname, NULL, NULL);
|
|
|
|
gtk_tree_view_column_set_expand(col, TRUE);
|
2006-06-18 07:41:36 +00:00
|
|
|
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
2006-03-23 12:39:39 +00:00
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
|
|
|
|
|
|
|
progrend = tr_cell_renderer_torrent_new();
|
|
|
|
/* this string is only used to determing the size of the progress bar */
|
|
|
|
str = g_markup_printf_escaped("<big>%s</big>", _(" fnord fnord "));
|
|
|
|
g_object_set(progrend, "label", str, NULL);
|
|
|
|
g_free(str);
|
|
|
|
col = gtk_tree_view_column_new_with_attributes(_("Progress"), progrend, NULL);
|
|
|
|
gtk_tree_view_column_set_cell_data_func(col, progrend, dfprog, NULL, NULL);
|
2006-06-18 07:41:36 +00:00
|
|
|
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
2006-03-23 12:39:39 +00:00
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
|
|
|
|
|
|
|
/* XXX this shouldn't be necessary */
|
|
|
|
g_signal_connect(view, "notify", G_CALLBACK(stylekludge), progrend);
|
|
|
|
|
|
|
|
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE);
|
|
|
|
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
|
|
|
|
gtk_tree_selection_set_mode(GTK_TREE_SELECTION(sel), GTK_SELECTION_MULTIPLE);
|
|
|
|
g_signal_connect(G_OBJECT(sel), "changed", G_CALLBACK(fixbuttons), data);
|
|
|
|
g_signal_connect(G_OBJECT(view), "button-press-event",
|
|
|
|
G_CALLBACK(listclick), data);
|
|
|
|
g_signal_connect(G_OBJECT(view), "popup-menu", G_CALLBACK(listpopup), data);
|
|
|
|
g_signal_connect(G_OBJECT(view), "row-activated",
|
|
|
|
G_CALLBACK(doubleclick), data);
|
|
|
|
gtk_widget_show_all(view);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
2006-01-12 18:32:29 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
winclose(GtkWidget *widget SHUTUP, GdkEvent *event SHUTUP, gpointer gdata) {
|
|
|
|
struct cbdata *data = gdata;
|
|
|
|
struct exitdata *edata;
|
2006-05-03 10:09:11 +00:00
|
|
|
unsigned int ii;
|
2006-05-31 23:20:59 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
TrTorrent *tor;
|
|
|
|
|
|
|
|
data->closing = TRUE;
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-05-03 10:09:11 +00:00
|
|
|
/* stop the update timer */
|
|
|
|
if(0 < data->timer)
|
2006-01-12 18:32:29 +00:00
|
|
|
g_source_remove(data->timer);
|
2006-05-03 10:09:11 +00:00
|
|
|
data->timer = 0;
|
2006-01-12 19:04:05 +00:00
|
|
|
|
2006-05-31 23:20:59 +00:00
|
|
|
/*
|
|
|
|
Add a reference to all torrents in the list, which will be removed
|
|
|
|
when the politely-stopped signal is emitted. This is necessary
|
|
|
|
because actionclick() adds a reference when it removes a torrent
|
|
|
|
from the model and calls tr_torrent_stop_polite() on it.
|
|
|
|
*/
|
|
|
|
if(gtk_tree_model_get_iter_first(data->model, &iter)) {
|
|
|
|
do
|
|
|
|
gtk_tree_model_get(data->model, &iter, MC_TORRENT, &tor, -1);
|
|
|
|
while(gtk_tree_model_iter_next(data->model, &iter));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to politely stop all the torrents */
|
2006-05-03 10:09:11 +00:00
|
|
|
tr_backend_stop_torrents(data->back);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-05-03 10:09:11 +00:00
|
|
|
/* set things up to wait for torrents to stop */
|
2006-01-12 18:32:29 +00:00
|
|
|
edata = g_new0(struct exitdata, 1);
|
|
|
|
edata->cbdata = data;
|
|
|
|
edata->started = time(NULL);
|
2006-05-03 10:09:11 +00:00
|
|
|
/* check if torrents are still running */
|
|
|
|
if(exitcheck(edata)) {
|
|
|
|
/* yes, start the exit timer and disable widgets */
|
|
|
|
edata->timer = g_timeout_add(EXIT_CHECK_INTERVAL, exitcheck, edata);
|
|
|
|
for(ii = 0; ii < ALEN(actionitems); ii++)
|
|
|
|
gtk_widget_set_sensitive(data->buttons[ii], FALSE);
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(data->view), FALSE);
|
|
|
|
}
|
2006-01-12 18:32:29 +00:00
|
|
|
|
|
|
|
/* returning FALSE means to destroy the window */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
exitcheck(gpointer gdata) {
|
|
|
|
struct exitdata *data = gdata;
|
|
|
|
|
|
|
|
/* keep going if we still have torrents and haven't hit the exit timeout */
|
2006-05-03 10:09:11 +00:00
|
|
|
if(time(NULL) - data->started < TRACKER_EXIT_TIMEOUT &&
|
|
|
|
!tr_backend_torrents_stopped(data->cbdata->back)) {
|
2006-01-12 18:32:29 +00:00
|
|
|
updatemodel(data->cbdata);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exit otherwise */
|
2006-05-03 10:09:11 +00:00
|
|
|
if(0 < data->timer)
|
2006-01-12 18:32:29 +00:00
|
|
|
g_source_remove(data->timer);
|
2006-05-03 10:09:11 +00:00
|
|
|
quittransmission(data->cbdata);
|
2006-01-12 18:32:29 +00:00
|
|
|
g_free(data);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-02-06 05:48:26 +00:00
|
|
|
void
|
|
|
|
gotdrag(GtkWidget *widget SHUTUP, GdkDragContext *dc, gint x SHUTUP,
|
|
|
|
gint y SHUTUP, GtkSelectionData *sel, guint info SHUTUP, guint time,
|
|
|
|
gpointer gdata) {
|
|
|
|
struct cbdata *data = gdata;
|
2006-02-10 01:49:10 +00:00
|
|
|
char prefix[] = "file:";
|
|
|
|
char *files, *decoded, *deslashed, *hostless;
|
|
|
|
int ii, len;
|
|
|
|
GList *errs;
|
|
|
|
struct stat sb;
|
|
|
|
int prelen = strlen(prefix);
|
2006-05-03 06:58:16 +00:00
|
|
|
GList *paths;
|
2006-02-10 01:49:10 +00:00
|
|
|
|
|
|
|
#ifdef DND_DEBUG
|
|
|
|
char *sele = gdk_atom_name(sel->selection);
|
|
|
|
char *targ = gdk_atom_name(sel->target);
|
|
|
|
char *type = gdk_atom_name(sel->type);
|
|
|
|
|
|
|
|
fprintf(stderr, "dropped file: sel=%s targ=%s type=%s fmt=%i len=%i\n",
|
|
|
|
sele, targ, type, sel->format, sel->length);
|
|
|
|
g_free(sele);
|
|
|
|
g_free(targ);
|
|
|
|
g_free(type);
|
|
|
|
if(8 == sel->format) {
|
|
|
|
for(ii = 0; ii < sel->length; ii++)
|
|
|
|
fprintf(stderr, "%02X ", sel->data[ii]);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
2006-02-06 05:48:26 +00:00
|
|
|
|
2006-02-10 01:49:10 +00:00
|
|
|
errs = NULL;
|
2006-05-03 06:58:16 +00:00
|
|
|
paths = NULL;
|
2006-02-06 05:48:26 +00:00
|
|
|
if(gdk_atom_intern("XdndSelection", FALSE) == sel->selection &&
|
2006-02-10 01:49:10 +00:00
|
|
|
8 == sel->format) {
|
|
|
|
/* split file list on carriage returns and linefeeds */
|
|
|
|
files = g_new(char, sel->length + 1);
|
|
|
|
memcpy(files, sel->data, sel->length);
|
|
|
|
files[sel->length] = '\0';
|
|
|
|
for(ii = 0; '\0' != files[ii]; ii++)
|
|
|
|
if('\015' == files[ii] || '\012' == files[ii])
|
|
|
|
files[ii] = '\0';
|
|
|
|
|
|
|
|
/* try to get a usable filename out of the URI supplied and add it */
|
|
|
|
for(ii = 0; ii < sel->length; ii += len + 1) {
|
|
|
|
if('\0' == files[ii])
|
|
|
|
len = 0;
|
|
|
|
else {
|
|
|
|
len = strlen(files + ii);
|
|
|
|
/* de-urlencode the URI */
|
|
|
|
decoded = urldecode(files + ii, len);
|
|
|
|
if(g_utf8_validate(decoded, -1, NULL)) {
|
|
|
|
/* remove the file: prefix */
|
|
|
|
if(prelen < len && 0 == strncmp(prefix, decoded, prelen)) {
|
|
|
|
deslashed = decoded + prelen;
|
|
|
|
/* trim excess / characters from the beginning */
|
|
|
|
while('/' == deslashed[0] && '/' == deslashed[1])
|
|
|
|
deslashed++;
|
|
|
|
/* if the file doesn't exist, the first part might be a hostname */
|
|
|
|
if(0 > g_stat(deslashed, &sb) &&
|
|
|
|
NULL != (hostless = strchr(deslashed + 1, '/')) &&
|
|
|
|
0 == g_stat(hostless, &sb))
|
|
|
|
deslashed = hostless;
|
2006-05-03 06:58:16 +00:00
|
|
|
/* finally, add it to the list of torrents to try adding */
|
|
|
|
paths = g_list_append(paths, deslashed);
|
2006-02-10 01:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(decoded);
|
|
|
|
}
|
2006-02-06 05:48:26 +00:00
|
|
|
}
|
2006-02-10 01:49:10 +00:00
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
/* try to add any torrents we found */
|
|
|
|
if(NULL != paths) {
|
2006-06-10 06:53:20 +00:00
|
|
|
addtorrents(data, NULL, paths, NULL,
|
2006-06-11 05:04:27 +00:00
|
|
|
addactionflag(cf_getpref(PREF_ADDSTD)));
|
2006-05-03 06:58:16 +00:00
|
|
|
freestrlist(paths);
|
2006-02-06 05:48:26 +00:00
|
|
|
}
|
2006-05-03 06:58:16 +00:00
|
|
|
g_free(files);
|
2006-02-06 05:48:26 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
gtk_drag_finish(dc, (NULL != paths), FALSE, time);
|
2006-02-06 05:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setupdrag(GtkWidget *widget, struct cbdata *data) {
|
|
|
|
GtkTargetEntry targets[] = {
|
|
|
|
{ "STRING", 0, 0 },
|
|
|
|
{ "text/plain", 0, 0 },
|
|
|
|
{ "text/uri-list", 0, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
g_signal_connect(widget, "drag_data_received", G_CALLBACK(gotdrag), data);
|
|
|
|
|
|
|
|
gtk_drag_dest_set(widget, GTK_DEST_DEFAULT_ALL, targets,
|
2006-02-08 04:45:46 +00:00
|
|
|
ALEN(targets), GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
2006-02-06 05:48:26 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:56:00 +00:00
|
|
|
/* kludge to have the progress bars notice theme changes */
|
|
|
|
static void
|
|
|
|
stylekludge(GObject *obj, GParamSpec *spec, gpointer gdata) {
|
|
|
|
if(0 == strcmp("style", spec->name)) {
|
2006-01-30 16:05:18 +00:00
|
|
|
tr_cell_renderer_torrent_reset_style(TR_CELL_RENDERER_TORRENT(gdata));
|
2006-01-12 18:56:00 +00:00
|
|
|
gtk_widget_queue_draw(GTK_WIDGET(obj));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:47:30 +00:00
|
|
|
/* disable buttons the user shouldn't be able to click on */
|
|
|
|
void
|
|
|
|
fixbuttons(GtkTreeSelection *sel, gpointer gdata) {
|
|
|
|
struct cbdata *data = gdata;
|
|
|
|
gboolean selected;
|
|
|
|
unsigned int ii;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if(NULL == sel)
|
|
|
|
sel = gtk_tree_view_get_selection(data->view);
|
2006-01-12 19:00:58 +00:00
|
|
|
status = 0;
|
|
|
|
gtk_tree_selection_selected_foreach(sel, orstatus, &status);
|
|
|
|
selected = (0 < gtk_tree_selection_count_selected_rows(sel));
|
2006-01-12 18:47:30 +00:00
|
|
|
|
|
|
|
for(ii = 0; ii < ALEN(actionitems); ii++)
|
|
|
|
if(actionitems[ii].avail)
|
|
|
|
gtk_widget_set_sensitive(data->buttons[ii],
|
|
|
|
(selected && (actionitems[ii].avail & status)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dfname(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
|
|
|
|
GtkTreeModel *model, GtkTreeIter *iter, gpointer gdata SHUTUP) {
|
2006-03-23 12:39:39 +00:00
|
|
|
char *name, *mb, *terr, *str, *top, *bottom;
|
2006-01-12 18:47:30 +00:00
|
|
|
guint64 size;
|
|
|
|
gfloat prog;
|
2006-03-23 12:39:39 +00:00
|
|
|
int status, err, eta, tpeers, upeers, dpeers;
|
2006-01-12 18:47:30 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get(model, iter, MC_NAME, &name, MC_STAT, &status,
|
2006-03-23 12:39:39 +00:00
|
|
|
MC_ERR, &err, MC_SIZE, &size, MC_PROG, &prog, MC_ETA, &eta,
|
|
|
|
MC_PEERS, &tpeers, MC_UPEERS, &upeers, MC_DPEERS, &dpeers, -1);
|
2006-01-12 18:47:30 +00:00
|
|
|
|
|
|
|
if(0 > tpeers)
|
|
|
|
tpeers = 0;
|
|
|
|
if(0 > upeers)
|
|
|
|
upeers = 0;
|
|
|
|
if(0 > dpeers)
|
|
|
|
dpeers = 0;
|
2006-02-24 14:07:38 +00:00
|
|
|
mb = readablesize(size);
|
2006-01-12 18:47:30 +00:00
|
|
|
prog *= 100;
|
|
|
|
|
|
|
|
if(status & TR_STATUS_CHECK)
|
2006-02-04 18:03:05 +00:00
|
|
|
top = g_strdup_printf(_("Checking existing files (%.1f%%)"), prog);
|
2006-02-15 22:55:59 +00:00
|
|
|
else if(status & TR_STATUS_DOWNLOAD) {
|
|
|
|
if(0 > eta)
|
|
|
|
top = g_strdup_printf(_("Finishing in --:--:-- (%.1f%%)"), prog);
|
|
|
|
else
|
|
|
|
top = g_strdup_printf(_("Finishing in %02i:%02i:%02i (%.1f%%)"),
|
|
|
|
eta / 60 / 60, eta / 60 % 60, eta % 60, prog);
|
|
|
|
}
|
2006-01-12 18:47:30 +00:00
|
|
|
else if(status & TR_STATUS_SEED)
|
2006-02-04 18:03:05 +00:00
|
|
|
top = g_strdup_printf(ngettext("Seeding, uploading to %d of %d peer",
|
|
|
|
"Seeding, uploading to %d of %d peers",
|
|
|
|
tpeers), dpeers, tpeers);
|
2006-01-12 18:47:30 +00:00
|
|
|
else if(status & TR_STATUS_STOPPING)
|
2006-02-04 18:03:05 +00:00
|
|
|
top = g_strdup(_("Stopping..."));
|
2006-01-12 18:47:30 +00:00
|
|
|
else if(status & TR_STATUS_PAUSE)
|
2006-02-04 18:03:05 +00:00
|
|
|
top = g_strdup_printf(_("Stopped (%.1f%%)"), prog);
|
2006-01-12 18:47:30 +00:00
|
|
|
else {
|
|
|
|
top = g_strdup("");
|
2006-05-03 10:09:11 +00:00
|
|
|
g_assert_not_reached();
|
2006-01-12 18:47:30 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
if(TR_NOERROR != err) {
|
|
|
|
gtk_tree_model_get(model, iter, MC_TERR, &terr, -1);
|
|
|
|
bottom = g_strconcat(_("Error: "), terr, NULL);
|
|
|
|
g_free(terr);
|
2006-01-12 18:47:30 +00:00
|
|
|
}
|
|
|
|
else if(status & TR_STATUS_DOWNLOAD)
|
2006-02-04 18:03:05 +00:00
|
|
|
bottom = g_strdup_printf(ngettext("Downloading from %i of %i peer",
|
|
|
|
"Downloading from %i of %i peers",
|
|
|
|
tpeers), upeers, tpeers);
|
2006-01-12 18:47:30 +00:00
|
|
|
else
|
|
|
|
bottom = NULL;
|
|
|
|
|
|
|
|
str = g_markup_printf_escaped("<big>%s (%s)</big>\n<small>%s\n%s</small>",
|
|
|
|
name, mb, top, (NULL == bottom ? "" : bottom));
|
|
|
|
g_object_set(rend, "markup", str, NULL);
|
|
|
|
g_free(name);
|
|
|
|
g_free(mb);
|
|
|
|
g_free(str);
|
|
|
|
g_free(top);
|
2006-05-03 06:58:16 +00:00
|
|
|
if(NULL != bottom)
|
|
|
|
g_free(bottom);
|
2006-01-12 18:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dfprog(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
|
|
|
|
GtkTreeModel *model, GtkTreeIter *iter, gpointer gdata SHUTUP) {
|
2006-02-04 18:03:05 +00:00
|
|
|
char *dlstr, *ulstr, *str, *marked;
|
2006-01-12 18:47:30 +00:00
|
|
|
gfloat prog, dl, ul;
|
2006-02-08 14:15:59 +00:00
|
|
|
guint64 down, up;
|
2006-01-12 18:47:30 +00:00
|
|
|
|
2006-02-08 14:15:59 +00:00
|
|
|
gtk_tree_model_get(model, iter, MC_PROG, &prog, MC_DRATE, &dl, MC_URATE, &ul,
|
|
|
|
MC_DOWN, &down, MC_UP, &up, -1);
|
2006-01-12 18:47:30 +00:00
|
|
|
if(0.0 > prog)
|
|
|
|
prog = 0.0;
|
|
|
|
else if(1.0 < prog)
|
|
|
|
prog = 1.0;
|
|
|
|
|
2006-02-24 14:07:38 +00:00
|
|
|
ulstr = readablesize(ul * 1024.0);
|
2006-02-07 17:15:16 +00:00
|
|
|
if(1.0 == prog) {
|
2006-02-08 14:15:59 +00:00
|
|
|
dlstr = ratiostr(down, up);
|
2006-02-07 17:15:16 +00:00
|
|
|
str = g_strdup_printf(_("Ratio: %s\nUL: %s/s"), dlstr, ulstr);
|
|
|
|
} else {
|
2006-02-24 14:07:38 +00:00
|
|
|
dlstr = readablesize(dl * 1024.0);
|
2006-02-07 17:15:16 +00:00
|
|
|
str = g_strdup_printf(_("DL: %s/s\nUL: %s/s"), dlstr, ulstr);
|
|
|
|
}
|
2006-02-04 18:03:05 +00:00
|
|
|
marked = g_markup_printf_escaped("<small>%s</small>", str);
|
2006-01-12 18:47:30 +00:00
|
|
|
g_object_set(rend, "text", str, "value", prog, NULL);
|
|
|
|
g_free(dlstr);
|
|
|
|
g_free(ulstr);
|
|
|
|
g_free(str);
|
2006-02-04 18:03:05 +00:00
|
|
|
g_free(marked);
|
2006-01-12 18:47:30 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
gboolean
|
|
|
|
updatemodel(gpointer gdata) {
|
|
|
|
struct cbdata *data = gdata;
|
2006-05-03 06:58:16 +00:00
|
|
|
TrTorrent *tor;
|
2006-01-12 18:32:29 +00:00
|
|
|
tr_stat_t *st;
|
2006-03-23 12:39:39 +00:00
|
|
|
tr_info_t *in;
|
2006-01-12 18:32:29 +00:00
|
|
|
GtkTreeIter iter;
|
2006-01-12 18:47:30 +00:00
|
|
|
float up, down;
|
|
|
|
char *upstr, *downstr, *str;
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
if(0 < global_sigcount) {
|
2006-05-03 10:09:11 +00:00
|
|
|
quittransmission(data);
|
|
|
|
return FALSE;
|
2006-01-12 18:32:29 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
if(gtk_tree_model_get_iter_first(data->model, &iter)) {
|
|
|
|
do {
|
|
|
|
gtk_tree_model_get(data->model, &iter, MC_TORRENT, &tor, -1);
|
2006-05-03 06:58:16 +00:00
|
|
|
st = tr_torrent_stat(tor);
|
|
|
|
in = tr_torrent_info(tor);
|
|
|
|
g_object_unref(tor);
|
2006-03-23 12:39:39 +00:00
|
|
|
/* XXX find out if setting the same data emits changed signal */
|
|
|
|
gtk_list_store_set(GTK_LIST_STORE(data->model), &iter, MC_NAME, in->name,
|
|
|
|
MC_SIZE, in->totalSize, MC_STAT, st->status, MC_ERR, st->error,
|
|
|
|
MC_TERR, st->trackerError, MC_PROG, st->progress,
|
|
|
|
MC_DRATE, st->rateDownload, MC_URATE, st->rateUpload, MC_ETA, st->eta,
|
|
|
|
MC_PEERS, st->peersTotal, MC_UPEERS, st->peersUploading,
|
|
|
|
MC_DPEERS, st->peersDownloading, MC_DOWN, st->downloaded,
|
|
|
|
MC_UP, st->uploaded, -1);
|
|
|
|
} while(gtk_tree_model_iter_next(data->model, &iter));
|
|
|
|
}
|
2006-01-12 18:45:41 +00:00
|
|
|
|
2006-01-12 18:47:30 +00:00
|
|
|
/* update the status bar */
|
2006-05-03 06:58:16 +00:00
|
|
|
tr_torrentRates(tr_backend_handle(data->back), &up, &down);
|
2006-02-24 14:07:38 +00:00
|
|
|
downstr = readablesize(down * 1024.0);
|
|
|
|
upstr = readablesize(up * 1024.0);
|
2006-02-04 18:03:05 +00:00
|
|
|
str = g_strdup_printf(_(" Total DL: %s/s Total UL: %s/s"),
|
|
|
|
upstr, downstr);
|
2006-01-12 18:47:30 +00:00
|
|
|
gtk_statusbar_pop(data->bar, 0);
|
|
|
|
gtk_statusbar_push(data->bar, 0, str);
|
|
|
|
g_free(str);
|
|
|
|
g_free(upstr);
|
|
|
|
g_free(downstr);
|
|
|
|
|
|
|
|
/* the status of the selected item may have changed, so update the buttons */
|
|
|
|
fixbuttons(NULL, data);
|
|
|
|
|
2006-05-31 23:20:59 +00:00
|
|
|
/* check for politely stopped torrents unless we're exiting */
|
|
|
|
if(!data->closing)
|
|
|
|
tr_backend_torrents_stopped(data->back);
|
|
|
|
|
2006-01-12 18:32:29 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-01-12 19:00:58 +00:00
|
|
|
/* show a popup menu for a right-click on the list */
|
2006-01-12 18:32:29 +00:00
|
|
|
gboolean
|
2006-01-12 18:47:30 +00:00
|
|
|
listclick(GtkWidget *widget SHUTUP, GdkEventButton *event, gpointer gdata) {
|
2006-01-12 18:32:29 +00:00
|
|
|
struct cbdata *data = gdata;
|
2006-01-12 19:00:58 +00:00
|
|
|
GtkTreeSelection *sel = gtk_tree_view_get_selection(data->view);
|
2006-01-12 18:47:30 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
2006-03-23 12:39:39 +00:00
|
|
|
int status;
|
2006-05-03 06:58:16 +00:00
|
|
|
TrTorrent *tor, *issel;
|
2006-01-12 18:32:29 +00:00
|
|
|
|
|
|
|
if(GDK_BUTTON_PRESS == event->type && 3 == event->button) {
|
2006-01-12 19:00:58 +00:00
|
|
|
/* find what row, if any, the user clicked on */
|
2006-01-12 18:47:30 +00:00
|
|
|
if(!gtk_tree_view_get_path_at_pos(data->view, event->x, event->y, &path,
|
|
|
|
NULL, NULL, NULL))
|
2006-05-03 06:58:16 +00:00
|
|
|
gtk_tree_selection_unselect_all(sel);
|
2006-01-12 18:47:30 +00:00
|
|
|
else {
|
2006-03-23 12:39:39 +00:00
|
|
|
if(gtk_tree_model_get_iter(data->model, &iter, path)) {
|
2006-05-03 06:58:16 +00:00
|
|
|
/* get torrent and status for the right-clicked row */
|
2006-03-23 12:39:39 +00:00
|
|
|
gtk_tree_model_get(data->model, &iter, MC_TORRENT, &tor,
|
|
|
|
MC_STAT, &status, -1);
|
2006-05-03 06:58:16 +00:00
|
|
|
issel = tor;
|
|
|
|
gtk_tree_selection_selected_foreach(sel, istorsel, &issel);
|
|
|
|
g_object_unref(tor);
|
|
|
|
/* if the clicked row isn't selected, select only it */
|
|
|
|
if(NULL != issel) {
|
|
|
|
gtk_tree_selection_unselect_all(sel);
|
|
|
|
gtk_tree_selection_select_iter(sel, &iter);
|
2006-01-12 19:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-12 18:47:30 +00:00
|
|
|
gtk_tree_path_free(path);
|
|
|
|
}
|
2006-05-03 06:58:16 +00:00
|
|
|
dopopupmenu(event, data);
|
2006-01-12 18:32:29 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2006-01-12 18:47:30 +00:00
|
|
|
listpopup(GtkWidget *widget SHUTUP, gpointer gdata) {
|
2006-05-03 06:58:16 +00:00
|
|
|
dopopupmenu(NULL, gdata);
|
2006-01-12 18:32:29 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-05-03 06:58:16 +00:00
|
|
|
dopopupmenu(GdkEventButton *event, struct cbdata *data) {
|
|
|
|
GtkTreeSelection *sel = gtk_tree_view_get_selection(data->view);
|
|
|
|
int count = gtk_tree_selection_count_selected_rows(sel);
|
2006-01-12 18:32:29 +00:00
|
|
|
GtkWidget *menu = gtk_menu_new();
|
|
|
|
GtkWidget *item;
|
|
|
|
unsigned int ii;
|
2006-05-03 06:58:16 +00:00
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
if(NULL != data->stupidpopuphack)
|
|
|
|
gtk_widget_destroy(data->stupidpopuphack);
|
|
|
|
data->stupidpopuphack = menu;
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
gtk_tree_selection_selected_foreach(sel, orstatus, &status);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
for(ii = 0; ii < ALEN(actionitems); ii++) {
|
2006-01-12 18:47:30 +00:00
|
|
|
if(actionitems[ii].nomenu ||
|
|
|
|
(actionitems[ii].avail &&
|
2006-05-03 06:58:16 +00:00
|
|
|
(0 == count || !(actionitems[ii].avail & status))))
|
2006-01-12 18:47:30 +00:00
|
|
|
continue;
|
2006-02-04 18:03:05 +00:00
|
|
|
item = gtk_menu_item_new_with_label(gettext(actionitems[ii].name));
|
2006-01-12 19:00:58 +00:00
|
|
|
/* set the action for the menu item */
|
2006-01-12 18:32:29 +00:00
|
|
|
g_object_set_data(G_OBJECT(item), LIST_ACTION,
|
|
|
|
GINT_TO_POINTER(actionitems[ii].act));
|
|
|
|
g_signal_connect(G_OBJECT(item), "activate",
|
|
|
|
G_CALLBACK(actionclick), data);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show_all(menu);
|
|
|
|
|
|
|
|
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
|
|
|
|
(NULL == event ? 0 : event->button),
|
|
|
|
gdk_event_get_time((GdkEvent*)event));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
actionclick(GtkWidget *widget, gpointer gdata) {
|
|
|
|
struct cbdata *data = gdata;
|
2006-05-31 23:20:59 +00:00
|
|
|
enum listact act;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GList *rows, *ii;
|
|
|
|
GtkTreeRowReference *ref;
|
2006-05-03 06:58:16 +00:00
|
|
|
GtkTreePath *path;
|
2006-03-23 12:39:39 +00:00
|
|
|
GtkTreeIter iter;
|
2006-05-31 23:20:59 +00:00
|
|
|
TrTorrent *tor;
|
|
|
|
unsigned int actoff, status;
|
|
|
|
gboolean changed;
|
|
|
|
|
|
|
|
act = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), LIST_ACTION));
|
2006-01-12 19:00:58 +00:00
|
|
|
|
2006-05-31 23:20:59 +00:00
|
|
|
switch(act) {
|
2006-01-12 18:40:47 +00:00
|
|
|
case ACT_OPEN:
|
2006-05-03 06:58:16 +00:00
|
|
|
makeaddwind(data->wind, addtorrents, data);
|
2006-01-12 18:40:47 +00:00
|
|
|
return;
|
|
|
|
case ACT_PREF:
|
2006-02-05 17:33:57 +00:00
|
|
|
if(!data->prefsopen)
|
2006-05-03 06:58:16 +00:00
|
|
|
makeprefwindow(data->wind, data->back, &data->prefsopen);
|
2006-01-12 18:40:47 +00:00
|
|
|
return;
|
2006-05-03 06:58:16 +00:00
|
|
|
case ACT_START:
|
|
|
|
case ACT_STOP:
|
|
|
|
case ACT_DELETE:
|
|
|
|
case ACT_INFO:
|
2006-01-12 18:40:47 +00:00
|
|
|
break;
|
2006-01-12 18:32:29 +00:00
|
|
|
}
|
|
|
|
|
2006-05-31 23:20:59 +00:00
|
|
|
sel = gtk_tree_view_get_selection(data->view);
|
|
|
|
rows = gtk_tree_selection_get_selected_rows(sel, NULL);
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-05-31 23:20:59 +00:00
|
|
|
for(ii = rows; NULL != ii; ii = ii->next) {
|
|
|
|
ref = gtk_tree_row_reference_new(data->model, ii->data);
|
|
|
|
gtk_tree_path_free(ii->data);
|
|
|
|
ii->data = ref;
|
|
|
|
}
|
2006-05-03 06:58:16 +00:00
|
|
|
|
2006-05-31 23:20:59 +00:00
|
|
|
for(actoff = 0; actoff < ALEN(actionitems); actoff++)
|
|
|
|
if(actionitems[actoff].act == act)
|
|
|
|
break;
|
|
|
|
g_assert(actoff < ALEN(actionitems));
|
|
|
|
|
|
|
|
changed = FALSE;
|
|
|
|
for(ii = rows; NULL != ii; ii = ii->next) {
|
|
|
|
if(NULL != (path = gtk_tree_row_reference_get_path(ii->data)) &&
|
|
|
|
gtk_tree_model_get_iter(data->model, &iter, path)) {
|
|
|
|
gtk_tree_model_get(data->model, &iter, MC_TORRENT, &tor,
|
|
|
|
MC_STAT, &status, -1);
|
|
|
|
/* check if this action is valid for this torrent */
|
|
|
|
if((!actionitems[actoff].avail || actionitems[actoff].avail & status) &&
|
|
|
|
!actionitems[actoff].nomenu) {
|
|
|
|
switch(act) {
|
|
|
|
case ACT_START:
|
|
|
|
tr_torrentStart(tr_torrent_handle(tor));
|
|
|
|
changed = TRUE;
|
|
|
|
break;
|
|
|
|
case ACT_STOP:
|
|
|
|
tr_torrentStop(tr_torrent_handle(tor));
|
|
|
|
changed = TRUE;
|
|
|
|
break;
|
|
|
|
case ACT_DELETE:
|
|
|
|
/* tor will be unref'd in the politely_stopped signal handler */
|
|
|
|
g_object_ref(tor);
|
|
|
|
tr_torrent_stop_politely(tor);
|
2006-06-10 06:53:20 +00:00
|
|
|
if(TR_FSAVEPRIVATE & tr_torrent_info(tor)->flags)
|
|
|
|
tr_torrentRemoveSaved(tr_torrent_handle(tor));
|
2006-05-31 23:20:59 +00:00
|
|
|
gtk_list_store_remove(GTK_LIST_STORE(data->model), &iter);
|
|
|
|
changed = TRUE;
|
|
|
|
break;
|
|
|
|
case ACT_INFO:
|
|
|
|
makeinfowind(data->wind, tor);
|
|
|
|
break;
|
|
|
|
case ACT_OPEN:
|
|
|
|
case ACT_PREF:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_object_unref(tor);
|
2006-05-03 10:09:11 +00:00
|
|
|
}
|
2006-05-31 23:20:59 +00:00
|
|
|
if(NULL != path)
|
|
|
|
gtk_tree_path_free(path);
|
2006-05-03 06:58:16 +00:00
|
|
|
gtk_tree_row_reference_free(ii->data);
|
|
|
|
}
|
2006-05-31 23:20:59 +00:00
|
|
|
g_list_free(rows);
|
2006-01-12 19:00:58 +00:00
|
|
|
|
2006-05-31 23:20:59 +00:00
|
|
|
if(changed) {
|
2006-05-03 06:58:16 +00:00
|
|
|
savetorrents(data);
|
|
|
|
updatemodel(data);
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 19:00:58 +00:00
|
|
|
|
2006-01-12 19:04:05 +00:00
|
|
|
gint
|
|
|
|
intrevcmp(gconstpointer a, gconstpointer b) {
|
|
|
|
int aint = GPOINTER_TO_INT(a);
|
|
|
|
int bint = GPOINTER_TO_INT(b);
|
|
|
|
|
|
|
|
if(bint > aint)
|
|
|
|
return 1;
|
|
|
|
else if(bint < aint)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-12 19:00:58 +00:00
|
|
|
void
|
|
|
|
doubleclick(GtkWidget *widget SHUTUP, GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *col SHUTUP, gpointer gdata) {
|
|
|
|
struct cbdata *data = gdata;
|
|
|
|
GtkTreeIter iter;
|
2006-05-03 06:58:16 +00:00
|
|
|
TrTorrent *tor;
|
2006-01-12 19:00:58 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
if(gtk_tree_model_get_iter(data->model, &iter, path)) {
|
|
|
|
gtk_tree_model_get(data->model, &iter, MC_TORRENT, &tor, -1);
|
|
|
|
makeinfowind(data->wind, tor);
|
2006-05-03 06:58:16 +00:00
|
|
|
g_object_unref(tor);
|
2006-01-12 19:00:58 +00:00
|
|
|
}
|
2006-01-12 18:32:29 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
void
|
|
|
|
addtorrents(void *vdata, void *state, GList *files,
|
2006-06-10 06:53:20 +00:00
|
|
|
const char *dir, guint flags) {
|
2006-03-23 12:39:39 +00:00
|
|
|
struct cbdata *data = vdata;
|
2006-05-03 06:58:16 +00:00
|
|
|
GList *torlist, *errlist, *ii;
|
|
|
|
char *errstr;
|
|
|
|
TrTorrent *tor;
|
2006-03-23 12:39:39 +00:00
|
|
|
GtkTreeIter iter;
|
2006-05-03 06:58:16 +00:00
|
|
|
char *wd;
|
2006-01-12 18:32:29 +00:00
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
errlist = NULL;
|
|
|
|
torlist = NULL;
|
2006-01-12 18:40:47 +00:00
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
if(NULL != state)
|
|
|
|
torlist = tr_backend_load_state(data->back, state, &errlist);
|
|
|
|
|
|
|
|
if(NULL != files) {
|
|
|
|
if(NULL == dir)
|
|
|
|
dir = cf_getpref(PREF_DIR);
|
|
|
|
wd = NULL;
|
|
|
|
if(NULL == dir) {
|
|
|
|
wd = g_new(char, MAX_PATH_LENGTH + 1);
|
|
|
|
if(NULL == getcwd(wd, MAX_PATH_LENGTH + 1))
|
|
|
|
dir = ".";
|
2006-03-23 12:39:39 +00:00
|
|
|
else
|
2006-05-03 06:58:16 +00:00
|
|
|
dir = wd;
|
2006-03-23 12:39:39 +00:00
|
|
|
}
|
2006-05-03 06:58:16 +00:00
|
|
|
for(ii = g_list_first(files); NULL != ii; ii = ii->next) {
|
|
|
|
errstr = NULL;
|
2006-06-10 06:53:20 +00:00
|
|
|
tor = tr_torrent_new(G_OBJECT(data->back), ii->data, dir,
|
|
|
|
flags, &errstr);
|
2006-05-03 06:58:16 +00:00
|
|
|
if(NULL != tor)
|
|
|
|
torlist = g_list_append(torlist, tor);
|
|
|
|
if(NULL != errstr)
|
|
|
|
errlist = g_list_append(errlist, errstr);
|
|
|
|
}
|
|
|
|
if(NULL != wd)
|
|
|
|
g_free(wd);
|
2006-01-12 18:32:29 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
for(ii = g_list_first(torlist); NULL != ii; ii = ii->next) {
|
|
|
|
gtk_list_store_append(GTK_LIST_STORE(data->model), &iter);
|
|
|
|
gtk_list_store_set(GTK_LIST_STORE(data->model), &iter,
|
|
|
|
MC_TORRENT, ii->data, -1);
|
2006-05-31 23:20:59 +00:00
|
|
|
/* we will always ref a torrent before politely stopping it */
|
|
|
|
g_signal_connect(ii->data, "politely_stopped",
|
|
|
|
G_CALLBACK(g_object_unref), data);
|
2006-05-03 06:58:16 +00:00
|
|
|
g_object_unref(ii->data);
|
2006-01-12 18:32:29 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
if(NULL != errlist) {
|
|
|
|
errstr = joinstrlist(errlist, "\n");
|
|
|
|
errmsg(data->wind, ngettext("Failed to load torrent file:\n%s",
|
|
|
|
"Failed to load torrent files:\n%s",
|
|
|
|
g_list_length(errlist)), errstr);
|
|
|
|
g_list_foreach(errlist, (GFunc)g_free, NULL);
|
|
|
|
g_list_free(errlist);
|
|
|
|
g_free(errstr);
|
|
|
|
}
|
2006-01-12 19:04:05 +00:00
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
if(NULL != torlist) {
|
|
|
|
updatemodel(data);
|
|
|
|
savetorrents(data);
|
|
|
|
}
|
2006-01-12 18:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-05-03 06:58:16 +00:00
|
|
|
savetorrents(struct cbdata *data) {
|
2006-01-12 18:32:29 +00:00
|
|
|
char *errstr;
|
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
tr_backend_save_state(data->back, &errstr);
|
|
|
|
if(NULL != errstr) {
|
|
|
|
errmsg(data->wind, "%s", errstr);
|
2006-01-12 18:32:29 +00:00
|
|
|
g_free(errstr);
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 19:00:58 +00:00
|
|
|
|
|
|
|
/* use with gtk_tree_selection_selected_foreach to | status of selected rows */
|
|
|
|
void
|
|
|
|
orstatus(GtkTreeModel *model, GtkTreePath *path SHUTUP, GtkTreeIter *iter,
|
|
|
|
gpointer gdata) {
|
|
|
|
int *allstatus = gdata;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, iter, MC_STAT, &status, -1);
|
|
|
|
*allstatus |= status;
|
|
|
|
}
|
|
|
|
|
2006-05-03 06:58:16 +00:00
|
|
|
/* data should be a TrTorrent**, will set torrent to NULL if it's selected */
|
2006-01-12 19:00:58 +00:00
|
|
|
void
|
2006-05-03 06:58:16 +00:00
|
|
|
istorsel(GtkTreeModel *model, GtkTreePath *path SHUTUP, GtkTreeIter *iter,
|
|
|
|
gpointer gdata) {
|
|
|
|
TrTorrent **torref = gdata;
|
|
|
|
TrTorrent *tor;
|
|
|
|
|
|
|
|
if(NULL != *torref) {
|
|
|
|
gtk_tree_model_get(model, iter, MC_TORRENT, &tor, -1);
|
|
|
|
if(tor == *torref)
|
|
|
|
*torref = NULL;
|
|
|
|
g_object_unref(tor);
|
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
}
|
|
|
|
|
2006-04-25 07:26:27 +00:00
|
|
|
void
|
|
|
|
safepipe(void) {
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
bzero(&sa, sizeof(sa));
|
|
|
|
sa.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGPIPE, &sa, NULL);
|
|
|
|
}
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
void
|
|
|
|
setupsighandlers(void) {
|
|
|
|
int sigs[] = {SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2};
|
|
|
|
struct sigaction sa;
|
|
|
|
unsigned int ii;
|
|
|
|
|
|
|
|
bzero(&sa, sizeof(sa));
|
|
|
|
sa.sa_handler = fatalsig;
|
|
|
|
for(ii = 0; ii < ALEN(sigs); ii++)
|
|
|
|
sigaction(sigs[ii], &sa, NULL);
|
|
|
|
}
|
2006-01-12 19:00:58 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
void
|
|
|
|
fatalsig(int sig) {
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
if(SIGCOUNT_MAX <= ++global_sigcount) {
|
|
|
|
bzero(&sa, sizeof(sa));
|
|
|
|
sa.sa_handler = SIG_DFL;
|
|
|
|
sigaction(sig, &sa, NULL);
|
|
|
|
raise(sig);
|
|
|
|
}
|
2006-01-12 19:00:58 +00:00
|
|
|
}
|