Changeset 847 for trunk/macosx


Ignore:
Timestamp:
Sep 5, 2006, 4:28:07 AM (16 years ago)
Author:
livings124
Message:

Use UKKQueue for auto import which gets rid of polling and makes the process instantaneous.

Location:
trunk/macosx
Files:
10 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r807 r847  
    8989    io_connect_t                    fRootPort;
    9090    NSTimer                         * fTimer;
    91    
    92     NSTimer                         * fAutoImportTimer;
    93     NSMutableArray                  * fAutoImportedNames;
    9491   
    9592    BOOL                            fUpdateInProgress;
     
    176173- (void) reloadInspectorSettings: (NSNotification *) notification;
    177174
    178 - (void) checkAutoImportDirectory: (NSTimer *) timer;
    179 - (void) autoImportChange: (NSNotification *) notification;
     175- (void) checkAutoImportDirectory;
    180176
    181177- (void) sleepCallBack: (natural_t) messageType argument: (void *) messageArgument;
  • trunk/macosx/Controller.m

    r831 r847  
    3030#import "TorrentTableView.h"
    3131#import "StringAdditions.h"
     32#import "UKKQueue.h"
    3233
    3334#import <Sparkle/Sparkle.h>
     
    9192        fBadger = [[Badger alloc] init];
    9293       
    93         fAutoImportedNames = [[NSMutableArray alloc] init];
    94        
    9594        [GrowlApplicationBridge setGrowlDelegate: self];
     95       
     96        [[UKKQueue sharedFileWatcher] setDelegate: self];
    9697    }
    9798    return self;
     
    112113    [fSortType release];
    113114    [fFilterType release];
    114     [fAutoImportedNames release];
    115115   
    116116    tr_close(fLib);
     
    318318                    name: @"AutoSpeedLimitChange" object: nil];
    319319   
    320     [nc addObserver: self selector: @selector(autoImportChange:)
     320    [nc addObserver: self selector: @selector(checkAutoImportDirectory)
    321321                    name: @"AutoImportSettingChange" object: nil];
    322322   
     
    367367    fSpeedLimitTimer = [NSTimer scheduledTimerWithTimeInterval: AUTO_SPEED_LIMIT_SECONDS target: self
    368368        selector: @selector(autoSpeedLimit:) userInfo: nil repeats: YES];
    369    
    370     //timer to check for auto import every 15 seconds, must do after everything else is set up
    371     fAutoImportTimer = [NSTimer scheduledTimerWithTimeInterval: AUTO_IMPORT_SECONDS target: self
    372         selector: @selector(checkAutoImportDirectory:) userInfo: nil repeats: YES];
    373     [[NSRunLoop currentRunLoop] addTimer: fAutoImportTimer forMode: NSDefaultRunLoopMode];
    374369}
    375370
     
    420415{
    421416    //stop timers
    422     [fAutoImportTimer invalidate];
    423417    [fSpeedLimitTimer invalidate];
    424418    [fTimer invalidate];
     
    15341528}
    15351529
    1536 - (void) checkAutoImportDirectory: (NSTimer *) timer
     1530-(void) watcher: (id<UKFileWatcher>) kq receivedNotification: (NSString*) nm forPath: (NSString*) fpath
     1531{
     1532    if ([nm isEqualToString: UKFileWatcherWriteNotification])
     1533        [self checkAutoImportDirectory];
     1534}
     1535
     1536- (void) checkAutoImportDirectory
    15371537{
    15381538    if (![fDefaults boolForKey: @"AutoImport"])
     
    15411541    NSString * path = [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath];
    15421542   
    1543     //if folder cannot be found or the contents hasn't changed simply give up
    1544     NSArray * allFileNames;
    1545     if (!(allFileNames = [[NSFileManager defaultManager] directoryContentsAtPath: path])
    1546             || [allFileNames isEqualToArray: fAutoImportedNames])
     1543    NSArray * importedNames;
     1544    if (!(importedNames = [[NSFileManager defaultManager] directoryContentsAtPath: path]))
    15471545        return;
    1548 
    1549     //try to add files that haven't already been added
    1550     NSMutableArray * newFileNames = [NSMutableArray arrayWithArray: allFileNames];
    1551     [newFileNames removeObjectsInArray: fAutoImportedNames];
    1552    
    1553     //save the current list of files
    1554     [fAutoImportedNames setArray: allFileNames];
    1555    
    1556     NSEnumerator * enumerator = [newFileNames objectEnumerator];
     1546   
     1547    NSEnumerator * enumerator = [importedNames objectEnumerator];
    15571548    NSString * file;
    15581549    unsigned oldCount;
     
    15681559                    notificationName: GROWL_AUTO_ADD iconData: nil priority: 0 isSticky: NO clickContext: nil];
    15691560        }
    1570 }
    1571 
    1572 - (void) autoImportChange: (NSNotification *) notification
    1573 {
    1574     [fAutoImportedNames removeAllObjects];
    1575     [self checkAutoImportDirectory: nil];
    15761561}
    15771562
  • trunk/macosx/PrefsController.m

    r807 r847  
    2525#import "PrefsController.h"
    2626#import "StringAdditions.h"
     27#import "UKKQueue.h"
    2728
    2829#define MIN_PORT    1
     
    113114    [fAutoImportCheck setState: autoImport];
    114115    [fImportFolderPopUp setEnabled: autoImport];
     116   
     117    if (autoImport)
     118        [[UKKQueue sharedFileWatcher] addPath: fImportFolder];
    115119   
    116120    //set auto size
     
    751755    [fImportFolderPopUp setEnabled: state];
    752756   
     757    if (state == NSOnState)
     758        [[UKKQueue sharedFileWatcher] addPath: fImportFolder];
     759    else
     760        [[UKKQueue sharedFileWatcher] removePathFromQueue: fImportFolder];
     761   
    753762    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
    754763}
     
    867876- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
    868877{
    869    if (code == NSOKButton)
    870    {
    871        [fImportFolder release];
    872        fImportFolder = [[[openPanel filenames] objectAtIndex: 0] retain];
    873 
    874        [fDefaults setObject: fImportFolder forKey: @"AutoImportDirectory"];
    875 
    876        [self updateImportPopUp];
    877        
    878        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
    879    }
    880    [fImportFolderPopUp selectItemAtIndex: 0];
     878    if (code == NSOKButton)
     879    {
     880        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
     881        [sharedQueue removePathFromQueue: fImportFolder];
     882       
     883        [fImportFolder release];
     884        fImportFolder = [[[openPanel filenames] objectAtIndex: 0] retain];
     885       
     886        [fDefaults setObject: fImportFolder forKey: @"AutoImportDirectory"];
     887       
     888        [self updateImportPopUp];
     889       
     890        [sharedQueue addPath: fImportFolder];
     891       
     892        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
     893    }
     894    [fImportFolderPopUp selectItemAtIndex: 0];
    881895}
    882896
Note: See TracChangeset for help on using the changeset viewer.