Ignore:
Timestamp:
Dec 11, 2011, 10:31:01 PM (10 years ago)
Author:
livings124
Message:

eliminate all warnings by switching NSOpenPanel/NSSavePanels to use completion handler blocks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/PrefsController.m

    r13103 r13108  
    6060- (void) setPrefView: (id) sender;
    6161
    62 - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    63 - (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    64 - (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    65 - (void) doneScriptSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    66 
    6762- (void) setKeychainPassword: (const char *) password forService: (const char *) service username: (const char *) username;
    6863
     
    816811    [panel setCanChooseDirectories: YES];
    817812    [panel setCanCreateDirectories: YES];
    818 
    819     [panel beginSheetForDirectory: nil file: nil types: nil
    820         modalForWindow: [self window] modalDelegate: self didEndSelector:
    821         @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
     813   
     814    [panel beginSheetModalForWindow: [self window] completionHandler: ^(NSInteger result) {
     815        if (result == NSFileHandlingPanelOKButton)
     816        {
     817            [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
     818           
     819            NSString * folder = [[[panel URLs] objectAtIndex: 0] path];
     820            [fDefaults setObject: folder forKey: @"DownloadFolder"];
     821            [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
     822           
     823            tr_sessionSetDownloadDir(fHandle, [folder UTF8String]);
     824        }
     825        else
     826        {
     827            //reset if cancelled
     828            [fFolderPopUp selectItemAtIndex: [fDefaults boolForKey: @"DownloadLocationConstant"] ? DOWNLOAD_FOLDER : DOWNLOAD_TORRENT];
     829        }
     830    }];
    822831}
    823832
     
    831840    [panel setCanChooseDirectories: YES];
    832841    [panel setCanCreateDirectories: YES];
    833 
    834     [panel beginSheetForDirectory: nil file: nil types: nil
    835         modalForWindow: [self window] modalDelegate: self didEndSelector:
    836         @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
     842   
     843    [panel beginSheetModalForWindow: [self window] completionHandler: ^(NSInteger result) {
     844        if (result == NSFileHandlingPanelOKButton)
     845        {
     846            NSString * folder = [[[panel URLs] objectAtIndex: 0] path];
     847            [fDefaults setObject: folder forKey: @"IncompleteDownloadFolder"];
     848           
     849            tr_sessionSetIncompleteDir(fHandle, [folder UTF8String]);
     850        }
     851        [fIncompleteFolderPopUp selectItemAtIndex: 0];
     852    }];
    837853}
    838854
     
    847863    [panel setCanCreateDirectories: NO];
    848864   
    849     [panel beginSheetForDirectory: nil file: nil types: nil
    850                    modalForWindow: [self window] modalDelegate: self didEndSelector:
    851      @selector(doneScriptSheetClosed:returnCode:contextInfo:) contextInfo: nil];
     865    [panel beginSheetModalForWindow: [self window] completionHandler: ^(NSInteger result) {
     866        if (result == NSFileHandlingPanelOKButton)
     867        {
     868            NSString * filePath = [[[panel URLs] objectAtIndex: 0] path];
     869           
     870            [fDefaults setObject: filePath forKey: @"DoneScriptPath"];
     871            tr_sessionSetTorrentDoneScript(fHandle, [filePath UTF8String]);
     872           
     873            [fDefaults setBool: YES forKey: @"DoneScriptEnabled"];
     874            tr_sessionSetTorrentDoneScriptEnabled(fHandle, YES);
     875        }
     876        [fDoneScriptPopUp selectItemAtIndex: 0];
     877    }];
    852878}
    853879
     
    900926    [panel setCanCreateDirectories: YES];
    901927
    902     [panel beginSheetForDirectory: nil file: nil types: nil
    903         modalForWindow: [self window] modalDelegate: self didEndSelector:
    904         @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
     928    [panel beginSheetModalForWindow: [self window] completionHandler: ^(NSInteger result) {
     929        NSString * path = [fDefaults stringForKey: @"AutoImportDirectory"];
     930        if (result == NSFileHandlingPanelOKButton)
     931        {
     932            UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
     933            if (path)
     934                [sharedQueue removePathFromQueue: [path stringByExpandingTildeInPath]];
     935           
     936            path = [[[panel URLs] objectAtIndex: 0] path];
     937            [fDefaults setObject: path forKey: @"AutoImportDirectory"];
     938            [sharedQueue addPath: [path stringByExpandingTildeInPath]];
     939           
     940            [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
     941        }
     942        else if (!path)
     943            [fDefaults setBool: NO forKey: @"AutoImport"];
     944       
     945        [fImportFolderPopUp selectItemAtIndex: 0];
     946    }];
    905947}
    906948
     
    13931435}
    13941436
    1395 - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
    1396 {
    1397     if (code == NSOKButton)
    1398     {
    1399         [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
    1400        
    1401         NSString * folder = [[[openPanel URLs] objectAtIndex: 0] path];
    1402         [fDefaults setObject: folder forKey: @"DownloadFolder"];
    1403         [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
    1404        
    1405         tr_sessionSetDownloadDir(fHandle, [folder UTF8String]);
    1406     }
    1407     else
    1408     {
    1409         //reset if cancelled
    1410         [fFolderPopUp selectItemAtIndex: [fDefaults boolForKey: @"DownloadLocationConstant"] ? DOWNLOAD_FOLDER : DOWNLOAD_TORRENT];
    1411     }
    1412 }
    1413 
    1414 - (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
    1415 {
    1416     if (code == NSOKButton)
    1417     {
    1418         NSString * folder = [[[openPanel URLs] objectAtIndex: 0] path];
    1419         [fDefaults setObject: folder forKey: @"IncompleteDownloadFolder"];
    1420        
    1421         tr_sessionSetIncompleteDir(fHandle, [folder UTF8String]);
    1422     }
    1423     [fIncompleteFolderPopUp selectItemAtIndex: 0];
    1424 }
    1425 
    1426 - (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
    1427 {
    1428     NSString * path = [fDefaults stringForKey: @"AutoImportDirectory"];
    1429     if (code == NSOKButton)
    1430     {
    1431         UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
    1432         if (path)
    1433             [sharedQueue removePathFromQueue: [path stringByExpandingTildeInPath]];
    1434        
    1435         path = [[[openPanel URLs] objectAtIndex: 0] path];
    1436         [fDefaults setObject: path forKey: @"AutoImportDirectory"];
    1437         [sharedQueue addPath: [path stringByExpandingTildeInPath]];
    1438        
    1439         [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
    1440     }
    1441     else if (!path)
    1442         [fDefaults setBool: NO forKey: @"AutoImport"];
    1443    
    1444     [fImportFolderPopUp selectItemAtIndex: 0];
    1445 }
    1446 
    1447 - (void) doneScriptSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
    1448 {
    1449     if (code == NSOKButton)
    1450     {
    1451         NSString * filePath = [[[openPanel URLs] objectAtIndex: 0] path];
    1452        
    1453         if ([[NSFileManager defaultManager] fileExistsAtPath: filePath])  // script file exists
    1454         {
    1455             [fDefaults setObject: filePath forKey: @"DoneScriptPath"];
    1456             [fDefaults setBool: YES forKey: @"DoneScriptEnabled"];
    1457         }
    1458         else // script file doesn't exist so don't enable
    1459         {
    1460             [fDefaults setObject: nil forKey:@"DoneScriptPath"];
    1461             [fDefaults setBool: NO forKey: @"DoneScriptEnabled"];
    1462         }
    1463         tr_sessionSetTorrentDoneScript(fHandle, [[fDefaults stringForKey:@"DoneScriptPath"] UTF8String]);
    1464         tr_sessionSetTorrentDoneScriptEnabled(fHandle, [fDefaults boolForKey:@"DoneScriptEnabled"]);
    1465     }
    1466     [fDoneScriptPopUp selectItemAtIndex: 0];
    1467 }
    1468 
    14691437- (void) setKeychainPassword: (const char *) password forService: (const char *) service username: (const char *) username
    14701438{
Note: See TracChangeset for help on using the changeset viewer.