Changeset 847


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

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

Location:
trunk
Files:
10 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Transmission.xcodeproj/project.pbxproj

    r835 r847  
    128128                A2912C540A2956E80097A0CA /* PrefsWindow.nib in Resources */ = {isa = PBXBuildFile; fileRef = A2912C520A2956E80097A0CA /* PrefsWindow.nib */; };
    129129                A29597350A72A9E10057248B /* StatusBarBackground.png in Resources */ = {isa = PBXBuildFile; fileRef = A29597340A72A9E10057248B /* StatusBarBackground.png */; };
     130                A2A3065B0AAD24A80049E2AC /* UKFileWatcher.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = A2A306530AAD24A80049E2AC /* UKFileWatcher.h */; };
     131                A2A3065C0AAD24A80049E2AC /* UKFileWatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A306540AAD24A80049E2AC /* UKFileWatcher.m */; };
     132                A2A3065D0AAD24A80049E2AC /* UKFNSubscribeFileWatcher.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = A2A306550AAD24A80049E2AC /* UKFNSubscribeFileWatcher.h */; };
     133                A2A3065E0AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A306560AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m */; };
     134                A2A3065F0AAD24A80049E2AC /* UKKQueue.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = A2A306570AAD24A80049E2AC /* UKKQueue.h */; };
     135                A2A306600AAD24A80049E2AC /* UKKQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A306580AAD24A80049E2AC /* UKKQueue.m */; };
     136                A2A306610AAD24A80049E2AC /* UKMainThreadProxy.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = A2A306590AAD24A80049E2AC /* UKMainThreadProxy.h */; };
     137                A2A306620AAD24A80049E2AC /* UKMainThreadProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A3065A0AAD24A80049E2AC /* UKMainThreadProxy.m */; };
    130138                A2AF1C390A3D0F6200F1575D /* FileTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = A2AF1C370A3D0F6200F1575D /* FileTableView.m */; };
    131139                A2BD40070A09BBEA008CCE96 /* bencode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D1838B709DEC0430047D688 /* bencode.h */; };
     
    166174                                A24F19210A3A796800C9C145 /* Sparkle.framework in CopyFiles */,
    167175                                A256588C0A9A695400E8A03B /* MessageWindowController.h in CopyFiles */,
     176                                A2A3065B0AAD24A80049E2AC /* UKFileWatcher.h in CopyFiles */,
     177                                A2A3065D0AAD24A80049E2AC /* UKFNSubscribeFileWatcher.h in CopyFiles */,
     178                                A2A3065F0AAD24A80049E2AC /* UKKQueue.h in CopyFiles */,
     179                                A2A306610AAD24A80049E2AC /* UKMainThreadProxy.h in CopyFiles */,
    168180                        );
    169181                        runOnlyForDeploymentPostprocessing = 0;
     
    337349                A2912C530A2956E80097A0CA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = macosx/English.lproj/PrefsWindow.nib; sourceTree = "<group>"; };
    338350                A29597340A72A9E10057248B /* StatusBarBackground.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = StatusBarBackground.png; path = macosx/Images/StatusBarBackground.png; sourceTree = "<group>"; };
     351                A2A306530AAD24A80049E2AC /* UKFileWatcher.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = UKFileWatcher.h; path = macosx/UKKQueue/UKFileWatcher.h; sourceTree = "<group>"; };
     352                A2A306540AAD24A80049E2AC /* UKFileWatcher.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = UKFileWatcher.m; path = macosx/UKKQueue/UKFileWatcher.m; sourceTree = "<group>"; };
     353                A2A306550AAD24A80049E2AC /* UKFNSubscribeFileWatcher.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = UKFNSubscribeFileWatcher.h; path = macosx/UKKQueue/UKFNSubscribeFileWatcher.h; sourceTree = "<group>"; };
     354                A2A306560AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = UKFNSubscribeFileWatcher.m; path = macosx/UKKQueue/UKFNSubscribeFileWatcher.m; sourceTree = "<group>"; };
     355                A2A306570AAD24A80049E2AC /* UKKQueue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = UKKQueue.h; path = macosx/UKKQueue/UKKQueue.h; sourceTree = "<group>"; };
     356                A2A306580AAD24A80049E2AC /* UKKQueue.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = UKKQueue.m; path = macosx/UKKQueue/UKKQueue.m; sourceTree = "<group>"; };
     357                A2A306590AAD24A80049E2AC /* UKMainThreadProxy.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = UKMainThreadProxy.h; path = macosx/UKKQueue/UKMainThreadProxy.h; sourceTree = "<group>"; };
     358                A2A3065A0AAD24A80049E2AC /* UKMainThreadProxy.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = UKMainThreadProxy.m; path = macosx/UKKQueue/UKMainThreadProxy.m; sourceTree = "<group>"; };
    339359                A2A84AD20A04FCDC00C898D4 /* BottomBorder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = BottomBorder.png; path = macosx/Images/BottomBorder.png; sourceTree = "<group>"; };
    340360                A2AF1C360A3D0F6200F1575D /* FileTableView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = FileTableView.h; path = macosx/FileTableView.h; sourceTree = "<group>"; };
     
    384404                        isa = PBXGroup;
    385405                        children = (
     406                                A2A306530AAD24A80049E2AC /* UKFileWatcher.h */,
     407                                A2A306540AAD24A80049E2AC /* UKFileWatcher.m */,
     408                                A2A306550AAD24A80049E2AC /* UKFNSubscribeFileWatcher.h */,
     409                                A2A306560AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m */,
     410                                A2A306570AAD24A80049E2AC /* UKKQueue.h */,
     411                                A2A306580AAD24A80049E2AC /* UKKQueue.m */,
     412                                A2A306590AAD24A80049E2AC /* UKMainThreadProxy.h */,
     413                                A2A3065A0AAD24A80049E2AC /* UKMainThreadProxy.m */,
    386414                                A256588A0A9A695400E8A03B /* MessageWindowController.h */,
    387415                                A256588B0A9A695400E8A03B /* MessageWindowController.m */,
     
    837865                                A256588D0A9A695400E8A03B /* MessageWindowController.m in Sources */,
    838866                                A23BBEB70A9BBE77003F7274 /* BarButton.m in Sources */,
     867                                A2A3065C0AAD24A80049E2AC /* UKFileWatcher.m in Sources */,
     868                                A2A3065E0AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m in Sources */,
     869                                A2A306600AAD24A80049E2AC /* UKKQueue.m in Sources */,
     870                                A2A306620AAD24A80049E2AC /* UKMainThreadProxy.m in Sources */,
    839871                        );
    840872                        runOnlyForDeploymentPostprocessing = 0;
  • 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.