From cdbc8574a7fbcec6bb45b926697cab9acebbaab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Mon, 1 Apr 2024 16:53:48 +0200 Subject: [PATCH] feat(macos): added last known location (#6610) * feat(macos): added last known location * fix data file label and reveal data button positions * code review: code style --------- Co-authored-by: BogdanArdelean --- macosx/Base.lproj/InfoGeneralView.xib | 88 +++++++++++++++++---------- macosx/InfoGeneralViewController.mm | 14 ++++- macosx/Torrent.h | 1 + macosx/Torrent.mm | 19 ++++++ 4 files changed, 89 insertions(+), 33 deletions(-) diff --git a/macosx/Base.lproj/InfoGeneralView.xib b/macosx/Base.lproj/InfoGeneralView.xib index 343f528fd..d2ac95f22 100644 --- a/macosx/Base.lproj/InfoGeneralView.xib +++ b/macosx/Base.lproj/InfoGeneralView.xib @@ -1,8 +1,8 @@ - + - + @@ -13,6 +13,8 @@ + + @@ -111,36 +113,6 @@ - - - - - - - - - - - - - - - - - @@ -189,6 +161,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -201,9 +219,12 @@ + + + @@ -226,9 +247,12 @@ + + + diff --git a/macosx/InfoGeneralViewController.mm b/macosx/InfoGeneralViewController.mm index 95985ae60..dec78f267 100644 --- a/macosx/InfoGeneralViewController.mm +++ b/macosx/InfoGeneralViewController.mm @@ -16,6 +16,8 @@ @property(nonatomic) IBOutlet NSTextField* fHashField; @property(nonatomic) IBOutlet NSTextField* fSecureField; @property(nonatomic) IBOutlet NSTextField* fDataLocationField; +@property(nonatomic) IBOutlet NSTextField* fLastDataLocationField; +@property(nonatomic) IBOutlet NSTextField* fLastDataLabel; @property(nonatomic) IBOutlet NSTextField* fCreatorField; @property(nonatomic) IBOutlet NSTextField* fDateCreatedField; @@ -60,10 +62,17 @@ Torrent* torrent = self.fTorrents[0]; NSString* location = torrent.dataLocation; + NSString* lastKnownDataLocation = torrent.lastKnownDataLocation; + self.fDataLocationField.stringValue = location ? location.stringByAbbreviatingWithTildeInPath : @""; self.fDataLocationField.toolTip = location ? location : @""; - self.fRevealDataButton.hidden = !location; + self.fLastDataLabel.hidden = location ? YES : NO; + self.fLastDataLocationField.hidden = location ? YES : NO; + self.fLastDataLocationField.stringValue = location ? @"" : lastKnownDataLocation.stringByAbbreviatingWithTildeInPath; + self.fLastDataLocationField.toolTip = location ? @"" : lastKnownDataLocation; + + self.fRevealDataButton.hidden = location ? NO : YES; } - (void)revealDataFile:(id)sender @@ -83,6 +92,9 @@ - (void)setupInfo { + self.fLastDataLabel.hidden = YES; + self.fLastDataLocationField.hidden = YES; + if (self.fTorrents.count == 1) { Torrent* torrent = self.fTorrents[0]; diff --git a/macosx/Torrent.h b/macosx/Torrent.h index ff3693881..777fbc183 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -111,6 +111,7 @@ extern NSString* const kTorrentDidChangeGroupNotification; @property(nonatomic, readonly) NSString* torrentLocation; @property(nonatomic, readonly) NSString* dataLocation; +@property(nonatomic, readonly) NSString* lastKnownDataLocation; - (NSString*)fileLocation:(FileListNode*)node; - (void)renameTorrent:(NSString*)newName completionHandler:(void (^)(BOOL didRename))completionHandler; diff --git a/macosx/Torrent.mm b/macosx/Torrent.mm index 6f5d83397..81a0ce0c5 100644 --- a/macosx/Torrent.mm +++ b/macosx/Torrent.mm @@ -773,6 +773,25 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error* error) } } +- (NSString*)lastKnownDataLocation +{ + if (self.magnet) + { + return nil; + } + + if (self.folder) + { + NSString* lastDataLocation = [self.currentDirectory stringByAppendingPathComponent:self.name]; + return lastDataLocation; + } + else + { + auto const lastFileName = @(tr_torrentFile(self.fHandle, 0).name); + return [self.currentDirectory stringByAppendingPathComponent:lastFileName]; + } +} + - (NSString*)fileLocation:(FileListNode*)node { if (node.isFolder)