Added ability to filter on error status. (#19)

This commit is contained in:
Markus Amalthea Magnuson 2022-03-07 07:01:01 +01:00 committed by GitHub
parent 0ac8c6079a
commit 143c5f5381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 10 deletions

View File

@ -2698,7 +2698,7 @@ static void removeKeRangerRansomware()
- (void)applyFilter
{
NSString* filterType = [self.fDefaults stringForKey:@"Filter"];
BOOL filterActive = NO, filterDownload = NO, filterSeed = NO, filterPause = NO, filterStatus = YES;
BOOL filterActive = NO, filterDownload = NO, filterSeed = NO, filterPause = NO, filterError = NO, filterStatus = YES;
if ([filterType isEqualToString:FILTER_ACTIVE])
{
filterActive = YES;
@ -2715,6 +2715,10 @@ static void removeKeRangerRansomware()
{
filterPause = YES;
}
else if ([filterType isEqualToString:FILTER_ERROR])
{
filterError = YES;
}
else
{
filterStatus = NO;
@ -2730,12 +2734,13 @@ static void removeKeRangerRansomware()
}
BOOL const filterTracker = searchStrings && [[self.fDefaults stringForKey:@"FilterSearchType"] isEqualToString:FILTER_TYPE_TRACKER];
std::atomic<int32_t> active{0}, downloading{0}, seeding{0}, paused{0};
std::atomic<int32_t> active{0}, downloading{0}, seeding{0}, paused{0}, error{0};
// Pointers to be captured by Obj-C Block as const*
auto* activeRef = &active;
auto* downloadingRef = &downloading;
auto* seedingRef = &seeding;
auto* pausedRef = &paused;
auto* errorRef = &error;
//filter & get counts of each type
NSIndexSet* indexesOfNonFilteredTorrents = [self.fTorrents
indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(Torrent* torrent, NSUInteger idx, BOOL* stop) {
@ -2765,6 +2770,13 @@ static void removeKeRangerRansomware()
}
}
}
else if (torrent.error) {
std::atomic_fetch_add_explicit(errorRef, 1, std::memory_order_relaxed);
if (filterStatus && !filterError)
{
return NO;
}
}
else
{
std::atomic_fetch_add_explicit(pausedRef, 1, std::memory_order_relaxed);
@ -2837,7 +2849,8 @@ static void removeKeRangerRansomware()
active:active.load()
downloading:downloading.load()
seeding:seeding.load()
paused:paused.load()];
paused:paused.load()
error:error.load()];
}
//if either the previous or current lists are blank, set its value to the other

View File

@ -10,6 +10,7 @@
<connections>
<outlet property="fActiveFilterButton" destination="3" id="30"/>
<outlet property="fDownloadFilterButton" destination="8" id="29"/>
<outlet property="fErrorFilterButton" destination="nvH-xy-86S" id="Rsj-yc-FIu"/>
<outlet property="fGroupsButton" destination="4" id="49"/>
<outlet property="fNoFilterButton" destination="9" id="27"/>
<outlet property="fPauseFilterButton" destination="6" id="28"/>
@ -21,7 +22,7 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="2" userLabel="FilterBar" customClass="FilterBarView">
<rect key="frame" x="0.0" y="0.0" width="457" height="23"/>
<rect key="frame" x="0.0" y="0.0" width="501" height="23"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3" customClass="FilterButton">
@ -108,7 +109,7 @@
</connections>
</button>
<searchField wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="10">
<rect key="frame" x="357" y="2" width="95" height="19"/>
<rect key="frame" x="401" y="2" width="95" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES"/>
<searchFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" bezelStyle="round" id="11">
<font key="font" metaFont="smallSystem"/>
@ -120,6 +121,17 @@
<outlet property="searchMenuTemplate" destination="22" id="48"/>
</connections>
</searchField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="nvH-xy-86S" customClass="FilterButton">
<rect key="frame" x="329" y="2" width="43" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="recessed" title="Error" bezelStyle="recessed" alignment="center" controlSize="mini" lineBreakMode="truncatingTail" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AtX-O4-Mqp">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="smallSystemBold"/>
</buttonCell>
<connections>
<action selector="setFilter:" target="-2" id="Rm7-FG-rfe"/>
</connections>
</button>
</subviews>
<point key="canvasLocation" x="139" y="150"/>
</customView>

View File

@ -9,6 +9,7 @@
#define FILTER_DOWNLOAD @"Download"
#define FILTER_SEED @"Seed"
#define FILTER_PAUSE @"Pause"
#define FILTER_ERROR @"Error"
#define FILTER_TYPE_NAME @"Name"
#define FILTER_TYPE_TRACKER @"Tracker"
@ -33,6 +34,7 @@
active:(NSUInteger)active
downloading:(NSUInteger)downloading
seeding:(NSUInteger)seeding
paused:(NSUInteger)paused;
paused:(NSUInteger)paused
error:(NSUInteger)error;
@end

View File

