[vlc-devel] commit: macosx: Use input_ItemHasErrorWhenReading to display a small icon if there was an error when reading . This allow us not to display the message panel each time we have an error when reading . (Pierre d'Herbemont )

git version control git at videolan.org
Fri Aug 1 22:50:11 CEST 2008


vlc | branch: master | Pierre d'Herbemont <pdherbemont at videolan.org> | Fri Aug  1 22:49:38 2008 +0200| [8a5d95d032dd1d3773858ece1d5efe2f970d6bab] | committer: Pierre d'Herbemont 

macosx: Use input_ItemHasErrorWhenReading to display a small icon if there was an error when reading. This allow us not to display the message panel each time we have an error when reading.

Regarding the new look, feel free to improve.

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

 .../Resources/English.lproj/MainMenu.nib/info.nib  |    5 +--
 .../English.lproj/MainMenu.nib/keyedobjects.nib    |  Bin 108951 -> 109218 bytes
 modules/gui/macosx/interaction.h                   |    3 -
 modules/gui/macosx/interaction.m                   |   46 +----------------
 modules/gui/macosx/misc.h                          |    9 +++
 modules/gui/macosx/misc.m                          |   53 ++++++++++++++++++++
 modules/gui/macosx/playlist.m                      |   48 ++++++++++-------
 7 files changed, 94 insertions(+), 70 deletions(-)

diff --git a/extras/package/macosx/Resources/English.lproj/MainMenu.nib/info.nib b/extras/package/macosx/Resources/English.lproj/MainMenu.nib/info.nib
index f71a769..624fd7a 100644
--- a/extras/package/macosx/Resources/English.lproj/MainMenu.nib/info.nib
+++ b/extras/package/macosx/Resources/English.lproj/MainMenu.nib/info.nib
@@ -10,10 +10,7 @@
 	<integer>5</integer>
 	<key>IBOpenObjects</key>
 	<array>
-		<integer>29</integer>
-		<integer>21</integer>
-		<integer>2417</integer>
-		<integer>915</integer>
+		<integer>2211</integer>
 	</array>
 	<key>IBSystem Version</key>
 	<string>9E17</string>
diff --git a/extras/package/macosx/Resources/English.lproj/MainMenu.nib/keyedobjects.nib b/extras/package/macosx/Resources/English.lproj/MainMenu.nib/keyedobjects.nib
index 4e79666..96a39ab 100644
Binary files a/extras/package/macosx/Resources/English.lproj/MainMenu.nib/keyedobjects.nib and b/extras/package/macosx/Resources/English.lproj/MainMenu.nib/keyedobjects.nib differ
diff --git a/modules/gui/macosx/interaction.h b/modules/gui/macosx/interaction.h
index 81bb98a..bde4bad 100644
--- a/modules/gui/macosx/interaction.h
+++ b/modules/gui/macosx/interaction.h
@@ -86,9 +86,6 @@
     NSMutableArray * o_errors;
     NSMutableArray * o_icons;
 
-    NSImage * warnIcon;
-    NSImage * errorIcon;
-
     BOOL nib_interact_errpanel_loaded;
 }
 - (IBAction)cleanupTable:(id)sender;
diff --git a/modules/gui/macosx/interaction.m b/modules/gui/macosx/interaction.m
index 4dd7fda..c62e36c 100644
--- a/modules/gui/macosx/interaction.m
+++ b/modules/gui/macosx/interaction.m
@@ -24,6 +24,7 @@
 
 #import "intf.h"
 #import "interaction.h"
+#import "misc.h"
 
 /* for the icons in our custom error panel */
 #import <ApplicationServices/ApplicationServices.h>
@@ -403,49 +404,11 @@
     o_errors = [[NSMutableArray alloc] init];
     o_icons = [[NSMutableArray alloc] init];
 
