Update 2005-12-25

This commit is contained in:
Eric Petit
2006-01-12 18:58:57 +00:00
parent f5deceaa64
commit 6c0a54caa5
18 changed files with 259 additions and 219 deletions

View File

@@ -1,7 +1,7 @@
AUTHORS for Transmission <http://transmission.m0k.org/> AUTHORS for Transmission <http://transmission.m0k.org/>
======================================================= =======================================================
Transmission is written is maintained by: Transmission is written and maintained by:
Eric Petit <titer@m0k.org> Eric Petit <titer@m0k.org>
+ Back-end + Back-end
@@ -44,3 +44,6 @@ Martin Stadtmueller
John Blitch John Blitch
+ Contextual menu patch + Contextual menu patch
Mitchell Livingston
+ OS X patches

View File

@@ -159,7 +159,7 @@ main(int argc, char **argv) {
tr = tr_init(); tr = tr_init();
if(cf_init(tr_getPrefsDirectory(tr), &err)) { if(cf_init(tr_getPrefsDirectory(), &err)) {
if(cf_lock(&err)) { if(cf_lock(&err)) {
/* create main window now so any error dialogs can be it's children */ /* create main window now so any error dialogs can be it's children */
mainwind = gtk_window_new(GTK_WINDOW_TOPLEVEL); mainwind = gtk_window_new(GTK_WINDOW_TOPLEVEL);

View File

@@ -40,11 +40,10 @@
static char * fastResumeFileName( tr_io_t * io ) static char * fastResumeFileName( tr_io_t * io )
{ {
tr_torrent_t * tor = io->tor;
char * ret, * p; char * ret, * p;
int i; int i;
asprintf( &ret, "%s/resume.%40d", tor->prefsDirectory, 0 ); asprintf( &ret, "%s/resume.%40d", tr_getPrefsDirectory(), 0 );
p = &ret[ strlen( ret ) - 2 * SHA_DIGEST_LENGTH ]; p = &ret[ strlen( ret ) - 2 * SHA_DIGEST_LENGTH ];
for( i = 0; i < SHA_DIGEST_LENGTH; i++ ) for( i = 0; i < SHA_DIGEST_LENGTH; i++ )

View File

@@ -104,7 +104,7 @@ FILE * tr_fdFileOpen( tr_fd_t * f, char * path )
int i, winner; int i, winner;
uint64_t date; uint64_t date;
tr_lockLock( f->lock ); tr_lockLock( &f->lock );
/* Is it already open? */ /* Is it already open? */
for( i = 0; i < TR_MAX_OPEN_FILES; i++ ) for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
@@ -115,9 +115,9 @@ FILE * tr_fdFileOpen( tr_fd_t * f, char * path )
if( f->open[i].status & STATUS_CLOSING ) if( f->open[i].status & STATUS_CLOSING )
{ {
/* Wait until the file is closed */ /* Wait until the file is closed */
tr_lockUnlock( f->lock ); tr_lockUnlock( &f->lock );
tr_wait( 10 ); tr_wait( 10 );
tr_lockLock( f->lock ); tr_lockLock( &f->lock );
i = -1; i = -1;
continue; continue;
} }
@@ -162,16 +162,16 @@ FILE * tr_fdFileOpen( tr_fd_t * f, char * path )
and we don't want to block other threads */ and we don't want to block other threads */
tr_dbg( "Closing %s", f->open[winner].path ); tr_dbg( "Closing %s", f->open[winner].path );
f->open[winner].status = STATUS_CLOSING; f->open[winner].status = STATUS_CLOSING;
tr_lockUnlock( f->lock ); tr_lockUnlock( &f->lock );
fclose( f->open[winner].file ); fclose( f->open[winner].file );
tr_lockLock( f->lock ); tr_lockLock( &f->lock );
goto open; goto open;
} }
/* All used! Wait a bit and try again */ /* All used! Wait a bit and try again */
tr_lockUnlock( f->lock ); tr_lockUnlock( &f->lock );
tr_wait( 10 ); tr_wait( 10 );
tr_lockLock( f->lock ); tr_lockLock( &f->lock );
} }
open: open:
@@ -182,7 +182,7 @@ open:
done: done:
f->open[winner].status = STATUS_USED; f->open[winner].status = STATUS_USED;
f->open[winner].date = tr_date(); f->open[winner].date = tr_date();
tr_lockUnlock( f->lock ); tr_lockUnlock( &f->lock );
return f->open[winner].file; return f->open[winner].file;
} }
@@ -193,7 +193,7 @@ done:
void tr_fdFileRelease( tr_fd_t * f, FILE * file ) void tr_fdFileRelease( tr_fd_t * f, FILE * file )
{ {
int i; int i;
tr_lockLock( f->lock ); tr_lockLock( &f->lock );
for( i = 0; i < TR_MAX_OPEN_FILES; i++ ) for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
{ {
@@ -204,7 +204,7 @@ void tr_fdFileRelease( tr_fd_t * f, FILE * file )
} }
} }
tr_lockUnlock( f->lock ); tr_lockUnlock( &f->lock );
} }
/*********************************************************************** /***********************************************************************
@@ -214,7 +214,7 @@ void tr_fdFileClose( tr_fd_t * f, char * path )
{ {
int i; int i;
tr_lockLock( f->lock ); tr_lockLock( &f->lock );
/* Is it already open? */ /* Is it already open? */
for( i = 0; i < TR_MAX_OPEN_FILES; i++ ) for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
@@ -232,14 +232,14 @@ void tr_fdFileClose( tr_fd_t * f, char * path )
} }
} }
tr_lockUnlock( f->lock ); tr_lockUnlock( &f->lock );
} }
int tr_fdSocketWillCreate( tr_fd_t * f, int reserved ) int tr_fdSocketWillCreate( tr_fd_t * f, int reserved )
{ {
int ret; int ret;
tr_lockLock( f->lock ); tr_lockLock( &f->lock );
if( reserved ) if( reserved )
{ {
@@ -266,14 +266,14 @@ int tr_fdSocketWillCreate( tr_fd_t * f, int reserved )
} }
} }
tr_lockUnlock( f->lock ); tr_lockUnlock( &f->lock );
return ret; return ret;
} }
void tr_fdSocketClosed( tr_fd_t * f, int reserved ) void tr_fdSocketClosed( tr_fd_t * f, int reserved )
{ {
tr_lockLock( f->lock ); tr_lockLock( &f->lock );
if( reserved ) if( reserved )
{ {
@@ -284,12 +284,12 @@ void tr_fdSocketClosed( tr_fd_t * f, int reserved )
(f->normal)--; (f->normal)--;
} }
tr_lockUnlock( f->lock ); tr_lockUnlock( &f->lock );
} }
void tr_fdClose( tr_fd_t * f ) void tr_fdClose( tr_fd_t * f )
{ {
tr_lockClose( f->lock ); tr_lockClose( &f->lock );
free( f ); free( f );
} }

