2006-08-13 00:26:52 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-02-07 07:35:33 +00:00
|
|
|
* Copyright (c) 2005-2007 Transmission authors and contributors
|
2006-08-13 00:26:52 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <errno.h>
|
2007-02-19 22:09:05 +00:00
|
|
|
#include <getopt.h>
|
2006-07-16 19:39:23 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "actions.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
#include "conf.h"
|
|
|
|
#include "dialogs.h"
|
|
|
|
#include "ipc.h"
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "makemeta-ui.h"
|
2006-08-20 22:45:29 +00:00
|
|
|
#include "msgwin.h"
|
2007-06-06 00:30:13 +00:00
|
|
|
#include "torrent-inspector.h"
|
2006-08-13 00:22:05 +00:00
|
|
|
#include "tr_cell_renderer_progress.h"
|
2007-05-23 00:49:31 +00:00
|
|
|
#include "tr_core.h"
|
2007-02-19 22:09:05 +00:00
|
|
|
#include "tr_icon.h"
|
|
|
|
#include "tr_prefs.h"
|
|
|
|
#include "tr_torrent.h"
|
2007-02-07 07:35:33 +00:00
|
|
|
#include "tr_window.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
#include "util.h"
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "ui.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/version.h>
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
/* time in seconds to wait for torrents to stop when exiting */
|
|
|
|
#define TRACKER_EXIT_TIMEOUT 10
|
|
|
|
|
|
|
|
/* interval in milliseconds to update the torrent list display */
|
|
|
|
#define UPDATE_INTERVAL 1000
|
|
|
|
|
|
|
|
/* interval in milliseconds to check for stopped torrents and update display */
|
|
|
|
#define EXIT_CHECK_INTERVAL 500
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* number of fatal signals required to cause an immediate exit */
|
|
|
|
#define SIGCOUNT_MAX 3
|
|
|
|
|
2007-06-09 17:08:25 +00:00
|
|
|
#if GTK_CHECK_VERSION(2,8,0)
|
|
|
|
#define SHOW_LICENSE
|
2007-06-09 15:20:32 +00:00
|
|
|
static const char * LICENSE =
|
2007-06-18 03:40:41 +00:00
|
|
|
"The Transmission binaries and most of its source code is distributed "
|
2007-06-09 15:20:32 +00:00
|
|
|
"license. "
|
|
|
|
"\n\n"
|
2007-06-18 03:40:41 +00:00
|
|
|
"Some files are copyrighted by Charles Kerr and are covered by "
|
|
|
|
"the GPL version 2. Works owned by the Transmission project "
|
|
|
|
"are granted a special exemption to clause 2(b) so that the bulk "
|
|
|
|
"of its code can remain under the MIT license. This exemption does "
|
|
|
|
"not extend to original or derived works not owned by the "
|
|
|
|
"Transmission project. "
|
|
|
|
"\n\n"
|
2007-06-09 15:20:32 +00:00
|
|
|
"Permission is hereby granted, free of charge, to any person obtaining "
|
|
|
|
"a copy of this software and associated documentation files (the "
|
|
|
|
"'Software'), to deal in the Software without restriction, including "
|
|
|
|
"without limitation the rights to use, copy, modify, merge, publish, "
|
|
|
|
"distribute, sublicense, and/or sell copies of the Software, and to "
|
|
|
|
"permit persons to whom the Software is furnished to do so, subject to "
|
|
|
|
"the following conditions: "
|
|
|
|
"\n\n"
|
|
|
|
"The above copyright notice and this permission notice shall be included "
|
|
|
|
"in all copies or substantial portions of the Software. "
|
|
|
|
"\n\n"
|
|
|
|
"THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, "
|
|
|
|
"EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF "
|
|
|
|
"MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. "
|
|
|
|
"IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY "
|
|
|
|
"CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, "
|
|
|
|
"TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE "
|
|
|
|
"SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.";
|
2007-06-09 17:08:25 +00:00
|
|
|
#endif
|
2007-06-09 15:20:32 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
struct cbdata {
|
2007-02-19 22:09:05 +00:00
|
|
|
GtkWindow * wind;
|
2007-05-23 00:49:31 +00:00
|
|
|
TrCore * core;
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkWidget * icon;
|
2007-02-19 22:09:05 +00:00
|
|
|
TrPrefs * prefs;
|
|
|
|
guint timer;
|
|
|
|
gboolean msgwinopen;
|
|
|
|
gboolean closing;
|
2007-05-23 17:59:35 +00:00
|
|
|
GList * errqueue;
|
2006-07-16 19:39:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct exitdata {
|
2007-02-19 22:09:05 +00:00
|
|
|
struct cbdata * cbdata;
|
|
|
|
time_t started;
|
|
|
|
guint timer;
|
2006-07-16 19:39:23 +00:00
|
|
|
};
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
#define CBDATA_PTR "callback-data-pointer"
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static GtkUIManager * myUIManager = NULL;
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static sig_atomic_t global_sigcount = 0;
|
|
|
|
|
|
|
|
static GList *
|
2007-02-19 22:09:05 +00:00
|
|
|
readargs( int argc, char ** argv, gboolean * sendquit, gboolean * paused );
|
|
|
|
static gboolean
|
|
|
|
sendremote( GList * files, gboolean sendquit );
|
|
|
|
static void
|
2007-06-18 03:40:41 +00:00
|
|
|
gtksetup( int * argc, char *** argv, struct cbdata* );
|
2007-02-19 22:09:05 +00:00
|
|
|
static void
|
2007-06-18 03:40:41 +00:00
|
|
|
appsetup( TrWindow * wind, benc_val_t * state, GList * args,
|
|
|
|
struct cbdata * , gboolean paused );
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2007-02-19 22:09:05 +00:00
|
|
|
winsetup( struct cbdata * cbdata, TrWindow * wind );
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2007-02-19 22:09:05 +00:00
|
|
|
makeicon( struct cbdata * cbdata );
|
|
|
|
static void
|
|
|
|
wannaquit( void * vdata );
|
2007-02-07 07:35:33 +00:00
|
|
|
static gboolean
|
2006-07-16 19:39:23 +00:00
|
|
|
exitcheck(gpointer gdata);
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
setupdrag(GtkWidget *widget, struct cbdata *data);
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
gotdrag(GtkWidget *widget, GdkDragContext *dc, gint x, gint y,
|
|
|
|
GtkSelectionData *sel, guint info, guint time, gpointer gdata);
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
static void
|
2007-05-23 17:59:35 +00:00
|
|
|
coreerr( TrCore * core, enum tr_core_err code, const char * msg,
|
|
|
|
gpointer gdata );
|
|
|
|
static void
|
2007-05-24 02:50:28 +00:00
|
|
|
coreprompt( TrCore *, GList *, enum tr_torrent_action, gboolean, gpointer );
|
|
|
|
static void
|
2007-05-24 10:37:07 +00:00
|
|
|
corepromptdata( TrCore *, uint8_t *, size_t, gboolean, gpointer );
|
|
|
|
static void
|
2007-02-19 22:09:05 +00:00
|
|
|
readinitialprefs( struct cbdata * cbdata );
|
|
|
|
static void
|
2007-05-24 13:55:57 +00:00
|
|
|
prefschanged( TrCore * core, int id, gpointer data );
|
2007-03-31 19:19:27 +00:00
|
|
|
static void
|
|
|
|
setpex( tr_torrent_t * tor, void * arg );
|
2007-02-07 07:35:33 +00:00
|
|
|
static gboolean
|
2006-07-16 19:39:23 +00:00
|
|
|
updatemodel(gpointer gdata);
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2007-02-19 22:09:05 +00:00
|
|
|
boolwindclosed(GtkWidget *widget, gpointer gdata);
|
|
|
|
static GList *
|
|
|
|
getselection( struct cbdata * cbdata );
|
2007-02-07 07:35:33 +00:00
|
|
|
|
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
safepipe(void);
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
setupsighandlers(void);
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
fatalsig(int sig);
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
|
|
|
accumulateStatusForeach (GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer accumulated_status)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
gtk_tree_model_get( model, iter, MC_STAT, &status, -1 );
|
|
|
|
*(int*)accumulated_status |= status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
refreshTorrentActions( GtkTreeSelection * s )
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
gtk_tree_selection_selected_foreach( s, accumulateStatusForeach, &status );
|
|
|
|
action_sensitize( "stop-torrent", (status & TR_STATUS_ACTIVE) != 0);
|
|
|
|
action_sensitize( "start-torrent", (status & TR_STATUS_INACTIVE) != 0);
|
|
|
|
action_sensitize( "remove-torrent", status != 0);
|
2007-06-22 20:59:23 +00:00
|
|
|
action_sensitize( "recheck-torrent", status != 0);
|
2007-06-18 03:40:41 +00:00
|
|
|
action_sensitize( "show-torrent-inspector", status != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selectionChangedCB( GtkTreeSelection * s, gpointer unused UNUSED )
|
|
|
|
{
|
|
|
|
refreshTorrentActions( s );
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
int
|
2007-02-19 22:09:05 +00:00
|
|
|
main( int argc, char ** argv )
|
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
struct cbdata * cbdata = g_new (struct cbdata, 1);
|
2007-02-19 22:09:05 +00:00
|
|
|
char * err;
|
|
|
|
benc_val_t * state;
|
|
|
|
GList * argfiles;
|
|
|
|
gboolean didinit, didlock, sendquit, startpaused;
|
|
|
|
|
|
|
|
safepipe(); /* ignore SIGPIPE */
|
|
|
|
argfiles = readargs( argc, argv, &sendquit, &startpaused );
|
|
|
|
didinit = cf_init( tr_getPrefsDirectory(), NULL );
|
|
|
|
didlock = FALSE;
|
|
|
|
if( didinit )
|
|
|
|
{
|
|
|
|
/* maybe send remote commands, also try cf_lock() */
|
|
|
|
didlock = sendremote( argfiles, sendquit );
|
|
|
|
}
|
|
|
|
setupsighandlers(); /* set up handlers for fatal signals */
|
2007-06-18 03:40:41 +00:00
|
|
|
gtksetup( &argc, &argv, cbdata ); /* set up gtk and gettext */
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
if( ( didinit || cf_init( tr_getPrefsDirectory(), &err ) ) &&
|
|
|
|
( didlock || cf_lock( &err ) ) )
|
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkWindow * mainwind;
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* create main window now to be a parent to any error dialogs */
|
2007-06-18 03:40:41 +00:00
|
|
|
mainwind = GTK_WINDOW( tr_window_new( myUIManager ) );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* try to load prefs and saved state */
|
|
|
|
cf_loadprefs( &err );
|
|
|
|
if( NULL != err )
|
|
|
|
{
|
|
|
|
errmsg( mainwind, "%s", err );
|
|
|
|
g_free( err );
|
|
|
|
}
|
|
|
|
state = cf_loadstate( &err );
|
|
|
|
if( NULL != err )
|
|
|
|
{
|
|
|
|
errmsg( mainwind, "%s", err );
|
|
|
|
g_free( err );
|
|
|
|
}
|
2006-08-20 22:45:29 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
msgwin_loadpref(); /* set message level here before tr_init() */
|
2007-06-18 03:40:41 +00:00
|
|
|
appsetup( mainwind, state, argfiles, cbdata, startpaused );
|
2007-02-19 22:09:05 +00:00
|
|
|
cf_freestate( state );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_show( errmsg_full( NULL, (callbackfunc_t)gtk_main_quit,
|
|
|
|
NULL, "%s", err ) );
|
|
|
|
g_free( err );
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
freestrlist(argfiles);
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
gtk_main();
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
GList *
|
|
|
|
readargs( int argc, char ** argv, gboolean * sendquit, gboolean * startpaused )
|
|
|
|
{
|
|
|
|
struct option opts[] =
|
|
|
|
{
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "paused", no_argument, NULL, 'p' },
|
|
|
|
{ "quit", no_argument, NULL, 'q' },
|
|
|
|
{ "version", no_argument, NULL, 'v' },
|
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
2007-03-24 09:23:24 +00:00
|
|
|
int opt;
|
|
|
|
const char * name;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
*sendquit = FALSE;
|
|
|
|
*startpaused = FALSE;
|
|
|
|
|
|
|
|
gtk_parse_args( &argc, &argv );
|
2007-03-24 09:23:24 +00:00
|
|
|
name = g_get_prgname();
|
2007-02-19 22:09:05 +00:00
|
|
|
|
|
|
|
while( 0 <= ( opt = getopt_long( argc, argv, "hpqv", opts, NULL ) ) )
|
|
|
|
{
|
|
|
|
switch( opt )
|
|
|
|
{
|
|
|
|
case 'p':
|
|
|
|
*startpaused = TRUE;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
*sendquit = TRUE;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
case 'h':
|
|
|
|
printf(
|
2007-03-24 09:23:24 +00:00
|
|
|
_("usage: %s [-hpq] [files...]\n"
|
2007-02-19 22:09:05 +00:00
|
|
|
"\n"
|
2007-07-10 19:40:21 +00:00
|
|
|
"Transmission %s http://transmission.m0k.org/\n"
|
2007-02-19 22:09:05 +00:00
|
|
|
"A free, lightweight BitTorrent client with a simple, intuitive interface\n"
|
|
|
|
"\n"
|
|
|
|
" -h --help display this message and exit\n"
|
|
|
|
" -p --paused start with all torrents paused\n"
|
2007-03-24 09:23:24 +00:00
|
|
|
" -q --quit request that the running %s instance quit\n"
|
2007-02-19 22:09:05 +00:00
|
|
|
"\n"
|
2007-03-24 09:23:24 +00:00
|
|
|
"Only one instance of %s may run at one time. Multiple\n"
|
2007-02-19 22:09:05 +00:00
|
|
|
"torrent files may be loaded at startup by adding them to the command\n"
|
2007-03-24 09:23:24 +00:00
|
|
|
"line. If %s is already running, those torrents will be\n"
|
2007-02-19 22:09:05 +00:00
|
|
|
"opened in the running instance.\n"),
|
2007-07-10 19:40:21 +00:00
|
|
|
name, LONG_VERSION_STRING,
|
2007-03-24 09:23:24 +00:00
|
|
|
name, name, name );
|
2007-02-19 22:09:05 +00:00
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
return checkfilenames( argc, argv );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
static gboolean
|
|
|
|
sendremote( GList * files, gboolean sendquit )
|
|
|
|
{
|
|
|
|
gboolean didlock;
|
|
|
|
|
|
|
|
didlock = cf_lock( NULL );
|
|
|
|
|
|
|
|
if( NULL != files )
|
|
|
|
{
|
|
|
|
/* send files if there's another instance, otherwise start normally */
|
|
|
|
if( !didlock )
|
|
|
|
{
|
|
|
|
exit( ipc_sendfiles_blocking( files ) ? 0 : 1 );
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2007-02-19 22:09:05 +00:00
|
|
|
|
|
|
|
if( sendquit )
|
|
|
|
{
|
|
|
|
/* either send a quit message or exit if no other instance */
|
|
|
|
if( !didlock )
|
|
|
|
{
|
|
|
|
exit( ipc_sendquit_blocking() ? 0 : 1 );
|
|
|
|
}
|
|
|
|
exit( 0 );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
return didlock;
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2007-06-18 03:40:41 +00:00
|
|
|
gtksetup( int * argc, char *** argv, struct cbdata * callback_data )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
bindtextdomain( "transmission-gtk", LOCALEDIR );
|
|
|
|
bind_textdomain_codeset( "transmission-gtk", "UTF-8" );
|
|
|
|
textdomain( "transmission-gtk" );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
g_set_application_name( _("Transmission") );
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_init( argc, argv );
|
|
|
|
|
|
|
|
/* connect up the actions */
|
|
|
|
myUIManager = gtk_ui_manager_new ();
|
|
|
|
actions_init ( myUIManager, callback_data );
|
|
|
|
gtk_ui_manager_add_ui_from_string (myUIManager, fallback_ui_file, -1, NULL);
|
|
|
|
gtk_ui_manager_ensure_update (myUIManager);
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* tweak some style properties in dialogs to get closer to the GNOME HiG */
|
|
|
|
gtk_rc_parse_string(
|
|
|
|
"style \"transmission-standard\"\n"
|
|
|
|
"{\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-07-16 19:39:23 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_window_set_default_icon_name ( "ICON_TRANSMISSION" );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
static void
|
2007-06-18 03:40:41 +00:00
|
|
|
appsetup( TrWindow * wind, benc_val_t * state, GList * args,
|
|
|
|
struct cbdata * cbdata, gboolean paused )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-05-24 02:50:28 +00:00
|
|
|
enum tr_torrent_action action;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
|
|
|
/* fill out cbdata */
|
|
|
|
cbdata->wind = NULL;
|
2007-05-23 00:49:31 +00:00
|
|
|
cbdata->core = tr_core_new();
|
2007-02-19 22:09:05 +00:00
|
|
|
cbdata->icon = NULL;
|
|
|
|
cbdata->prefs = NULL;
|
|
|
|
cbdata->timer = 0;
|
|
|
|
cbdata->msgwinopen = FALSE;
|
|
|
|
cbdata->closing = FALSE;
|
2007-05-23 17:59:35 +00:00
|
|
|
cbdata->errqueue = NULL;
|
|
|
|
|
2007-05-24 02:50:28 +00:00
|
|
|
/* set up core handlers */
|
2007-05-23 17:59:35 +00:00
|
|
|
g_signal_connect( cbdata->core, "error", G_CALLBACK( coreerr ), cbdata );
|
2007-05-24 02:50:28 +00:00
|
|
|
g_signal_connect( cbdata->core, "directory-prompt",
|
|
|
|
G_CALLBACK( coreprompt ), cbdata );
|
2007-05-24 10:37:07 +00:00
|
|
|
g_signal_connect( cbdata->core, "directory-prompt-data",
|
|
|
|
G_CALLBACK( corepromptdata ), cbdata );
|
2007-05-24 03:29:23 +00:00
|
|
|
g_signal_connect_swapped( cbdata->core, "quit",
|
|
|
|
G_CALLBACK( wannaquit ), cbdata );
|
2007-05-24 13:55:57 +00:00
|
|
|
g_signal_connect( cbdata->core, "prefs-changed",
|
|
|
|
G_CALLBACK( prefschanged ), cbdata );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
|
|
|
/* apply a few prefs */
|
|
|
|
readinitialprefs( cbdata );
|
|
|
|
|
2007-05-24 02:50:28 +00:00
|
|
|
/* add torrents from command-line and saved state */
|
2007-07-23 03:03:45 +00:00
|
|
|
tr_core_load( cbdata->core, paused );
|
|
|
|
|
2007-05-24 02:50:28 +00:00
|
|
|
if( NULL != args )
|
|
|
|
{
|
|
|
|
action = toraddaction( tr_prefs_get( PREF_ID_ADDIPC ) );
|
|
|
|
tr_core_add_list( cbdata->core, args, action, paused );
|
|
|
|
}
|
|
|
|
tr_core_torrents_added( cbdata->core );
|
|
|
|
|
|
|
|
/* set up the ipc socket */
|
2007-05-24 03:29:23 +00:00
|
|
|
ipc_socket_setup( GTK_WINDOW( wind ), cbdata->core );
|
2007-05-24 02:50:28 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* set up main window */
|
|
|
|
winsetup( cbdata, wind );
|
|
|
|
|
|
|
|
/* start model update timer */
|
|
|
|
cbdata->timer = g_timeout_add( UPDATE_INTERVAL, updatemodel, cbdata );
|
|
|
|
updatemodel( cbdata );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-04-03 08:18:53 +00:00
|
|
|
/* show the window */
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_widget_show( GTK_WIDGET(wind) );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static gboolean
|
|
|
|
winclose( GtkWidget * widget UNUSED, GdkEvent * event UNUSED, gpointer gdata )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
struct cbdata * cbdata = (struct cbdata *) gdata;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
if( cbdata->icon != NULL )
|
|
|
|
gtk_widget_hide( GTK_WIDGET( cbdata->wind ) );
|
|
|
|
else
|
2007-07-16 18:45:51 +00:00
|
|
|
askquit( cbdata->core, cbdata->wind, wannaquit, cbdata );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
return TRUE; /* don't propagate event further */
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-18 03:40:41 +00:00
|
|
|
rowChangedCB( GtkTreeModel * model UNUSED,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter UNUSED,
|
|
|
|
gpointer sel)
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
refreshTorrentActions( GTK_TREE_SELECTION(sel) );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-18 03:40:41 +00:00
|
|
|
winsetup( struct cbdata * cbdata, TrWindow * wind )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkTreeModel * model;
|
|
|
|
GtkTreeSelection * sel;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
g_assert( NULL == cbdata->wind );
|
|
|
|
cbdata->wind = GTK_WINDOW( wind );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
sel = tr_window_get_selection( cbdata->wind );
|
|
|
|
g_signal_connect( sel, "changed", G_CALLBACK(selectionChangedCB), NULL );
|
|
|
|
selectionChangedCB( sel, NULL );
|
|
|
|
model = tr_core_model( cbdata->core );
|
|
|
|
gtk_tree_view_set_model ( gtk_tree_selection_get_tree_view(sel), model );
|
|
|
|
g_signal_connect( model, "row-changed", G_CALLBACK(rowChangedCB), sel );
|
|
|
|
g_signal_connect( wind, "delete-event", G_CALLBACK( winclose ), cbdata );
|
|
|
|
|
|
|
|
setupdrag( GTK_WIDGET(wind), cbdata );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
|
|
|
makeicon( struct cbdata * cbdata )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
if( NULL == cbdata->icon )
|
|
|
|
cbdata->icon = tr_icon_new( );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wannaquit( void * vdata )
|
|
|
|
{
|
|
|
|
struct cbdata * data;
|
2006-07-16 19:39:23 +00:00
|
|
|
struct exitdata *edata;
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
data = vdata;
|
|
|
|
if( data->closing )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
data->closing = TRUE;
|
|
|
|
|
|
|
|
/* stop the update timer */
|
|
|
|
if(0 < data->timer)
|
|
|
|
g_source_remove(data->timer);
|
|
|
|
data->timer = 0;
|
|
|
|
|
2007-05-23 01:47:42 +00:00
|
|
|
/* pause torrents and stop nat traversal */
|
2007-05-23 06:25:15 +00:00
|
|
|
tr_core_shutdown( data->core );
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
/* set things up to wait for torrents to stop */
|
|
|
|
edata = g_new0(struct exitdata, 1);
|
|
|
|
edata->cbdata = data;
|
|
|
|
edata->started = time(NULL);
|
|
|
|
/* 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);
|
2007-02-19 22:09:05 +00:00
|
|
|
if( NULL != data->wind )
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive( GTK_WIDGET( data->wind ), FALSE );
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
static gboolean
|
|
|
|
exitcheck( gpointer gdata )
|
|
|
|
{
|
|
|
|
struct exitdata * edata;
|
|
|
|
struct cbdata * cbdata;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
edata = gdata;
|
|
|
|
cbdata = edata->cbdata;
|
|
|
|
|
2007-05-23 01:47:42 +00:00
|
|
|
/* keep waiting until we're ready to quit or we hit the exit timeout */
|
2007-02-19 22:09:05 +00:00
|
|
|
if( time( NULL ) - edata->started < TRACKER_EXIT_TIMEOUT )
|
|
|
|
{
|
2007-05-23 06:25:15 +00:00
|
|
|
if( !tr_core_quiescent( cbdata->core ) )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
|
|
|
updatemodel( cbdata );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* exit otherwise */
|
|
|
|
if( 0 < edata->timer )
|
|
|
|
{
|
|
|
|
g_source_remove( edata->timer );
|
|
|
|
}
|
|
|
|
g_free( edata );
|
2007-05-24 13:55:57 +00:00
|
|
|
/* note that cbdata->prefs holds a reference to cbdata->core, and
|
|
|
|
it's destruction may trigger callbacks that use cbdata->core */
|
2007-02-19 22:09:05 +00:00
|
|
|
if( NULL != cbdata->prefs )
|
|
|
|
{
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( cbdata->prefs ) );
|
|
|
|
}
|
|
|
|
if( NULL != cbdata->wind )
|
|
|
|
{
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( cbdata->wind ) );
|
|
|
|
}
|
2007-05-23 00:49:31 +00:00
|
|
|
g_object_unref( cbdata->core );
|
2007-02-19 22:09:05 +00:00
|
|
|
if( NULL != cbdata->icon )
|
|
|
|
{
|
|
|
|
g_object_unref( cbdata->icon );
|
|
|
|
}
|
|
|
|
g_assert( 0 == cbdata->timer );
|
2007-05-23 17:59:35 +00:00
|
|
|
if( NULL != cbdata->errqueue )
|
|
|
|
{
|
|
|
|
g_list_foreach( cbdata->errqueue, (GFunc) g_free, NULL );
|
|
|
|
g_list_free( cbdata->errqueue );
|
|
|
|
}
|
2007-02-19 22:09:05 +00:00
|
|
|
g_free( cbdata );
|
|
|
|
gtk_main_quit();
|
|
|
|
|
|
|
|
return FALSE;
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
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;
|
|
|
|
char prefix[] = "file:";
|
|
|
|
char *files, *decoded, *deslashed, *hostless;
|
|
|
|
int ii, len;
|
|
|
|
GList *errs;
|
|
|
|
struct stat sb;
|
|
|
|
int prelen = strlen(prefix);
|
|
|
|
GList *paths, *freeables;
|
2007-05-24 02:50:28 +00:00
|
|
|
enum tr_torrent_action action;
|
2006-07-16 19:39:23 +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
|
|
|
|
|
|
|
|
errs = NULL;
|
|
|
|
paths = NULL;
|
|
|
|
freeables = NULL;
|
|
|
|
if(gdk_atom_intern("XdndSelection", FALSE) == sel->selection &&
|
|
|
|
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);
|
|
|
|
freeables = g_list_append(freeables, decoded);
|
|
|
|
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;
|
|
|
|
/* finally, add it to the list of torrents to try adding */
|
|
|
|
paths = g_list_append(paths, deslashed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to add any torrents we found */
|
2007-02-19 22:09:05 +00:00
|
|
|
if( NULL != paths )
|
|
|
|
{
|
2007-05-24 02:50:28 +00:00
|
|
|
action = toraddaction( tr_prefs_get( PREF_ID_ADDSTD ) );
|
|
|
|
tr_core_add_list( data->core, paths, action, FALSE );
|
|
|
|
tr_core_torrents_added( data->core );
|
2007-06-06 00:30:13 +00:00
|
|
|
g_list_free(paths);
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
freestrlist(freeables);
|
|
|
|
g_free(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_drag_finish(dc, (NULL != paths), FALSE, time);
|
|
|
|
}
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
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,
|
|
|
|
ALEN(targets), GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
|
|
}
|
|
|
|
|
2007-05-23 17:59:35 +00:00
|
|
|
static void
|
|
|
|
coreerr( TrCore * core SHUTUP, enum tr_core_err code, const char * msg,
|
|
|
|
gpointer gdata )
|
|
|
|
{
|
|
|
|
struct cbdata * cbdata = gdata;
|
|
|
|
char * joined;
|
|
|
|
|
|
|
|
switch( code )
|
|
|
|
{
|
|
|
|
case TR_CORE_ERR_ADD_TORRENT:
|
|
|
|
cbdata->errqueue = g_list_append( cbdata->errqueue,
|
|
|
|
g_strdup( msg ) );
|
|
|
|
return;
|
|
|
|
case TR_CORE_ERR_NO_MORE_TORRENTS:
|
|
|
|
if( NULL != cbdata->errqueue )
|
|
|
|
{
|
|
|
|
joined = joinstrlist( cbdata->errqueue, "\n" );
|
|
|
|
errmsg( cbdata->wind,
|
|
|
|
ngettext( "Failed to load torrent file:\n%s",
|
|
|
|
"Failed to load torrent files:\n%s",
|
|
|
|
g_list_length( cbdata->errqueue ) ),
|
|
|
|
joined );
|
|
|
|
g_list_foreach( cbdata->errqueue, (GFunc) g_free, NULL );
|
|
|
|
g_list_free( cbdata->errqueue );
|
|
|
|
cbdata->errqueue = NULL;
|
|
|
|
g_free( joined );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case TR_CORE_ERR_SAVE_STATE:
|
|
|
|
errmsg( cbdata->wind, "%s", msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2007-05-24 02:50:28 +00:00
|
|
|
void
|
|
|
|
coreprompt( TrCore * core, GList * paths, enum tr_torrent_action act,
|
|
|
|
gboolean paused, gpointer gdata )
|
|
|
|
{
|
|
|
|
struct cbdata * cbdata = gdata;
|
|
|
|
|
2007-05-24 10:37:07 +00:00
|
|
|
promptfordir( cbdata->wind, core, paths, NULL, 0, act, paused );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
corepromptdata( TrCore * core, uint8_t * data, size_t size,
|
|
|
|
gboolean paused, gpointer gdata )
|
|
|
|
{
|
|
|
|
struct cbdata * cbdata = gdata;
|
|
|
|
|
|
|
|
promptfordir( cbdata->wind, core, NULL, data, size, TR_TOR_LEAVE, paused );
|
2007-05-24 02:50:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
static void
|
|
|
|
readinitialprefs( struct cbdata * cbdata )
|
|
|
|
{
|
|
|
|
int prefs[] =
|
|
|
|
{
|
|
|
|
PREF_ID_PORT,
|
2007-07-23 03:03:45 +00:00
|
|
|
PREF_ID_DOWNLIMIT,
|
2007-02-19 22:09:05 +00:00
|
|
|
PREF_ID_USEDOWNLIMIT,
|
2007-07-23 03:03:45 +00:00
|
|
|
PREF_ID_UPLIMIT,
|
2007-02-19 22:09:05 +00:00
|
|
|
PREF_ID_USEUPLIMIT,
|
|
|
|
PREF_ID_NAT,
|
|
|
|
PREF_ID_ICON,
|
2007-03-31 19:19:27 +00:00
|
|
|
PREF_ID_PEX,
|
2007-02-19 22:09:05 +00:00
|
|
|
};
|
|
|
|
int ii;
|
|
|
|
|
|
|
|
for( ii = 0; ALEN( prefs ) > ii; ii++ )
|
|
|
|
{
|
|
|
|
prefschanged( NULL, prefs[ii], cbdata );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-05-24 13:55:57 +00:00
|
|
|
prefschanged( TrCore * core SHUTUP, int id, gpointer data )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-07-23 03:03:45 +00:00
|
|
|
struct cbdata * cbdata = data;
|
|
|
|
tr_handle_t * tr = tr_core_handle( cbdata->core );
|
2007-03-31 19:19:27 +00:00
|
|
|
gboolean boolval;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case PREF_ID_PORT:
|
|
|
|
tr_setBindPort( tr, tr_prefs_get_int_with_default( id ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PREF_ID_USEDOWNLIMIT:
|
2007-07-20 08:33:59 +00:00
|
|
|
tr_setUseGlobalSpeedLimit( tr, TR_DOWN,
|
|
|
|
tr_prefs_get_bool_with_default( PREF_ID_USEDOWNLIMIT ) );
|
|
|
|
break;
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
case PREF_ID_DOWNLIMIT:
|
2007-07-20 08:33:59 +00:00
|
|
|
tr_setGlobalSpeedLimit( tr, TR_DOWN,
|
|
|
|
tr_prefs_get_int_with_default( PREF_ID_DOWNLIMIT ) );
|
2007-02-19 22:09:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PREF_ID_USEUPLIMIT:
|
2007-07-20 08:33:59 +00:00
|
|
|
tr_setUseGlobalSpeedLimit( tr, TR_UP,
|
|
|
|
tr_prefs_get_bool_with_default( PREF_ID_USEUPLIMIT ) );
|
|
|
|
break;
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
case PREF_ID_UPLIMIT:
|
2007-07-20 08:33:59 +00:00
|
|
|
tr_setGlobalSpeedLimit( tr, TR_UP,
|
|
|
|
tr_prefs_get_int_with_default( PREF_ID_UPLIMIT ) );
|
2007-02-19 22:09:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PREF_ID_NAT:
|
|
|
|
tr_natTraversalEnable( tr, tr_prefs_get_bool_with_default( id ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PREF_ID_ICON:
|
|
|
|
if( tr_prefs_get_bool_with_default( id ) )
|
|
|
|
{
|
|
|
|
makeicon( cbdata );
|
|
|
|
}
|
|
|
|
else if( NULL != cbdata->icon )
|
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
g_message ("foo");
|
2007-02-19 22:09:05 +00:00
|
|
|
g_object_unref( cbdata->icon );
|
|
|
|
cbdata->icon = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-03-31 19:19:27 +00:00
|
|
|
case PREF_ID_PEX:
|
|
|
|
boolval = tr_prefs_get_bool_with_default( id );
|
|
|
|
tr_torrentIterate( tr, setpex, &boolval );
|
|
|
|
break;
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
case PREF_ID_DIR:
|
|
|
|
case PREF_ID_ASKDIR:
|
|
|
|
case PREF_ID_ADDSTD:
|
|
|
|
case PREF_ID_ADDIPC:
|
|
|
|
case PREF_ID_MSGLEVEL:
|
|
|
|
case PREF_MAX_ID:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-31 19:19:27 +00:00
|
|
|
void
|
|
|
|
setpex( tr_torrent_t * tor, void * arg )
|
|
|
|
{
|
|
|
|
gboolean * val;
|
|
|
|
|
|
|
|
val = arg;
|
|
|
|
tr_torrentDisablePex( tor, !(*val) );
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
gboolean
|
|
|
|
updatemodel(gpointer gdata) {
|
|
|
|
struct cbdata *data = gdata;
|
|
|
|
float up, down;
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
if( !data->closing && 0 < global_sigcount )
|
|
|
|
{
|
|
|
|
wannaquit( data );
|
|
|
|
return FALSE;
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-05-23 02:45:28 +00:00
|
|
|
/* update the torrent data in the model */
|
|
|
|
tr_core_update( data->core );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
/* update the main window's statusbar and toolbar buttons */
|
2007-02-19 22:09:05 +00:00
|
|
|
if( NULL != data->wind )
|
|
|
|
{
|
2007-05-23 01:47:42 +00:00
|
|
|
tr_torrentRates( tr_core_handle( data->core ), &down, &up );
|
2007-06-18 03:40:41 +00:00
|
|
|
tr_window_update( data->wind, down, up );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2006-08-20 22:45:29 +00:00
|
|
|
/* update the message window */
|
|
|
|
msgwin_update();
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-08-20 22:45:29 +00:00
|
|
|
boolwindclosed(GtkWidget *widget SHUTUP, gpointer gdata) {
|
|
|
|
gboolean *preachy_gcc = gdata;
|
|
|
|
|
|
|
|
*preachy_gcc = FALSE;
|
|
|
|
}
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* returns a GList containing a GtkTreeRowReference to each selected row */
|
|
|
|
static GList *
|
|
|
|
getselection( struct cbdata * cbdata )
|
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
GList * rows = NULL;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
if( NULL != cbdata->wind )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
GList * ii;
|
|
|
|
GtkTreeSelection *s = tr_window_get_selection(cbdata->wind);
|
|
|
|
GtkTreeModel * model = tr_core_model( cbdata->core );
|
|
|
|
rows = gtk_tree_selection_get_selected_rows( s, NULL );
|
|
|
|
for( ii = rows; NULL != ii; ii = ii->next )
|
|
|
|
{
|
|
|
|
GtkTreeRowReference * ref = gtk_tree_row_reference_new(
|
|
|
|
model, ii->data );
|
|
|
|
gtk_tree_path_free( ii->data );
|
|
|
|
ii->data = ref;
|
|
|
|
}
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
2007-06-09 15:20:32 +00:00
|
|
|
static void
|
|
|
|
about ( void )
|
|
|
|
{
|
|
|
|
GtkWidget * w = gtk_about_dialog_new ();
|
|
|
|
GtkAboutDialog * a = GTK_ABOUT_DIALOG (w);
|
|
|
|
const char *authors[] = { "Eric Petit (Back-end; OS X)",
|
|
|
|
"Josh Elsasser (Back-end; GTK+)",
|
|
|
|
"Mitchell Livingston (Back-end; OS X)",
|
|
|
|
"Charles Kerr (Back-end; GTK+)",
|
|
|
|
"Bryan Varner (BeOS)",
|
|
|
|
NULL };
|
2007-07-10 19:40:21 +00:00
|
|
|
gtk_about_dialog_set_version (a, LONG_VERSION_STRING );
|
2007-06-09 17:08:25 +00:00
|
|
|
#ifdef SHOW_LICENSE
|
2007-06-09 15:20:32 +00:00
|
|
|
gtk_about_dialog_set_license (a, LICENSE);
|
|
|
|
gtk_about_dialog_set_wrap_license (a, TRUE);
|
2007-06-09 17:08:25 +00:00
|
|
|
#endif
|
2007-06-09 15:20:32 +00:00
|
|
|
gtk_about_dialog_set_website (a, "http://transmission.m0k.org/");
|
|
|
|
gtk_about_dialog_set_copyright (a, _("Copyright 2005-2007 The Transmission Project"));
|
|
|
|
gtk_about_dialog_set_authors (a, authors);
|
|
|
|
gtk_about_dialog_set_translator_credits (a, _("translator-credits"));
|
|
|
|
g_signal_connect_swapped (w, "response", G_CALLBACK (gtk_widget_destroy), w);
|
|
|
|
gtk_widget_show_all (w);
|
|
|
|
}
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2007-06-18 03:40:41 +00:00
|
|
|
startTorrentForeach (GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
TrTorrent * tor = NULL;
|
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
|
|
|
tr_torrent_start( tor );
|
|
|
|
g_object_unref( G_OBJECT( tor ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stopTorrentForeach (GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
|
|
|
{
|
|
|
|
TrTorrent * tor = NULL;
|
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
|
|
|
tr_torrent_stop( tor );
|
|
|
|
g_object_unref( G_OBJECT( tor ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
showInfoForeach (GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
|
|
|
{
|
|
|
|
TrTorrent * tor = NULL;
|
|
|
|
GtkWidget * w;
|
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
|
|
|
w = torrent_inspector_new( GTK_WINDOW(data), tor );
|
|
|
|
gtk_widget_show( w );
|
|
|
|
g_object_unref( G_OBJECT( tor ) );
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
|
|
|
recheckTorrentForeach (GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
|
|
|
{
|
|
|
|
TrTorrent * gtor = NULL;
|
2007-06-26 18:45:03 +00:00
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, >or, -1 );
|
|
|
|
tr_torrentRecheck( tr_torrent_handle( gtor ) );
|
2007-06-18 03:40:41 +00:00
|
|
|
g_object_unref( G_OBJECT( gtor ) );
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
void
|
|
|
|
doAction ( const char * action_name, gpointer user_data )
|
|
|
|
{
|
|
|
|
struct cbdata * data = (struct cbdata *) user_data;
|
|
|
|
gboolean changed = FALSE;
|
|
|
|
|
|
|
|
if (!strcmp (action_name, "add-torrent"))
|
2007-05-23 00:49:31 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
makeaddwind( data->wind, data->core );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
else if (!strcmp (action_name, "start-torrent"))
|
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
|
|
|
gtk_tree_selection_selected_foreach( s, startTorrentForeach, NULL );
|
|
|
|
changed |= gtk_tree_selection_count_selected_rows( s ) != 0;
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "stop-torrent"))
|
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
|
|
|
gtk_tree_selection_selected_foreach( s, stopTorrentForeach, NULL );
|
|
|
|
changed |= gtk_tree_selection_count_selected_rows( s ) != 0;
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "recheck-torrent"))
|
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
|
|
|
gtk_tree_selection_selected_foreach( s, recheckTorrentForeach, NULL );
|
|
|
|
changed |= gtk_tree_selection_count_selected_rows( s ) != 0;
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "show-torrent-inspector"))
|
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
|
|
|
gtk_tree_selection_selected_foreach( s, showInfoForeach, data->wind );
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "create-torrent"))
|
|
|
|
{
|
|
|
|
GtkWidget * w = make_meta_ui( GTK_WINDOW( data->wind ), tr_core_handle( data->core ) );
|
|
|
|
gtk_widget_show_all( w );
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "remove-torrent"))
|
|
|
|
{
|
|
|
|
/* this modifies the model's contents, so can't use foreach */
|
|
|
|
GList *l, *sel = getselection( data );
|
|
|
|
GtkTreeModel *model = tr_core_model( data->core );
|
|
|
|
for( l=sel; l!=NULL; l=l->next )
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeRowReference * reference = (GtkTreeRowReference *) l->data;
|
|
|
|
GtkTreePath * path = gtk_tree_row_reference_get_path( reference );
|
|
|
|
gtk_tree_model_get_iter( model, &iter, path );
|
|
|
|
tr_core_delete_torrent( data->core, &iter );
|
|
|
|
gtk_tree_row_reference_free( reference );
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
g_list_free( sel );
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "close"))
|
|
|
|
{
|
|
|
|
if( data->wind != NULL )
|
|
|
|
winclose( NULL, NULL, data );
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "quit"))
|
|
|
|
{
|
2007-07-16 18:45:51 +00:00
|
|
|
askquit( data->core, data->wind, wannaquit, data );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "edit-preferences"))
|
|
|
|
{
|
|
|
|
if( NULL == data->prefs )
|
|
|
|
{
|
|
|
|
data->prefs = tr_prefs_new_with_parent( G_OBJECT( data->core ),
|
|
|
|
data->wind );
|
|
|
|
g_signal_connect( data->prefs, "destroy",
|
|
|
|
G_CALLBACK( gtk_widget_destroyed ), &data->prefs );
|
|
|
|
gtk_widget_show( GTK_WIDGET( data->prefs ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "show-debug-window"))
|
|
|
|
{
|
|
|
|
if( !data->msgwinopen )
|
|
|
|
{
|
2007-06-22 20:59:23 +00:00
|
|
|
GtkWidget * win = msgwin_create( data->core );
|
2007-06-18 03:40:41 +00:00
|
|
|
g_signal_connect( win, "destroy", G_CALLBACK( boolwindclosed ),
|
|
|
|
&data->msgwinopen );
|
|
|
|
data->msgwinopen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "show-about-dialog"))
|
|
|
|
{
|
|
|
|
about();
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "toggle-main-window"))
|
|
|
|
{
|
|
|
|
GtkWidget * w = GTK_WIDGET (data->wind);
|
|
|
|
if (GTK_WIDGET_VISIBLE(w))
|
|
|
|
gtk_widget_hide (w);
|
|
|
|
else
|
|
|
|
gtk_window_present (GTK_WINDOW(w));
|
|
|
|
}
|
|
|
|
else g_error ("Unhandled action: %s", action_name );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
if(changed)
|
|
|
|
{
|
|
|
|
updatemodel( data );
|
|
|
|
tr_core_save( data->core );
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
safepipe(void) {
|
|
|
|
struct sigaction sa;
|
|
|
|
|
2007-07-18 17:28:25 +00:00
|
|
|
memset(&sa, 0, sizeof(sa));
|
2006-07-16 19:39:23 +00:00
|
|
|
sa.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGPIPE, &sa, NULL);
|
|
|
|
}
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
setupsighandlers(void) {
|
2007-02-19 22:09:05 +00:00
|
|
|
int sigs[] = {SIGHUP, SIGINT, SIGQUIT, SIGTERM};
|
2006-07-16 19:39:23 +00:00
|
|
|
struct sigaction sa;
|
2007-02-19 22:09:05 +00:00
|
|
|
int ii;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-18 17:28:25 +00:00
|
|
|
memset(&sa, 0, sizeof(sa));
|
2006-07-16 19:39:23 +00:00
|
|
|
sa.sa_handler = fatalsig;
|
|
|
|
for(ii = 0; ii < ALEN(sigs); ii++)
|
|
|
|
sigaction(sigs[ii], &sa, NULL);
|
|
|
|
}
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2006-07-16 19:39:23 +00:00
|
|
|
fatalsig(int sig) {
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
if(SIGCOUNT_MAX <= ++global_sigcount) {
|
2007-07-18 17:28:25 +00:00
|
|
|
memset(&sa, 0, sizeof(sa));
|
2006-07-16 19:39:23 +00:00
|
|
|
sa.sa_handler = SIG_DFL;
|
|
|
|
sigaction(sig, &sa, NULL);
|
|
|
|
raise(sig);
|
|
|
|
}
|
|
|
|
}
|