2008-02-13 03:00:21 +00:00
|
|
|
/*
|
2010-01-04 21:00:47 +00:00
|
|
|
* This file Copyright (C) 2008-2010 Mnemosyne LLC
|
2008-02-13 03:00:21 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2008-02-13 03:00:21 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2008-02-26 21:08:51 +00:00
|
|
|
* $Id$
|
2008-02-13 03:00:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
2009-11-22 16:20:22 +00:00
|
|
|
|
2010-02-05 12:35:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-04-03 02:11:15 +00:00
|
|
|
#include "add-dialog.h"
|
2008-03-18 20:41:27 +00:00
|
|
|
#include "conf.h"
|
2008-02-13 03:00:21 +00:00
|
|
|
#include "file-list.h"
|
|
|
|
#include "hig.h"
|
2008-03-18 20:41:27 +00:00
|
|
|
#include "tr-prefs.h"
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2008-07-02 00:17:27 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
#define N_RECENT 4
|
|
|
|
|
|
|
|
static GSList*
|
|
|
|
get_recent_destinations( void )
|
|
|
|
{
|
2009-11-22 16:20:22 +00:00
|
|
|
int i;
|
2008-07-02 00:17:27 +00:00
|
|
|
GSList * list = NULL;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
for( i=0; i<N_RECENT; ++i )
|
2008-07-02 00:17:27 +00:00
|
|
|
{
|
2009-11-22 16:20:22 +00:00
|
|
|
char key[64];
|
2008-07-02 00:17:27 +00:00
|
|
|
const char * val;
|
2009-11-22 16:20:22 +00:00
|
|
|
g_snprintf( key, sizeof( key ), "recent-download-dir-%d", i+1 );
|
|
|
|
if(( val = pref_string_get( key )))
|
2008-07-02 00:17:27 +00:00
|
|
|
list = g_slist_append( list, (void*)val );
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-13 23:17:36 +00:00
|
|
|
save_recent_destination( TrCore * core, const char * dir )
|
2008-07-02 00:17:27 +00:00
|
|
|
{
|
2009-11-22 16:20:22 +00:00
|
|
|
int i;
|
2008-07-02 00:17:27 +00:00
|
|
|
GSList * l;
|
2009-11-22 16:20:22 +00:00
|
|
|
GSList * list = get_recent_destinations( );
|
2008-07-02 00:17:27 +00:00
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
if( dir == NULL )
|
2008-07-02 00:17:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* if it was already in the list, remove it */
|
2009-11-22 16:20:22 +00:00
|
|
|
if(( l = g_slist_find_custom( list, dir, (GCompareFunc)strcmp )))
|
2008-07-02 00:17:27 +00:00
|
|
|
list = g_slist_delete_link( list, l );
|
|
|
|
|
|
|
|
/* add it to the front of the list */
|
|
|
|
list = g_slist_prepend( list, (void*)dir );
|
|
|
|
|
|
|
|
/* make local copies of the strings that aren't
|
|
|
|
* invalidated by pref_string_set() */
|
2009-11-22 16:20:22 +00:00
|
|
|
for( l=list; l; l=l->next )
|
2008-09-23 19:11:04 +00:00
|
|
|
l->data = g_strdup( l->data );
|
2008-07-02 00:17:27 +00:00
|
|
|
|
|
|
|
/* save the first N_RECENT directories */
|
2009-11-22 16:20:22 +00:00
|
|
|
for( l=list, i=0; l && ( i<N_RECENT ); ++i, l=l->next ) {
|
2008-07-02 00:17:27 +00:00
|
|
|
char key[64];
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( key, sizeof( key ), "recent-download-dir-%d", i + 1 );
|
2008-07-02 00:17:27 +00:00
|
|
|
pref_string_set( key, l->data );
|
|
|
|
}
|
2008-12-13 23:17:36 +00:00
|
|
|
pref_save( tr_core_session( core ) );
|
2008-07-02 00:17:27 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_slist_foreach( list, (GFunc)g_free, NULL );
|
|
|
|
g_slist_free( list );
|
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2008-04-03 02:11:15 +00:00
|
|
|
struct AddData
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
TrCore * core;
|
2010-05-13 13:12:27 +00:00
|
|
|
GtkWidget * file_list;
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * run_check;
|
|
|
|
GtkWidget * trash_check;
|
2010-02-02 07:51:45 +00:00
|
|
|
GtkWidget * priority_combo;
|
2008-09-23 19:11:04 +00:00
|
|
|
char * filename;
|
|
|
|
char * downloadDir;
|
|
|
|
TrTorrent * gtor;
|
|
|
|
tr_ctor * ctor;
|
2008-02-13 03:00:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2008-05-20 23:58:59 +00:00
|
|
|
removeOldTorrent( struct AddData * data )
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
|
|
|
if( data->gtor )
|
|
|
|
{
|
2010-05-13 13:12:27 +00:00
|
|
|
file_list_clear( data->file_list );
|
2008-05-20 23:58:59 +00:00
|
|
|
tr_torrent_set_remove_flag( data->gtor, TRUE );
|
2008-02-13 03:00:21 +00:00
|
|
|
g_object_unref( G_OBJECT( data->gtor ) );
|
|
|
|
data->gtor = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
addResponseCB( GtkDialog * dialog,
|
|
|
|
gint response,
|
|
|
|
gpointer gdata )
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2008-04-03 02:11:15 +00:00
|
|
|
struct AddData * data = gdata;
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
if( data->gtor )
|
|
|
|
{
|
|
|
|
if( response != GTK_RESPONSE_ACCEPT )
|
2008-12-13 23:17:36 +00:00
|
|
|
{
|
2008-05-20 23:58:59 +00:00
|
|
|
removeOldTorrent( data );
|
2008-12-13 23:17:36 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
else
|
|
|
|
{
|
2010-02-02 07:51:45 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle( data->gtor );
|
|
|
|
|
2010-07-24 02:57:39 +00:00
|
|
|
tr_torrentSetPriority( tor, gtr_priority_combo_get_value( GTK_COMBO_BOX( data->priority_combo ) ) );
|
2010-02-02 07:51:45 +00:00
|
|
|
|
2008-12-13 23:17:36 +00:00
|
|
|
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->run_check ) ) )
|
2010-02-02 07:51:45 +00:00
|
|
|
tr_torrentStart( tor );
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2009-06-11 16:17:48 +00:00
|
|
|
tr_core_add_torrent( data->core, data->gtor, FALSE );
|
2008-12-13 23:17:36 +00:00
|
|
|
|
|
|
|
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->trash_check ) ) )
|
2010-04-21 04:38:54 +00:00
|
|
|
gtr_file_trash_or_remove( data->filename );
|
2008-12-13 23:17:36 +00:00
|
|
|
|
|
|
|
save_recent_destination( data->core, data->downloadDir );
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_ctorFree( data->ctor );
|
|
|
|
g_free( data->filename );
|
2008-05-18 16:44:30 +00:00
|
|
|
g_free( data->downloadDir );
|
2008-02-13 03:00:21 +00:00
|
|
|
g_free( data );
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( dialog ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-03 02:11:15 +00:00
|
|
|
updateTorrent( struct AddData * o )
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2010-05-13 13:12:27 +00:00
|
|
|
const gboolean isLocalFile = tr_ctorGetSourceFile( o->ctor ) != NULL;
|
|
|
|
gtk_widget_set_sensitive( o->trash_check, isLocalFile );
|
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
if( !o->gtor )
|
2010-05-13 13:12:27 +00:00
|
|
|
{
|
|
|
|
file_list_clear( o->file_list );
|
|
|
|
gtk_widget_set_sensitive( o->file_list, FALSE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-24 01:37:04 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle( o->gtor );
|
|
|
|
tr_torrentSetDownloadDir( tor, o->downloadDir );
|
2010-05-13 13:12:27 +00:00
|
|
|
gtk_widget_set_sensitive( o->file_list, tr_torrentHasMetadata( tor ) );
|
|
|
|
file_list_set_torrent( o->file_list, tr_torrentId( tor ) );
|
2010-03-12 00:17:35 +00:00
|
|
|
tr_torrentVerify( tor );
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 03:37:02 +00:00
|
|
|
/**
|
|
|
|
* When the source .torrent file is deleted
|
|
|
|
* (such as, if it was a temp file that a web browser passed to us),
|
|
|
|
* gtk invokes this callback and `filename' will be NULL.
|
|
|
|
* The `filename' tests here are to prevent us from losing the current
|
|
|
|
* metadata when that happens.
|
|
|
|
*/
|
2008-02-13 03:00:21 +00:00
|
|
|
static void
|
2010-03-12 00:17:35 +00:00
|
|
|
sourceChanged( GtkFileChooserButton * b, gpointer gdata )
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2008-04-03 02:11:15 +00:00
|
|
|
struct AddData * data = gdata;
|
2010-03-12 00:17:35 +00:00
|
|
|
char * filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
/* maybe instantiate a torrent */
|
2010-05-13 13:12:27 +00:00
|
|
|
if( filename || !data->gtor )
|
2008-08-14 03:37:02 +00:00
|
|
|
{
|
2010-05-13 13:12:27 +00:00
|
|
|
int err = 0;
|
|
|
|
int new_file = 0;
|
2008-02-13 03:00:21 +00:00
|
|
|
tr_torrent * torrent;
|
2008-08-14 03:37:02 +00:00
|
|
|
|
2010-05-13 13:12:27 +00:00
|
|
|
if( filename && ( !data->filename || strcmp( filename, data->filename ) ) )
|
2008-08-14 03:37:02 +00:00
|
|
|
{
|
|
|
|
g_free( data->filename );
|
|
|
|
data->filename = g_strdup( filename );
|
|
|
|
tr_ctorSetMetainfoFromFile( data->ctor, data->filename );
|
|
|
|
new_file = 1;
|
|
|
|
}
|
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
tr_ctorSetDownloadDir( data->ctor, TR_FORCE, data->downloadDir );
|
2008-02-14 17:18:00 +00:00
|
|
|
tr_ctorSetPaused( data->ctor, TR_FORCE, TRUE );
|
|
|
|
tr_ctorSetDeleteSource( data->ctor, FALSE );
|
2008-08-14 03:37:02 +00:00
|
|
|
|
2009-04-02 17:30:29 +00:00
|
|
|
if( ( torrent = tr_torrentNew( data->ctor, &err ) ) )
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2008-08-14 03:37:02 +00:00
|
|
|
removeOldTorrent( data );
|
2008-02-13 03:00:21 +00:00
|
|
|
data->gtor = tr_torrent_new_preexisting( torrent );
|
2008-09-23 19:11:04 +00:00
|
|
|
}
|
|
|
|
else if( new_file )
|
|
|
|
{
|
|
|
|
addTorrentErrorDialog( GTK_WIDGET( b ), err, data->filename );
|
2008-08-14 03:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateTorrent( data );
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 03:37:02 +00:00
|
|
|
g_free( filename );
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-12 00:17:35 +00:00
|
|
|
downloadDirChanged( GtkFileChooserButton * b, gpointer gdata )
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2008-04-03 02:11:15 +00:00
|
|
|
struct AddData * data = gdata;
|
2010-03-12 00:17:35 +00:00
|
|
|
char * fname = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) );
|
2008-08-14 03:37:02 +00:00
|
|
|
|
|
|
|
if( fname && ( !data->downloadDir || strcmp( fname, data->downloadDir ) ) )
|
2008-04-13 01:36:53 +00:00
|
|
|
{
|
2008-05-18 16:44:30 +00:00
|
|
|
g_free( data->downloadDir );
|
2008-08-14 03:37:02 +00:00
|
|
|
data->downloadDir = g_strdup( fname );
|
2008-04-13 01:36:53 +00:00
|
|
|
updateTorrent( data );
|
|
|
|
}
|
2008-08-14 03:37:02 +00:00
|
|
|
|
|
|
|
g_free( fname );
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2008-03-19 20:34:35 +00:00
|
|
|
static void
|
|
|
|
addTorrentFilters( GtkFileChooser * chooser )
|
|
|
|
{
|
|
|
|
GtkFileFilter * filter;
|
|
|
|
|
|
|
|
filter = gtk_file_filter_new( );
|
|
|
|
gtk_file_filter_set_name( filter, _( "Torrent files" ) );
|
|
|
|
gtk_file_filter_add_pattern( filter, "*.torrent" );
|
|
|
|
gtk_file_chooser_add_filter( chooser, filter );
|
|
|
|
|
|
|
|
filter = gtk_file_filter_new( );
|
|
|
|
gtk_file_filter_set_name( filter, _( "All files" ) );
|
|
|
|
gtk_file_filter_add_pattern( filter, "*" );
|
|
|
|
gtk_file_chooser_add_filter( chooser, filter );
|
|
|
|
}
|
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2008-02-19 05:52:37 +00:00
|
|
|
GtkWidget*
|
2010-02-02 07:51:45 +00:00
|
|
|
addSingleTorrentDialog( GtkWindow * parent, TrCore * core, tr_ctor * ctor )
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int row;
|
|
|
|
int col;
|
|
|
|
const char * str;
|
|
|
|
GtkWidget * w;
|
|
|
|
GtkWidget * d;
|
|
|
|
GtkWidget * t;
|
|
|
|
GtkWidget * l;
|
2010-02-23 21:58:43 +00:00
|
|
|
GtkWidget * grab;
|
2009-06-11 14:51:21 +00:00
|
|
|
GtkWidget * source_chooser;
|
2008-04-03 02:11:15 +00:00
|
|
|
struct AddData * data;
|
2008-09-23 19:11:04 +00:00
|
|
|
uint8_t flag;
|
|
|
|
GSList * list;
|
|
|
|
GSList * walk;
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
/* make the dialog */
|
2010-02-02 07:51:45 +00:00
|
|
|
d = gtk_dialog_new_with_buttons( _( "Torrent Options" ), parent,
|
2008-09-23 19:11:04 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT |
|
|
|
|
GTK_DIALOG_NO_SEPARATOR,
|
|
|
|
NULL );
|
2010-02-23 21:58:43 +00:00
|
|
|
gtk_dialog_add_button( GTK_DIALOG( d ), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL );
|
|
|
|
grab = gtk_dialog_add_button( GTK_DIALOG( d ), GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT );
|
2008-02-28 14:48:23 +00:00
|
|
|
gtk_dialog_set_default_response( GTK_DIALOG( d ),
|
|
|
|
GTK_RESPONSE_ACCEPT );
|
|
|
|
gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ),
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1 );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
if( tr_ctorGetDownloadDir( ctor, TR_FORCE, &str ) )
|
2008-02-13 03:57:48 +00:00
|
|
|
g_assert_not_reached( );
|
2008-04-13 01:36:53 +00:00
|
|
|
g_assert( str );
|
2008-03-18 16:18:22 +00:00
|
|
|
|
2008-04-03 02:11:15 +00:00
|
|
|
data = g_new0( struct AddData, 1 );
|
2008-02-13 03:00:21 +00:00
|
|
|
data->core = core;
|
|
|
|
data->ctor = ctor;
|
|
|
|
data->filename = g_strdup( tr_ctorGetSourceFile( ctor ) );
|
2008-05-18 16:44:30 +00:00
|
|
|
data->downloadDir = g_strdup( str );
|
2010-05-13 13:12:27 +00:00
|
|
|
data->file_list = file_list_new( core, 0 );
|
2009-10-20 14:01:15 +00:00
|
|
|
str = _( "Mo_ve .torrent file to the trash" );
|
|
|
|
data->trash_check = gtk_check_button_new_with_mnemonic( str );
|
|
|
|
str = _( "_Start when added" );
|
|
|
|
data->run_check = gtk_check_button_new_with_mnemonic( str );
|
2008-03-18 16:18:22 +00:00
|
|
|
|
2010-07-24 02:57:39 +00:00
|
|
|
w = data->priority_combo = gtr_priority_combo_new( );
|
|
|
|
gtr_priority_combo_set_value( GTK_COMBO_BOX( w ), TR_PRI_NORMAL );
|
2010-02-02 07:51:45 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
g_signal_connect( G_OBJECT( d ), "response",
|
2008-04-03 02:11:15 +00:00
|
|
|
G_CALLBACK( addResponseCB ), data );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
t = gtk_table_new( 6, 2, FALSE );
|
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( t ), GUI_PAD_BIG );
|
|
|
|
gtk_table_set_row_spacings( GTK_TABLE( t ), GUI_PAD );
|
|
|
|
gtk_table_set_col_spacings( GTK_TABLE( t ), GUI_PAD_BIG );
|
|
|
|
|
|
|
|
row = col = 0;
|
2008-07-19 19:55:08 +00:00
|
|
|
l = gtk_label_new_with_mnemonic( _( "_Torrent file:" ) );
|
2008-02-13 03:00:21 +00:00
|
|
|
gtk_misc_set_alignment( GTK_MISC( l ), 0.0f, 0.5f );
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_table_attach( GTK_TABLE( t ), l, col, col + 1, row, row + 1, GTK_FILL, 0, 0, 0 );
|
2008-02-13 03:00:21 +00:00
|
|
|
++col;
|
2008-03-19 20:34:35 +00:00
|
|
|
w = gtk_file_chooser_button_new( _( "Select Source File" ),
|
2008-02-14 17:18:00 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN );
|
2009-06-11 14:51:21 +00:00
|
|
|
source_chooser = w;
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_table_attach( GTK_TABLE( t ), w, col, col + 1, row, row + 1, ~0, 0, 0, 0 );
|
2008-02-13 03:00:21 +00:00
|
|
|
gtk_label_set_mnemonic_widget( GTK_LABEL( l ), w );
|
2008-03-19 20:34:35 +00:00
|
|
|
addTorrentFilters( GTK_FILE_CHOOSER( w ) );
|
2008-05-06 01:43:24 +00:00
|
|
|
g_signal_connect( w, "selection-changed",
|
|
|
|
G_CALLBACK( sourceChanged ), data );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
++row;
|
|
|
|
col = 0;
|
2008-03-19 17:14:47 +00:00
|
|
|
l = gtk_label_new_with_mnemonic( _( "_Destination folder:" ) );
|
2008-02-13 03:00:21 +00:00
|
|
|
gtk_misc_set_alignment( GTK_MISC( l ), 0.0f, 0.5f );
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_table_attach( GTK_TABLE( t ), l, col, col + 1, row, row + 1, GTK_FILL, 0, 0, 0 );
|
2008-02-13 03:00:21 +00:00
|
|
|
++col;
|
2010-02-02 07:51:45 +00:00
|
|
|
w = gtk_file_chooser_button_new( _( "Select Destination Folder" ),
|
2008-09-23 19:11:04 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
|
2010-03-09 22:00:43 +00:00
|
|
|
if( !gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( w ),
|
|
|
|
data->downloadDir ) )
|
2008-05-18 16:44:30 +00:00
|
|
|
g_warning( "couldn't select '%s'", data->downloadDir );
|
2008-07-02 00:17:27 +00:00
|
|
|
list = get_recent_destinations( );
|
2008-09-23 19:11:04 +00:00
|
|
|
for( walk = list; walk; walk = walk->next )
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_file_chooser_add_shortcut_folder( GTK_FILE_CHOOSER( w ), walk->data, NULL );
|
2008-07-02 00:17:27 +00:00
|
|
|
g_slist_free( list );
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_table_attach( GTK_TABLE( t ), w, col, col + 1, row, row + 1, ~0, 0, 0, 0 );
|
2008-02-13 03:00:21 +00:00
|
|
|
gtk_label_set_mnemonic_widget( GTK_LABEL( l ), w );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( w, "selection-changed",
|
|
|
|
G_CALLBACK( downloadDirChanged ), data );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
++row;
|
|
|
|
col = 0;
|
2010-05-13 13:12:27 +00:00
|
|
|
w = data->file_list;
|
2008-02-13 03:00:21 +00:00
|
|
|
gtk_widget_set_size_request ( w, 466u, 300u );
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_table_attach_defaults( GTK_TABLE( t ), w, col, col + 2, row, row + 1 );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
++row;
|
|
|
|
col = 0;
|
2010-02-02 07:51:45 +00:00
|
|
|
w = gtk_label_new_with_mnemonic( _( "Torrent _priority:" ) );
|
|
|
|
gtk_misc_set_alignment( GTK_MISC( w ), 0.0f, 0.5f );
|
2010-02-24 20:12:07 +00:00
|
|
|
gtk_table_attach( GTK_TABLE( t ), w, col, col + 1, row, row + 1, ~0, 0, 0, 0 );
|
2010-02-02 07:51:45 +00:00
|
|
|
++col;
|
2010-02-24 20:12:07 +00:00
|
|
|
gtk_table_attach( GTK_TABLE( t ), data->priority_combo, col, col + 1, row, row + 1, ~0, 0, 0, 0 );
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_label_set_mnemonic_widget( GTK_LABEL( w ), data->priority_combo );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
++row;
|
|
|
|
col = 0;
|
2008-03-18 19:14:21 +00:00
|
|
|
w = data->run_check;
|
|
|
|
if( tr_ctorGetPaused( ctor, TR_FORCE, &flag ) )
|
2008-03-09 15:27:08 +00:00
|
|
|
g_assert_not_reached( );
|
2008-03-18 19:14:21 +00:00
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), !flag );
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_table_attach( GTK_TABLE( t ), w, col, col + 2, row, row + 1, GTK_FILL, 0, 0, 0 );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
++row;
|
|
|
|
col = 0;
|
2008-03-18 19:14:21 +00:00
|
|
|
w = data->trash_check;
|
|
|
|
if( tr_ctorGetDeleteSource( ctor, &flag ) )
|
2008-02-13 03:57:48 +00:00
|
|
|
g_assert_not_reached( );
|
2008-03-18 19:14:21 +00:00
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), flag );
|
2010-02-02 07:51:45 +00:00
|
|
|
gtk_table_attach( GTK_TABLE( t ), w, col, col + 2, row, row + 1, GTK_FILL, 0, 0, 0 );
|
|
|
|
|
2009-06-11 14:51:21 +00:00
|
|
|
/* trigger sourceChanged, either directly or indirectly,
|
|
|
|
* so that it creates the tor/gtor objects */
|
|
|
|
w = source_chooser;
|
|
|
|
if( data->filename )
|
|
|
|
gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( w ), data->filename );
|
|
|
|
else
|
|
|
|
sourceChanged( GTK_FILE_CHOOSER_BUTTON( w ), data );
|
|
|
|
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( GTK_DIALOG( d )->vbox ), t, TRUE, TRUE, 0 );
|
2010-02-23 21:58:43 +00:00
|
|
|
|
|
|
|
gtk_widget_grab_focus( grab );
|
2008-02-13 03:00:21 +00:00
|
|
|
gtk_widget_show_all( d );
|
2008-02-19 05:52:37 +00:00
|
|
|
return d;
|
2008-02-13 03:00:21 +00:00
|
|
|
}
|
2008-03-18 01:22:11 +00:00
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onAddDialogResponse( GtkDialog * dialog,
|
|
|
|
int response,
|
|
|
|
gpointer core )
|
2008-03-18 01:22:11 +00:00
|
|
|
{
|
2008-03-19 14:54:32 +00:00
|
|
|
char * folder;
|
|
|
|
|
|
|
|
/* remember this folder the next time we use this dialog */
|
|
|
|
folder = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER( dialog ) );
|
2008-03-18 20:41:27 +00:00
|
|
|
pref_string_set( PREF_KEY_OPEN_DIALOG_FOLDER, folder );
|
|
|
|
g_free( folder );
|
|
|
|
|
2008-03-19 14:54:32 +00:00
|
|
|
if( response == GTK_RESPONSE_ACCEPT )
|
|
|
|
{
|
2008-10-28 19:49:33 +00:00
|
|
|
GtkFileChooser * chooser = GTK_FILE_CHOOSER( dialog );
|
|
|
|
GtkWidget * w = gtk_file_chooser_get_extra_widget( chooser );
|
|
|
|
GtkToggleButton * tb = GTK_TOGGLE_BUTTON( w );
|
|
|
|
const gboolean showOptions = gtk_toggle_button_get_active( tb );
|
2008-03-19 14:54:32 +00:00
|
|
|
const pref_flag_t start = PREF_FLAG_DEFAULT;
|
2008-10-28 19:49:33 +00:00
|
|
|
const pref_flag_t prompt = showOptions
|
|
|
|
? PREF_FLAG_TRUE
|
|
|
|
: PREF_FLAG_FALSE;
|
|
|
|
GSList * l = gtk_file_chooser_get_filenames( chooser );
|
|
|
|
|
2009-06-11 16:17:48 +00:00
|
|
|
tr_core_add_list( core, l, start, prompt, FALSE );
|
2008-03-18 01:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( dialog ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
2008-04-03 02:11:15 +00:00
|
|
|
addDialog( GtkWindow * parent,
|
2008-09-23 19:11:04 +00:00
|
|
|
TrCore * core )
|
2008-03-18 01:22:11 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
GtkWidget * w;
|
|
|
|
GtkWidget * c;
|
2008-06-12 16:25:36 +00:00
|
|
|
const char * folder;
|
2008-03-18 01:22:11 +00:00
|
|
|
|
2008-04-03 02:13:13 +00:00
|
|
|
w = gtk_file_chooser_dialog_new( _( "Add a Torrent" ), parent,
|
2008-03-18 01:22:11 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2008-04-03 02:11:15 +00:00
|
|
|
GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
|
2008-03-18 01:22:11 +00:00
|
|
|
NULL );
|
|
|
|
gtk_dialog_set_alternative_button_order( GTK_DIALOG( w ),
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1 );
|
|
|
|
gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( w ), TRUE );
|
2008-03-19 20:34:35 +00:00
|
|
|
addTorrentFilters( GTK_FILE_CHOOSER( w ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( w, "response", G_CALLBACK(
|
|
|
|
onAddDialogResponse ), core );
|
2008-03-18 01:22:11 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
if( ( folder = pref_string_get( PREF_KEY_OPEN_DIALOG_FOLDER ) ) )
|
2008-03-18 20:41:27 +00:00
|
|
|
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( w ), folder );
|
2008-03-19 14:54:32 +00:00
|
|
|
|
2009-10-20 14:01:15 +00:00
|
|
|
c = gtk_check_button_new_with_mnemonic( _( "Show _options dialog" ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( c ),
|
|
|
|
pref_flag_get( PREF_KEY_OPTIONS_PROMPT ) );
|
2008-03-19 14:54:32 +00:00
|
|
|
gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER( w ), c );
|
|
|
|
gtk_widget_show( c );
|
2008-03-18 20:41:27 +00:00
|
|
|
|
2008-03-18 01:22:11 +00:00
|
|
|
gtk_widget_show( w );
|
|
|
|
return w;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static void
|
|
|
|
onAddURLResponse( GtkDialog * dialog, int response, gpointer user_data )
|
|
|
|
{
|
|
|
|
gboolean destroy = TRUE;
|
|
|
|
|
|
|
|
if( response == GTK_RESPONSE_ACCEPT )
|
|
|
|
{
|
|
|
|
GtkWidget * e = GTK_WIDGET( g_object_get_data( G_OBJECT( dialog ), "url-entry" ) );
|
|
|
|
char * url = g_strdup( gtk_entry_get_text( GTK_ENTRY( e ) ) );
|
|
|
|
g_strstrip( url );
|
|
|
|
|
|
|
|
if( url && *url )
|
|
|
|
{
|
|
|
|
TrCore * core = user_data;
|
|
|
|
|
2009-11-29 07:42:39 +00:00
|
|
|
if( gtr_is_supported_url( url ) || gtr_is_magnet_link( url )
|
|
|
|
|| gtr_is_hex_hashcode( url ) )
|
2009-11-22 16:20:22 +00:00
|
|
|
{
|
|
|
|
tr_core_add_from_url( core, url );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-05 13:59:44 +00:00
|
|
|
gtr_unrecognized_url_dialog( GTK_WIDGET( dialog ), url );
|
2009-11-22 16:20:22 +00:00
|
|
|
destroy = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-01-20 17:20:35 +00:00
|
|
|
|
|
|
|
g_free( url );
|
2009-11-22 16:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( destroy )
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( dialog ) );
|
|
|
|
}
|
|
|
|
|
2010-04-11 14:18:29 +00:00
|
|
|
static void
|
|
|
|
paste_clipboard_url_into_entry( GtkWidget * e )
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
char * text[] = {
|
|
|
|
gtk_clipboard_wait_for_text( gtk_clipboard_get( GDK_SELECTION_PRIMARY ) ),
|
|
|
|
gtk_clipboard_wait_for_text( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ) )
|
|
|
|
};
|
|
|
|
|
|
|
|
for( i=0; i<G_N_ELEMENTS(text); ++i ) {
|
|
|
|
char * s = text[i];
|
|
|
|
if( s && ( gtr_is_supported_url( s ) || gtr_is_magnet_link( s ) ) ) {
|
|
|
|
gtk_entry_set_text( GTK_ENTRY( e ), s );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i=0; i<G_N_ELEMENTS(text); ++i )
|
|
|
|
g_free( text[i] );
|
|
|
|
}
|
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
GtkWidget*
|
|
|
|
addURLDialog( GtkWindow * parent, TrCore * core )
|
|
|
|
{
|
|
|
|
int row;
|
|
|
|
GtkWidget * e;
|
|
|
|
GtkWidget * t;
|
|
|
|
GtkWidget * w;
|
|
|
|
|
2009-11-24 17:10:40 +00:00
|
|
|
w = gtk_dialog_new_with_buttons( _( "Add URL" ), parent,
|
2009-11-25 08:22:57 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
|
2009-11-22 16:20:22 +00:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL );
|
|
|
|
gtk_dialog_set_alternative_button_order( GTK_DIALOG( w ),
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1 );
|
|
|
|
g_signal_connect( w, "response", G_CALLBACK( onAddURLResponse ), core );
|
|
|
|
|
|
|
|
row = 0;
|
|
|
|
t = hig_workarea_create( );
|
|
|
|
hig_workarea_add_section_title( t, &row, _( "Add torrent from URL" ) );
|
|
|
|
e = gtk_entry_new( );
|
2010-06-30 23:40:25 +00:00
|
|
|
gtk_widget_set_size_request( e, 400, -1 );
|
2010-04-11 14:18:29 +00:00
|
|
|
paste_clipboard_url_into_entry( e );
|
2009-11-22 16:20:22 +00:00
|
|
|
g_object_set_data( G_OBJECT( w ), "url-entry", e );
|
|
|
|
hig_workarea_add_row( t, &row, _( "_URL" ), e, NULL );
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( GTK_DIALOG( w )->vbox ), t, TRUE, TRUE, 0 );
|
|
|
|
gtk_widget_show_all( t );
|
|
|
|
gtk_widget_show( w );
|
|
|
|
return w;
|
|
|
|
}
|