[vlc-commits] macosx: fixed enabling/disabling SDs through the sidebar

Felix Paul Kühne git at videolan.org
Sat Jan 14 19:03:10 CET 2012


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Jan 14 19:03:00 2012 +0100| [4c0f16871304032f95f0d56737d438c17621d51d] | committer: Felix Paul Kühne

macosx: fixed enabling/disabling SDs through the sidebar

note that the playlist table remains to be fixed to show the current selection only

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

 modules/gui/macosx/MainWindow.m      |   53 +++++++++++++++++++++++++++++----
 modules/gui/macosx/MainWindowTitle.m |    2 +-
 modules/gui/macosx/PXSourceList.m    |    6 +++-
 modules/gui/macosx/SideBarItem.h     |    2 +
 modules/gui/macosx/SideBarItem.m     |    2 +
 modules/gui/macosx/playlist.m        |    1 +
 6 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/modules/gui/macosx/MainWindow.m b/modules/gui/macosx/MainWindow.m
index ea804c2..a4500fc 100644
--- a/modules/gui/macosx/MainWindow.m
+++ b/modules/gui/macosx/MainWindow.m
@@ -328,7 +328,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
     for (; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++)
     {
         o_identifier = [NSString stringWithCString: *ppsz_name encoding: NSUTF8StringEncoding];
-        o_identifier = [[o_identifier componentsSeparatedByString:@"{"] objectAtIndex:0];
         switch (*p_category) {
             case SD_CAT_INTERNET:
                 {
@@ -337,18 +336,21 @@ static VLCMainWindow *_o_sharedInstance = nil;
                         [[internetItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-podcast"]];
                     else
                         [[internetItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
+                    [[internetItems lastObject] setSdtype: SD_CAT_INTERNET];
                 }
                 break;
             case SD_CAT_DEVICES:
                 {
                     [devicesItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
                     [[devicesItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
+                    [[devicesItems lastObject] setSdtype: SD_CAT_DEVICES];
                 }
                 break;
             case SD_CAT_LAN:
                 {
                     [lanItems addObject: [SideBarItem itemWithTitle: [NSString stringWithCString: *ppsz_longname encoding: NSUTF8StringEncoding] identifier: o_identifier]];
                     [[lanItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-local"]];
+                    [[lanItems lastObject] setSdtype: SD_CAT_LAN];
                 }
                 break;
             case SD_CAT_MYCOMPUTER:
@@ -362,6 +364,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
                         [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-pictures"]];
                     else
                         [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
+                    [[mycompItems lastObject] setSdtype: SD_CAT_MYCOMPUTER];
                 }
                 break;
             default:
@@ -1063,7 +1066,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
     [o_fspanel setSeekable: b_seekable];
 
     PL_LOCK;
-    if (playlist_CurrentSize( p_playlist ) >= 1)
+    if (p_playlist->items.i_size >= 1)
         [self hideDropZone];
     else
         [self showDropZone];
@@ -1895,14 +1898,41 @@ static VLCMainWindow *_o_sharedInstance = nil;
 - (NSMenu*)sourceList:(PXSourceList*)aSourceList menuForEvent:(NSEvent*)theEvent item:(id)item
 {
 	if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)) {
-		NSMenu * m = [[NSMenu alloc] init];
 		if (item != nil)
-			[m addItemWithTitle:[item title] action:nil keyEquivalent:@""];
-		return [m autorelease];
+        {
+            NSMenu * m;
+            if ([item sdtype] > 0)
+            {
+                m = [[NSMenu alloc] init];
+                playlist_t * p_playlist = pl_Get( VLCIntf );
+                BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded( p_playlist, [[item identifier] UTF8String] );
+                if (!sd_loaded)
+                    [m addItemWithTitle:_NS("Enable") action:@selector(sdmenuhandler:) keyEquivalent:@""];
+                else
+                    [m addItemWithTitle:_NS("Disable") action:@selector(sdmenuhandler:) keyEquivalent:@""];
+                [[m itemAtIndex:0] setRepresentedObject: [item identifier]];
+            }
+            return [m autorelease];
+        }
 	}
 	return nil;
 }
 
+- (IBAction)sdmenuhandler:(id)sender
+{
+    NSString * identifier = [sender representedObject];
+    if ([identifier length] > 0 && ![identifier isEqualToString:@"lua{sd='freebox',longname='Freebox TV'}"])
+    {
+        playlist_t * p_playlist = pl_Get( VLCIntf );
+        BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded( p_playlist, [identifier UTF8String] );
+
+        if (!sd_loaded)
+            playlist_ServicesDiscoveryAdd( p_playlist, [identifier UTF8String] );
+        else
+            playlist_ServicesDiscoveryRemove( p_playlist, [identifier UTF8String] );
+    }
+}
+
 #pragma mark -
 #pragma mark Side Bar Delegate Methods
 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
@@ -1917,9 +1947,18 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 	//Set the label text to represent the new selection
     if([selectedIndexes count]==1) {
-		NSString *title = [[o_sidebar_view itemAtRow:[selectedIndexes firstIndex]] title];
+        id item = [o_sidebar_view itemAtRow:[selectedIndexes firstIndex]];
+        if ([item sdtype] > -1)
+        {
+            playlist_t * p_playlist = pl_Get( VLCIntf );
+            BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded( p_playlist, [[item identifier] UTF8String] );
+            if (!sd_loaded)
+            {
+                playlist_ServicesDiscoveryAdd( p_playlist, [[item identifier] UTF8String] );
+            }
+        }
 
-		[o_chosen_category_lbl setStringValue:title];
+		[o_chosen_category_lbl setStringValue:[item title]];
 	}
 	else {
 		[o_chosen_category_lbl setStringValue:@"(none)"];
diff --git a/modules/gui/macosx/MainWindowTitle.m b/modules/gui/macosx/MainWindowTitle.m
index d8800df..f200885 100644
--- a/modules/gui/macosx/MainWindowTitle.m
+++ b/modules/gui/macosx/MainWindowTitle.m
@@ -276,7 +276,7 @@
 /*****************************************************************************
  * VLCColorView
  *
- * since we are using a clear window color when using the black window 
+ * since we are using a clear window color when using the black window
  * style, some filling is needed behind the video and some other elements
  *****************************************************************************/
 
diff --git a/modules/gui/macosx/PXSourceList.m b/modules/gui/macosx/PXSourceList.m
index 20a591a..58192ad 100644
--- a/modules/gui/macosx/PXSourceList.m
+++ b/modules/gui/macosx/PXSourceList.m
@@ -9,6 +9,7 @@
 //
 
 #import "PXSourceList.h"
+#import "SideBarItem.h"
 
 //Layout constants
 #define MIN_BADGE_WIDTH							22.0		//The minimum badge width for each item (default 22.0)
@@ -610,7 +611,10 @@ NSString * const PXSLDeleteKeyPressedOnRowsNotification = @"PXSourceListDeleteKe
 		NSPoint clickPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
 		NSInteger row = [self rowAtPoint:clickPoint];
 		id clickedItem = [self itemAtRow:row];
-		m = [_secondaryDelegate sourceList:self menuForEvent:theEvent item:clickedItem];
+        if ([clickedItem sdtype] > 0)
+            m = [_secondaryDelegate sourceList:self menuForEvent:theEvent item:clickedItem];
+        else
+            m = [super menuForEvent:theEvent];
 	}
 	if (m == nil) {
 		m = [super menuForEvent:theEvent];
diff --git a/modules/gui/macosx/SideBarItem.h b/modules/gui/macosx/SideBarItem.h
index 91d7b78..acb403b 100644
--- a/modules/gui/macosx/SideBarItem.h
+++ b/modules/gui/macosx/SideBarItem.h
@@ -32,6 +32,7 @@
 	NSString *identifier;
 	NSImage *icon;
 	NSInteger badgeValue;
+    NSInteger sdtype;
 
 	NSArray *children;
 }
@@ -40,6 +41,7 @@
 @property (nonatomic, copy) NSString *identifier;
 @property (nonatomic, retain) NSImage *icon;
 @property NSInteger badgeValue;
+ at property NSInteger sdtype;
 
 @property (nonatomic, copy) NSArray *children;
 
diff --git a/modules/gui/macosx/SideBarItem.m b/modules/gui/macosx/SideBarItem.m
index b646d84..859031f 100644
--- a/modules/gui/macosx/SideBarItem.m
+++ b/modules/gui/macosx/SideBarItem.m
@@ -20,6 +20,7 @@
 @synthesize icon;
 @synthesize badgeValue;
 @synthesize children;
+ at synthesize sdtype;
 
 #pragma mark -
 #pragma mark Init/Dealloc/Finalize
@@ -29,6 +30,7 @@
 	if(self=[super init])
 	{
 		badgeValue = -1;	//We don't want a badge value by default
+        sdtype = -1; //no sd type set
 	}
 
 	return self;
diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index f09f19b..ea7a97b 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -520,6 +520,7 @@
     [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
 
     [self outlineViewSelectionDidChange: nil];
+    [[VLCMain sharedInstance] updateMainWindow];
 }
 
 - (void)outlineViewSelectionDidChange:(NSNotification *)notification



More information about the vlc-commits mailing list