Ticket #167: DownloadFolderAlias.patch

File DownloadFolderAlias.patch, 11.6 KB (added by cluthi81, 15 years ago)

The patch itself (also adds the above files in the Xcode project)

  • Transmission.xcodeproj/project.pbxproj

     
    157157                A2F40AE40A361C00006B8288 /* Transmission.icns in Resources */ = {isa = PBXBuildFile; fileRef = 4D2784360905709500687951 /* Transmission.icns */; };
    158158                A2F6DB090A55F31C0058D1E5 /* SpeedLimitButton.png in Resources */ = {isa = PBXBuildFile; fileRef = A2F6DB070A55F31C0058D1E5 /* SpeedLimitButton.png */; };
    159159                A2F8951F0A2D4BA500ED2127 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = A2F8951E0A2D4BA500ED2127 /* Credits.rtf */; };
     160                DA3BA7F20AF5E7F6005FE32D /* AliasDataToIconTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = DA3BA7EE0AF5E7F6005FE32D /* AliasDataToIconTransformer.m */; };
     161                DA3BA7F40AF5E7F6005FE32D /* AliasDataToPathTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = DA3BA7F00AF5E7F6005FE32D /* AliasDataToPathTransformer.m */; };
     162                DA3BA8B30AF5E828005FE32D /* BDAlias.m in Sources */ = {isa = PBXBuildFile; fileRef = DA3BA8B10AF5E828005FE32D /* BDAlias.m */; };
    160163/* End PBXBuildFile section */
    161164
    162165/* Begin PBXContainerItemProxy section */
     
    398401                A2D4F0840A915F7200890C32 /* GreenDot.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = GreenDot.tiff; path = macosx/Images/GreenDot.tiff; sourceTree = "<group>"; };
    399402                A2F6DB070A55F31C0058D1E5 /* SpeedLimitButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = SpeedLimitButton.png; path = macosx/Images/SpeedLimitButton.png; sourceTree = "<group>"; };
    400403                A2F8951E0A2D4BA500ED2127 /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = Credits.rtf; path = macosx/Credits.rtf; sourceTree = "<group>"; };
     404                DA3BA7ED0AF5E7F6005FE32D /* AliasDataToIconTransformer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AliasDataToIconTransformer.h; path = macosx/AliasDataToIconTransformer.h; sourceTree = "<group>"; };
     405                DA3BA7EE0AF5E7F6005FE32D /* AliasDataToIconTransformer.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = AliasDataToIconTransformer.m; path = macosx/AliasDataToIconTransformer.m; sourceTree = "<group>"; };
     406                DA3BA7EF0AF5E7F6005FE32D /* AliasDataToPathTransformer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AliasDataToPathTransformer.h; path = macosx/AliasDataToPathTransformer.h; sourceTree = "<group>"; };
     407                DA3BA7F00AF5E7F6005FE32D /* AliasDataToPathTransformer.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = AliasDataToPathTransformer.m; path = macosx/AliasDataToPathTransformer.m; sourceTree = "<group>"; };
     408                DA3BA8B00AF5E828005FE32D /* BDAlias.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = BDAlias.h; path = macosx/BDAlias.h; sourceTree = "<group>"; };
     409                DA3BA8B10AF5E828005FE32D /* BDAlias.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = BDAlias.m; path = macosx/BDAlias.m; sourceTree = "<group>"; };
    401410/* End PBXFileReference section */
    402411
    403412/* Begin PBXFrameworksBuildPhase section */
     
    436445                080E96DDFE201D6D7F000001 /* Sources */ = {
    437446                        isa = PBXGroup;
    438447                        children = (
     448                                DA3BA7ED0AF5E7F6005FE32D /* AliasDataToIconTransformer.h */,
     449                                DA3BA7EE0AF5E7F6005FE32D /* AliasDataToIconTransformer.m */,
     450                                DA3BA7EF0AF5E7F6005FE32D /* AliasDataToPathTransformer.h */,
     451                                DA3BA7F00AF5E7F6005FE32D /* AliasDataToPathTransformer.m */,
    439452                                A25E74440AF5089E006F11AE /* ExpandedPathToPathTransformer.m */,
    440453                                A25E74450AF5089E006F11AE /* ExpandedPathToPathTransformer.h */,
    441454                                A25E74460AF5089E006F11AE /* ExpandedPathToIconTransformer.m */,
     
    466479                                4D118E1908CB46B20033958F /* PrefsController.m */,
    467480                                4D364D9E091FBB2C00377D12 /* TorrentTableView.h */,
    468481                                4D364D9F091FBB2C00377D12 /* TorrentTableView.m */,
     482                                DA3BA8B00AF5E828005FE32D /* BDAlias.h */,
     483                                DA3BA8B10AF5E828005FE32D /* BDAlias.m */,
    469484                                4DE5CC9B0980656F00BE280E /* StringAdditions.h */,
    470485                                4DE5CC9C0980656F00BE280E /* StringAdditions.m */,
    471486                                4DE5CCA50980735700BE280E /* Badger.h */,
     
    946961                                A21F5C040AF26DD5008CE5CE /* ActionMenuSpeedToDisplayLimitTransformer.m in Sources */,
    947962                                A25E74650AF5097C006F11AE /* ExpandedPathToPathTransformer.m in Sources */,
    948963                                A25E74660AF5097D006F11AE /* ExpandedPathToIconTransformer.m in Sources */,
     964                                DA3BA7F20AF5E7F6005FE32D /* AliasDataToIconTransformer.m in Sources */,
     965                                DA3BA7F40AF5E7F6005FE32D /* AliasDataToPathTransformer.m in Sources */,
     966                                DA3BA8B30AF5E828005FE32D /* BDAlias.m in Sources */,
    949967                        );
    950968                        runOnlyForDeploymentPostprocessing = 0;
    951969                };
  • macosx/Defaults.plist

     
    3232        <false/>
    3333        <key>DownloadChoice</key>
    3434        <string>Constant</string>
    35         <key>DownloadFolder</key>
    36         <string>~/Desktop</string>
    3735        <key>DownloadLimit</key>
    3836        <integer>100</integer>
    3937        <key>DownloadSound</key>
  • macosx/StringAdditions.h

     
    2929+ (NSString *) ellipsis;
    3030- (NSString *) stringByAppendingEllipsis;
    3131
     32+ (NSString *) desktopPath;
     33
    3234+ (NSString *) stringWithInt: (int) value;
    3335
    3436+ (NSString *) stringForFileSize: (uint64_t) size;
  • macosx/StringAdditions.m

     
    3636        return [self stringByAppendingString: [NSString ellipsis]];
    3737}
    3838
     39+ (NSString *) desktopPath
     40{
     41        return [@"~/Desktop" stringByExpandingTildeInPath];
     42}
     43
    3944+ (NSString *) stringWithInt: (int) value
    4045{
    4146    return [NSString stringWithFormat: @"%d", value];
  • macosx/PrefsController.h

     
    8888
    8989- (void) helpForNetwork: (id) sender;
    9090
     91- (void) refreshAliasPaths;
     92
    9193@end
  • macosx/Controller.m

     
    2424
    2525#import <IOKit/IOMessage.h>
    2626
     27#import "BDAlias.h"
    2728#import "Controller.h"
    2829#import "Torrent.h"
    2930#import "TorrentCell.h"
     
    3435#import "ActionMenuRatioToDisplayRatioTransformer.h"
    3536#import "ExpandedPathToPathTransformer.h"
    3637#import "ExpandedPathToIconTransformer.h"
     38#import "AliasDataToPathTransformer.h"
     39#import "AliasDataToIconTransformer.h"
    3740
    3841#import <Sparkle/Sparkle.h>
    3942
     
    9295    ExpandedPathToIconTransformer * iconTransformer =
    9396                        [[[ExpandedPathToIconTransformer alloc] init] autorelease];
    9497    [NSValueTransformer setValueTransformer: iconTransformer forName: @"ExpandedPathToIconTransformer"];
     98   
     99    AliasDataToPathTransformer * pathAliasTransformer =
     100                        [[[AliasDataToPathTransformer alloc] init] autorelease];
     101    [NSValueTransformer setValueTransformer: pathAliasTransformer forName: @"AliasDataToPathTransformer"];
     102   
     103    AliasDataToIconTransformer * iconAliasTransformer =
     104                        [[[AliasDataToIconTransformer alloc] init] autorelease];
     105    [NSValueTransformer setValueTransformer: iconAliasTransformer forName: @"AliasDataToIconTransformer"];
    95106}
    96107
    97108- (id) init
     
    104115        fDisplayedTorrents = [[NSMutableArray alloc] initWithCapacity: 10];
    105116       
    106117        fDefaults = [NSUserDefaults standardUserDefaults];
     118        // update prefs as paths to prefs as alias record
     119        NSString * downloadFolder = [fDefaults stringForKey: @"DownloadFolder"];
     120        if (downloadFolder)
     121        {
     122            BDAlias * downloadFolderAlias = [BDAlias aliasWithPath: [downloadFolder stringByExpandingTildeInPath]];
     123            if ([downloadFolderAlias isValidAlias])
     124                [fDefaults setObject: [downloadFolderAlias aliasData] forKey: @"DownloadFolderAlias"];
     125            else
     126                [fDefaults setObject: [[BDAlias aliasWithPath: [NSString desktopPath]] aliasData] forKey: @"DownloadFolderAlias"];
     127            [fDefaults setObject: nil forKey: @"DownloadFolder"];
     128        }
    107129       
    108130        fMessageController = [[MessageWindowController alloc] initWithWindowNibName: @"MessageWindow"];
    109131        fInfoController = [[InfoWindowController alloc] initWithWindowNibName: @"InfoWindow"];
     
    469491- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore
    470492{
    471493    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"], * torrentPath;
     494    BDAlias * downloadFolderAlias = [BDAlias aliasWithData: [fDefaults objectForKey: @"DownloadFolderAlias"]];
    472495   
    473     if (ignore || [downloadChoice isEqualToString: @"Ask"])
     496    if (ignore || [downloadChoice isEqualToString: @"Ask"] ||
     497            ([downloadChoice isEqualToString: @"Constant"] && ![downloadFolderAlias isValidAlias]))
    474498    {
    475499        [self openFilesAsk: [filenames mutableCopy]];
    476500        return;
     
    487511        [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
    488512
    489513        NSString * folder = [downloadChoice isEqualToString: @"Constant"]
    490             ? [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]
     514            ? [downloadFolderAlias fullPathWithDefault: [NSString desktopPath]]
    491515            : [torrentPath stringByDeletingLastPathComponent];
    492516       
    493517        [torrent setDownloadFolder: folder];
     
    911935
    912936- (void) showPreferenceWindow: (id) sender
    913937{
     938    [fPrefsController refreshAliasPaths];
    914939    NSWindow * window = [fPrefsController window];
    915940    if (![window isVisible])
    916941        [window center];
  • macosx/PrefsController.m

     
    2222 * DEALINGS IN THE SOFTWARE.
    2323 *****************************************************************************/
    2424
     25#import "BDAlias.h"
    2526#import "PrefsController.h"
    2627#import "StringAdditions.h"
    2728#import "UKKQueue.h"
     
    442443        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
    443444}
    444445
     446- (void) refreshAliasPaths
     447{
     448    [fDefaults setObject: [fDefaults objectForKey: @"DownloadFolderAlias"] forKey: @"DownloadFolderAlias"];
     449}
     450
    445451@end
    446452
    447453@implementation PrefsController (Private)
     
    453459    {
    454460        NSString * identifier = [sender itemIdentifier];
    455461        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
     462        {
     463            [self refreshAliasPaths];
    456464            view = fTransfersView;
     465        }
    457466        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
    458467            view = fBandwidthView;
    459468        else if ([identifier isEqualToString: TOOLBAR_NETWORK])
     
    500509    if (code == NSOKButton)
    501510    {
    502511        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
    503         [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
     512        [fDefaults setObject: [[BDAlias aliasWithPath:[[openPanel filenames] objectAtIndex: 0]] aliasData] forKey: @"DownloadFolderAlias"];
    504513        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
    505514    }
    506515    else