Skip to content

Commit

Permalink
Merge pull request #229 from griff/url-session
Browse files Browse the repository at this point in the history
Rewritten versions of search plugins
  • Loading branch information
jmcintyre committed Mar 8, 2020
2 parents e4eb3cd + 8017400 commit b9ec864
Show file tree
Hide file tree
Showing 79 changed files with 2,889 additions and 613 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,5 +1,5 @@
os: osx
osx_image: xcode9.3
osx_image: xcode10.1
language: objective-c
before_install:
- bash Scripts/decrypt.bash
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions App/MetaZ_Prefix.pch
Expand Up @@ -5,4 +5,5 @@
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <MetaZKit/MetaZKit.h>
#import <MetaZKit/MetaZKit-Swift.h>
#endif
4 changes: 2 additions & 2 deletions App/resources/FactorySettings.plist
Expand Up @@ -33,8 +33,8 @@
<key>enabledActionPlugins</key>
<array>
<string>Update iTunes</string>
<string>org.maven-group.metaz.plugin.OSXNotificationPlugin</string>
<string>org.maven-group.metaz.plugin.AlertWindowPlugin</string>
<string>io.metaz.plugin.OSXNotification</string>
<string>io.metaz.plugin.AlertWindow</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion App/src/AppController.m
Expand Up @@ -462,7 +462,7 @@ - (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem
if(action == @selector(showImageEditor:))
{
id value = [filesController protectedValueForKeyPath:@"selection.picture"];
return [value isKindOfClass:[NSData class]] || [value isKindOfClass:[MZRemoteData class]];
return [value isKindOfClass:[NSData class]] || [value isKindOfClass:[RemoteData class]];
}
if(action == @selector(searchForImages:))
{
Expand Down
9 changes: 7 additions & 2 deletions App/src/FilesArrayController.m
Expand Up @@ -60,7 +60,7 @@ - (BOOL)canApply:(id)source;
for(NSString* key in [source allKeys])
{
id value = [source objectForKey:key];
if([value isKindOfClass:[MZRemoteData class]])
if([value isKindOfClass:[RemoteData class]])
{
if(![value isLoaded])
return NO;
Expand Down Expand Up @@ -100,8 +100,13 @@ - (void)apply:(id)source;
if(![edit getterChangedForKey:[tag identifier]])
{
id value = [source objectForKey:[tag identifier]];
if([value isKindOfClass:[MZRemoteData class]])
if([value isKindOfClass:[RemoteData class]])
value = [value data];
if([value isKindOfClass:[NSArray class]] &&
[value count] == 0)
{
continue;
}
if(value)
[edit setterValue:value forKey:[tag identifier]];
}
Expand Down
3 changes: 3 additions & 0 deletions App/src/FilesTableView.m
Expand Up @@ -558,6 +558,9 @@ - (void)awakeFromNib
[[status headerCell] setImage:image];

[self setDataSource:self];

NSSortDescriptor* sort = [NSSortDescriptor sortDescriptorWithKey:@"fileName" ascending:YES selector:@selector(numericCompare:)];
[self setSortDescriptors:[NSArray arrayWithObject:sort]];
}

- (void)keyDown:(NSEvent *)theEvent {
Expand Down
36 changes: 18 additions & 18 deletions App/src/PictureEditor.m
Expand Up @@ -32,9 +32,9 @@ + (NSSet *)keyPathsForValuesAffectingDataChangedEditable

- (void)dealloc
{
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
MZRemoteData* remote = picture;
RemoteData* remote = picture;
if(!remote.isLoaded)
[remote gtm_removeObserver:self forKeyPath:@"isLoaded" selector:@selector(pictureIsLoaded:)];
}
Expand Down Expand Up @@ -72,9 +72,9 @@ - (void)awakeFromNib

- (NSData *)data
{
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
MZRemoteData* remote = picture;
RemoteData* remote = picture;
if(!remote.isLoaded)
return nil;
return remote.data;
Expand All @@ -92,7 +92,7 @@ - (void)setData:(NSData *)newData

- (void)updateRemoteData
{
MZRemoteData* remote = self.picture;
RemoteData* remote = self.picture;
if(remote.isLoaded)
{
[indicator stopAnimation:self];
Expand All @@ -116,7 +116,7 @@ - (void)picturesUpdated:(GTMKeyValueChangeNotification *)notification
{
id status = [picturesController protectedValueForKeyPath:@"selection.self"];
self.picture = status;
if([status isKindOfClass:[MZRemoteData class]])
if([status isKindOfClass:[RemoteData class]])
return;
if(status == NSMultipleValuesMarker)
[posterView setStatus:MZMultiplePosterImage];
Expand Down Expand Up @@ -151,9 +151,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N

- (BOOL)dataChangedEditable
{
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
MZRemoteData* remote = picture;
RemoteData* remote = picture;
return remote.isLoaded && remote.error == nil;
}
id changed = [self.observerFix valueForKeyPath:@"selection.pictureChanged"];
Expand All @@ -164,9 +164,9 @@ - (BOOL)dataChangedEditable

- (void)setDataChanged:(NSNumber*)newValue
{
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
MZRemoteData* remote = picture;
RemoteData* remote = picture;
if(!remote.isLoaded)
return;
[filesController setValue:remote.data forKeyPath:@"selection.picture"];
Expand All @@ -177,9 +177,9 @@ - (void)setDataChanged:(NSNumber*)newValue

- (NSNumber*)dataChanged
{
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
MZRemoteData* remote = picture;
RemoteData* remote = picture;
if(!remote.isLoaded || remote.error != nil)
return NSNotApplicableMarker;
}
Expand All @@ -195,9 +195,9 @@ - (id)picture
- (void)setPicture:(id)newPicture
{
[self willChangeValueForKey:@"data"];
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
MZRemoteData* remote = picture;
RemoteData* remote = picture;
if(!remote.isLoaded)
{
[indicator stopAnimation:self];
Expand All @@ -209,9 +209,9 @@ - (void)setPicture:(id)newPicture
id oldPicture = picture;
picture = [newPicture retain];
[oldPicture release];
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
MZRemoteData* remote = picture;
RemoteData* remote = picture;
if(!remote.isLoaded)
{
[remote gtm_addObserver:self forKeyPath:@"isLoaded" selector:@selector(pictureIsLoaded:) userInfo:nil options:0];
Expand All @@ -236,9 +236,9 @@ - (void)setPicture:(id)newPicture

- (IBAction)retryLoad:(id)sender
{
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
MZRemoteData* remote = picture;
RemoteData* remote = picture;
if(remote.isLoaded && remote.error != nil)
{
[indicator setHidden:NO];
Expand Down
11 changes: 8 additions & 3 deletions App/src/PicturesArrayController.m
Expand Up @@ -8,15 +8,14 @@

#import "PicturesArrayController.h"


@implementation PicturesArrayController

- (BOOL)canApply:(id)data;
{
if([[data objectForKey:MZPictureTagIdent] isKindOfClass:[NSArray class]])
{
id picture = [self valueForKeyPath:@"selection.self"];
if([picture isKindOfClass:[MZRemoteData class]])
if([picture isKindOfClass:[RemoteData class]])
{
if(![picture isLoaded])
return NO;
Expand All @@ -30,7 +29,13 @@ - (void)applyData:(id)data toEdit:(MetaEdits *)edit;
if([[data objectForKey:MZPictureTagIdent] isKindOfClass:[NSArray class]])
{
id picture = [self valueForKeyPath:@"selection.self"];
if([picture isKindOfClass:[MZRemoteData class]])
if(picture == NSMultipleValuesMarker ||
picture == NSNotApplicableMarker ||
picture == NSNoSelectionMarker)
{
return;
}
if([picture isKindOfClass:[RemoteData class]])
picture = [picture data];
if(picture)
[edit setterValue:picture forKey:MZPictureTagIdent];
Expand Down
15 changes: 15 additions & 0 deletions App/src/PosterView.m
Expand Up @@ -178,6 +178,21 @@ - (void)keyDown:(NSEvent *)theEvent
[super keyDown:theEvent];
}

- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
SEL action = [menuItem action];
if(action == @selector(delete:)
|| action == @selector(cut:)
|| action == @selector(copy:))
{
if([self image] == [NSImage imageNamed:MZFadedIcon] ||
[self image] == [NSImage imageNamed:MZFadedIconError])
{
return NO;
}
}
return [super validateMenuItem:menuItem];
}

- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
{
if(![self isEnabled])
Expand Down
4 changes: 2 additions & 2 deletions App/src/SearchProfile.m
Expand Up @@ -29,7 +29,7 @@ + (SearchProfile*)unknownTypeProfile
{
return [self profileWithIdentifier:@"unknown" mainTag:MZTitleTagIdent
tag:[NSArray arrayWithObjects:
MZTitleTagIdent, MZChaptersTagIdent, nil]];
MZTitleTagIdent, MZDateTagIdent, MZChaptersTagIdent, nil]];
}

+ (SearchProfile*)tvShowProfile
Expand All @@ -44,7 +44,7 @@ + (SearchProfile*)movieProfile
{
return [self profileWithIdentifier:@"movie" mainTag:MZTitleTagIdent
tag:[NSArray arrayWithObjects:
MZTitleTagIdent, MZVideoTypeTagIdent, MZChaptersTagIdent, nil]];
MZTitleTagIdent, MZVideoTypeTagIdent, MZDateTagIdent, MZChaptersTagIdent, nil]];
}

+ (id)profileWithIdentifier:(NSString *)ident mainTag:(NSString *)main tag:(NSArray *)tags;
Expand Down
72 changes: 61 additions & 11 deletions App/src/main.m
Expand Up @@ -78,7 +78,7 @@ int main(int argc, const char *argv[])
if(whenDone == 4 || whenDone == 5)
[enabled addObject:@"Quit MetaZ"];
if(whenDone == 2 || whenDone == 3 || whenDone == 5)
[enabled addObject:@"org.maven-group.metaz.plugin.GrowlPlugin"];
[enabled addObject:@"org.maven-group.metaz.plugin.OSXNotificationPlugin"];
[[NSUserDefaults standardUserDefaults] setObject:enabled forKey:@"enabledActionPlugins"];
}
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"whenDoneAction"];
Expand All @@ -96,20 +96,70 @@ int main(int argc, const char *argv[])
[[NSUserDefaults standardUserDefaults] setInteger:version forKey:@"version"];
}

if(version == 2)
if(version == 2 || version == 3)
{
if([[MZVersion systemVersion] isGreaterThanOrEqualTo:[MZVersion versionWithString:@"10.8"]])
NSArray* actions = [[NSUserDefaults standardUserDefaults] arrayForKey:@"enabledActionPlugins"];
if([actions indexOfObject:@"org.maven-group.metaz.plugin.GrowlPlugin"] != NSNotFound)
{
NSArray* actions = [[NSUserDefaults standardUserDefaults] arrayForKey:@"enabledActionPlugins"];
if([actions indexOfObject:@"org.maven-group.metaz.plugin.GrowlPlugin"] != NSNotFound)
{
NSMutableArray* enabled = [NSMutableArray arrayWithArray:actions];
[enabled removeObject:@"org.maven-group.metaz.plugin.GrowlPlugin"];
[enabled addObject:@"org.maven-group.metaz.plugin.OSXNotificationPlugin"];
[[NSUserDefaults standardUserDefaults] setObject:enabled forKey:@"enabledActionPlugins"];
NSMutableArray* enabled = [NSMutableArray arrayWithArray:actions];
[enabled removeObject:@"org.maven-group.metaz.plugin.GrowlPlugin"];
[enabled addObject:@"org.maven-group.metaz.plugin.OSXNotificationPlugin"];
[[NSUserDefaults standardUserDefaults] setObject:enabled forKey:@"enabledActionPlugins"];
}
version = 4;
[[NSUserDefaults standardUserDefaults] setInteger:version forKey:@"version"];
}
if(version == 4)
{
NSArray* actions = [[NSUserDefaults standardUserDefaults] arrayForKey:@"enabledActionPlugins"];
NSMutableArray* enabled = [NSMutableArray array];
for (NSString* key in actions) {
if([key isEqualToString:@"org.maven-group.metaz.plugin.OSXNotificationPlugin"]) {
[enabled addObject:@"io.metaz.plugin.OSXNotification"];
} else if ([key isEqualToString:@"org.maven-group.metaz.plugin.AlertWindowPlugin"]) {
[enabled addObject:@"io.metaz.plugin.AlertWindow"];
} else if ([key isEqualToString:@"org.maven-group.metaz.plugin.GrowlPlugin"]) {
} else {
[enabled addObject:key];
}
}
[[NSUserDefaults standardUserDefaults] setObject:enabled forKey:@"enabledActionPlugins"];

NSArray* plugins = [[NSUserDefaults standardUserDefaults] arrayForKey:@"disabledPlugins"];
NSMutableArray* disabled = [NSMutableArray array];
for (NSString* key in plugins) {
if([key isEqualToString:@"org.maven-group.metaz.TheTVDBPlugin"]) {
[disabled addObject:@"io.metaz.plugin.TheTVDB"];
} else if ([key isEqualToString:@"org.maven-group.metaz.TheTVDB"]) {
[disabled addObject:@"io.metaz.plugin.TheTVDB"];
} else if ([key isEqualToString:@"org.maven-group.metaz.TheMovieDb"]) {
[disabled addObject:@"io.metaz.plugin.TheMovieDb"];
} else if ([key isEqualToString:@"org.maven-group.metaz.TheMovieDbNG"]) {
[disabled addObject:@"io.metaz.plugin.TheMovieDbNG"];
} else if ([key isEqualToString:@"org.maven-group.metaz.TheTVDB3"]) {
[disabled addObject:@"io.metaz.plugin.TheTVDB3"];
} else if ([key isEqualToString:@"org.maven-group.metaz.TagChimp"]) {
} else {
[disabled addObject:key];
}
}
version = 3;
version = 5;
[[NSUserDefaults standardUserDefaults] setInteger:version forKey:@"version"];
}
if(version == 5)
{
NSArray* plugins = [[NSUserDefaults standardUserDefaults] arrayForKey:@"disabledPlugins"];
NSMutableArray* disabled = [NSMutableArray array];
if([disabled indexOfObject:@"io.metaz.plugin.TheMovieDb"] == NSNotFound)
{
[disabled addObject:@"io.metaz.plugin.TheMovieDb"];
}
if([plugins indexOfObject:@"io.metaz.plugin.TheTVDB"] == NSNotFound)
{
[disabled addObject:@"io.metaz.plugin.TheTVDB"];
}
[[NSUserDefaults standardUserDefaults] setObject:disabled forKey:@"disabledPlugins"];
version = 6;
[[NSUserDefaults standardUserDefaults] setInteger:version forKey:@"version"];
}

Expand Down
2 changes: 1 addition & 1 deletion Framework/MetaZKit_Prefix.pch
Expand Up @@ -4,5 +4,5 @@

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import "MZConstants.h"
#import <MetaZKit/MZConstants.h>
#endif
26 changes: 26 additions & 0 deletions Framework/src/Array-safe-get.swift
@@ -0,0 +1,26 @@
//
// File.swift
// MetaZKit
//
// Created by Brian Olsen on 22/02/2020.
//

import Foundation

extension Array {
// Safely lookup an index that might be out of bounds,
// returning nil if it does not exist
public func safeGet(index: Int) -> Element? {
if 0 <= index && index < count {
return self[index]
} else {
return nil
}
}
}

extension Array where Element: CustomStringConvertible {
public func join(sep: String = ", ") -> String {
return self.reduce("", { $0 + ($0.isEmpty ? "" : sep) + String(describing:$1) })
}
}

0 comments on commit b9ec864

Please sign in to comment.