View File

@@ -368,7 +368,7 @@ static int readOrWriteBytes( tr_io_t * io, uint64_t offset, int size,
/* Release the torrent lock so the UI can still update itself if /* Release the torrent lock so the UI can still update itself if
this blocks for a while */ this blocks for a while */
tr_lockUnlock( tor->lock ); tr_lockUnlock( &tor->lock );
/* We don't ever read or write more than a piece at a time */ /* We don't ever read or write more than a piece at a time */
if( tr_pieceSize( piece ) < begin + size ) if( tr_pieceSize( piece ) < begin + size )
@@ -439,11 +439,11 @@ static int readOrWriteBytes( tr_io_t * io, uint64_t offset, int size,
buf += cur; buf += cur;
} }
tr_lockLock( tor->lock ); tr_lockLock( &tor->lock );
return 0; return 0;
fail: fail:
tr_lockLock( tor->lock ); tr_lockLock( &tor->lock );
return 1; return 1;
} }

View File

@@ -71,30 +71,6 @@
#define TR_NTOHL(p,a) (a) = ntohl(*((uint32_t*)(p))) #define TR_NTOHL(p,a) (a) = ntohl(*((uint32_t*)(p)))
#define TR_HTONL(a,p) *((uint32_t*)(p)) = htonl((a)) #define TR_HTONL(a,p) *((uint32_t*)(p)) = htonl((a))
/* Multithreading support: native threads on BeOS, pthreads elsewhere */
#ifdef SYS_BEOS
# include <kernel/OS.h>
# define tr_thread_t thread_id
# define tr_threadCreate(pt,f,d) *(pt) = spawn_thread((void*)f,"",10,d); \
resume_thread(*(pt));
# define tr_threadJoin(t) { long e; wait_for_thread(t,&e); }
# define tr_lock_t sem_id
# define tr_lockInit(pl) *(pl) = create_sem(1,"")
# define tr_lockLock(l) acquire_sem(l)
# define tr_lockUnlock(l) release_sem(l)
# define tr_lockClose(l) delete_sem(l)
#else
# include <pthread.h>
# define tr_thread_t pthread_t
# define tr_threadCreate(pt,f,d) pthread_create(pt,NULL,(void*)f,d)
# define tr_threadJoin(t) pthread_join(t,NULL)
# define tr_lock_t pthread_mutex_t
# define tr_lockInit(pl) pthread_mutex_init(pl,NULL)
# define tr_lockLock(l) pthread_mutex_lock(&l)
# define tr_lockUnlock(l) pthread_mutex_unlock(&l)
# define tr_lockClose(l) pthread_mutex_destroy(&l)
#endif
/* Sometimes the system defines MAX/MIN, sometimes not. In the latter /* Sometimes the system defines MAX/MIN, sometimes not. In the latter
case, define those here since we will use them */ case, define those here since we will use them */
#ifndef MAX #ifndef MAX
@@ -109,6 +85,7 @@
typedef struct tr_torrent_s tr_torrent_t; typedef struct tr_torrent_s tr_torrent_t;
typedef struct tr_completion_s tr_completion_t; typedef struct tr_completion_s tr_completion_t;
#include "platform.h"
#include "bencode.h" #include "bencode.h"
#include "metainfo.h" #include "metainfo.h"
#include "tracker.h" #include "tracker.h"
@@ -171,8 +148,6 @@ struct tr_torrent_s
uint64_t dates[10]; uint64_t dates[10];
uint64_t downloaded[10]; uint64_t downloaded[10];
uint64_t uploaded[10]; uint64_t uploaded[10];
char * prefsDirectory;
}; };
#include "utils.h" #include "utils.h"
@@ -190,7 +165,6 @@ struct tr_handle_s
char id[21]; char id[21];
char key[21]; char key[21];
char prefsDirectory[256];
}; };
#endif #endif

