ample/Ample/MediaViewController.m
Kelvin Sherlock 3d5a2951bb Squashed commit of the following:
commit 78c81626670fdf41fa6bdd71a4243a89a0746615
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Mon Jun 7 00:33:48 2021 -0400

    check if software set has a particular entry.

commit ef5ab6b6948dc3bbbe2947ea099fcacd08435e86
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun Jun 6 22:20:34 2021 -0400

    fix scroller background on recent disk images window.

commit dee56fa50e87299b396b48361bd0a780aaaaa768
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun Jun 6 21:26:23 2021 -0400

    update cheat sheet javascript to work with 10.11
    * => functions not supported
    * NodeList.prototype.forEach not supported.

commit b00cc05413f4ebd6d6d58f96e24303008608f3a6
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun Jun 6 17:10:41 2021 -0400

    default full machine name for bookmark entry.

commit a671cafdc98051b56b12cdd3ccd13c22f54f605a
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun Jun 6 15:39:32 2021 -0400

    loading a bookmark wasn't updating the media.

commit 3000e0eb1b10bede3345aaab8478e9ec209f328c
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun Jun 6 15:38:53 2021 -0400

    bump copyright year.

commit 45222dacd4aa0047fae63a9112509de57139df63
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun Jun 6 13:38:23 2021 -0400

    add reset w/ value for setting the item explicitely.

commit cc7fde1253b71c4d8655eb4c010bbf4e61333a15
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun Jun 6 13:37:48 2021 -0400

    add checkboxes for bitbanger/share directory.

    The general idea is it's easier to toggle a checkbox than to type/retype a path.

commit 5674b2d7f6b0e2f0b973197bf3493ad61bf46428
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sat Jun 5 19:11:43 2021 -0400

    commentary on searches with diacritics.

commit ec60634dcd9c573130dc34673b4d3fe597ea2b42
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sat Jun 5 19:11:22 2021 -0400

    clean up auto-complete a little bit when setting a value directly.

commit 1a182bbdab237c89d355d8294b5a4a64b785783a
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sat Jun 5 13:08:29 2021 -0400

    fix text color when value is set.

    There are still some bugs relating to multiple copies of the value being stored.

commit 49c0bc15c73446259d8cc151cf52d6058644db76
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sat Jun 5 12:09:44 2021 -0400

    reset all controls first.

commit 059797ad85b057e296cc707b4645f839bfccac13
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sat Jun 5 10:52:06 2021 -0400

    more bookmark loading.

commit e5a612d9f8e7414dd15c66dbaa540b637765eeec
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Jun 4 23:52:38 2021 -0400

    bookmark - restore the software

commit f9411a1e84df7bd46e352cc5ca995b585c2a0523
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Jun 4 23:52:25 2021 -0400

    clean up software / name logic.

commit f628d99e4a
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Jun 4 00:21:08 2021 -0400

    load bookmark...

commit 0b248e6aad
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Jun 4 00:20:42 2021 -0400

    stringValue can't be nil.

commit 94aac38af4
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Thu Jun 3 23:04:37 2021 -0400

    add bookmark menu

commit 6215a0df12
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Thu Jun 3 23:03:29 2021 -0400

    slot view needs to know the machine.

commit d348c15dc5
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Thu Jun 3 23:02:58 2021 -0400

    transformer to enable/disable control based on string length.

commit e14336a009
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Thu Jun 3 23:02:14 2021 -0400

    shut up compiler warning.

commit 4baf545245
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Thu Jun 3 23:01:15 2021 -0400

    bookmark manager

commit 0f3e6c8307
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Mon May 31 23:54:29 2021 -0400

    more (untested) bookmark code

commit 8fdb149eb3
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Mon May 31 16:13:43 2021 -0400

    start of bookmarking support. Untested.

commit 787eac87f6
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Mon May 31 16:12:45 2021 -0400

    shut up warnings about content clipping.
    maybe it's a 10.11 thing.  The size was chosen by interface builder.
2021-06-07 00:34:26 -04:00

754 lines
19 KiB
Objective-C