-    /* ugly Carbon stuff following...
-     * regrettably, you can't get the icons through clean Cocoa */
-
-    /* retrieve our error icon */
-    IconRef ourIconRef;
-    int returnValue;
-    returnValue = GetIconRef(kOnSystemDisk, 'macs', 'stop', &ourIconRef);
-    errorIcon = [[NSImage alloc] initWithSize:NSMakeSize(32,32)];
-    [errorIcon lockFocus];
-    CGRect rect = CGRectMake(0,0,32,32);
-    PlotIconRefInContext((CGContextRef)[[NSGraphicsContext currentContext]
-        graphicsPort],
-        &rect,
-        kAlignNone,
-        kTransformNone,
-        NULL /*inLabelColor*/,
-        kPlotIconRefNormalFlags,
-        (IconRef)ourIconRef);
-    [errorIcon unlockFocus];
-    returnValue = ReleaseIconRef(ourIconRef);
-
-    /* retrieve our caution icon */
-    returnValue = GetIconRef(kOnSystemDisk, 'macs', 'caut', &ourIconRef);
-    warnIcon = [[NSImage alloc] initWithSize:NSMakeSize(32,32)];
-    [warnIcon lockFocus];
-    PlotIconRefInContext((CGContextRef)[[NSGraphicsContext currentContext]
-        graphicsPort],
-        &rect,
-        kAlignNone,
-        kTransformNone,
-        NULL /*inLabelColor*/,
-        kPlotIconRefNormalFlags,
-        (IconRef)ourIconRef);
-    [warnIcon unlockFocus];
-    returnValue = ReleaseIconRef(ourIconRef);
-
     return self;
 }
 
 -(void)dealloc
 {
-    [errorIcon release];
-    [warnIcon release];
     [o_errors release];
     [o_icons release];
     [super dealloc];
@@ -471,10 +434,9 @@
     [o_errors addObject: ourError];
     [ourError release];
 
-    [o_icons addObject: errorIcon];
+    [o_icons addObject: [NSImage imageWithErrorIcon]];
 
     [o_error_table reloadData];
-    [self showPanel];
 }
 
 -(void)addWarning: (NSString *)o_warning withMsg:(NSString *)o_msg
@@ -492,11 +454,9 @@
     [o_errors addObject: ourWarning];
     [ourWarning release];
 
-    [o_icons addObject: warnIcon];
+    [o_icons addObject: [NSImage imageWithWarningIcon]];
  
     [o_error_table reloadData];
-
-    [self showPanel];
 }
 
 -(IBAction)cleanupTable:(id)sender
diff --git a/modules/gui/macosx/misc.h b/modules/gui/macosx/misc.h
index fe06daa..a27f87c 100644
--- a/modules/gui/macosx/misc.h
+++ b/modules/gui/macosx/misc.h
@@ -25,6 +25,15 @@
 #import <ApplicationServices/ApplicationServices.h>
 
 /*****************************************************************************
+ * NSImage (VLCAddition)
+ *****************************************************************************/
+
+ at interface NSImage (VLCAdditions)
++ (id)imageWithWarningIcon;
++ (id)imageWithErrorIcon;
+ at end
+
+/*****************************************************************************
  * NSAnimation (VLCAddition)
  *****************************************************************************/
 
diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m
index a4decce..3a033f8 100644
--- a/modules/gui/macosx/misc.m
+++ b/modules/gui/macosx/misc.m
@@ -31,6 +31,59 @@
 #import "controls.h"
 
 /*****************************************************************************
+ * NSImage (VLCAdditions)
+ *
+ *  Addition to NSImage
+ *****************************************************************************/
+ at implementation NSImage (VLCAdditions)
++ (id)imageWithSystemName:(int)name
+{
+    /* ugly Carbon stuff following...
+     * regrettably, you can't get the icons through clean Cocoa */
+
+    /* retrieve our error icon */
+    NSImage * icon;
+    IconRef ourIconRef;
+    int returnValue;
+    returnValue = GetIconRef(kOnSystemDisk, 'macs', name, &ourIconRef);
+    icon = [[[NSImage alloc] initWithSize:NSMakeSize(32,32)] autorelease];
+    [icon lockFocus];
+    CGRect rect = CGRectMake(0,0,32,32);
+    PlotIconRefInContext((CGContextRef)[[NSGraphicsContext currentContext]
+        graphicsPort],
+        &rect,
+        kAlignNone,
+        kTransformNone,
+        NULL /*inLabelColor*/,
+        kPlotIconRefNormalFlags,
+        (IconRef)ourIconRef);
+    [icon unlockFocus];
+    returnValue = ReleaseIconRef(ourIconRef);
+    return icon;
+}
+
++ (id)imageWithWarningIcon
+{
+    static NSImage * imageWithWarningIcon = nil;
+    if( !imageWithWarningIcon )
+    {
+        imageWithWarningIcon = [[[self class] imageWithSystemName:'caut'] retain];
+    }
+    return imageWithWarningIcon;
+}
+
++ (id)imageWithErrorIcon
+{
+    static NSImage * imageWithErrorIcon = nil;
+    if( !imageWithErrorIcon )
+    {
+        imageWithErrorIcon = [[[self class] imageWithSystemName:'stop'] retain];
+    }
+    return imageWithErrorIcon;
+}
+
+ at end
+/*****************************************************************************
  * NSAnimation (VLCAdditions)
  *
  *  Missing extension to NSAnimation
diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index a01e714..f9e6e8e 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -258,7 +258,7 @@
  
     attempted_reload = NO;
 
-    if( [[o_tc identifier] isEqualToString:@"1"] )
+    if( [[o_tc identifier] isEqualToString:@"name"] )
     {
         /* sanity check to prevent the NSString class from crashing */
         char *psz_title =  input_item_GetTitle( p_item->p_input );
@@ -269,36 +269,37 @@
         else
         {
             char *psz_name = input_item_GetName( p_item->p_input );
-            if( !EMPTY_STR( psz_name ) )
-            {
+            if( psz_name )
                 o_value = [NSString stringWithUTF8String: psz_name];
-            }
             free( psz_name );
         }
         free( psz_title );
     }
-    else
+    else if( [[o_tc identifier] isEqualToString:@"artist"] )
     {
         char *psz_artist = input_item_GetArtist( p_item->p_input );
-        if( [[o_tc identifier] isEqualToString:@"2"] && !EMPTY_STR( psz_artist ) )
-        {
+        if( psz_artist )
             o_value = [NSString stringWithUTF8String: psz_artist];
+        free( psz_artist );
+    }
+    else if( [[o_tc identifier] isEqualToString:@"duration"] )
+    {
+        char psz_duration[MSTRTIME_MAX_SIZE];
+        mtime_t dur = input_item_GetDuration( p_item->p_input );
+        if( dur != -1 )
+        {
+            secstotimestr( psz_duration, dur/1000000 );
+            o_value = [NSString stringWithUTF8String: psz_duration];
         }
-        else if( [[o_tc identifier] isEqualToString:@"3"] )
+        else
+            o_value = @"--:--";
+    }
+    else if( [[o_tc identifier] isEqualToString:@"status"] )
+    {
+        if( input_ItemHasErrorWhenReading( p_item->p_input ) )
         {
-            char psz_duration[MSTRTIME_MAX_SIZE];
-            mtime_t dur = input_item_GetDuration( p_item->p_input );
-            if( dur != -1 )
-            {
-                secstotimestr( psz_duration, dur/1000000 );
-                o_value = [NSString stringWithUTF8String: psz_duration];
-            }
-            else
-            {
-                o_value = @"--:--";
-            }
+            o_value = [NSImage imageWithWarningIcon];
         }
-        free( psz_artist );
     }
     return o_value;
 }
@@ -351,6 +352,13 @@
     return self;
 }
 
+- (void)dealloc
+{
+    [o_nodes_array release];
+    [o_items_array release];
+    [super dealloc];
+}
+
 - (void)awakeFromNib
 {
     playlist_t * p_playlist = pl_Yield( VLCIntf );




More information about the vlc-devel mailing list