View File

@@ -20,40 +20,109 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*****************************************************************************/ *****************************************************************************/
#include "platform.h" #ifdef SYS_BEOS
#include <fs_info.h>
#include <FindDirectory.h>
#endif
#ifdef SYS_DARWIN
#include <sys/types.h>
#include <dirent.h>
#endif
#include "transmission.h"
char * tr_getPrefsDirectory()
{
static char prefsDirectory[MAX_PATH_LENGTH];
static int init = 0;
if( init )
{
return prefsDirectory;
}
#ifdef SYS_BEOS #ifdef SYS_BEOS
/***********************************************************************
* tr_init_beos
***********************************************************************
* Puts the prefsDirectory in the right place.
**********************************************************************/
void tr_init_beos( tr_handle_t * h )
{
int32 length = 0;
char path[B_FILE_NAME_LENGTH];
find_directory( B_USER_SETTINGS_DIRECTORY, dev_for_path("/boot"), find_directory( B_USER_SETTINGS_DIRECTORY, dev_for_path("/boot"),
true, path, length ); true, prefsDirectory, MAX_PATH_LENGTH );
strcat( prefsDirectory, "/Transmission" );
snprintf( h->prefsDirectory, B_FILE_NAME_LENGTH, #elif defined( SYS_DARWIN )
"%s/Transmission", path ); snprintf( prefsDirectory, MAX_PATH_LENGTH,
mkdir( h->prefsDirectory, 0755 ); "%s/Library/Caches/Transmission", getenv( "HOME" ) );
} #else
snprintf( prefsDirectory, MAX_PATH_LENGTH, "%s/.transmission",
getenv( "HOME" ) );
#endif #endif
/*********************************************************************** mkdir( prefsDirectory, 0755 );
* tr_init_platform init = 1;
***********************************************************************
* Setup the prefsDirectory for the current platform. #ifdef SYS_DARWIN
**********************************************************************/ DIR * dirh;
void tr_init_platform( tr_handle_t *h ) struct dirent * dirp;
char oldDirectory[MAX_PATH_LENGTH];
char oldFile[MAX_PATH_LENGTH];
char newFile[MAX_PATH_LENGTH];
snprintf( oldDirectory, MAX_PATH_LENGTH, "%s/.transmission",
getenv( "HOME" ) );
if( ( dirh = opendir( oldDirectory ) ) )
{
while( ( dirp = readdir( dirh ) ) )
{
if( !strcmp( ".", dirp->d_name ) ||
!strcmp( "..", dirp->d_name ) )
{
continue;
}
snprintf( oldFile, MAX_PATH_LENGTH, "%s/%s",
oldDirectory, dirp->d_name );
snprintf( newFile, MAX_PATH_LENGTH, "%s/%s",
prefsDirectory, dirp->d_name );
rename( oldFile, newFile );
}
closedir( dirh );
rmdir( oldDirectory );
}
#endif
return prefsDirectory;
}
void tr_threadCreate( tr_thread_t * t, void (*func)(void *), void * arg )
{ {
#ifdef SYS_BEOS #ifdef SYS_BEOS
tr_init_beos( h ); *t = spawn_thread( (void *) func, "torrent-tx", arg );
resume_thread( *t );
#else #else
snprintf( h->prefsDirectory, sizeof( h->prefsDirectory ), pthread_create( t, NULL, (void *) func, arg );
"%s/.transmission", getenv( "HOME" ) );
mkdir( h->prefsDirectory, 0755 );
#endif #endif
} }
void tr_threadJoin( tr_thread_t * t )
{
#ifdef SYS_BEOS
long exit;
wait_for_thread( *t, &exit );
#else
pthread_join( *t, NULL );
#endif
}
void tr_lockInit( tr_lock_t * l )
{
#ifdef SYS_BEOS
*l = create_sem( 1, "" );
#else
pthread_mutex_init( l, NULL );
#endif
}
void tr_lockClose( tr_lock_t * l )
{
#ifdef SYS_BEOS
delete_sem( *l );
#else
pthread_mutex_destroy( l );
#endif
}

