Commit 44e1e3c7 authored by David Fuhrmann's avatar David Fuhrmann

macosx: addons: add a new addon class for the model representation

Also loads the locally installed addons properly to mark these ones
as installed.

close #11476
parent 4330d456
/*****************************************************************************
* AddonListDataSource.h: Addons manager for the Mac
****************************************************************************
* Copyright (C) 2014 VideoLAN and authors
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
* David Fuhrmann <dfuhrmann # videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#import <vlc_common.h>
#import <vlc_addons.h>
@interface VLCAddon : NSObject
{
addon_entry_t *p_addon_entry;
}
- (id)initWithAddon:(addon_entry_t *)p_entry;
- (uint8_t *)uuid;
- (NSString *)name;
- (NSString *)author;
- (NSString *)version;
- (NSString *)description;
- (BOOL)isInstalled;
- (addon_type_t)type;
@end
/*****************************************************************************
* AddonListDataSource.m: Addons manager for the Mac
****************************************************************************
* Copyright (C) 2014 VideoLAN and authors
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
* David Fuhrmann <dfuhrmann # videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "AddonListDataSource.h"
#import "StringUtility.h"
@implementation VLCAddon
- (id)initWithAddon:(addon_entry_t *)p_entry
{
self = [super init];
if(self) {
p_addon_entry = addon_entry_Hold(p_entry);
}
return self;
}
-(void)dealloc
{
addon_entry_Release(p_addon_entry);
[super dealloc];
}
- (uint8_t *)uuid
{
return p_addon_entry->uuid;
}
- (NSString *)name
{
return toNSStr(p_addon_entry->psz_name);
}
- (NSString *)author
{
return toNSStr(p_addon_entry->psz_author);
}
- (NSString *)version
{
return toNSStr(p_addon_entry->psz_version);
}
- (NSString *)description
{
return toNSStr(p_addon_entry->psz_description);
}
- (BOOL)isInstalled
{
return p_addon_entry->e_state == ADDON_INSTALLED;
}
- (addon_type_t)type
{
return p_addon_entry->e_type;
}
@end
......@@ -19,12 +19,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "AddonManager.h"
#import <vlc_common.h>
#import <vlc_events.h>
#import <vlc_addons.h>
#import "AddonManager.h"
#import "intf.h"
#import "AddonListDataSource.h"
@interface VLCAddonManager ()
{
......@@ -38,8 +39,6 @@
- (void)addonChanged:(addon_entry_t *)data;
@end
static void addonsEventsCallback( const vlc_event_t *, void * );
static void addonsEventsCallback( const vlc_event_t *event, void *data )
{
if (event->type == vlc_AddonFound)
......@@ -126,6 +125,8 @@ static VLCAddonManager *_o_sharedInstance = nil;
- (void)showWindow
{
[self _findInstalled];
[self _findNewAddons];
[_window makeKeyAndOrderFront:nil];
}
......@@ -146,8 +147,8 @@ static VLCAddonManager *_o_sharedInstance = nil;
if (selectedRow > _displayedAddons.count - 1 || selectedRow < 0)
return;
NSDictionary *currentItem = [_displayedAddons objectAtIndex:selectedRow];
[self _installAddonWithID:[[currentItem objectForKey:@"uuid"] pointerValue]];
VLCAddon *currentAddon = [_displayedAddons objectAtIndex:selectedRow];
[self _installAddonWithID:[currentAddon uuid]];
}
- (IBAction)uninstallSelection:(id)sender
......@@ -156,8 +157,8 @@ static VLCAddonManager *_o_sharedInstance = nil;
if (selectedRow > _displayedAddons.count - 1 || selectedRow < 0)
return;
NSDictionary *currentItem = [_displayedAddons objectAtIndex:selectedRow];
[self _removeAddonWithID:[[currentItem objectForKey:@"uuid"] pointerValue]];
VLCAddon *currentAddon = [_displayedAddons objectAtIndex:selectedRow];
[self _removeAddonWithID:[currentAddon uuid]];
}
- (IBAction)refresh:(id)sender
......@@ -181,24 +182,22 @@ static VLCAddonManager *_o_sharedInstance = nil;
return;
}
NSDictionary *currentItem = [_displayedAddons objectAtIndex:selectedRow];
[_name setStringValue:[currentItem objectForKey:@"name"]];
[_author setStringValue:[currentItem objectForKey:@"author"]];
[_version setStringValue:[currentItem objectForKey:@"version"]];
[_description setString:[currentItem objectForKey:@"description"]];
VLCAddon *currentItem = [_displayedAddons objectAtIndex:selectedRow];
[_name setStringValue:[currentItem name]];
[_author setStringValue:[currentItem author]];
[_version setStringValue:[currentItem version]];
[_description setString:[currentItem description]];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
NSString *identifier = [aTableColumn identifier];
if ([identifier isEqualToString:@"installed"]) {
if ([[[_displayedAddons objectAtIndex:rowIndex] objectForKey:@"state"] intValue] == ADDON_INSTALLED)
return @"✔";
return @"✘";
} else if([identifier isEqualToString:@"type"])
return [self _getAddonType:[[[_displayedAddons objectAtIndex:rowIndex] objectForKey:@"type"] intValue]];
return [[_displayedAddons objectAtIndex:rowIndex] isInstalled] ? @"✔" : @"✘";
} else if([identifier isEqualToString:@"name"])
return [[_displayedAddons objectAtIndex:rowIndex] name];
return [[_displayedAddons objectAtIndex:rowIndex] objectForKey:identifier];
return @"";
}
#pragma mark - data handling
......@@ -206,25 +205,10 @@ static VLCAddonManager *_o_sharedInstance = nil;
- (void)addAddon:(addon_entry_t *)p_entry
{
@autoreleasepool {
NSString *name = [NSString stringWithUTF8String:p_entry->psz_name ? p_entry->psz_name : ""];
if (p_entry->e_state == ADDON_INSTALLED)
name = [name stringByAppendingFormat: @" (%@)", _NS("Installed")];
NSDictionary *addonProperties = [NSDictionary dictionaryWithObjectsAndKeys:
name, @"name",
toNSStr(p_entry->psz_description), @"description",
toNSStr(p_entry->psz_author), @"author",
toNSStr(p_entry->psz_source_uri), @"uri",
toNSStr(p_entry->psz_version), @"version",
toNSStr(p_entry->psz_image_uri), @"imageuri",
[NSNumber numberWithInt:p_entry->e_state], @"state",
[NSNumber numberWithInt:p_entry->e_type], @"type",
[NSValue valueWithPointer:&p_entry->uuid], @"uuid",
nil];
/* no skin support on OS X so far */
if ([[addonProperties objectForKey:@"type"] intValue] != ADDON_SKIN2)
[_addons addObject:addonProperties];
if (p_entry->e_type != ADDON_SKIN2)
[_addons addObject:[[[VLCAddon alloc] initWithAddon:p_entry] autorelease]];
}
}
......@@ -248,20 +232,19 @@ static VLCAddonManager *_o_sharedInstance = nil;
NSUInteger count = _addons.count;
NSMutableArray *filteredItems = [[NSMutableArray alloc] initWithCapacity:count];
NSDictionary *currentItem;
for (NSUInteger x = 0; x < count; x++) {
currentItem = [_addons objectAtIndex:x];
VLCAddon *currentItem = [_addons objectAtIndex:x];
if (type != -1) {
if ([[currentItem objectForKey:@"type"] intValue] == type) {
if ([currentItem type] == type) {
if (installedOnly) {
if ([[currentItem objectForKey:@"state"] intValue] == ADDON_INSTALLED)
if ([currentItem isInstalled])
[filteredItems addObject:currentItem];
} else
[filteredItems addObject:currentItem];
}
} else {
if (installedOnly) {
if ([[currentItem objectForKey:@"state"] intValue] == ADDON_INSTALLED)
if ([currentItem isInstalled])
[filteredItems addObject:currentItem];
} else
[filteredItems addObject:currentItem];
......@@ -288,7 +271,6 @@ static VLCAddonManager *_o_sharedInstance = nil;
addons_manager_Gather(_manager, [uri UTF8String]);
}
/* FIXME: un-used */
- (void)_findInstalled
{
addons_manager_LoadCatalog(_manager);
......
......@@ -22,6 +22,8 @@ SOURCES_macosx = \
ExtensionsDialogProvider.m \
AddonManager.h \
AddonManager.m \
AddonListDataSource.h \
AddonListDataSource.m \
VLCUIWidgets.h \
VLCUIWidgets.m \
about.h \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment