+- (int)intValue
+{
+ return [o_popup selectedTag];
+}
+@end
+
+@implementation ModuleListConfigControl
+- (id) initWithItem: (module_config_t *)_p_item
+ withView: (NSView *)o_parent_view
+{
+if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
+//TODO....
+ return nil;
+
+//Fill our array to know how may items we have...
+ module_t *p_parser, **p_list;
+ size_t i_module_index;
+ NSRect mainFrame = [o_parent_view frame];
+ NSString *o_labelString, *o_textfieldString, *o_tooltip;
+
+ o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
+ /* build a list of available modules */
+ p_list = module_list_get( NULL );
+ for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
+ {
+ int i;
+ p_parser = p_list[i_module_index];
+
+ if( module_is_main( p_parser ) )
+ continue;
+
+ unsigned int confsize;
+ module_config_get( p_parser, &confsize );
+
+ for ( i = 0; i < confsize; i++ )
+ {
+ unsigned int unused;
+ module_config_t *p_config = module_config_get( p_parser, &unused ) + i;
+ NSString *o_modulelongname, *o_modulename;
+ NSNumber *o_moduleenabled = nil;
+
+ /* Hack: required subcategory is stored in i_min */
+ if( p_config->i_type == CONFIG_SUBCATEGORY &&
+ p_config->value.i == _p_item->min.i )
+ {
+ o_modulelongname = [NSString stringWithUTF8String:
+ module_GetLongName( p_parser )];
+ o_modulename = [NSString stringWithUTF8String:
+ module_get_object( p_parser )];
+
+ if( _p_item->value.psz &&
+ strstr( _p_item->value.psz, module_get_object( p_parser ) ) )
+ o_moduleenabled = [NSNumber numberWithBool:YES];
+ else
+ o_moduleenabled = [NSNumber numberWithBool:NO];
+
+ [o_modulearray addObject:[NSMutableArray
+ arrayWithObjects: o_modulename, o_modulelongname,
+ o_moduleenabled, nil]];
+ }
+ }
+ }
+ module_list_free( p_list );
+
+ mainFrame.size.height = 30 + 18 * [o_modulearray count];
+ mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
+ mainFrame.origin.x = LEFTMARGIN;
+ mainFrame.origin.y = 0;
+ if( [super initWithFrame: mainFrame item: _p_item] != nil )
+ {
+ i_view_type = CONFIG_ITEM_MODULE_LIST;
+
+ o_tooltip = [[VLCMain sharedInstance] wrapString:
+ [[VLCMain sharedInstance]
+ localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
+
+ /* add the label */
+ if( p_item->psz_text )
+ o_labelString = [[VLCMain sharedInstance]
+ localizedString: (char *)p_item->psz_text];
+ else
+ o_labelString = [NSString stringWithString:@""];
+ ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
+ [o_label setAutoresizingMask:NSViewNotSizable ];
+ [self addSubview: o_label];
+
+ /* build the textfield */
+ if( p_item->value.psz )
+ o_textfieldString = [[VLCMain sharedInstance]
+ localizedString: (char *)p_item->value.psz];
+ else
+ o_textfieldString = [NSString stringWithString: @""];
+ ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
+ mainFrame.size.height - 22, mainFrame.size.width -
+ [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
+ [o_textfield setAutoresizingMask:NSViewWidthSizable ];
+ [self addSubview: o_textfield];
+
+
+{
+ NSRect s_rc = mainFrame;
+ s_rc.size.height = mainFrame.size.height - 30;
+ s_rc.size.width = mainFrame.size.width - 12;
+ s_rc.origin.x = 12;
+ s_rc.origin.y = 0;
+ o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
+ [o_scrollview setDrawsBackground: NO];
+ [o_scrollview setBorderType: NSBezelBorder];
+ [o_scrollview setAutohidesScrollers:YES];
+
+ NSTableView *o_tableview;
+ o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
+ [o_tableview setUsesAlternatingRowBackgroundColors:YES];
+ [o_tableview setHeaderView:nil];
+/* TODO: find a good way to fix the row height and text size*/
+/* FIXME: support for multiple selection... */
+// [o_tableview setAllowsMultipleSelection:YES];
+
+ NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
+ NSCell *o_dataCell = [[NSButtonCell alloc] init];
+ [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
+ [o_dataCell setTitle:@""];
+ [o_dataCell setFont:[NSFont systemFontOfSize:0]];
+ NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
+ initWithIdentifier:@"Enabled"];
+ [o_tableColumn setHeaderCell: o_headerCell];
+ [o_tableColumn setDataCell: o_dataCell];
+ [o_tableColumn setWidth:17];
+ [o_tableview addTableColumn: o_tableColumn];
+
+ o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
+ o_dataCell = [[NSTextFieldCell alloc] init];
+ [o_dataCell setFont:[NSFont systemFontOfSize:12]];
+ o_tableColumn = [[NSTableColumn alloc]
+ initWithIdentifier:@"Module"];
+ [o_tableColumn setHeaderCell: o_headerCell];
+ [o_tableColumn setDataCell: o_dataCell];
+ [o_tableColumn setWidth:388 - 17];
+ [o_tableview addTableColumn: o_tableColumn];
+ [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
+ @"VLC media player module", nil]];
+
+ [o_tableview setDataSource:self];
+ [o_tableview setTarget: self];
+ [o_tableview setAction: @selector(tableChanged:)];
+ [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
+ NSLeftMouseDraggedMask];
+ [o_scrollview setDocumentView: o_tableview];
+}
+ [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
+ [self addSubview: o_scrollview];
+
+
+ }
+ return self;
+}
+
+- (void) alignWithXPosition:(int)i_xPos
+{
+ ;
+}
+
+- (IBAction)tableChanged:(id)sender
+{
+ NSString *o_newstring = @"";
+ unsigned int i;
+ for( i = 0 ; i < [o_modulearray count] ; i++ )
+ if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
+ boolValue] != NO )
+ {
+ o_newstring = [o_newstring stringByAppendingString:
+ [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
+ o_newstring = [o_newstring stringByAppendingString:@":"];
+ }
+
+ [o_textfield setStringValue: [o_newstring
+ substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
+}
+
+- (void)dealloc
+{
+ [o_scrollview release];
+ [super dealloc];
+}
+
+
+- (char *)stringValue
+{
+ return strdup( [[o_textfield stringValue] UTF8String] );
+}
+
+@end
+
+@implementation ModuleListConfigControl (NSTableDataSource)
+
+- (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
+ toPasteboard:(NSPasteboard*)pb
+{
+ // We only want to allow dragging of selected rows.
+ NSEnumerator *iter = [rows objectEnumerator];
+ NSNumber *row;
+ while ((row = [iter nextObject]) != nil)
+ {
+ if (![table isRowSelected:[row intValue]])
+ return NO;
+ }
+
+ [pb declareTypes:[NSArray
+ arrayWithObject:@"VLC media player module"] owner:nil];
+ [pb setPropertyList:rows forType:@"VLC media player module"];
+ return YES;
+}
+
+- (NSDragOperation)tableView:(NSTableView*)table
+ validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
+ proposedDropOperation:(NSTableViewDropOperation)op
+{
+ // Make drops at the end of the table go to the end.
+ if (row == -1)
+ {
+ row = [table numberOfRows];
+ op = NSTableViewDropAbove;
+ [table setDropRow:row dropOperation:op];
+ }
+
+ // We don't ever want to drop onto a row, only between rows.
+ if (op == NSTableViewDropOn)
+ [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
+ return NSTableViewDropAbove;
+}
+
+- (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
+ row:(NSInteger)dropRow dropOperation:(NSTableViewDropOperation)op;
+{
+ NSPasteboard *pb = [info draggingPasteboard];
+ NSDragOperation srcMask = [info draggingSourceOperationMask];
+ BOOL accepted = NO;
+
+ NS_DURING
+
+ NSArray *array;
+
+ // Intra-table drag - data is the array of rows.
+ if (!accepted && (array =
+ [pb propertyListForType:@"VLC media player module"]) != NULL)
+ {
+ NSEnumerator *iter = nil;
+ id val;
+ BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
+ // Move the modules
+ iter = [array objectEnumerator];
+ while ((val = [iter nextObject]) != NULL)
+ {
+ NSArray *o_tmp = [[o_modulearray objectAtIndex:
+ [val intValue]] mutableCopyWithZone:nil];
+ [o_modulearray removeObject:o_tmp];
+ [o_modulearray insertObject:o_tmp
+ atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
+ dropRow++;
+ }
+
+ // Select the newly-dragged items.
+ iter = [array objectEnumerator];
+//TODO...
+ [table deselectAll:self];
+
+ [self tableChanged:self];
+ [table setNeedsDisplay:YES];
+ // Indicate that we finished the drag.
+ accepted = YES;
+ }
+ [table reloadData];
+ [table setNeedsDisplay:YES];
+
+ NS_HANDLER
+
+ // An exception occurred. Uh-oh. Update the track table so that
+ // it stays consistent, and re-raise the exception.
+ [table reloadData];
+ [localException raise];
+ [table setNeedsDisplay:YES];
+ NS_ENDHANDLER
+
+ return accepted;
+}
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
+{
+ return [o_modulearray count];
+}
+
+- (id)tableView:(NSTableView *)aTableView
+ objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+ if( [[aTableColumn identifier] isEqualToString: @"Enabled"] )
+ return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
+ if( [[aTableColumn identifier] isEqualToString: @"Module"] )
+ return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
+
+ return nil;
+}
+
+- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
+ forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+ [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
+ withObject: anObject];
+}