View File

@@ -1,5 +1,3 @@
#ifndef TR_PLATFORM_H
#define TR_PLATFORM_H 1
/****************************************************************************** /******************************************************************************
* Copyright (c) 2005 Eric Petit * Copyright (c) 2005 Eric Petit
* *
@@ -21,22 +19,40 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*****************************************************************************/ *****************************************************************************/
#ifndef TR_PLATFORM_H
#include "transmission.h" #define TR_PLATFORM_H 1
#ifdef SYS_BEOS #ifdef SYS_BEOS
#include <fs_info.h> #include <kernel/OS.h>
#include <FindDirectory.h> typedef thread_id tr_thread_t;
typedef sem_id tr_lock_t;
#else
#include <pthread.h>
typedef pthread_t tr_thread_t;
typedef pthread_mutex_t tr_lock_t;
#endif #endif
/*********************************************************************** void tr_threadCreate ( tr_thread_t *, void (*func)(void *), void * arg );
* tr_init_platform void tr_threadJoin ( tr_thread_t * );
*********************************************************************** void tr_lockInit ( tr_lock_t * );
* Performs some platform specific initialization. void tr_lockClose ( tr_lock_t * );
**********************************************************************/
void tr_init_platform( tr_handle_t *h );
static inline void tr_lockLock( tr_lock_t * l )
{
#ifdef SYS_BEOS
acquire_sem( *l );
#else
pthread_mutex_lock( l );
#endif
}
static inline void tr_lockUnlock( tr_lock_t * l )
{
#ifdef SYS_BEOS
release_sem( *l );
#else
pthread_mutex_unlock( l );
#endif
}
#endif #endif

View File

@@ -440,7 +440,7 @@ static void recvAnswer( tr_tracker_t * tc )
{ {
tr_err( "Tracker: \"peers\" of size %d", tr_err( "Tracker: \"peers\" of size %d",
bePeers->val.s.i ); bePeers->val.s.i );
tr_lockUnlock( tor->lock ); tr_lockUnlock( &tor->lock );
goto cleanup; goto cleanup;
} }

View File

