Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

playlistinfo.m

00001 /*****************************************************************************
00002  r playlistinfo.m: MacOS X interface module
00003  *****************************************************************************
00004  * Copyright (C) 2002-2005 the VideoLAN team
00005  * $Id: playlistinfo.m 12560 2005-09-15 14:21:38Z hartman $
00006  *
00007  * Authors: Benjamin Pracht <bigben at videolan dot org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 
00028 #include "intf.h"
00029 #include "playlistinfo.h"
00030 #include "playlist.h"
00031 
00032 /*****************************************************************************
00033  * VLCPlaylistInfo Implementation
00034  *****************************************************************************/
00035 
00036 @implementation VLCInfo
00037 
00038 - (id)init
00039 {
00040     self = [super init];
00041 
00042     if( self != nil )
00043     {
00044         p_item = NULL;
00045     }
00046     return( self );
00047 }
00048 
00049 - (void)awakeFromNib
00050 {
00051     [o_info_window setExcludedFromWindowsMenu: TRUE];
00052 
00053     [o_info_window setTitle: _NS("Properties")];
00054     [o_uri_lbl setStringValue: _NS("URI")];
00055     [o_title_lbl setStringValue: _NS("Title")];
00056     [o_author_lbl setStringValue: _NS("Author")];
00057     [o_btn_ok setTitle: _NS("OK")];
00058     [o_btn_cancel setTitle: _NS("Cancel")];
00059 }
00060 
00061 - (IBAction)togglePlaylistInfoPanel:(id)sender
00062 {
00063     if( [o_info_window isVisible] )
00064     {
00065         [o_info_window orderOut: sender];
00066     }
00067     else
00068     {
00069         p_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
00070         [self initPanel:sender];
00071     }
00072 }
00073 
00074 - (IBAction)toggleInfoPanel:(id)sender
00075 {
00076     if( [o_info_window isVisible] )
00077     {
00078         [o_info_window orderOut: sender];
00079     }
00080     else
00081     {
00082         intf_thread_t * p_intf = VLCIntf;
00083         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00084                                           FIND_ANYWHERE );
00085 
00086         if( p_playlist )
00087         {
00088             p_item = p_playlist->status.p_item;
00089             vlc_object_release( p_playlist );
00090         }
00091         [self initPanel:sender];
00092     }
00093 }
00094 
00095 - (void)initPanel:(id)sender
00096 {
00097     char *psz_temp;
00098     vlc_mutex_lock( &p_item->input.lock );
00099 
00100     /*fill uri / title / author info */
00101     if( p_item->input.psz_uri )
00102     {
00103         [o_uri_txt setStringValue:
00104             ([NSString stringWithUTF8String:p_item->input.psz_uri] == nil ) ?
00105             [NSString stringWithCString:p_item->input.psz_uri] :
00106             [NSString stringWithUTF8String:p_item->input.psz_uri]];
00107     }
00108 
00109     if( p_item->input.psz_name )
00110     {
00111         [o_title_txt setStringValue:
00112             ([NSString stringWithUTF8String:p_item->input.psz_name] == nil ) ?
00113             [NSString stringWithCString:p_item->input.psz_name] :
00114             [NSString stringWithUTF8String:p_item->input.psz_name]];
00115     }
00116     vlc_mutex_unlock( &p_item->input.lock );
00117 
00118     psz_temp = vlc_input_item_GetInfo( &p_item->input, _("Meta-information"), _("Artist") );
00119 
00120     if( psz_temp )
00121     {
00122         [o_author_txt setStringValue: [NSString stringWithUTF8String: psz_temp]];
00123         free( psz_temp );
00124     }
00125 
00126     [[VLCInfoTreeItem rootItem] refresh];
00127     [o_outline_view reloadData];
00128 
00129     [o_info_window makeKeyAndOrderFront: sender];
00130 }
00131 
00132 - (IBAction)infoCancel:(id)sender
00133 {
00134     [o_info_window orderOut: self];
00135 }
00136 
00137 
00138 - (IBAction)infoOk:(id)sender
00139 {
00140     intf_thread_t * p_intf = VLCIntf;
00141     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00142                                           FIND_ANYWHERE );
00143     vlc_value_t val;
00144 
00145     if( [self isItemInPlaylist: p_item] )
00146     {
00147         vlc_mutex_lock( &p_item->input.lock );
00148 
00149         p_item->input.psz_uri = strdup( [[o_uri_txt stringValue] UTF8String] );
00150         p_item->input.psz_name = strdup( [[o_title_txt stringValue] UTF8String] );
00151         vlc_mutex_unlock( &p_item->input.lock );
00152         vlc_input_item_AddInfo( &p_item->input, _("Meta-information"), _("Artist"), [[o_author_txt stringValue] UTF8String]);
00153         
00154         val.b_bool = VLC_TRUE;
00155         var_Set( p_playlist, "intf-change", val );
00156     }
00157     vlc_object_release( p_playlist );
00158     [o_info_window orderOut: self];
00159 }
00160 
00161 - (playlist_item_t *)getItem
00162 {
00163     return p_item;
00164 }
00165 
00166 - (BOOL)isItemInPlaylist:(playlist_item_t *)p_local_item
00167 {
00168     intf_thread_t * p_intf = VLCIntf;
00169     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00170                                           FIND_ANYWHERE );
00171     int i;
00172 
00173     if( p_playlist == NULL )
00174     {
00175         return NO;
00176     }
00177 
00178     for( i = 0 ; i < p_playlist->i_size ; i++ )
00179     {
00180         if( p_playlist->pp_items[i] == p_local_item )
00181         {
00182             vlc_object_release( p_playlist );
00183             return YES;
00184         }
00185     }
00186     vlc_object_release( p_playlist );
00187     return NO;
00188 }
00189 
00190 @end
00191 
00192 @implementation VLCInfo (NSMenuValidation)
00193 
00194 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
00195 {
00196     BOOL bEnabled = TRUE;
00197 
00198     intf_thread_t * p_intf = VLCIntf;
00199     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
00200                                                        FIND_ANYWHERE );
00201 
00202     if( [[o_mi title] isEqualToString: _NS("Info")] )
00203     {
00204         if( p_input == NULL )
00205         {
00206             bEnabled = FALSE;
00207         }
00208     }
00209     if( p_input ) vlc_object_release( p_input );
00210 
00211     return( bEnabled );
00212 }
00213 
00214 @end
00215 
00216 @implementation VLCInfo (NSTableDataSource)
00217 
00218 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
00219 {
00220     return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
00221 }
00222 
00223 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
00224     return ([item numberOfChildren] > 0);
00225 }
00226 
00227 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
00228 {
00229     return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
00230 }
00231 
00232 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
00233 {
00234     if ([[tableColumn identifier] isEqualToString:@"0"])
00235     {
00236         return (item == nil) ? @"" : (id)[item getName];
00237     }
00238     else
00239     {
00240         return (item == nil) ? @"" : (id)[item getValue];
00241     }
00242 }
00243 
00244 
00245 @end
00246 
00247 @implementation VLCInfoTreeItem
00248 
00249 static VLCInfoTreeItem *o_root_item = nil;
00250 
00251 #define IsALeafNode ((id)-1)
00252 
00253 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
00254 {
00255     self = [super init];
00256 
00257     if( self != nil )
00258     {
00259         o_name = [o_item_name copy];
00260         o_value = [o_item_value copy];
00261         i_object_id = i_id;
00262         o_parent = o_parent_item;
00263         if( [[VLCMain sharedInstance] getInfo] != nil )
00264             p_item = [[[VLCMain sharedInstance] getInfo] getItem];
00265         else
00266             p_item = NULL;
00267     }
00268     return( self );
00269 }
00270 
00271 + (VLCInfoTreeItem *)rootItem {
00272     if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
00273     return o_root_item;
00274 }
00275 
00276 - (void)dealloc
00277 {
00278     if( o_children != IsALeafNode ) [o_children release];
00279     [o_name release];
00280     [super dealloc];
00281 }
00282 
00283 /* Creates and returns the array of children
00284  * Loads children incrementally */
00285 - (NSArray *)children
00286 {
00287     if (o_children == NULL)
00288     {
00289         int i;
00290 
00291         if( [[[VLCMain sharedInstance] getInfo] isItemInPlaylist: p_item] )
00292         {
00293             if( self == o_root_item )
00294             {
00295                 vlc_mutex_lock( &p_item->input.lock );
00296                 o_children = [[NSMutableArray alloc] initWithCapacity:
00297                                                 p_item->input.i_categories];
00298                 for (i = 0 ; i < p_item->input.i_categories ; i++)
00299                 {
00300                     [o_children addObject:[[VLCInfoTreeItem alloc]
00301                         initWithName: [NSString stringWithUTF8String:
00302                             p_item->input.pp_categories[i]->psz_name]
00303                         value: @""
00304                         ID: i
00305                         parent: self]];
00306                 }
00307                 vlc_mutex_unlock( &p_item->input.lock );
00308             }
00309             else if( o_parent == o_root_item )
00310             {
00311                 vlc_mutex_lock( &p_item->input.lock );
00312                 o_children = [[NSMutableArray alloc] initWithCapacity:
00313                     p_item->input.pp_categories[i_object_id]->i_infos];
00314 
00315                 for (i = 0 ; i < p_item->input.pp_categories[i_object_id]->i_infos ; i++)
00316                 {
00317                     [o_children addObject:[[VLCInfoTreeItem alloc]
00318                     initWithName: [NSString stringWithUTF8String:
00319                             p_item->input.pp_categories[i_object_id]->pp_infos[i]->psz_name]
00320                         value: [NSString stringWithUTF8String:
00321                             p_item->input.pp_categories[i_object_id]->pp_infos[i]->psz_value]
00322                         ID: i
00323                         parent: self]];
00324                 }
00325                 vlc_mutex_unlock( &p_item->input.lock );
00326             }
00327             else
00328             {
00329                 o_children = IsALeafNode;
00330             }
00331         }
00332     }
00333     return o_children;
00334 }
00335 
00336 - (NSString *)getName
00337 {
00338     return o_name;
00339 }
00340 
00341 - (NSString *)getValue
00342 {
00343     return o_value;
00344 }
00345 
00346 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
00347     return [[self children] objectAtIndex:i_index];
00348 }
00349 
00350 - (int)numberOfChildren {
00351     id i_tmp = [self children];
00352     return ( i_tmp == IsALeafNode ) ? (-1) : (int)[i_tmp count];
00353 }
00354 
00355 /*- (int)selectedPlaylistItem
00356 {
00357     return i_item;
00358 }
00359 */
00360 - (void)refresh
00361 {
00362     p_item = [[[VLCMain sharedInstance] getInfo] getItem];
00363     if( o_children != NULL )
00364     {
00365         [o_children release];
00366         o_children = NULL;
00367     }
00368 }
00369 
00370 @end
00371 

Generated on Tue Dec 20 10:14:38 2005 for vlc-0.8.4a by  doxygen 1.4.2