1 | /****************************************************************************** |
---|
2 | * $Id: main.c 7552 2008-12-30 22:07:39Z charles $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005-2008 Transmission authors and contributors |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
7 | * copy of this software and associated documentation files (the "Software"), |
---|
8 | * to deal in the Software without restriction, including without limitation |
---|
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
10 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
11 | * Software is furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
22 | * DEALINGS IN THE SOFTWARE. |
---|
23 | *****************************************************************************/ |
---|
24 | |
---|
25 | #include <locale.h> |
---|
26 | #include <sys/param.h> |
---|
27 | #include <signal.h> |
---|
28 | #include <string.h> |
---|
29 | #include <stdio.h> |
---|
30 | #include <stdlib.h> |
---|
31 | #include <time.h> |
---|
32 | #include <unistd.h> |
---|
33 | |
---|
34 | #include <gtk/gtk.h> |
---|
35 | #include <glib/gi18n.h> |
---|
36 | #include <glib/gstdio.h> |
---|
37 | |
---|
38 | #include <gdk/gdk.h> |
---|
39 | #ifdef GDK_WINDOWING_X11 |
---|
40 | #include <X11/Xatom.h> |
---|
41 | #include <gdk/gdkx.h> |
---|
42 | #endif |
---|
43 | |
---|
44 | #include <libtransmission/transmission.h> |
---|
45 | #include <libtransmission/rpcimpl.h> |
---|
46 | #include <libtransmission/utils.h> |
---|
47 | #include <libtransmission/version.h> |
---|
48 | |
---|
49 | #include "actions.h" |
---|
50 | #include "add-dialog.h" |
---|
51 | #include "blocklist.h" |
---|
52 | #include "conf.h" |
---|
53 | #include "details.h" |
---|
54 | #include "dialogs.h" |
---|
55 | #include "hig.h" |
---|
56 | #include "makemeta-ui.h" |
---|
57 | #include "msgwin.h" |
---|
58 | #include "notify.h" |
---|
59 | #include "stats.h" |
---|
60 | #include "tr-core.h" |
---|
61 | #include "tr-icon.h" |
---|
62 | #include "tr-prefs.h" |
---|
63 | #include "tr-torrent.h" |
---|
64 | #include "tr-window.h" |
---|
65 | #include "util.h" |
---|
66 | #include "ui.h" |
---|
67 | |
---|
68 | #include <libtransmission/transmission.h> |
---|
69 | #include <libtransmission/version.h> |
---|
70 | |
---|
71 | #define MY_NAME "transmission" |
---|
72 | |
---|
73 | /* interval in milliseconds to update the torrent list display */ |
---|
74 | #define UPDATE_INTERVAL 1666 |
---|
75 | |
---|
76 | /* interval in milliseconds to check for stopped torrents and update display */ |
---|
77 | #define EXIT_CHECK_INTERVAL 500 |
---|
78 | |
---|
79 | #if GTK_CHECK_VERSION( 2, 8, 0 ) |
---|
80 | #define SHOW_LICENSE |
---|
81 | static const char * LICENSE = |
---|
82 | "The Transmission binaries and most of its source code is distributed " |
---|
83 | "license. " |
---|
84 | "\n\n" |
---|
85 | "Some files are copyrighted by Charles Kerr and are covered by " |
---|
86 | "the GPL version 2. Works owned by the Transmission project " |
---|
87 | "are granted a special exemption to clause 2(b) so that the bulk " |
---|
88 | "of its code can remain under the MIT license. This exemption does " |
---|
89 | "not extend to original or derived works not owned by the " |
---|
90 | "Transmission project. " |
---|
91 | "\n\n" |
---|
92 | "Permission is hereby granted, free of charge, to any person obtaining " |
---|
93 | "a copy of this software and associated documentation files (the " |
---|
94 | "'Software'), to deal in the Software without restriction, including " |
---|
95 | "without limitation the rights to use, copy, modify, merge, publish, " |
---|
96 | "distribute, sublicense, and/or sell copies of the Software, and to " |
---|
97 | "permit persons to whom the Software is furnished to do so, subject to " |
---|
98 | "the following conditions: " |
---|
99 | "\n\n" |
---|
100 | "The above copyright notice and this permission notice shall be included " |
---|
101 | "in all copies or substantial portions of the Software. " |
---|
102 | "\n\n" |
---|
103 | "THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, " |
---|
104 | "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " |
---|
105 | "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. " |
---|
106 | "IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY " |
---|
107 | "CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " |
---|
108 | "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE " |
---|
109 | "SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."; |
---|
110 | #endif |
---|
111 | |
---|
112 | struct cbdata |
---|
113 | { |
---|
114 | unsigned int isIconified : 1; |
---|
115 | unsigned int isClosing : 1; |
---|
116 | guint timer; |
---|
117 | gpointer icon; |
---|
118 | GtkWindow * wind; |
---|
119 | TrCore * core; |
---|
120 | GtkWidget * msgwin; |
---|
121 | GtkWidget * prefs; |
---|
122 | GSList * errqueue; |
---|
123 | GSList * dupqueue; |
---|
124 | GHashTable * tor2details; |
---|
125 | GHashTable * details2tor; |
---|
126 | GtkTreeSelection * sel; |
---|
127 | }; |
---|
128 | |
---|
129 | #define CBDATA_PTR "callback-data-pointer" |
---|
130 | |
---|
131 | static GtkUIManager * myUIManager = NULL; |
---|
132 | |
---|
133 | static void appsetup( TrWindow * wind, |
---|
134 | GSList * args, |
---|
135 | struct cbdata *, |
---|
136 | gboolean paused, |
---|
137 | gboolean minimized ); |
---|
138 | |
---|
139 | static void winsetup( struct cbdata * cbdata, |
---|
140 | TrWindow * wind ); |
---|
141 | |
---|
142 | static void wannaquit( void * vdata ); |
---|
143 | |
---|
144 | static void setupdrag( GtkWidget * widget, |
---|
145 | struct cbdata *data ); |
---|
146 | |
---|
147 | static void gotdrag( GtkWidget * widget, |
---|
148 | GdkDragContext * dc, |
---|
149 | gint x, |
---|
150 | gint y, |
---|
151 | GtkSelectionData *sel, |
---|
152 | guint info, |
---|
153 | guint time, |
---|
154 | gpointer gdata ); |
---|
155 | |
---|
156 | static void coreerr( TrCore * core, |
---|
157 | enum tr_core_err code, |
---|
158 | const char * msg, |
---|
159 | gpointer gdata ); |
---|
160 | |
---|
161 | static void onAddTorrent( TrCore *, |
---|
162 | tr_ctor *, |
---|
163 | gpointer ); |
---|
164 | |
---|
165 | static void prefschanged( TrCore * core, |
---|
166 | const char * key, |
---|
167 | gpointer data ); |
---|
168 | |
---|
169 | static gboolean updatemodel( gpointer gdata ); |
---|
170 | |
---|
171 | struct counts_data |
---|
172 | { |
---|
173 | int totalCount; |
---|
174 | int activeCount; |
---|
175 | int inactiveCount; |
---|
176 | }; |
---|
177 | |
---|
178 | static void |
---|
179 | accumulateStatusForeach( GtkTreeModel * model, |
---|
180 | GtkTreePath * path UNUSED, |
---|
181 | GtkTreeIter * iter, |
---|
182 | gpointer user_data ) |
---|
183 | { |
---|
184 | int activity = 0; |
---|
185 | struct counts_data * counts = user_data; |
---|
186 | |
---|
187 | ++counts->totalCount; |
---|
188 | |
---|
189 | gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 ); |
---|
190 | |
---|
191 | if( TR_STATUS_IS_ACTIVE( activity ) ) |
---|
192 | ++counts->activeCount; |
---|
193 | else |
---|
194 | ++counts->inactiveCount; |
---|
195 | } |
---|
196 | |
---|
197 | static void |
---|
198 | accumulateCanUpdateForeach( GtkTreeModel * model, |
---|
199 | GtkTreePath * path UNUSED, |
---|
200 | GtkTreeIter * iter, |
---|
201 | gpointer accumulated_status ) |
---|
202 | { |
---|
203 | tr_torrent * tor; |
---|
204 | gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 ); |
---|
205 | *(int*)accumulated_status |= tr_torrentCanManualUpdate( tor ); |
---|
206 | } |
---|
207 | |
---|
208 | static void |
---|
209 | refreshTorrentActions( struct cbdata * data ) |
---|
210 | { |
---|
211 | int canUpdate; |
---|
212 | struct counts_data counts; |
---|
213 | GtkTreeSelection * s = data->sel; |
---|
214 | |
---|
215 | counts.activeCount = 0; |
---|
216 | counts.inactiveCount = 0; |
---|
217 | counts.totalCount = 0; |
---|
218 | gtk_tree_selection_selected_foreach( s, accumulateStatusForeach, &counts ); |
---|
219 | action_sensitize( "pause-torrent", counts.activeCount != 0 ); |
---|
220 | action_sensitize( "start-torrent", counts.inactiveCount != 0 ); |
---|
221 | action_sensitize( "remove-torrent", counts.totalCount != 0 ); |
---|
222 | action_sensitize( "delete-torrent", counts.totalCount != 0 ); |
---|
223 | action_sensitize( "verify-torrent", counts.totalCount != 0 ); |
---|
224 | action_sensitize( "open-torrent-folder", counts.totalCount == 1 ); |
---|
225 | action_sensitize( "show-torrent-properties", counts.totalCount == 1 ); |
---|
226 | |
---|
227 | canUpdate = 0; |
---|
228 | gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach, &canUpdate ); |
---|
229 | action_sensitize( "update-tracker", canUpdate != 0 ); |
---|
230 | |
---|
231 | { |
---|
232 | GtkTreeView * view = gtk_tree_selection_get_tree_view( s ); |
---|
233 | GtkTreeModel * model = gtk_tree_view_get_model( view ); |
---|
234 | const int torrentCount = gtk_tree_model_iter_n_children( model, NULL ) != 0; |
---|
235 | action_sensitize( "select-all", torrentCount != 0 ); |
---|
236 | action_sensitize( "deselect-all", torrentCount != 0 ); |
---|
237 | } |
---|
238 | |
---|
239 | { |
---|
240 | tr_torrent * tor = NULL; |
---|
241 | tr_session * session = tr_core_session( data->core ); |
---|
242 | int activeCount = 0; |
---|
243 | while(( tor = tr_torrentNext( session, tor ))) |
---|
244 | if( TR_STATUS_IS_ACTIVE( tr_torrentGetActivity( tor ))) |
---|
245 | ++activeCount; |
---|
246 | action_sensitize( "pause-all-torrents", activeCount != 0 ); |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | static void |
---|
251 | selectionChangedCB( GtkTreeSelection * s UNUSED, gpointer data ) |
---|
252 | { |
---|
253 | refreshTorrentActions( data ); |
---|
254 | } |
---|
255 | |
---|
256 | static void |
---|
257 | onMainWindowSizeAllocated( GtkWidget * window, |
---|
258 | GtkAllocation * alloc UNUSED, |
---|
259 | gpointer gdata UNUSED ) |
---|
260 | { |
---|
261 | const gboolean isMaximized = window->window |
---|
262 | && ( gdk_window_get_state( window->window ) |
---|
263 | & GDK_WINDOW_STATE_MAXIMIZED ); |
---|
264 | |
---|
265 | if( !isMaximized ) |
---|
266 | { |
---|
267 | int x, y, w, h; |
---|
268 | gtk_window_get_position( GTK_WINDOW( window ), &x, &y ); |
---|
269 | gtk_window_get_size( GTK_WINDOW( window ), &w, &h ); |
---|
270 | pref_int_set( PREF_KEY_MAIN_WINDOW_X, x ); |
---|
271 | pref_int_set( PREF_KEY_MAIN_WINDOW_Y, y ); |
---|
272 | pref_int_set( PREF_KEY_MAIN_WINDOW_WIDTH, w ); |
---|
273 | pref_int_set( PREF_KEY_MAIN_WINDOW_HEIGHT, h ); |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | static sig_atomic_t global_sigcount = 0; |
---|
278 | |
---|
279 | static void |
---|
280 | fatalsig( int sig ) |
---|
281 | { |
---|
282 | /* revert to default handler after this many */ |
---|
283 | static const int SIGCOUNT_MAX = 3; |
---|
284 | |
---|
285 | if( ++global_sigcount >= SIGCOUNT_MAX ) |
---|
286 | { |
---|
287 | signal( sig, SIG_DFL ); |
---|
288 | raise( sig ); |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | static void |
---|
293 | setupsighandlers( void ) |
---|
294 | { |
---|
295 | #ifdef G_OS_WIN32 |
---|
296 | const int sigs[] = { SIGINT, SIGTERM }; |
---|
297 | #else |
---|
298 | const int sigs[] = { SIGHUP, SIGINT, SIGQUIT, SIGTERM }; |
---|
299 | #endif |
---|
300 | guint i; |
---|
301 | |
---|
302 | for( i = 0; i < G_N_ELEMENTS( sigs ); ++i ) |
---|
303 | signal( sigs[i], fatalsig ); |
---|
304 | } |
---|
305 | |
---|
306 | static tr_rpc_callback_status |
---|
307 | onRPCChanged( tr_session * session UNUSED, |
---|
308 | tr_rpc_callback_type type, |
---|
309 | struct tr_torrent * tor, |
---|
310 | void * gdata ) |
---|
311 | { |
---|
312 | struct cbdata * cbdata = gdata; |
---|
313 | gdk_threads_enter( ); |
---|
314 | |
---|
315 | switch( type ) |
---|
316 | { |
---|
317 | case TR_RPC_TORRENT_ADDED: |
---|
318 | tr_core_add_torrent( cbdata->core, |
---|
319 | tr_torrent_new_preexisting( tor ) ); |
---|
320 | break; |
---|
321 | |
---|
322 | case TR_RPC_TORRENT_STARTED: |
---|
323 | /* this should be automatic */ |
---|
324 | break; |
---|
325 | |
---|
326 | case TR_RPC_TORRENT_STOPPED: |
---|
327 | /* this should be automatic */ |
---|
328 | break; |
---|
329 | |
---|
330 | case TR_RPC_TORRENT_REMOVING: |
---|
331 | tr_core_torrent_destroyed( cbdata->core, tr_torrentId( tor ) ); |
---|
332 | break; |
---|
333 | |
---|
334 | case TR_RPC_TORRENT_CHANGED: |
---|
335 | case TR_RPC_SESSION_CHANGED: |
---|
336 | /* nothing interesting to do here */ |
---|
337 | break; |
---|
338 | } |
---|
339 | |
---|
340 | gdk_threads_leave( ); |
---|
341 | return TR_RPC_OK; |
---|
342 | } |
---|
343 | |
---|
344 | int |
---|
345 | main( int argc, |
---|
346 | char ** argv ) |
---|
347 | { |
---|
348 | char * err = NULL; |
---|
349 | struct cbdata * cbdata; |
---|
350 | GSList * argfiles; |
---|
351 | GError * gerr; |
---|
352 | gboolean didinit = FALSE; |
---|
353 | gboolean didlock = FALSE; |
---|
354 | gboolean showversion = FALSE; |
---|
355 | gboolean startpaused = FALSE; |
---|
356 | gboolean startminimized = FALSE; |
---|
357 | char * domain = MY_NAME; |
---|
358 | char * configDir = NULL; |
---|
359 | tr_lockfile_state_t tr_state; |
---|
360 | |
---|
361 | GOptionEntry entries[] = { |
---|
362 | { "paused", 'p', 0, G_OPTION_ARG_NONE, |
---|
363 | &startpaused, _( "Start with all torrents paused" ), NULL }, |
---|
364 | { "version", '\0', 0, G_OPTION_ARG_NONE, |
---|
365 | &showversion, _( "Show version number and exit" ), NULL }, |
---|
366 | #ifdef STATUS_ICON_SUPPORTED |
---|
367 | { "minimized", 'm', 0, G_OPTION_ARG_NONE, |
---|
368 | &startminimized, |
---|
369 | _( "Start minimized in system tray" ), NULL }, |
---|
370 | #endif |
---|
371 | { "config-dir", 'g', 0, G_OPTION_ARG_FILENAME, &configDir, |
---|
372 | _( "Where to look for configuration files" ), NULL }, |
---|
373 | { NULL, 0, 0, 0, NULL, NULL, NULL } |
---|
374 | }; |
---|
375 | |
---|
376 | cbdata = g_new0( struct cbdata, 1 ); |
---|
377 | cbdata->tor2details = g_hash_table_new( g_str_hash, g_str_equal ); |
---|
378 | cbdata->details2tor = g_hash_table_new( g_direct_hash, g_direct_equal ); |
---|
379 | |
---|
380 | /* bind the gettext domain */ |
---|
381 | setlocale( LC_ALL, "" ); |
---|
382 | bindtextdomain( domain, TRANSMISSIONLOCALEDIR ); |
---|
383 | bind_textdomain_codeset( domain, "UTF-8" ); |
---|
384 | textdomain( domain ); |
---|
385 | g_set_application_name( _( "Transmission" ) ); |
---|
386 | |
---|
387 | /* initialize gtk */ |
---|
388 | if( !g_thread_supported( ) ) |
---|
389 | g_thread_init( NULL ); |
---|
390 | |
---|
391 | gerr = NULL; |
---|
392 | if( !gtk_init_with_args( &argc, &argv, _( "[torrent files]" ), entries, |
---|
393 | domain, &gerr ) ) |
---|
394 | { |
---|
395 | fprintf( stderr, "%s\n", gerr->message ); |
---|
396 | g_clear_error( &gerr ); |
---|
397 | return 0; |
---|
398 | } |
---|
399 | |
---|
400 | if( showversion ) |
---|
401 | { |
---|
402 | fprintf( stderr, "%s %s\n", g_get_application_name( ), LONG_VERSION_STRING ); |
---|
403 | return 0; |
---|
404 | } |
---|
405 | |
---|
406 | if( configDir == NULL ) |
---|
407 | configDir = (char*) tr_getDefaultConfigDir( MY_NAME ); |
---|
408 | |
---|
409 | tr_notify_init( ); |
---|
410 | didinit = cf_init( configDir, NULL ); /* must come before actions_init */ |
---|
411 | tr_prefs_init_global( ); |
---|
412 | |
---|
413 | myUIManager = gtk_ui_manager_new ( ); |
---|
414 | actions_init ( myUIManager, cbdata ); |
---|
415 | gtk_ui_manager_add_ui_from_string ( myUIManager, fallback_ui_file, -1, NULL ); |
---|
416 | gtk_ui_manager_ensure_update ( myUIManager ); |
---|
417 | gtk_window_set_default_icon_name ( MY_NAME ); |
---|
418 | |
---|
419 | setupsighandlers( ); /* set up handlers for fatal signals */ |
---|
420 | |
---|
421 | /* either get a lockfile s.t. this is the one instance of |
---|
422 | * transmission that's running, OR if there are files to |
---|
423 | * be added, delegate that to the running instance via dbus */ |
---|
424 | didlock = cf_lock( &tr_state, &err ); |
---|
425 | argfiles = checkfilenames( argc - 1, argv + 1 ); |
---|
426 | if( !didlock && argfiles ) |
---|
427 | { |
---|
428 | GSList * l; |
---|
429 | gboolean delegated = FALSE; |
---|
430 | for( l = argfiles; l; l = l->next ) |
---|
431 | delegated |= gtr_dbus_add_torrent( l->data ); |
---|
432 | if( delegated ) |
---|
433 | err = NULL; |
---|
434 | } |
---|
435 | else if( ( !didlock ) && ( tr_state == TR_LOCKFILE_ELOCK ) ) |
---|
436 | { |
---|
437 | gtr_dbus_present_window( ); |
---|
438 | err = NULL; |
---|
439 | } |
---|
440 | |
---|
441 | if( didlock && ( didinit || cf_init( configDir, &err ) ) ) |
---|
442 | { |
---|
443 | GtkWindow * win; |
---|
444 | tr_session * session; |
---|
445 | |
---|
446 | /* initialize the libtransmission session */ |
---|
447 | session = tr_sessionInit( "gtk", configDir, TRUE, pref_get_all( ) ); |
---|
448 | cbdata->core = tr_core_new( session ); |
---|
449 | |
---|
450 | /* create main window now to be a parent to any error dialogs */ |
---|
451 | win = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) ); |
---|
452 | g_signal_connect( win, "size-allocate", G_CALLBACK( onMainWindowSizeAllocated ), cbdata ); |
---|
453 | |
---|
454 | appsetup( win, argfiles, cbdata, startpaused, startminimized ); |
---|
455 | tr_sessionSetRPCCallback( session, onRPCChanged, cbdata ); |
---|
456 | gtr_blocklist_maybe_autoupdate( cbdata->core ); |
---|
457 | |
---|
458 | gtk_main( ); |
---|
459 | } |
---|
460 | else if( err ) |
---|
461 | { |
---|
462 | gtk_widget_show( errmsg_full( NULL, (callbackfunc_t)gtk_main_quit, |
---|
463 | NULL, "%s", err ) ); |
---|
464 | g_free( err ); |
---|
465 | gtk_main( ); |
---|
466 | } |
---|
467 | |
---|
468 | return 0; |
---|
469 | } |
---|
470 | |
---|
471 | static gboolean |
---|
472 | updateScheduledLimits( gpointer data ) |
---|
473 | { |
---|
474 | tr_session * tr = data; |
---|
475 | static gboolean last_state = FALSE; |
---|
476 | gboolean in_sched_state = FALSE; |
---|
477 | |
---|
478 | if( !pref_flag_get( PREF_KEY_SCHED_LIMIT_ENABLED ) ) |
---|
479 | { |
---|
480 | in_sched_state = FALSE; |
---|
481 | } |
---|
482 | else |
---|
483 | { |
---|
484 | const int begin_time = pref_int_get( PREF_KEY_SCHED_BEGIN ); |
---|
485 | const int end_time = pref_int_get( PREF_KEY_SCHED_END ); |
---|
486 | time_t t; |
---|
487 | struct tm *tm; |
---|
488 | int cur_time; |
---|
489 | |
---|
490 | time( &t ); |
---|
491 | tm = localtime ( &t ); |
---|
492 | cur_time = ( tm->tm_hour * 60 ) + tm->tm_min; |
---|
493 | |
---|
494 | if( end_time >= begin_time ) |
---|
495 | { |
---|
496 | if( ( cur_time >= begin_time ) && ( cur_time <= end_time ) ) |
---|
497 | in_sched_state = TRUE; |
---|
498 | } |
---|
499 | else |
---|
500 | { |
---|
501 | if( ( cur_time >= begin_time ) || ( cur_time <= end_time ) ) |
---|
502 | in_sched_state = TRUE; |
---|
503 | } |
---|
504 | } |
---|
505 | |
---|
506 | if( last_state != in_sched_state ) |
---|
507 | { |
---|
508 | if( in_sched_state ) |
---|
509 | { |
---|
510 | int limit; |
---|
511 | |
---|
512 | tr_inf ( _( "Beginning to use scheduled bandwidth limits" ) ); |
---|
513 | |
---|
514 | tr_sessionSetSpeedLimitEnabled( tr, TR_DOWN, TRUE ); |
---|
515 | limit = pref_int_get( PREF_KEY_SCHED_DL_LIMIT ); |
---|
516 | tr_sessionSetSpeedLimit( tr, TR_DOWN, limit ); |
---|
517 | tr_sessionSetSpeedLimitEnabled( tr, TR_UP, TRUE ); |
---|
518 | limit = pref_int_get( PREF_KEY_SCHED_UL_LIMIT ); |
---|
519 | tr_sessionSetSpeedLimit( tr, TR_UP, limit ); |
---|
520 | } |
---|
521 | else |
---|
522 | { |
---|
523 | gboolean b; |
---|
524 | int limit; |
---|
525 | |
---|
526 | tr_inf ( _( "Ending use of scheduled bandwidth limits" ) ); |
---|
527 | |
---|
528 | b = pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED ); |
---|
529 | tr_sessionSetSpeedLimitEnabled( tr, TR_DOWN, b ); |
---|
530 | limit = pref_int_get( TR_PREFS_KEY_DSPEED ); |
---|
531 | tr_sessionSetSpeedLimit( tr, TR_DOWN, limit ); |
---|
532 | b = pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED ); |
---|
533 | tr_sessionSetSpeedLimitEnabled( tr, TR_UP, b ); |
---|
534 | limit = pref_int_get( TR_PREFS_KEY_USPEED ); |
---|
535 | tr_sessionSetSpeedLimit( tr, TR_UP, limit ); |
---|
536 | } |
---|
537 | |
---|
538 | last_state = in_sched_state; |
---|
539 | } |
---|
540 | else if( in_sched_state ) |
---|
541 | { |
---|
542 | static int old_dl_limit = 0, old_ul_limit = 0; |
---|
543 | int dl_limit = pref_int_get( PREF_KEY_SCHED_DL_LIMIT ); |
---|
544 | int ul_limit = pref_int_get( PREF_KEY_SCHED_UL_LIMIT ); |
---|
545 | |
---|
546 | if( ( dl_limit != old_dl_limit ) || ( ul_limit != old_ul_limit ) ) |
---|
547 | { |
---|
548 | tr_sessionSetSpeedLimitEnabled( tr, TR_DOWN, TRUE ); |
---|
549 | tr_sessionSetSpeedLimit( tr, TR_DOWN, dl_limit ); |
---|
550 | tr_sessionSetSpeedLimitEnabled( tr, TR_UP, TRUE ); |
---|
551 | tr_sessionSetSpeedLimit( tr, TR_UP, ul_limit ); |
---|
552 | |
---|
553 | old_dl_limit = dl_limit; |
---|
554 | old_ul_limit = ul_limit; |
---|
555 | } |
---|
556 | } |
---|
557 | |
---|
558 | return TRUE; |
---|
559 | } |
---|
560 | |
---|
561 | static void |
---|
562 | appsetup( TrWindow * wind, |
---|
563 | GSList * torrentFiles, |
---|
564 | struct cbdata * cbdata, |
---|
565 | gboolean forcepause, |
---|
566 | gboolean isIconified ) |
---|
567 | { |
---|
568 | const pref_flag_t start = |
---|
569 | forcepause ? PREF_FLAG_FALSE : PREF_FLAG_DEFAULT; |
---|
570 | const pref_flag_t prompt = PREF_FLAG_DEFAULT; |
---|
571 | |
---|
572 | /* fill out cbdata */ |
---|
573 | cbdata->wind = NULL; |
---|
574 | cbdata->icon = NULL; |
---|
575 | cbdata->msgwin = NULL; |
---|
576 | cbdata->prefs = NULL; |
---|
577 | cbdata->timer = 0; |
---|
578 | cbdata->isClosing = 0; |
---|
579 | cbdata->errqueue = NULL; |
---|
580 | cbdata->dupqueue = NULL; |
---|
581 | cbdata->isIconified = isIconified; |
---|
582 | |
---|
583 | if( isIconified ) |
---|
584 | pref_flag_set( PREF_KEY_SHOW_TRAY_ICON, TRUE ); |
---|
585 | |
---|
586 | actions_set_core( cbdata->core ); |
---|
587 | |
---|
588 | /* set up core handlers */ |
---|
589 | g_signal_connect( cbdata->core, "error", G_CALLBACK( coreerr ), cbdata ); |
---|
590 | g_signal_connect( cbdata->core, "add-torrent-prompt", |
---|
591 | G_CALLBACK( onAddTorrent ), cbdata ); |
---|
592 | g_signal_connect_swapped( cbdata->core, "quit", |
---|
593 | G_CALLBACK( wannaquit ), cbdata ); |
---|
594 | g_signal_connect( cbdata->core, "prefs-changed", |
---|
595 | G_CALLBACK( prefschanged ), cbdata ); |
---|
596 | |
---|
597 | /* add torrents from command-line and saved state */ |
---|
598 | tr_core_load( cbdata->core, forcepause ); |
---|
599 | tr_core_add_list( cbdata->core, torrentFiles, start, prompt ); |
---|
600 | torrentFiles = NULL; |
---|
601 | tr_core_torrents_added( cbdata->core ); |
---|
602 | |
---|
603 | /* set up main window */ |
---|
604 | winsetup( cbdata, wind ); |
---|
605 | |
---|
606 | /* set up the icon */ |
---|
607 | prefschanged( cbdata->core, PREF_KEY_SHOW_TRAY_ICON, cbdata ); |
---|
608 | |
---|
609 | /* start model update timer */ |
---|
610 | cbdata->timer = g_timeout_add( UPDATE_INTERVAL, updatemodel, cbdata ); |
---|
611 | updatemodel( cbdata ); |
---|
612 | |
---|
613 | /* start scheduled rate timer */ |
---|
614 | updateScheduledLimits ( tr_core_session( cbdata->core ) ); |
---|
615 | gtr_timeout_add_seconds( 60, updateScheduledLimits, tr_core_session( cbdata->core ) ); |
---|
616 | |
---|
617 | /* either show the window or iconify it */ |
---|
618 | if( !isIconified ) |
---|
619 | gtk_widget_show( GTK_WIDGET( wind ) ); |
---|
620 | else |
---|
621 | { |
---|
622 | gtk_window_iconify( wind ); |
---|
623 | gtk_window_set_skip_taskbar_hint( cbdata->wind, |
---|
624 | cbdata->icon != NULL ); |
---|
625 | } |
---|
626 | } |
---|
627 | |
---|
628 | static void |
---|
629 | tr_window_present( GtkWindow * window ) |
---|
630 | { |
---|
631 | #if GTK_CHECK_VERSION( 2, 8, 0 ) |
---|
632 | gtk_window_present_with_time( window, gtk_get_current_event_time( ) ); |
---|
633 | #else |
---|
634 | gtk_window_present( window ); |
---|
635 | #endif |
---|
636 | } |
---|
637 | |
---|
638 | static void |
---|
639 | toggleMainWindow( struct cbdata * cbdata, |
---|
640 | gboolean doPresent ) |
---|
641 | { |
---|
642 | GtkWindow * window = GTK_WINDOW( cbdata->wind ); |
---|
643 | const int doShow = cbdata->isIconified; |
---|
644 | static int x = 0; |
---|
645 | static int y = 0; |
---|
646 | |
---|
647 | if( doShow || doPresent ) |
---|
648 | { |
---|
649 | cbdata->isIconified = 0; |
---|
650 | gtk_window_set_skip_taskbar_hint( window, FALSE ); |
---|
651 | gtk_window_move( window, x, y ); |
---|
652 | gtk_widget_show( GTK_WIDGET( window ) ); |
---|
653 | tr_window_present( window ); |
---|
654 | } |
---|
655 | else |
---|
656 | { |
---|
657 | gtk_window_get_position( window, &x, &y ); |
---|
658 | gtk_window_set_skip_taskbar_hint( window, TRUE ); |
---|
659 | gtk_widget_hide( GTK_WIDGET( window ) ); |
---|
660 | cbdata->isIconified = 1; |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | static gboolean |
---|
665 | winclose( GtkWidget * w UNUSED, |
---|
666 | GdkEvent * event UNUSED, |
---|
667 | gpointer gdata ) |
---|
668 | { |
---|
669 | struct cbdata * cbdata = gdata; |
---|
670 | |
---|
671 | if( cbdata->icon != NULL ) |
---|
672 | action_activate ( "toggle-main-window" ); |
---|
673 | else |
---|
674 | askquit( cbdata->core, cbdata->wind, wannaquit, cbdata ); |
---|
675 | |
---|
676 | return TRUE; /* don't propagate event further */ |
---|
677 | } |
---|
678 | |
---|
679 | static void |
---|
680 | rowChangedCB( GtkTreeModel * model UNUSED, |
---|
681 | GtkTreePath * path, |
---|
682 | GtkTreeIter * iter UNUSED, |
---|
683 | gpointer gdata ) |
---|
684 | { |
---|
685 | struct cbdata * data = gdata; |
---|
686 | if( gtk_tree_selection_path_is_selected ( data->sel, path ) ) |
---|
687 | refreshTorrentActions( gdata ); |
---|
688 | } |
---|
689 | |
---|
690 | static void |
---|
691 | winsetup( struct cbdata * cbdata, |
---|
692 | TrWindow * wind ) |
---|
693 | { |
---|
694 | GtkTreeModel * model; |
---|
695 | GtkTreeSelection * sel; |
---|
696 | |
---|
697 | g_assert( NULL == cbdata->wind ); |
---|
698 | cbdata->wind = GTK_WINDOW( wind ); |
---|
699 | cbdata->sel = sel = GTK_TREE_SELECTION( tr_window_get_selection( cbdata->wind ) ); |
---|
700 | |
---|
701 | g_signal_connect( sel, "changed", G_CALLBACK( selectionChangedCB ), cbdata ); |
---|
702 | selectionChangedCB( sel, cbdata ); |
---|
703 | model = tr_core_model( cbdata->core ); |
---|
704 | g_signal_connect( model, "row-changed", G_CALLBACK( rowChangedCB ), cbdata ); |
---|
705 | g_signal_connect( wind, "delete-event", G_CALLBACK( winclose ), cbdata ); |
---|
706 | refreshTorrentActions( cbdata ); |
---|
707 | |
---|
708 | setupdrag( GTK_WIDGET( wind ), cbdata ); |
---|
709 | } |
---|
710 | |
---|
711 | static gpointer |
---|
712 | quitThreadFunc( gpointer gdata ) |
---|
713 | { |
---|
714 | struct cbdata * cbdata = gdata; |
---|
715 | |
---|
716 | tr_core_close( cbdata->core ); |
---|
717 | |
---|
718 | /* shutdown the gui */ |
---|
719 | if( cbdata->prefs ) |
---|
720 | gtk_widget_destroy( GTK_WIDGET( cbdata->prefs ) ); |
---|
721 | if( cbdata->wind ) |
---|
722 | gtk_widget_destroy( GTK_WIDGET( cbdata->wind ) ); |
---|
723 | g_object_unref( cbdata->core ); |
---|
724 | if( cbdata->icon ) |
---|
725 | g_object_unref( cbdata->icon ); |
---|
726 | if( cbdata->errqueue ) |
---|
727 | { |
---|
728 | g_slist_foreach( cbdata->errqueue, (GFunc)g_free, NULL ); |
---|
729 | g_slist_free( cbdata->errqueue ); |
---|
730 | } |
---|
731 | if( cbdata->dupqueue ) |
---|
732 | { |
---|
733 | g_slist_foreach( cbdata->dupqueue, (GFunc)g_free, NULL ); |
---|
734 | g_slist_free( cbdata->dupqueue ); |
---|
735 | } |
---|
736 | |
---|
737 | g_hash_table_destroy( cbdata->details2tor ); |
---|
738 | g_hash_table_destroy( cbdata->tor2details ); |
---|
739 | g_free( cbdata ); |
---|
740 | |
---|
741 | /* exit the gtk main loop */ |
---|
742 | gtk_main_quit( ); |
---|
743 | return NULL; |
---|
744 | } |
---|
745 | |
---|
746 | static void |
---|
747 | do_exit_cb( GtkWidget *w UNUSED, |
---|
748 | gpointer data UNUSED ) |
---|
749 | { |
---|
750 | exit( 0 ); |
---|
751 | } |
---|
752 | |
---|
753 | static void |
---|
754 | wannaquit( void * vdata ) |
---|
755 | { |
---|
756 | GtkWidget * r, * p, * b, * w, *c; |
---|
757 | struct cbdata * cbdata = vdata; |
---|
758 | |
---|
759 | /* stop the update timer */ |
---|
760 | if( cbdata->timer ) |
---|
761 | { |
---|
762 | g_source_remove( cbdata->timer ); |
---|
763 | cbdata->timer = 0; |
---|
764 | } |
---|
765 | |
---|
766 | c = GTK_WIDGET( cbdata->wind ); |
---|
767 | gtk_container_remove( GTK_CONTAINER( c ), gtk_bin_get_child( GTK_BIN( c ) ) ); |
---|
768 | |
---|
769 | r = gtk_alignment_new( 0.5, 0.5, 0.01, 0.01 ); |
---|
770 | gtk_container_add( GTK_CONTAINER( c ), r ); |
---|
771 | |
---|
772 | p = gtk_table_new( 3, 2, FALSE ); |
---|
773 | gtk_table_set_col_spacings( GTK_TABLE( p ), GUI_PAD_BIG ); |
---|
774 | gtk_container_add( GTK_CONTAINER( r ), p ); |
---|
775 | |
---|
776 | w = gtk_image_new_from_stock( GTK_STOCK_NETWORK, GTK_ICON_SIZE_DIALOG ); |
---|
777 | gtk_table_attach_defaults( GTK_TABLE( p ), w, 0, 1, 0, 2 ); |
---|
778 | |
---|
779 | w = gtk_label_new( NULL ); |
---|
780 | gtk_label_set_markup( GTK_LABEL( w ), _( "<b>Closing Connections</b>" ) ); |
---|
781 | gtk_misc_set_alignment( GTK_MISC( w ), 0.0, 0.5 ); |
---|
782 | gtk_table_attach_defaults( GTK_TABLE( p ), w, 1, 2, 0, 1 ); |
---|
783 | |
---|
784 | w = gtk_label_new( _( "Sending upload/download totals to tracker..." ) ); |
---|
785 | gtk_misc_set_alignment( GTK_MISC( w ), 0.0, 0.5 ); |
---|
786 | gtk_table_attach_defaults( GTK_TABLE( p ), w, 1, 2, 1, 2 ); |
---|
787 | |
---|
788 | b = gtk_alignment_new( 0.0, 1.0, 0.01, 0.01 ); |
---|
789 | w = gtr_button_new_from_stock( GTK_STOCK_QUIT, _( "_Quit Now" ) ); |
---|
790 | g_signal_connect( w, "clicked", G_CALLBACK( do_exit_cb ), NULL ); |
---|
791 | gtk_container_add( GTK_CONTAINER( b ), w ); |
---|
792 | gtk_table_attach( GTK_TABLE( |
---|
793 | p ), b, 1, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 10 ); |
---|
794 | |
---|
795 | gtk_widget_show_all( r ); |
---|
796 | |
---|
797 | /* clear the UI */ |
---|
798 | gtk_list_store_clear( GTK_LIST_STORE( tr_core_model( cbdata->core ) ) ); |
---|
799 | |
---|
800 | /* shut down libT */ |
---|
801 | g_thread_create( quitThreadFunc, vdata, TRUE, NULL ); |
---|
802 | } |
---|
803 | |
---|
804 | static void |
---|
805 | gotdrag( GtkWidget * widget UNUSED, |
---|
806 | GdkDragContext * dc, |
---|
807 | gint x UNUSED, |
---|
808 | gint y UNUSED, |
---|
809 | GtkSelectionData * sel, |
---|
810 | guint info UNUSED, |
---|
811 | guint time, |
---|
812 | gpointer gdata ) |
---|
813 | { |
---|
814 | struct cbdata * data = gdata; |
---|
815 | GSList * paths = NULL; |
---|
816 | GSList * freeme = NULL; |
---|
817 | |
---|
818 | #if 0 |
---|
819 | int i; |
---|
820 | char * sele = gdk_atom_name( sel->selection ); |
---|
821 | char * targ = gdk_atom_name( sel->target ); |
---|
822 | char * type = gdk_atom_name( sel->type ); |
---|
823 | |
---|
824 | g_message( "dropped file: sel=%s targ=%s type=%s fmt=%i len=%i", |
---|
825 | sele, targ, type, sel->format, sel->length ); |
---|
826 | g_free( sele ); |
---|
827 | g_free( targ ); |
---|
828 | g_free( type ); |
---|
829 | if( sel->format == 8 ) |
---|
830 | { |
---|
831 | for( i = 0; i < sel->length; ++i ) |
---|
832 | fprintf( stderr, "%02X ", sel->data[i] ); |
---|
833 | fprintf( stderr, "\n" ); |
---|
834 | } |
---|
835 | #endif |
---|
836 | |
---|
837 | if( ( sel->format == 8 ) |
---|
838 | && ( sel->selection == gdk_atom_intern( "XdndSelection", FALSE ) ) ) |
---|
839 | { |
---|
840 | int i; |
---|
841 | char * str = g_strndup( (char*)sel->data, sel->length ); |
---|
842 | gchar ** files = g_strsplit_set( str, "\r\n", -1 ); |
---|
843 | for( i = 0; files && files[i]; ++i ) |
---|
844 | { |
---|
845 | char * filename; |
---|
846 | if( !*files[i] ) /* empty filename... */ |
---|
847 | continue; |
---|
848 | |
---|
849 | /* decode the filename */ |
---|
850 | filename = decode_uri( files[i] ); |
---|
851 | freeme = g_slist_prepend( freeme, filename ); |
---|
852 | if( !g_utf8_validate( filename, -1, NULL ) ) |
---|
853 | continue; |
---|
854 | |
---|
855 | /* walk past "file://", if present */ |
---|
856 | if( g_str_has_prefix( filename, "file:" ) ) |
---|
857 | { |
---|
858 | filename += 5; |
---|
859 | while( g_str_has_prefix( filename, "//" ) ) |
---|
860 | ++filename; |
---|
861 | } |
---|
862 | |
---|
863 | /* if the file doesn't exist, the first part |
---|
864 | might be a hostname ... walk past it. */ |
---|
865 | if( !g_file_test( filename, G_FILE_TEST_EXISTS ) ) |
---|
866 | { |
---|
867 | char * pch = strchr( filename + 1, '/' ); |
---|
868 | if( pch != NULL ) |
---|
869 | filename = pch; |
---|
870 | } |
---|
871 | |
---|
872 | /* finally, add it to the list of torrents to try adding */ |
---|
873 | if( g_file_test( filename, G_FILE_TEST_EXISTS ) ) |
---|
874 | paths = g_slist_prepend( paths, g_strdup( filename ) ); |
---|
875 | } |
---|
876 | |
---|
877 | /* try to add any torrents we found */ |
---|
878 | if( paths ) |
---|
879 | { |
---|
880 | paths = g_slist_reverse( paths ); |
---|
881 | tr_core_add_list_defaults( data->core, paths ); |
---|
882 | tr_core_torrents_added( data->core ); |
---|
883 | } |
---|
884 | |
---|
885 | freestrlist( freeme ); |
---|
886 | g_strfreev( files ); |
---|
887 | g_free( str ); |
---|
888 | } |
---|
889 | |
---|
890 | gtk_drag_finish( dc, ( NULL != paths ), FALSE, time ); |
---|
891 | } |
---|
892 | |
---|
893 | static void |
---|
894 | setupdrag( GtkWidget * widget, |
---|
895 | struct cbdata *data ) |
---|
896 | { |
---|
897 | GtkTargetEntry targets[] = { |
---|
898 | { "STRING", 0, 0 }, |
---|
899 | { "text/plain", 0, 0 }, |
---|
900 | { "text/uri-list", 0, 0 }, |
---|
901 | }; |
---|
902 | |
---|
903 | g_signal_connect( widget, "drag_data_received", G_CALLBACK( |
---|
904 | gotdrag ), data ); |
---|
905 | |
---|
906 | gtk_drag_dest_set( widget, GTK_DEST_DEFAULT_ALL, targets, |
---|
907 | ALEN( targets ), GDK_ACTION_COPY | GDK_ACTION_MOVE ); |
---|
908 | } |
---|
909 | |
---|
910 | static void |
---|
911 | flushAddTorrentErrors( GtkWindow * window, |
---|
912 | const char * primary, |
---|
913 | GSList ** files ) |
---|
914 | { |
---|
915 | GString * s = g_string_new( NULL ); |
---|
916 | GSList * l; |
---|
917 | GtkWidget * w; |
---|
918 | |
---|
919 | if( g_slist_length( *files ) > 1 ) { |
---|
920 | for( l=*files; l!=NULL; l=l->next ) |
---|
921 | g_string_append_printf( s, "\xE2\x88\x99 %s\n", (const char*)l->data ); |
---|
922 | } else { |
---|
923 | for( l=*files; l!=NULL; l=l->next ) |
---|
924 | g_string_append_printf( s, "%s\n", (const char*)l->data ); |
---|
925 | } |
---|
926 | w = gtk_message_dialog_new( window, |
---|
927 | GTK_DIALOG_DESTROY_WITH_PARENT, |
---|
928 | GTK_MESSAGE_ERROR, |
---|
929 | GTK_BUTTONS_CLOSE, |
---|
930 | "%s", primary ); |
---|
931 | gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( w ), |
---|
932 | "%s", s->str ); |
---|
933 | g_signal_connect_swapped( w, "response", |
---|
934 | G_CALLBACK( gtk_widget_destroy ), w ); |
---|
935 | gtk_widget_show_all( w ); |
---|
936 | g_string_free( s, TRUE ); |
---|
937 | |
---|
938 | g_slist_foreach( *files, (GFunc)g_free, NULL ); |
---|
939 | g_slist_free( *files ); |
---|
940 | *files = NULL; |
---|
941 | } |
---|
942 | |
---|
943 | static void |
---|
944 | showTorrentErrors( struct cbdata * cbdata ) |
---|
945 | { |
---|
946 | if( cbdata->errqueue ) |
---|
947 | flushAddTorrentErrors( GTK_WINDOW( cbdata->wind ), |
---|
948 | ngettext( "Couldn't add corrupt torrent", |
---|
949 | "Couldn't add corrupt torrents", |
---|
950 | g_slist_length( cbdata->errqueue ) ), |
---|
951 | &cbdata->errqueue ); |
---|
952 | |
---|
953 | if( cbdata->dupqueue ) |
---|
954 | flushAddTorrentErrors( GTK_WINDOW( cbdata->wind ), |
---|
955 | ngettext( "Couldn't add duplicate torrent", |
---|
956 | "Couldn't add duplicate torrents", |
---|
957 | g_slist_length( cbdata->dupqueue ) ), |
---|
958 | &cbdata->dupqueue ); |
---|
959 | } |
---|
960 | |
---|
961 | static void |
---|
962 | coreerr( TrCore * core UNUSED, |
---|
963 | enum tr_core_err code, |
---|
964 | const char * msg, |
---|
965 | gpointer gdata ) |
---|
966 | { |
---|
967 | struct cbdata * c = gdata; |
---|
968 | |
---|
969 | switch( code ) |
---|
970 | { |
---|
971 | case TR_EINVALID: |
---|
972 | c->errqueue = |
---|
973 | g_slist_append( c->errqueue, g_path_get_basename( msg ) ); |
---|
974 | break; |
---|
975 | |
---|
976 | case TR_EDUPLICATE: |
---|
977 | c->dupqueue = g_slist_append( c->dupqueue, g_strdup( msg ) ); |
---|
978 | break; |
---|
979 | |
---|
980 | case TR_CORE_ERR_NO_MORE_TORRENTS: |
---|
981 | showTorrentErrors( c ); |
---|
982 | break; |
---|
983 | |
---|
984 | case TR_CORE_ERR_SAVE_STATE: |
---|
985 | errmsg( c->wind, "%s", msg ); |
---|
986 | break; |
---|
987 | |
---|
988 | default: |
---|
989 | g_assert_not_reached( ); |
---|
990 | break; |
---|
991 | } |
---|
992 | } |
---|
993 | |
---|
994 | #if GTK_CHECK_VERSION( 2, 8, 0 ) |
---|
995 | static void |
---|
996 | on_main_window_focus_in( GtkWidget * widget UNUSED, |
---|
997 | GdkEventFocus * event UNUSED, |
---|
998 | gpointer gdata ) |
---|
999 | { |
---|
1000 | struct cbdata * cbdata = gdata; |
---|
1001 | |
---|
1002 | gtk_window_set_urgency_hint( GTK_WINDOW( cbdata->wind ), FALSE ); |
---|
1003 | } |
---|
1004 | |
---|
1005 | #endif |
---|
1006 | |
---|
1007 | static void |
---|
1008 | onAddTorrent( TrCore * core, |
---|
1009 | tr_ctor * ctor, |
---|
1010 | gpointer gdata ) |
---|
1011 | { |
---|
1012 | struct cbdata * cbdata = gdata; |
---|
1013 | GtkWidget * w = addSingleTorrentDialog( cbdata->wind, core, ctor ); |
---|
1014 | |
---|
1015 | #if GTK_CHECK_VERSION( 2, 8, 0 ) |
---|
1016 | g_signal_connect( w, "focus-in-event", |
---|
1017 | G_CALLBACK( on_main_window_focus_in ), cbdata ); |
---|
1018 | gtk_window_set_urgency_hint( cbdata->wind, TRUE ); |
---|
1019 | #endif |
---|
1020 | } |
---|
1021 | |
---|
1022 | static void |
---|
1023 | prefschanged( TrCore * core UNUSED, |
---|
1024 | const char * key, |
---|
1025 | gpointer data ) |
---|
1026 | { |
---|
1027 | struct cbdata * cbdata = data; |
---|
1028 | tr_session * tr = tr_core_session( cbdata->core ); |
---|
1029 | |
---|
1030 | if( !strcmp( key, TR_PREFS_KEY_ENCRYPTION ) ) |
---|
1031 | { |
---|
1032 | const int encryption = pref_int_get( key ); |
---|
1033 | g_message( "setting encryption to %d", encryption ); |
---|
1034 | tr_sessionSetEncryption( tr, encryption ); |
---|
1035 | } |
---|
1036 | else if( !strcmp( key, TR_PREFS_KEY_DOWNLOAD_DIR ) ) |
---|
1037 | { |
---|
1038 | tr_sessionSetDownloadDir( tr, pref_string_get( key ) ); |
---|
1039 | } |
---|
1040 | else if( !strcmp( key, TR_PREFS_KEY_MSGLEVEL ) ) |
---|
1041 | { |
---|
1042 | tr_setMessageLevel( pref_int_get( key ) ); |
---|
1043 | } |
---|
1044 | else if( !strcmp( key, TR_PREFS_KEY_PEER_PORT_RANDOM_ENABLED ) ) |
---|
1045 | { |
---|
1046 | /* FIXME */ |
---|
1047 | } |
---|
1048 | else if( !strcmp( key, TR_PREFS_KEY_PEER_PORT ) ) |
---|
1049 | { |
---|
1050 | const int port = pref_int_get( key ); |
---|
1051 | tr_sessionSetPeerPort( tr, port ); |
---|
1052 | } |
---|
1053 | else if( !strcmp( key, TR_PREFS_KEY_BLOCKLIST_ENABLED ) ) |
---|
1054 | { |
---|
1055 | const gboolean flag = pref_flag_get( key ); |
---|
1056 | tr_blocklistSetEnabled( tr, flag ); |
---|
1057 | } |
---|
1058 | else if( !strcmp( key, PREF_KEY_SHOW_TRAY_ICON ) ) |
---|
1059 | { |
---|
1060 | const int show = pref_flag_get( key ); |
---|
1061 | if( show && !cbdata->icon ) |
---|
1062 | cbdata->icon = tr_icon_new( cbdata->core ); |
---|
1063 | else if( !show && cbdata->icon ) |
---|
1064 | { |
---|
1065 | g_object_unref( cbdata->icon ); |
---|
1066 | cbdata->icon = NULL; |
---|
1067 | } |
---|
1068 | } |
---|
1069 | else if( !strcmp( key, TR_PREFS_KEY_DSPEED_ENABLED ) ) |
---|
1070 | { |
---|
1071 | const gboolean b = pref_flag_get( key ); |
---|
1072 | tr_sessionSetSpeedLimitEnabled( tr, TR_DOWN, b ); |
---|
1073 | } |
---|
1074 | else if( !strcmp( key, TR_PREFS_KEY_DSPEED ) ) |
---|
1075 | { |
---|
1076 | const int limit = pref_int_get( key ); |
---|
1077 | tr_sessionSetSpeedLimit( tr, TR_DOWN, limit ); |
---|
1078 | } |
---|
1079 | else if( !strcmp( key, TR_PREFS_KEY_USPEED_ENABLED ) ) |
---|
1080 | { |
---|
1081 | const gboolean b = pref_flag_get( key ); |
---|
1082 | tr_sessionSetSpeedLimitEnabled( tr, TR_UP, b ); |
---|
1083 | } |
---|
1084 | else if( !strcmp( key, TR_PREFS_KEY_USPEED ) ) |
---|
1085 | { |
---|
1086 | const int limit = pref_int_get( key ); |
---|
1087 | tr_sessionSetSpeedLimit( tr, TR_UP, limit ); |
---|
1088 | } |
---|
1089 | else if( !strncmp( key, "sched-", 6 ) ) |
---|
1090 | { |
---|
1091 | updateScheduledLimits( tr ); |
---|
1092 | } |
---|
1093 | else if( !strcmp( key, TR_PREFS_KEY_PORT_FORWARDING ) ) |
---|
1094 | { |
---|
1095 | tr_sessionSetPortForwardingEnabled( tr, pref_flag_get( key ) ); |
---|
1096 | } |
---|
1097 | else if( !strcmp( key, TR_PREFS_KEY_PEX_ENABLED ) ) |
---|
1098 | { |
---|
1099 | tr_sessionSetPexEnabled( tr, pref_flag_get( key ) ); |
---|
1100 | } |
---|
1101 | else if( !strcmp( key, TR_PREFS_KEY_RPC_PORT ) ) |
---|
1102 | { |
---|
1103 | tr_sessionSetRPCPort( tr, pref_int_get( key ) ); |
---|
1104 | } |
---|
1105 | else if( !strcmp( key, TR_PREFS_KEY_RPC_ENABLED ) ) |
---|
1106 | { |
---|
1107 | tr_sessionSetRPCEnabled( tr, pref_flag_get( key ) ); |
---|
1108 | } |
---|
1109 | else if( !strcmp( key, TR_PREFS_KEY_RPC_WHITELIST ) ) |
---|
1110 | { |
---|
1111 | const char * s = pref_string_get( key ); |
---|
1112 | tr_sessionSetRPCWhitelist( tr, s ); |
---|
1113 | } |
---|
1114 | else if( !strcmp( key, TR_PREFS_KEY_RPC_WHITELIST_ENABLED ) ) |
---|
1115 | { |
---|
1116 | tr_sessionSetRPCWhitelistEnabled( tr, pref_flag_get( key ) ); |
---|
1117 | } |
---|
1118 | else if( !strcmp( key, TR_PREFS_KEY_RPC_USERNAME ) ) |
---|
1119 | { |
---|
1120 | const char * s = pref_string_get( key ); |
---|
1121 | tr_sessionSetRPCUsername( tr, s ); |
---|
1122 | } |
---|
1123 | else if( !strcmp( key, TR_PREFS_KEY_RPC_PASSWORD ) ) |
---|
1124 | { |
---|
1125 | const char * s = pref_string_get( key ); |
---|
1126 | tr_sessionSetRPCPassword( tr, s ); |
---|
1127 | } |
---|
1128 | else if( !strcmp( key, TR_PREFS_KEY_RPC_AUTH_REQUIRED ) ) |
---|
1129 | { |
---|
1130 | const gboolean enabled = pref_flag_get( key ); |
---|
1131 | tr_sessionSetRPCPasswordEnabled( tr, enabled ); |
---|
1132 | } |
---|
1133 | else if( !strcmp( key, TR_PREFS_KEY_PROXY ) ) |
---|
1134 | { |
---|
1135 | const char * s = pref_string_get( key ); |
---|
1136 | tr_sessionSetProxy( tr, s ); |
---|
1137 | } |
---|
1138 | else if( !strcmp( key, TR_PREFS_KEY_PROXY_TYPE ) ) |
---|
1139 | { |
---|
1140 | const int i = pref_int_get( key ); |
---|
1141 | tr_sessionSetProxyType( tr, i ); |
---|
1142 | } |
---|
1143 | else if( !strcmp( key, TR_PREFS_KEY_PROXY_ENABLED ) ) |
---|
1144 | { |
---|
1145 | const gboolean enabled = pref_flag_get( key ); |
---|
1146 | tr_sessionSetProxyEnabled( tr, enabled ); |
---|
1147 | } |
---|
1148 | else if( !strcmp( key, TR_PREFS_KEY_PROXY_AUTH_ENABLED ) ) |
---|
1149 | { |
---|
1150 | const gboolean enabled = pref_flag_get( key ); |
---|
1151 | tr_sessionSetProxyAuthEnabled( tr, enabled ); |
---|
1152 | } |
---|
1153 | else if( !strcmp( key, TR_PREFS_KEY_PROXY_USERNAME ) ) |
---|
1154 | { |
---|
1155 | const char * s = pref_string_get( key ); |
---|
1156 | tr_sessionSetProxyUsername( tr, s ); |
---|
1157 | } |
---|
1158 | else if( !strcmp( key, TR_PREFS_KEY_PROXY_PASSWORD ) ) |
---|
1159 | { |
---|
1160 | const char * s = pref_string_get( key ); |
---|
1161 | tr_sessionSetProxyPassword( tr, s ); |
---|
1162 | } |
---|
1163 | else if( !strcmp( key, TR_PREFS_KEY_PROXY_PORT ) ) |
---|
1164 | { |
---|
1165 | tr_sessionSetProxyPort( tr, pref_int_get( key ) ); |
---|
1166 | } |
---|
1167 | else if( !strcmp( key, TR_PREFS_KEY_RPC_PASSWORD ) ) |
---|
1168 | { |
---|
1169 | const char * s = pref_string_get( key ); |
---|
1170 | tr_sessionSetProxyPassword( tr, s ); |
---|
1171 | } |
---|
1172 | } |
---|
1173 | |
---|
1174 | static gboolean |
---|
1175 | updatemodel( gpointer gdata ) |
---|
1176 | { |
---|
1177 | struct cbdata *data = gdata; |
---|
1178 | const gboolean done = data->isClosing || global_sigcount; |
---|
1179 | |
---|
1180 | if( !done ) |
---|
1181 | { |
---|
1182 | /* update the torrent data in the model */ |
---|
1183 | tr_core_update( data->core ); |
---|
1184 | |
---|
1185 | /* update the main window's statusbar and toolbar buttons */ |
---|
1186 | if( data->wind ) |
---|
1187 | tr_window_update( data->wind ); |
---|
1188 | |
---|
1189 | /* update the actions */ |
---|
1190 | refreshTorrentActions( data ); |
---|
1191 | } |
---|
1192 | |
---|
1193 | return !done; |
---|
1194 | } |
---|
1195 | |
---|
1196 | static void |
---|
1197 | aboutDialogActivateLink( GtkAboutDialog * dialog UNUSED, |
---|
1198 | const gchar * link_, |
---|
1199 | gpointer user_data UNUSED ) |
---|
1200 | { |
---|
1201 | gtr_open_file( link_ ); |
---|
1202 | } |
---|
1203 | |
---|
1204 | static void |
---|
1205 | about( GtkWindow * parent ) |
---|
1206 | { |
---|
1207 | const char *authors[] = |
---|
1208 | { |
---|
1209 | "Charles Kerr (Backend; GTK+)", |
---|
1210 | "Mitchell Livingston (Backend; OS X)", |
---|
1211 | "Eric Petit (Backend; OS X)", |
---|
1212 | "Josh Elsasser (Daemon; Backend; GTK+)", |
---|
1213 | "Bryan Varner (BeOS)", |
---|
1214 | NULL |
---|
1215 | }; |
---|
1216 | |
---|
1217 | const char *website_url = "http://www.transmissionbt.com/"; |
---|
1218 | |
---|
1219 | gtk_about_dialog_set_url_hook( aboutDialogActivateLink, NULL, NULL ); |
---|
1220 | |
---|
1221 | gtk_show_about_dialog( parent, |
---|
1222 | "name", g_get_application_name( ), |
---|
1223 | "comments", |
---|
1224 | _( "A fast and easy BitTorrent client" ), |
---|
1225 | "version", LONG_VERSION_STRING, |
---|
1226 | "website", website_url, |
---|
1227 | "website-label", website_url, |
---|
1228 | "copyright", |
---|
1229 | _( "Copyright 2005-2008 The Transmission Project" ), |
---|
1230 | "logo-icon-name", MY_NAME, |
---|
1231 | #ifdef SHOW_LICENSE |
---|
1232 | "license", LICENSE, |
---|
1233 | "wrap-license", TRUE, |
---|
1234 | #endif |
---|
1235 | "authors", authors, |
---|
1236 | /* Translators: translate "translator-credits" as |
---|
1237 | your name |
---|
1238 | to have it appear in the credits in the "About" |
---|
1239 | dialog */ |
---|
1240 | "translator-credits", _( "translator-credits" ), |
---|
1241 | NULL ); |
---|
1242 | } |
---|
1243 | |
---|
1244 | static void |
---|
1245 | startTorrentForeach( GtkTreeModel * model, |
---|
1246 | GtkTreePath * path UNUSED, |
---|
1247 | GtkTreeIter * iter, |
---|
1248 | gpointer data UNUSED ) |
---|
1249 | { |
---|
1250 | tr_torrent * tor = NULL; |
---|
1251 | |
---|
1252 | gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 ); |
---|
1253 | tr_torrentStart( tor ); |
---|
1254 | } |
---|
1255 | |
---|
1256 | static void |
---|
1257 | stopTorrentForeach( GtkTreeModel * model, |
---|
1258 | GtkTreePath * path UNUSED, |
---|
1259 | GtkTreeIter * iter, |
---|
1260 | gpointer data UNUSED ) |
---|
1261 | { |
---|
1262 | tr_torrent * tor = NULL; |
---|
1263 | |
---|
1264 | gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 ); |
---|
1265 | tr_torrentStop( tor ); |
---|
1266 | } |
---|
1267 | |
---|
1268 | static void |
---|
1269 | updateTrackerForeach( GtkTreeModel * model, |
---|
1270 | GtkTreePath * path UNUSED, |
---|
1271 | GtkTreeIter * iter, |
---|
1272 | gpointer data UNUSED ) |
---|
1273 | { |
---|
1274 | tr_torrent * tor = NULL; |
---|
1275 | |
---|
1276 | gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 ); |
---|
1277 | tr_torrentManualUpdate( tor ); |
---|
1278 | } |
---|
1279 | |
---|
1280 | static void |
---|
1281 | detailsClosed( gpointer user_data, |
---|
1282 | GObject * details ) |
---|
1283 | { |
---|
1284 | struct cbdata * data = user_data; |
---|
1285 | gpointer hashString = g_hash_table_lookup( data->details2tor, |
---|
1286 | details ); |
---|
1287 | |
---|
1288 | g_hash_table_remove( data->details2tor, details ); |
---|
1289 | g_hash_table_remove( data->tor2details, hashString ); |
---|
1290 | } |
---|
1291 | |
---|
1292 | static void |
---|
1293 | openFolderForeach( GtkTreeModel * model, |
---|
1294 | GtkTreePath * path UNUSED, |
---|
1295 | GtkTreeIter * iter, |
---|
1296 | gpointer user_data UNUSED ) |
---|
1297 | { |
---|
1298 | TrTorrent * gtor = NULL; |
---|
1299 | |
---|
1300 | gtk_tree_model_get( model, iter, MC_TORRENT, >or, -1 ); |
---|
1301 | tr_torrent_open_folder( gtor ); |
---|
1302 | g_object_unref( G_OBJECT( gtor ) ); |
---|
1303 | } |
---|
1304 | |
---|
1305 | static void |
---|
1306 | showInfoForeach( GtkTreeModel * model, |
---|
1307 | GtkTreePath * path UNUSED, |
---|
1308 | GtkTreeIter * iter, |
---|
1309 | gpointer user_data ) |
---|
1310 | { |
---|
1311 | const char * hashString; |
---|
1312 | struct cbdata * data = user_data; |
---|
1313 | TrTorrent * tor = NULL; |
---|
1314 | GtkWidget * w; |
---|
1315 | |
---|
1316 | gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 ); |
---|
1317 | hashString = tr_torrent_info( tor )->hashString; |
---|
1318 | w = g_hash_table_lookup( data->tor2details, hashString ); |
---|
1319 | if( w != NULL ) |
---|
1320 | gtk_window_present( GTK_WINDOW( w ) ); |
---|
1321 | else |
---|
1322 | { |
---|
1323 | w = torrent_inspector_new( GTK_WINDOW( data->wind ), tor ); |
---|
1324 | gtk_widget_show( w ); |
---|
1325 | g_hash_table_insert( data->tor2details, (gpointer)hashString, w ); |
---|
1326 | g_hash_table_insert( data->details2tor, w, (gpointer)hashString ); |
---|
1327 | g_object_weak_ref( G_OBJECT( w ), detailsClosed, data ); |
---|
1328 | } |
---|
1329 | |
---|
1330 | g_object_unref( G_OBJECT( tor ) ); |
---|
1331 | } |
---|
1332 | |
---|
1333 | static void |
---|
1334 | recheckTorrentForeach( GtkTreeModel * model, |
---|
1335 | GtkTreePath * path UNUSED, |
---|
1336 | GtkTreeIter * iter, |
---|
1337 | gpointer data UNUSED ) |
---|
1338 | { |
---|
1339 | TrTorrent * gtor = NULL; |
---|
1340 | |
---|
1341 | gtk_tree_model_get( model, iter, MC_TORRENT, >or, -1 ); |
---|
1342 | tr_torrentVerify( tr_torrent_handle( gtor ) ); |
---|
1343 | g_object_unref( G_OBJECT( gtor ) ); |
---|
1344 | } |
---|
1345 | |
---|
1346 | static gboolean |
---|
1347 | msgwinclosed( void ) |
---|
1348 | { |
---|
1349 | action_toggle( "toggle-message-log", FALSE ); |
---|
1350 | return FALSE; |
---|
1351 | } |
---|
1352 | |
---|
1353 | static void |
---|
1354 | accumulateSelectedTorrents( GtkTreeModel * model, |
---|
1355 | GtkTreePath * path UNUSED, |
---|
1356 | GtkTreeIter * iter, |
---|
1357 | gpointer gdata ) |
---|
1358 | { |
---|
1359 | GSList ** data = ( GSList** ) gdata; |
---|
1360 | TrTorrent * tor = NULL; |
---|
1361 | |
---|
1362 | gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 ); |
---|
1363 | *data = g_slist_prepend( *data, tor ); |
---|
1364 | } |
---|
1365 | |
---|
1366 | static void |
---|
1367 | removeSelected( struct cbdata * data, |
---|
1368 | gboolean delete_files ) |
---|
1369 | { |
---|
1370 | GSList * l = NULL; |
---|
1371 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1372 | |
---|
1373 | gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l ); |
---|
1374 | gtk_tree_selection_unselect_all( s ); |
---|
1375 | if( l ) |
---|
1376 | { |
---|
1377 | l = g_slist_reverse( l ); |
---|
1378 | confirmRemove( data->wind, data->core, l, delete_files ); |
---|
1379 | } |
---|
1380 | } |
---|
1381 | |
---|
1382 | static void |
---|
1383 | pauseAllTorrents( struct cbdata * data ) |
---|
1384 | { |
---|
1385 | tr_session * session = tr_core_session( data->core ); |
---|
1386 | const char * cmd = "{ \"method\": \"torrent-stop\" }"; |
---|
1387 | tr_rpc_request_exec_json( session, cmd, strlen( cmd ), NULL ); |
---|
1388 | } |
---|
1389 | |
---|
1390 | void |
---|
1391 | doAction( const char * action_name, gpointer user_data ) |
---|
1392 | { |
---|
1393 | struct cbdata * data = user_data; |
---|
1394 | gboolean changed = FALSE; |
---|
1395 | |
---|
1396 | if( !strcmp( action_name, "add-torrent-menu" ) |
---|
1397 | || !strcmp( action_name, "add-torrent-toolbar" ) ) |
---|
1398 | { |
---|
1399 | addDialog( data->wind, data->core ); |
---|
1400 | } |
---|
1401 | else if( !strcmp( action_name, "show-stats" ) ) |
---|
1402 | { |
---|
1403 | GtkWidget * dialog = stats_dialog_create( data->wind, data->core ); |
---|
1404 | gtk_widget_show( dialog ); |
---|
1405 | } |
---|
1406 | else if( !strcmp( action_name, "start-torrent" ) ) |
---|
1407 | { |
---|
1408 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1409 | gtk_tree_selection_selected_foreach( s, startTorrentForeach, NULL ); |
---|
1410 | changed |= gtk_tree_selection_count_selected_rows( s ) != 0; |
---|
1411 | } |
---|
1412 | else if( !strcmp( action_name, "pause-all-torrents" ) ) |
---|
1413 | { |
---|
1414 | pauseAllTorrents( data ); |
---|
1415 | } |
---|
1416 | else if( !strcmp( action_name, "pause-torrent" ) ) |
---|
1417 | { |
---|
1418 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1419 | gtk_tree_selection_selected_foreach( s, stopTorrentForeach, NULL ); |
---|
1420 | changed |= gtk_tree_selection_count_selected_rows( s ) != 0; |
---|
1421 | } |
---|
1422 | else if( !strcmp( action_name, "verify-torrent" ) ) |
---|
1423 | { |
---|
1424 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1425 | gtk_tree_selection_selected_foreach( s, recheckTorrentForeach, NULL ); |
---|
1426 | changed |= gtk_tree_selection_count_selected_rows( s ) != 0; |
---|
1427 | } |
---|
1428 | else if( !strcmp( action_name, "open-torrent-folder" ) ) |
---|
1429 | { |
---|
1430 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1431 | gtk_tree_selection_selected_foreach( s, openFolderForeach, data ); |
---|
1432 | } |
---|
1433 | else if( !strcmp( action_name, "show-torrent-properties" ) ) |
---|
1434 | { |
---|
1435 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1436 | gtk_tree_selection_selected_foreach( s, showInfoForeach, data ); |
---|
1437 | } |
---|
1438 | else if( !strcmp( action_name, "update-tracker" ) ) |
---|
1439 | { |
---|
1440 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1441 | gtk_tree_selection_selected_foreach( s, updateTrackerForeach, |
---|
1442 | data->wind ); |
---|
1443 | } |
---|
1444 | else if( !strcmp( action_name, "new-torrent" ) ) |
---|
1445 | { |
---|
1446 | GtkWidget * w = make_meta_ui( GTK_WINDOW( data->wind ), |
---|
1447 | tr_core_session( data->core ) ); |
---|
1448 | gtk_widget_show_all( w ); |
---|
1449 | } |
---|
1450 | else if( !strcmp( action_name, "remove-torrent" ) ) |
---|
1451 | { |
---|
1452 | removeSelected( data, FALSE ); |
---|
1453 | } |
---|
1454 | else if( !strcmp( action_name, "delete-torrent" ) ) |
---|
1455 | { |
---|
1456 | removeSelected( data, TRUE ); |
---|
1457 | } |
---|
1458 | else if( !strcmp( action_name, "quit" ) ) |
---|
1459 | { |
---|
1460 | askquit( data->core, data->wind, wannaquit, data ); |
---|
1461 | } |
---|
1462 | else if( !strcmp( action_name, "select-all" ) ) |
---|
1463 | { |
---|
1464 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1465 | gtk_tree_selection_select_all( s ); |
---|
1466 | } |
---|
1467 | else if( !strcmp( action_name, "deselect-all" ) ) |
---|
1468 | { |
---|
1469 | GtkTreeSelection * s = tr_window_get_selection( data->wind ); |
---|
1470 | gtk_tree_selection_unselect_all( s ); |
---|
1471 | } |
---|
1472 | else if( !strcmp( action_name, "edit-preferences" ) ) |
---|
1473 | { |
---|
1474 | if( NULL == data->prefs ) |
---|
1475 | { |
---|
1476 | data->prefs = tr_prefs_dialog_new( G_OBJECT( data->core ), |
---|
1477 | data->wind ); |
---|
1478 | g_signal_connect( data->prefs, "destroy", |
---|
1479 | G_CALLBACK( gtk_widget_destroyed ), &data->prefs ); |
---|
1480 | gtk_widget_show( GTK_WIDGET( data->prefs ) ); |
---|
1481 | } |
---|
1482 | } |
---|
1483 | else if( !strcmp( action_name, "toggle-message-log" ) ) |
---|
1484 | { |
---|
1485 | if( !data->msgwin ) |
---|
1486 | { |
---|
1487 | GtkWidget * win = msgwin_new( data->core ); |
---|
1488 | g_signal_connect( win, "destroy", G_CALLBACK( msgwinclosed ), |
---|
1489 | NULL ); |
---|
1490 | data->msgwin = win; |
---|
1491 | } |
---|
1492 | else |
---|
1493 | { |
---|
1494 | action_toggle( "toggle-message-log", FALSE ); |
---|
1495 | gtk_widget_destroy( data->msgwin ); |
---|
1496 | data->msgwin = NULL; |
---|
1497 | } |
---|
1498 | } |
---|
1499 | else if( !strcmp( action_name, "show-about-dialog" ) ) |
---|
1500 | { |
---|
1501 | about( data->wind ); |
---|
1502 | } |
---|
1503 | else if( !strcmp ( action_name, "help" ) ) |
---|
1504 | { |
---|
1505 | char * url = gtr_get_help_url( ); |
---|
1506 | gtr_open_file( url ); |
---|
1507 | g_free( url ); |
---|
1508 | } |
---|
1509 | else if( !strcmp( action_name, "toggle-main-window" ) ) |
---|
1510 | { |
---|
1511 | toggleMainWindow( data, FALSE ); |
---|
1512 | } |
---|
1513 | else if( !strcmp( action_name, "present-main-window" ) ) |
---|
1514 | { |
---|
1515 | toggleMainWindow( data, TRUE ); |
---|
1516 | } |
---|
1517 | else g_error ( "Unhandled action: %s", action_name ); |
---|
1518 | |
---|
1519 | if( changed ) |
---|
1520 | updatemodel( data ); |
---|
1521 | } |
---|
1522 | |
---|