Changeset 1051 for trunk/macosx


Ignore:
Timestamp:
Nov 3, 2006, 4:01:45 PM (15 years ago)
Author:
livings124
Message:

incomplete folder for downloading torrents

Location:
trunk/macosx
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Defaults.plist

    r1049 r1051  
    4545        <key>History</key>
    4646        <array/>
     47        <key>IncompleteDownloadFolder</key>
     48        <string>~/Desktop</string>
    4749        <key>InfoTab</key>
    4850        <string>Info</string>
     
    105107        <key>UseAdvancedBar</key>
    106108        <false/>
     109        <key>UseIncompleteDownloadFolder</key>
     110        <false/>
    107111</dict>
    108112</plist>
  • trunk/macosx/English.lproj/PrefsWindow.nib/classes.nib

    r1049 r1051  
    1010                helpForNetwork = id;
    1111                importFolderSheetShow = id;
     12                incompleteFolderSheetShow = id;
    1213                setAutoImport = id;
    1314                setAutoSize = id;
     
    3233                fGeneralView = NSView;
    3334                fImportFolderPopUp = NSPopUpButton;
     35                fIncompleteFolderPopUp = NSPopUpButton;
    3436                fNatCheck = NSButton;
    3537                fNatStatusField = NSTextField;
  • trunk/macosx/English.lproj/PrefsWindow.nib/info.nib

    r1049 r1051  
    44<dict>
    55        <key>IBDocumentLocation</key>
    6         <string>18 87 356 240 0 0 1152 842 </string>
     6        <string>19 87 356 240 0 0 1152 842 </string>
    77        <key>IBEditorPositions</key>
    88        <dict>
    99                <key>153</key>
    10                 <string>123 483 563 267 0 0 1152 842 </string>
     10                <string>294 445 563 267 0 0 1152 842 </string>
    1111                <key>28</key>
    1212                <string>294 434 563 290 0 0 1152 842 </string>
    1313                <key>41</key>
    14                 <string>294 420 563 317 0 0 1152 842 </string>
     14                <string>108 420 563 342 0 0 1152 842 </string>
    1515                <key>66</key>
    1616                <string>294 507 563 144 0 0 1152 842 </string>
     
    2424        <key>IBOpenObjects</key>
    2525        <array>
    26                 <integer>153</integer>
     26                <integer>41</integer>
    2727        </array>
    2828        <key>IBSystem Version</key>
  • trunk/macosx/PrefsController.h

    r1049 r1051  
    3737    IBOutlet NSView         * fGeneralView, * fTransfersView, * fBandwidthView, * fNetworkView;
    3838   
    39     IBOutlet NSPopUpButton  * fFolderPopUp, * fImportFolderPopUp,
     39    IBOutlet NSPopUpButton  * fFolderPopUp, * fIncompleteFolderPopUp, * fImportFolderPopUp,
    4040                            * fDownloadSoundPopUp, * fSeedingSoundPopUp;
    4141   
     
    6969- (void) setCopyTorrents: (id) sender;
    7070
    71 - (void) setDownloadLocation:   (id) sender;
    72 - (void) folderSheetShow:       (id) sender;
     71- (void) setDownloadLocation:       (id) sender;
     72- (void) folderSheetShow:           (id) sender;
     73- (void) incompleteFolderSheetShow: (id) sender;
    7374
    7475- (void) setPort:   (id) sender;
  • trunk/macosx/PrefsController.m

    r1050 r1051  
    4545
    4646- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
     47- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    4748- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    4849
     
    397398}
    398399
     400- (void) incompleteFolderSheetShow: (id) sender
     401{
     402    NSOpenPanel * panel = [NSOpenPanel openPanel];
     403
     404    [panel setPrompt: @"Select"];
     405    [panel setAllowsMultipleSelection: NO];
     406    [panel setCanChooseFiles: NO];
     407    [panel setCanChooseDirectories: YES];
     408    [panel setCanCreateDirectories: YES];
     409
     410    [panel beginSheetForDirectory: nil file: nil types: nil
     411        modalForWindow: [self window] modalDelegate: self didEndSelector:
     412        @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
     413}
     414
    399415- (void) setAutoImport: (id) sender
    400416{
     
    509525}
    510526
     527- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
     528{
     529    if (code == NSOKButton)
     530        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
     531    [fIncompleteFolderPopUp selectItemAtIndex: 0];
     532}
     533
    511534- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
    512535{
  • trunk/macosx/Torrent.h

    r1010 r1051  
    3939    BOOL         fResumeOnWake;
    4040    NSDate       * fDate;
     41   
     42    BOOL        fUseIncompleteFolder;
     43    NSString    * fDownloadFolder, * fIncompleteFolder;
    4144   
    4245    BOOL        fPrivateTorrent, fPublicTorrent;
  • trunk/macosx/Torrent.m

    r1040 r1051  
    6666    if (self)
    6767    {
     68        fUseIncompleteFolder = [fDefaults boolForKey: @"UseIncompleteDownloadFolder"];
     69        fIncompleteFolder = [[fDefaults stringForKey: @"IncompleteDownloadFolder"] copy];
     70       
    6871        if (!fPublicTorrent)
    6972            [self trashFile: path];
     
    8689    if (self)
    8790    {
     91        //download folders
    8892        NSString * downloadFolder;
    8993        if (!(downloadFolder = [history objectForKey: @"DownloadFolder"]))
    9094            downloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
     95       
     96        NSNumber * useIncompleteFolder;
     97        if ((useIncompleteFolder = [history objectForKey: @"UseIncompleteFolder"]))
     98        {
     99            if ((fUseIncompleteFolder = [useIncompleteFolder boolValue]))
     100            {
     101                NSString * incompleteFolder;
     102                if (incompleteFolder = [history objectForKey: @"IncompleteFolder"])
     103                    fIncompleteFolder = [incompleteFolder copy];
     104                else
     105                    fIncompleteFolder = [[[fDefaults stringForKey: @"IncompleteDownloadFolder"]
     106                                            stringByExpandingTildeInPath] copy];
     107            }
     108        }
     109        else
     110            fUseIncompleteFolder = NO;
     111       
    91112        [self setDownloadFolder: downloadFolder];
    92113
     
    106127                    [NSNumber numberWithBool: fPrivateTorrent], @"PrivateCopy",
    107128                    [NSNumber numberWithBool: fPublicTorrent], @"PublicCopy",
    108                     [self downloadFolder], @"DownloadFolder",
     129                    fDownloadFolder, @"DownloadFolder",
     130                    [NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder",
    109131                    [self isActive] ? @"NO" : @"YES", @"Paused",
    110132                    [self date], @"Date",
     
    113135                    [NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
    114136                    [self orderValue], @"OrderValue", nil];
    115            
     137   
     138    if (fUseIncompleteFolder)
     139        [history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];
     140   
    116141    if (fPrivateTorrent)
    117142        [history setObject: [self hashString] forKey: @"TorrentHash"];
     
    128153    {
    129154        tr_torrentClose(fLib, fHandle);
     155       
     156        if (fDownloadFolder)
     157            [fDownloadFolder release];
     158        if (fIncompleteFolder)
     159            [fIncompleteFolder release];
    130160       
    131161        if (fPublicTorrentLocation)
     
    152182- (void) setDownloadFolder: (NSString *) path
    153183{
    154     tr_torrentSetFolder(fHandle, [path UTF8String]);
     184    fDownloadFolder = [path copy];
     185   
     186    if (!fUseIncompleteFolder || [[NSFileManager defaultManager] fileExistsAtPath:
     187                                    [path stringByAppendingPathComponent: [self name]]])
     188        tr_torrentSetFolder(fHandle, [path UTF8String]);
     189    else
     190        tr_torrentSetFolder(fHandle, [fIncompleteFolder UTF8String]);
    155191}
    156192
     
    176212    //notification when downloading finished
    177213    if ([self justFinished])
     214    {
     215        //move file from incomplete folder to download folder
     216        if (fUseIncompleteFolder && ![[self downloadFolder] isEqualToString: fDownloadFolder])
     217        {
     218            tr_torrentStop(fHandle);
     219            if ([[NSFileManager defaultManager] movePath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]
     220                                    toPath: [fDownloadFolder stringByAppendingPathComponent: [self name]] handler: nil])
     221                tr_torrentSetFolder(fHandle, [fDownloadFolder UTF8String]);
     222            tr_torrentStart(fHandle);
     223        }
     224       
    178225        [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
     226    }
    179227   
    180228    //check to stop for ratio
Note: See TracChangeset for help on using the changeset viewer.