//
// MediaViewController.m
// Ample
//
// Created by Kelvin Sherlock on 8/20/2020.
// Copyright © 2020 Kelvin Sherlock. All rights reserved.
//
#import "MediaViewController.h"
#import "TableCellView.h"
@protocol MediaNode
-(BOOL)isGroupItem;
-(BOOL)isExpandable;
-(NSInteger) count;
-(NSString *)viewIdentifier;
-(void)prepareView: (NSTableCellView *)view;
-(CGFloat)height;
-(NSInteger)index;
@end
@interface MediaCategory : NSObject <MediaNode> {
}
@property NSInteger validCount;
@property NSMutableArray *children; // URLs?
@property NSString *title;
@property NSInteger index;
-(NSInteger)count;
-(id)objectAtIndex:(NSInteger)index;
-(BOOL)isGroupItem;
@end
@interface MediaItem : NSObject <MediaNode>
@property NSURL *url;
@property BOOL valid;
@property NSInteger index;
-(NSInteger)count;
-(id)objectAtIndex:(NSInteger)index;
-(BOOL)isGroupItem;
-(void)invalidate;
@end
@implementation MediaCategory
+(instancetype)categoryWithTitle: (NSString *)title {
return [[self alloc] initWithTitle: title];
}
-(instancetype)initWithTitle: (NSString *)title {
[self setTitle: title];
return self;
}
-(NSInteger) count {
return [_children count];
}
-(id)objectAtIndex:(NSInteger)index {
return [_children objectAtIndex: index];
}
-(BOOL)isGroupItem {
return YES;
}
-(BOOL)isExpandable {
return YES;
}
-(NSString *)viewIdentifier {
return @"CategoryView";
}
-(void)prepareView: (NSTableCellView *)view {
[view setObjectValue: self];
[[view textField] setStringValue: _title];
}
-(CGFloat)height {
return 17;
}
-(BOOL)setItemCount: (unsigned)newCount {
if (newCount == _validCount) {
return NO;
}
unsigned count = (unsigned)[_children count];
_validCount = newCount;
if (!_children) _children = [NSMutableArray new];
for (unsigned i = count; i < newCount; ++i) {
MediaItem *item = [MediaItem new];
[item setIndex: i];
[_children addObject: item];
}
// delete excess items, if blank. otherwise, mark invalid.
unsigned ix = 0;
for(MediaItem *item in _children) {
[item setValid: ix++ < newCount];
}
for (unsigned i = newCount; i < count; ++i) {
MediaItem *item = [_children lastObject];
if ([item url]) break;
[_children removeLastObject];
}
return YES;
}
-(BOOL)pruneChildrenWithOutlineView: (NSOutlineView *)view {
NSUInteger count = [_children count];
BOOL delta = NO;
if (_validCount == count) return NO;
NSMutableIndexSet *set = [NSMutableIndexSet new];
for (NSInteger i = _validCount; i < count; ++i) {
MediaItem *item = [_children lastObject];
if ([item url]) break;
[_children removeLastObject];
[set addIndex: [_children count]];
delta = YES;
}
if (delta) {
if (view)
[view removeItemsAtIndexes: set inParent: self withAnimation: NSTableViewAnimationEffectFade];
return YES;
}
return NO;
}
-(BOOL)moveItemFrom: (NSInteger)oldIndex to: (NSInteger)newIndex outlineView: (NSOutlineView *)view {
if (newIndex == oldIndex) return NO;
NSUInteger count = [_children count];
if (oldIndex >= count) return NO;
MediaItem *item = [_children objectAtIndex: oldIndex];
[_children removeObjectAtIndex: oldIndex];
if (newIndex > oldIndex) newIndex--;
if (newIndex >= count) {
[_children addObject: item];
} else {
[_children insertObject: item atIndex: newIndex];
}
if (view) [view moveItemAtIndex: oldIndex inParent: self toIndex: newIndex inParent: self];
// re-index and re-validate.
unsigned ix = 0;
for (MediaItem *item in _children) {
[item setIndex: ix];
[item setValid: ix < _validCount];
// [view reloadItem: item];
++ix;
}
[self pruneChildrenWithOutlineView: view];
//[view reloadItem: self reloadChildren: YES];
return YES;
}
@end
@implementation MediaItem
-(instancetype)initWithURL: (NSURL *)url {
[self setUrl: url];
return self;
}
-(NSInteger) count {
return 0;
}
-(id)objectAtIndex:(NSInteger)index {
return nil;
}
-(BOOL)isGroupItem {
return NO;
}
-(BOOL)isExpandable {
return NO;
}
-(NSString *)viewIdentifier {
return @"ItemView";
}
-(void)prepareView: (TablePathView *)view {
NSValueTransformer *t;
NSDictionary *options;
[view setObjectValue: self];
NSPathControl *pc = [view pathControl];
NSButton *button = [view ejectButton];
[pc unbind: @"value"];
[pc unbind: @"enabled"];
[pc bind: @"value" toObject: self withKeyPath: @"url" options: nil];
[pc bind: @"enabled" toObject: self withKeyPath: @"valid" options: options];
[button unbind: @"enabled"];
t = [NSValueTransformer valueTransformerForName: NSIsNotNilTransformerName];
options = @{ NSValueTransformerBindingOption: t};
[button bind: @"enabled" toObject: self withKeyPath: @"url" options: options];
if (@available(macOS 10.14, *)) {
[button unbind: @"contentTintColor"];
t = [NSValueTransformer valueTransformerForName: @"ValidColorTransformer"];
options = @{ NSValueTransformerBindingOption: t};
[button bind: @"contentTintColor" toObject: self withKeyPath: @"valid" options: options];
} else {
// El Capitan TODO...
}
#if 0
NSColor *tintColor = nil;
if (!_valid) tintColor = [NSColor systemRedColor];
[button setContentTintColor: tintColor];
#endif
}
-(CGFloat)height {
return 27;
}
-(void)invalidate {
if (!_valid) return;
[self setValid: NO];
}
@end
#define CATEGORY_COUNT 6
#define SIZEOF(x) (sizeof(x) / sizeof(x[0]))
@interface MediaViewController () {
MediaCategory *_data[CATEGORY_COUNT];
NSArray *_root;
Media _media;
BOOL _loadingBookmark;
}
@end
@implementation MediaViewController
enum {
kIndexFloppy525 = 0,
kIndexFloppy35,
kIndexHardDrive,
kIndexCDROM,
kIndexCassette,
kIndexDiskImage,
};
-(void)awakeFromNib {
static unsigned first = 0;
if (first) return;
first++;
_data[kIndexFloppy525] = [MediaCategory categoryWithTitle: @"5.25\" Floppies"];
_data[kIndexFloppy35] = [MediaCategory categoryWithTitle: @"3.5\" Floppies"];
_data[kIndexHardDrive] = [MediaCategory categoryWithTitle: @"Hard Drives"];
_data[kIndexCDROM] = [MediaCategory categoryWithTitle: @"CD-ROMs"];
_data[kIndexCassette] = [MediaCategory categoryWithTitle: @"Cassettes"];
_data[kIndexDiskImage] = [MediaCategory categoryWithTitle: @"Hard Disk Images"]; // Mac Nubus psuedo image device
_root = @[];
}
-(void)rebuildArgs {
static char* prefix[] = {
"flop", "flop", "hard", "cdrm", "cass", "disk"
};
static_assert(SIZEOF(prefix) == CATEGORY_COUNT, "Missing item");
NSMutableArray *args = [NSMutableArray new];
unsigned counts[CATEGORY_COUNT] = { 0 };
for (unsigned j = 0; j < CATEGORY_COUNT; ++j) {
MediaCategory *cat = _data[j];
NSInteger valid = [cat validCount];
for (NSInteger i = 0; i < valid; ++i) {
counts[j]++;
MediaItem *item = [cat objectAtIndex: i];
NSURL *url = [item url];
if (!url) continue;
[args addObject: [NSString stringWithFormat: @"-%s%u", prefix[j], counts[j]]];
NSString *s = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding];
[args addObject: s];
}
if (j == 0) counts[1] = counts[0]; // 3.5/5.25
}
[self setArgs: args];
}
-(void)rebuildRoot {
NSMutableArray *tmp = [NSMutableArray new];
int ix = 0;
for (unsigned j = 0 ; j < CATEGORY_COUNT; ++j) {
MediaCategory *cat = _data[j];
[cat setIndex: -1];
if ([cat count]) {
[cat setIndex: ix++];
[tmp addObject: cat];
}
}
_root = tmp;
// todo - switch this to use removeItemsAtIndexes:inParent:withAnimation:
// and insertItemsAtIndexes:inParent:withAnimation:
if (!_loadingBookmark) {
[_outlineView reloadData];
[_outlineView expandItem: nil expandChildren: YES];
}
}
-(void)setMedia: (Media)media {
MediaCategory *cat;
BOOL delta = NO;
unsigned x;
if (MediaEqual(&_media, &media)) return;
_media = media;
#undef _
#define _(name, index) \
x = media.name; cat = _data[index]; delta |= [cat setItemCount: x]
_(cass, kIndexCassette);
_(cdrom, kIndexCDROM);
_(hard, kIndexHardDrive);
_(floppy_3_5, kIndexFloppy35);
_(floppy_5_25, kIndexFloppy525);
_(pseudo_disk, kIndexDiskImage);
if (delta) {
[self rebuildRoot];
if (!_loadingBookmark) [self rebuildArgs];
}
}
-(void)resetDiskImages {
BOOL delta = NO;
for (unsigned j = 0; j < CATEGORY_COUNT; ++j) {
MediaCategory *cat = _data[j];
NSInteger count = [cat count];
for (NSInteger i = 0; i < count; ++i) {
MediaItem *item = [cat objectAtIndex: i];
NSURL *url = [item url];
if (!url) continue;
[item setUrl: nil];
delta = YES;
}
}
if (delta) {
[self rebuildRoot];
if (!_loadingBookmark) [self rebuildArgs];
}
}
static NSString *kDragType = @"private.ample.media";
- (void)viewDidLoad {
[super viewDidLoad];
//NSOutlineView *view = [self view];
//[view expandItem: nil expandChildren: YES];
// Do view setup here.
[_outlineView reloadData];
[_outlineView expandItem: nil expandChildren: YES];
[_outlineView registerForDraggedTypes: @[kDragType]];
}
#pragma mark - NSOutlineViewDelegate
- (void)outlineView:(NSOutlineView *)outlineView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
}
- (void)outlineView:(NSOutlineView *)outlineView didRemoveRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
}
//- (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item;
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id<MediaNode>)item {
NSString *ident = [item viewIdentifier];
if (!ident) return nil;
NSTableCellView *v = [outlineView makeViewWithIdentifier: ident owner: self];
[(id<MediaNode>)item prepareView: v];
[v setObjectValue: item];
return v;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id<MediaNode>)item {
return [item isExpandable];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item {
return NO; //[item isGroupItem];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item {
return NO;
}
/*
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowCellExpansionForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
return NO;
}
*/
-(BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item {
return NO;
}
- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
//return nil;
return [[item cellClass] new];
}
#pragma mark - NSOutlineViewDataSource
// nil item indicates the root.
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
if (item == nil)
return [_root count];
return [item count];
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
if (item == nil) {
return [_root objectAtIndex: index];
}
return [item objectAtIndex: index];
}
-(CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id<MediaNode>)item {
return [item height];
}
#if 0
- (id<NSPasteboardWriting>)outlineView:(NSOutlineView *)outlineView pasteboardWriterForItem:(id<MediaNode>)item {
if ([item isGroupItem]) return nil;
NSPasteboardItem *pb = [NSPasteboardItem new];
return pb;
}
#endif
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard {
if ([items count] > 1) return NO;
//NSLog(@"%s", sel_getName(_cmd));
MediaItem *item = [items firstObject];
if (![item isKindOfClass: [MediaItem class]]) return NO;
// find the category. only allow if more than 1 item in the category.
MediaCategory *cat = nil;
for (MediaCategory *c in _root) {
NSUInteger ix = [[c children] indexOfObject: item];
if (ix != NSNotFound){
cat = c;
break;
}
}
if (!cat) return NO;
if ([cat count] < 2) return NO;
NSInteger indexes[2] = { 0, 0 };
indexes[0] = [cat index];
indexes[1] = [item index];
NSData *data = [NSData dataWithBytes: indexes length: sizeof(indexes)];
[pasteboard setData: data forType: kDragType];
return YES;
}
/*
* IF item is present, it's a MediaCategory and index is the index of the MediaItem it would be inserted as.
* IF item is nil, index is the MediaCategory index, which should be converted to moving to the end.
* IF index < 0, dragging far beyond the category list, so NOPE it.
*
*/
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id<NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index {
if (index < 0) return NSDragOperationNone;
NSPasteboard *pb = [info draggingPasteboard];
NSData *data = [pb dataForType: kDragType];
if (!data) return NSDragOperationNone;
NSInteger indexes[2];
if ([data length] != sizeof(indexes)) return NSDragOperationNone;
[data getBytes: &indexes length: sizeof(indexes)];
//NSLog(@"%d - %d", (int)indexes[0], (int)indexes[1]);
MediaCategory *cat = item;
if (!item) {
// move to the END of the previous category.
if (index == 0) return NSDragOperationNone;
cat = [_root objectAtIndex: index - 1];
index = [cat count]; // -1; - interferes w/ -1 logic below.
}
//NSLog(@"%d - %d", (int)[(MediaCategory *)item index], (int)index);
if ([cat index] != indexes[0]) return NSDragOperationNone;
if (indexes[1] == index) return NSDragOperationNone;
if (indexes[1] == index-1) return NSDragOperationNone;
return NSDragOperationMove;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id<NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index {
if (index < 0) return NO;
NSPasteboard *pb = [info draggingPasteboard];
NSData *data = [pb dataForType: kDragType];
if (!data) return NSDragOperationNone;
NSInteger indexes[2];
if ([data length] != sizeof(indexes)) return NO;
[data getBytes: &indexes length: sizeof(indexes)];
//NSLog(@"%d - %d", (int)indexes[0], (int)indexes[1]);
MediaCategory *cat = item;
if (!item) {
// move to the END of the previous category.
if (index == 0) return NO;
cat = [_root objectAtIndex: index - 1];
index = [cat count]; // -1; - interferes w/ -1 logic below.
}
//NSLog(@"%d - %d", (int)[(MediaCategory *)item index], (int)index);
if ([cat index] != indexes[0]) return NO;
if (indexes[1] == index) return NO;
if (indexes[1] == index-1) return NO;
NSInteger oldIndex = indexes[1];
[_outlineView beginUpdates];
[cat moveItemFrom: oldIndex to: index outlineView: _outlineView];
[_outlineView endUpdates];
[self rebuildArgs];
//[_outlineView reloadItem: cat reloadChildren: YES];
return YES;
}
#pragma mark - IBActions
- (IBAction)ejectAction:(id)sender {
NSInteger row = [_outlineView rowForView: sender];
if (row < 0) return;
//TablePathView *pv = [_outlineView viewAtColumn: 0 row: row makeIfNecessary: NO];
MediaItem *item = [_outlineView itemAtRow: row];
[item setUrl: nil];
//[[pv pathControl] setURL: nil];
// if item is invalid, should attempt to remove...
if (![item valid]) {
MediaCategory *cat = [_outlineView parentForItem: item];
[_outlineView beginUpdates];
[cat pruneChildrenWithOutlineView: _outlineView];
[_outlineView endUpdates];
}
// todo -- if this eliminates a category completely, it will still be included
// since we're now using animaations instead of reloading.
[self rebuildArgs];
}
- (IBAction)pathAction:(id)sender {
// need to update the eject button...
NSURL *url = [(NSPathControl *)sender URL];
if (url) {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName: @"DiskImageAdded" object: url];
}
[self rebuildArgs];
}
-(IBAction)reset:(id)sender {
[self resetDiskImages];
}
@end
@implementation MediaViewController (Bookmark)
-(void)willLoadBookmark:(NSDictionary *)bookmark {
_loadingBookmark = YES;
[self resetDiskImages];
}
-(void)didLoadBookmark:(NSDictionary *)bookmark {
_loadingBookmark = NO;
[self rebuildRoot];
[self rebuildArgs];
}
-(BOOL)loadBookmark: (NSDictionary *)bookmark {
// if order of indexes change, would need to do a version check.
NSArray *media = [bookmark objectForKey: @"media"];
unsigned ix = 0;
for (NSArray *a in media) {
if (ix >= CATEGORY_COUNT) {
NSLog(@"MediaViewController: too many categories.");
break;
}
MediaCategory *cat = _data[ix++];
NSInteger count = [cat count];
unsigned i = 0;
for (NSString *path in a) {
if (i >= count) {
NSLog(@"MediaViewController: too many files.");
break; //
}
MediaItem *item = [cat objectAtIndex: i++];
NSURL *url = nil;
if ([path length])
url = [NSURL fileURLWithPath: path];
[item setUrl: url];
}
}
return YES;
}
-(BOOL)saveBookmark: (NSMutableDictionary *)bookmark {
NSMutableArray *media = [NSMutableArray arrayWithCapacity: CATEGORY_COUNT];
for (unsigned ix = 0; ix < CATEGORY_COUNT; ++ix) {
MediaCategory *cat = _data[ix];
NSInteger count = [cat validCount];
NSMutableArray *array = [NSMutableArray new];
for (NSInteger i = 0; i < count; ++i) {
MediaItem *item = [cat objectAtIndex: i];
NSURL *url = [item url];
NSString *s = @"";
if (url)
s = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding];
[array addObject: s];
}
[media addObject: array];
}
[bookmark setObject: media forKey: @"media"];
return YES;
}
@end