Changeset 2316
- Timestamp:
- Jul 10, 2007, 3:12:46 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/actions.c
r2304 r2316 40 40 { "priority-high", NULL, N_("_High"), NULL, NULL, TR_PRI_HIGH }, 41 41 { "priority-normal", NULL, N_("_Normal"), NULL, NULL, TR_PRI_NORMAL }, 42 { "priority-low", NULL, N_("_Low"), NULL, NULL, TR_PRI_LOW }, 43 { "priority-dnd", NULL, N_("_Don't Get"), NULL, NULL, TR_PRI_DND } 42 { "priority-low", NULL, N_("_Low"), NULL, NULL, TR_PRI_LOW } 44 43 }; 45 44 -
trunk/gtk/torrent-inspector.c
r2267 r2316 943 943 FC_SIZE, 944 944 FC_PRIORITY, 945 FC_ENABLED, 945 946 N_FILE_COLS 946 947 }; … … 962 963 case TR_PRI_NORMAL: return _("Normal"); 963 964 case TR_PRI_LOW: return _("Low"); 964 case TR_PRI_DND: return _("Don't Get");965 965 default: return "BUG!"; 966 966 } … … 972 972 if( !strcmp( str, _( "High" ) ) ) return TR_PRI_HIGH; 973 973 if( !strcmp( str, _( "Low" ) ) ) return TR_PRI_LOW; 974 if( !strcmp( str, _( "Don't Get" ) ) ) return TR_PRI_DND;;975 974 return TR_PRI_NORMAL; 976 975 } … … 989 988 const char * stock; 990 989 int priority = 0; 990 gboolean enabled = TRUE; 991 991 992 992 model = GTK_TREE_MODEL( store ); … … 1026 1026 } 1027 1027 1028 if (index != -1) 1028 if (index != -1) { 1029 1029 priority = tr_torrentGetFilePriority( tor, index ); 1030 enabled = tr_torrentGetFileDL( tor, index ); 1031 } 1030 1032 1031 1033 escaped = g_markup_escape_text (file, -1); 1032 gtk_tree_store_set( store, &iter, FC_INDEX, index, FC_LABEL, escaped, 1033 FC_KEY, mykey, FC_STOCK, stock, 1034 FC_PRIORITY, priorityToString(priority), 1035 FC_SIZE, size, -1 ); 1034 gtk_tree_store_set( store, &iter, FC_INDEX, index, 1035 FC_LABEL, escaped, 1036 FC_KEY, mykey, 1037 FC_STOCK, stock, 1038 FC_PRIORITY, priorityToString(priority), 1039 FC_ENABLED, enabled, 1040 FC_SIZE, size, -1 ); 1036 1041 done: 1037 1042 g_free( escaped ); … … 1141 1146 gtk_list_store_append (store, &iter); 1142 1147 gtk_list_store_set (store, &iter, 0, _("Low"), 1, TR_PRI_LOW, -1); 1143 gtk_list_store_append (store, &iter);1144 gtk_list_store_set (store, &iter, 0, _("Don't Get"), 1, TR_PRI_DND, -1);1145 1148 return GTK_TREE_MODEL (store); 1146 1149 } … … 1156 1159 action_sensitize ( "priority-normal", has_selection ); 1157 1160 action_sensitize ( "priority-low", has_selection ); 1158 action_sensitize ( "priority-dnd", has_selection );1159 1161 1160 1162 if( has_selection ) … … 1167 1169 case TR_PRI_HIGH: key = "priority-high"; break; 1168 1170 case TR_PRI_LOW: key = "priority-low"; break; 1169 case TR_PRI_DND: key = "priority-dnd"; break;1170 1171 default: key = "priority-normal"; break; 1171 1172 } … … 1173 1174 g_free( pch ); 1174 1175 } 1176 } 1177 1178 static void 1179 set_files_enabled( GtkTreeStore * store, 1180 GtkTreeIter * iter, 1181 tr_torrent_t * tor, 1182 gboolean enabled ) 1183 { 1184 int index; 1185 GtkTreeIter child; 1186 1187 gtk_tree_model_get( GTK_TREE_MODEL(store), iter, FC_INDEX, &index, -1 ); 1188 if (index >= 0) 1189 tr_torrentSetFileDL( tor, index, !enabled ); 1190 gtk_tree_store_set( store, iter, FC_ENABLED, enabled, -1 ); 1191 1192 if( gtk_tree_model_iter_children( GTK_TREE_MODEL(store), &child, iter ) ) do 1193 set_files_enabled( store, &child, tor, enabled ); 1194 while( gtk_tree_model_iter_next( GTK_TREE_MODEL(store), &child ) ); 1175 1195 } 1176 1196 … … 1252 1272 } 1253 1273 1274 static void 1275 enabled_toggled (GtkCellRendererToggle * cell UNUSED, 1276 const gchar * path_str, 1277 gpointer data_gpointer) 1278 { 1279 FileData * data = (FileData*) data_gpointer; 1280 GtkTreePath * path = gtk_tree_path_new_from_string( path_str ); 1281 GtkTreeModel * model = data->model; 1282 GtkTreeIter iter; 1283 gboolean enabled; 1284 1285 gtk_tree_model_get_iter( model, &iter, path ); 1286 gtk_tree_model_get( model, &iter, FC_ENABLED, &enabled, -1 ); 1287 enabled = !enabled; 1288 set_files_enabled( GTK_TREE_STORE(model), 1289 &iter, 1290 tr_torrent_handle( data->gtor ), 1291 enabled ); 1292 1293 gtk_tree_path_free( path ); 1294 } 1295 1254 1296 GtkWidget * 1255 1297 file_page_new ( TrTorrent * gtor ) … … 1263 1305 GtkWidget * view, * scroll; 1264 1306 GtkCellRenderer * rend; 1307 GtkCellRenderer * priority_rend; 1265 1308 GtkTreeViewColumn * col; 1266 1309 GtkTreeSelection * sel; … … 1268 1311 1269 1312 store = gtk_tree_store_new ( N_FILE_COLS, 1270 G_TYPE_STRING, /* stock */ 1271 G_TYPE_STRING, /* label */ 1272 G_TYPE_INT, /* prog [0..100] */ 1273 G_TYPE_STRING, /* key */ 1274 G_TYPE_INT, /* index */ 1275 G_TYPE_UINT64, /* size */ 1276 G_TYPE_STRING); /* priority */ 1313 G_TYPE_STRING, /* stock */ 1314 G_TYPE_STRING, /* label */ 1315 G_TYPE_INT, /* prog [0..100] */ 1316 G_TYPE_STRING, /* key */ 1317 G_TYPE_INT, /* index */ 1318 G_TYPE_UINT64, /* size */ 1319 G_TYPE_STRING, /* priority */ 1320 G_TYPE_BOOLEAN ); /* dl enabled */ 1277 1321 1278 1322 /* set up the model */ … … 1323 1367 fileSelectionChangedCB( sel, NULL ); 1324 1368 1325 1326 1369 /* add priority column */ 1327 1370 model = priority_model_new (); … … 1329 1372 gtk_tree_view_column_set_sort_column_id( col, FC_PRIORITY ); 1330 1373 gtk_tree_view_column_set_title (col, _("Priority")); 1331 rend = gtk_cell_renderer_combo_new ();1374 rend = priority_rend = gtk_cell_renderer_combo_new (); 1332 1375 gtk_tree_view_column_pack_start (col, rend, TRUE); 1333 1376 g_object_set (G_OBJECT(rend), "model", model, … … 1340 1383 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), col ); 1341 1384 1385 /* download enabled column */ 1386 col = gtk_tree_view_column_new (); 1387 gtk_tree_view_column_set_sort_column_id( col, FC_ENABLED ); 1388 rend = gtk_cell_renderer_toggle_new (); 1389 col = gtk_tree_view_column_new_with_attributes (_("Enabled"), 1390 rend, 1391 "active", FC_ENABLED, 1392 NULL); 1393 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), col ); 1394 1342 1395 /* create the scrolled window and stick the view in it */ 1343 1396 scroll = gtk_scrolled_window_new( NULL, NULL ); … … 1357 1410 data->selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ); 1358 1411 g_object_set_data_full (G_OBJECT(ret), "file-data", data, g_free); 1359 g_signal_connect (G_OBJECT(rend), "edited", G_CALLBACK(priority_changed_cb), data); 1412 g_signal_connect (G_OBJECT(priority_rend), "edited", G_CALLBACK(priority_changed_cb), data); 1413 g_signal_connect( rend, "toggled", G_CALLBACK(enabled_toggled), data ); 1360 1414 return ret; 1361 1415 } -
trunk/gtk/ui.h
r2149 r2316 59 59 " <menuitem action='priority-normal'/>\n" 60 60 " <menuitem action='priority-low'/>\n" 61 " <menuitem action='priority-dnd'/>\n"62 61 " </menu>\n" 63 62 " </popup>\n" -
trunk/libtransmission/completion.c
r2308 r2316 296 296 if( tr_cpPieceIsComplete( cp, i ) ) 297 297 continue; 298 if( info->pieces[i].priority != TR_PRI_DND)298 if( !info->pieces[i].dnd ) 299 299 return TR_CP_INCOMPLETE; 300 300 ret = TR_CP_DONE; … … 344 344 345 345 for( i=0; i<info->pieceCount; ++i ) 346 if( !tr_cpPieceIsComplete( cp, i ) && info->pieces[i].priority != TR_PRI_DND)346 if( !tr_cpPieceIsComplete( cp, i ) && !info->pieces[i].dnd ) 347 347 b += ( tr_cpCountBlocks( cp, i ) - cp->completeBlocks[ i ] ); 348 348 … … 350 350 351 351 i = tor->blockCount - 1; 352 if( !tr_cpBlockIsComplete( cp, tor->blockCount-1 ) 353 && info->pieces[info->pieceCount-1].priority != TR_PRI_DND ) 352 if( !tr_cpBlockIsComplete( cp, tor->blockCount-1 ) && !info->pieces[info->pieceCount-1].dnd ) 354 353 b -= (tor->blockSize - (tor->info.totalSize % tor->blockSize)); 355 354 -
trunk/libtransmission/fastresume.c
r2315 r2316 61 61 */ 62 62 #define FR_ID_PROGRESS 0x05 63 /* dnd and priority 64 * char * number of files: l,n,h for low, normal, high priority 65 * uint8_t * number of files: nonzero if dnd flag is set 66 */ 67 #define FR_ID_PRIORITY 0x06 63 68 64 69 /* macros for the length of various pieces of the progress data */ … … 168 173 } 169 174 175 176 /* Write the priorities and DND flags */ 177 if( TRUE ) 178 { 179 int i; 180 const int n = tor->info.fileCount; 181 char * buf = tr_new0( char, n*2 ); 182 char * walk = buf; 183 184 /* priorities */ 185 for( i=0; i<n; ++i ) { 186 char ch; 187 const int priority = tor->info.files[i].priority; 188 switch( priority ) { 189 case TR_PRI_LOW: ch = 'l'; break; /* low */ 190 case TR_PRI_HIGH: ch = 'h'; break; /* high */ 191 default: ch = 'n'; break; /* normal */ 192 }; 193 *walk++ = ch; 194 } 195 196 /* dnd flags */ 197 for( i=0; i<n; ++i ) 198 *walk++ = tor->info.files[i].dnd ? '\1' : '\0'; 199 200 /* write it */ 201 assert( walk - buf == 2*n ); 202 fastResumeWriteData( FR_ID_PRIORITY, buf, 1, walk-buf, file ); 203 204 /* cleanup */ 205 tr_free( buf ); 206 } 207 208 170 209 /* Write download and upload totals */ 171 210 total = tor->downloadedCur + tor->downloadedPrev; … … 189 228 190 229 tr_dbg( "Resume file '%s' written", path ); 230 } 231 232 static int 233 fastResumeLoadPriorities( tr_torrent_t * tor, 234 FILE * file ) 235 { 236 const size_t n = tor->info.fileCount; 237 const size_t len = 2 * n; 238 char * buf = tr_new0( char, len ); 239 char * walk = buf; 240 size_t i; 241 242 if( len != fread( buf, 1, len, file ) ) { 243 tr_inf( "Couldn't read from resume file" ); 244 free( buf ); 245 return TR_ERROR_IO_OTHER; 246 } 247 248 /* set file priorities */ 249 for( i=0; i<n; ++i ) { 250 tr_priority_t priority; 251 const char ch = *walk++; 252 switch( ch ) { 253 case 'l': priority = TR_PRI_LOW; break; 254 case 'h': priority = TR_PRI_HIGH; break; 255 default: priority = TR_PRI_NORMAL; break; 256 } 257 tor->info.files[i].priority = priority; 258 } 259 260 /* set the dnd flags */ 261 for( i=0; i<n; ++i ) 262 tor->info.files[i].dnd = *walk++ != 0; 263 264 free( buf ); 265 return TR_OK; 191 266 } 192 267 … … 326 401 if( (uint32_t)FR_PROGRESS_LEN( tor ) == len ) 327 402 { 328 if( fastResumeLoadProgress( tor, uncheckedPieces, file ) ) 403 ret = fastResumeLoadProgress( tor, uncheckedPieces, file ); 404 405 if( ret && ( feof(file) || ferror(file) ) ) 329 406 { 330 if( feof( file ) || ferror( file ) ) 331 { 332 fclose( file ); 333 return 1; 334 } 407 fclose( file ); 408 return 1; 335 409 } 336 else 410 411 continue; 412 } 413 break; 414 415 case FR_ID_PRIORITY: 416 417 /* read priority data */ 418 if( len == (uint32_t)(2 * tor->info.fileCount) ) 419 { 420 ret = fastResumeLoadPriorities( tor, file ); 421 422 if( ret && ( feof(file) || ferror(file) ) ) 337 423 { 338 ret = 0; 424 fclose( file ); 425 return 1; 339 426 } 427 340 428 continue; 341 429 } -
trunk/libtransmission/peerutils.h
r2306 r2316 170 170 return 0; 171 171 172 if( tor->info.pieces[piece]. priority == TR_PRI_DND) /* we don't want it */172 if( tor->info.pieces[piece].dnd ) /* we don't want it */ 173 173 return 0; 174 174 -
trunk/libtransmission/torrent.c
r2313 r2316 23 23 *****************************************************************************/ 24 24 25 #include "transmission.h" 26 #include "fastresume.h" 25 27 #include "trcompat.h" /* for strlcpy */ 26 #include "transmission.h"27 28 #include "metainfo.h" 28 29 #include "net.h" /* tr_netNtop */ … … 130 131 { 131 132 int i; 132 tr_priority_t priority = TR_PRI_ DND;133 tr_priority_t priority = TR_PRI_NORMAL; 133 134 134 135 for( i=0; i<tor->info.fileCount; ++i ) … … 1110 1111 ***/ 1111 1112 1113 static void 1114 tr_torrentSetFilePriorityImpl( tr_torrent_t * tor, 1115 int fileIndex, 1116 tr_priority_t priority, 1117 int doSave ) 1118 { 1119 int i; 1120 tr_file_t * file; 1121 1122 tr_torrentWriterLock( tor ); 1123 1124 assert( tor != NULL ); 1125 assert( 0<=fileIndex && fileIndex<tor->info.fileCount ); 1126 assert( priority==TR_PRI_LOW || priority==TR_PRI_NORMAL || priority==TR_PRI_HIGH ); 1127 1128 file = &tor->info.files[fileIndex]; 1129 file->priority = priority; 1130 for( i=file->firstPiece; i<=file->lastPiece; ++i ) 1131 tor->info.pieces[i].priority = calculatePiecePriority( tor, i ); 1132 1133 tr_dbg ( "Setting file #%d (pieces %d-%d) priority to %d (%s)", 1134 fileIndex, file->firstPiece, file->lastPiece, 1135 priority, tor->info.files[fileIndex].name ); 1136 1137 if( doSave ) 1138 fastResumeSave( tor ); 1139 1140 tr_torrentWriterUnlock( tor ); 1141 } 1142 1112 1143 void 1113 1144 tr_torrentSetFilePriority( tr_torrent_t * tor, … … 1115 1146 tr_priority_t priority ) 1116 1147 { 1148 tr_torrentSetFilePriorityImpl( tor, fileIndex, priority, TRUE ); 1149 } 1150 1151 void 1152 tr_torrentSetFilePriorities( tr_torrent_t * tor, 1153 const tr_priority_t * filePriorities ) 1154 { 1117 1155 int i; 1118 tr_file_t * file; 1119 1120 tr_torrentWriterLock( tor ); 1121 1122 assert( tor != NULL ); 1123 assert( 0<=fileIndex && fileIndex<tor->info.fileCount ); 1124 assert( priority==TR_PRI_LOW || priority==TR_PRI_NORMAL 1125 || priority==TR_PRI_HIGH || priority==TR_PRI_DND ); 1126 1127 file = &tor->info.files[fileIndex]; 1128 file->priority = priority; 1129 for( i=file->firstPiece; i<=file->lastPiece; ++i ) 1130 tor->info.pieces[i].priority = calculatePiecePriority( tor, i ); 1131 1132 tr_dbg ( "Setting file #%d (pieces %d-%d) priority to %d (%s)", 1133 fileIndex, file->firstPiece, file->lastPiece, 1134 priority, tor->info.files[fileIndex].name ); 1135 1136 tr_torrentWriterUnlock( tor ); 1156 for( i=0; i<tor->info.pieceCount; ++i ) 1157 tr_torrentSetFilePriorityImpl( tor, i, filePriorities[i], FALSE ); 1158 fastResumeSave( tor ); 1137 1159 } 1138 1160 … … 1152 1174 1153 1175 1154 void1155 tr_torrentSetFilePriorities( tr_torrent_t * tor,1156 const tr_priority_t * filePriorities )1157 {1158 int i;1159 for( i=0; i<tor->info.pieceCount; ++i )1160 tr_torrentSetFilePriority( tor, i, filePriorities[i] );1161 }1162 1163 1176 tr_priority_t* 1164 1177 tr_torrentGetFilePriorities( const tr_torrent_t * tor ) … … 1175 1188 return p; 1176 1189 } 1190 1191 int 1192 tr_torrentGetFileDL( const tr_torrent_t * tor, 1193 int file ) 1194 { 1195 int do_download; 1196 tr_torrentReaderLock( tor ); 1197 1198 assert( 0<=file && file<tor->info.fileCount ); 1199 do_download = !tor->info.files[file].dnd; 1200 1201 tr_torrentReaderUnlock( tor ); 1202 return do_download != 0; 1203 } 1204 1205 void 1206 tr_torrentSetFileDL( tr_torrent_t * tor, 1207 int file, 1208 int do_download ) 1209 { 1210 tr_torrentWriterLock( tor ); 1211 1212 assert( 0<=file && file<tor->info.fileCount ); 1213 tor->info.files[file].dnd = !do_download; 1214 fastResumeSave( tor ); 1215 1216 tr_torrentWriterUnlock( tor ); 1217 } -
trunk/libtransmission/transmission.h
r2259 r2316 207 207 enum 208 208 { 209 TR_PRI_DND = -2, /* Do Not Download */210 209 TR_PRI_LOW = -1, 211 210 TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ … … 216 215 217 216 /* priorities should be an array of tor->info.fileCount bytes, 218 * each holding a value of TR_PRI_NORMAL, _HIGH, _LOW, or _DND.*/217 * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW */ 219 218 void tr_torrentSetFilePriorities ( tr_torrent_t *, const tr_priority_t * priorities ); 220 219 221 220 /* single-file form of tr_torrentPrioritizeFiles. 222 * priority must be one of TR_PRI_NORMAL, _HIGH, _LOW, or _DND*/221 * priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW */ 223 222 void tr_torrentSetFilePriority( tr_torrent_t *, int file, tr_priority_t priority ); 224 223 225 224 /* returns a malloc()ed array of tor->info.fileCount items, 226 * each holding a value of TR_PRI_NORMAL, _HIGH, _LOW, or _DND.225 * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW. 227 226 free the array when done. */ 228 227 tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent_t * ); 229 228 230 229 /* single-file form of tr_torrentGetFilePriorities. 231 * returns one of TR_PRI_NORMAL, _HIGH, _LOW, or _DND*/230 * returns one of TR_PRI_NORMAL, _HIGH, or _LOW. */ 232 231 tr_priority_t tr_torrentGetFilePriority( const tr_torrent_t *, int file ); 233 232 234 /* returns the priority for the specified piece, 235 * as ranked by the number of files of various priorities in that piece. 236 * a zero priority means DND */ 237 tr_priority_t tr_torrentGetPiecePriority( const tr_torrent_t *, int pieceIndex ); 233 /* returns true if the file's `download' flag is set */ 234 int tr_torrentGetFileDL( const tr_torrent_t *, int file ); 235 236 /* set the specified file's `download' flag */ 237 void tr_torrentSetFileDL( tr_torrent_t *, int file, int do_download ); 238 238 239 239 240 /*********************************************************************** … … 468 469 uint64_t length; /* Length of the file, in bytes */ 469 470 char name[MAX_PATH_LENGTH]; /* Path to the file */ 470 int8_t priority; /* TR_PRI_HIGH, _NORMAL, _LOW, or _DND */ 471 int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ 472 int8_t dnd; /* nonzero if the file shouldn't be downloaded */ 471 473 int firstPiece; /* We need pieces [firstPiece... */ 472 474 int lastPiece; /* ...lastPiece] to dl this file */ … … 478 480 { 479 481 uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ 480 int8_t priority; /* TR_PRI_HIGH, _NORMAL, _LOW, or _DND */ 482 int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ 483 int8_t dnd; /* nonzero if the piece shouldn't be downloaded */ 481 484 } 482 485 tr_piece_t;
Note: See TracChangeset
for help on using the changeset viewer.