]> git.sesse.net Git - vlc/commitdiff
macosx: fixed enabling/disabling SDs through the sidebar
authorFelix Paul Kühne <fkuehne@videolan.org>
Sat, 14 Jan 2012 18:03:00 +0000 (19:03 +0100)
committerFelix Paul Kühne <fkuehne@videolan.org>
Sat, 14 Jan 2012 18:03:09 +0000 (19:03 +0100)
note that the playlist table remains to be fixed to show the current selection only

modules/gui/macosx/MainWindow.m
modules/gui/macosx/MainWindowTitle.m
modules/gui/macosx/PXSourceList.m
modules/gui/macosx/SideBarItem.h
modules/gui/macosx/SideBarItem.m
modules/gui/macosx/playlist.m

index ea804c267125a0dfbac62001695fe9c9282f69cd..a4500fc7fa279ce08013a6c2dc786aa3d9484c40 100644 (file)
@@ -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)"];
index d8800dfe9ac956382cea144e419f218b22986491..f20088532f5256b55fbbd4fbb65c96cd349f4c53 100644 (file)
 /*****************************************************************************
  * 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
  *****************************************************************************/
 
index 20a591a417a54455e0d431ac3f818a433f5221d3..58192adbc4fcaacf61e1b5802c7f11aec549fc7e 100644 (file)
@@ -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];
index 91d7b782e469e012113ea772cee9ae05043ae63e..acb403bd6ec8982fab783c02d621f82e30eb5ab0 100644 (file)
@@ -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;
+@property NSInteger sdtype;
 
 @property (nonatomic, copy) NSArray *children;
 
index b646d84efbaaa9a5000f80636a896e675d495065..859031f31c87f9d8acf5faa40cbc72e7286545cc 100644 (file)
@@ -20,6 +20,7 @@
 @synthesize icon;
 @synthesize badgeValue;
 @synthesize children;
+@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;
index f09f19be0701eea32821134c2cb900bf16032d62..ea7a97ba0695fe61eefb23d6c90c6b12773c181b 100644 (file)
     [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
 
     [self outlineViewSelectionDidChange: nil];
+    [[VLCMain sharedInstance] updateMainWindow];
 }
 
 - (void)outlineViewSelectionDidChange:(NSNotification *)notification