Commit 5289253f authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: fix extension rendering and clean the code a bit

parent 985ad1a4
......@@ -38,10 +38,7 @@
*****************************************************************************/
@interface ExtensionsDialogProvider : NSObject <NSWindowDelegate>
+ (ExtensionsDialogProvider *)sharedInstance:(intf_thread_t *)_p_intf;
+ (void)killInstance;
- (id)initWithIntf:(intf_thread_t *)_p_intf;
+ (ExtensionsDialogProvider *)sharedInstance;
- (void)performEventWithObject: (NSValue *)o_value ofType:(const char*)type;
......
......@@ -38,7 +38,7 @@
* VLCExtensionsDialogProvider implementation
*****************************************************************************/
static int dialogCallback(vlc_object_t *p_this, const char *psz_variable,
static int extensionDialogCallback(vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val,
void *param);
......@@ -155,11 +155,10 @@ static void updateControlFromWidget(NSView *control, extension_widget_t *widget,
// Get the web view
assert([control isKindOfClass:[WebView class]]);
WebView *webView = (WebView *)control;
NSString *string = [NSString stringWithUTF8String:widget->psz_text];
NSString *string = toNSStr(widget->psz_text);
[[webView mainFrame] loadHTMLString:string baseURL:[NSURL URLWithString:@""]];
[webView setNeedsDisplay:YES];
break;
}
case EXTENSION_WIDGET_LABEL:
case EXTENSION_WIDGET_PASSWORD:
......@@ -169,7 +168,7 @@ static void updateControlFromWidget(NSView *control, extension_widget_t *widget,
break;
assert([control isKindOfClass:[NSControl class]]);
NSControl *field = (NSControl *)control;
NSString *string = [NSString stringWithCString:widget->psz_text encoding:NSUTF8StringEncoding];
NSString *string = toNSStr(widget->psz_text);
NSAttributedString *attrString = [[NSAttributedString alloc] initWithHTML:[string dataUsingEncoding: NSISOLatin1StringEncoding] documentAttributes:NULL];
[field setAttributedStringValue:attrString];
break;
......@@ -246,7 +245,7 @@ static void updateControlFromWidget(NSView *control, extension_widget_t *widget,
/**
* Ask the dialogs provider to create a new dialog
**/
static int dialogCallback(vlc_object_t *p_this, const char *psz_variable,
static int extensionDialogCallback(vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val,
void *param)
{
......@@ -256,71 +255,59 @@ static int dialogCallback(vlc_object_t *p_this, const char *psz_variable,
(void) old_val;
(void) param;
ExtensionsDialogProvider *p_edp = [ExtensionsDialogProvider sharedInstance:(intf_thread_t *)p_this];
if (!p_edp)
ExtensionsDialogProvider *extensionDialogProvider = [ExtensionsDialogProvider sharedInstance];
if (!extensionDialogProvider)
return VLC_EGENERIC;
if (!new_val.p_address)
return VLC_EGENERIC;
extension_dialog_t *p_dialog = (extension_dialog_t*) new_val.p_address;
[p_edp manageDialog:p_dialog];
[extensionDialogProvider manageDialog:p_dialog];
return VLC_SUCCESS;
}
}
@interface ExtensionsDialogProvider ()
{
intf_thread_t *p_intf;
}
@end
@implementation ExtensionsDialogProvider
static ExtensionsDialogProvider *sharedInstance = nil;
+ (ExtensionsDialogProvider *)sharedInstance:(intf_thread_t *)_p_intf
+ (ExtensionsDialogProvider *)sharedInstance
{
static ExtensionsDialogProvider *sharedInstance = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [[ExtensionsDialogProvider alloc] initWithIntf:_p_intf];
sharedInstance = [[ExtensionsDialogProvider alloc] init];
});
return sharedInstance;
}
+ (void)killInstance
{
sharedInstance = nil;
}
- (id)initWithIntf:(intf_thread_t *)_p_intf
- (id)init
{
self = [super init];
if (self) {
p_intf = _p_intf;
// The Cocoa interface already called dialog_Register()
intf_thread_t *p_intf = VLCIntf;
var_Create(p_intf, "dialog-extension", VLC_VAR_ADDRESS);
var_AddCallback(p_intf, "dialog-extension", dialogCallback, NULL);
var_AddCallback(p_intf, "dialog-extension", extensionDialogCallback, (__bridge void *)self);
dialog_Register(p_intf);
}
return self;
}
- (void)dealloc
{
msg_Dbg(p_intf, "ExtensionsDialogProvider is quitting...");
var_DelCallback(p_intf, "dialog-extension", dialogCallback, NULL);
intf_thread_t *p_intf = VLCIntf;
var_DelCallback(p_intf, "dialog-extension", extensionDialogCallback, (__bridge void *)self);
}
- (void)performEventWithObject: (NSValue *)o_value ofType: (const char*)type
- (void)performEventWithObject:(NSValue *)objectValue ofType:(const char*)type
{
NSString *o_type = [NSString stringWithUTF8String:type];
NSString *typeString = [NSString stringWithUTF8String:type];
if ([o_type isEqualToString: @"dialog-extension"]) {
if ([typeString isEqualToString: @"dialog-extension"]) {
[self performSelectorOnMainThread:@selector(updateExtensionDialog:)
withObject:o_value
withObject:objectValue
waitUntilDone:YES];
}
......@@ -413,13 +400,13 @@ static ExtensionsDialogProvider *sharedInstance = nil;
continue; /* Some widgets may be NULL@this point */
BOOL shouldDestroy = widget->b_kill;
NSView *control = (__bridge NSView *)(widget->p_sys_intf);
NSView *control = CFBridgingRelease(widget->p_sys_intf);
BOOL update = widget->b_update;
if (!control && !shouldDestroy) {
control = createControlFromWidget(widget, self);
updateControlFromWidget(control, widget, self);
widget->p_sys_intf = (__bridge void *)(control);
widget->p_sys_intf = (void *)CFBridgingRetain(control);
update = YES; // Force update and repositionning
[control setHidden:widget->b_hide];
}
......@@ -456,7 +443,7 @@ static ExtensionsDialogProvider *sharedInstance = nil;
* Note: Lock on p_dialog->lock must be held. */
- (VLCDialogWindow *)createExtensionDialog:(extension_dialog_t *)p_dialog
{
VLCDialogWindow *dialogWindow = nil;
VLCDialogWindow *dialogWindow;
BOOL shouldDestroy = p_dialog->b_kill;
if (!shouldDestroy) {
......@@ -467,13 +454,13 @@ static ExtensionsDialogProvider *sharedInstance = nil;
defer:NO];
[dialogWindow setDelegate:self];
[dialogWindow setDialog:p_dialog];
[dialogWindow setTitle:[NSString stringWithUTF8String:p_dialog->psz_title]];
[dialogWindow setTitle:toNSStr(p_dialog->psz_title)];
VLCDialogGridView *gridView = [[VLCDialogGridView alloc] init];
[gridView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
[dialogWindow setContentView:gridView];
p_dialog->p_sys_intf = (__bridge void *)dialogWindow;
p_dialog->p_sys_intf = (void *)CFBridgingRetain(dialogWindow);
}
[self updateWidgets:p_dialog];
......@@ -494,14 +481,13 @@ static ExtensionsDialogProvider *sharedInstance = nil;
{
assert(p_dialog);
VLCDialogWindow *dialogWindow = (__bridge VLCDialogWindow*) p_dialog->p_sys_intf;
VLCDialogWindow *dialogWindow = CFBridgingRelease(p_dialog->p_sys_intf);
if (!dialogWindow) {
msg_Warn(VLCIntf, "dialog window not found");
return VLC_EGENERIC;
}
[dialogWindow setDelegate:nil];
[dialogWindow close];
dialogWindow = nil;
p_dialog->p_sys_intf = NULL;
......@@ -541,8 +527,7 @@ static ExtensionsDialogProvider *sharedInstance = nil;
[self updateWidgets:p_dialog];
if (strcmp([[dialogWindow title] UTF8String],
p_dialog->psz_title) != 0) {
NSString *titleString = [NSString stringWithCString:p_dialog->psz_title
encoding:NSUTF8StringEncoding];
NSString *titleString = toNSStr(p_dialog->psz_title);
[dialogWindow setTitle:titleString];
}
......@@ -569,7 +554,7 @@ static ExtensionsDialogProvider *sharedInstance = nil;
- (void)manageDialog:(extension_dialog_t *)p_dialog
{
assert(p_dialog);
ExtensionsManager *extMgr = [ExtensionsManager getInstance:p_intf];
ExtensionsManager *extMgr = [ExtensionsManager sharedInstance];
assert(extMgr != NULL);
NSValue *o_value = [NSValue valueWithPointer:p_dialog];
......
......@@ -40,9 +40,8 @@
@interface ExtensionsManager : NSObject
+ (ExtensionsManager *)getInstance:(intf_thread_t *)_p_intf;
+ (ExtensionsManager *)sharedInstance;
- (id)initWithIntf:(intf_thread_t *)_p_intf;
- (void)buildMenu:(NSMenu *)extMenu;
- (BOOL)loadExtensions;
......
......@@ -35,9 +35,8 @@
@interface ExtensionsManager()
{
intf_thread_t *p_intf;
extensions_manager_t *p_extensions_manager;
ExtensionsDialogProvider *p_edp;
ExtensionsDialogProvider *_extensionDialogProvider;
NSMutableDictionary *p_extDict;
......@@ -51,19 +50,20 @@
static ExtensionsManager* instance = nil;
+ (ExtensionsManager *)getInstance:(intf_thread_t *)_p_intf
+ (ExtensionsManager *)sharedInstance
{
if (!instance)
instance = [[ExtensionsManager alloc] initWithIntf:_p_intf];
instance = [[ExtensionsManager alloc] init];
return instance;
}
- (id)initWithIntf:(intf_thread_t *)_p_intf
- (id)init
{
if ((self = [super init])) {
p_intf = _p_intf;
self = [super init];
if (self) {
p_extensions_manager = NULL;
p_edp = NULL;
_extensionDialogProvider = [ExtensionsDialogProvider sharedInstance];
p_extDict = [[NSMutableDictionary alloc] init];
......@@ -79,19 +79,24 @@ static ExtensionsManager* instance = nil;
- (void)buildMenu:(NSMenu *)extMenu
{
assert(extMenu != nil);
if (![self isLoaded])
// This case can happen: do nothing
/* check if stuff was loaded, which can fail */
if (![self isLoaded]) {
BOOL b_ret = [self loadExtensions];
if (b_ret == NO)
return;
}
intf_thread_t *p_intf = VLCIntf;
vlc_mutex_lock(&p_extensions_manager->lock);
extension_t *p_ext = NULL;
int i_ext = 0;
FOREACH_ARRAY(p_ext, p_extensions_manager->extensions) {
bool b_Active = extension_IsActivated(p_extensions_manager, p_ext);
NSString *titleString = [NSString stringWithCString:p_ext->psz_title
encoding:NSUTF8StringEncoding];
NSString *titleString = toNSStr(p_ext->psz_title);
if (b_Active && extension_HasMenu(p_extensions_manager, p_ext)) {
NSMenu *submenu = [[NSMenu alloc] initWithTitle:titleString];
......@@ -105,12 +110,10 @@ static ExtensionsManager* instance = nil;
uint16_t *pi_ids = NULL;
size_t i_num = 0;
if (extension_GetMenu(p_extensions_manager, p_ext,
&ppsz_titles, &pi_ids) == VLC_SUCCESS) {
if (extension_GetMenu(p_extensions_manager, p_ext, &ppsz_titles, &pi_ids) == VLC_SUCCESS) {
for (int i = 0; ppsz_titles[i] != NULL; ++i) {
++i_num;
titleString = [NSString stringWithCString:ppsz_titles[i]
encoding:NSUTF8StringEncoding];
titleString = toNSStr(ppsz_titles[i]);
NSMenuItem *menuItem = [submenu addItemWithTitle:titleString
action:@selector(triggerMenu:)
keyEquivalent:@""];
......@@ -166,17 +169,16 @@ static ExtensionsManager* instance = nil;
- (BOOL)loadExtensions
{
intf_thread_t *p_intf = VLCIntf;
if (!p_extensions_manager) {
p_extensions_manager = (extensions_manager_t*)
vlc_object_create(p_intf, sizeof(extensions_manager_t));
p_extensions_manager = (extensions_manager_t*)vlc_object_create(p_intf, sizeof(extensions_manager_t));
if (!p_extensions_manager) {
b_failed = true;
[delegate extensionsUpdated];
return false;
}
p_extensions_manager->p_module =
module_need(p_extensions_manager, "extension", NULL, false);
p_extensions_manager->p_module = module_need(p_extensions_manager, "extension", NULL, false);
if (!p_extensions_manager->p_module) {
msg_Err(p_intf, "Unable to load extensions module");
......@@ -188,12 +190,11 @@ static ExtensionsManager* instance = nil;
}
/* Initialize dialog provider */
p_edp = [ExtensionsDialogProvider sharedInstance:p_intf];
_extensionDialogProvider = [ExtensionsDialogProvider sharedInstance];
if (!p_edp) {
if (!_extensionDialogProvider) {
msg_Err(p_intf, "Unable to create dialogs provider for extensions");
module_unneed(p_extensions_manager,
p_extensions_manager->p_module);
module_unneed(p_extensions_manager, p_extensions_manager->p_module);
vlc_object_release(p_extensions_manager);
p_extensions_manager = NULL;
b_failed = true;
......@@ -228,6 +229,8 @@ static ExtensionsManager* instance = nil;
- (void)triggerMenu:(id)sender
{
NSLog(@"%s", __PRETTY_FUNCTION__);
intf_thread_t *p_intf = VLCIntf;
uint32_t identifier = [(NSMenuItem *)sender tag];
uint16_t i_ext = MENU_GET_EXTENSION(identifier);
......@@ -319,8 +322,8 @@ static ExtensionsManager* instance = nil;
- (void)dealloc
{
intf_thread_t *p_intf = VLCIntf;
msg_Dbg(p_intf, "Killing extension dialog provider");
[ExtensionsDialogProvider killInstance];
if (p_extensions_manager)
vlc_object_release(p_extensions_manager);
......
......@@ -230,7 +230,7 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
* The serial queue ensures that changed inputs are propagated in the same order as they arrive.
*/
dispatch_async(informInputChangedQueue, ^{
[[ExtensionsManager getInstance:VLCIntf] inputChanged:p_input_changed];
[[ExtensionsManager sharedInstance] inputChanged:p_input_changed];
if (p_input_changed)
vlc_object_release(p_input_changed);
});
......
......@@ -53,7 +53,6 @@
@interface VLCMainMenu()
{
BOOL b_mainMenu_setup;
BOOL b_nib_videoeffects_loaded;
BOOL b_nib_audioeffects_loaded;
BOOL b_nib_tracksynchrloaded;
......@@ -117,11 +116,6 @@
- (void)awakeFromNib
{
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(applicationWillFinishLaunching:)
name: NSApplicationWillFinishLaunchingNotification
object: nil];
/* check whether the user runs OSX with a RTL language */
NSArray* languages = [NSLocale preferredLanguages];
NSString* preferredLanguage = [languages firstObject];
......@@ -130,10 +124,7 @@
msg_Dbg(VLCIntf, "adapting interface since '%s' is a RTL language", [preferredLanguage UTF8String]);
[_rateTextField setAlignment: NSLeftTextAlignment];
}
}
- (void)applicationWillFinishLaunching:(NSNotification *)notification
{
[self setRateControlsEnabled:NO];
#ifdef HAVE_SPARKLE
......@@ -149,14 +140,9 @@
VLCStringUtility *stringUtility = [VLCStringUtility sharedInstance];
char *key;
/* Check if we already did this once. Opening the other nibs calls it too,
because VLCMain is the owner */
if (b_mainMenu_setup)
return;
/* Get ExtensionsManager */
intf_thread_t *p_intf = VLCIntf;
_extensionManager = [ExtensionsManager getInstance:p_intf];
_extensionManager = [ExtensionsManager sharedInstance];
[self initStrings];
......@@ -259,21 +245,18 @@
name: NSApplicationDidChangeScreenParametersNotification
object: nil];
/* we're done */
b_mainMenu_setup = YES;
[self setupVarMenuItem:_add_intf target: (vlc_object_t *)p_intf
var:"intf-add" selector: @selector(toggleVar:)];
/* setup extensions menu */
// FIXME: Implement preference for autoloading extensions on mac
if (![_extensionManager isLoaded] && ![_extensionManager cannotLoad])
[_extensionManager loadExtensions];
/* Let the ExtensionsManager itself build the menu */
[_extensionManager buildMenu:_extensionsMenu];
[_extensions setEnabled: ([_extensionsMenu numberOfItems] > 0)];
// FIXME: Implement preference for autoloading extensions on mac
if (![_extensionManager isLoaded] && ![_extensionManager cannotLoad])
[_extensionManager loadExtensions];
/* setup post-proc menu */
NSUInteger count = (NSUInteger) [_postprocessingMenu numberOfItems];
if (count > 0)
......
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