2006-08-13 00:26:52 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-01 17:20:20 +00:00
|
|
|
* Copyright (c) 2005-2008 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 <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>
|
|
|
|
|
2008-02-07 01:10:34 +00:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#endif
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "actions.h"
|
2008-04-03 02:11:15 +00:00
|
|
|
#include "add-dialog.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
#include "conf.h"
|
2008-02-19 03:57:03 +00:00
|
|
|
#include "details.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
#include "dialogs.h"
|
2008-03-13 20:47:58 +00:00
|
|
|
#include "hig.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
#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"
|
2008-02-24 15:42:31 +00:00
|
|
|
#include "notify.h"
|
2007-11-27 03:29:51 +00:00
|
|
|
#include "stats.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-core.h"
|
|
|
|
#include "tr-icon.h"
|
|
|
|
#include "tr-prefs.h"
|
|
|
|
#include "tr-torrent.h"
|
|
|
|
#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
|
|
|
/* interval in milliseconds to update the torrent list display */
|
2008-03-16 15:18:19 +00:00
|
|
|
#define UPDATE_INTERVAL 1666
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
/* interval in milliseconds to check for stopped torrents and update display */
|
|
|
|
#define EXIT_CHECK_INTERVAL 500
|
|
|
|
|
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
|
|
|
|
2008-01-28 22:18:43 +00:00
|
|
|
struct cbdata
|
|
|
|
{
|
2008-03-17 03:25:03 +00:00
|
|
|
gboolean minimized;
|
|
|
|
gboolean closing;
|
|
|
|
guint timer;
|
2008-02-07 01:10:34 +00:00
|
|
|
guint idle_hide_mainwindow_tag;
|
2008-03-17 03:25:03 +00:00
|
|
|
gpointer icon;
|
2007-02-19 22:09:05 +00:00
|
|
|
GtkWindow * wind;
|
2007-05-23 00:49:31 +00:00
|
|
|
TrCore * core;
|
2007-09-21 16:29:09 +00:00
|
|
|
GtkWidget * msgwin;
|
2007-09-27 20:57:58 +00:00
|
|
|
GtkWidget * prefs;
|
2008-03-18 01:22:11 +00:00
|
|
|
GSList * errqueue;
|
2008-01-28 22:18:43 +00:00
|
|
|
GHashTable * tor2details;
|
|
|
|
GHashTable * details2tor;
|
2006-07-16 19:39:23 +00:00
|
|
|
};
|
|
|
|
|
2007-11-09 16:11:10 +00:00
|
|
|
#define CBDATA_PTR "callback-data-pointer"
|
2007-02-07 07:35:33 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static GtkUIManager * myUIManager = NULL;
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
static gboolean
|
2008-03-18 01:22:11 +00:00
|
|
|
sendremote( GSList * files, gboolean sendquit );
|
2007-02-19 22:09:05 +00:00
|
|
|
static void
|
2008-03-18 01:22:11 +00:00
|
|
|
appsetup( TrWindow * wind, GSList * args,
|
2008-01-23 16:22:52 +00:00
|
|
|
struct cbdata *,
|
|
|
|
gboolean paused, gboolean minimized );
|
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
|
|
|
wannaquit( void * vdata );
|
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
|
2008-03-18 01:22:11 +00:00
|
|
|
onAddTorrent( TrCore *, tr_ctor *, gpointer );
|
2007-05-24 10:37:07 +00:00
|
|
|
static void
|
2007-09-27 20:57:58 +00:00
|
|
|
prefschanged( TrCore * core, const char * key, gpointer data );
|
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
|
|
|
|
2007-10-26 23:29:19 +00:00
|
|
|
struct counts_data
|
|
|
|
{
|
|
|
|
int totalCount;
|
|
|
|
int activeCount;
|
|
|
|
int inactiveCount;
|
|
|
|
};
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
2007-12-28 06:22:40 +00:00
|
|
|
accumulateStatusForeach( GtkTreeModel * model,
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
2007-10-26 23:29:19 +00:00
|
|
|
gpointer user_data )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
|
|
|
int status = 0;
|
2007-10-26 23:29:19 +00:00
|
|
|
struct counts_data * counts = user_data;
|
|
|
|
|
|
|
|
++counts->totalCount;
|
|
|
|
|
2007-12-28 06:22:40 +00:00
|
|
|
gtk_tree_model_get( model, iter, MC_STATUS, &status, -1 );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
2007-10-26 23:29:19 +00:00
|
|
|
if( TR_STATUS_IS_ACTIVE( status ) )
|
|
|
|
++counts->activeCount;
|
|
|
|
else
|
|
|
|
++counts->inactiveCount;
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2007-07-30 17:11:00 +00:00
|
|
|
static void
|
|
|
|
accumulateCanUpdateForeach (GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer accumulated_status)
|
|
|
|
{
|
2007-12-28 06:22:40 +00:00
|
|
|
tr_torrent * tor;
|
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 );
|
|
|
|
*(int*)accumulated_status |= tr_torrentCanManualUpdate( tor );
|
2007-07-30 17:11:00 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
|
|
|
refreshTorrentActions( GtkTreeSelection * s )
|
|
|
|
{
|
2007-10-26 23:29:19 +00:00
|
|
|
int canUpdate;
|
|
|
|
struct counts_data counts;
|
|
|
|
|
|
|
|
counts.activeCount = 0;
|
|
|
|
counts.inactiveCount = 0;
|
|
|
|
counts.totalCount = 0;
|
|
|
|
gtk_tree_selection_selected_foreach( s, accumulateStatusForeach, &counts );
|
|
|
|
action_sensitize( "pause-torrent", counts.activeCount!=0 );
|
|
|
|
action_sensitize( "start-torrent", counts.inactiveCount!=0 );
|
2008-03-07 17:47:42 +00:00
|
|
|
action_sensitize( "remove-torrent", counts.totalCount!=0 );
|
2008-03-02 15:54:58 +00:00
|
|
|
action_sensitize( "delete-torrent", counts.totalCount!=0 );
|
2007-10-26 23:29:19 +00:00
|
|
|
action_sensitize( "verify-torrent", counts.totalCount!=0 );
|
2008-04-11 02:21:33 +00:00
|
|
|
action_sensitize( "open-torrent-folder", counts.totalCount==1 );
|
2008-01-03 23:54:29 +00:00
|
|
|
action_sensitize( "show-torrent-details", counts.totalCount==1 );
|
2007-10-26 23:29:19 +00:00
|
|
|
|
|
|
|
canUpdate = 0;
|
|
|
|
gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach, &canUpdate );
|
|
|
|
action_sensitize( "update-tracker", canUpdate!=0 );
|
2008-03-19 20:34:35 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
GtkTreeView * view = gtk_tree_selection_get_tree_view( s );
|
|
|
|
GtkTreeModel * model = gtk_tree_view_get_model( view );
|
|
|
|
const int torrentCount = gtk_tree_model_iter_n_children( model, NULL ) != 0;
|
|
|
|
action_sensitize( "select-all", torrentCount!=0 );
|
|
|
|
action_sensitize( "deselect-all", torrentCount!=0 );
|
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selectionChangedCB( GtkTreeSelection * s, gpointer unused UNUSED )
|
|
|
|
{
|
|
|
|
refreshTorrentActions( s );
|
|
|
|
}
|
|
|
|
|
2008-02-27 20:30:51 +00:00
|
|
|
static void
|
|
|
|
windowStateChanged( GtkWidget * widget UNUSED, GdkEventWindowState * event, gpointer gdata )
|
|
|
|
{
|
|
|
|
if( event->changed_mask & GDK_WINDOW_STATE_ICONIFIED )
|
|
|
|
{
|
|
|
|
struct cbdata * cbdata = gdata;
|
|
|
|
cbdata->minimized = ( event->new_window_state & GDK_WINDOW_STATE_ICONIFIED ) ? 1 : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 17:51:54 +00:00
|
|
|
static sig_atomic_t global_sigcount = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
fatalsig( int sig )
|
|
|
|
{
|
|
|
|
static const int SIGCOUNT_MAX = 3; /* revert to default handler after this many */
|
|
|
|
|
|
|
|
if( ++global_sigcount >= SIGCOUNT_MAX )
|
|
|
|
{
|
|
|
|
signal( sig, SIG_DFL );
|
|
|
|
raise( sig );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
setupsighandlers( void )
|
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
const int sigs[] = { SIGINT, SIGTERM };
|
|
|
|
#else
|
|
|
|
const int sigs[] = { SIGHUP, SIGINT, SIGQUIT, SIGTERM };
|
|
|
|
#endif
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for( i=0; i<G_N_ELEMENTS(sigs); ++i )
|
|
|
|
signal( sigs[i], fatalsig );
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
int
|
2007-02-19 22:09:05 +00:00
|
|
|
main( int argc, char ** argv )
|
|
|
|
{
|
2007-10-12 19:53:30 +00:00
|
|
|
char * err;
|
2008-01-28 22:18:43 +00:00
|
|
|
struct cbdata * cbdata;
|
2008-03-18 01:22:11 +00:00
|
|
|
GSList * argfiles;
|
2007-12-30 18:23:45 +00:00
|
|
|
GError * gerr;
|
2007-10-12 20:50:03 +00:00
|
|
|
gboolean didinit = FALSE;
|
|
|
|
gboolean didlock = FALSE;
|
|
|
|
gboolean sendquit = FALSE;
|
|
|
|
gboolean startpaused = FALSE;
|
2008-01-23 16:22:52 +00:00
|
|
|
gboolean startminimized = FALSE;
|
2007-10-12 19:53:30 +00:00
|
|
|
char * domain = "transmission";
|
2008-04-05 20:12:11 +00:00
|
|
|
const char * configDir = tr_getDefaultConfigDir( );
|
|
|
|
|
2007-10-12 19:53:30 +00:00
|
|
|
GOptionEntry entries[] = {
|
2007-10-13 03:15:02 +00:00
|
|
|
{ "paused", 'p', 0, G_OPTION_ARG_NONE, &startpaused,
|
|
|
|
_("Start with all torrents paused"), NULL },
|
|
|
|
{ "quit", 'q', 0, G_OPTION_ARG_NONE, &sendquit,
|
2008-03-07 20:48:36 +00:00
|
|
|
_( "Ask the running instance to quit"), NULL },
|
2008-01-23 16:22:52 +00:00
|
|
|
#ifdef STATUS_ICON_SUPPORTED
|
|
|
|
{ "minimized", 'm', 0, G_OPTION_ARG_NONE, &startminimized,
|
|
|
|
_( "Start minimized in system tray"), NULL },
|
|
|
|
#endif
|
2007-10-12 19:53:30 +00:00
|
|
|
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2008-01-28 22:18:43 +00:00
|
|
|
cbdata = g_new0( struct cbdata, 1 );
|
|
|
|
cbdata->tor2details = g_hash_table_new( g_str_hash, g_str_equal );
|
|
|
|
cbdata->details2tor = g_hash_table_new( g_direct_hash, g_direct_equal );
|
|
|
|
|
2007-10-12 19:53:30 +00:00
|
|
|
/* bind the gettext domain */
|
|
|
|
bindtextdomain( domain, TRANSMISSIONLOCALEDIR );
|
|
|
|
bind_textdomain_codeset( domain, "UTF-8" );
|
|
|
|
textdomain( domain );
|
|
|
|
g_set_application_name( _( "Transmission" ) );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-10-12 19:53:30 +00:00
|
|
|
/* initialize gtk */
|
2007-11-09 16:11:10 +00:00
|
|
|
g_thread_init( NULL );
|
2007-12-30 18:23:45 +00:00
|
|
|
gerr = NULL;
|
|
|
|
if( !gtk_init_with_args( &argc, &argv, _("[torrent files]"), entries, domain, &gerr ) ) {
|
|
|
|
g_message( "%s", gerr->message );
|
|
|
|
g_clear_error( &gerr );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-24 15:42:31 +00:00
|
|
|
tr_notify_init( );
|
|
|
|
|
2008-04-05 20:12:11 +00:00
|
|
|
didinit = cf_init( configDir, NULL ); /* must come before actions_init */
|
2007-12-19 02:46:30 +00:00
|
|
|
tr_prefs_init_global( );
|
2007-10-12 19:53:30 +00:00
|
|
|
myUIManager = gtk_ui_manager_new ();
|
|
|
|
actions_init ( myUIManager, cbdata );
|
|
|
|
gtk_ui_manager_add_ui_from_string (myUIManager, fallback_ui_file, -1, NULL);
|
|
|
|
gtk_ui_manager_ensure_update (myUIManager);
|
2008-02-07 20:02:06 +00:00
|
|
|
gtk_window_set_default_icon_name ( "transmission" );
|
2007-10-12 19:53:30 +00:00
|
|
|
|
|
|
|
argfiles = checkfilenames( argc-1, argv+1 );
|
2007-10-13 03:15:02 +00:00
|
|
|
didlock = didinit && sendremote( argfiles, sendquit );
|
|
|
|
setupsighandlers( ); /* set up handlers for fatal signals */
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-04-05 20:12:11 +00:00
|
|
|
if( ( didinit || cf_init( configDir, &err ) ) &&
|
2007-02-19 22:09:05 +00:00
|
|
|
( didlock || cf_lock( &err ) ) )
|
|
|
|
{
|
2007-12-19 19:16:36 +00:00
|
|
|
cbdata->core = tr_core_new( );
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* create main window now to be a parent to any error dialogs */
|
2007-12-19 19:16:36 +00:00
|
|
|
GtkWindow * mainwind = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) );
|
2008-02-27 20:30:51 +00:00
|
|
|
g_signal_connect( mainwind, "window-state-event", G_CALLBACK(windowStateChanged), cbdata );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-01-23 16:22:52 +00:00
|
|
|
appsetup( mainwind, argfiles, cbdata, startpaused, startminimized );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
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
|
|
|
static gboolean
|
2008-03-18 01:22:11 +00:00
|
|
|
sendremote( GSList * files, gboolean sendquit )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-10-13 03:15:02 +00:00
|
|
|
const gboolean didlock = cf_lock( NULL );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-10-13 03:15:02 +00:00
|
|
|
/* send files if there's another instance, otherwise start normally */
|
|
|
|
if( !didlock && files )
|
|
|
|
exit( ipc_sendfiles_blocking( files ) ? 0 : 1 );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-10-13 03:15:02 +00:00
|
|
|
/* either send a quit message or exit if no other instance */
|
2007-02-19 22:09:05 +00:00
|
|
|
if( sendquit )
|
2007-10-13 03:15:02 +00:00
|
|
|
exit( didlock ? 0 : !ipc_sendquit_blocking() );
|
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-19 22:09:05 +00:00
|
|
|
static void
|
2008-03-18 01:22:11 +00:00
|
|
|
appsetup( TrWindow * wind, GSList * torrentFiles,
|
2008-01-23 16:22:52 +00:00
|
|
|
struct cbdata * cbdata,
|
2008-02-13 03:00:21 +00:00
|
|
|
gboolean forcepause, gboolean minimized )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2008-03-19 14:54:32 +00:00
|
|
|
const pref_flag_t start = forcepause ? PREF_FLAG_FALSE : PREF_FLAG_DEFAULT;
|
|
|
|
const pref_flag_t prompt = PREF_FLAG_DEFAULT;
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* fill out cbdata */
|
|
|
|
cbdata->wind = NULL;
|
|
|
|
cbdata->icon = NULL;
|
2007-09-21 16:29:09 +00:00
|
|
|
cbdata->msgwin = NULL;
|
2007-02-19 22:09:05 +00:00
|
|
|
cbdata->prefs = NULL;
|
|
|
|
cbdata->timer = 0;
|
|
|
|
cbdata->closing = FALSE;
|
2007-05-23 17:59:35 +00:00
|
|
|
cbdata->errqueue = NULL;
|
2008-02-03 01:43:47 +00:00
|
|
|
cbdata->minimized = minimized;
|
2007-05-23 17:59:35 +00:00
|
|
|
|
2007-12-19 18:42:33 +00:00
|
|
|
actions_set_core( cbdata->core );
|
|
|
|
|
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 );
|
2008-03-18 01:22:11 +00:00
|
|
|
g_signal_connect( cbdata->core, "add-torrent-prompt",
|
|
|
|
G_CALLBACK( onAddTorrent ), 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
|
|
|
|
2007-05-24 02:50:28 +00:00
|
|
|
/* add torrents from command-line and saved state */
|
2008-02-13 03:00:21 +00:00
|
|
|
tr_core_load( cbdata->core, forcepause );
|
2008-03-19 14:54:32 +00:00
|
|
|
tr_core_add_list( cbdata->core, torrentFiles, start, prompt );
|
2008-03-18 01:22:11 +00:00
|
|
|
torrentFiles = NULL;
|
2007-05-24 02:50:28 +00:00
|
|
|
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 );
|
|
|
|
|
2008-03-08 17:37:13 +00:00
|
|
|
/* set up the system tray */
|
2008-03-17 03:25:03 +00:00
|
|
|
cbdata->icon = tr_icon_new( cbdata->core );
|
2008-03-08 17:37:13 +00:00
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
/* start model update timer */
|
|
|
|
cbdata->timer = g_timeout_add( UPDATE_INTERVAL, updatemodel, cbdata );
|
|
|
|
updatemodel( cbdata );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-04-11 14:36:29 +00:00
|
|
|
/* either show the window or iconify it */
|
|
|
|
if( !minimized )
|
|
|
|
gtk_widget_show( GTK_WIDGET( wind ) );
|
|
|
|
else {
|
2008-02-03 01:43:47 +00:00
|
|
|
gtk_window_iconify( wind );
|
2008-02-07 01:10:34 +00:00
|
|
|
gtk_window_set_skip_taskbar_hint( cbdata->wind, cbdata->icon != NULL );
|
|
|
|
}
|
2008-02-03 01:43:47 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 01:10:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* hideMainWindow, and the timeout hack in toggleMainWindow,
|
|
|
|
* are loosely cribbed from Colin Walters' tr-shell.c in Rhythmbox
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
idle_hide_mainwindow( gpointer window )
|
|
|
|
{
|
|
|
|
gtk_widget_hide( window );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-02-03 01:43:47 +00:00
|
|
|
static void
|
2008-02-07 01:10:34 +00:00
|
|
|
hideMainWindow( struct cbdata * cbdata )
|
2008-02-03 01:43:47 +00:00
|
|
|
{
|
2008-02-07 01:10:34 +00:00
|
|
|
#if defined(STATUS_ICON_SUPPORTED) && defined(GDK_WINDOWING_X11)
|
|
|
|
GdkRectangle bounds;
|
|
|
|
gulong data[4];
|
|
|
|
Display *dpy;
|
|
|
|
GdkWindow *gdk_window;
|
|
|
|
|
|
|
|
gtk_status_icon_get_geometry( GTK_STATUS_ICON( cbdata->icon ), NULL, &bounds, NULL );
|
|
|
|
gdk_window = GTK_WIDGET (cbdata->wind)->window;
|
|
|
|
dpy = gdk_x11_drawable_get_xdisplay (gdk_window);
|
|
|
|
|
|
|
|
data[0] = bounds.x;
|
|
|
|
data[1] = bounds.y;
|
|
|
|
data[2] = bounds.width;
|
|
|
|
data[3] = bounds.height;
|
|
|
|
|
|
|
|
XChangeProperty (dpy,
|
|
|
|
GDK_WINDOW_XID (gdk_window),
|
|
|
|
gdk_x11_get_xatom_by_name_for_display (gdk_drawable_get_display (gdk_window),
|
|
|
|
"_NET_WM_ICON_GEOMETRY"),
|
|
|
|
XA_CARDINAL, 32, PropModeReplace,
|
|
|
|
(guchar*)&data, 4);
|
|
|
|
|
|
|
|
gtk_window_set_skip_taskbar_hint( cbdata->wind, TRUE );
|
|
|
|
#endif
|
|
|
|
gtk_window_iconify( cbdata->wind );
|
|
|
|
}
|
2008-02-03 01:43:47 +00:00
|
|
|
|
2008-02-07 01:10:34 +00:00
|
|
|
static void
|
|
|
|
clearTag( guint * tag )
|
|
|
|
{
|
|
|
|
if( *tag )
|
|
|
|
g_source_remove( *tag );
|
|
|
|
*tag = 0;
|
2008-02-03 01:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-02-07 01:10:34 +00:00
|
|
|
toggleMainWindow( struct cbdata * cbdata )
|
2008-02-03 01:43:47 +00:00
|
|
|
{
|
2008-02-07 01:10:34 +00:00
|
|
|
GtkWindow * window = GTK_WINDOW( cbdata->wind );
|
2008-02-27 20:30:51 +00:00
|
|
|
const int hide = !cbdata->minimized;
|
2008-02-08 03:51:08 +00:00
|
|
|
static int x=0, y=0;
|
2008-02-07 01:10:34 +00:00
|
|
|
|
|
|
|
if( hide )
|
|
|
|
{
|
2008-02-08 03:51:08 +00:00
|
|
|
gtk_window_get_position( window, &x, &y );
|
2008-02-07 01:10:34 +00:00
|
|
|
clearTag( &cbdata->idle_hide_mainwindow_tag );
|
|
|
|
hideMainWindow( cbdata );
|
|
|
|
cbdata->idle_hide_mainwindow_tag = g_timeout_add( 250, idle_hide_mainwindow, window );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_window_set_skip_taskbar_hint( window, FALSE );
|
2008-02-08 03:51:08 +00:00
|
|
|
gtk_window_move( window, x, y );
|
2008-02-07 01:10:34 +00:00
|
|
|
gtk_widget_show( GTK_WIDGET( window ) );
|
|
|
|
gtk_window_deiconify( window );
|
2008-02-07 01:25:52 +00:00
|
|
|
#if GTK_CHECK_VERSION(2,8,0)
|
2008-02-07 01:10:34 +00:00
|
|
|
gtk_window_present_with_time( window, gtk_get_current_event_time( ) );
|
2008-02-07 01:25:52 +00:00
|
|
|
#else
|
|
|
|
gtk_window_present( window );
|
|
|
|
#endif
|
2008-02-07 01:10:34 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static gboolean
|
2007-10-13 03:15:02 +00:00
|
|
|
winclose( GtkWidget * w UNUSED, GdkEvent * event UNUSED, gpointer gdata )
|
2007-02-07 07:35:33 +00:00
|
|
|
{
|
2007-10-13 03:15:02 +00:00
|
|
|
struct cbdata * cbdata = gdata;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
if( cbdata->icon != NULL )
|
2008-02-07 01:10:34 +00:00
|
|
|
action_activate ("toggle-main-window");
|
2007-06-18 03:40:41 +00:00
|
|
|
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,
|
2007-11-23 15:36:31 +00:00
|
|
|
GtkTreePath * path,
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkTreeIter * iter UNUSED,
|
|
|
|
gpointer sel)
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-11-23 15:36:31 +00:00
|
|
|
if( gtk_tree_selection_path_is_selected ( sel, path ) )
|
|
|
|
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 );
|
|
|
|
g_signal_connect( model, "row-changed", G_CALLBACK(rowChangedCB), sel );
|
|
|
|
g_signal_connect( wind, "delete-event", G_CALLBACK( winclose ), cbdata );
|
2007-11-23 15:36:31 +00:00
|
|
|
refreshTorrentActions( sel );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
setupdrag( GTK_WIDGET(wind), cbdata );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-11-09 16:11:10 +00:00
|
|
|
static gpointer
|
|
|
|
quitThreadFunc( gpointer gdata )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-11-09 16:11:10 +00:00
|
|
|
struct cbdata * cbdata = gdata;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-11-09 16:11:10 +00:00
|
|
|
tr_close( tr_core_handle( cbdata->core ) );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-11-09 16:11:10 +00:00
|
|
|
/* shutdown the gui */
|
|
|
|
if( cbdata->prefs )
|
2007-02-19 22:09:05 +00:00
|
|
|
gtk_widget_destroy( GTK_WIDGET( cbdata->prefs ) );
|
2007-11-09 16:11:10 +00:00
|
|
|
if( cbdata->wind )
|
2007-02-19 22:09:05 +00:00
|
|
|
gtk_widget_destroy( GTK_WIDGET( cbdata->wind ) );
|
2007-05-23 00:49:31 +00:00
|
|
|
g_object_unref( cbdata->core );
|
2007-11-09 16:11:10 +00:00
|
|
|
if( cbdata->icon )
|
2007-02-19 22:09:05 +00:00
|
|
|
g_object_unref( cbdata->icon );
|
2007-11-09 16:11:10 +00:00
|
|
|
if( cbdata->errqueue ) {
|
2008-03-18 01:22:11 +00:00
|
|
|
g_slist_foreach( cbdata->errqueue, (GFunc)g_free, NULL );
|
|
|
|
g_slist_free( cbdata->errqueue );
|
2007-05-23 17:59:35 +00:00
|
|
|
}
|
2008-01-28 22:18:43 +00:00
|
|
|
|
|
|
|
g_hash_table_destroy( cbdata->details2tor );
|
|
|
|
g_hash_table_destroy( cbdata->tor2details );
|
2007-02-19 22:09:05 +00:00
|
|
|
g_free( cbdata );
|
|
|
|
|
2007-11-09 16:11:10 +00:00
|
|
|
/* exit the gtk main loop */
|
|
|
|
gtk_main_quit( );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-29 02:32:10 +00:00
|
|
|
/* since there are no buttons in the dialog, gtk tries to
|
|
|
|
* select one of the labels, which looks ugly... so force
|
|
|
|
* the dialog's primary and secondary labels to be unselectable */
|
|
|
|
static void
|
|
|
|
deselectLabels( GtkWidget * w, gpointer unused UNUSED )
|
|
|
|
{
|
|
|
|
if( GTK_IS_LABEL( w ) )
|
|
|
|
gtk_label_set_selectable( GTK_LABEL(w), FALSE );
|
|
|
|
else if( GTK_IS_CONTAINER( w ) )
|
|
|
|
gtk_container_foreach( GTK_CONTAINER(w), deselectLabels, NULL );
|
|
|
|
}
|
|
|
|
|
2007-12-14 18:36:19 +00:00
|
|
|
static void
|
|
|
|
do_exit_cb( GtkWidget *w UNUSED, gpointer data UNUSED )
|
|
|
|
{
|
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
2007-11-09 16:11:10 +00:00
|
|
|
static void
|
|
|
|
wannaquit( void * vdata )
|
|
|
|
{
|
2007-12-14 18:36:19 +00:00
|
|
|
GtkWidget * r, * p, * b, * w, *c;
|
2007-11-09 16:11:10 +00:00
|
|
|
struct cbdata * cbdata = vdata;
|
|
|
|
|
|
|
|
/* stop the update timer */
|
|
|
|
if( cbdata->timer ) {
|
|
|
|
g_source_remove( cbdata->timer );
|
|
|
|
cbdata->timer = 0;
|
|
|
|
}
|
|
|
|
|
2007-12-14 18:36:19 +00:00
|
|
|
c = GTK_WIDGET( cbdata->wind );
|
|
|
|
gtk_container_remove( GTK_CONTAINER( c ), gtk_bin_get_child( GTK_BIN( c ) ) );
|
|
|
|
|
|
|
|
r = gtk_alignment_new(0.5, 0.5, 0.01, 0.01);
|
|
|
|
gtk_container_add(GTK_CONTAINER(c), r);
|
|
|
|
|
2008-03-13 20:47:58 +00:00
|
|
|
p = gtk_table_new(3, 2, FALSE);
|
|
|
|
gtk_table_set_col_spacings( GTK_TABLE( p ), GUI_PAD_BIG );
|
|
|
|
gtk_container_add( GTK_CONTAINER( r ), p );
|
2007-12-14 18:36:19 +00:00
|
|
|
|
|
|
|
w = gtk_image_new_from_stock( GTK_STOCK_NETWORK, GTK_ICON_SIZE_DIALOG );
|
2008-03-13 20:47:58 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(p), w, 0, 1, 0, 2 );
|
2007-12-14 18:36:19 +00:00
|
|
|
|
2008-03-13 20:47:58 +00:00
|
|
|
w = gtk_label_new( NULL );
|
|
|
|
gtk_label_set_markup( GTK_LABEL( w ), _( "<b>Closing Connections</b>" ) );
|
|
|
|
gtk_misc_set_alignment( GTK_MISC( w ), 0.0, 0.5 );
|
|
|
|
gtk_table_attach_defaults( GTK_TABLE( p ), w, 1, 2, 0, 1 );
|
|
|
|
|
|
|
|
w = gtk_label_new( _( "Sending upload/download totals to tracker..." ) );
|
|
|
|
gtk_misc_set_alignment( GTK_MISC( w ), 0.0, 0.5 );
|
|
|
|
gtk_table_attach_defaults( GTK_TABLE( p ), w, 1, 2, 1, 2 );
|
2007-12-14 18:36:19 +00:00
|
|
|
|
|
|
|
b = gtk_alignment_new(0.0, 1.0, 0.01, 0.01);
|
|
|
|
w = gtk_button_new_with_label( _( "_Quit Immediately" ) );
|
|
|
|
gtk_button_set_image( GTK_BUTTON(w), gtk_image_new_from_stock( GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON ) );
|
|
|
|
g_signal_connect(w, "clicked", G_CALLBACK(do_exit_cb), NULL);
|
|
|
|
gtk_container_add(GTK_CONTAINER(b), w);
|
2008-03-13 20:47:58 +00:00
|
|
|
gtk_table_attach(GTK_TABLE(p), b, 1, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 10 );
|
2007-12-14 18:36:19 +00:00
|
|
|
|
|
|
|
gtk_widget_show_all(r);
|
2007-11-29 02:32:10 +00:00
|
|
|
|
2007-11-11 20:38:59 +00:00
|
|
|
/* clear the UI */
|
|
|
|
gtk_list_store_clear( GTK_LIST_STORE( tr_core_model( cbdata->core ) ) );
|
2007-11-29 02:32:10 +00:00
|
|
|
|
2007-11-09 16:11:10 +00:00
|
|
|
/* shut down libT */
|
|
|
|
g_thread_create( quitThreadFunc, vdata, TRUE, NULL );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 07:35:33 +00:00
|
|
|
static void
|
2007-10-12 19:53:30 +00:00
|
|
|
gotdrag( GtkWidget * widget UNUSED,
|
|
|
|
GdkDragContext * dc,
|
|
|
|
gint x UNUSED,
|
|
|
|
gint y UNUSED,
|
|
|
|
GtkSelectionData * sel,
|
|
|
|
guint info UNUSED,
|
|
|
|
guint time,
|
|
|
|
gpointer gdata )
|
|
|
|
{
|
|
|
|
struct cbdata * data = gdata;
|
2008-03-18 01:22:11 +00:00
|
|
|
GSList * paths = NULL;
|
|
|
|
GSList * freeme = NULL;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
#if 0
|
|
|
|
int i;
|
2007-10-12 19:53:30 +00:00
|
|
|
char *sele = gdk_atom_name(sel->selection);
|
|
|
|
char *targ = gdk_atom_name(sel->target);
|
|
|
|
char *type = gdk_atom_name(sel->type);
|
|
|
|
|
2007-10-13 03:15:02 +00:00
|
|
|
g_message( "dropped file: sel=%s targ=%s type=%s fmt=%i len=%i",
|
|
|
|
sele, targ, type, sel->format, sel->length );
|
2007-10-12 19:53:30 +00:00
|
|
|
g_free(sele);
|
|
|
|
g_free(targ);
|
|
|
|
g_free(type);
|
|
|
|
if( sel->format == 8 ) {
|
|
|
|
for( i=0; i<sel->length; ++i )
|
|
|
|
fprintf(stderr, "%02X ", sel->data[i]);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-12 19:53:30 +00:00
|
|
|
if( ( sel->format == 8 ) &&
|
|
|
|
( sel->selection == gdk_atom_intern( "XdndSelection", FALSE ) ) )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char * str = g_strndup( (char*)sel->data, sel->length );
|
|
|
|
gchar ** files = g_strsplit_set( str, "\r\n", -1 );
|
|
|
|
for( i=0; files && files[i]; ++i )
|
|
|
|
{
|
|
|
|
char * filename;
|
|
|
|
if( !*files[i] ) /* empty filename... */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* decode the filename */
|
2008-01-20 15:50:42 +00:00
|
|
|
filename = decode_uri( files[i] );
|
2008-03-18 01:22:11 +00:00
|
|
|
freeme = g_slist_prepend( freeme, filename );
|
2007-10-12 19:53:30 +00:00
|
|
|
if( !g_utf8_validate( filename, -1, NULL ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* walk past "file://", if present */
|
|
|
|
if( g_str_has_prefix( filename, "file:" ) ) {
|
|
|
|
filename += 5;
|
|
|
|
while( g_str_has_prefix( filename, "//" ) )
|
|
|
|
++filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the file doesn't exist, the first part
|
|
|
|
might be a hostname ... walk past it. */
|
|
|
|
if( !g_file_test( filename, G_FILE_TEST_EXISTS ) ) {
|
|
|
|
char * pch = strchr( filename + 1, '/' );
|
|
|
|
if( pch != NULL )
|
|
|
|
filename = pch;
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
/* finally, add it to the list of torrents to try adding */
|
2007-10-12 19:53:30 +00:00
|
|
|
if( g_file_test( filename, G_FILE_TEST_EXISTS ) )
|
2008-03-18 01:22:11 +00:00
|
|
|
paths = g_slist_prepend( paths, g_strdup( filename ) );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 19:53:30 +00:00
|
|
|
/* try to add any torrents we found */
|
2008-03-18 01:22:11 +00:00
|
|
|
if( paths )
|
2007-10-12 19:53:30 +00:00
|
|
|
{
|
2008-03-18 01:22:11 +00:00
|
|
|
paths = g_slist_reverse( paths );
|
2008-03-19 14:54:32 +00:00
|
|
|
tr_core_add_list_defaults( data->core, paths );
|
2007-10-12 19:53:30 +00:00
|
|
|
tr_core_torrents_added( data->core );
|
|
|
|
}
|
|
|
|
|
|
|
|
freestrlist( freeme );
|
|
|
|
g_strfreev( files );
|
|
|
|
g_free( str );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-10-12 19:53:30 +00:00
|
|
|
gtk_drag_finish(dc, (NULL != paths), FALSE, time);
|
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
|
|
|
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
|
2007-10-13 03:15:02 +00:00
|
|
|
coreerr( TrCore * core UNUSED, enum tr_core_err code, const char * msg,
|
2007-05-23 17:59:35 +00:00
|
|
|
gpointer gdata )
|
|
|
|
{
|
|
|
|
struct cbdata * cbdata = gdata;
|
|
|
|
char * joined;
|
|
|
|
|
|
|
|
switch( code )
|
|
|
|
{
|
|
|
|
case TR_CORE_ERR_ADD_TORRENT:
|
2008-03-18 01:22:11 +00:00
|
|
|
cbdata->errqueue = g_slist_append( cbdata->errqueue,
|
|
|
|
g_strdup( msg ) );
|
2007-05-23 17:59:35 +00:00
|
|
|
return;
|
|
|
|
case TR_CORE_ERR_NO_MORE_TORRENTS:
|
2008-03-18 01:22:11 +00:00
|
|
|
if( cbdata->errqueue )
|
2007-05-23 17:59:35 +00:00
|
|
|
{
|
|
|
|
joined = joinstrlist( cbdata->errqueue, "\n" );
|
|
|
|
errmsg( cbdata->wind,
|
2008-03-07 21:59:27 +00:00
|
|
|
ngettext( "Failed to load torrent file: %s",
|
|
|
|
"Failed to load torrent files: %s",
|
2008-03-18 01:22:11 +00:00
|
|
|
g_slist_length( cbdata->errqueue ) ),
|
2007-05-23 17:59:35 +00:00
|
|
|
joined );
|
2008-03-18 01:22:11 +00:00
|
|
|
g_slist_foreach( cbdata->errqueue, (GFunc) g_free, NULL );
|
|
|
|
g_slist_free( cbdata->errqueue );
|
2007-05-23 17:59:35 +00:00
|
|
|
cbdata->errqueue = NULL;
|
|
|
|
g_free( joined );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case TR_CORE_ERR_SAVE_STATE:
|
|
|
|
errmsg( cbdata->wind, "%s", msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2008-02-19 05:52:37 +00:00
|
|
|
#if GTK_CHECK_VERSION(2,8,0)
|
|
|
|
static void
|
|
|
|
on_main_window_focus_in( GtkWidget * widget UNUSED,
|
|
|
|
GdkEventFocus * event UNUSED,
|
|
|
|
gpointer gdata )
|
|
|
|
{
|
|
|
|
struct cbdata * cbdata = gdata;
|
|
|
|
gtk_window_set_urgency_hint( GTK_WINDOW( cbdata->wind ), FALSE );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
static void
|
2008-03-18 01:22:11 +00:00
|
|
|
onAddTorrent( TrCore * core, tr_ctor * ctor, gpointer gdata )
|
2007-05-24 10:37:07 +00:00
|
|
|
{
|
|
|
|
struct cbdata * cbdata = gdata;
|
2008-04-03 02:11:15 +00:00
|
|
|
GtkWidget * w = addSingleTorrentDialog( cbdata->wind, core, ctor );
|
2008-02-19 05:52:37 +00:00
|
|
|
#if GTK_CHECK_VERSION(2,8,0)
|
2008-03-18 01:22:11 +00:00
|
|
|
g_signal_connect( w, "focus-in-event", G_CALLBACK(on_main_window_focus_in), cbdata );
|
|
|
|
gtk_window_set_urgency_hint( cbdata->wind, TRUE );
|
2008-02-19 05:52:37 +00:00
|
|
|
#endif
|
2007-05-24 02:50:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-19 22:09:05 +00:00
|
|
|
static void
|
2007-09-27 20:57:58 +00:00
|
|
|
prefschanged( TrCore * core UNUSED, const char * key, gpointer data )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-07-23 03:03:45 +00:00
|
|
|
struct cbdata * cbdata = data;
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_handle * tr = tr_core_handle( cbdata->core );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-09-28 00:46:22 +00:00
|
|
|
if( !strcmp( key, PREF_KEY_ENCRYPTED_ONLY ) )
|
|
|
|
{
|
|
|
|
const gboolean crypto_only = pref_flag_get( key );
|
|
|
|
tr_setEncryptionMode( tr, crypto_only ? TR_ENCRYPTION_REQUIRED
|
|
|
|
: TR_ENCRYPTION_PREFERRED );
|
|
|
|
}
|
|
|
|
else if( !strcmp( key, PREF_KEY_PORT ) )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
const int port = pref_int_get( key );
|
|
|
|
tr_setBindPort( tr, port );
|
|
|
|
}
|
|
|
|
else if( !strcmp( key, PREF_KEY_DL_LIMIT_ENABLED ) )
|
|
|
|
{
|
|
|
|
const gboolean b = pref_flag_get( key );
|
|
|
|
tr_setUseGlobalSpeedLimit( tr, TR_DOWN, b );
|
|
|
|
}
|
|
|
|
else if( !strcmp( key, PREF_KEY_DL_LIMIT ) )
|
|
|
|
{
|
|
|
|
const int limit = pref_int_get( key );
|
|
|
|
tr_setGlobalSpeedLimit( tr, TR_DOWN, limit );
|
|
|
|
}
|
|
|
|
else if( !strcmp( key, PREF_KEY_UL_LIMIT_ENABLED ) )
|
|
|
|
{
|
|
|
|
const gboolean b = pref_flag_get( key );
|
|
|
|
tr_setUseGlobalSpeedLimit( tr, TR_UP, b );
|
|
|
|
}
|
|
|
|
else if( !strcmp( key, PREF_KEY_UL_LIMIT ) )
|
|
|
|
{
|
|
|
|
const int limit = pref_int_get( key );
|
|
|
|
tr_setGlobalSpeedLimit( tr, TR_UP, limit );
|
|
|
|
}
|
|
|
|
else if( !strcmp( key, PREF_KEY_NAT ) )
|
|
|
|
{
|
|
|
|
const gboolean enabled = pref_flag_get( key );
|
|
|
|
tr_natTraversalEnable( tr, enabled );
|
|
|
|
}
|
|
|
|
else if( !strcmp( key, PREF_KEY_PEX ) )
|
|
|
|
{
|
2007-12-24 05:03:40 +00:00
|
|
|
const gboolean enabled = pref_flag_get( key );
|
|
|
|
tr_setPexEnabled( tr_core_handle( cbdata->core ), enabled );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
gboolean
|
|
|
|
updatemodel(gpointer gdata) {
|
|
|
|
struct cbdata *data = gdata;
|
|
|
|
|
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-12-20 19:21:21 +00:00
|
|
|
if( data->wind )
|
|
|
|
tr_window_update( data->wind );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-06-09 15:20:32 +00:00
|
|
|
static void
|
2008-02-07 19:42:54 +00:00
|
|
|
about ( GtkWindow * parent )
|
2007-06-09 15:20:32 +00:00
|
|
|
{
|
2008-02-07 19:42:54 +00:00
|
|
|
const char *authors[] =
|
|
|
|
{
|
|
|
|
"Charles Kerr (Backend; GTK+)",
|
|
|
|
"Mitchell Livingston (Backend; OS X)",
|
|
|
|
"Eric Petit (Backend; OS X)",
|
|
|
|
"Josh Elsasser (Daemon; Backend; GTK+)",
|
|
|
|
"Bryan Varner (BeOS)",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gtk_show_about_dialog( parent,
|
|
|
|
"name", g_get_application_name(),
|
|
|
|
"comments", _("A fast and easy BitTorrent client"),
|
|
|
|
"version", LONG_VERSION_STRING,
|
|
|
|
"website", "http://www.transmissionbt.com/",
|
|
|
|
"copyright",_("Copyright 2005-2008 The Transmission Project"),
|
2008-02-07 20:02:06 +00:00
|
|
|
"logo-icon-name", "transmission",
|
2007-06-09 17:08:25 +00:00
|
|
|
#ifdef SHOW_LICENSE
|
2008-02-07 19:42:54 +00:00
|
|
|
"license", LICENSE,
|
|
|
|
"wrap-license", TRUE,
|
2007-06-09 17:08:25 +00:00
|
|
|
#endif
|
2008-02-07 19:42:54 +00:00
|
|
|
"authors", authors,
|
2008-03-08 04:53:11 +00:00
|
|
|
/* Translators: translate "translator-credits" as your name
|
|
|
|
to have it appear in the credits in the "About" dialog */
|
2008-02-07 19:42:54 +00:00
|
|
|
"translator-credits", _("translator-credits"),
|
|
|
|
NULL );
|
2007-06-09 15:20:32 +00:00
|
|
|
}
|
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
|
2007-07-30 17:11:00 +00:00
|
|
|
static void
|
|
|
|
updateTrackerForeach (GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer data UNUSED)
|
|
|
|
{
|
|
|
|
TrTorrent * tor = NULL;
|
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
|
|
|
tr_manualUpdate( tr_torrent_handle( tor ) );
|
|
|
|
g_object_unref( G_OBJECT( tor ) );
|
|
|
|
}
|
|
|
|
|
2008-01-28 22:18:43 +00:00
|
|
|
static void
|
|
|
|
detailsClosed( gpointer user_data, GObject * details )
|
|
|
|
{
|
|
|
|
struct cbdata * data = user_data;
|
|
|
|
gpointer hashString = g_hash_table_lookup( data->details2tor, details );
|
|
|
|
g_hash_table_remove( data->details2tor, details );
|
|
|
|
g_hash_table_remove( data->tor2details, hashString );
|
|
|
|
}
|
|
|
|
|
2008-04-11 02:21:33 +00:00
|
|
|
static void
|
|
|
|
openFolderForeach( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer user_data UNUSED )
|
|
|
|
{
|
|
|
|
TrTorrent * gtor = NULL;
|
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, >or, -1 );
|
|
|
|
tr_torrent_open_folder( gtor );
|
|
|
|
g_object_unref( G_OBJECT( gtor ) );
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
|
|
|
showInfoForeach (GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
2008-01-28 22:18:43 +00:00
|
|
|
gpointer user_data )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-01-28 22:18:43 +00:00
|
|
|
const char * hashString;
|
|
|
|
struct cbdata * data = user_data;
|
2007-06-18 03:40:41 +00:00
|
|
|
TrTorrent * tor = NULL;
|
|
|
|
GtkWidget * w;
|
2008-01-28 22:18:43 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
2008-01-28 22:18:43 +00:00
|
|
|
hashString = tr_torrent_info(tor)->hashString;
|
|
|
|
w = g_hash_table_lookup( data->tor2details, hashString );
|
|
|
|
if( w != NULL )
|
|
|
|
gtk_window_present( GTK_WINDOW( w ) );
|
|
|
|
else {
|
|
|
|
w = torrent_inspector_new( GTK_WINDOW( data->wind ), tor );
|
|
|
|
gtk_widget_show( w );
|
|
|
|
g_hash_table_insert( data->tor2details, (gpointer)hashString, w );
|
|
|
|
g_hash_table_insert( data->details2tor, w, (gpointer)hashString );
|
|
|
|
g_object_weak_ref( G_OBJECT( w ), detailsClosed, data );
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
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 );
|
2008-02-27 17:38:39 +00:00
|
|
|
tr_torrentVerify( 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-09-21 16:29:09 +00:00
|
|
|
static gboolean
|
2008-03-02 15:54:58 +00:00
|
|
|
msgwinclosed( void )
|
2007-09-21 16:29:09 +00:00
|
|
|
{
|
2007-11-18 02:32:46 +00:00
|
|
|
action_toggle( "toggle-message-log", FALSE );
|
2007-09-21 16:29:09 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-02 15:54:58 +00:00
|
|
|
static void
|
|
|
|
accumulateSelectedTorrents( GtkTreeModel * model,
|
|
|
|
GtkTreePath * path UNUSED,
|
|
|
|
GtkTreeIter * iter,
|
|
|
|
gpointer gdata )
|
|
|
|
{
|
2008-03-18 01:22:11 +00:00
|
|
|
GSList ** data = ( GSList** ) gdata;
|
2008-03-02 15:54:58 +00:00
|
|
|
TrTorrent * tor = NULL;
|
|
|
|
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
|
2008-03-18 01:22:11 +00:00
|
|
|
*data = g_slist_prepend( *data, tor );
|
2008-03-02 15:54:58 +00:00
|
|
|
}
|
|
|
|
|
2008-03-07 16:58:44 +00:00
|
|
|
static void
|
2008-03-07 17:47:42 +00:00
|
|
|
removeSelected( struct cbdata * data, gboolean delete_files )
|
2008-03-02 15:54:58 +00:00
|
|
|
{
|
2008-03-18 01:22:11 +00:00
|
|
|
GSList * l = NULL;
|
2008-03-02 15:54:58 +00:00
|
|
|
GtkTreeSelection * s = tr_window_get_selection( data->wind );
|
|
|
|
gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l );
|
|
|
|
gtk_tree_selection_unselect_all( s );
|
2008-03-18 01:22:11 +00:00
|
|
|
if( l ) {
|
|
|
|
l = g_slist_reverse( l );
|
2008-03-07 17:47:42 +00:00
|
|
|
confirmRemove( data->wind, data->core, l, delete_files );
|
2008-03-18 01:22:11 +00:00
|
|
|
}
|
2008-03-02 15:54:58 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
void
|
|
|
|
doAction ( const char * action_name, gpointer user_data )
|
|
|
|
{
|
2008-01-28 22:18:43 +00:00
|
|
|
struct cbdata * data = user_data;
|
2007-06-18 03:40:41 +00:00
|
|
|
gboolean changed = FALSE;
|
|
|
|
|
2008-04-03 02:11:15 +00:00
|
|
|
if ( !strcmp (action_name, "add-torrent-menu") ||
|
|
|
|
!strcmp( action_name, "add-torrent-toolbar" ))
|
2007-05-23 00:49:31 +00:00
|
|
|
{
|
2008-04-03 02:11:15 +00:00
|
|
|
addDialog( data->wind, data->core );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2007-11-27 03:29:51 +00:00
|
|
|
else if (!strcmp (action_name, "show-stats"))
|
|
|
|
{
|
|
|
|
GtkWidget * dialog = stats_dialog_create( data->wind,
|
|
|
|
data->core );
|
|
|
|
gtk_widget_show( dialog );
|
|
|
|
}
|
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;
|
|
|
|
}
|
2007-10-10 17:25:56 +00:00
|
|
|
else if (!strcmp (action_name, "pause-torrent"))
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2007-10-10 18:20:52 +00:00
|
|
|
else if (!strcmp (action_name, "verify-torrent"))
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2008-04-11 02:21:33 +00:00
|
|
|
else if (!strcmp (action_name, "open-torrent-folder"))
|
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
|
|
|
gtk_tree_selection_selected_foreach( s, openFolderForeach, data );
|
|
|
|
}
|
2007-10-10 18:52:08 +00:00
|
|
|
else if (!strcmp (action_name, "show-torrent-details"))
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
2008-01-28 22:18:43 +00:00
|
|
|
gtk_tree_selection_selected_foreach( s, showInfoForeach, data );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
2007-07-30 17:11:00 +00:00
|
|
|
else if (!strcmp( action_name, "update-tracker"))
|
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
|
|
|
gtk_tree_selection_selected_foreach( s, updateTrackerForeach, data->wind );
|
|
|
|
}
|
2008-02-03 17:10:03 +00:00
|
|
|
else if (!strcmp (action_name, "new-torrent"))
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2007-10-13 03:15:02 +00:00
|
|
|
GtkWidget * w = make_meta_ui( GTK_WINDOW( data->wind ),
|
|
|
|
tr_core_handle( data->core ) );
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_widget_show_all( w );
|
|
|
|
}
|
2008-03-07 17:47:42 +00:00
|
|
|
else if( !strcmp( action_name, "remove-torrent" ) )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-03-07 17:47:42 +00:00
|
|
|
removeSelected( data, FALSE );
|
2008-03-02 15:54:58 +00:00
|
|
|
}
|
|
|
|
else if( !strcmp( action_name, "delete-torrent" ) )
|
|
|
|
{
|
2008-03-07 17:47:42 +00:00
|
|
|
removeSelected( data, TRUE );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2007-07-30 15:51:37 +00:00
|
|
|
else if (!strcmp (action_name, "select-all"))
|
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
|
|
|
gtk_tree_selection_select_all( s );
|
|
|
|
}
|
2008-03-19 20:34:35 +00:00
|
|
|
else if (!strcmp (action_name, "deselect-all"))
|
2007-07-30 15:51:37 +00:00
|
|
|
{
|
|
|
|
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
|
|
|
gtk_tree_selection_unselect_all( s );
|
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
else if (!strcmp (action_name, "edit-preferences"))
|
|
|
|
{
|
|
|
|
if( NULL == data->prefs )
|
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
data->prefs = tr_prefs_dialog_new( G_OBJECT(data->core), data->wind );
|
2007-06-18 03:40:41 +00:00
|
|
|
g_signal_connect( data->prefs, "destroy",
|
|
|
|
G_CALLBACK( gtk_widget_destroyed ), &data->prefs );
|
|
|
|
gtk_widget_show( GTK_WIDGET( data->prefs ) );
|
|
|
|
}
|
|
|
|
}
|
2007-11-18 02:32:46 +00:00
|
|
|
else if (!strcmp (action_name, "toggle-message-log"))
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2007-09-21 16:29:09 +00:00
|
|
|
if( !data->msgwin )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-03-16 15:18:19 +00:00
|
|
|
GtkWidget * win = msgwin_new( data->core );
|
2007-09-21 16:29:09 +00:00
|
|
|
g_signal_connect( win, "destroy", G_CALLBACK( msgwinclosed ),
|
|
|
|
NULL );
|
|
|
|
data->msgwin = win;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-18 02:32:46 +00:00
|
|
|
action_toggle("toggle-message-log", FALSE);
|
2007-09-21 16:29:09 +00:00
|
|
|
gtk_widget_destroy( data->msgwin );
|
|
|
|
data->msgwin = NULL;
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "show-about-dialog"))
|
|
|
|
{
|
2008-02-07 19:42:54 +00:00
|
|
|
about( data->wind );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp (action_name, "toggle-main-window"))
|
|
|
|
{
|
2008-01-29 16:54:59 +00:00
|
|
|
toggleMainWindow( data );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
else g_error ("Unhandled action: %s", action_name );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-10-12 20:50:03 +00:00
|
|
|
if( changed )
|
2007-06-18 03:40:41 +00:00
|
|
|
updatemodel( data );
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|