]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/playlistinfo.m
More l10n string fixes. Adds a FIXME to atmo.cpp, because that setting description...
[vlc] / modules / gui / macosx / playlistinfo.m
index 3bda2f7ba6cbcfa0e63e2babfbacbf0e30edbbc7..11d8b144aeddde844f53d0c9d8ac6c27f3a66c1f 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  r playlistinfo.m: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2002-2007 the VideoLAN team
+ * Copyright (C) 2002-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Benjamin Pracht <bigben at videolan dot org>
- *          Felix Kühne <fkuehne at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * 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
 
 @implementation VLCInfo
 
-- (id)init
+static VLCInfo *_o_sharedInstance = nil;
+
++ (VLCInfo *)sharedInstance
 {
-    self = [super init];
+    return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
+}
 
-    if( self != nil )
-    {
-        p_item = NULL;
-        o_statUpdateTimer = nil;
+- (id)init
+{
+    if( _o_sharedInstance ) {
+        [self dealloc];
+    } else {
+        _o_sharedInstance = [super init];
+        
+        if( _o_sharedInstance != nil )
+        {
+            p_item = NULL;
+            o_statUpdateTimer = nil;
+        }
     }
-    return( self );
+
+    return _o_sharedInstance;
 }
 
 - (void)awakeFromNib
 {
     [o_info_window setExcludedFromWindowsMenu: TRUE];
 
-    [o_info_window setTitle: _NS("Information")];
-    [o_uri_lbl setStringValue: _NS("URI")];
+    [o_info_window setTitle: _NS("Media Information")];
+    [o_uri_lbl setStringValue: _NS("Location")];
     [o_title_lbl setStringValue: _NS("Title")];
-    [o_author_lbl setStringValue: _NS("Author")];
-    [o_btn_ok setTitle: _NS("OK")];
-    [o_btn_cancel setTitle: _NS("Cancel")];
-    
+    [o_author_lbl setStringValue: _NS("Artist")];
+    [o_saveMetaData_btn setStringValue: _NS("Save Metadata" )];
+
     [[o_tab_view tabViewItemAtIndex: 0] setLabel: _NS("General")];
-    [[o_tab_view tabViewItemAtIndex: 1] setLabel: _NS("Advanced Information")];
+    [[o_tab_view tabViewItemAtIndex: 1] setLabel: _NS("Codec Details")];
     [[o_tab_view tabViewItemAtIndex: 2] setLabel: _NS("Statistics")];
     [o_tab_view selectTabViewItemAtIndex: 0];
 
     /* constants defined in vlc_meta.h */
     [o_genre_lbl setStringValue: _NS(VLC_META_GENRE)];
     [o_copyright_lbl setStringValue: _NS(VLC_META_COPYRIGHT)];
-    [o_collection_lbl setStringValue: _NS(VLC_META_COLLECTION)];
-    [o_seqNum_lbl setStringValue: _NS(VLC_META_SEQ_NUM)];
+    [o_collection_lbl setStringValue: _NS(VLC_META_ALBUM)];
+    [o_seqNum_lbl setStringValue: _NS(VLC_META_TRACK_NUMBER)];
     [o_description_lbl setStringValue: _NS(VLC_META_DESCRIPTION)];
-    [o_rating_lbl setStringValue: _NS(VLC_META_RATING)];
     [o_date_lbl setStringValue: _NS(VLC_META_DATE)];
     [o_language_lbl setStringValue: _NS(VLC_META_LANGUAGE)];
     [o_nowPlaying_lbl setStringValue: _NS(VLC_META_NOW_PLAYING)];
     [o_publisher_lbl setStringValue: _NS(VLC_META_PUBLISHER)];
-    
+
     /* statistics */
     [o_input_box setTitle: _NS("Input")];
     [o_read_bytes_lbl setStringValue: _NS("Read at media")];
     [o_input_bitrate_lbl setStringValue: _NS("Input bitrate")];
     [o_demux_bytes_lbl setStringValue: _NS("Demuxed")];
     [o_demux_bitrate_lbl setStringValue: _NS("Stream bitrate")];
-    
+
     [o_video_box setTitle: _NS("Video")];
     [o_video_decoded_lbl setStringValue: _NS("Decoded blocks")];
     [o_displayed_lbl setStringValue: _NS("Displayed frames")];
     [o_lost_frames_lbl setStringValue: _NS("Lost frames")];
-    
+       [o_fps_lbl setStringValue: _NS("Frames per Second")];
+
     [o_sout_box setTitle: _NS("Streaming")];
     [o_sent_packets_lbl setStringValue: _NS("Sent packets")];
     [o_sent_bytes_lbl setStringValue: _NS("Sent bytes")];
     [o_sent_bitrate_lbl setStringValue: _NS("Send rate")];
-    
+
     [o_audio_box setTitle: _NS("Audio")];
     [o_audio_decoded_lbl setStringValue: _NS("Decoded blocks")];
     [o_played_abuffers_lbl setStringValue: _NS("Played buffers")];
     [o_lost_abuffers_lbl setStringValue: _NS("Lost buffers")];
+
+    [o_info_window setInitialFirstResponder: o_uri_txt];
 }
 
 - (void)dealloc
     [super dealloc];
 }
 
