2007-06-18 03:40:41 +00:00
|
|
|
/*
|
2008-01-01 17:20:20 +00:00
|
|
|
* This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com>
|
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>
|
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"
|
2008-06-01 05:36:23 +00:00
|
|
|
#include "tracker-list.h"
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#define UPDATE_INTERVAL_MSEC 200
|
|
|
|
|
2008-05-07 04:06:07 +00:00
|
|
|
#define UI_KEY "ui"
|
2008-10-02 15:29:45 +00:00
|
|
|
#define ANNOUNCE_KEY "recent-announce-url"
|
2008-05-07 04:06:07 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-10-28 19:49:33 +00:00
|
|
|
GtkWidget * filename_entry;
|
|
|
|
GtkWidget * size_lb;
|
|
|
|
GtkWidget * pieces_lb;
|
|
|
|
GtkWidget * announce_list;
|
|
|
|
GtkWidget * comment_entry;
|
|
|
|
GtkWidget * progressbar;
|
|
|
|
GtkWidget * private_check;
|
|
|
|
GtkWidget * dialog;
|
|
|
|
|
|
|
|
tr_metainfo_builder * builder;
|
|
|
|
tr_session * session;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
gboolean isBuilding;
|
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
|
|
|
|
|
|
|
memset( ui, ~0, sizeof( MakeMetaUI ) );
|
2007-06-18 03:40:41 +00:00
|
|
|
g_free( ui );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-01-28 04:27:22 +00:00
|
|
|
refreshButtons( MakeMetaUI * ui )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-01-28 04:27:22 +00:00
|
|
|
GtkDialog * d = GTK_DIALOG( ui->dialog );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
|
|
|
gtk_dialog_set_response_sensitive(
|
|
|
|
d, GTK_RESPONSE_ACCEPT, !ui->isBuilding && ( ui->builder != NULL ) );
|
|
|
|
gtk_dialog_set_response_sensitive( d, GTK_RESPONSE_CLOSE,
|
|
|
|
!ui->isBuilding );
|
|
|
|
gtk_dialog_set_response_sensitive( d, GTK_RESPONSE_CANCEL,
|
|
|
|
ui->isBuilding );
|
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
|
2008-09-23 19:11:04 +00:00
|
|
|
setIsBuilding( MakeMetaUI * ui,
|
|
|
|
gboolean isBuilding )
|
2008-01-28 04:27:22 +00:00
|
|
|
{
|
|
|
|
ui->isBuilding = isBuilding;
|
|
|
|
|
|
|
|
if( ui->builder != NULL )
|
2008-03-24 17:18:08 +00:00
|
|
|
ui->builder->result = TR_MAKEMETA_OK;
|
2008-01-28 04:27:22 +00:00
|
|
|
|
|
|
|
if( !isBuilding )
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(
|
|
|
|
ui->progressbar ), 0 );
|
2008-01-28 04:27:22 +00:00
|
|
|
|
|
|
|
refreshButtons( ui );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
refresh_cb( gpointer user_data )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int denom;
|
|
|
|
char buf[1024];
|
|
|
|
double fraction;
|
|
|
|
MakeMetaUI * ui = user_data;
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkProgressBar * p = GTK_PROGRESS_BAR( ui->progressbar );
|
|
|
|
|
2007-07-06 18:24:54 +00:00
|
|
|
denom = ui->builder->pieceCount ? ui->builder->pieceCount : 1;
|
|
|
|
fraction = (double)ui->builder->pieceIndex / denom;
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_progress_bar_set_fraction( p, fraction );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_snprintf( buf, sizeof( buf ), "%s.torrent (%d%%)", ui->builder->top,
|
|
|
|
(int)( fraction * 100 ) );
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_progress_bar_set_text( p, buf );
|
|
|
|
|
|
|
|
if( ui->builder->isDone )
|
|
|
|
{
|
2008-03-24 17:18:08 +00:00
|
|
|
char * txt = NULL;
|
|
|
|
|
|
|
|
switch( ui->builder->result )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-03-24 17:18:08 +00:00
|
|
|
case TR_MAKEMETA_OK:
|
2008-06-02 21:02:38 +00:00
|
|
|
txt = g_strdup( _( "Torrent created!" ) );
|
2008-03-24 17:18:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_MAKEMETA_URL:
|
2008-09-23 19:11:04 +00:00
|
|
|
txt = g_strdup_printf( _(
|
|
|
|
"Torrent creation failed: %s" ),
|
|
|
|
_( "Invalid URL" ) );
|
2008-03-24 17:18:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_MAKEMETA_CANCELLED:
|
|
|
|
txt = g_strdup_printf( _( "Torrent creation cancelled" ) );
|
|
|
|
break;
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
case TR_MAKEMETA_IO_READ:
|
|
|
|
{
|
|
|
|
char * tmp =
|
|
|
|
g_strdup_printf( _(
|
|
|
|
"Couldn't read \"%1$s\": %2$s" ),
|
|
|
|
ui->builder->errfile,
|
|
|
|
g_strerror( ui->builder->my_errno ) );
|
|
|
|
txt = g_strdup_printf( _(
|
|
|
|
"Torrent creation failed: %s" ),
|
|
|
|
tmp );
|
2008-03-24 17:18:08 +00:00
|
|
|
g_free( tmp );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
case TR_MAKEMETA_IO_WRITE:
|
|
|
|
{
|
|
|
|
char * tmp =
|
|
|
|
g_strdup_printf( _(
|
|
|
|
"Couldn't create \"%1$s\": %2$s" ),
|
|
|
|
ui->builder->errfile,
|
|
|
|
g_strerror( ui->builder->my_errno ) );
|
|
|
|
txt = g_strdup_printf( _(
|
|
|
|
"Torrent creation failed: %s" ),
|
|
|
|
tmp );
|
2008-03-24 17:18:08 +00:00
|
|
|
g_free( tmp );
|
|
|
|
break;
|
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
2008-01-28 04:27:22 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_progress_bar_set_fraction(
|
|
|
|
p, ui->builder->result == TR_MAKEMETA_OK ? 1.0 : 0.0 );
|
2008-03-24 17:18:08 +00:00
|
|
|
gtk_progress_bar_set_text( p, txt );
|
2008-01-28 04:27:22 +00:00
|
|
|
setIsBuilding( ui, FALSE );
|
2008-03-24 17:18:08 +00:00
|
|
|
g_free( txt );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return !ui->builder->isDone;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
remove_tag( gpointer tag )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
g_source_remove ( GPOINTER_TO_UINT( tag ) ); /* stop the periodic refresh */
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
response_cb( GtkDialog* d,
|
|
|
|
int response,
|
|
|
|
gpointer user_data )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
MakeMetaUI * ui = user_data;
|
|
|
|
char * tmp;
|
|
|
|
char buf[1024];
|
|
|
|
guint tag;
|
2008-06-01 05:36:23 +00:00
|
|
|
tr_tracker_info * trackers = NULL;
|
2008-09-23 19:11:04 +00:00
|
|
|
int i;
|
|
|
|
int trackerCount = 0;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
if( response != GTK_RESPONSE_ACCEPT )
|
|
|
|
{
|
2008-01-28 04:27:22 +00:00
|
|
|
if( ui->builder == NULL )
|
|
|
|
{
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( d ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ui->builder->isDone || !ui->isBuilding )
|
|
|
|
{
|
|
|
|
gtk_widget_destroy( ui->dialog );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->builder->abortFlag = TRUE;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-28 04:27:22 +00:00
|
|
|
if( ui->builder == NULL || ui->isBuilding )
|
2007-10-19 21:49:18 +00:00
|
|
|
return;
|
|
|
|
|
2008-01-28 04:27:22 +00:00
|
|
|
setIsBuilding( ui, TRUE );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
tmp = g_path_get_basename ( ui->builder->top );
|
|
|
|
g_snprintf( buf, sizeof( buf ), "%s.torrent (%d%%)", ui->builder->top,
|
|
|
|
0 );
|
2008-01-28 04:27:22 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_progress_bar_set_text( GTK_PROGRESS_BAR( ui->progressbar ), buf );
|
2007-06-18 03:40:41 +00:00
|
|
|
g_free( tmp );
|
|
|
|
|
2008-06-01 05:36:23 +00:00
|
|
|
trackers = tracker_list_get_trackers( ui->announce_list, &trackerCount );
|
|
|
|
|
2008-10-02 15:29:45 +00:00
|
|
|
pref_int_set( ANNOUNCE_KEY"-count", trackerCount );
|
|
|
|
for( i=0; i<trackerCount; ++i )
|
|
|
|
{
|
|
|
|
char key[512];
|
|
|
|
g_snprintf( key, sizeof( key ), ANNOUNCE_KEY"-%d-tier", i );
|
|
|
|
pref_int_set( key, trackers[i].tier );
|
|
|
|
g_snprintf( key, sizeof( key ), ANNOUNCE_KEY"-%d-announce", i );
|
|
|
|
pref_string_set( key, trackers[i].announce );
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
tr_makeMetaInfo( ui->builder,
|
2008-09-23 19:11:04 +00:00
|
|
|
NULL,
|
|
|
|
trackers, trackerCount,
|
|
|
|
gtk_entry_get_text( GTK_ENTRY( ui->comment_entry ) ),
|
|
|
|
gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ui->
|
|
|
|
private_check ) ) );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
tag = g_timeout_add ( UPDATE_INTERVAL_MSEC, refresh_cb, ui );
|
|
|
|
g_object_set_data_full ( G_OBJECT( d ), "tag", GUINT_TO_POINTER(
|
|
|
|
tag ), remove_tag );
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0; i < trackerCount; ++i )
|
2008-06-01 05:36:23 +00:00
|
|
|
g_free( trackers[i].announce );
|
|
|
|
g_free( trackers );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
static void
|
2008-05-07 04:06:07 +00:00
|
|
|
refreshFromBuilder( MakeMetaUI * ui )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
char sizeStr[128];
|
2008-10-14 03:39:16 +00:00
|
|
|
char * buf;
|
2008-05-07 04:06:07 +00:00
|
|
|
tr_metainfo_builder * builder = ui->builder;
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * filename = builder ? builder->top : NULL;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-10-14 03:39:16 +00:00
|
|
|
|
|
|
|
/* update the progressbar */
|
2008-01-28 04:27:22 +00:00
|
|
|
if( !filename )
|
2008-10-14 03:39:16 +00:00
|
|
|
buf = g_strdup( _( "No source selected" ) );
|
2008-05-07 04:06:07 +00:00
|
|
|
else
|
2008-10-14 03:39:16 +00:00
|
|
|
buf = g_strdup_printf( "%s.torrent (%d%%)", filename, 0 );
|
2008-01-28 04:27:22 +00:00
|
|
|
gtk_progress_bar_set_text( GTK_PROGRESS_BAR( ui->progressbar ), buf );
|
|
|
|
refreshButtons( ui );
|
2008-10-14 03:39:16 +00:00
|
|
|
g_free( buf );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-10-14 03:39:16 +00:00
|
|
|
/* update the size label */
|
2008-03-19 19:23:54 +00:00
|
|
|
if( !filename )
|
2008-10-14 03:39:16 +00:00
|
|
|
buf = g_strdup( "<i>No source selected</i>" );
|
|
|
|
else {
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_strlsize( sizeStr, builder->totalSize, sizeof( sizeStr ) );
|
2008-10-14 03:39:16 +00:00
|
|
|
buf = g_strdup_printf( /* %1$s is the torrent size
|
|
|
|
%2$'d is its number of files */
|
|
|
|
ngettext( "<i>%1$s; %2$'d File</i>",
|
|
|
|
"<i>%1$s; %2$'d Files</i>",
|
|
|
|
builder->fileCount ),
|
|
|
|
sizeStr, builder->fileCount );
|
2008-03-19 19:23:54 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_label_set_markup ( GTK_LABEL( ui->size_lb ), buf );
|
2008-10-14 03:39:16 +00:00
|
|
|
g_free( buf );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-10-14 03:39:16 +00:00
|
|
|
/* update the pieces label */
|
2008-03-19 19:23:54 +00:00
|
|
|
if( !filename )
|
2008-10-14 03:39:16 +00:00
|
|
|
buf = g_strdup( "" );
|
|
|
|
else {
|
|
|
|
char * countStr = g_strdup_printf( ngettext( "%'d Piece", "%'d Pieces",
|
|
|
|
builder->pieceCount ),
|
|
|
|
builder->pieceCount );
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_strlsize( sizeStr, builder->pieceSize, sizeof( sizeStr ) );
|
2008-10-14 03:39:16 +00:00
|
|
|
buf = g_strdup_printf( /* %1$s is number of pieces;
|
|
|
|
%2$s is how big each piece is */
|
|
|
|
_( "%1$s @ %2$s" ), countStr, sizeStr );
|
|
|
|
g_free( countStr );
|
2008-03-19 19:23:54 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_label_set_markup ( GTK_LABEL( ui->pieces_lb ), buf );
|
2008-10-14 03:39:16 +00:00
|
|
|
g_free( buf );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
2008-05-07 04:06:07 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onSourceActivated( GtkEditable * editable,
|
|
|
|
gpointer gui )
|
2008-05-07 04:06:07 +00:00
|
|
|
{
|
2008-06-01 15:46:20 +00:00
|
|
|
const char * filename = gtk_entry_get_text( GTK_ENTRY( editable ) );
|
2008-05-07 04:06:07 +00:00
|
|
|
MakeMetaUI * ui = gui;
|
|
|
|
|
2008-06-01 15:46:20 +00:00
|
|
|
if( ui->builder )
|
|
|
|
tr_metaInfoBuilderFree( ui->builder );
|
2008-10-28 19:49:33 +00:00
|
|
|
ui->builder = tr_metaInfoBuilderCreate( ui->session, filename );
|
2008-05-07 04:06:07 +00:00
|
|
|
refreshFromBuilder( ui );
|
2008-06-01 15:46:20 +00:00
|
|
|
}
|
2008-05-07 04:06:07 +00:00
|
|
|
|
2008-06-01 15:46:20 +00:00
|
|
|
static gboolean
|
2008-09-23 19:11:04 +00:00
|
|
|
onSourceLostFocus( GtkWidget * w,
|
|
|
|
GdkEventFocus * focus UNUSED,
|
|
|
|
gpointer gui )
|
2008-06-01 15:46:20 +00:00
|
|
|
{
|
|
|
|
onSourceActivated( GTK_EDITABLE( w ), gui );
|
|
|
|
return FALSE;
|
2008-05-07 04:06:07 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 04:52:03 +00:00
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onChooseClicked( GtkButton * button,
|
|
|
|
gpointer gui,
|
|
|
|
const char * title,
|
|
|
|
GtkFileChooserAction chooserAction )
|
2007-06-18 04:52:03 +00:00
|
|
|
{
|
2008-06-01 15:46:20 +00:00
|
|
|
GtkWidget * top = gtk_widget_get_toplevel( GTK_WIDGET( button ) );
|
|
|
|
GtkWidget * d = gtk_file_chooser_dialog_new( title,
|
2008-09-23 19:11:04 +00:00
|
|
|
GTK_WINDOW(
|
|
|
|
top ),
|
2008-06-01 15:46:20 +00:00
|
|
|
chooserAction,
|
2008-09-23 19:11:04 +00:00
|
|
|
GTK_STOCK_CANCEL,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_ADD,
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL );
|
|
|
|
|
2008-06-01 15:46:20 +00:00
|
|
|
if( gtk_dialog_run( GTK_DIALOG( d ) ) == GTK_RESPONSE_ACCEPT )
|
2008-05-07 04:06:07 +00:00
|
|
|
{
|
2008-06-01 15:46:20 +00:00
|
|
|
MakeMetaUI * ui = gui;
|
2008-09-23 19:11:04 +00:00
|
|
|
char * filename = gtk_file_chooser_get_filename(
|
|
|
|
GTK_FILE_CHOOSER( d ) );
|
2008-06-01 15:46:20 +00:00
|
|
|
gtk_entry_set_text( GTK_ENTRY( ui->filename_entry ), filename );
|
|
|
|
onSourceActivated( GTK_EDITABLE( ui->filename_entry ), gui );
|
|
|
|
g_free( filename );
|
2008-05-07 04:06:07 +00:00
|
|
|
}
|
2008-06-01 15:46:20 +00:00
|
|
|
|
|
|
|
gtk_widget_destroy( d );
|
2007-06-18 04:52:03 +00:00
|
|
|
}
|
2008-06-01 15:46:20 +00:00
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onChooseDirectoryClicked( GtkButton * b,
|
|
|
|
gpointer gui )
|
2008-06-01 15:46:20 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
onChooseClicked( b, gui, _(
|
|
|
|
"Choose Directory" ),
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
|
2008-06-01 15:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-23 19:11:04 +00:00
|
|
|
onChooseFileClicked( GtkButton * b,
|
|
|
|
gpointer gui )
|
2008-06-01 15:46:20 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
onChooseClicked( b, gui, _(
|
|
|
|
"Choose File" ), GTK_FILE_CHOOSER_ACTION_OPEN );
|
2008-06-01 15:46:20 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
GtkWidget*
|
2008-10-28 19:49:33 +00:00
|
|
|
make_meta_ui( GtkWindow * parent,
|
|
|
|
tr_session * session )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-10-02 15:29:45 +00:00
|
|
|
int n;
|
2008-09-23 19:11:04 +00:00
|
|
|
int row = 0;
|
|
|
|
GtkWidget * d, *t, *w, *h, *h2, *v, *focusMe, *extras;
|
|
|
|
GtkBox * main_vbox;
|
2007-06-18 03:40:41 +00:00
|
|
|
MakeMetaUI * ui = g_new0 ( MakeMetaUI, 1 );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-28 19:49:33 +00:00
|
|
|
ui->session = session;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +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,
|
2008-06-02 04:41:55 +00:00
|
|
|
GTK_STOCK_STOP, GTK_RESPONSE_CANCEL,
|
2007-06-18 03:40:41 +00:00
|
|
|
NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_signal_connect( d, "response", G_CALLBACK( response_cb ), ui );
|
|
|
|
g_object_set_data_full( G_OBJECT( d ), "ui", ui, freeMetaUI );
|
2007-06-18 03:40:41 +00:00
|
|
|
ui->dialog = d;
|
2008-01-28 04:27:22 +00:00
|
|
|
main_vbox = GTK_BOX( GTK_DIALOG( d )->vbox );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
t = hig_workarea_create ( );
|
|
|
|
|
|
|
|
hig_workarea_add_section_title ( t, &row, _( "Source" ) );
|
|
|
|
|
|
|
|
h = gtk_hbox_new( FALSE, GUI_PAD );
|
|
|
|
v = gtk_vbox_new( FALSE, GUI_PAD_SMALL );
|
|
|
|
w = ui->filename_entry = gtk_entry_new( );
|
|
|
|
g_signal_connect( w, "activate", G_CALLBACK( onSourceActivated ), ui );
|
|
|
|
g_signal_connect( w, "focus-out-event", G_CALLBACK(
|
|
|
|
onSourceLostFocus ), ui );
|
|
|
|
gtk_box_pack_start( GTK_BOX( v ), w, FALSE, FALSE, 0 );
|
|
|
|
h2 = gtk_hbox_new( FALSE, GUI_PAD_SMALL );
|
|
|
|
w = ui->size_lb = gtk_label_new ( NULL );
|
|
|
|
gtk_label_set_markup ( GTK_LABEL( w ), _( "<i>No source selected</i>" ) );
|
|
|
|
gtk_box_pack_start( GTK_BOX( h2 ), w, FALSE, FALSE, GUI_PAD_SMALL );
|
|
|
|
w = ui->pieces_lb = gtk_label_new ( NULL );
|
|
|
|
gtk_box_pack_end( GTK_BOX( h2 ), w, FALSE, FALSE, GUI_PAD_SMALL );
|
|
|
|
w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
|
|
|
|
gtk_widget_set_size_request ( w, 2 * GUI_PAD_BIG, 0 );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( h2 ), w, TRUE, TRUE, 0 );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( v ), h2, FALSE, FALSE, 0 );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( h ), v, TRUE, TRUE, 0 );
|
2008-09-23 19:11:04 +00:00
|
|
|
v = gtk_vbox_new( FALSE, GUI_PAD_SMALL );
|
|
|
|
w = gtr_button_new_from_stock( GTK_STOCK_DIRECTORY, _( "F_older" ) );
|
|
|
|
focusMe = w;
|
|
|
|
g_signal_connect( w, "clicked", G_CALLBACK(
|
|
|
|
onChooseDirectoryClicked ), ui );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( v ), w, TRUE, TRUE, 0 );
|
2008-09-23 19:11:04 +00:00
|
|
|
w = gtr_button_new_from_stock( GTK_STOCK_FILE, _( "_File" ) );
|
|
|
|
g_signal_connect( w, "clicked", G_CALLBACK( onChooseFileClicked ), ui );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( v ), w, TRUE, TRUE, 0 );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX( h ), v, FALSE, FALSE, 0 );
|
|
|
|
hig_workarea_add_wide_control( t, &row, h );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider( t, &row );
|
2008-06-01 15:46:20 +00:00
|
|
|
hig_workarea_add_section_title( t, &row, _( "Trackers" ) );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
w = tracker_list_new( NULL );
|
2008-10-02 15:29:45 +00:00
|
|
|
|
|
|
|
n = pref_int_get( ANNOUNCE_KEY"-count" );
|
|
|
|
if( n > 0 )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int trackerCount = 0;
|
|
|
|
tr_tracker_info * trackers = g_new0( tr_tracker_info, n );
|
|
|
|
|
|
|
|
for( i=0; i<n; ++i )
|
|
|
|
{
|
|
|
|
char key[512];
|
|
|
|
int tier;
|
|
|
|
const char * announce;
|
|
|
|
g_snprintf( key, sizeof( key ), ANNOUNCE_KEY"-%d-tier", i );
|
|
|
|
tier = pref_int_get( key );
|
|
|
|
g_snprintf( key, sizeof( key ), ANNOUNCE_KEY"-%d-announce", i );
|
|
|
|
announce = pref_string_get( key );
|
|
|
|
if( tier >= 0 && announce && *announce ) {
|
|
|
|
trackers[trackerCount].tier = tier;
|
|
|
|
trackers[trackerCount++].announce = (char*) announce;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( trackerCount > 0 )
|
|
|
|
tracker_list_add_trackers( w, trackers, trackerCount );
|
|
|
|
|
|
|
|
g_free( trackers );
|
|
|
|
}
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
ui->announce_list = w;
|
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider( t, &row );
|
2008-06-02 04:41:55 +00:00
|
|
|
w = extras = gtk_expander_new_with_mnemonic( _( "<b>E_xtras</b>" ) );
|
|
|
|
gtk_expander_set_use_markup( GTK_EXPANDER( w ), TRUE );
|
|
|
|
hig_workarea_add_section_title_widget( t, &row, w );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
|
|
|
int row2 = 0;
|
2008-06-02 04:41:55 +00:00
|
|
|
GtkWidget * t2 = hig_workarea_create( );
|
2007-06-18 03:40:41 +00:00
|
|
|
w = ui->comment_entry = gtk_entry_new( );
|
2008-06-02 04:41:55 +00:00
|
|
|
hig_workarea_add_row( t2, &row2, _( "Commen_t:" ), w, NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
w =
|
|
|
|
hig_workarea_add_wide_checkbutton( t2, &row2, _(
|
|
|
|
"_Private torrent" ),
|
|
|
|
FALSE );
|
2008-06-01 15:46:20 +00:00
|
|
|
ui->private_check = w;
|
2008-06-02 04:41:55 +00:00
|
|
|
hig_workarea_finish( t2, &row2 );
|
|
|
|
gtk_container_add( GTK_CONTAINER( extras ), t2 );
|
2008-09-23 19:11:04 +00:00
|
|
|
}
|
2008-06-01 15:46:20 +00:00
|
|
|
|
2008-01-28 04:27:22 +00:00
|
|
|
hig_workarea_finish( t, &row );
|
2008-10-31 18:25:21 +00:00
|
|
|
gtk_box_pack_start( main_vbox, t, TRUE, TRUE, 0 );
|
2008-01-28 04:27:22 +00:00
|
|
|
|
|
|
|
w = gtk_frame_new( NULL );
|
|
|
|
gtk_frame_set_shadow_type( GTK_FRAME( w ), GTK_SHADOW_NONE );
|
2008-06-02 04:58:49 +00:00
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( w ), GUI_PAD );
|
|
|
|
gtk_container_add( GTK_CONTAINER( w ), gtk_hseparator_new( ) );
|
|
|
|
gtk_box_pack_start( main_vbox, w, FALSE, FALSE, 0 );
|
2008-01-28 04:27:22 +00:00
|
|
|
|
2008-06-02 04:58:49 +00:00
|
|
|
w = gtk_frame_new( NULL );
|
|
|
|
gtk_frame_set_shadow_type( GTK_FRAME( w ), GTK_SHADOW_NONE );
|
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( w ), GUI_PAD );
|
|
|
|
ui->progressbar = gtk_progress_bar_new( );
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_progress_bar_set_text( GTK_PROGRESS_BAR( ui->progressbar ),
|
|
|
|
_( "No source selected" ) );
|
2008-06-02 04:58:49 +00:00
|
|
|
gtk_container_add( GTK_CONTAINER( w ), ui->progressbar );
|
2008-06-02 04:41:55 +00:00
|
|
|
gtk_box_pack_start( main_vbox, w, FALSE, FALSE, 0 );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gtk_window_set_default_size( GTK_WINDOW( d ), 500, 0 );
|
|
|
|
gtk_widget_show_all( GTK_DIALOG( d )->vbox );
|
2008-01-28 04:27:22 +00:00
|
|
|
setIsBuilding( ui, FALSE );
|
2008-06-01 15:46:20 +00:00
|
|
|
gtk_widget_grab_focus( focusMe );
|
2007-06-18 03:40:41 +00:00
|
|
|
return d;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|