[vlc-commits] macosx: information panel: rewrite data source for codecs list
David Fuhrmann
git at videolan.org
Sat Jan 2 21:15:44 CET 2016
vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Jan 2 21:08:38 2016 +0100| [0b969a5fb773398ba5b2a29290e399765a1be118] | committer: David Fuhrmann
macosx: information panel: rewrite data source for codecs list
Removes old complicated data model for codecs list, and replaces
it by a new and cleaner implementation. And there is no need to
hold dozens of input item references...
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0b969a5fb773398ba5b2a29290e399765a1be118
---
modules/gui/macosx/VLCPlaylistInfo.h | 16 ++--
modules/gui/macosx/VLCPlaylistInfo.m | 173 +++++++++-------------------------
2 files changed, 54 insertions(+), 135 deletions(-)
diff --git a/modules/gui/macosx/VLCPlaylistInfo.h b/modules/gui/macosx/VLCPlaylistInfo.h
index e4288b7..7b1ad64 100644
--- a/modules/gui/macosx/VLCPlaylistInfo.h
+++ b/modules/gui/macosx/VLCPlaylistInfo.h
@@ -26,9 +26,8 @@
* VLCPlaylistInfo interface
*****************************************************************************/
- at class VLCInfoTreeItem;
- at interface VLCInfo : NSWindowController
+ at interface VLCInfo : NSWindowController<NSOutlineViewDataSource>
@property (readonly) input_item_t *item;
@@ -109,15 +108,14 @@
@end
+/**
+ * Holds information for one element in the codec information panel
+ */
@interface VLCInfoTreeItem : NSObject
- at property (readonly) int numberOfChildren;
- at property (readonly) NSString *name;
- at property (readonly) NSString *value;
+ at property (readwrite) NSString *name;
+ at property (readwrite) NSString *value;
-- (id)initWithInputItem:(input_item_t *)inputItem;
-
-- (VLCInfoTreeItem *)childAtIndex:(NSUInteger)i_index;
-- (void)refreshWithItem:(input_item_t *)inputItem;
+ at property (readwrite) NSArray *children;
@end
diff --git a/modules/gui/macosx/VLCPlaylistInfo.m b/modules/gui/macosx/VLCPlaylistInfo.m
index a2ab412..f3a9fbd 100644
--- a/modules/gui/macosx/VLCPlaylistInfo.m
+++ b/modules/gui/macosx/VLCPlaylistInfo.m
@@ -188,8 +188,6 @@
p_item = _p_item;
}
- rootItem = [[VLCInfoTreeItem alloc] initWithInputItem:p_item];
-
if (!p_item) {
/* Erase */
#define SET( foo ) \
@@ -258,10 +256,8 @@
FREENULL(psz_meta);
}
- /* reload the advanced table */
- [rootItem refreshWithItem:p_item];
- [_outlineView reloadData];
- [_outlineView expandItem:nil expandChildren:YES];
+ /* reload the codec details table */
+ [self updateStreamsList];
/* update the stats once to display p_item change faster */
[self updateStatistics];
@@ -320,6 +316,43 @@
}
}
+- (void)updateStreamsList
+{
+ rootItem = [[VLCInfoTreeItem alloc] init];
+
+ if (p_item) {
+ vlc_mutex_lock(&p_item->lock);
+ // build list of streams
+ NSMutableArray *streams = [NSMutableArray array];
+
+ for (int i = 0; i < p_item->i_categories; i++) {
+ info_category_t *cat = p_item->pp_categories[i];
+
+ VLCInfoTreeItem *subItem = [[VLCInfoTreeItem alloc] init];
+ subItem.name = toNSStr(cat->psz_name);
+
+ // Build list of codec details
+ NSMutableArray *infos = [NSMutableArray array];
+
+ for (int j = 0; j < cat->i_infos; j++) {
+ VLCInfoTreeItem *infoItem = [[VLCInfoTreeItem alloc] init];
+ infoItem.name = toNSStr(cat->pp_infos[j]->psz_name);
+ infoItem.value = toNSStr(cat->pp_infos[j]->psz_value);
+ [infos addObject:infoItem];
+ }
+
+ subItem.children = [infos copy];
+ [streams addObject:subItem];
+ }
+
+ rootItem.children = [streams copy];
+ vlc_mutex_unlock(&p_item->lock);
+ }
+
+ [_outlineView reloadData];
+ [_outlineView expandItem:nil expandChildren:YES];
+}
+
- (IBAction)metaFieldChanged:(id)sender
{
[_saveMetaDataButton setEnabled: YES];
@@ -391,144 +424,32 @@ error:
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
- return (item == nil) ? [rootItem numberOfChildren] : [item numberOfChildren];
+ return (item == nil) ? [rootItem children].count : [item children].count;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
- return ([item numberOfChildren] > 0);
+ return ([item children].count > 0);
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
- return (item == nil) ? [rootItem childAtIndex:index] : (id)[item childAtIndex:index];
+ return (item == nil) ? [[rootItem children] objectAtIndex:index] : [[item children]objectAtIndex:index];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
+ if (!item)
+ return @"";
+
if ([[tableColumn identifier] isEqualToString:@"0"])
- return (item == nil) ? @"" : (id)[item name];
+ return [item name];
else
- return (item == nil) ? @"" : (id)[item value];
+ return [item value];
}
@end
- at interface VLCInfoTreeItem ()
-{
- int i_object_id;
- input_item_t *p_item;
- VLCInfoTreeItem *_parent;
- NSMutableArray *_children;
- BOOL _isALeafNode;
-}
-
- at end
@implementation VLCInfoTreeItem
-- (id)initWithName:(NSString *)item_name
- value:(NSString *)item_value
- ID:(int)i_id
- parent:(VLCInfoTreeItem *)parent_item
- inputItem:(input_item_t*)inputItem
-{
- self = [super init];
-
- if (self != nil) {
- _name = [item_name copy];
- _value = [item_value copy];
- i_object_id = i_id;
- _parent = parent_item;
- p_item = inputItem;
- if (p_item)
- input_item_Hold(p_item);
- }
- return self;
-}
-
-- (id)initWithInputItem:(input_item_t *)inputItem
-{
- return [self initWithName:@"main" value:@"" ID:-1 parent:nil inputItem:inputItem];
-}
-
-- (void)dealloc
-{
- if (p_item)
- input_item_Release(p_item);
-}
-
-/* Creates and returns the array of children
- *Loads children incrementally */
-- (void)_updateChildren
-{
- if (!p_item)
- return;
-
- if (_children != nil)
- return;
-
- _children = [[NSMutableArray alloc] init];
- if (i_object_id == -1) {
- vlc_mutex_lock(&p_item->lock);
- for (int i = 0 ; i < p_item->i_categories ; i++) {
- NSString *name = toNSStr(p_item->pp_categories[i]->psz_name);
- VLCInfoTreeItem *item = [[VLCInfoTreeItem alloc]
- initWithName:name
- value:@""
- ID:i
- parent:self
- inputItem:p_item];
- [_children addObject:item];
- }
- vlc_mutex_unlock(&p_item->lock);
- _isALeafNode = NO;
- }
- else if (_parent->i_object_id == -1) {
- vlc_mutex_lock(&p_item->lock);
- info_category_t *cat = p_item->pp_categories[i_object_id];
- for (int i = 0 ; i < cat->i_infos ; i++) {
- NSString *name = toNSStr(cat->pp_infos[i]->psz_name);
- NSString *value = toNSStr(cat->pp_infos[i]->psz_value);
- VLCInfoTreeItem *item = [[VLCInfoTreeItem alloc]
- initWithName:name
- value:value
- ID:i
- parent:self
- inputItem:p_item];
- [_children addObject:item];
- }
- vlc_mutex_unlock(&p_item->lock);
- _isALeafNode = NO;
- }
- else
- _isALeafNode = YES;
-}
-
-- (void)refreshWithItem:(input_item_t *)inputItem;
-{
- if (p_item)
- input_item_Release(p_item);
-
- p_item = inputItem;
- if (p_item)
- input_item_Hold(p_item);
-
- _children = nil;
-}
-
-- (VLCInfoTreeItem *)childAtIndex:(NSUInteger)i_index
-{
- return [_children objectAtIndex:i_index];
-}
-
-- (int)numberOfChildren
-{
- [self _updateChildren];
-
- if (_isALeafNode)
- return -1;
-
- return [_children count];
-}
-
@end
More information about the vlc-commits
mailing list