[vlc-devel] commit: macosx display provider: added the ability to enable/disable Last. FM submissions through the distributed notification center ( Felix Paul Kühne )

git version control git at videolan.org
Sat Feb 20 01:29:25 CET 2010


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Feb 20 01:06:31 2010 +0100| [09b32304d4c67d718af46c210ffdb67da0366fe8] | committer: Felix Paul Kühne 

macosx display provider: added the ability to enable/disable Last.FM submissions through the distributed notification center

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=09b32304d4c67d718af46c210ffdb67da0366fe8
---

 .../gui/macosx_dialog_provider/dialogProvider.h    |   56 +++++++++++++--
 .../gui/macosx_dialog_provider/dialogProvider.m    |   72 +++++++++++++-------
 2 files changed, 94 insertions(+), 34 deletions(-)

diff --git a/modules/gui/macosx_dialog_provider/dialogProvider.h b/modules/gui/macosx_dialog_provider/dialogProvider.h
index f11b590..21ad941 100644
--- a/modules/gui/macosx_dialog_provider/dialogProvider.h
+++ b/modules/gui/macosx_dialog_provider/dialogProvider.h
@@ -1,16 +1,56 @@
-//
-//  dialogProvider.h
-//  
-//
-//  Created by Felix Paul Kühne on 26.12.09.
-//  Copyright 2009 __MyCompanyName__. All rights reserved.
-//
+/*****************************************************************************
+ * dialogProvider.h: Minimal Dialog Provider for Mac OS X
+ *****************************************************************************
+ * Copyright (C) 2009-2010 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *          Pierre d'Herbemont <pdherbemont # videolan dot>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
 
 #import <Cocoa/Cocoa.h>
 
+#import <vlc_interface.h>
 
- at interface dialogProvider : NSObject {
+#import "VLCLoginPanel.h"
+#import "VLCProgressPanel.h"
 
+ at interface VLCDialogDisplayer : NSObject
+{
+    intf_thread_t *p_intf;
+    VLCProgressPanel *_currentProgressBarPanel;
 }
+- (intf_thread_t *)intf;
+- (void)setIntf:(intf_thread_t *)p_mainintf;
+- (void)globalNotificationReceived: (NSNotification *)theNotification;
 
++ (NSDictionary *)dictionaryForDialog:(const char *)title :(const char *)message :(const char *)yes :(const char *)no :(const char *)cancel;
+
+- (void)displayError:(NSDictionary *)dialog;
+- (void)displayCritical:(NSDictionary *)dialog;
+- (NSNumber *)displayQuestion:(NSDictionary *)dialog;
+- (NSDictionary *)displayLogin:(NSDictionary *)dialog;
+
+- (void)displayProgressBar:(NSDictionary *)dict;
+- (void)updateProgressPanel:(NSDictionary *)dict;
+- (void)destroyProgressPanel;
+- (NSNumber *)checkProgressPanel;
+
+- (void)updateExtensionDialog:(NSValue *)extensionDialog;
+
+- (id)resultFromSelectorOnMainThread:(SEL)sel withObject:(id)object;
 @end
diff --git a/modules/gui/macosx_dialog_provider/dialogProvider.m b/modules/gui/macosx_dialog_provider/dialogProvider.m
index 93a882c..b60dfd5 100644
--- a/modules/gui/macosx_dialog_provider/dialogProvider.m
+++ b/modules/gui/macosx_dialog_provider/dialogProvider.m
@@ -5,6 +5,7 @@
  * $Id$
  *
  * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *          Pierre d'Herbemont <pdherbemont # videolan dot>
  *
  * 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
@@ -34,12 +35,9 @@
 #import <vlc_common.h>
 #import <vlc_plugin.h>
 #import <vlc_dialog.h>
-#import <vlc_interface.h>
 #import <vlc_extensions.h>
 
-#import <Cocoa/Cocoa.h>
-#import "VLCLoginPanel.h"
-#import "VLCProgressPanel.h"
+#import "dialogProvider.h"
 
 /*****************************************************************************
  * Prototypes
@@ -59,28 +57,6 @@ static void updateProgressPanel (void *, const char *, float);
 static bool checkProgressPanel (void *);
 static void destroyProgressPanel (void *);
 
- at interface VLCDialogDisplayer : NSObject
-{
-    VLCProgressPanel *_currentProgressBarPanel;
-}
-
-+ (NSDictionary *)dictionaryForDialog:(const char *)title :(const char *)message :(const char *)yes :(const char *)no :(const char *)cancel;
-
-- (void)displayError:(NSDictionary *)dialog;
-- (void)displayCritical:(NSDictionary *)dialog;
-- (NSNumber *)displayQuestion:(NSDictionary *)dialog;
-- (NSDictionary *)displayLogin:(NSDictionary *)dialog;
-
-- (void)displayProgressBar:(NSDictionary *)dict;
-- (void)updateProgressPanel:(NSDictionary *)dict;
-- (void)destroyProgressPanel;
-- (NSNumber *)checkProgressPanel;
-
-- (void)updateExtensionDialog:(NSValue *)extensionDialog;
-
-- (id)resultFromSelectorOnMainThread:(SEL)sel withObject:(id)object;
- at end
-
 @interface VLCDialogButton : NSButton
 {
     extension_widget_t *widget;
@@ -545,6 +521,7 @@ int OpenIntf(vlc_object_t *p_this)
     memset(p_intf->p_sys,0,sizeof(*p_intf->p_sys));
 
     p_intf->p_sys->displayer = [[VLCDialogDisplayer alloc] init];
+    [p_intf->p_sys->displayer setIntf:p_intf];
 
     bool hide = var_CreateGetBool(p_intf, prefix "hide-no-user-action-dialogs");
     p_intf->p_sys->is_hidding_noaction_dialogs = hide;
@@ -568,6 +545,13 @@ int OpenIntf(vlc_object_t *p_this)
     var_AddCallback(p_intf,"dialog-extension",DisplayExtension,p_intf);
     dialog_Register(p_intf);
 
+    /* subscribe to our last.fm announcements */
+    [[NSDistributedNotificationCenter defaultCenter] addObserver:p_intf->p_sys->displayer
+                                                        selector:@selector(globalNotificationReceived:)
+                                                            name:NULL
+                                                          object:@"VLCLastFMSupport"
+                                              suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
+
     msg_Dbg(p_intf,"Mac OS X dialog provider initialised");
 
     return VLC_SUCCESS;
@@ -724,10 +708,21 @@ bool checkProgressPanel (void *priv)
 @implementation VLCDialogDisplayer
 - (void)dealloc
 {
+    [[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
     assert(!_currentProgressBarPanel); // This has to be closed on main thread.
     [super dealloc];
 }
 
+- (void)setIntf: (intf_thread_t *)p_mainintf
+{
+    p_intf = p_mainintf;
+}
+
+- (intf_thread_t *)intf
+{
+    return p_intf;
+}
+
 + (NSDictionary *)dictionaryForDialog:(const char *)title :(const char *)message :(const char *)yes :(const char *)no :(const char *)cancel
 {
     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
@@ -863,6 +858,31 @@ bool checkProgressPanel (void *priv)
 }
 
 #pragma mark -
+#pragma mark Last.FM support
+- (void)globalNotificationReceived: (NSNotification *)theNotification
+{
+    NSLog(@"globalNotificationReceived");
+    NSDictionary *userData = [theNotification userInfo];
+    BOOL lastFMEnabled = [[userData objectForKey:@"enabled"] intValue];
+    NSString *lastFMUsername = [userData objectForKey:@"username"];
+    NSString *lastFMPassword = [userData objectForKey:@"password"];
+
+    if (module_exists("audioscrobbler")) {
+        if (lastFMEnabled)
+            config_AddIntf(p_intf, "audioscrobbler");
+        else
+            config_RemoveIntf(p_intf, "audioscrobbler");
+
+        config_PutPsz(p_intf, "lastfm-username", [lastFMUsername UTF8String]);
+        config_PutPsz(p_intf, "lastfm-password", [lastFMPassword UTF8String]);
+        config_SaveConfigFile( p_intf, "main" );
+        config_SaveConfigFile(p_intf, "audioscrobbler");
+    }
+    else
+        msg_Err(p_intf,"Last.FM module not found, no action");
+}
+
+#pragma mark -
 #pragma mark Extensions Dialog
 
 - (void)triggerClick:(id)sender




More information about the vlc-devel mailing list