2006-01-12 17:43:21 +00:00
|
|
|
/******************************************************************************
|
2006-03-23 12:39:39 +00:00
|
|
|
* Copyright (c) 2005-2006 Transmission authors and contributors
|
2006-01-12 17:43:21 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2006-01-20 01:13:21 +00:00
|
|
|
#import <IOKit/IOMessage.h>
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
#import "Controller.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
#import "TorrentCell.h"
|
2006-01-20 01:13:21 +00:00
|
|
|
#import "StringAdditions.h"
|
|
|
|
#import "Utils.h"
|
|
|
|
#import "TorrentTableView.h"
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
#import "PrefsController.h"
|
|
|
|
|
2006-01-12 18:54:46 +00:00
|
|
|
#define TOOLBAR_OPEN @"Toolbar Open"
|
|
|
|
#define TOOLBAR_REMOVE @"Toolbar Remove"
|
|
|
|
#define TOOLBAR_INFO @"Toolbar Info"
|
|
|
|
#define TOOLBAR_PAUSE_ALL @"Toolbar Pause All"
|
|
|
|
#define TOOLBAR_RESUME_ALL @"Toolbar Resume All"
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-29 22:01:08 +00:00
|
|
|
#define WEBSITE_URL @"http://transmission.m0k.org/"
|
|
|
|
#define FORUM_URL @"http://transmission.m0k.org/forum/"
|
|
|
|
#define VERSION_PLIST_URL @"http://transmission.m0k.org/version.plist"
|
2006-01-12 18:57:23 +00:00
|
|
|
|
|
|
|
#define GROWL_PATH @"/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app"
|
2006-01-12 18:29:20 +00:00
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
static void sleepCallBack( void * controller, io_service_t y,
|
|
|
|
natural_t messageType, void * messageArgument )
|
|
|
|
{
|
|
|
|
Controller * c = controller;
|
|
|
|
[c sleepCallBack: messageType argument: messageArgument];
|
|
|
|
}
|
|
|
|
|
2006-01-12 21:45:45 +00:00
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
@implementation Controller
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
fLib = tr_init();
|
|
|
|
fTorrents = [[NSMutableArray alloc] initWithCapacity: 10];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[fTorrents release];
|
|
|
|
tr_close( fLib );
|
2006-03-28 11:17:42 +00:00
|
|
|
[fAppIcon release];
|
2006-03-23 12:39:39 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2006-03-28 11:17:42 +00:00
|
|
|
fAppIcon = [[NSApp applicationIconImage] copy];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
[fPrefsController setPrefsWindow: fLib];
|
2006-01-12 18:57:23 +00:00
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
//check advanced bar menu item
|
|
|
|
[fAdvancedBarItem setState: [fDefaults
|
2006-01-12 17:43:21 +00:00
|
|
|
boolForKey:@"UseAdvancedBar"] ? NSOnState : NSOffState];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Transmission Toolbar"];
|
|
|
|
[fToolbar setDelegate: self];
|
|
|
|
[fToolbar setAllowsUserCustomization: YES];
|
|
|
|
[fToolbar setAutosavesConfiguration: YES];
|
2006-01-12 18:57:23 +00:00
|
|
|
[fWindow setToolbar: fToolbar];
|
|
|
|
[fWindow setDelegate: self];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
[fTableView setTorrents: fTorrents];
|
|
|
|
[[fTableView tableColumnWithIdentifier: @"Torrent"] setDataCell:
|
|
|
|
[[TorrentCell alloc] init]];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
|
|
|
[fTableView registerForDraggedTypes: [NSArray arrayWithObjects:
|
|
|
|
NSFilenamesPboardType, NULL]];
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
//Register for sleep notifications
|
2006-01-12 17:43:21 +00:00
|
|
|
IONotificationPortRef notify;
|
|
|
|
io_object_t anIterator;
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
fRootPort = IORegisterForSystemPower( self, & notify, sleepCallBack,
|
|
|
|
& anIterator);
|
|
|
|
if (fRootPort)
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
|
|
|
CFRunLoopAddSource( CFRunLoopGetCurrent(),
|
|
|
|
IONotificationPortGetRunLoopSource( notify ),
|
|
|
|
kCFRunLoopCommonModes );
|
|
|
|
}
|
2006-01-12 18:57:23 +00:00
|
|
|
else
|
|
|
|
printf( "Could not IORegisterForSystemPower\n" );
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
NSString * torrentPath, * downloadFolder, * paused;
|
|
|
|
NSDictionary * dic;
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
Torrent * torrent;
|
2006-01-12 18:57:23 +00:00
|
|
|
NSEnumerator * enumerator = [[fDefaults arrayForKey: @"History"] objectEnumerator];
|
|
|
|
while ((dic = [enumerator nextObject]))
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:57:23 +00:00
|
|
|
torrentPath = [dic objectForKey: @"TorrentPath"];
|
|
|
|
downloadFolder = [dic objectForKey: @"DownloadFolder"];
|
|
|
|
paused = [dic objectForKey: @"Paused"];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
if (!torrentPath || !downloadFolder || !paused)
|
|
|
|
continue;
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
torrent = [[Torrent alloc] initWithPath: torrentPath lib: fLib];
|
|
|
|
if( !torrent )
|
2006-01-12 18:57:23 +00:00
|
|
|
continue;
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
[fTorrents addObject: torrent];
|
|
|
|
|
|
|
|
[torrent setFolder: downloadFolder];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
if ([paused isEqualToString: @"NO"])
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent start];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:57:23 +00:00
|
|
|
|
|
|
|
//check and register Growl if it is installed for this user or all users
|
|
|
|
NSFileManager * manager = [NSFileManager defaultManager];
|
|
|
|
fHasGrowl = [manager fileExistsAtPath: GROWL_PATH]
|
|
|
|
|| [manager fileExistsAtPath: [[NSString stringWithFormat: @"~%@",
|
|
|
|
GROWL_PATH] stringByExpandingTildeInPath]];
|
2006-01-12 18:40:47 +00:00
|
|
|
[self growlRegister: self];
|
2006-01-20 01:51:07 +00:00
|
|
|
|
|
|
|
//initialize badging
|
|
|
|
fBadger = [[Badger alloc] init];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
//update the interface every 500 ms
|
2006-01-29 01:20:22 +00:00
|
|
|
fCompleted = 0;
|
2006-02-11 06:46:40 +00:00
|
|
|
[self updateUI: nil];
|
2006-02-07 02:32:50 +00:00
|
|
|
fTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self
|
2006-02-11 06:46:40 +00:00
|
|
|
selector: @selector( updateUI: ) userInfo: nil repeats: YES];
|
2006-01-29 22:01:08 +00:00
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fTimer
|
|
|
|
forMode: NSModalPanelRunLoopMode];
|
2006-01-12 17:43:21 +00:00
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fTimer
|
2006-01-12 18:20:48 +00:00
|
|
|
forMode: NSEventTrackingRunLoopMode];
|
2006-01-29 22:01:08 +00:00
|
|
|
|
|
|
|
[self checkForUpdateTimer: nil];
|
|
|
|
fUpdateTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0
|
|
|
|
target: self selector: @selector( checkForUpdateTimer: )
|
2006-02-11 06:46:40 +00:00
|
|
|
userInfo: nil repeats: YES];
|
2006-01-12 18:20:48 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 01:51:07 +00:00
|
|
|
- (void) windowDidBecomeKey: (NSNotification *) n
|
|
|
|
{
|
|
|
|
/* Reset the number of recently completed downloads */
|
|
|
|
fCompleted = 0;
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:20:48 +00:00
|
|
|
- (void) windowDidResize: (NSNotification *) n
|
|
|
|
{
|
|
|
|
[fTableView sizeToFit];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) windowShouldClose: (id) sender
|
|
|
|
{
|
2006-03-28 11:17:42 +00:00
|
|
|
[fWindow orderOut: nil];
|
2006-01-12 17:43:21 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) applicationShouldHandleReopen: (NSApplication *) app
|
|
|
|
hasVisibleWindows: (BOOL) flag
|
|
|
|
{
|
2006-03-28 11:17:42 +00:00
|
|
|
[self showMainWindow: nil];
|
2006-01-12 17:43:21 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
int active = 0;
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
{
|
|
|
|
if( [torrent isActive] )
|
|
|
|
{
|
|
|
|
active++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-10 20:06:39 +00:00
|
|
|
if (active > 0 && [fDefaults boolForKey: @"CheckQuit"])
|
2006-01-29 01:20:22 +00:00
|
|
|
{
|
|
|
|
NSString * message = active == 1
|
|
|
|
? @"There is an active torrent. Do you really want to quit?"
|
|
|
|
: [NSString stringWithFormat:
|
2006-02-01 00:14:26 +00:00
|
|
|
@"There are %d active torrents. Do you really want to quit?",
|
|
|
|
active];
|
2006-01-29 01:20:22 +00:00
|
|
|
|
|
|
|
NSBeginAlertSheet(@"Confirm Quit",
|
|
|
|
@"Quit", @"Cancel", nil,
|
|
|
|
fWindow, self,
|
|
|
|
@selector(quitSheetDidEnd:returnCode:contextInfo:),
|
|
|
|
nil, nil, message);
|
|
|
|
return NSTerminateLater;
|
2006-03-23 12:39:39 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) quitSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
|
|
|
|
contextInfo:(void *)contextInfo
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:57:23 +00:00
|
|
|
[NSApp stopModal];
|
2006-01-29 22:16:16 +00:00
|
|
|
[NSApp replyToApplicationShouldTerminate:
|
|
|
|
(returnCode == NSAlertDefaultReturn)];
|
2006-01-12 18:57:23 +00:00
|
|
|
}
|
|
|
|
|
2006-01-29 22:16:16 +00:00
|
|
|
- (void) applicationWillTerminate: (NSNotification *) notification
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
NSEnumerator * enumerator;
|
|
|
|
Torrent * torrent;
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
// Stop updating the interface
|
2006-01-12 17:43:21 +00:00
|
|
|
[fTimer invalidate];
|
2006-01-29 22:01:08 +00:00
|
|
|
[fUpdateTimer invalidate];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-29 22:16:16 +00:00
|
|
|
//clear badge
|
|
|
|
[fBadger clearBadge];
|
2006-03-23 12:39:39 +00:00
|
|
|
[fBadger release];
|
2006-01-29 22:16:16 +00:00
|
|
|
|
2006-02-08 19:05:42 +00:00
|
|
|
// Save history
|
|
|
|
[self updateTorrentHistory];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-02-08 19:05:42 +00:00
|
|
|
// Stop running torrents
|
2006-03-23 12:39:39 +00:00
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
{
|
|
|
|
[torrent stop];
|
|
|
|
}
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
// Wait for torrents to stop (5 seconds timeout)
|
2006-01-12 17:43:21 +00:00
|
|
|
NSDate * start = [NSDate date];
|
2006-03-23 12:39:39 +00:00
|
|
|
while( [fTorrents count] )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
torrent = [fTorrents objectAtIndex: 0];
|
2006-01-29 22:16:16 +00:00
|
|
|
while( [[NSDate date] timeIntervalSinceDate: start] < 5 &&
|
2006-03-23 12:39:39 +00:00
|
|
|
![torrent isPaused] )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-29 22:16:16 +00:00
|
|
|
usleep( 100000 );
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent update];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
[fTorrents removeObject: torrent];
|
|
|
|
[torrent release];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:57:23 +00:00
|
|
|
}
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
- (void) showPreferenceWindow: (id) sender
|
|
|
|
{
|
2006-01-12 18:58:57 +00:00
|
|
|
//place the window if not open
|
|
|
|
if (![fPrefsWindow isVisible])
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
2006-02-10 19:17:54 +00:00
|
|
|
[fPrefsWindow center];
|
2006-01-12 18:58:57 +00:00
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
[fPrefsWindow makeKeyAndOrderFront:NULL];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) folderChoiceClosed: (NSOpenPanel *) s returnCode: (int) code
|
2006-04-04 09:45:36 +00:00
|
|
|
contextInfo: (Torrent *) torrent
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:57:23 +00:00
|
|
|
if (code == NSOKButton)
|
|
|
|
{
|
2006-04-04 09:45:36 +00:00
|
|
|
[fTorrents addObject: torrent];
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent setFolder: [[s filenames] objectAtIndex: 0]];
|
|
|
|
[torrent start];
|
2006-01-12 18:57:23 +00:00
|
|
|
}
|
|
|
|
else
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent release];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
[NSApp stopModal];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) application: (NSApplication *) sender
|
|
|
|
openFiles: (NSArray *) filenames
|
|
|
|
{
|
|
|
|
NSString * downloadChoice, * downloadFolder, * torrentPath;
|
2006-03-23 12:39:39 +00:00
|
|
|
Torrent * torrent;
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
|
|
|
|
downloadFolder = [fDefaults stringForKey: @"DownloadFolder"];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
NSEnumerator * enumerator = [filenames objectEnumerator];
|
|
|
|
while ((torrentPath = [enumerator nextObject]))
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
torrent = [[Torrent alloc] initWithPath: torrentPath lib: fLib];
|
|
|
|
if( !torrent )
|
2006-01-12 17:43:21 +00:00
|
|
|
continue;
|
|
|
|
|
2006-01-12 18:58:57 +00:00
|
|
|
/* Add it to the "File > Open Recent" menu */
|
|
|
|
[[NSDocumentController sharedDocumentController]
|
|
|
|
noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
|
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
if( [downloadChoice isEqualToString: @"Constant"] )
|
|
|
|
{
|
2006-04-04 09:45:36 +00:00
|
|
|
[fTorrents addObject: torrent];
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent setFolder: [downloadFolder stringByExpandingTildeInPath]];
|
|
|
|
[torrent start];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:58:57 +00:00
|
|
|
else if( [downloadChoice isEqualToString: @"Torrent"] )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-04-04 09:45:36 +00:00
|
|
|
[fTorrents addObject: torrent];
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent setFolder: [torrentPath stringByDeletingLastPathComponent]];
|
|
|
|
[torrent start];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:58:57 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:58:57 +00:00
|
|
|
[panel setPrompt: @"Select Download Folder"];
|
|
|
|
[panel setAllowsMultipleSelection: NO];
|
|
|
|
[panel setCanChooseFiles: NO];
|
|
|
|
[panel setCanChooseDirectories: YES];
|
|
|
|
|
2006-04-03 19:29:09 +00:00
|
|
|
if( [panel respondsToSelector: @selector(setMessage:)] )
|
|
|
|
/* >= 10.3 */
|
|
|
|
[panel setMessage: [NSString stringWithFormat:
|
|
|
|
@"Select the download folder for %@",
|
|
|
|
[torrentPath lastPathComponent]]];
|
|
|
|
|
2006-01-12 18:58:57 +00:00
|
|
|
[panel beginSheetForDirectory: NULL file: NULL types: NULL
|
|
|
|
modalForWindow: fWindow modalDelegate: self didEndSelector:
|
|
|
|
@selector( folderChoiceClosed:returnCode:contextInfo: )
|
2006-04-04 09:45:36 +00:00
|
|
|
contextInfo: torrent];
|
2006-01-12 18:58:57 +00:00
|
|
|
[NSApp runModalForWindow: panel];
|
|
|
|
}
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-04-04 09:45:36 +00:00
|
|
|
[self updateUI: nil];
|
2006-02-08 19:05:42 +00:00
|
|
|
[self updateTorrentHistory];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) advancedChanged: (id) sender
|
|
|
|
{
|
2006-01-12 18:57:23 +00:00
|
|
|
[fAdvancedBarItem setState: ![fAdvancedBarItem state]];
|
|
|
|
[fDefaults setObject: [fAdvancedBarItem state] == NSOffState ? @"NO" : @"YES"
|
|
|
|
forKey:@"UseAdvancedBar"];
|
|
|
|
|
2006-01-12 18:33:20 +00:00
|
|
|
[fTableView display];
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
//called on by applescript
|
2006-01-12 18:33:20 +00:00
|
|
|
- (void) open: (NSArray *) files
|
|
|
|
{
|
|
|
|
[self performSelectorOnMainThread: @selector(cantFindAName:)
|
2006-04-05 13:39:30 +00:00
|
|
|
withObject: files waitUntilDone: NO];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openShowSheet: (id) sender
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel;
|
|
|
|
NSArray * fileTypes;
|
|
|
|
|
|
|
|
panel = [NSOpenPanel openPanel];
|
|
|
|
fileTypes = [NSArray arrayWithObject: @"torrent"];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
[panel setAllowsMultipleSelection: YES];
|
|
|
|
[panel setCanChooseFiles: YES];
|
|
|
|
[panel setCanChooseDirectories: NO];
|
|
|
|
|
|
|
|
[panel beginSheetForDirectory: NULL file: NULL types: fileTypes
|
|
|
|
modalForWindow: fWindow modalDelegate: self didEndSelector:
|
|
|
|
@selector( openSheetClosed:returnCode:contextInfo: )
|
|
|
|
contextInfo: NULL];
|
|
|
|
}
|
|
|
|
|
2006-04-05 13:39:30 +00:00
|
|
|
- (void) cantFindAName: (NSArray *) filenames
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-04-05 13:39:30 +00:00
|
|
|
[self application: NSApp openFiles: filenames];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openSheetClosed: (NSOpenPanel *) s returnCode: (int) code
|
|
|
|
contextInfo: (void *) info
|
|
|
|
{
|
2006-04-05 13:39:30 +00:00
|
|
|
if( code == NSOKButton )
|
|
|
|
[self performSelectorOnMainThread: @selector(cantFindAName:)
|
|
|
|
withObject: [s filenames] waitUntilDone: NO];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resumeTorrent: (id) sender
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self resumeTorrentWithIndex: [fTableView selectedRowIndexes]];
|
2006-01-12 18:20:48 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:33:20 +00:00
|
|
|
- (void) resumeAllTorrents: (id) sender
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self resumeTorrentWithIndex: [NSIndexSet indexSetWithIndexesInRange:
|
|
|
|
NSMakeRange(0, [fTorrents count])]];
|
2006-01-12 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 13:09:19 +00:00
|
|
|
- (void) resumeTorrentWithIndex: (NSIndexSet *) indexSet
|
2006-01-12 18:20:48 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
|
|
|
{
|
|
|
|
torrent = [fTorrents objectAtIndex: i];
|
|
|
|
[torrent start];
|
|
|
|
}
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
[self updateUI: nil];
|
2006-02-08 19:05:42 +00:00
|
|
|
[self updateTorrentHistory];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) stopTorrent: (id) sender
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self stopTorrentWithIndex: [fTableView selectedRowIndexes]];
|
2006-01-12 18:20:48 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:33:20 +00:00
|
|
|
- (void) stopAllTorrents: (id) sender
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self stopTorrentWithIndex: [NSIndexSet indexSetWithIndexesInRange:
|
|
|
|
NSMakeRange(0, [fTorrents count])]];
|
2006-01-12 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 13:09:19 +00:00
|
|
|
- (void) stopTorrentWithIndex: (NSIndexSet *) indexSet
|
2006-01-12 18:20:48 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
|
|
|
{
|
|
|
|
torrent = [fTorrents objectAtIndex: i];
|
|
|
|
[torrent stop];
|
|
|
|
}
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
[self updateUI: nil];
|
2006-02-08 19:05:42 +00:00
|
|
|
[self updateTorrentHistory];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 13:09:19 +00:00
|
|
|
- (void) removeTorrentWithIndex: (NSIndexSet *) indexSet
|
2006-01-12 18:29:20 +00:00
|
|
|
deleteTorrent: (BOOL) deleteTorrent
|
|
|
|
deleteData: (BOOL) deleteData
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
int active = 0;
|
|
|
|
unsigned int i;
|
|
|
|
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
|
|
|
if ([[fTorrents objectAtIndex: i] isActive])
|
|
|
|
active++;
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-04-07 13:09:19 +00:00
|
|
|
if( active > 0 && [fDefaults boolForKey: @"CheckRemove"] )
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
2006-04-07 13:09:19 +00:00
|
|
|
[fTableView selectedRowIndexes], @"Index",
|
2006-04-05 13:52:00 +00:00
|
|
|
[NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent",
|
|
|
|
[NSNumber numberWithBool: deleteData], @"DeleteData",
|
2006-03-23 12:39:39 +00:00
|
|
|
nil];
|
|
|
|
[dict retain];
|
|
|
|
|
2006-04-07 13:09:19 +00:00
|
|
|
NSString * title, * message;
|
|
|
|
|
|
|
|
int selected = [fTableView numberOfSelectedRows];
|
|
|
|
if (selected == 1)
|
|
|
|
{
|
|
|
|
title = [NSString stringWithFormat: @"Comfirm Removal of %@",
|
|
|
|
[[fTorrents objectAtIndex: [fTableView selectedRow]] name]];
|
|
|
|
message = @"This torrent is active. Do you really want to remove it?";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
title = [NSString stringWithFormat: @"Comfirm Removal of %d Torrents", active];
|
|
|
|
if (selected == active)
|
|
|
|
message = [NSString stringWithFormat:
|
|
|
|
@"There are %d active torrents. Do you really want to remove them?", active];
|
|
|
|
else
|
|
|
|
message = [NSString stringWithFormat:
|
|
|
|
@"There are %d torrents (%d active). Do you really want to remove them?", selected, active];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSBeginAlertSheet(title,
|
2006-03-23 12:39:39 +00:00
|
|
|
@"Remove", @"Cancel", nil, fWindow, self,
|
2006-04-07 13:09:19 +00:00
|
|
|
@selector(removeSheetDidEnd:returnCode:contextInfo:),
|
|
|
|
nil, dict, message);
|
2006-03-23 12:39:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self confirmRemoveTorrentWithIndex: indexSet
|
2006-03-23 12:39:39 +00:00
|
|
|
deleteTorrent: deleteTorrent
|
|
|
|
deleteData: deleteData];
|
2006-01-12 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
|
2006-04-07 13:09:19 +00:00
|
|
|
contextInfo:(NSDictionary *)dict
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
|
|
|
[NSApp stopModal];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
|
|
|
if( returnCode == NSAlertDefaultReturn )
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self confirmRemoveTorrentWithIndex: [dict objectForKey:@"Index"]
|
2006-04-05 13:52:00 +00:00
|
|
|
deleteTorrent: [[dict objectForKey:@"DeleteTorrent"] boolValue]
|
|
|
|
deleteData: [[dict objectForKey:@"DeleteData"] boolValue]];
|
2006-01-12 18:57:23 +00:00
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
[dict release];
|
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-04-07 13:09:19 +00:00
|
|
|
- (void) confirmRemoveTorrentWithIndex: (NSIndexSet *) indexSet
|
2006-01-12 18:57:23 +00:00
|
|
|
deleteTorrent: (BOOL) deleteTorrent
|
|
|
|
deleteData: (BOOL) deleteData
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = [indexSet lastIndex]; i != NSNotFound; i = [indexSet indexLessThanIndex: i])
|
|
|
|
{
|
|
|
|
torrent = [fTorrents objectAtIndex: i];
|
|
|
|
|
|
|
|
[torrent stop];
|
|
|
|
|
|
|
|
if( deleteData )
|
|
|
|
[torrent trashData];
|
|
|
|
|
|
|
|
if( deleteTorrent )
|
|
|
|
[torrent trashTorrent];
|
|
|
|
|
|
|
|
[fTorrents removeObject: torrent];
|
|
|
|
[torrent release];
|
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
|
|
|
|
[self updateUI: nil];
|
2006-02-08 19:05:42 +00:00
|
|
|
[self updateTorrentHistory];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:29:20 +00:00
|
|
|
- (void) removeTorrent: (id) sender
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: NO deleteData: NO ];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeTorrentDeleteFile: (id) sender
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: YES deleteData: NO];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeTorrentDeleteData: (id) sender
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: NO deleteData: YES];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeTorrentDeleteBoth: (id) sender
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: YES deleteData: YES];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
- (void) showInfo: (id) sender
|
|
|
|
{
|
|
|
|
if( [fInfoPanel isVisible] )
|
|
|
|
{
|
|
|
|
[fInfoPanel close];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fInfoPanel orderFront: sender];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-27 15:09:29 +00:00
|
|
|
- (void) updateInfoPanel
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
int numberSelected = [fTableView numberOfSelectedRows];
|
|
|
|
if( numberSelected != 1 )
|
2006-03-27 15:09:29 +00:00
|
|
|
{
|
2006-03-28 11:17:42 +00:00
|
|
|
[fInfoImageView setImage: fAppIcon];
|
2006-04-07 13:09:19 +00:00
|
|
|
|
|
|
|
[fInfoName setStringValue: numberSelected == 0
|
|
|
|
? @"No Torrent Selected"
|
|
|
|
: [[NSString stringWithInt: numberSelected]
|
|
|
|
stringByAppendingString: @" Torrents Selected"]];
|
|
|
|
|
2006-03-27 15:09:29 +00:00
|
|
|
[fInfoSize setStringValue: @""];
|
|
|
|
[fInfoTracker setStringValue: @""];
|
|
|
|
[fInfoAnnounce setStringValue: @""];
|
|
|
|
[fInfoPieceSize setStringValue: @""];
|
|
|
|
[fInfoPieces setStringValue: @""];
|
|
|
|
[fInfoHash1 setStringValue: @""];
|
|
|
|
[fInfoHash2 setStringValue: @""];
|
|
|
|
[fInfoSeeders setStringValue: @""];
|
|
|
|
[fInfoLeechers setStringValue: @""];
|
|
|
|
[fInfoDownloaded setStringValue: @""];
|
|
|
|
[fInfoUploaded setStringValue: @""];
|
|
|
|
return;
|
|
|
|
}
|
2006-04-07 13:09:19 +00:00
|
|
|
|
|
|
|
int row = [fTableView selectedRow];
|
2006-03-27 15:09:29 +00:00
|
|
|
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: row];
|
|
|
|
[fInfoImageView setImage: [torrent iconNonFlipped]];
|
|
|
|
[fInfoName setStringValue: [torrent name]];
|
|
|
|
[fInfoSize setStringValue: [NSString
|
|
|
|
stringForFileSize: [torrent size]]];
|
|
|
|
[fInfoTracker setStringValue: [torrent tracker]];
|
|
|
|
[fInfoAnnounce setStringValue: [torrent announce]];
|
|
|
|
[fInfoPieceSize setStringValue: [NSString
|
|
|
|
stringForFileSize: [torrent pieceSize]]];
|
2006-03-28 11:17:42 +00:00
|
|
|
[fInfoPieces setIntValue: [torrent pieceCount]];
|
2006-03-27 15:09:29 +00:00
|
|
|
[fInfoHash1 setStringValue: [torrent hash1]];
|
|
|
|
[fInfoHash2 setStringValue: [torrent hash2]];
|
|
|
|
int seeders = [torrent seeders], leechers = [torrent leechers];
|
|
|
|
[fInfoSeeders setStringValue: seeders < 0 ?
|
|
|
|
@"?" : [NSString stringWithInt: seeders]];
|
|
|
|
[fInfoLeechers setStringValue: leechers < 0 ?
|
|
|
|
@"?" : [NSString stringWithInt: leechers]];
|
|
|
|
[fInfoDownloaded setStringValue: [NSString
|
|
|
|
stringForFileSize: [torrent downloaded]]];
|
|
|
|
[fInfoUploaded setStringValue: [NSString
|
|
|
|
stringForFileSize: [torrent uploaded]]];
|
|
|
|
}
|
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
- (void) updateUI: (NSTimer *) t
|
|
|
|
{
|
|
|
|
float dl, ul;
|
2006-03-23 12:39:39 +00:00
|
|
|
NSEnumerator * enumerator;
|
|
|
|
Torrent * torrent;
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
/* Update the TableView */
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
{
|
|
|
|
[torrent update];
|
|
|
|
|
|
|
|
if( [torrent justFinished] )
|
|
|
|
{
|
|
|
|
/* Notifications */
|
|
|
|
[self notifyGrowl: [torrent name]];
|
|
|
|
if( ![fWindow isKeyWindow] )
|
|
|
|
{
|
|
|
|
fCompleted++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[fTableView reloadData];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
//Update the global DL/UL rates
|
2006-03-23 12:39:39 +00:00
|
|
|
tr_torrentRates( fLib, &dl, &ul );
|
2006-01-20 01:51:07 +00:00
|
|
|
NSString * downloadRate = [NSString stringForSpeed: dl];
|
|
|
|
NSString * uploadRate = [NSString stringForSpeed: ul];
|
|
|
|
[fTotalDLField setStringValue: downloadRate];
|
|
|
|
[fTotalULField setStringValue: uploadRate];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-03-27 15:09:29 +00:00
|
|
|
[self updateInfoPanel];
|
2006-01-20 01:51:07 +00:00
|
|
|
|
|
|
|
//badge dock
|
2006-02-08 18:10:42 +00:00
|
|
|
[fBadger updateBadgeWithCompleted: fCompleted
|
2006-02-10 20:06:39 +00:00
|
|
|
uploadRate: ul >= 0.1 && [fDefaults boolForKey: @"BadgeUploadRate"]
|
2006-02-08 18:10:42 +00:00
|
|
|
? [NSString stringForSpeedAbbrev: ul] : nil
|
2006-02-10 20:06:39 +00:00
|
|
|
downloadRate: dl >= 0.1 && [fDefaults boolForKey: @"BadgeDownloadRate"]
|
2006-02-08 18:10:42 +00:00
|
|
|
? [NSString stringForSpeedAbbrev: dl] : nil];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-02-08 19:05:42 +00:00
|
|
|
- (void) updateTorrentHistory
|
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
NSMutableArray * history = [NSMutableArray
|
|
|
|
arrayWithCapacity: [fTorrents count]];
|
2006-02-08 19:05:42 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
{
|
2006-02-08 19:05:42 +00:00
|
|
|
[history addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent path], @"TorrentPath",
|
|
|
|
[torrent getFolder], @"DownloadFolder",
|
|
|
|
[torrent isActive] ? @"NO" : @"YES", @"Paused",
|
2006-02-08 19:05:42 +00:00
|
|
|
nil]];
|
2006-03-23 12:39:39 +00:00
|
|
|
}
|
2006-02-08 19:05:42 +00:00
|
|
|
|
|
|
|
[fDefaults setObject: history forKey: @"History"];
|
|
|
|
}
|
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
- (int) numberOfRowsInTableView: (NSTableView *) t
|
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
return [fTorrents count];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *) t objectValueForTableColumn:
|
|
|
|
(NSTableColumn *) tableColumn row: (int) rowIndex
|
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
return nil;
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView: (NSTableView *) t willDisplayCell: (id) cell
|
|
|
|
forTableColumn: (NSTableColumn *) tableColumn row: (int) rowIndex
|
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
[cell setTorrent: [fTorrents objectAtIndex: rowIndex]];
|
2006-04-03 19:29:09 +00:00
|
|
|
|
|
|
|
if( OSX_VERSION >= 10.3 && [fWindow isKeyWindow] &&
|
2006-04-07 13:09:19 +00:00
|
|
|
[fTableView isRowSelected: rowIndex] )
|
2006-04-03 19:29:09 +00:00
|
|
|
[cell setTextColor: [NSColor whiteColor]];
|
|
|
|
else
|
|
|
|
[cell setTextColor: [NSColor blackColor]];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) tableView: (NSTableView *) t acceptDrop:
|
|
|
|
(id <NSDraggingInfo>) info row: (int) row dropOperation:
|
|
|
|
(NSTableViewDropOperation) operation
|
|
|
|
{
|
2006-02-11 06:46:40 +00:00
|
|
|
[self application: NSApp openFiles: [[[info draggingPasteboard]
|
|
|
|
propertyListForType: NSFilenamesPboardType]
|
|
|
|
pathsMatchingExtensions: [NSArray arrayWithObject: @"torrent"]]];
|
2006-01-12 17:43:21 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation) tableView: (NSTableView *) t validateDrop:
|
|
|
|
(id <NSDraggingInfo>) info proposedRow: (int) row
|
|
|
|
proposedDropOperation: (NSTableViewDropOperation) operation
|
|
|
|
{
|
2006-02-10 20:46:44 +00:00
|
|
|
NSPasteboard * pasteboard = [info draggingPasteboard];
|
|
|
|
|
|
|
|
if (![[pasteboard types] containsObject: NSFilenamesPboardType]
|
|
|
|
|| [[[pasteboard propertyListForType: NSFilenamesPboardType]
|
|
|
|
pathsMatchingExtensions: [NSArray arrayWithObject: @"torrent"]]
|
|
|
|
count] == 0)
|
|
|
|
return NSDragOperationNone;
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
[fTableView setDropRow: [fTorrents count]
|
|
|
|
dropOperation: NSTableViewDropAbove];
|
2006-01-12 17:43:21 +00:00
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableViewSelectionDidChange: (NSNotification *) n
|
|
|
|
{
|
2006-03-27 15:09:29 +00:00
|
|
|
[self updateInfoPanel];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier:
|
|
|
|
(NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag
|
|
|
|
{
|
2006-01-12 18:57:23 +00:00
|
|
|
NSToolbarItem * item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
|
|
|
if( [ident isEqualToString: TOOLBAR_OPEN] )
|
|
|
|
{
|
|
|
|
[item setLabel: @"Open"];
|
2006-01-12 18:54:46 +00:00
|
|
|
[item setPaletteLabel: [item label]];
|
2006-01-12 17:43:21 +00:00
|
|
|
[item setToolTip: @"Open a torrent"];
|
2006-01-12 18:20:48 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Open.png"]];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector( openShowSheet: )];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
else if( [ident isEqualToString: TOOLBAR_REMOVE] )
|
|
|
|
{
|
|
|
|
[item setLabel: @"Remove"];
|
2006-01-12 18:54:46 +00:00
|
|
|
[item setPaletteLabel: [item label]];
|
2006-01-12 17:43:21 +00:00
|
|
|
[item setToolTip: @"Remove torrent from list"];
|
2006-01-12 18:20:48 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Remove.png"]];
|
|
|
|
[item setTarget: self];
|
2006-01-12 18:54:46 +00:00
|
|
|
[item setAction: @selector( removeTorrent: )];
|
2006-01-12 18:20:48 +00:00
|
|
|
}
|
2006-01-12 17:43:21 +00:00
|
|
|
else if( [ident isEqualToString: TOOLBAR_INFO] )
|
|
|
|
{
|
|
|
|
[item setLabel: @"Info"];
|
2006-01-12 18:54:46 +00:00
|
|
|
[item setPaletteLabel: [item label]];
|
2006-01-12 17:43:21 +00:00
|
|
|
[item setToolTip: @"Information"];
|
2006-01-12 18:20:48 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Info.png"]];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector( showInfo: )];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:54:46 +00:00
|
|
|
else if( [ident isEqualToString: TOOLBAR_RESUME_ALL] )
|
|
|
|
{
|
|
|
|
[item setLabel: @"Resume All"];
|
|
|
|
[item setPaletteLabel: [item label]];
|
|
|
|
[item setToolTip: @"Resume all torrents"];
|
2006-01-21 02:34:14 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"ResumeAll.png"]];
|
2006-01-12 18:54:46 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector( resumeAllTorrents: )];
|
|
|
|
}
|
|
|
|
else if( [ident isEqualToString: TOOLBAR_PAUSE_ALL] )
|
|
|
|
{
|
|
|
|
[item setLabel: @"Pause All"];
|
|
|
|
[item setPaletteLabel: [item label]];
|
|
|
|
[item setToolTip: @"Pause all torrents"];
|
2006-01-21 02:34:14 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"PauseAll.png"]];
|
2006-01-12 18:54:46 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setAction: @selector( stopAllTorrents: )];
|
|
|
|
}
|
2006-01-12 17:43:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[item release];
|
2006-04-07 13:09:19 +00:00
|
|
|
return nil;
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) t
|
|
|
|
{
|
2006-01-12 18:54:46 +00:00
|
|
|
return [NSArray arrayWithObjects:
|
|
|
|
TOOLBAR_OPEN, TOOLBAR_REMOVE,
|
2006-01-12 18:57:23 +00:00
|
|
|
TOOLBAR_RESUME_ALL, TOOLBAR_PAUSE_ALL,
|
|
|
|
TOOLBAR_INFO,
|
2006-01-12 18:54:46 +00:00
|
|
|
NSToolbarSeparatorItemIdentifier,
|
|
|
|
NSToolbarSpaceItemIdentifier,
|
|
|
|
NSToolbarFlexibleSpaceItemIdentifier,
|
|
|
|
NSToolbarCustomizeToolbarItemIdentifier,
|
|
|
|
NULL];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) t
|
|
|
|
{
|
2006-01-12 18:54:46 +00:00
|
|
|
return [NSArray arrayWithObjects:
|
|
|
|
TOOLBAR_OPEN, TOOLBAR_REMOVE,
|
2006-01-12 18:57:23 +00:00
|
|
|
NSToolbarSeparatorItemIdentifier,
|
|
|
|
TOOLBAR_RESUME_ALL, TOOLBAR_PAUSE_ALL,
|
2006-01-12 18:54:46 +00:00
|
|
|
NSToolbarFlexibleSpaceItemIdentifier,
|
2006-01-12 18:57:23 +00:00
|
|
|
TOOLBAR_INFO,
|
2006-01-12 18:54:46 +00:00
|
|
|
NULL];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) runCustomizationPalette: (id) sender
|
|
|
|
{
|
|
|
|
[fToolbar runCustomizationPalette:sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) showHideToolbar: (id) sender
|
|
|
|
{
|
|
|
|
[fWindow toggleToolbarShown:sender];
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem
|
|
|
|
{
|
2006-01-29 01:20:22 +00:00
|
|
|
SEL action = [toolbarItem action];
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
//enable remove item
|
2006-01-29 01:20:22 +00:00
|
|
|
if (action == @selector(removeTorrent:))
|
2006-04-07 13:09:19 +00:00
|
|
|
return [fTableView numberOfSelectedRows] > 0;
|
2006-03-23 12:39:39 +00:00
|
|
|
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator;
|
2006-01-29 01:20:22 +00:00
|
|
|
|
|
|
|
//enable resume all item
|
|
|
|
if (action == @selector(resumeAllTorrents:))
|
2006-03-23 12:39:39 +00:00
|
|
|
{
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
if( [torrent isPaused] )
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
2006-01-29 01:20:22 +00:00
|
|
|
|
|
|
|
//enable pause all item
|
|
|
|
if (action == @selector(stopAllTorrents:))
|
2006-03-23 12:39:39 +00:00
|
|
|
{
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
if( [torrent isActive] )
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:54:46 +00:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
|
|
|
|
{
|
2006-01-29 01:20:22 +00:00
|
|
|
SEL action = [menuItem action];
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
//disable menus if customize sheet is active
|
|
|
|
if ([fToolbar customizationPaletteIsRunning])
|
|
|
|
return NO;
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:54:46 +00:00
|
|
|
//enable customize toolbar item
|
2006-01-29 01:20:22 +00:00
|
|
|
if (action == @selector(showHideToolbar:))
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
2006-01-12 18:54:46 +00:00
|
|
|
[menuItem setTitle: [fToolbar isVisible] ? @"Hide Toolbar" : @"Show Toolbar"];
|
2006-01-12 18:57:23 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:54:46 +00:00
|
|
|
//enable show info
|
2006-01-29 01:20:22 +00:00
|
|
|
if (action == @selector(showInfo:))
|
2006-01-12 18:54:46 +00:00
|
|
|
{
|
|
|
|
[menuItem setTitle: [fInfoPanel isVisible] ? @"Hide Info" : @"Show Info"];
|
2006-01-12 18:57:23 +00:00
|
|
|
return YES;
|
2006-01-12 18:54:46 +00:00
|
|
|
}
|
2006-01-29 01:20:22 +00:00
|
|
|
|
|
|
|
//enable resume all item
|
|
|
|
if (action == @selector(resumeAllTorrents:))
|
2006-03-23 12:39:39 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
2006-03-23 12:39:39 +00:00
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
if( [torrent isPaused] )
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
2006-01-29 01:20:22 +00:00
|
|
|
|
|
|
|
//enable pause all item
|
|
|
|
if (action == @selector(stopAllTorrents:))
|
2006-03-23 12:39:39 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
2006-03-23 12:39:39 +00:00
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
if( [torrent isActive] )
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == @selector(revealFromMenu:))
|
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
return [fTableView numberOfSelectedRows] > 0;
|
2006-03-23 12:39:39 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:54:46 +00:00
|
|
|
//enable remove items
|
2006-01-29 01:20:22 +00:00
|
|
|
if (action == @selector(removeTorrent:)
|
|
|
|
|| action == @selector(removeTorrentDeleteFile:)
|
|
|
|
|| action == @selector(removeTorrentDeleteData:)
|
|
|
|
|| action == @selector(removeTorrentDeleteBoth:))
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
BOOL active = NO;
|
|
|
|
Torrent * torrent;
|
|
|
|
NSIndexSet * indexSet = [fTableView selectedRowIndexes];
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
|
|
|
{
|
|
|
|
torrent = [fTorrents objectAtIndex: i];
|
|
|
|
if ([torrent isActive])
|
|
|
|
{
|
|
|
|
active = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
//append or remove ellipsis when needed
|
2006-04-07 13:09:19 +00:00
|
|
|
if( active && [fDefaults boolForKey: @"CheckRemove"] )
|
2006-01-12 18:57:23 +00:00
|
|
|
{
|
|
|
|
if (![[menuItem title] hasSuffix:NS_ELLIPSIS])
|
|
|
|
[menuItem setTitle:[[menuItem title] stringByAppendingString:NS_ELLIPSIS]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([[menuItem title] hasSuffix:NS_ELLIPSIS])
|
|
|
|
[menuItem setTitle:[[menuItem title] substringToIndex:[[menuItem title] length]-[NS_ELLIPSIS length]]];
|
|
|
|
}
|
2006-04-07 13:09:19 +00:00
|
|
|
return [fTableView numberOfSelectedRows] > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable pause item
|
|
|
|
if( action == @selector(stopTorrent:) )
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSIndexSet * indexSet = [fTableView selectedRowIndexes];
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
|
|
|
{
|
|
|
|
torrent = [fTorrents objectAtIndex: i];
|
|
|
|
if ([torrent isActive])
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//enable resume item
|
|
|
|
if( action == @selector(resumeTorrent:) )
|
|
|
|
{
|
|
|
|
Torrent * torrent;
|
|
|
|
NSIndexSet * indexSet = [fTableView selectedRowIndexes];
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
|
|
|
{
|
|
|
|
torrent = [fTorrents objectAtIndex: i];
|
|
|
|
if ([torrent isPaused])
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
2006-01-12 18:54:46 +00:00
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
return YES;
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) sleepCallBack: (natural_t) messageType argument:
|
|
|
|
(void *) messageArgument
|
|
|
|
{
|
2006-04-05 12:21:16 +00:00
|
|
|
NSEnumerator * enumerator;
|
2006-03-23 12:39:39 +00:00
|
|
|
Torrent * torrent;
|
2006-04-05 12:21:16 +00:00
|
|
|
BOOL active;
|
2006-01-12 17:43:21 +00:00
|
|
|
|
|
|
|
switch( messageType )
|
|
|
|
{
|
|
|
|
case kIOMessageSystemWillSleep:
|
|
|
|
/* Close all connections before going to sleep and remember
|
|
|
|
we should resume when we wake up */
|
2006-03-23 12:39:39 +00:00
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent sleep];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for torrents to stop (5 seconds timeout) */
|
|
|
|
NSDate * start = [NSDate date];
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
|
|
|
{
|
|
|
|
while( [[NSDate date] timeIntervalSinceDate: start] < 5 &&
|
|
|
|
![torrent isPaused] )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
usleep( 100000 );
|
|
|
|
[torrent update];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IOAllowPowerChange( fRootPort, (long) messageArgument );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kIOMessageCanSystemSleep:
|
2006-01-29 01:20:22 +00:00
|
|
|
/* Prevent idle sleep unless all paused */
|
2006-04-05 12:21:16 +00:00
|
|
|
active = NO;
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( !active && ( torrent = [enumerator nextObject] ) )
|
|
|
|
if( [torrent isActive] )
|
|
|
|
active = YES;
|
|
|
|
|
|
|
|
if (active)
|
2006-01-29 01:20:22 +00:00
|
|
|
IOCancelPowerChange( fRootPort, (long) messageArgument );
|
|
|
|
else
|
|
|
|
IOAllowPowerChange( fRootPort, (long) messageArgument );
|
2006-01-12 17:43:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kIOMessageSystemHasPoweredOn:
|
|
|
|
/* Resume download after we wake up */
|
2006-03-23 12:39:39 +00:00
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
while( ( torrent = [enumerator nextObject] ) )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
[torrent wakeUp];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) windowWillUseStandardFrame: (NSWindow *) w
|
|
|
|
defaultFrame: (NSRect) defaultFrame
|
|
|
|
{
|
|
|
|
NSRect rectWin, rectView;
|
|
|
|
float foo;
|
|
|
|
|
|
|
|
rectWin = [fWindow frame];
|
2006-02-07 05:02:45 +00:00
|
|
|
rectView = [fScrollView frame];
|
2006-03-28 11:21:17 +00:00
|
|
|
foo = 10.0 - rectView.size.height + MAX( 1U, [fTorrents count] ) *
|
2006-03-23 12:39:39 +00:00
|
|
|
( [fTableView rowHeight] + [fTableView intercellSpacing].height );
|
2006-01-12 17:43:21 +00:00
|
|
|
|
|
|
|
rectWin.size.height += foo;
|
|
|
|
rectWin.origin.y -= foo;
|
|
|
|
|
|
|
|
return rectWin;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) showMainWindow: (id) sender
|
|
|
|
{
|
2006-01-12 18:57:23 +00:00
|
|
|
[fWindow makeKeyAndOrderFront: nil];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) linkHomepage: (id) sender
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL: [NSURL
|
2006-01-12 18:57:23 +00:00
|
|
|
URLWithString: WEBSITE_URL]];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) linkForums: (id) sender
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL: [NSURL
|
2006-01-12 18:57:23 +00:00
|
|
|
URLWithString: FORUM_URL]];
|
2006-01-12 18:47:30 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
- (void) notifyGrowl: (NSString * ) file
|
2006-01-12 18:33:20 +00:00
|
|
|
{
|
2006-01-12 18:40:47 +00:00
|
|
|
NSString * growlScript;
|
|
|
|
NSAppleScript * appleScript;
|
|
|
|
NSDictionary * error;
|
2006-01-12 18:47:30 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
if( !fHasGrowl )
|
2006-01-12 18:47:30 +00:00
|
|
|
return;
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
growlScript = [NSString stringWithFormat:
|
|
|
|
@"tell application \"System Events\"\n"
|
|
|
|
" if exists application process \"GrowlHelperApp\" then\n"
|
|
|
|
" tell application \"GrowlHelperApp\"\n "
|
|
|
|
" notify with name \"Download Complete\""
|
|
|
|
" title \"Download Complete\""
|
|
|
|
" description \"%@\""
|
|
|
|
" application name \"Transmission\"\n"
|
|
|
|
" end tell\n"
|
|
|
|
" end if\n"
|
|
|
|
"end tell", file];
|
|
|
|
appleScript = [[NSAppleScript alloc] initWithSource: growlScript];
|
|
|
|
if( ![appleScript executeAndReturnError: &error] )
|
|
|
|
{
|
|
|
|
printf( "Growl notify failed\n" );
|
|
|
|
}
|
|
|
|
[appleScript release];
|
2006-01-12 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
- (void) growlRegister: (id) sender
|
2006-03-23 12:39:39 +00:00
|
|
|
{
|
2006-01-12 18:40:47 +00:00
|
|
|
NSString * growlScript;
|
|
|
|
NSAppleScript * appleScript;
|
|
|
|
NSDictionary * error;
|
2006-01-12 18:47:30 +00:00
|
|
|
|
2006-01-12 18:57:23 +00:00
|
|
|
if( !fHasGrowl )
|
2006-01-12 18:47:30 +00:00
|
|
|
return;
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
growlScript = [NSString stringWithFormat:
|
|
|
|
@"tell application \"System Events\"\n"
|
|
|
|
" if exists application process \"GrowlHelperApp\" then\n"
|
|
|
|
" tell application \"GrowlHelperApp\"\n"
|
|
|
|
" register as application \"Transmission\" "
|
|
|
|
" all notifications {\"Download Complete\"}"
|
|
|
|
" default notifications {\"Download Complete\"}"
|
|
|
|
" icon of application \"Transmission\"\n"
|
|
|
|
" end tell\n"
|
|
|
|
" end if\n"
|
|
|
|
"end tell"];
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-12 18:40:47 +00:00
|
|
|
appleScript = [[NSAppleScript alloc] initWithSource: growlScript];
|
|
|
|
if( ![appleScript executeAndReturnError: &error] )
|
|
|
|
{
|
|
|
|
printf( "Growl registration failed\n" );
|
|
|
|
}
|
|
|
|
[appleScript release];
|
2006-01-12 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealFromMenu: (id) sender
|
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
torrent = [fTorrents objectAtIndex: [fTableView selectedRow]];
|
|
|
|
[torrent reveal];
|
2006-01-12 18:40:47 +00:00
|
|
|
}
|
2006-01-12 18:33:20 +00:00
|
|
|
|
2006-01-29 22:01:08 +00:00
|
|
|
- (void) checkForUpdate: (id) sender
|
|
|
|
{
|
|
|
|
[self checkForUpdateAuto: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) checkForUpdateTimer: (NSTimer *) timer
|
|
|
|
{
|
|
|
|
NSString * check = [fDefaults stringForKey: @"VersionCheck"];
|
|
|
|
if( [check isEqualToString: @"Never"] )
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSTimeInterval interval;
|
|
|
|
if( [check isEqualToString: @"Daily"] )
|
|
|
|
interval = 24 * 3600;
|
|
|
|
else if( [check isEqualToString: @"Weekly"] )
|
|
|
|
interval = 7 * 24 * 3600;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
id lastObject = [fDefaults objectForKey: @"VersionCheckLast"];
|
|
|
|
NSDate * lastDate = [lastObject isKindOfClass: [NSDate class]] ?
|
|
|
|
lastObject : nil;
|
|
|
|
if( lastDate )
|
|
|
|
{
|
|
|
|
NSTimeInterval actualInterval =
|
|
|
|
[[NSDate date] timeIntervalSinceDate: lastDate];
|
|
|
|
if( actualInterval > 0 && actualInterval < interval )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self checkForUpdateAuto: YES];
|
|
|
|
[fDefaults setObject: [NSDate date] forKey: @"VersionCheckLast"];
|
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
|
2006-01-29 22:01:08 +00:00
|
|
|
- (void) checkForUpdateAuto: (BOOL) automatic
|
|
|
|
{
|
|
|
|
fCheckIsAutomatic = automatic;
|
|
|
|
[[NSURL URLWithString: VERSION_PLIST_URL]
|
|
|
|
loadResourceDataNotifyingClient: self usingCache: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) URLResourceDidFinishLoading: (NSURL *) sender
|
2006-03-23 12:39:39 +00:00
|
|
|
{
|
2006-01-29 22:01:08 +00:00
|
|
|
NSDictionary * dict = [NSPropertyListSerialization
|
|
|
|
propertyListFromData: [sender resourceDataUsingCache: NO]
|
|
|
|
mutabilityOption: NSPropertyListImmutable
|
|
|
|
format: nil errorDescription: nil];
|
|
|
|
|
|
|
|
//check if plist was actually found and contains a version
|
|
|
|
NSString * webVersion = nil;
|
|
|
|
if (dict)
|
|
|
|
webVersion = [dict objectForKey: @"Version"];
|
|
|
|
if (!webVersion)
|
|
|
|
{
|
|
|
|
if (!fCheckIsAutomatic)
|
|
|
|
{
|
2006-04-03 19:29:09 +00:00
|
|
|
if( OSX_VERSION >= 10.3 )
|
|
|
|
{
|
|
|
|
NSAlert * dialog = [[NSAlert alloc] init];
|
|
|
|
[dialog addButtonWithTitle: @"OK"];
|
|
|
|
[dialog setMessageText: @"Error checking for updates."];
|
|
|
|
[dialog setInformativeText:
|
|
|
|
@"Transmission was not able to check the latest version available."];
|
|
|
|
[dialog setAlertStyle: NSInformationalAlertStyle];
|
|
|
|
|
|
|
|
[dialog runModal];
|
|
|
|
[dialog release];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* XXX */;
|
2006-01-29 22:01:08 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString * currentVersion = [[[NSBundle mainBundle] infoDictionary]
|
|
|
|
objectForKey: (NSString *)kCFBundleVersionKey];
|
|
|
|
|
|
|
|
NSEnumerator * webEnum = [[webVersion componentsSeparatedByString: @"."] objectEnumerator],
|
|
|
|
* currentEnum = [[currentVersion componentsSeparatedByString: @"."] objectEnumerator];
|
|
|
|
NSString * webSub, * currentSub;
|
|
|
|
|
|
|
|
BOOL webGreater = NO;
|
|
|
|
NSComparisonResult result;
|
|
|
|
while ((webSub = [webEnum nextObject]))
|
|
|
|
{
|
|
|
|
if (!(currentSub = [currentEnum nextObject]))
|
|
|
|
{
|
|
|
|
webGreater = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-04-03 19:29:09 +00:00
|
|
|
if( OSX_VERSION >= 10.3 )
|
2006-01-29 22:01:08 +00:00
|
|
|
{
|
2006-04-03 19:29:09 +00:00
|
|
|
result = [currentSub compare: webSub options: NSNumericSearch];
|
|
|
|
if (result != NSOrderedSame)
|
|
|
|
{
|
|
|
|
if (result == NSOrderedAscending)
|
|
|
|
webGreater = YES;
|
|
|
|
break;
|
|
|
|
}
|
2006-01-29 22:01:08 +00:00
|
|
|
}
|
2006-04-03 19:29:09 +00:00
|
|
|
else
|
|
|
|
/* XXX */;
|
2006-01-29 22:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (webGreater)
|
|
|
|
{
|
2006-04-03 19:29:09 +00:00
|
|
|
if( OSX_VERSION >= 10.3 )
|
|
|
|
{
|
|
|
|
NSAlert * dialog = [[NSAlert alloc] init];
|
|
|
|
[dialog addButtonWithTitle: @"Go to Website"];
|
|
|
|
[dialog addButtonWithTitle:@"Cancel"];
|
|
|
|
[dialog setMessageText: @"New version is available!"];
|
|
|
|
[dialog setInformativeText: [NSString stringWithFormat:
|
|
|
|
@"A newer version (%@) is available for download from the Transmission website.", webVersion]];
|
|
|
|
[dialog setAlertStyle: NSInformationalAlertStyle];
|
|
|
|
|
|
|
|
if ([dialog runModal] == NSAlertFirstButtonReturn)
|
|
|
|
[self linkHomepage: nil];
|
|
|
|
|
|
|
|
[dialog release];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* XXX */;
|
2006-01-29 22:01:08 +00:00
|
|
|
}
|
|
|
|
else if (!fCheckIsAutomatic)
|
|
|
|
{
|
2006-04-03 19:29:09 +00:00
|
|
|
if( OSX_VERSION >= 10.3 )
|
|
|
|
{
|
|
|
|
NSAlert * dialog = [[NSAlert alloc] init];
|
|
|
|
[dialog addButtonWithTitle: @"OK"];
|
|
|
|
[dialog setMessageText: @"No new versions are available."];
|
|
|
|
[dialog setInformativeText: [NSString stringWithFormat:
|
|
|
|
@"You are running the most current version of Transmission (%@).", currentVersion]];
|
|
|
|
[dialog setAlertStyle: NSInformationalAlertStyle];
|
|
|
|
|
|
|
|
[dialog runModal];
|
|
|
|
[dialog release];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* XXX */;
|
2006-01-29 22:01:08 +00:00
|
|
|
}
|
|
|
|
else;
|
|
|
|
}
|
|
|
|
|
2006-01-12 17:43:21 +00:00
|
|
|
@end
|