@@ -22,12 +22,6 @@
#include "transmission.h" #include "transmission.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "platform.h"
/*********************************************************************** /***********************************************************************
* Local prototypes * Local prototypes
**********************************************************************/ **********************************************************************/
@@ -73,21 +67,9 @@ tr_handle_t * tr_init()
h->bindPort = TR_DEFAULT_PORT; h->bindPort = TR_DEFAULT_PORT;
tr_init_platform( h );
return h; return h;
} }
/***********************************************************************
* tr_getPrefsDirectory
***********************************************************************
*
**********************************************************************/
char * tr_getPrefsDirectory( tr_handle_t * h )
{
return (char *) h->prefsDirectory;
}
/*********************************************************************** /***********************************************************************
* tr_setBindPort * tr_setBindPort
*********************************************************************** ***********************************************************************
@@ -125,10 +107,10 @@ void tr_torrentRates( tr_handle_t * h, float * dl, float * ul )
for( i = 0; i < h->torrentCount; i++ ) for( i = 0; i < h->torrentCount; i++ )
{ {
tor = h->torrents[i]; tor = h->torrents[i];
tr_lockLock( tor->lock ); tr_lockLock( &tor->lock );
*dl += rateDownload( tor ); *dl += rateDownload( tor );
*ul += rateUpload( tor ); *ul += rateUpload( tor );
tr_lockUnlock( tor->lock ); tr_lockUnlock( &tor->lock );
} }
} }
@@ -211,7 +193,6 @@ int tr_torrentInit( tr_handle_t * h, const char * path )
tor->upload = h->upload; tor->upload = h->upload;
tor->fdlimit = h->fdlimit; tor->fdlimit = h->fdlimit;
tor->prefsDirectory = (char *) h->prefsDirectory;
/* We have a new torrent */ /* We have a new torrent */
h->torrents[h->torrentCount] = tor; h->torrents[h->torrentCount] = tor;
@@ -277,11 +258,11 @@ void tr_torrentStop( tr_handle_t * h, int t )
{ {
tr_torrent_t * tor = h->torrents[t]; tr_torrent_t * tor = h->torrents[t];
tr_lockLock( tor->lock ); tr_lockLock( &tor->lock );
tr_trackerStopped( tor->tracker ); tr_trackerStopped( tor->tracker );
tor->status = TR_STATUS_STOPPING; tor->status = TR_STATUS_STOPPING;
tor->stopDate = tr_date(); tor->stopDate = tr_date();
tr_lockUnlock( tor->lock ); tr_lockUnlock( &tor->lock );
} }
/*********************************************************************** /***********************************************************************
@@ -294,7 +275,7 @@ static void torrentReallyStop( tr_handle_t * h, int t )
tr_torrent_t * tor = h->torrents[t]; tr_torrent_t * tor = h->torrents[t];
tor->die = 1; tor->die = 1;
tr_threadJoin( tor->thread ); tr_threadJoin( &tor->thread );
tr_dbg( "Thread joined" ); tr_dbg( "Thread joined" );
tr_trackerClose( tor->tracker ); tr_trackerClose( tor->tracker );
@@ -360,7 +341,7 @@ int tr_torrentStat( tr_handle_t * h, tr_stat_t ** stat )
tor->status = TR_STATUS_PAUSE; tor->status = TR_STATUS_PAUSE;
} }
tr_lockLock( tor->lock ); tr_lockLock( &tor->lock );
memcpy( &s[i].info, &tor->info, sizeof( tr_info_t ) ); memcpy( &s[i].info, &tor->info, sizeof( tr_info_t ) );
s[i].status = tor->status; s[i].status = tor->status;
@@ -434,7 +415,7 @@ int tr_torrentStat( tr_handle_t * h, tr_stat_t ** stat )
s[i].folder = tor->destination; s[i].folder = tor->destination;
tr_lockUnlock( tor->lock ); tr_lockUnlock( &tor->lock );
} }
*stat = s; *stat = s;
@@ -459,7 +440,7 @@ void tr_torrentClose( tr_handle_t * h, int t )
h->torrentCount--; h->torrentCount--;
tr_lockClose( tor->lock ); tr_lockClose( &tor->lock );
tr_cpClose( tor->completion ); tr_cpClose( tor->completion );
if( tor->destination ) if( tor->destination )
@@ -492,13 +473,12 @@ static void downloadLoop( void * _tor )
tr_dbg( "Thread started" ); tr_dbg( "Thread started" );
#ifdef SYS_BEOS #ifdef SYS_BEOS
rename_thread(tor->thread, "torrent-tx");
/* This is required because on BeOS, SIGINT is sent to each thread, /* This is required because on BeOS, SIGINT is sent to each thread,
which kills them not nicely */ which kills them not nicely */
signal( SIGINT, SIG_IGN ); signal( SIGINT, SIG_IGN );
#endif #endif
tr_lockLock( tor->lock ); tr_lockLock( &tor->lock );
tr_cpReset( tor->completion ); tr_cpReset( tor->completion );
tor->io = tr_ioInit( tor ); tor->io = tr_ioInit( tor );
@@ -534,13 +514,13 @@ static void downloadLoop( void * _tor )
date2 = tr_date(); date2 = tr_date();
if( date2 < date1 + 20 ) if( date2 < date1 + 20 )
{ {
tr_lockUnlock( tor->lock ); tr_lockUnlock( &tor->lock );
tr_wait( date1 + 20 - date2 ); tr_wait( date1 + 20 - date2 );
tr_lockLock( tor->lock ); tr_lockLock( &tor->lock );
} }
} }
tr_lockUnlock( tor->lock ); tr_lockUnlock( &tor->lock );
tr_ioClose( tor->io ); tr_ioClose( tor->io );
@@ -580,7 +560,3 @@ static float rateUpload( tr_torrent_t * tor )
{ {
return rateGeneric( tor->dates, tor->uploaded ); return rateGeneric( tor->dates, tor->uploaded );
} }
#ifdef __cplusplus
}
#endif

View File

