]> granicus.if.org Git - transmission/commitdiff
(daemon) let file download flags and priorities be set by transmission-remote. Add...
authorCharles Kerr <charles@transmissionbt.com>
Thu, 10 Jul 2008 20:59:15 +0000 (20:59 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 10 Jul 2008 20:59:15 +0000 (20:59 +0000)
(libT) minor tweaks to tr-getopt
(gtk) tweak the preference dialog's "port forwarding" text for clarity as suggested in the forums

daemon/remote.c
daemon/transmission-remote.1
gtk/tr-prefs.c
libtransmission/rpc.c
libtransmission/tr-getopt.c

index 69c524f0b361c5a08ae6bf969ca99458b037caa8..59114bb321c4a6491892c8b7966f416af2a2b2a7 100644 (file)
@@ -10,6 +10,7 @@
  * $Id$
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h> /* strcmp */
@@ -36,22 +37,38 @@ enum { TAG_LIST, TAG_DETAILS, TAG_FILES };
 static const char*
 getUsage( void )
 {
-    return "Transmission "LONG_VERSION_STRING"  http://www.transmissionbt.com/\n"
-           "A fast and easy BitTorrent client\n"
-           "\n"
-           "Usage: "MY_NAME" [host] [options]\n"
-           "       "MY_NAME" [port] [options]\n"
-           "       "MY_NAME" [host:port] [options]";
+    return
+"Transmission "LONG_VERSION_STRING"  http://www.transmissionbt.com/\n"
+"A fast and easy BitTorrent client\n"
+"\n"
+"Usage: "MY_NAME" [host] [options]\n"
+"       "MY_NAME" [port] [options]\n"
+"       "MY_NAME" [host:port] [options]\n"
+"\n"
+"Notes:\n"
+"  <files> can be 'all', a single index, or a comma-separated list.\n"
+"  <torrents> can be 'all', a torrent id or hash string, or a comma-separated list of ids and hash strings.\n"
+"\n"
+"Examples:\n"
+"  \""MY_NAME" -l\" (list all torrents)\n"
+"  \""MY_NAME" -tall --start\" (start all torrents)\n"
+"  \""MY_NAME" --add ~/Desktop/*torrent\" (add all the torrent files in $HOME/Desktop)\n"
+"  \""MY_NAME" -t1 -i\" (get detailed information on the torrent whose id is '1')\n"
+"  \""MY_NAME" -t1 -Gall -g2,4,6\" (same torrent; only download the second, fourth, and sixth files)\n"
+"  \""MY_NAME" -tall -ph1,2\" (set all torrent's first two files' priorities to high)\n"
+"  \""MY_NAME" -tall -pnall\" (set all torrent's files' priorities to normal)";
 }
 
 static tr_option opts[] =
 {
     { 'a', "add",          "Add torrent files", "a", 0, NULL },
+    { 'b', "debug",        "Print debugging information", "b", 0, NULL },
     { 'd', "downlimit",    "Set the maximum download speed in KB/s", "d", 1, "<number>" },
     { 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL },
     { 'e', "encryption",   "Set encryption mode [required, preferred, tolerated]", "e", 1, "<mode>" },
     { 'f', "files",        "Get a file list for the current torrent(s)", "f", 0, NULL },
-    { 'g', "debug",        "Print debugging information", "g", 0, NULL },
+    { 'g', "get",          "Mark files for download", "g", 1, "<files>" },
+    { 'G', "no-get",       "Mark files for not downloading", "G", 1, "<files>" },
     { 'h', "help",         "Show this help page and exit", "h", 0, NULL },
     { 'i', "info",         "Show details of the current torrent(s)", "i", 0, NULL },
     { 'l', "list",         "List all torrents", "l", 0, NULL },
@@ -59,10 +76,13 @@ static tr_option opts[] =
     { 'M', "no-portmap",   "Disable portmapping", "M", 0, NULL },
     { 'n', "auth",         "Set username for authentication", "n", 1, "<user>:<pass>" },
     { 'p', "port",         "Port to listen for incoming peers", "p", 1, "<port>" },
+    { 900, "priority-high", "Set one or more files' priority as high", "ph", 1, "<files>" },
+    { 901, "priority-normal", "Set one or more files' priority as normal", "pn", 1, "<files>" },
+    { 902, "priority-normal", "Set one or more files' priority as low", "pl", 1, "<files>" },
     { 'r', "remove",       "Remove the current torrent(s)", "r", 0, NULL },
     { 's', "start",        "Start the current torrent(s)", "s", 0, NULL },
     { 'S', "stop",         "Stop the current torrent(s)", "S", 0, NULL },
-    { 't', "torrent",      "Set the current torrent(s)", "t", 1, "<id|hash|all>" },
+    { 't', "torrent",      "Set the current torrent(s)", "t", 1, "<torrents>" },
     { 'u', "uplimit",      "Set the maximum upload speed in KB/s", "u", 1, "<number>" },
     { 'U', "no-uplimit",   "Don't limit the upload speed", "U", 0, NULL },
     { 'v', "verify",       "Verify the current torrent(s)", "v", 0, NULL },
@@ -125,11 +145,40 @@ addIdArg( tr_benc * args, const char * id )
     if( !*id ) {
         fprintf( stderr, "No torrent specified!  Please use the -t option first.\n" );
         id = "-1"; /* no torrent will have this ID, so should be a no-op */
-    } else if( strcmp( id, "all" ) ) {
+    }
+    if( strcmp( id, "all" ) ) {
         tr_rpc_parse_list_str( tr_bencDictAdd( args, "ids" ), id, strlen(id) );
     }
 }
 
+static void
+addFiles( tr_benc * args, const char * key, const char * arg )
+{
+    tr_benc * files = tr_bencDictAddList( args, key, 100 );
+
+    if( !*arg )
+    {
+        fprintf( stderr, "No files specified!\n" );
+        arg = "-1"; /* no file will have this index, so should be a no-op */
+    }
+    if( strcmp( arg, "all" ) )
+    {
+        const char * walk = arg;
+        while( *walk ) {
+            char * p;
+            unsigned long l;
+            errno = 0;
+            l = strtol( walk, &p, 10 );
+            if( errno )
+                break; 
+            tr_bencListAddInt( files, l - 1 );
+            if( *p != ',' )
+                break;
+            walk = p + 1;
+        }
+    }
+}
+
 static void
 readargs( int argc, const char ** argv )
 {
@@ -165,6 +214,9 @@ readargs( int argc, const char ** argv )
             case 'a': addingTorrents = 1;
                       addArg = FALSE;
                       break;
+            case 'b': debug = 1;
+                      addArg = FALSE;
+                      break;
             case 'd': tr_bencDictAddStr( &top, "method", "session-set" );
                       tr_bencDictAddInt( args, "speed-limit-down", numarg( optarg ) );
                       tr_bencDictAddInt( args, "speed-limit-down-enabled", 1 );
@@ -183,8 +235,13 @@ readargs( int argc, const char ** argv )
                              | TR_RPC_TORRENT_PRIORITIES;
                       tr_bencDictAddInt( args, "fields", fields );
                       break;
-            case 'g': debug = 1;
-                      addArg = FALSE;
+            case 'g': tr_bencDictAddStr( &top, "method", "torrent-set" );
+                      addIdArg( args, id );
+                      addFiles( args, "files-wanted", optarg );
+                      break;
+            case 'G': tr_bencDictAddStr( &top, "method", "torrent-set" );
+                      addIdArg( args, id );
+                      addFiles( args, "files-unwanted", optarg );
                       break;
             case 'i': tr_bencDictAddStr( &top, "method", "torrent-get" );
                       tr_bencDictAddInt( &top, "tag", TAG_DETAILS );
@@ -252,6 +309,18 @@ readargs( int argc, const char ** argv )
             case 'X': tr_bencDictAddStr( &top, "method", "session-set" );
                       tr_bencDictAddInt( args, "pex-allowed", 0 );
                       break;
+            case 900: tr_bencDictAddStr( &top, "method", "torrent-set" );
+                      addIdArg( args, id );
+                      addFiles( args, "priority-high", optarg );
+                      break;
+            case 901: tr_bencDictAddStr( &top, "method", "torrent-set" );
+                      addIdArg( args, id );
+                      addFiles( args, "priority-normal", optarg );
+                      break;
+            case 902: tr_bencDictAddStr( &top, "method", "torrent-set" );
+                      addIdArg( args, id );
+                      addFiles( args, "priority-low", optarg );
+                      break;
             default:  fprintf( stderr, "got opt [%d]\n", (int)c );
                       showUsage( );
                       break;
index b573eb33ff676dd0b3d3aea6736592211ab91d63..fe02190a4f543b3ee2be120f2763f9a7fe7c0689 100644 (file)
@@ -12,11 +12,13 @@ and
 .Nm
 .Op Ar host:port | host | port
 .Op Fl a Ar torrent-files
+.Op Fl b
 .Op Fl d Ar number
 .Op Fl D
 .Op Fl e Ar mode
 .Op Fl f
-.Op Fl g
+.Op Fl g Ar files
+.Op Fl G Ar files
 .Op Fl h
 .Op Fl i
 .Op Fl l
@@ -24,6 +26,9 @@ and
 .Op Fl M
 .Op Fl n Ar user:pass
 .Op Fl p Ar port
+.Op Fl ph Ar files
+.Op Fl pl Ar files
+.Op Fl pn Ar files
 .Op Fl r
 .Op Fl s
 .Op Fl S
@@ -53,6 +58,9 @@ The options are as follows:
 Add metainfo
 .Ar torrent-file(s) .
 
+.It Fl b Fl -debug
+Enable debugging mode.
+
 .It Fl d Fl -downlimit Ar limit
 Limit the download speed to
 .Ar limit
@@ -71,6 +79,16 @@ Prefer unencrypted peer connections.
 .It Fl f Fl -files
 Get a file list for the current torrent(s)
 
+.It Fl g Fl -get Ar files
+Mark file(s) for download.
+.Ar files
+can be a file index, or a comma-separated list of file indices, or the literal
+.Ar all
+for all files in the torrent.
+
+.It Fl g Fl -no-get Ar files
+Mark file(s) for not downloading
+
 .It Fl h Fl -help
 Print command-line option descriptions.
 
@@ -96,6 +114,25 @@ Set the
 .Ar port
 for use when listening for incoming peer connections
 
+.It Fl ph Fl -priority-high Ar files
+Mark 
+.Ar files
+as high priority.
+.Ar files
+can be a file index, or a comma-separated list of file indices, or the literal
+.Ar all
+for all files in the torrent.
+
+.It Fl pl Fl -priority-low Ar files
+Mark 
+.Ar files
+as low priority
+
+.It Fl pn Fl -priority-normal Ar files
+Mark 
+.Ar files
+as normal priority
+
 .It Fl r Fl -remove
 Remove the current torrent(s).  This does not delete the downloaded data.
 
@@ -135,28 +172,47 @@ Disable peer exchange (PEX).
 
 .El
 .Sh EXAMPLES
-Show all torrents, their ID numbers, and their status:
+
+List all torrents:
 .Pp
-.Dl transmission-remote -l
+.Dl transmission-remote -l
 .Pp
-Pause torrent #12:
+
+Start all torrents:
 .Pp
-.Dl transmission-remote -t 12 -S
-.Dl transmission-remote --torrent=12 --stop
+.Dl $ transmission-remote -tall --start
 .Pp
-Start all torrents:
+
+Get detailed information on the torrent whose ID is '1':
 .Pp
-.Dl transmission-remote -t all -s
-.Dl transmission-remote --torrent=all --start
+.Dl $ transmission-remote -t1 -i
 .Pp
+
+Only download the second, fourth, and sixth files of the torrent whose ID is '1':
+.Pp
+.Dl $ transmission-remote -t1 -Gall -g2,4,6
+.Pp
+
+Set all torrents' first two files' priorities to high:
+.Pp
+.Dl $ transmission-remote -t1 -ph1,2
+.Pp
+
+Set all torrents' files' priorities to normal:
+.Pp
+.Dl $ transmission-remote -tall -pnall
+.Pp
+
 Set download and upload limits to 100 KiB/sec and 20 KiB/sec:
 .Pp
-.Dl transmission-remote -d 100 -u 20
-.Dl transmission-remote -d=100 -u=20
+.Dl transmission-remote -d 100 -u 20
+.Dl transmission-remote -d=100 -u=20
 .Pp
+
 Add two torrents:
 .Pp
-.Dl transmission-remote -a one.torrent two.torrent
+.Dl $ transmission-remote -a one.torrent two.torrent
+.Pp
 
 .Sh AUTHORS
 .An -nosplit
index 38390a4bc68f7190b8e98cb99ccf7d3dd71c02be..9bafef9d6715bbe9b5681c5c8186f4256e21e10c 100644 (file)
@@ -979,7 +979,7 @@ networkPage( GObject * core )
     t = hig_workarea_create( );
     hig_workarea_add_section_title (t, &row, _( "Router" ) );
 
-        s = _("Use port _forwarding from my router" );
+        s = _("Use UPnP or NAT-PMP port _forwarding from my router" );
         w = new_check_button( s, PREF_KEY_PORT_FORWARDING, core );
         hig_workarea_add_wide_control( t, &row, w );
 
index 2ded11266aa259c38a431b0c7a4f96406e5ed09b..3022533f09a267c8bb66f07394a7f808c9fd6928 100644 (file)
@@ -338,11 +338,21 @@ setFilePriorities( tr_torrent * tor, int priority, tr_benc * list )
     int64_t tmp;
     int fileCount = 0;
     const int n = tr_bencListSize( list );
-    tr_file_index_t * files = tr_new0( tr_file_index_t, n );
+    tr_file_index_t * files = tr_new0( tr_file_index_t, tor->info.fileCount );
 
-    for( i=0; i<n; ++i )
-        if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
-            files[fileCount++] = tmp;
+    if( n )
+    {
+        for( i=0; i<n; ++i )
+            if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
+                if( 0<=tmp && tmp<tor->info.fileCount )
+                    files[fileCount++] = tmp;
+    }
+    else // if empty set, apply to all
+    {
+        tr_file_index_t t;
+        for( t=0; t<tor->info.fileCount; ++t )
+            files[fileCount++] = t;
+    }
 
     if( fileCount )
         tr_torrentSetFilePriorities( tor, files, fileCount, priority );
@@ -357,11 +367,21 @@ setFileDLs( tr_torrent * tor, int do_download, tr_benc * list )
     int64_t tmp;
     int fileCount = 0;
     const int n = tr_bencListSize( list );
-    tr_file_index_t * files = tr_new0( tr_file_index_t, n );
+    tr_file_index_t * files = tr_new0( tr_file_index_t, tor->info.fileCount );
 
-    for( i=0; i<n; ++i )
-        if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
-            files[fileCount++] = tmp;
+    if( n ) // if argument list, process them
+    {
+        for( i=0; i<n; ++i )
+            if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
+                if( 0<=tmp && tmp<tor->info.fileCount )
+                    files[fileCount++] = tmp;
+    }
+    else // if empty set, apply to all
+    {
+        tr_file_index_t t;
+        for( t=0; t<tor->info.fileCount; ++t )
+            files[fileCount++] = t;
+    }
 
     if( fileCount )
         tr_torrentSetFileDLs( tor, files, fileCount, do_download );
index 2077134f47980f3f31536588f3e67dc8c4a5dc5d..eddccf9e696986f56f45c5524dabc3d92c8e650e 100644 (file)
@@ -56,7 +56,7 @@ getopts_usage_line( const tr_option * opt,
     const char * longName   = opt->longName ? opt->longName : "";
     const char * shortName  = opt->shortName ? opt->shortName : "";
     const char * arg        = getArgName( opt );
-    printf( "  -%*s, --%-*s %-*s  %s\n", shortWidth, shortName,
+    printf( "  -%-*s --%-*s %-*s  %s\n", shortWidth, shortName,
                                          longWidth, longName,
                                          argWidth, arg,
                                          opt->description );