2007-06-18 03:40:41 +00:00
|
|
|
/*
|
2010-01-04 21:00:47 +00:00
|
|
|
* This file Copyright (C) 2007-2010 Mnemosyne LLC
|
2007-06-18 03:40:41 +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.
|
2007-06-18 03:40:41 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2007-08-18 17:19:49 +00:00
|
|
|
* $Id$
|
2007-06-18 03:40:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/makemeta.h>
|
2010-07-07 22:50:18 +00:00
|
|
|
#include <libtransmission/utils.h> /* tr_formatter_mem_B() */
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-10-02 15:29:45 +00:00
|
|
|
#include "conf.h"
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "hig.h"
|
|
|
|
#include "makemeta-ui.h"
|
2009-09-17 01:28:45 +00:00
|
|
|
#include "tr-core.h"
|
2010-02-01 04:54:10 +00:00
|
|
|
#include "tr-prefs.h"
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
#define FILE_CHOSEN_KEY "file-is-chosen"
|
2008-05-07 04:06:07 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
char * target;
|
|
|
|
guint progress_tag;
|
2010-08-02 20:55:11 +00:00
|
|
|
GtkWidget * file_radio;
|
2009-09-17 01:28:45 +00:00
|
|
|
GtkWidget * file_chooser;
|
2010-08-02 20:55:11 +00:00
|
|
|
GtkWidget * folder_radio;
|
2009-09-17 01:28:45 +00:00
|
|
|
GtkWidget * folder_chooser;
|
2008-10-28 19:49:33 +00:00
|
|
|
GtkWidget * pieces_lb;
|
2009-09-17 01:28:45 +00:00
|
|
|
GtkWidget * destination_chooser;
|
|
|
|
GtkWidget * comment_check;
|
2008-10-28 19:49:33 +00:00
|
|
|
GtkWidget * comment_entry;
|
|
|
|
GtkWidget * private_check;
|
2009-09-17 01:28:45 +00:00
|
|
|
GtkWidget * progress_label;
|
|
|
|
GtkWidget * progress_bar;
|
|
|
|
GtkWidget * progress_dialog;
|
2008-10-28 19:49:33 +00:00
|
|
|
GtkWidget * dialog;
|
2009-09-17 01:28:45 +00:00
|
|
|
GtkTextBuffer * announce_text_buffer;
|
|
|
|
TrCore * core;
|
|
|
|
tr_metainfo_builder * builder;
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
MakeMetaUI;
|
|
|
|
|
|
|
|
static void
|
|
|
|
freeMetaUI( gpointer p )
|
|
|
|
{
|
2008-04-17 19:54:22 +00:00
|
|
|
MakeMetaUI * ui = p;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2010-01-20 14:16:44 +00:00
|
|
|
tr_metaInfoBuilderFree( ui->builder );
|
2010-01-20 14:27:48 +00:00
|
|
|
g_free( ui->target );
|
2008-09-23 19:11:04 +00:00
|
|
|
memset( ui, ~0, sizeof( MakeMetaUI ) );
|
2007-06-18 03:40:41 +00:00
|
|
|
g_free( ui );
|
|
|
|
}
|
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
static gboolean
|
|
|
|
onProgressDialogRefresh( gpointer data )
|
|
|
|
{
|
2009-12-07 04:06:14 +00:00
|
|
|
char * str = NULL;
|
2009-09-17 01:28:45 +00:00
|
|
|
MakeMetaUI * ui = data;
|
|
|
|
const tr_metainfo_builder * b = ui->builder;
|
|
|
|
GtkDialog * d = GTK_DIALOG( ui->progress_dialog );
|
|
|
|
GtkProgressBar * p = GTK_PROGRESS_BAR( ui->progress_bar );
|
2010-07-07 22:50:18 +00:00
|
|
|
const double fraction = b->pieceCount ? ((double)b->pieceIndex / b->pieceCount) : 0;
|
|
|
|
char * base = g_path_get_basename( b->top );
|
2009-09-17 01:28:45 +00:00
|
|
|
|
|
|
|
/* progress label */
|
|
|
|
if( !b->isDone )
|
|
|
|
str = g_strdup_printf( _( "Creating \"%s\"" ), base );
|
|
|
|
else if( b->result == TR_MAKEMETA_OK )
|
|
|
|
str = g_strdup_printf( _( "Created \"%s\"!" ), base );
|
|
|
|
else if( b->result == TR_MAKEMETA_URL )
|
|
|
|
str = g_strdup_printf( _( "Error: invalid announce URL \"%s\"" ), b->errfile );
|
|
|
|
else if( b->result == TR_MAKEMETA_CANCELLED )
|
|
|
|
str = g_strdup_printf( _( "Cancelled" ) );
|
|
|
|
else if( b->result == TR_MAKEMETA_IO_READ )
|
|
|
|
str = g_strdup_printf( _( "Error reading \"%s\": %s" ), b->errfile, g_strerror( b->my_errno ) );
|
|
|
|
else if( b->result == TR_MAKEMETA_IO_WRITE )
|
|
|
|
str = g_strdup_printf( _( "Error writing \"%s\": %s" ), b->errfile, g_strerror( b->my_errno ) );
|
2009-12-07 04:06:14 +00:00
|
|
|
else
|
|
|
|
g_assert_not_reached( );
|
|
|
|
|
|
|
|
if( str != NULL ) {
|
|
|
|
gtk_label_set_text( GTK_LABEL( ui->progress_label ), str );
|
|
|
|
g_free( str );
|
|
|
|
}
|
2009-09-17 01:28:45 +00:00
|
|
|
|
|
|
|
/* progress bar */
|
|
|
|
if( !b->pieceIndex )
|
|
|
|
str = g_strdup( "" );
|
|
|
|
else {
|
|
|
|
char sizebuf[128];
|
|
|
|
tr_strlsize( sizebuf, (uint64_t)b->pieceIndex *
|
|
|
|
(uint64_t)b->pieceSize, sizeof( sizebuf ) );
|
|
|
|
/* how much data we've scanned through to generate checksums */
|
|
|
|
str = g_strdup_printf( _( "Scanned %s" ), sizebuf );
|
|
|
|
}
|
|
|
|
gtk_progress_bar_set_fraction( p, fraction );
|
|
|
|
gtk_progress_bar_set_text( p, str );
|
|
|
|
g_free( str );
|
|
|
|
|
|
|
|
/* buttons */
|
|
|
|
gtk_dialog_set_response_sensitive( d, GTK_RESPONSE_CANCEL, !b->isDone );
|
|
|
|
gtk_dialog_set_response_sensitive( d, GTK_RESPONSE_CLOSE, b->isDone );
|
|
|
|
gtk_dialog_set_response_sensitive( d, GTK_RESPONSE_ACCEPT, b->isDone && !b->result );
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
g_free( base );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
onProgressDialogDestroyed( gpointer data, GObject * dead UNUSED )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
MakeMetaUI * ui = data;
|
|
|
|
g_source_remove( ui->progress_tag );
|
2008-01-28 04:27:22 +00:00
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-01-28 04:27:22 +00:00
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
addTorrent( MakeMetaUI * ui )
|
2008-01-28 04:27:22 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
char * path;
|
|
|
|
const tr_metainfo_builder * b = ui->builder;
|
|
|
|
tr_ctor * ctor = tr_ctorNew( tr_core_session( ui->core ) );
|
2008-01-28 04:27:22 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
tr_ctorSetMetainfoFromFile( ctor, ui->target );
|
2008-01-28 04:27:22 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
path = g_path_get_dirname( b->top );
|
|
|
|
tr_ctorSetDownloadDir( ctor, TR_FORCE, path );
|
|
|
|
g_free( path );
|
2008-01-28 04:27:22 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
tr_core_add_ctor( ui->core, ctor );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
static void
|
|
|
|
onProgressDialogResponse( GtkDialog * d, int response, gpointer data )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
MakeMetaUI * ui = data;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
switch( response )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
ui->builder->abortFlag = TRUE;
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( d ) );
|
|
|
|
break;
|
|
|
|
case GTK_RESPONSE_ACCEPT:
|
|
|
|
addTorrent( ui );
|
|
|
|
/* fall-through */
|
|
|
|
case GTK_RESPONSE_CLOSE:
|
|
|
|
gtk_widget_destroy( ui->builder->result ? GTK_WIDGET( d ) : ui->dialog );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert( 0 && "unhandled response" );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
makeProgressDialog( GtkWidget * parent, MakeMetaUI * ui )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
GtkWidget *d, *l, *w, *v, *fr;
|
|
|
|
|
|
|
|
d = gtk_dialog_new_with_buttons( _( "New Torrent" ),
|
|
|
|
GTK_WINDOW( parent ),
|
|
|
|
GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
|
|
|
GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL );
|
|
|
|
ui->progress_dialog = d;
|
|
|
|
g_signal_connect( d, "response", G_CALLBACK( onProgressDialogResponse ), ui );
|
|
|
|
|
|
|
|
fr = gtk_frame_new( NULL );
|
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( fr ), GUI_PAD_BIG );
|
|
|
|
gtk_frame_set_shadow_type( GTK_FRAME( fr ), GTK_SHADOW_NONE );
|
|
|
|
v = gtk_vbox_new( TRUE, GUI_PAD );
|
|
|
|
gtk_container_add( GTK_CONTAINER( fr ), v );
|
|
|
|
|
|
|
|
l = gtk_label_new( _( "Creating torrent..." ) );
|
|
|
|
gtk_misc_set_alignment( GTK_MISC( l ), 0.0, 0.5 );
|
|
|
|
gtk_label_set_justify( GTK_LABEL( l ), GTK_JUSTIFY_LEFT );
|
|
|
|
ui->progress_label = l;
|
|
|
|
gtk_box_pack_start( GTK_BOX( v ), l, FALSE, FALSE, 0 );
|
|
|
|
|
|
|
|
w = gtk_progress_bar_new( );
|
|
|
|
ui->progress_bar = w;
|
|
|
|
gtk_box_pack_start( GTK_BOX( v ), w, FALSE, FALSE, 0 );
|
|
|
|
|
2010-02-01 04:54:10 +00:00
|
|
|
ui->progress_tag = gtr_timeout_add_seconds( SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS, onProgressDialogRefresh, ui );
|
2009-09-17 01:28:45 +00:00
|
|
|
g_object_weak_ref( G_OBJECT( d ), onProgressDialogDestroyed, ui );
|
|
|
|
onProgressDialogRefresh( ui );
|
|
|
|
|
|
|
|
gtk_box_pack_start( GTK_BOX( GTK_DIALOG( d )->vbox ), fr, TRUE, TRUE, 0 );
|
|
|
|
gtk_widget_show_all( d );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
onResponse( GtkDialog* d, int response, gpointer user_data )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
MakeMetaUI * ui = user_data;
|
|
|
|
|
|
|
|
if( response == GTK_RESPONSE_ACCEPT )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
if( ui->builder != NULL )
|
2008-01-28 04:27:22 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
int tier;
|
|
|
|
GtkTextIter start, end;
|
|
|
|
char * dir;
|
|
|
|
char * base;
|
|
|
|
char * tracker_text;
|
|
|
|
char ** tracker_strings;
|
|
|
|
GtkEntry * c_entry = GTK_ENTRY( ui->comment_entry );
|
|
|
|
GtkToggleButton * p_check = GTK_TOGGLE_BUTTON( ui->private_check );
|
|
|
|
GtkToggleButton * c_check = GTK_TOGGLE_BUTTON( ui->comment_check );
|
|
|
|
const char * comment = gtk_entry_get_text( c_entry );
|
|
|
|
const gboolean isPrivate = gtk_toggle_button_get_active( p_check );
|
|
|
|
const gboolean useComment = gtk_toggle_button_get_active( c_check );
|
|
|
|
tr_tracker_info * trackers;
|
|
|
|
|
|
|
|
/* destination file */
|
|
|
|
dir = gtk_file_chooser_get_filename(
|
|
|
|
GTK_FILE_CHOOSER( ui->destination_chooser ) );
|
|
|
|
base = g_path_get_basename( ui->builder->top );
|
|
|
|
g_free( ui->target );
|
|
|
|
ui->target = g_strdup_printf( "%s/%s.torrent", dir, base );
|
|
|
|
|
|
|
|
/* build the array of trackers */
|
|
|
|
gtk_text_buffer_get_bounds( ui->announce_text_buffer, &start, &end );
|
|
|
|
tracker_text = gtk_text_buffer_get_text( ui->announce_text_buffer,
|
|
|
|
&start, &end, FALSE );
|
|
|
|
tracker_strings = g_strsplit( tracker_text, "\n", 0 );
|
|
|
|
for( i=0; tracker_strings[i]; )
|
|
|
|
++i;
|
|
|
|
trackers = g_new0( tr_tracker_info, i );
|
|
|
|
for( i=n=tier=0; tracker_strings[i]; ++i ) {
|
|
|
|
const char * str = tracker_strings[i];
|
|
|
|
if( !*str )
|
|
|
|
++tier;
|
|
|
|
else {
|
|
|
|
trackers[n].tier = tier;
|
|
|
|
trackers[n].announce = tracker_strings[i];
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
}
|
2008-01-28 04:27:22 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
/* build the .torrent */
|
|
|
|
makeProgressDialog( GTK_WIDGET( d ), ui );
|
|
|
|
tr_makeMetaInfo( ui->builder, ui->target, trackers, n,
|
|
|
|
useComment ? comment : NULL, isPrivate );
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
g_free( trackers );
|
|
|
|
g_strfreev( tracker_strings );
|
|
|
|
g_free( tracker_text );
|
|
|
|
g_free( base );
|
|
|
|
g_free( dir );
|
2008-01-28 04:27:22 +00:00
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
2009-09-17 01:28:45 +00:00
|
|
|
else if( response == GTK_RESPONSE_CLOSE )
|
2008-10-02 15:29:45 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
gtk_widget_destroy( GTK_WIDGET( d ) );
|
2008-10-02 15:29:45 +00:00
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
onSourceToggled( GtkToggleButton * tb, gpointer user_data )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
gtk_widget_set_sensitive( GTK_WIDGET( user_data ),
|
|
|
|
gtk_toggle_button_get_active( tb ) );
|
|
|
|
}
|
2008-10-14 03:39:16 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
static void
|
|
|
|
updatePiecesLabel( MakeMetaUI * ui )
|
|
|
|
{
|
|
|
|
const tr_metainfo_builder * builder = ui->builder;
|
|
|
|
const char * filename = builder ? builder->top : NULL;
|
|
|
|
GString * gstr = g_string_new( NULL );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
g_string_append( gstr, "<i>" );
|
2008-03-19 19:23:54 +00:00
|
|
|
if( !filename )
|
2009-09-17 01:28:45 +00:00
|
|
|
{
|
|
|
|
g_string_append( gstr, _( "No source selected" ) );
|
2008-03-19 19:23:54 +00:00
|
|
|
}
|
2009-09-17 01:28:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
tr_strlsize( buf, builder->totalSize, sizeof( buf ) );
|
|
|
|
g_string_append_printf( gstr, ngettext( "%1$s; %2$'d File",
|
|
|
|
"%1$s; %2$'d Files",
|
|
|
|
builder->fileCount ),
|
|
|
|
buf, builder->fileCount );
|
|
|
|
g_string_append( gstr, "; " );
|
2010-07-07 22:50:18 +00:00
|
|
|
|
|
|
|
tr_formatter_mem_B( buf, builder->pieceSize, sizeof( buf ) );
|
2009-09-17 01:28:45 +00:00
|
|
|
g_string_append_printf( gstr, ngettext( "%1$'d Piece @ %2$s",
|
|
|
|
"%1$'d Pieces @ %2$s",
|
|
|
|
builder->pieceCount ),
|
|
|
|
builder->pieceCount, buf );
|
2008-03-19 19:23:54 +00:00
|
|
|
}
|
2009-09-17 01:28:45 +00:00
|
|
|
g_string_append( gstr, "</i>" );
|
|
|
|
gtk_label_set_markup ( GTK_LABEL( ui->pieces_lb ), gstr->str );
|
|
|
|
g_string_free( gstr, TRUE );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2008-05-07 04:06:07 +00:00
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
setFilename( MakeMetaUI * ui, const char * filename )
|
2008-05-07 04:06:07 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
if( ui->builder ) {
|
2008-06-01 15:46:20 +00:00
|
|
|
tr_metaInfoBuilderFree( ui->builder );
|
2009-09-17 01:28:45 +00:00
|
|
|
ui->builder = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( filename )
|
|
|
|
ui->builder = tr_metaInfoBuilderCreate( filename );
|
|
|
|
|
|
|
|
updatePiecesLabel( ui );
|
2008-06-01 15:46:20 +00:00
|
|
|
}
|
2008-05-07 04:06:07 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
static void
|
|
|
|
onChooserChosen( GtkFileChooser * chooser, gpointer user_data )
|
2008-06-01 15:46:20 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
char * filename;
|
|
|
|
MakeMetaUI * ui = user_data;
|
|
|
|
|
|
|
|
g_object_set_data( G_OBJECT( chooser ), FILE_CHOSEN_KEY,
|
|
|
|
GINT_TO_POINTER( TRUE ) );
|
|
|
|
|
|
|
|
filename = gtk_file_chooser_get_filename( chooser );
|
|
|
|
setFilename( ui, filename );
|
|
|
|
g_free( filename );
|
2008-05-07 04:06:07 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 04:52:03 +00:00
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
onSourceToggled2( GtkToggleButton * tb, GtkWidget * chooser, MakeMetaUI * ui )
|
2007-06-18 04:52:03 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
if( gtk_toggle_button_get_active( tb ) )
|
2008-05-07 04:06:07 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
if( g_object_get_data( G_OBJECT( chooser ), FILE_CHOSEN_KEY ) != NULL )
|
|
|
|
onChooserChosen( GTK_FILE_CHOOSER( chooser ), ui );
|
|
|
|
else
|
|
|
|
setFilename( ui, NULL );
|
2008-05-07 04:06:07 +00:00
|
|
|
}
|
2007-06-18 04:52:03 +00:00
|
|
|
}
|
2008-06-01 15:46:20 +00:00
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
onFolderToggled( GtkToggleButton * tb, gpointer data )
|
2008-06-01 15:46:20 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
MakeMetaUI * ui = data;
|
|
|
|
onSourceToggled2( tb, ui->folder_chooser, ui );
|
2008-06-01 15:46:20 +00:00
|
|
|
}
|
|
|
|
static void
|
2009-09-17 01:28:45 +00:00
|
|
|
onFileToggled( GtkToggleButton * tb, gpointer data )
|
|
|
|
{
|
|
|
|
MakeMetaUI * ui = data;
|
|
|
|
onSourceToggled2( tb, ui->file_chooser, ui );
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
getDefaultSavePath( void )
|
2008-06-01 15:46:20 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
const char * path;
|
|
|
|
#if GLIB_CHECK_VERSION( 2,14,0 )
|
|
|
|
path = g_get_user_special_dir( G_USER_DIRECTORY_DESKTOP );
|
|
|
|
#else
|
|
|
|
path = g_get_home_dir( );
|
|
|
|
#endif
|
|
|
|
return path;
|
2008-06-01 15:46:20 +00:00
|
|
|
}
|
|
|
|
|
2010-08-02 20:55:11 +00:00
|
|
|
static void
|
|
|
|
on_drag_data_received( GtkWidget * widget UNUSED,
|
2010-08-02 22:31:31 +00:00
|
|
|
GdkDragContext * drag_context,
|
2010-08-02 20:55:11 +00:00
|
|
|
gint x UNUSED,
|
|
|
|
gint y UNUSED,
|
|
|
|
GtkSelectionData * selection_data,
|
|
|
|
guint info UNUSED,
|
2010-08-02 22:31:31 +00:00
|
|
|
guint time_,
|
2010-08-02 20:55:11 +00:00
|
|
|
gpointer user_data )
|
|
|
|
{
|
2010-08-02 22:31:31 +00:00
|
|
|
gboolean success = FALSE;
|
2010-08-02 20:55:11 +00:00
|
|
|
MakeMetaUI * ui = user_data;
|
|
|
|
char ** uris = gtk_selection_data_get_uris( selection_data );
|
|
|
|
|
|
|
|
if( uris && uris[0] )
|
|
|
|
{
|
|
|
|
const char * uri = uris[ 0 ];
|
|
|
|
gchar * filename = g_filename_from_uri( uri, NULL, NULL );
|
|
|
|
|
|
|
|
if( g_file_test( filename, G_FILE_TEST_IS_DIR ) )
|
|
|
|
{
|
|
|
|
/* a directory was dragged onto the dialog... */
|
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( ui->folder_radio ), TRUE );
|
|
|
|
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( ui->folder_chooser ), filename );
|
2010-08-02 22:31:31 +00:00
|
|
|
success = TRUE;
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
else if( g_file_test( filename, G_FILE_TEST_IS_REGULAR ) )
|
|
|
|
{
|
|
|
|
/* a file was dragged on to the dialog... */
|
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( ui->file_radio ), TRUE );
|
|
|
|
gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( ui->file_chooser ), filename );
|
2010-08-02 22:31:31 +00:00
|
|
|
success = TRUE;
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free( filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev( uris );
|
2010-08-02 22:31:31 +00:00
|
|
|
gtk_drag_finish( drag_context, success, FALSE, time_ );
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkWidget*
|
2009-09-17 01:28:45 +00:00
|
|
|
make_meta_ui( GtkWindow * parent, TrCore * core )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2009-09-17 01:28:45 +00:00
|
|
|
int row = 0;
|
|
|
|
const char * str;
|
2009-10-04 02:32:38 +00:00
|
|
|
GtkWidget * d, *t, *w, *l, *fr, *sw, *v;
|
2009-09-17 01:28:45 +00:00
|
|
|
GSList * slist;
|
2007-06-18 03:40:41 +00:00
|
|
|
MakeMetaUI * ui = g_new0 ( MakeMetaUI, 1 );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
ui->core = core;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
d = gtk_dialog_new_with_buttons( _( "New Torrent" ),
|
2007-06-18 03:40:41 +00:00
|
|
|
parent,
|
2008-09-23 19:11:04 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT |
|
|
|
|
GTK_DIALOG_NO_SEPARATOR,
|
2008-01-28 04:27:22 +00:00
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
2007-06-18 03:40:41 +00:00
|
|
|
GTK_STOCK_NEW, GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL );
|
|
|
|
ui->dialog = d;
|
2009-09-17 01:28:45 +00:00
|
|
|
g_signal_connect( d, "response", G_CALLBACK( onResponse ), ui );
|
|
|
|
g_object_set_data_full( G_OBJECT( d ), "ui", ui, freeMetaUI );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
t = hig_workarea_create ( );
|
|
|
|
|
2009-09-17 01:28:45 +00:00
|
|
|
hig_workarea_add_section_title ( t, &row, _( "Files" ) );
|
|
|
|
|
|
|
|
str = _( "Sa_ve to:" );
|
|
|
|
w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
|
2010-03-09 22:00:43 +00:00
|
|
|
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( w ), getDefaultSavePath( ) );
|
2009-09-17 01:28:45 +00:00
|
|
|
ui->destination_chooser = w;
|
|
|
|
hig_workarea_add_row( t, &row, str, w, NULL );
|
|
|
|
|
|
|
|
l = gtk_radio_button_new_with_mnemonic( NULL, _( "Source F_older:" ) );
|
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( l ), FALSE );
|
|
|
|
w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
|
|
|
|
g_signal_connect( l, "toggled", G_CALLBACK( onFolderToggled ), ui );
|
|
|
|
g_signal_connect( l, "toggled", G_CALLBACK( onSourceToggled ), w );
|
|
|
|
g_signal_connect( w, "selection-changed", G_CALLBACK( onChooserChosen ), ui );
|
2010-08-02 20:55:11 +00:00
|
|
|
ui->folder_radio = l;
|
2009-09-17 01:28:45 +00:00
|
|
|
ui->folder_chooser = w;
|
|
|
|
gtk_widget_set_sensitive( GTK_WIDGET( w ), FALSE );
|
|
|
|
hig_workarea_add_row_w( t, &row, l, w, NULL );
|
|
|
|
|
|
|
|
slist = gtk_radio_button_get_group( GTK_RADIO_BUTTON( l ) ),
|
|
|
|
l = gtk_radio_button_new_with_mnemonic( slist, _( "Source _File:" ) );
|
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( l ), TRUE );
|
|
|
|
w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_OPEN );
|
|
|
|
g_signal_connect( l, "toggled", G_CALLBACK( onFileToggled ), ui );
|
|
|
|
g_signal_connect( l, "toggled", G_CALLBACK( onSourceToggled ), w );
|
|
|
|
g_signal_connect( w, "selection-changed", G_CALLBACK( onChooserChosen ), ui );
|
2010-08-02 20:55:11 +00:00
|
|
|
ui->file_radio = l;
|
2009-09-17 01:28:45 +00:00
|
|
|
ui->file_chooser = w;
|
|
|
|
hig_workarea_add_row_w( t, &row, l, w, NULL );
|
|
|
|
|
|
|
|
w = gtk_label_new( NULL );
|
|
|
|
ui->pieces_lb = w;
|
|
|
|
gtk_label_set_markup( GTK_LABEL( w ), _( "<i>No source selected</i>" ) );
|
|
|
|
hig_workarea_add_row( t, &row, NULL, w, NULL );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider( t, &row );
|
2009-09-17 01:28:45 +00:00
|
|
|
hig_workarea_add_section_title ( t, &row, _( "Properties" ) );
|
|
|
|
|
|
|
|
str = _( "_Trackers:" );
|
2009-10-04 02:32:38 +00:00
|
|
|
v = gtk_vbox_new( FALSE, GUI_PAD_SMALL );
|
2009-09-17 01:28:45 +00:00
|
|
|
ui->announce_text_buffer = gtk_text_buffer_new( NULL );
|
|
|
|
w = gtk_text_view_new_with_buffer( ui->announce_text_buffer );
|
|
|
|
gtk_widget_set_size_request( w, -1, 80 );
|
|
|
|
sw = gtk_scrolled_window_new( NULL, NULL );
|
|
|
|
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( sw ),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC );
|
|
|
|
gtk_container_add( GTK_CONTAINER( sw ), w );
|
|
|
|
fr = gtk_frame_new( NULL );
|
|
|
|
gtk_frame_set_shadow_type( GTK_FRAME( fr ), GTK_SHADOW_IN );
|
|
|
|
gtk_container_add( GTK_CONTAINER( fr ), sw );
|
2009-10-04 02:32:38 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( v ), fr, TRUE, TRUE, 0 );
|
|
|
|
l = gtk_label_new( NULL );
|
|
|
|
gtk_label_set_markup( GTK_LABEL( l ), _( "To add a backup URL, add it on the line after the primary URL.\n"
|
|
|
|
"To add another primary URL, add it after a blank line." ) );
|
|
|
|
gtk_label_set_justify( GTK_LABEL( l ), GTK_JUSTIFY_LEFT );
|
|
|
|
gtk_misc_set_alignment( GTK_MISC( l ), 0.0, 0.5 );
|
|
|
|
gtk_box_pack_start( GTK_BOX( v ), l, FALSE, FALSE, 0 );
|
|
|
|
hig_workarea_add_tall_row( t, &row, str, v, NULL );
|
2009-09-17 01:28:45 +00:00
|
|
|
|
|
|
|
l = gtk_check_button_new_with_mnemonic( _( "Co_mment:" ) );
|
|
|
|
ui->comment_check = l;
|
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( l ), FALSE );
|
|
|
|
w = gtk_entry_new( );
|
|
|
|
ui->comment_entry = w;
|
|
|
|
gtk_widget_set_sensitive( GTK_WIDGET( w ), FALSE );
|
|
|
|
g_signal_connect( l, "toggled", G_CALLBACK( onSourceToggled ), w );
|
|
|
|
hig_workarea_add_row_w( t, &row, l, w, NULL );
|
|
|
|
|
|
|
|
w = hig_workarea_add_wide_checkbutton( t, &row, _( "_Private torrent" ), FALSE );
|
2008-06-01 15:46:20 +00:00
|
|
|
ui->private_check = w;
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2008-01-28 04:27:22 +00:00
|
|
|
hig_workarea_finish( t, &row );
|
2009-09-17 01:28:45 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( GTK_DIALOG( d )->vbox ), t, TRUE, TRUE, 0 );
|
|
|
|
|
2010-08-02 20:55:11 +00:00
|
|
|
gtk_drag_dest_set( d, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY );
|
|
|
|
gtk_drag_dest_add_uri_targets( d );
|
|
|
|
g_signal_connect( d, "drag-data-received", G_CALLBACK( on_drag_data_received ), ui );
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
return d;
|
|
|
|
}
|