@@ -30,7 +30,7 @@ extern "C" {
#include <inttypes.h> #include <inttypes.h>
#define SHA_DIGEST_LENGTH 20 #define SHA_DIGEST_LENGTH 20
#ifdef SYS_BEOS #ifdef __BEOS__
# include <StorageDefs.h> # include <StorageDefs.h>
# define MAX_PATH_LENGTH B_FILE_NAME_LENGTH # define MAX_PATH_LENGTH B_FILE_NAME_LENGTH
#else #else
@@ -57,7 +57,7 @@ tr_handle_t * tr_init();
* store the resume files. The string belongs to libtransmission, do * store the resume files. The string belongs to libtransmission, do
* not free it. * not free it.
**********************************************************************/ **********************************************************************/
char * tr_getPrefsDirectory( tr_handle_t * ); char * tr_getPrefsDirectory();
/*********************************************************************** /***********************************************************************
* tr_setBindPort * tr_setBindPort
@@ -230,8 +230,8 @@ struct tr_stat_s
int peersUploading; int peersUploading;
int peersDownloading; int peersDownloading;
char pieces[120]; char pieces[120];
int seeders; int seeders;
int leechers; int leechers;
uint64_t downloaded; uint64_t downloaded;
uint64_t uploaded; uint64_t uploaded;

View File

@@ -45,16 +45,16 @@ tr_upload_t * tr_uploadInit()
void tr_uploadSetLimit( tr_upload_t * u, int limit ) void tr_uploadSetLimit( tr_upload_t * u, int limit )
{ {
tr_lockLock( u->lock ); tr_lockLock( &u->lock );
u->limit = limit; u->limit = limit;
tr_lockUnlock( u->lock ); tr_lockUnlock( &u->lock );
} }
int tr_uploadCanUnchoke( tr_upload_t * u ) int tr_uploadCanUnchoke( tr_upload_t * u )
{ {
int ret; int ret;
tr_lockLock( u->lock ); tr_lockLock( &u->lock );
if( u->limit < 0 ) if( u->limit < 0 )
{ {
/* Infinite number of slots */ /* Infinite number of slots */
@@ -65,23 +65,23 @@ int tr_uploadCanUnchoke( tr_upload_t * u )
/* One slot per 2 KB/s */ /* One slot per 2 KB/s */
ret = ( u->count < ( u->limit + 1 ) / 2 ); ret = ( u->count < ( u->limit + 1 ) / 2 );
} }
tr_lockUnlock( u->lock ); tr_lockUnlock( &u->lock );
return ret; return ret;
} }
void tr_uploadChoked( tr_upload_t * u ) void tr_uploadChoked( tr_upload_t * u )
{ {
tr_lockLock( u->lock ); tr_lockLock( &u->lock );
(u->count)--; (u->count)--;
tr_lockUnlock( u->lock ); tr_lockUnlock( &u->lock );
} }
void tr_uploadUnchoked( tr_upload_t * u ) void tr_uploadUnchoked( tr_upload_t * u )
{ {
tr_lockLock( u->lock ); tr_lockLock( &u->lock );
(u->count)++; (u->count)++;
tr_lockUnlock( u->lock ); tr_lockUnlock( &u->lock );
} }
int tr_uploadCanUpload( tr_upload_t * u ) int tr_uploadCanUpload( tr_upload_t * u )
@@ -89,7 +89,7 @@ int tr_uploadCanUpload( tr_upload_t * u )
int ret, i, size; int ret, i, size;
uint64_t now; uint64_t now;
tr_lockLock( u->lock ); tr_lockLock( &u->lock );
if( u->limit < 0 ) if( u->limit < 0 )
{ {
/* No limit */ /* No limit */
@@ -114,23 +114,23 @@ int tr_uploadCanUpload( tr_upload_t * u )
} }
} }
} }
tr_lockUnlock( u->lock ); tr_lockUnlock( &u->lock );
return ret; return ret;
} }
void tr_uploadUploaded( tr_upload_t * u, int size ) void tr_uploadUploaded( tr_upload_t * u, int size )
{ {
tr_lockLock( u->lock ); tr_lockLock( &u->lock );
memmove( &u->dates[1], &u->dates[0], (FOO-1) * sizeof( uint64_t ) ); memmove( &u->dates[1], &u->dates[0], (FOO-1) * sizeof( uint64_t ) );
memmove( &u->sizes[1], &u->sizes[0], (FOO-1) * sizeof( int ) ); memmove( &u->sizes[1], &u->sizes[0], (FOO-1) * sizeof( int ) );
u->dates[0] = tr_date(); u->dates[0] = tr_date();
u->sizes[0] = size; u->sizes[0] = size;
tr_lockUnlock( u->lock ); tr_lockUnlock( &u->lock );
} }
void tr_uploadClose( tr_upload_t * u ) void tr_uploadClose( tr_upload_t * u )
{ {
tr_lockClose( u->lock ); tr_lockClose( &u->lock );
free( u ); free( u );
} }

View File