-#if GC_ENABLED
-- (void)finalize
-{
-    /* since dealloc isn't called with enabled GC on 10.5, we need this to prevent core crashes */
-    if( [o_statUpdateTimer isValid] )
-        [o_statUpdateTimer invalidate];
-    [super finalize];
-}
-#endif
-    
-- (IBAction)togglePlaylistInfoPanel:(id)sender
-{
-    if( [o_info_window isVisible] )
-    {
-        [self windowShouldClose: nil];
-        [o_info_window orderOut: sender];
-    }
-    else
-    {
-        p_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
-        [self initPanel:sender];
-    }
-}
-
-- (IBAction)toggleInfoPanel:(id)sender
-{
-    if( [o_info_window isVisible] )
-    {
-        [self windowShouldClose: nil];
-        [o_info_window orderOut: sender];
-    }
-    else
-    {
-        intf_thread_t * p_intf = VLCIntf;
-        playlist_t * p_playlist = pl_Yield( p_intf );
-
-        p_item = p_playlist->status.p_item;
-        vlc_object_release( p_playlist );
-        
-        [self initPanel:sender];
-    }
-}
-
-- (void)initPanel:(id)sender
+- (void)initPanel
 {
     BOOL b_stats = config_GetInt(VLCIntf, "stats");
+    [self initMediaPanelStats];
     if( b_stats )
     {
         o_statUpdateTimer = [NSTimer scheduledTimerWithTimeInterval: 1
             target: self selector: @selector(updateStatistics:)
-            userInfo: nil repeats: YES]; 
+            userInfo: nil repeats: YES];
         [o_statUpdateTimer fire];
         [o_statUpdateTimer retain];
     }
     }
 
     [self updatePanel];
-    [o_info_window makeKeyAndOrderFront: sender];
+    [o_info_window makeKeyAndOrderFront: self];
+}
+
+- (void)initMediaPanelStats
+{
+    //Initializing Input Variables
+    [o_read_bytes_txt setStringValue: [NSString stringWithFormat:@"%8.0f kB", (float)0]];
+    [o_input_bitrate_txt setStringValue: [NSString stringWithFormat:@"%6.0f kb/s", (float)0]];
+    [o_demux_bytes_txt setStringValue: [NSString stringWithFormat:@"%8.0f kB", (float)0]];
+    [o_demux_bitrate_txt setStringValue: [NSString stringWithFormat:@"%6.0f kb/s", (float)0]];
+    
+    //Initializing Video Variables
+    [o_video_decoded_txt setIntValue:0];
+    [o_displayed_txt setIntValue:0];
+    [o_lost_frames_txt setIntValue:0];
+    [o_fps_txt setFloatValue:0];
+
+    //Initializing Output Variables
+    [o_sent_packets_txt setIntValue: 0];
+    [o_sent_bytes_txt setStringValue: [NSString stringWithFormat:@"%8.0f kB", (float)0]];
+    [o_sent_bitrate_txt setStringValue: [NSString stringWithFormat:@"%6.0f kb/s", (float)0]];
+
+    //Initializing Audio Variables
+    [o_audio_decoded_txt setIntValue:0];
+    [o_played_abuffers_txt setIntValue: 0];
+    [o_lost_abuffers_txt setIntValue: 0];
+
 }
 
 - (void)updatePanel
     if(! [self isItemInPlaylist: p_item] ) return;
 
     /* fill uri info */
-    char *psz_uri = input_item_GetURI( p_item->p_input );
-    if( psz_uri )
+    if( input_item_GetURI( p_item->p_input ) != NULL )
     {
-        [o_uri_txt setStringValue:
-            ([NSString stringWithUTF8String:psz_uri] == nil ) ?
-            [NSString stringWithCString:psz_uri] :
-            [NSString stringWithUTF8String:psz_uri]];
+        [o_uri_txt setStringValue: [NSString stringWithUTF8String: input_item_GetURI( p_item->p_input ) ]];
     }
