1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-30 19:03:04 +00:00

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

View file

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

View file

@ -40,11 +40,10 @@
static char * fastResumeFileName( tr_io_t * io )
{
tr_torrent_t * tor = io->tor;
char * ret, * p;
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 ];
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;
uint64_t date;
tr_lockLock( f->lock );
tr_lockLock( &f->lock );
/* Is it already open? */
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 )
{
/* Wait until the file is closed */
tr_lockUnlock( f->lock );
tr_lockUnlock( &f->lock );
tr_wait( 10 );
tr_lockLock( f->lock );
tr_lockLock( &f->lock );
i = -1;
continue;
}
@ -162,16 +162,16 @@ FILE * tr_fdFileOpen( tr_fd_t * f, char * path )
and we don't want to block other threads */
tr_dbg( "Closing %s", f->open[winner].path );
f->open[winner].status = STATUS_CLOSING;
tr_lockUnlock( f->lock );
tr_lockUnlock( &f->lock );
fclose( f->open[winner].file );
tr_lockLock( f->lock );
tr_lockLock( &f->lock );
goto open;
}
/* All used! Wait a bit and try again */
tr_lockUnlock( f->lock );
tr_lockUnlock( &f->lock );
tr_wait( 10 );
tr_lockLock( f->lock );
tr_lockLock( &f->lock );
}
open:
@ -182,7 +182,7 @@ open:
done:
f->open[winner].status = STATUS_USED;
f->open[winner].date = tr_date();
tr_lockUnlock( f->lock );
tr_lockUnlock( &f->lock );
return f->open[winner].file;
}
@ -193,7 +193,7 @@ done:
void tr_fdFileRelease( tr_fd_t * f, FILE * file )
{
int i;
tr_lockLock( f->lock );
tr_lockLock( &f->lock );
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;
tr_lockLock( f->lock );
tr_lockLock( &f->lock );
/* Is it already open? */
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 ret;
tr_lockLock( f->lock );
tr_lockLock( &f->lock );
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;
}
void tr_fdSocketClosed( tr_fd_t * f, int reserved )
{
tr_lockLock( f->lock );
tr_lockLock( &f->lock );
if( reserved )
{
@ -284,12 +284,12 @@ void tr_fdSocketClosed( tr_fd_t * f, int reserved )
(f->normal)--;
}
tr_lockUnlock( f->lock );
tr_lockUnlock( &f->lock );
}
void tr_fdClose( tr_fd_t * f )
{
tr_lockClose( f->lock );
tr_lockClose( &f->lock );
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
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 */
if( tr_pieceSize( piece ) < begin + size )
@ -439,11 +439,11 @@ static int readOrWriteBytes( tr_io_t * io, uint64_t offset, int size,
buf += cur;
}
tr_lockLock( tor->lock );
tr_lockLock( &tor->lock );
return 0;
fail:
tr_lockLock( tor->lock );
tr_lockLock( &tor->lock );
return 1;
}

View file

@ -71,30 +71,6 @@
#define TR_NTOHL(p,a) (a) = ntohl(*((uint32_t*)(p)))
#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
case, define those here since we will use them */
#ifndef MAX
@ -109,6 +85,7 @@
typedef struct tr_torrent_s tr_torrent_t;
typedef struct tr_completion_s tr_completion_t;
#include "platform.h"
#include "bencode.h"
#include "metainfo.h"
#include "tracker.h"
@ -171,8 +148,6 @@ struct tr_torrent_s
uint64_t dates[10];
uint64_t downloaded[10];
uint64_t uploaded[10];
char * prefsDirectory;
};
#include "utils.h"
@ -190,7 +165,6 @@ struct tr_handle_s
char id[21];
char key[21];
char prefsDirectory[256];
};
#endif

View file

@ -20,40 +20,109 @@
* 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
/***********************************************************************
* 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"),
true, path, length );
snprintf( h->prefsDirectory, B_FILE_NAME_LENGTH,
"%s/Transmission", path );
mkdir( h->prefsDirectory, 0755 );
}
true, prefsDirectory, MAX_PATH_LENGTH );
strcat( prefsDirectory, "/Transmission" );
#elif defined( SYS_DARWIN )
snprintf( prefsDirectory, MAX_PATH_LENGTH,
"%s/Library/Caches/Transmission", getenv( "HOME" ) );
#else
snprintf( prefsDirectory, MAX_PATH_LENGTH, "%s/.transmission",
getenv( "HOME" ) );
#endif
/***********************************************************************
* tr_init_platform
***********************************************************************
* Setup the prefsDirectory for the current platform.
**********************************************************************/
void tr_init_platform( tr_handle_t *h )
mkdir( prefsDirectory, 0755 );
init = 1;
#ifdef SYS_DARWIN
DIR * dirh;
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
tr_init_beos( h );
*t = spawn_thread( (void *) func, "torrent-tx", arg );
resume_thread( *t );
#else
snprintf( h->prefsDirectory, sizeof( h->prefsDirectory ),
"%s/.transmission", getenv( "HOME" ) );
mkdir( h->prefsDirectory, 0755 );
pthread_create( t, NULL, (void *) func, arg );
#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
*
@ -21,22 +19,40 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include "transmission.h"
#ifndef TR_PLATFORM_H
#define TR_PLATFORM_H 1
#ifdef SYS_BEOS
#include <fs_info.h>
#include <FindDirectory.h>
#include <kernel/OS.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
/***********************************************************************
* tr_init_platform
***********************************************************************
* Performs some platform specific initialization.
**********************************************************************/
void tr_init_platform( tr_handle_t *h );
void tr_threadCreate ( tr_thread_t *, void (*func)(void *), void * arg );
void tr_threadJoin ( tr_thread_t * );
void tr_lockInit ( tr_lock_t * );
void tr_lockClose ( tr_lock_t * );
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",
bePeers->val.s.i );
tr_lockUnlock( tor->lock );
tr_lockUnlock( &tor->lock );
goto cleanup;
}

View file

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

View file

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

View file

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

View file

@ -246,36 +246,21 @@ static void sleepCallBack( void * controller, io_service_t y,
- (void) showPreferenceWindow: (id) sender
{
NSRect mainFrame;
NSRect prefsFrame;
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 )
//place the window if not open
if (![fPrefsWindow isVisible])
{
point.x = screenRect.origin.x;
}
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;
}
NSRect prefsFrame, screenRect;
NSPoint point;
[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];
}
@ -309,37 +294,40 @@ static void sleepCallBack( void * controller, io_service_t y,
if( tr_torrentInit( fHandle, [torrentPath UTF8String] ) )
continue;
/* Add it to the "File > Open Recent" menu */
[[NSDocumentController sharedDocumentController]
noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
if( [downloadChoice isEqualToString: @"Constant"] )
{
tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
[downloadFolder UTF8String] );
tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
continue;
}
if( [downloadChoice isEqualToString: @"Torrent"] )
else if( [downloadChoice isEqualToString: @"Torrent"] )
{
tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
[[torrentPath stringByDeletingLastPathComponent] UTF8String] );
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 setPrompt: @"Select Download Folder"];
[panel setMessage: [NSString stringWithFormat:
@"Select the download folder for %@",
[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];
[panel beginSheetForDirectory: NULL file: NULL types: NULL
modalForWindow: fWindow modalDelegate: self didEndSelector:
@selector( folderChoiceClosed:returnCode:contextInfo: )
contextInfo: NULL];
[NSApp runModalForWindow: panel];
}
}
[self updateUI: NULL];

View file

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

View file

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

Binary file not shown.

View file

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

View file

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