Commit 19e793f9 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx/prefs: split complete from simple prefs, fix class API and remove object instances from xib

parent 9e904e66
...@@ -154,6 +154,7 @@ EXTRA_DIST += \ ...@@ -154,6 +154,7 @@ EXTRA_DIST += \
extras/package/macosx/Resources/English.lproj/Preferences.xib \ extras/package/macosx/Resources/English.lproj/Preferences.xib \
extras/package/macosx/Resources/English.lproj/ResumeDialog.xib \ extras/package/macosx/Resources/English.lproj/ResumeDialog.xib \
extras/package/macosx/Resources/English.lproj/SharedDialogs.xib \ extras/package/macosx/Resources/English.lproj/SharedDialogs.xib \
extras/package/macosx/Resources/English.lproj/SimplePreferences.xib \
extras/package/macosx/Resources/English.lproj/SyncTracks.xib \ extras/package/macosx/Resources/English.lproj/SyncTracks.xib \
extras/package/macosx/Resources/English.lproj/VideoEffects.xib \ extras/package/macosx/Resources/English.lproj/VideoEffects.xib \
extras/package/macosx/Resources/fspanel/fs_background.png \ extras/package/macosx/Resources/fspanel/fs_background.png \
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/***************************************************************************** /*****************************************************************************
* prefs.h: MacOS X module for vlc * prefs.h: MacOS X module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2002-2007 VLC authors and VideoLAN * Copyright (C) 2002-2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Felix Paul Kühne <fkuehne at videolan dot org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -27,28 +28,23 @@ ...@@ -27,28 +28,23 @@
* VLCPrefs interface * VLCPrefs interface
*****************************************************************************/ *****************************************************************************/
@interface VLCPrefs : NSObject @interface VLCPrefs : NSObject
{
IBOutlet id o_prefs_window;
IBOutlet id o_title;
IBOutlet id o_tree;
IBOutlet id o_prefs_view;
IBOutlet id o_save_btn;
IBOutlet id o_cancel_btn;
IBOutlet id o_reset_btn;
IBOutlet id o_showBasic_btn;
}
+ (VLCPrefs *)sharedInstance; + (VLCPrefs *)sharedInstance;
- (void)initStrings; @property (readwrite, weak) IBOutlet NSWindow *prefsWindow;
@property (readwrite, weak) IBOutlet NSTextField *titleLabel;
@property (readwrite, weak) IBOutlet NSOutlineView *tree;
@property (readwrite, weak) IBOutlet NSScrollView *prefsView;
@property (readwrite, weak) IBOutlet NSButton *saveButton;
@property (readwrite, weak) IBOutlet NSButton *cancelButton;
@property (readwrite, weak) IBOutlet NSButton *resetButton;
@property (readwrite, weak) IBOutlet NSButton *showBasicButton;
- (void)setTitle: (NSString *) o_title_name; - (void)setTitle: (NSString *) o_title_name;
- (void)showPrefsWithLevel:(NSInteger)i_window_level; - (void)showPrefsWithLevel:(NSInteger)i_window_level;
- (IBAction)savePrefs: (id)sender; - (IBAction)savePrefs: (id)sender;
- (IBAction)closePrefs: (id)sender; - (IBAction)closePrefs: (id)sender;
- (IBAction)buttonAction: (id)sender; - (IBAction)showSimplePrefs: (id)sender;
- (IBAction)resetPrefs: (id)sender;
@end
@interface VLCFlippedView : NSView
@end @end
/***************************************************************************** /*****************************************************************************
* prefs.m: MacOS X module for vlc * prefs.m: MacOS X module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2002-2012 VLC authors and VideoLAN * Copyright (C) 2002-2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
- (NSString *)name; - (NSString *)name;
- (NSMutableArray *)children; - (NSMutableArray *)children;
- (NSMutableArray *)options; - (NSMutableArray *)options;
- (void)showView:(NSScrollView *)o_prefs_view; - (void)showView:(NSScrollView *)prefsView;
- (void)applyChanges; - (void)applyChanges;
- (void)resetView; - (void)resetView;
...@@ -147,9 +147,8 @@ ...@@ -147,9 +147,8 @@
@interface VLCPrefs() @interface VLCPrefs()
{ {
intf_thread_t *p_intf;
VLCTreeMainItem * _rootTreeItem; VLCTreeMainItem * _rootTreeItem;
NSView *o_empty_view; NSView *o_emptyView;
NSMutableDictionary *o_save_prefs; NSMutableDictionary *o_save_prefs;
} }
@end @end
...@@ -168,74 +167,65 @@ ...@@ -168,74 +167,65 @@
return sharedInstance; return sharedInstance;
} }
- (id)init
{
self = [super init];
if (self) {
p_intf = VLCIntf;
o_empty_view = [[NSView alloc] init];
_rootTreeItem = [[VLCTreeMainItem alloc] init];
}
return self;
}
- (void)awakeFromNib - (void)awakeFromNib
{ {
p_intf = VLCIntf; o_emptyView = [[NSView alloc] init];
_rootTreeItem = [[VLCTreeMainItem alloc] init];
[_prefsWindow setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
[_prefsWindow setHidesOnDeactivate:YES];
[o_prefs_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary]; [_prefsWindow setTitle: _NS("Preferences")];
[o_prefs_window setHidesOnDeactivate:YES]; [_saveButton setTitle: _NS("Save")];
[_cancelButton setTitle: _NS("Cancel")];
[_resetButton setTitle: _NS("Reset All")];
[_showBasicButton setTitle: _NS("Show Basic")];
[self initStrings]; [_prefsView setBorderType: NSGrooveBorder];
[o_prefs_view setBorderType: NSGrooveBorder]; [_prefsView setHasVerticalScroller: YES];
[o_prefs_view setHasVerticalScroller: YES]; [_prefsView setDrawsBackground: NO];
[o_prefs_view setDrawsBackground: NO]; [_prefsView setDocumentView: o_emptyView];
[o_prefs_view setDocumentView: o_empty_view]; [_tree selectRowIndexes: [NSIndexSet indexSetWithIndex: 0] byExtendingSelection: NO];
[o_tree selectRowIndexes: [NSIndexSet indexSetWithIndex: 0] byExtendingSelection: NO];
} }
- (void)setTitle: (NSString *) o_title_name - (void)setTitle: (NSString *) o_title_name
{ {
[o_title setStringValue: o_title_name]; [_titleLabel setStringValue: o_title_name];
} }
- (void)showPrefsWithLevel:(NSInteger)i_window_level - (void)showPrefsWithLevel:(NSInteger)iWindow_level
{ {
[o_prefs_window setLevel: i_window_level]; [_prefsWindow setLevel: iWindow_level];
[o_prefs_window center]; [_prefsWindow center];
[o_prefs_window makeKeyAndOrderFront:self]; [_prefsWindow makeKeyAndOrderFront:self];
[_rootTreeItem resetView]; [_rootTreeItem resetView];
} }
- (void)initStrings
{
[o_prefs_window setTitle: _NS("Preferences")];
[o_save_btn setTitle: _NS("Save")];
[o_cancel_btn setTitle: _NS("Cancel")];
[o_reset_btn setTitle: _NS("Reset All")];
[o_showBasic_btn setTitle: _NS("Show Basic")];
}
- (IBAction)savePrefs: (id)sender - (IBAction)savePrefs: (id)sender
{ {
/* TODO: call savePrefs on Root item */ /* TODO: call savePrefs on Root item */
[_rootTreeItem applyChanges]; [_rootTreeItem applyChanges];
[[VLCCoreInteraction sharedInstance] fixPreferences]; [[VLCCoreInteraction sharedInstance] fixPreferences];
config_SaveConfigFile(p_intf); config_SaveConfigFile(VLCIntf);
[o_prefs_window orderOut:self]; [_prefsWindow orderOut:self];
} }
- (IBAction)closePrefs: (id)sender - (IBAction)closePrefs: (id)sender
{ {
[o_prefs_window orderOut:self]; [_prefsWindow orderOut:self];
} }
- (IBAction)buttonAction: (id)sender - (IBAction)showSimplePrefs: (id)sender
{ {
[o_prefs_window orderOut: self]; [_prefsWindow orderOut: self];
[[[VLCMain sharedInstance] simplePreferences] showSimplePrefs]; [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
} }
- (IBAction)resetPrefs:(id)sender
{
#warning implement me
}
- (void)loadConfigTree - (void)loadConfigTree
{ {
} }
...@@ -247,8 +237,8 @@ ...@@ -247,8 +237,8 @@
/* update the document view to the view of the selected tree item */ /* update the document view to the view of the selected tree item */
- (void)outlineViewSelectionDidChange:(NSNotification *)o_notification - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
{ {
[[o_tree itemAtRow:[o_tree selectedRow]] showView: o_prefs_view]; [[_tree itemAtRow:[_tree selectedRow]] showView: _prefsView];
[o_tree expandItem:[o_tree itemAtRow:[o_tree selectedRow]]]; [_tree expandItem:[_tree itemAtRow:[_tree selectedRow]]];
} }
@end @end
...@@ -278,6 +268,140 @@ ...@@ -278,6 +268,140 @@
@end @end
#pragma mark -
#pragma mark (Root class for all TreeItems)
@implementation VLCTreeItem
- (id)initWithName:(NSString*)name
{
self = [super init];
if (self != nil)
_name = name;
return self;
}
- (VLCTreeItem *)childAtIndex:(NSInteger)i_index
{
return [[self children] objectAtIndex:i_index];
}
- (int)numberOfChildren
{
return [[self children] count];
}
- (NSString *)name
{
return _name;
}
- (void)showView:(NSScrollView *)prefsView
{
NSRect s_vrc;
NSView *view;
[[VLCPrefs sharedInstance] setTitle: [self name]];
s_vrc = [[prefsView contentView] bounds]; s_vrc.size.height -= 4;
view = [[NSView alloc] initWithFrame: s_vrc];
[view setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin | NSViewMaxYMargin];
if (!_subviews) {
_subviews = [[NSMutableArray alloc] initWithCapacity:10];
NSUInteger count = [[self options] count];
for (NSUInteger i = 0; i < count; i++) {
VLCTreeLeafItem * item = [[self options] objectAtIndex:i];
VLCConfigControl *control;
control = [VLCConfigControl newControl:[item configItem] withView:view];
if (control) {
[control setAutoresizingMask: NSViewMaxYMargin | NSViewWidthSizable];
[_subviews addObject: control];
}
}
}
assert(view);
int i_lastItem = 0;
int i_yPos = -2;
int i_max_label = 0;
NSEnumerator *enumerator = [_subviews objectEnumerator];
VLCConfigControl *widget;
NSRect frame;
while((widget = [enumerator nextObject])) {
if (i_max_label < [widget labelSize])
i_max_label = [widget labelSize];
}
enumerator = [_subviews objectEnumerator];
while((widget = [enumerator nextObject])) {
int i_widget;
i_widget = [widget viewType];
i_yPos += [VLCConfigControl calcVerticalMargin:i_widget lastItem:i_lastItem];
[widget setYPos:i_yPos];
frame = [widget frame];
frame.size.width = [view frame].size.width - LEFTMARGIN - RIGHTMARGIN;
[widget setFrame:frame];
[widget alignWithXPosition: i_max_label];
i_yPos += [widget frame].size.height;
i_lastItem = i_widget;
[view addSubview:widget];
}
frame = [view frame];
frame.size.height = i_yPos;
[view setFrame:frame];
[prefsView setDocumentView:view];
}
- (void)applyChanges
{
NSUInteger i;
NSUInteger count = [_subviews count];
for (i = 0 ; i < count ; i++)
[[_subviews objectAtIndex:i] applyChanges];
count = [_children count];
for (i = 0 ; i < count ; i++)
[[_children objectAtIndex:i] applyChanges];
}
- (void)resetView
{
NSUInteger count = [_subviews count];
for (NSUInteger i = 0 ; i < count ; i++)
[[_subviews objectAtIndex:i] resetValues];
count = [_options count];
for (NSUInteger i = 0 ; i < count ; i++)
[[_options objectAtIndex:i] resetView];
count = [_children count];
for (NSUInteger i = 0 ; i < count ; i++)
[[_children objectAtIndex:i] resetView];
}
- (NSMutableArray *)children
{
if (!_children)
_children = [[NSMutableArray alloc] init];
return _children;
}
- (NSMutableArray *)options
{
if (!_options)
_options = [[NSMutableArray alloc] init];
return _options;
}
@end
#pragma mark - #pragma mark -
@implementation VLCTreeMainItem @implementation VLCTreeMainItem
...@@ -313,8 +437,6 @@ ...@@ -313,8 +437,6 @@
if (_children) return _children; if (_children) return _children;
_children = [[NSMutableArray alloc] init]; _children = [[NSMutableArray alloc] init];
intf_thread_t *p_intf = VLCIntf;
/* List the modules */ /* List the modules */
size_t count, i; size_t count, i;
module_t ** modules = module_list_get(&count); module_t ** modules = module_list_get(&count);
...@@ -502,147 +624,3 @@ ...@@ -502,147 +624,3 @@
return _configItem; return _configItem;
} }
@end @end
#pragma mark -
#pragma mark (Root class for all TreeItems)
@implementation VLCTreeItem
- (id)initWithName:(NSString*)name
{
self = [super init];
if (self != nil)
_name = name;
return self;
}
- (VLCTreeItem *)childAtIndex:(NSInteger)i_index
{
return [[self children] objectAtIndex:i_index];
}
- (int)numberOfChildren
{
return [[self children] count];
}
- (NSString *)name
{
return _name;
}
- (void)showView:(NSScrollView *)prefsView
{
NSRect s_vrc;
NSView *view;
[[VLCPrefs sharedInstance] setTitle: [self name]];
s_vrc = [[prefsView contentView] bounds]; s_vrc.size.height -= 4;
view = [[VLCFlippedView alloc] initWithFrame: s_vrc];
[view setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin | NSViewMaxYMargin];
if (!_subviews) {
_subviews = [[NSMutableArray alloc] initWithCapacity:10];
NSUInteger count = [[self options] count];
for (NSUInteger i = 0; i < count; i++) {
VLCTreeLeafItem * item = [[self options] objectAtIndex:i];
VLCConfigControl *control;
control = [VLCConfigControl newControl:[item configItem] withView:view];
if (control) {
[control setAutoresizingMask: NSViewMaxYMargin | NSViewWidthSizable];
[_subviews addObject: control];
}
}
}
assert(view);
int i_lastItem = 0;
int i_yPos = -2;
int i_max_label = 0;
NSEnumerator *enumerator = [_subviews objectEnumerator];
VLCConfigControl *widget;
NSRect frame;
while((widget = [enumerator nextObject])) {
if (i_max_label < [widget labelSize])
i_max_label = [widget labelSize];
}
enumerator = [_subviews objectEnumerator];
while((widget = [enumerator nextObject])) {
int i_widget;
i_widget = [widget viewType];
i_yPos += [VLCConfigControl calcVerticalMargin:i_widget lastItem:i_lastItem];
[widget setYPos:i_yPos];
frame = [widget frame];
frame.size.width = [view frame].size.width - LEFTMARGIN - RIGHTMARGIN;
[widget setFrame:frame];
[widget alignWithXPosition: i_max_label];
i_yPos += [widget frame].size.height;
i_lastItem = i_widget;
[view addSubview:widget];
}
frame = [view frame];
frame.size.height = i_yPos;
[view setFrame:frame];
[prefsView setDocumentView:view];
}
- (void)applyChanges
{
NSUInteger i;
NSUInteger count = [_subviews count];
for (i = 0 ; i < count ; i++)
[[_subviews objectAtIndex:i] applyChanges];
count = [_children count];
for (i = 0 ; i < count ; i++)
[[_children objectAtIndex:i] applyChanges];
}
- (void)resetView
{
NSUInteger count = [_subviews count];
for (NSUInteger i = 0 ; i < count ; i++)
[[_subviews objectAtIndex:i] resetValues];
count = [_options count];
for (NSUInteger i = 0 ; i < count ; i++)
[[_options objectAtIndex:i] resetView];
count = [_children count];
for (NSUInteger i = 0 ; i < count ; i++)
[[_children objectAtIndex:i] resetView];
}
- (NSMutableArray *)children
{
if (!_children)
_children = [[NSMutableArray alloc] init];
return _children;
}
- (NSMutableArray *)options
{
if (!_options)
_options = [[NSMutableArray alloc] init];
return _options;
}
@end
#pragma mark -
@implementation VLCFlippedView
- (BOOL)isFlipped
{
return(YES);
}
@end
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