-    free( psz_uri );
 
 #define SET( foo, bar ) \
     char *psz_##foo = input_item_Get##bar ( p_item->p_input ); \
-    [set setMeta: psz_##foo forlabel: o_##foo##_txt]; \
-    free( psz_foo );
+    [self setMeta: psz_##foo forLabel: o_##foo##_txt]; \
+    FREENULL( psz_##foo );
 
     /* fill the other fields */
     SET( title, Title );
     SET( seqNum, TrackNum );
     SET( genre, Genre );
     SET( copyright, Copyright );
-    SET( rating, Rating );
     SET( publisher, Publisher );
     SET( nowPlaying, NowPlaying );
     SET( language, Language );
     SET( date, Date );
+    SET( description, Description );
 
 #undef SET
 
+    char *psz_meta;
+    NSImage *o_image;
+    psz_meta = input_item_GetArtURL( p_item->p_input );
+    if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
+        o_image = [[NSImage alloc] initWithContentsOfURL: [NSURL URLWithString: [NSString stringWithUTF8String: psz_meta]]];
+    else
+        o_image = [[NSImage imageNamed: @"noart.png"] retain];
+    [o_image_well setImage: o_image];
+    [o_image release];
+    FREENULL( psz_meta );
+
     /* reload the advanced table */
     [[VLCInfoTreeItem rootItem] refresh];
     [o_outline_view reloadData];
 - (void)setMeta: (char *)psz_meta forLabel: (id)theItem
 {
     if( psz_meta != NULL && *psz_meta)
-        [theItem setStringValue: 
-            ([NSString stringWithUTF8String:psz_meta] == nil ) ? 
-            [NSString stringWithCString:psz_meta] :
-            [NSString stringWithUTF8String:psz_meta]];
+        [theItem setStringValue: [NSString stringWithUTF8String:psz_meta]];
     else
-        [theItem setStringValue: @"-"];
+        [theItem setStringValue: @""];
 }
 
 - (void)updateStatistics:(NSTimer*)theTimer
 {
     if( [self isItemInPlaylist: p_item] )
     {
-        /* we can only do that if there's a valid input around */
-
         vlc_mutex_lock( &p_item->p_input->p_stats->lock );
 
         /* input */
             @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_demux_bitrate)*8000]];
 
         /* Video */
-        [o_video_decoded_txt setStringValue: [NSString stringWithFormat: @"%5i",
-            p_item->p_input->p_stats->i_decoded_video]];
-        [o_displayed_txt setStringValue: [NSString stringWithFormat: @"%5i",
-            p_item->p_input->p_stats->i_displayed_pictures]];
-        [o_lost_frames_txt setStringValue: [NSString stringWithFormat: @"%5i",
-            p_item->p_input->p_stats->i_lost_pictures]];
+        [o_video_decoded_txt setIntValue: p_item->p_input->p_stats->i_decoded_video];
+        [o_displayed_txt setIntValue: p_item->p_input->p_stats->i_displayed_pictures];
+        [o_lost_frames_txt setIntValue: p_item->p_input->p_stats->i_lost_pictures];
+        float f_fps = 0;
+        /* FIXME: input_Control( p_item->p_input, INPUT_GET_VIDEO_FPS, &f_fps ); */
+        [o_fps_txt setFloatValue: f_fps];
 
         /* Sout */
-        [o_sent_packets_txt setStringValue: [NSString stringWithFormat: @"%5i",
-            p_item->p_input->p_stats->i_sent_packets]];
+        [o_sent_packets_txt setIntValue: p_item->p_input->p_stats->i_sent_packets];
         [o_sent_bytes_txt setStringValue: [NSString stringWithFormat: @"%8.0f kB",
             (float)(p_item->p_input->p_stats->i_sent_bytes)/1000]];
         [o_sent_bitrate_txt setStringValue: [NSString stringWithFormat:
             @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_send_bitrate*8)*1000]];
 
         /* Audio */
-        [o_audio_decoded_txt setStringValue: [NSString stringWithFormat: @"%5i",
-            p_item->p_input->p_stats->i_decoded_audio]];
-        [o_played_abuffers_txt setStringValue: [NSString stringWithFormat: @"%5i",
-            p_item->p_input->p_stats->i_played_abuffers]];
-        [o_lost_abuffers_txt setStringValue: [NSString stringWithFormat: @"%5i",
-            p_item->p_input->p_stats->i_lost_abuffers]];
+        [o_audio_decoded_txt setIntValue: p_item->p_input->p_stats->i_decoded_audio];
+        [o_played_abuffers_txt setIntValue: p_item->p_input->p_stats->i_played_abuffers];
+        [o_lost_abuffers_txt setIntValue: p_item->p_input->p_stats->i_lost_abuffers];
 
         vlc_mutex_unlock( &p_item->p_input->p_stats->lock );
     }
 }
 