@@ -246,36 +246,21 @@ static void sleepCallBack( void * controller, io_service_t y,
- (void) showPreferenceWindow: (id) sender - (void) showPreferenceWindow: (id) sender
{ {
NSRect mainFrame; //place the window if not open
NSRect prefsFrame; if (![fPrefsWindow isVisible])
NSRect screenRect;
NSPoint point;
/* Place the window */
mainFrame = [fWindow frame];
prefsFrame = [fPrefsWindow frame];
screenRect = [[NSScreen mainScreen] visibleFrame];
point.x = mainFrame.origin.x + mainFrame.size.width / 2 -
prefsFrame.size.width / 2;
point.y = mainFrame.origin.y + mainFrame.size.height - 30;
/* Make sure it is in the screen */
if( point.x < screenRect.origin.x )
{ {
point.x = screenRect.origin.x; NSRect prefsFrame, screenRect;
} NSPoint point;
if( point.x + prefsFrame.size.width >
screenRect.origin.x + screenRect.size.width )
{
point.x = screenRect.origin.x +
screenRect.size.width - prefsFrame.size.width;
}
if( point.y - prefsFrame.size.height < screenRect.origin.y )
{
point.y = screenRect.origin.y + prefsFrame.size.height;
}
[fPrefsWindow setFrameTopLeftPoint: point]; prefsFrame = [fPrefsWindow frame];
screenRect = [[NSScreen mainScreen] visibleFrame];
point.x = (screenRect.size.width - prefsFrame.size.width) * 0.5;
point.y = screenRect.origin.y + screenRect.size.height * 0.67 +
prefsFrame.size.height * 0.33;
[fPrefsWindow setFrameTopLeftPoint: point];
}
[fPrefsWindow makeKeyAndOrderFront:NULL]; [fPrefsWindow makeKeyAndOrderFront:NULL];
} }
@@ -309,37 +294,40 @@ static void sleepCallBack( void * controller, io_service_t y,
if( tr_torrentInit( fHandle, [torrentPath UTF8String] ) ) if( tr_torrentInit( fHandle, [torrentPath UTF8String] ) )
continue; continue;
/* Add it to the "File > Open Recent" menu */
[[NSDocumentController sharedDocumentController]
noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
if( [downloadChoice isEqualToString: @"Constant"] ) if( [downloadChoice isEqualToString: @"Constant"] )
{ {
tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
[downloadFolder UTF8String] ); [downloadFolder UTF8String] );
tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
continue;
} }
else if( [downloadChoice isEqualToString: @"Torrent"] )
if( [downloadChoice isEqualToString: @"Torrent"] )
{ {
tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
[[torrentPath stringByDeletingLastPathComponent] UTF8String] ); [[torrentPath stringByDeletingLastPathComponent] UTF8String] );
tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
continue;
} }
else
{
NSOpenPanel * panel = [NSOpenPanel openPanel];
[panel setPrompt: @"Select Download Folder"];
[panel setMessage: [NSString stringWithFormat:
@"Select the download folder for %@",
[torrentPath lastPathComponent]]];
[panel setAllowsMultipleSelection: NO];
[panel setCanChooseFiles: NO];
[panel setCanChooseDirectories: YES];
NSOpenPanel * panel = [NSOpenPanel openPanel]; [panel beginSheetForDirectory: NULL file: NULL types: NULL
modalForWindow: fWindow modalDelegate: self didEndSelector:
[panel setPrompt: @"Select Download Folder"]; @selector( folderChoiceClosed:returnCode:contextInfo: )
[panel setMessage: [NSString stringWithFormat: contextInfo: NULL];
@"Select the download folder for %@", [NSApp runModalForWindow: panel];
[torrentPath lastPathComponent]]]; }
[panel setAllowsMultipleSelection: NO];
[panel setCanChooseFiles: NO];
[panel setCanChooseDirectories: YES];
[panel beginSheetForDirectory: NULL file: NULL types: NULL
modalForWindow: fWindow modalDelegate: self didEndSelector:
@selector( folderChoiceClosed:returnCode:contextInfo: )
contextInfo: NULL];
[NSApp runModalForWindow: panel];
} }
[self updateUI: NULL]; [self updateUI: NULL];

View File