@ -20,6 +20,7 @@
@property(nonatomic) IBOutlet FilterButton* fDownloadFilterButton;
@property(nonatomic) IBOutlet FilterButton* fSeedFilterButton;
@property(nonatomic) IBOutlet FilterButton* fPauseFilterButton;
@property(nonatomic) IBOutlet FilterButton* fErrorFilterButton;
@property(nonatomic) IBOutlet NSSearchField* fSearchField;
@ -46,12 +47,14 @@
self.fDownloadFilterButton.title = NSLocalizedString(@"Downloading", "Filter Bar -> filter button");
self.fSeedFilterButton.title = NSLocalizedString(@"Seeding", "Filter Bar -> filter button");
self.fPauseFilterButton.title = NSLocalizedString(@"Paused", "Filter Bar -> filter button");
self.fErrorFilterButton.title = NSLocalizedString(@"Error", "Filter Bar -> filter button");
self.fNoFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
self.fActiveFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
self.fDownloadFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
self.fSeedFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
self.fPauseFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
self.fErrorFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
[self.fSearchField.searchMenuTemplate itemWithTag:FILTER_TYPE_TAG_NAME].title = NSLocalizedString(@"Name", "Filter Bar -> filter menu");
[self.fSearchField.searchMenuTemplate itemWithTag:FILTER_TYPE_TAG_TRACKER].title = NSLocalizedString(@"Tracker", "Filter Bar -> filter menu");
@ -80,6 +83,10 @@
{
currentFilterButton = self.fDownloadFilterButton;
}
else if ([filterType isEqualToString:FILTER_ERROR])
{
currentFilterButton = self.fErrorFilterButton;
}
else
{
//safety
@ -152,6 +159,10 @@
{
prevFilterButton = self.fDownloadFilterButton;
}
else if ([oldFilterType isEqualToString:FILTER_ERROR])
{
prevFilterButton = self.fErrorFilterButton;
}
else
{
prevFilterButton = self.fNoFilterButton;
@ -179,6 +190,10 @@
{
filterType = FILTER_SEED;
}
else if (sender == self.fErrorFilterButton)
{
filterType = FILTER_ERROR;
}
else
{
filterType = FILTER_NONE;
@ -201,7 +216,7 @@
NSButton* button;
if ([filterType isEqualToString:FILTER_NONE])
{
button = right ? self.fActiveFilterButton : self.fPauseFilterButton;
button = right ? self.fActiveFilterButton : self.fErrorFilterButton;
}
else if ([filterType isEqualToString:FILTER_ACTIVE])
{
@ -217,7 +232,11 @@
}
else if ([filterType isEqualToString:FILTER_PAUSE])
{
button = right ? self.fNoFilterButton : self.fSeedFilterButton;
button = right ? self.fErrorFilterButton : self.fSeedFilterButton;
}
else if ([filterType isEqualToString:FILTER_ERROR])
{
button = right ? self.fNoFilterButton : self.fPauseFilterButton;
}
else
{
@ -310,12 +329,14 @@
downloading:(NSUInteger)downloading
seeding:(NSUInteger)seeding
paused:(NSUInteger)paused
error:(NSUInteger)error
{
self.fNoFilterButton.count = all;
self.fActiveFilterButton.count = active;
self.fDownloadFilterButton.count = downloading;
self.fSeedFilterButton.count = seeding;
self.fPauseFilterButton.count = paused;
self.fErrorFilterButton.count = error;
}
- (void)menuNeedsUpdate:(NSMenu*)menu
@ -383,16 +404,18 @@
[self.fDownloadFilterButton sizeToFit];
[self.fSeedFilterButton sizeToFit];
[self.fPauseFilterButton sizeToFit];
[self.fErrorFilterButton sizeToFit];
NSRect allRect = self.fNoFilterButton.frame;
NSRect activeRect = self.fActiveFilterButton.frame;
NSRect downloadRect = self.fDownloadFilterButton.frame;
NSRect seedRect = self.fSeedFilterButton.frame;
NSRect pauseRect = self.fPauseFilterButton.frame;
NSRect errorRect = self.fErrorFilterButton.frame;
//size search filter to not overlap buttons
NSRect searchFrame = self.fSearchField.frame;
searchFrame.origin.x = NSMaxX(pauseRect) + 5.0;
searchFrame.origin.x = NSMaxX(errorRect) + 5.0;
searchFrame.size.width = NSWidth(self.view.frame) - searchFrame.origin.x - 5.0;
//make sure it is not too long
@ -409,7 +432,7 @@
//calculate width the buttons can take up
CGFloat const allowedWidth = (searchFrame.origin.x - 5.0) - allRect.origin.x;
CGFloat const currentWidth = NSWidth(allRect) + NSWidth(activeRect) + NSWidth(downloadRect) + NSWidth(seedRect) +
NSWidth(pauseRect) + 4.0; //add 4 for space between buttons
NSWidth(pauseRect) + NSWidth(errorRect) + 4.0; //add 4 for space between buttons
CGFloat const ratio = allowedWidth / currentWidth;
//decrease button widths proportionally
@ -418,18 +441,21 @@
downloadRect.size.width = NSWidth(downloadRect) * ratio;
seedRect.size.width = NSWidth(seedRect) * ratio;
pauseRect.size.width = NSWidth(pauseRect) * ratio;
errorRect.size.width = NSWidth(errorRect) * ratio;
}
activeRect.origin.x = NSMaxX(allRect) + 1.0;
downloadRect.origin.x = NSMaxX(activeRect) + 1.0;
seedRect.origin.x = NSMaxX(downloadRect) + 1.0;
pauseRect.origin.x = NSMaxX(seedRect) + 1.0;
errorRect.origin.x = NSMaxX(pauseRect) + 1.0;
self.fNoFilterButton.frame = allRect;
self.fActiveFilterButton.frame = activeRect;
self.fDownloadFilterButton.frame = downloadRect;
self.fSeedFilterButton.frame = seedRect;
self.fPauseFilterButton.frame = pauseRect;
self.fErrorFilterButton.frame = errorRect;
self.fSearchField.frame = searchFrame;
}