-- (IBAction)infoCancel:(id)sender
+- (IBAction)metaFieldChanged:(id)sender
 {
-    [self windowShouldClose: nil];
-    [o_info_window orderOut: self];
+    [o_saveMetaData_btn setEnabled: YES];
 }
 
-
-- (IBAction)infoOk:(id)sender
+- (IBAction)saveMetaData:(id)sender
 {
     intf_thread_t * p_intf = VLCIntf;
     playlist_t * p_playlist = pl_Yield( p_intf );
 
     if( [self isItemInPlaylist: p_item] )
     {
-        input_item_SetName( p_item->p_input,
-                [[o_title_txt stringValue] UTF8String] );
-        input_item_SetURI( p_item->p_input,
-                [[o_uri_txt stringValue] UTF8String] );
-        input_item_SetArtist( p_item->p_input,
-                [[o_author_txt stringValue] UTF8String] );
-
-        val.b_bool = VLC_TRUE;
+        meta_export_t p_export;
+        p_export.p_item = p_item->p_input;
+
+        if( p_item->p_input == NULL )
+            goto end;
+
+        /* we can write meta data only in a file */
+        vlc_mutex_lock( &p_item->p_input->lock );
+        int i_type = p_item->p_input->i_type;
+        vlc_mutex_unlock( &p_item->p_input->lock );
+        if( i_type == ITEM_TYPE_FILE )
+        {
+            char *psz_uri_orig = input_item_GetURI( p_item->p_input );
+            char *psz_uri = psz_uri_orig;
+            if( !strncmp( psz_uri, "file://", 7 ) )
+                psz_uri += 7; /* strlen("file://") = 7 */
+            
+            p_export.psz_file = strndup( psz_uri, PATH_MAX );
+            free( psz_uri_orig );
+        }
+        else
+            goto end;
+
+        #define utf8( o_blub ) \
+            [[o_blub stringValue] UTF8String]
+
+        input_item_SetName( p_item->p_input, utf8( o_title_txt ) );
+        input_item_SetTitle( p_item->p_input, utf8( o_title_txt ) );
+        input_item_SetArtist( p_item->p_input, utf8( o_author_txt ) );
+        input_item_SetAlbum( p_item->p_input, utf8( o_collection_txt ) );
+        input_item_SetGenre( p_item->p_input, utf8( o_genre_txt ) );
+        input_item_SetTrackNum( p_item->p_input, utf8( o_seqNum_txt ) );
+        input_item_SetDate( p_item->p_input, utf8( o_date_txt ) );
+        input_item_SetCopyright( p_item->p_input, utf8( o_copyright_txt ) );
+        input_item_SetPublisher( p_item->p_input, utf8( o_publisher_txt ) );
+        input_item_SetDescription( p_item->p_input, utf8( o_description_txt ) );
+        input_item_SetLanguage( p_item->p_input, utf8( o_language_txt ) );
+
+        PL_LOCK;
+        p_playlist->p_private = &p_export;
+
+        module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
+        if( p_mod )
+            module_Unneed( p_playlist, p_mod );
+        PL_UNLOCK;
+
+        val.b_bool = true;
         var_Set( p_playlist, "intf-change", val );
+        [self updatePanel];
     }
+
+    end:
     vlc_object_release( p_playlist );
-    [self windowShouldClose: nil];
-    [o_info_window orderOut: self];
+    [o_saveMetaData_btn setEnabled: NO];
 }
 
 - (playlist_item_t *)getItem
@@ -479,7 +512,7 @@ static VLCInfoTreeItem *o_root_item = nil;
                     initWithName: [NSString stringWithUTF8String:
                             p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_name]
                         value: [NSString stringWithUTF8String:
-                            p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_value]
+                            p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_value ? : ""]
                         ID: i
                         parent: self]];
                 }
@@ -513,11 +546,6 @@ static VLCInfoTreeItem *o_root_item = nil;
     return ( i_tmp == IsALeafNode ) ? (-1) : (int)[i_tmp count];
 }
 
-/*- (int)selectedPlaylistItem
-{
-    return i_item;
-}
-*/
 - (void)refresh
 {
     p_item = [[[VLCMain sharedInstance] getInfo] getItem];