@@ -70,7 +70,6 @@
LANGUAGE = ObjC; LANGUAGE = ObjC;
OUTLETS = { OUTLETS = {
fBlankView = NSView; fBlankView = NSView;
fFolderMatrix = NSMatrix;
fFolderPopUp = NSPopUpButton; fFolderPopUp = NSPopUpButton;
fGeneralView = NSView; fGeneralView = NSView;
fNetworkView = NSView; fNetworkView = NSView;

View File

@@ -15,11 +15,11 @@
<key>589</key> <key>589</key>
<string>54 521 112 118 0 0 1152 842 </string> <string>54 521 112 118 0 0 1152 842 </string>
<key>783</key> <key>783</key>
<string>428 442 385 225 0 0 1280 832 </string> <string>409 477 420 155 0 0 1280 832 </string>
<key>796</key> <key>796</key>
<string>479 490 282 129 0 0 1280 832 </string> <string>409 490 420 129 0 0 1280 832 </string>
<key>825</key> <key>825</key>
<string>498 523 155 107 0 0 1152 842 </string> <string>542 501 155 107 0 0 1280 832 </string>
</dict> </dict>
<key>IBFramework Version</key> <key>IBFramework Version</key>
<string>443.0</string> <string>443.0</string>
@@ -27,10 +27,12 @@
<integer>3</integer> <integer>3</integer>
<key>IBOpenObjects</key> <key>IBOpenObjects</key>
<array> <array>
<integer>29</integer> <integer>781</integer>
<integer>783</integer> <integer>783</integer>
<integer>796</integer>
<integer>21</integer> <integer>21</integer>
<integer>796</integer>
<integer>825</integer>
<integer>29</integer>
</array> </array>
<key>IBSystem Version</key> <key>IBSystem Version</key>
<string>8F46</string> <string>8F46</string>

Binary file not shown.

View File

@@ -34,7 +34,6 @@
IBOutlet NSView * fNetworkView; IBOutlet NSView * fNetworkView;
IBOutlet NSView * fBlankView; IBOutlet NSView * fBlankView;
IBOutlet NSMatrix * fFolderMatrix;
IBOutlet NSPopUpButton * fFolderPopUp; IBOutlet NSPopUpButton * fFolderPopUp;
IBOutlet NSTextField * fPortField; IBOutlet NSTextField * fPortField;
IBOutlet NSButton * fUploadCheck; IBOutlet NSButton * fUploadCheck;

View File

@@ -27,8 +27,8 @@
#define MAX_PORT 65535 #define MAX_PORT 65535
#define DOWNLOAD_FOLDER 0 #define DOWNLOAD_FOLDER 0
#define DOWNLOAD_TORRENT 1 #define DOWNLOAD_TORRENT 2
#define DOWNLOAD_ASK 2 #define DOWNLOAD_ASK 3
#define TOOLBAR_GENERAL @"General" #define TOOLBAR_GENERAL @"General"
#define TOOLBAR_NETWORK @"Network" #define TOOLBAR_NETWORK @"Network"
@@ -58,7 +58,7 @@
- Always download to Desktop - Always download to Desktop
- Port TR_DEFAULT_PORT - Port TR_DEFAULT_PORT
- Upload limit DEFAULT_UPLOAD - Upload limit DEFAULT_UPLOAD
- Do not limit upload - Limit upload
- Ask before quitting - Ask before quitting
- Ask before removing */ - Ask before removing */
desktop = [NSHomeDirectory() stringByAppendingString: @"/Desktop"]; desktop = [NSHomeDirectory() stringByAppendingString: @"/Desktop"];
@@ -105,18 +105,17 @@
if( [downloadChoice isEqualToString: @"Constant"] ) if( [downloadChoice isEqualToString: @"Constant"] )
{ {
[fFolderMatrix selectCellAtRow: DOWNLOAD_FOLDER column: 0]; [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
} }
else if( [downloadChoice isEqualToString: @"Torrent"] ) else if( [downloadChoice isEqualToString: @"Torrent"] )
{ {
[fFolderMatrix selectCellAtRow: DOWNLOAD_TORRENT column: 0]; [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
} }
else else
{ {
[fFolderMatrix selectCellAtRow: DOWNLOAD_ASK column: 0]; [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
} }
[self updatePopUp]; [self updatePopUp];
[fFolderPopUp setEnabled: [fFolderMatrix selectedRow] == 0];
//set bind port //set bind port
int bindPort = [fDefaults integerForKey: @"BindPort"]; int bindPort = [fDefaults integerForKey: @"BindPort"];
@@ -269,7 +268,7 @@
- (void) setDownloadLocation: (id) sender - (void) setDownloadLocation: (id) sender
{ {
//Download folder //Download folder
switch( [fFolderMatrix selectedRow] ) switch( [fFolderPopUp indexOfSelectedItem] )
{ {
case DOWNLOAD_FOLDER: case DOWNLOAD_FOLDER:
[fDefaults setObject: @"Constant" forKey: @"DownloadChoice"]; [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
@@ -281,7 +280,6 @@
[fDefaults setObject: @"Ask" forKey: @"DownloadChoice"]; [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
break; break;
} }
[fFolderPopUp setEnabled: [fFolderMatrix selectedRow] == 0];
} }
- (void) folderSheetShow: (id) sender - (void) folderSheetShow: (id) sender
@@ -330,18 +328,35 @@
- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code
contextInfo: (void *) info contextInfo: (void *) info
{ {
[fFolderPopUp selectItemAtIndex: 0]; if (code == NSOKButton)
{
[fDownloadFolder release];
fDownloadFolder = [[openPanel filenames] objectAtIndex: 0];
[fDownloadFolder retain];
if (code != NSOKButton) [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
return; [fDefaults setObject: fDownloadFolder forKey: @"DownloadFolder"];
[fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
[fDownloadFolder release]; [self updatePopUp];
fDownloadFolder = [[openPanel filenames] objectAtIndex: 0]; }
[fDownloadFolder retain]; else
{
[fDefaults setObject: fDownloadFolder forKey: @"DownloadFolder"]; //reset if cancelled
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
[self updatePopUp]; if( [downloadChoice isEqualToString: @"Constant"] )
{
[fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
}
else if( [downloadChoice isEqualToString: @"Torrent"] )
{
[fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
}
else
{
[fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
}
}
} }
- (void) updatePopUp - (void) updatePopUp