]> git.sesse.net Git - vlc/blob - modules/gui/macosx/ConvertAndSave.m
f2e9fba58dfd45dc64172d2ed4fb9df009ed800d
[vlc] / modules / gui / macosx / ConvertAndSave.m
1 /*****************************************************************************
2  * ConvertAndSave.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2012 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import "ConvertAndSave.h"
25 #import "intf.h"
26 #import "playlist.h"
27 #import <vlc_common.h>
28 #import <vlc_url.h>
29
30 /* mini doc:
31  * the used NSMatrix includes a bunch of cells referenced most easily by tags. There you go: */
32 #define MPEGTS 0
33 #define WEBM 1
34 #define OGG 2
35 #define MP4 3
36 #define MPEGPS 4
37 #define MJPEG 5
38 #define WAV 6
39 #define FLV 7
40 #define MPEG1 8
41 #define MKV 9
42 #define RAW 10
43 #define AVI 11
44 #define ASF 12
45 /* 13-15 are present, but not set */
46
47 @interface VLCConvertAndSave (Internal)
48 - (void)updateDropView;
49 - (void)updateOKButton;
50 - (void)resetCustomizationSheetBasedOnProfile:(NSString *)profileString;
51 - (void)selectCellByEncapsulationFormat:(NSString *)format;
52 - (NSString *)currentEncapsulationFormatAsFileExtension:(BOOL)b_extension;
53 - (NSString *)composedOptions;
54 - (void)updateCurrentProfile;
55 - (void)storeProfilesOnDisk;
56 - (void)recreateProfilePopup;
57 @end
58
59 @implementation VLCConvertAndSave
60
61 @synthesize MRL=_MRL, outputDestination=_outputDestination, profileNames=_profileNames, profileValueList=_profileValueList, currentProfile=_currentProfile;
62
63 static VLCConvertAndSave *_o_sharedInstance = nil;
64
65 #pragma mark -
66 #pragma mark Initialization
67
68 + (void)initialize{
69     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
70
71     /* We are using the same format as the Qt4 intf here:
72      * Container(string), transcode video(bool), transcode audio(bool),
73      * use subtitles(bool), video codec(string), video bitrate(integer),
74      * scale(float), fps(float), width(integer, height(integer),
75      * audio codec(string), audio bitrate(integer), channels(integer),
76      * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */
77     NSArray * defaultProfiles = [[NSArray alloc] initWithObjects:
78                                  @"mp4;1;1;0;h264;0;0;0;0;0;mpga;128;2;44100;0;1",
79                                  @"webm;1;1;0;VP80;2000;0;0;0;0;vorb;128;2;44100;0;1",
80                                  @"ts;1;1;0;h264;800;1;0;0;0;mpga;128;2;44100;0;0",
81                                  @"ts;1;1;0;drac;800;1;0;0;0;mpga;128;2;44100;0;0",
82                                  @"ogg;1;1;0;theo;800;1;0;0;0;vorb;128;2;44100;0;0",
83                                  @"ogg;1;1;0;theo;800;1;0;0;0;flac;128;2;44100;0;0",
84                                  @"ts;1;1;0;mp2v;800;1;0;0;0;mpga;128;2;44100;0;0",
85                                  @"asf;1;1;0;WMV2;800;1;0;0;0;wma2;128;2;44100;0;0",
86                                  @"asf;1;1;0;DIV3;800;1;0;0;0;mp3;128;2;44100;0;0",
87                                  @"ogg;1;1;0;none;800;1;0;0;0;vorb;128;2;44100;none;0",
88                                  @"raw;1;1;0;none;800;1;0;0;0;mp3;128;2;44100;none;0",
89                                  @"mp4;1;1;0;none;800;1;0;0;0;mpga;128;2;44100;none;0",
90                                  @"raw;1;1;0;none;800;1;0;0;0;flac;128;2;44100;none;0",
91                                  @"wav;1;1;0;none;800;1;0;0;0;s16l;128;2;44100;none;0", nil];
92
93     NSArray * defaultProfileNames = [[NSArray alloc] initWithObjects:
94                                      @"Video - H.264 + MP3 (MP4)",
95                                      @"Video - VP80 + Vorbis (Webm)",
96                                      @"Video - H.264 + MP3 (TS)",
97                                      @"Video - Dirac + MP3 (TS)",
98                                      @"Video - Theora + Vorbis (OGG)",
99                                      @"Video - Theora + Flac (OGG)",
100                                      @"Video - MPEG-2 + MPGA (TS)",
101                                      @"Video - WMV + WMA (ASF)",
102                                      @"Video - DIV3 + MP3 (ASF)",
103                                      @"Audio - Vorbis (OGG)",
104                                      @"Audio - MP3",
105                                      @"Audio - MP3 (MP4)",
106                                      @"Audio - FLAC",
107                                      @"Audio - CD",
108                                      nil];
109
110     NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:defaultProfiles, @"CASProfiles", defaultProfileNames, @"CASProfileNames", nil];
111
112     [defaults registerDefaults:appDefaults];
113     [defaultProfiles release];
114     [defaultProfileNames release];
115 }
116
117 + (VLCConvertAndSave *)sharedInstance
118 {
119     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
120 }
121
122 - (id)init
123 {
124     if (_o_sharedInstance) {
125         [self dealloc];
126     } else {
127         _o_sharedInstance = [super init];
128     }
129
130     return _o_sharedInstance;
131 }
132
133 - (void)dealloc
134 {
135     if (_currentProfile)
136         [_currentProfile release];
137
138     [_profileNames release];
139     [_profileValueList release];
140     [_videoCodecs release];
141     [_audioCodecs release];
142     [_subsCodecs release];
143
144     [super dealloc];
145 }
146
147 - (void)awakeFromNib
148 {
149     [_window setTitle: _NS("Convert & Save")];
150     [_ok_btn setTitle: _NS("Save")];
151     [_drop_lbl setStringValue: _NS("Drop media here")];
152     [_drop_btn setTitle: _NS("Open media...")];
153     [_profile_lbl setStringValue: _NS("Choose Profile")];
154     [_profile_btn setTitle: _NS("Customize...")];
155     [_destination_lbl setStringValue: _NS("Choose Destination")];
156     [_destination_filename_stub_lbl setStringValue: _NS("Choose an output location")];
157     [_destination_filename_lbl setHidden: YES];
158     [_destination_browse_btn setTitle:_NS("Browse...")];
159     [_destination_stream_btn setTitle:_NS("Setup Streaming...")];
160     [_destination_stream_lbl setStringValue:@"Select Streaming Method"];
161     [_destination_itwantafile_btn setTitle:_NS("Save as File")];
162     [_destination_itwantastream_btn setTitle:_NS("Stream")];
163     [_destination_cancel_btn setHidden:YES];
164     [_customize_ok_btn setTitle: _NS("Apply")];
165     [_customize_cancel_btn setTitle: _NS("Cancel")];
166     [_customize_newProfile_btn setTitle: _NS("Save as new Profile...")];
167     [[_customize_tabview tabViewItemAtIndex:0] setLabel: _NS("Encapsulation")];
168     [[_customize_tabview tabViewItemAtIndex:1] setLabel: _NS("Video codec")];
169     [[_customize_tabview tabViewItemAtIndex:2] setLabel: _NS("Audio codec")];
170     [[_customize_tabview tabViewItemAtIndex:3] setLabel: _NS("Subtitles")];
171     [_customize_tabview selectTabViewItemAtIndex: 0];
172     [_customize_vid_ckb setTitle: _NS("Video")];
173     [_customize_vid_keep_ckb setTitle: _NS("Keep original video track")];
174     [_customize_vid_codec_lbl setStringValue: _NS("Codec")];
175     [_customize_vid_bitrate_lbl setStringValue: _NS("Bitrate")];
176     [_customize_vid_framerate_lbl setStringValue: _NS("Frame Rate")];
177     [_customize_vid_res_box setTitle: _NS("Resolution")];
178     [_customize_vid_res_lbl setStringValue: _NS("You just need to fill one of the three following parameters, VLC will autodetect the other using the original aspect ratio")];
179     [_customize_vid_width_lbl setStringValue: _NS("Width")];
180     [_customize_vid_height_lbl setStringValue: _NS("Height")];
181     [_customize_vid_scale_lbl setStringValue: _NS("Scale")];
182     [_customize_aud_ckb setTitle: _NS("Audio")];
183     [_customize_aud_keep_ckb setTitle: _NS("Keep original audio track")];
184     [_customize_aud_codec_lbl setStringValue: _NS("Codec")];
185     [_customize_aud_bitrate_lbl setStringValue: _NS("Bitrate")];
186     [_customize_aud_channels_lbl setStringValue: _NS("Channels")];
187     [_customize_aud_samplerate_lbl setStringValue: _NS("Sample Rate")];
188     [_customize_subs_ckb setTitle: _NS("Subtitles")];
189     [_customize_subs_overlay_ckb setTitle: _NS("Overlay subtitles on the video")];
190     [_stream_ok_btn setTitle:_NS("Close")];
191     [_stream_destination_lbl setStringValue:_NS("Stream Destination")];
192     [_stream_announcement_lbl setStringValue:_NS("Stream Announcement")];
193     [_stream_type_lbl setStringValue:_NS("Type")];
194     [_stream_address_lbl setStringValue:_NS("Address")];
195     [_stream_ttl_lbl setStringValue:_NS("TTL")];
196     [_stream_ttl_fld setEnabled:NO];
197     [_stream_ttl_stepper setEnabled:NO];
198     [_stream_port_lbl setStringValue:_NS("Port")];
199     [_stream_sap_ckb setStringValue:_NS("SAP Announcement")];
200     [_stream_http_ckb setStringValue:_NS("HTTP Announcement")];
201     [_stream_rtsp_ckb setStringValue:_NS("RTSP Announcement")];
202     [_stream_sdp_ckb setStringValue:_NS("Export SDP as file")];
203     [_stream_sap_ckb setState:NSOffState];
204     [_stream_http_ckb setState:NSOffState];
205     [_stream_rtsp_ckb setState:NSOffState];
206     [_stream_sdp_ckb setState:NSOffState];
207
208     /* there is no way to hide single cells, so replace the existing ones with empty cells.. */
209     id blankCell = [[[NSCell alloc] init] autorelease];
210     [blankCell setEnabled:NO];
211     [_customize_encap_matrix putCell:blankCell atRow:3 column:1];
212     [_customize_encap_matrix putCell:blankCell atRow:3 column:2];
213     [_customize_encap_matrix putCell:blankCell atRow:3 column:3];
214
215     /* fetch profiles from defaults */
216     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
217     [self setProfileValueList: [defaults arrayForKey:@"CASProfiles"]];
218     [self setProfileNames: [defaults arrayForKey:@"CASProfileNames"]];
219     [self recreateProfilePopup];
220
221     _videoCodecs = [[NSArray alloc] initWithObjects:
222                     [NSArray arrayWithObjects:@"MPEG-1", @"MPEG-2", @"MPEG-4", @"DIVX 1", @"DIVX 2", @"DIVX 3", @"H.263", @"H.264", @"VP8", @"WMV1", @"WMV2", @"M-JPEG", @"Theora", @"Dirac", nil],
223                     [NSArray arrayWithObjects:@"mpgv", @"mp2v", @"mp4v", @"DIV1", @"DIV2", @"DIV3", @"H263", @"h264", @"VP80", @"WMV1", @"WMV2", @"MJPG", @"theo", @"drac", nil],
224                     nil];
225     _audioCodecs = [[NSArray alloc] initWithObjects:
226                     [NSArray arrayWithObjects:@"MPEG Audio", @"MP3", @"MPEG 4 Audio (AAC)", @"A52/AC-3", @"Vorbis", @"Flac", @"Speex", @"WAV", @"WMA2", nil],
227                     [NSArray arrayWithObjects:@"mpga", @"mp3", @"mp4a", @"a52", @"vorb", @"flac", @"spx", @"s16l", @"wma2", nil],
228                     nil];
229     _subsCodecs = [[NSArray alloc] initWithObjects:
230                    [NSArray arrayWithObjects:@"DVB subtitle", @"T.140", nil],
231                    [NSArray arrayWithObjects:@"dvbs", @"t140", nil],
232                    nil];
233
234     [_customize_vid_codec_pop removeAllItems];
235     [_customize_vid_scale_pop removeAllItems];
236     [_customize_aud_codec_pop removeAllItems];
237     [_customize_aud_samplerate_pop removeAllItems];
238     [_customize_subs_pop removeAllItems];
239
240     [_customize_vid_codec_pop addItemsWithTitles:[_videoCodecs objectAtIndex:0]];
241     [_customize_aud_codec_pop addItemsWithTitles:[_audioCodecs objectAtIndex:0]];
242     [_customize_subs_pop addItemsWithTitles:[_subsCodecs objectAtIndex:0]];
243
244     [_customize_aud_samplerate_pop addItemWithTitle:@"8000"];
245     [_customize_aud_samplerate_pop addItemWithTitle:@"11025"];
246     [_customize_aud_samplerate_pop addItemWithTitle:@"22050"];
247     [_customize_aud_samplerate_pop addItemWithTitle:@"44100"];
248     [_customize_aud_samplerate_pop addItemWithTitle:@"48000"];
249
250     [_customize_vid_scale_pop addItemWithTitle:@"1"];
251     [_customize_vid_scale_pop addItemWithTitle:@"0.25"];
252     [_customize_vid_scale_pop addItemWithTitle:@"0.5"];
253     [_customize_vid_scale_pop addItemWithTitle:@"0.75"];
254     [_customize_vid_scale_pop addItemWithTitle:@"1.25"];
255     [_customize_vid_scale_pop addItemWithTitle:@"1.5"];
256     [_customize_vid_scale_pop addItemWithTitle:@"1.75"];
257     [_customize_vid_scale_pop addItemWithTitle:@"2"];
258
259     [_ok_btn setEnabled: NO];
260
261     [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:0]];
262 }
263
264 # pragma mark -
265 # pragma mark Code to Communicate with other objects
266
267 - (void)toggleWindow
268 {
269     [_window makeKeyAndOrderFront: nil];
270 }
271
272 # pragma mark -
273 # pragma mark User Interaction
274
275 - (IBAction)finalizePanel:(id)sender
276 {
277     playlist_t * p_playlist = pl_Get(VLCIntf);
278
279     input_item_t *p_input = input_item_New([_MRL UTF8String], [[_dropin_media_lbl stringValue] UTF8String]);
280     if (!p_input)
281         return;
282
283     input_item_AddOption(p_input, [[self composedOptions] UTF8String], VLC_INPUT_OPTION_TRUSTED);
284
285     int returnValue;
286     returnValue = playlist_AddInput(p_playlist, p_input, PLAYLIST_STOP, PLAYLIST_END, true, pl_Unlocked);
287
288     if (returnValue == VLC_SUCCESS) {
289         /* let's "play" */
290         PL_LOCK;
291         playlist_item_t *p_item = playlist_ItemGetByInput(p_playlist, p_input);
292         playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, NULL,
293                          p_item);
294         PL_UNLOCK;
295     }
296     else
297         msg_Err(VLCIntf, "CAS: playlist add input failed :(");
298
299     /* we're done with this input */
300     vlc_gc_decref(p_input);
301
302     [_window performClose:sender];
303 }
304
305 - (IBAction)openMedia:(id)sender
306 {
307     /* preliminary implementation until the open panel is cleaned up */
308     NSOpenPanel * openPanel = [NSOpenPanel openPanel];
309     [openPanel setCanChooseDirectories:NO];
310     [openPanel setResolvesAliases:YES];
311     [openPanel setAllowsMultipleSelection:NO];
312     [openPanel beginSheetModalForWindow:_window completionHandler:^(NSInteger returnCode) {
313         if (returnCode == NSOKButton)
314         {
315             [self setMRL: [NSString stringWithUTF8String:vlc_path2uri([[[openPanel URL] path] UTF8String], NULL)]];
316             [self updateOKButton];
317             [self updateDropView];
318         }
319     }];
320 }
321
322 - (IBAction)switchProfile:(id)sender
323 {
324     NSUInteger index = [_profile_pop indexOfSelectedItem];
325     if (index < ([self.profileValueList count] - 1))
326         [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:index]];
327 }
328
329 - (IBAction)customizeProfile:(id)sender
330 {
331     [NSApp beginSheet:_customize_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil];
332 }
333
334 - (IBAction)closeCustomizationSheet:(id)sender
335 {
336     [_customize_panel orderOut:sender];
337     [NSApp endSheet: _customize_panel];
338
339     if (sender == _customize_ok_btn)
340         [self updateCurrentProfile];
341 }
342
343 - (IBAction)newProfileAction:(id)sender
344 {
345     /* show panel */
346     VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance];
347     [panel setTitle: _NS("Save as new profile")];
348     [panel setSubTitle: _NS("Enter a name for the new profile:")];
349     [panel setCancelButtonLabel: _NS("Cancel")];
350     [panel setOKButtonLabel: _NS("Save")];
351     [panel setTarget:self];
352
353     [panel runModalForWindow:_customize_panel];
354 }
355
356 - (IBAction)deleteProfileAction:(id)sender
357 {
358     /* show panel */
359     VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance];
360     [panel setTitle:_NS("Remove a profile")];
361     [panel setSubTitle:_NS("Select the profile you would like to remove:")];
362     [panel setOKButtonLabel:_NS("Remove")];
363     [panel setCancelButtonLabel:_NS("Cancel")];
364     [panel setPopupButtonContent:self.profileNames];
365     [panel setTarget:self];
366
367     [panel runModalForWindow:_window];
368 }
369
370 - (IBAction)iWantAFile:(id)sender
371 {
372     NSRect boxFrame = [_destination_box frame];
373     NSRect subViewFrame = [_destination_itwantafile_view frame];
374     subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
375     subViewFrame.origin.y = ((boxFrame.size.height - subViewFrame.size.height) / 2) - 15.;
376     [_destination_itwantafile_view setFrame: subViewFrame];
377     [[_destination_itwantafile_btn animator] setHidden: YES];
378     [[_destination_itwantastream_btn animator] setHidden: YES];
379     [_destination_box performSelector:@selector(addSubview:) withObject:_destination_itwantafile_view afterDelay:0.2];
380     [[_destination_cancel_btn animator] setHidden:NO];
381     b_streaming = NO;
382     [_ok_btn setTitle:_NS("Save")];
383 }
384
385 - (IBAction)iWantAStream:(id)sender
386 {
387     NSRect boxFrame = [_destination_box frame];
388     NSRect subViewFrame = [_destination_itwantastream_view frame];
389     subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
390     subViewFrame.origin.y = ((boxFrame.size.height - subViewFrame.size.height) / 2) - 15.;
391     [_destination_itwantastream_view setFrame: subViewFrame];
392     [[_destination_itwantafile_btn animator] setHidden: YES];
393     [[_destination_itwantastream_btn animator] setHidden: YES];
394     [_destination_box performSelector:@selector(addSubview:) withObject:_destination_itwantastream_view afterDelay:0.2];
395     [[_destination_cancel_btn animator] setHidden:NO];
396     b_streaming = YES;
397     [_ok_btn setTitle:_NS("Stream")];
398 }
399
400 - (IBAction)cancelDestination:(id)sender
401 {
402     if ([_destination_itwantastream_view superview] != nil)
403         [_destination_itwantastream_view removeFromSuperview];
404     if ([_destination_itwantafile_view superview] != nil)
405         [_destination_itwantafile_view removeFromSuperview];
406
407     [_destination_cancel_btn setHidden:YES];
408     [[_destination_itwantafile_btn animator] setHidden: NO];
409     [[_destination_itwantastream_btn animator] setHidden: NO];
410     b_streaming = NO;
411 }
412
413 - (IBAction)browseFileDestination:(id)sender
414 {
415     NSSavePanel * saveFilePanel = [NSSavePanel savePanel];
416     [saveFilePanel setCanSelectHiddenExtension: YES];
417     [saveFilePanel setCanCreateDirectories: YES];
418     if ([[_customize_encap_matrix selectedCell] tag] != RAW) // there is no clever guess for this
419         [saveFilePanel setAllowedFileTypes:[NSArray arrayWithObject:[self currentEncapsulationFormatAsFileExtension:YES]]];
420     [saveFilePanel beginSheetModalForWindow:_window completionHandler:^(NSInteger returnCode) {
421         if (returnCode == NSOKButton) {
422             [self setOutputDestination:[[saveFilePanel URL] path]];
423             [_destination_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:_outputDestination]];
424             [[_destination_filename_stub_lbl animator] setHidden: YES];
425             [[_destination_filename_lbl animator] setHidden: NO];
426         } else {
427             [self setOutputDestination:@""];
428             [[_destination_filename_lbl animator] setHidden: YES];
429             [[_destination_filename_stub_lbl animator] setHidden: NO];
430         }
431         [self updateOKButton];
432     }];
433 }
434
435 - (IBAction)showStreamPanel:(id)sender
436 {
437     [NSApp beginSheet:_stream_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil];
438 }
439
440 - (IBAction)closeStreamPanel:(id)sender
441 {
442     /* provide a summary of the user selections */
443     NSMutableString * labelContent = [[NSMutableString alloc] initWithFormat:_NS("%@ stream to %@:%@"), [_stream_type_pop titleOfSelectedItem], [_stream_address_fld stringValue], [_stream_port_fld stringValue]];
444
445     if ([_stream_type_pop indexOfSelectedItem] > 1)
446         [labelContent appendFormat:@" (\"%@\")", [_stream_channel_fld stringValue]];
447
448     [_destination_stream_lbl setStringValue:labelContent];
449     [labelContent release];
450
451     /* catch obvious errors */
452     if (([_stream_http_ckb state] || [_stream_rtsp_ckb state] || [_stream_sap_ckb state]) && ![[_stream_channel_fld stringValue] length] > 0) {
453         NSBeginInformationalAlertSheet(_NS("No Channel Name given"),
454                                        _NS("OK"), @"", @"", _stream_panel, nil, nil, nil, nil,
455                                        @"%@", _NS("A stream announcement option is enabled. However, no channel name is provided."));
456         return;
457     }
458
459     if ([_stream_sdp_ckb state] && ![[_stream_sdp_fld stringValue] length] > 0) {
460         NSBeginInformationalAlertSheet(_NS("No SDP URL given"),
461                                        _NS("OK"), @"", @"", _stream_panel, nil, nil, nil, nil,
462                                        @"%@", _NS("A SDP export is requested, but no URL is provided."));
463         return;
464     }
465
466     NSString *tmpString = [_stream_address_fld stringValue];
467     if ([[tmpString componentsSeparatedByString:@":"] count] != 5 || [[tmpString componentsSeparatedByString:@"."] count] != 3 || ![tmpString isEqualToString:@"localhost"]) {
468         NSBeginInformationalAlertSheet(_NS("Invalid Output Destination"),
469                                        _NS("OK"), @"", @"", _stream_panel, nil, nil, nil, nil,
470                                        @"%@", _NS("The entered output destination IP does not appear to be legit."));
471         return;
472     }
473
474     /* store destination for further reference and update UI */
475     [self setOutputDestination: [_stream_address_fld stringValue]];
476     [self updateOKButton];
477
478     [_stream_panel orderOut:sender];
479     [NSApp endSheet: _stream_panel];
480 }
481
482 - (IBAction)streamTypeToggle:(id)sender
483 {
484     NSUInteger index = [_stream_type_pop indexOfSelectedItem];
485     if (index <= 1) { // HTTP, MMSH
486         [_stream_ttl_fld setEnabled:NO];
487         [_stream_ttl_stepper setEnabled:NO];
488         [_stream_sap_ckb setEnabled:NO];
489         [_stream_rtsp_ckb setEnabled:NO];
490         [_stream_http_ckb setEnabled:NO];
491         [_stream_sdp_ckb setEnabled:NO];
492     } else if (index == 2) { // RTP
493         [_stream_ttl_fld setEnabled:YES];
494         [_stream_ttl_stepper setEnabled:YES];
495         [_stream_sap_ckb setEnabled:YES];
496         [_stream_rtsp_ckb setEnabled:YES];
497         [_stream_http_ckb setEnabled:YES];
498         [_stream_sdp_ckb setEnabled:YES];
499     } else { // UDP
500         [_stream_ttl_fld setEnabled:YES];
501         [_stream_ttl_stepper setEnabled:YES];
502         [_stream_sap_ckb setEnabled:YES];
503         [_stream_rtsp_ckb setEnabled:NO];
504         [_stream_http_ckb setEnabled:NO];
505         [_stream_sdp_ckb setEnabled:NO];
506     }
507     [self streamAnnouncementToggle:sender];
508 }
509
510 - (IBAction)streamAnnouncementToggle:(id)sender
511 {
512     [_stream_channel_fld setEnabled:([_stream_http_ckb state] || [_stream_rtsp_ckb state] || [_stream_sap_ckb state]) && ([_stream_http_ckb isEnabled] || [_stream_rtsp_ckb isEnabled] || [_stream_sap_ckb isEnabled])];
513     [_stream_sdp_fld setEnabled:[_stream_sdp_ckb state]];
514 }
515
516 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
517 {
518     NSPasteboard *paste = [sender draggingPasteboard];
519     NSArray *types = [NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil];
520     NSString *desired_type = [paste availableTypeFromArray: types];
521     NSData *carried_data = [paste dataForType: desired_type];
522
523     if (carried_data) {
524         if ([desired_type isEqualToString:NSFilenamesPboardType]) {
525             NSArray *values = [[paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
526
527             if ([values count] > 0) {
528                 [self setMRL: [NSString stringWithUTF8String:vlc_path2uri([[values objectAtIndex:0] UTF8String], NULL)]];
529                 [self updateOKButton];
530                 [self updateDropView];
531                 return YES;
532             }
533         } else if ([desired_type isEqualToString:@"VLCPlaylistItemPboardType"]) {
534             NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
535             NSUInteger count = [array count];
536             if (count > 0) {
537                 playlist_t * p_playlist = pl_Get(VLCIntf);
538                 playlist_item_t * p_item = NULL;
539
540                 PL_LOCK;
541                 /* let's look for the first proper input item */
542                 for (NSUInteger x = 0; x < count; x++) {
543                     p_item = [[array objectAtIndex:x] pointerValue];
544                     if (p_item) {
545                         if (p_item->p_input) {
546                             if (p_item->p_input->psz_uri != nil) {
547                                 [self setMRL: [NSString stringWithFormat:@"%s", p_item->p_input->psz_uri]];
548                                 [self updateDropView];
549                                 [self updateOKButton];
550
551                                 PL_UNLOCK;
552
553                                 return YES;
554                             }
555                         }
556                     }
557                 }
558                 PL_UNLOCK;
559             }
560         }
561     }
562     return NO;
563 }
564
565 - (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
566 {
567     if (value == NSOKButton) {
568         if ([text length] > 0) {
569             /* prepare current data */
570             [self updateCurrentProfile];
571
572             /* add profile to arrays */
573             NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
574             [workArray addObject:text];
575             [self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
576             [workArray release];
577             workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
578             [workArray addObject:[[[NSArray alloc] initWithArray:self.currentProfile] autorelease]];
579             [self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
580             [workArray release];
581
582             /* update UI */
583             [self recreateProfilePopup];
584             [_profile_pop selectItemWithTitle:text];
585
586             /* update internals */
587             [self switchProfile:self];
588             [self storeProfilesOnDisk];
589         }
590     }
591 }
592
593 - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
594 {
595     if (value == NSOKButton) {
596         /* remove requested profile from the arrays */
597         NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
598         [workArray removeObjectAtIndex:item];
599         [self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
600         [workArray release];
601         workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
602         [workArray removeObjectAtIndex:item];
603         [self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
604         [workArray release];
605
606         /* update UI */
607         [_profile_pop removeAllItems];
608         [_profile_pop addItemsWithTitles:self.profileNames];
609         [_profile_pop addItemWithTitle:_NS("Custom")];
610         [[_profile_pop menu] addItem:[NSMenuItem separatorItem]];
611         [_profile_pop addItemWithTitle:_NS("Organize Profiles...")];
612         [[_profile_pop lastItem] setTarget: self];
613         [[_profile_pop lastItem] setAction: @selector(deleteProfileAction:)];
614
615         /* update internals */
616         [self switchProfile:self];
617         [self storeProfilesOnDisk];
618     }
619 }
620
621 # pragma mark -
622 # pragma mark Private Functionality
623 - (void)updateDropView
624 {
625     if ([_MRL length] > 0) {
626         NSString * path = [[NSURL URLWithString:_MRL] path];
627         [_dropin_media_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: path]];
628         NSImage * image = [[NSWorkspace sharedWorkspace] iconForFile: path];
629         [image setSize:NSMakeSize(128,128)];
630         [_dropin_icon_view setImage: image];
631
632         if (![_dropin_view superview]) {
633             NSRect boxFrame = [_drop_box frame];
634             NSRect subViewFrame = [_dropin_view frame];
635             subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
636             subViewFrame.origin.y = (boxFrame.size.height - subViewFrame.size.height) / 2;
637             [_dropin_view setFrame: subViewFrame];
638             [[_drop_image_view animator] setHidden: YES];
639             [_drop_box performSelector:@selector(addSubview:) withObject:_dropin_view afterDelay:0.6];
640         }
641     } else {
642         [_dropin_view removeFromSuperview];
643         [[_drop_image_view animator] setHidden: NO];
644     }
645 }
646
647 - (void)updateOKButton
648 {
649     if ([_outputDestination length] > 0 && [_MRL length] > 0)
650         [_ok_btn setEnabled: YES];
651     else
652         [_ok_btn setEnabled: NO];
653 }
654
655 - (void)resetCustomizationSheetBasedOnProfile:(NSString *)profileString
656 {
657     /* Container(string), transcode video(bool), transcode audio(bool),
658     * use subtitles(bool), video codec(string), video bitrate(integer),
659     * scale(float), fps(float), width(integer, height(integer),
660     * audio codec(string), audio bitrate(integer), channels(integer),
661     * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */
662
663     NSArray * components = [profileString componentsSeparatedByString:@";"];
664     if ([components count] != 16) {
665         msg_Err(VLCIntf, "CAS: the requested profile '%s' is invalid", [profileString UTF8String]);
666         return;
667     }
668
669     [self selectCellByEncapsulationFormat:[components objectAtIndex:0]];
670     [_customize_vid_ckb setState:[[components objectAtIndex:1] intValue]];
671     [_customize_aud_ckb setState:[[components objectAtIndex:2] intValue]];
672     [_customize_subs_ckb setState:[[components objectAtIndex:3] intValue]];
673     [_customize_vid_bitrate_fld setStringValue:[components objectAtIndex:5]];
674     [_customize_vid_scale_pop selectItemWithTitle:[components objectAtIndex:6]];
675     [_customize_vid_framerate_fld setStringValue:[components objectAtIndex:7]];
676     [_customize_vid_width_fld setStringValue:[components objectAtIndex:8]];
677     [_customize_vid_height_fld setStringValue:[components objectAtIndex:9]];
678     [_customize_aud_bitrate_fld setStringValue:[components objectAtIndex:11]];
679     [_customize_aud_channels_fld setStringValue:[components objectAtIndex:12]];
680     [_customize_aud_samplerate_pop selectItemWithTitle:[components objectAtIndex:13]];
681     [_customize_subs_overlay_ckb setState:[[components objectAtIndex:15] intValue]];
682
683     /* since there is no proper lookup mechanism in arrays, we need to implement a string specific one ourselves */
684     NSArray * tempArray = [_videoCodecs objectAtIndex:1];
685     NSUInteger count = [tempArray count];
686     NSString * searchString = [components objectAtIndex:4];
687     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"]) {
688         [_customize_vid_codec_pop selectItemAtIndex:-1];
689     } else {
690         for (NSUInteger x = 0; x < count; x++) {
691             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
692                 [_customize_vid_codec_pop selectItemAtIndex:x];
693                 break;
694             }
695         }
696     }
697
698     tempArray = [_audioCodecs objectAtIndex:1];
699     count = [tempArray count];
700     searchString = [components objectAtIndex:10];
701     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"]) {
702         [_customize_aud_codec_pop selectItemAtIndex:-1];
703     } else {
704         for (NSUInteger x = 0; x < count; x++) {
705             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
706                 [_customize_aud_codec_pop selectItemAtIndex:x];
707                 break;
708             }
709         }
710     }
711
712     tempArray = [_subsCodecs objectAtIndex:1];
713     count = [tempArray count];
714     searchString = [components objectAtIndex:14];
715     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"]) {
716         [_customize_subs_pop selectItemAtIndex:-1];
717     } else {
718         for (NSUInteger x = 0; x < count; x++) {
719             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
720                 [_customize_subs_pop selectItemAtIndex:x];
721                 break;
722             }
723         }
724     }
725
726     [self setCurrentProfile: [[[NSMutableArray alloc] initWithArray: [profileString componentsSeparatedByString:@";"]] autorelease]];
727 }
728
729 - (void)selectCellByEncapsulationFormat:(NSString *)format
730 {
731     if ([format isEqualToString:@"ts"])
732         [_customize_encap_matrix selectCellWithTag:MPEGTS];
733     else if ([format isEqualToString:@"webm"])
734         [_customize_encap_matrix selectCellWithTag:WEBM];
735     else if ([format isEqualToString:@"ogg"])
736         [_customize_encap_matrix selectCellWithTag:OGG];
737     else if ([format isEqualToString:@"ogm"])
738         [_customize_encap_matrix selectCellWithTag:OGG];
739     else if ([format isEqualToString:@"mp4"])
740         [_customize_encap_matrix selectCellWithTag:MP4];
741     else if ([format isEqualToString:@"mov"])
742         [_customize_encap_matrix selectCellWithTag:MP4];
743     else if ([format isEqualToString:@"ps"])
744         [_customize_encap_matrix selectCellWithTag:MPEGPS];
745     else if ([format isEqualToString:@"mpjpeg"])
746         [_customize_encap_matrix selectCellWithTag:MJPEG];
747     else if ([format isEqualToString:@"wav"])
748         [_customize_encap_matrix selectCellWithTag:WAV];
749     else if ([format isEqualToString:@"flv"])
750         [_customize_encap_matrix selectCellWithTag:FLV];
751     else if ([format isEqualToString:@"mpeg1"])
752         [_customize_encap_matrix selectCellWithTag:MPEG1];
753     else if ([format isEqualToString:@"mkv"])
754         [_customize_encap_matrix selectCellWithTag:MKV];
755     else if ([format isEqualToString:@"raw"])
756         [_customize_encap_matrix selectCellWithTag:RAW];
757     else if ([format isEqualToString:@"avi"])
758         [_customize_encap_matrix selectCellWithTag:AVI];
759     else if ([format isEqualToString:@"asf"])
760         [_customize_encap_matrix selectCellWithTag:ASF];
761     else if ([format isEqualToString:@"wmv"])
762         [_customize_encap_matrix selectCellWithTag:ASF];
763     else
764         msg_Err(VLCIntf, "CAS: unknown encap format requested for customization");
765 }
766
767 - (NSString *)currentEncapsulationFormatAsFileExtension:(BOOL)b_extension
768 {
769     NSUInteger cellTag = [[_customize_encap_matrix selectedCell] tag];
770     NSString * returnValue;
771     switch (cellTag) {
772         case MPEGTS:
773             returnValue = @"ts";
774             break;
775         case WEBM:
776             returnValue = @"webm";
777             break;
778         case OGG:
779             returnValue = @"ogg";
780             break;
781         case MP4:
782         {
783             if (b_extension)
784                 returnValue = @"m4v";
785             else
786                 returnValue = @"mp4";
787             break;
788         }
789         case MPEGPS:
790         {
791             if (b_extension)
792                 returnValue = @"mpg";
793             else
794                 returnValue = @"ps";
795             break;
796         }
797         case MJPEG:
798             returnValue = @"mjpeg";
799             break;
800         case WAV:
801             returnValue = @"wav";
802             break;
803         case FLV:
804             returnValue = @"flv";
805             break;
806         case MPEG1:
807         {
808             if (b_extension)
809                 returnValue = @"mpg";
810             else
811                 returnValue = @"mpeg1";
812             break;
813         }
814         case MKV:
815             returnValue = @"mkv";
816             break;
817         case RAW:
818             returnValue = @"raw";
819             break;
820         case AVI:
821             returnValue = @"avi";
822             break;
823         case ASF:
824             returnValue = @"asf";
825             break;
826
827         default:
828             returnValue = @"none";
829             break;
830     }
831
832     return returnValue;
833 }
834
835 - (NSString *)composedOptions
836 {
837     NSMutableString *composedOptions = [[NSMutableString alloc] initWithString:@":sout=#transcode{"];
838     if ([[self.currentProfile objectAtIndex:1] intValue]) {
839         // video is enabled
840         [composedOptions appendFormat:@"vcodec=%@", [self.currentProfile objectAtIndex:4]];
841         if (![[self.currentProfile objectAtIndex:4] isEqualToString:@"none"]) {
842             if ([[self.currentProfile objectAtIndex:5] intValue] > 0) // bitrate
843                 [composedOptions appendFormat:@",vb=%@", [self.currentProfile objectAtIndex:5]];
844             if ([[self.currentProfile objectAtIndex:6] floatValue] > 0.) // scale
845                 [composedOptions appendFormat:@",scale=%@", [self.currentProfile objectAtIndex:6]];
846             if ([[self.currentProfile objectAtIndex:7] floatValue] > 0.) // fps
847                 [composedOptions appendFormat:@",fps=%@", [self.currentProfile objectAtIndex:7]];
848             if ([[self.currentProfile objectAtIndex:8] intValue] > 0) // width
849                 [composedOptions appendFormat:@",width=%@", [self.currentProfile objectAtIndex:8]];
850             if ([[self.currentProfile objectAtIndex:9] intValue] > 0) // height
851                 [composedOptions appendFormat:@",height=%@", [self.currentProfile objectAtIndex:9]];
852         }
853     }
854     if ([[self.currentProfile objectAtIndex:2] intValue]) {
855         // audio is enabled
856
857         // add another comma in case video is enabled
858         if ([[self.currentProfile objectAtIndex:1] intValue])
859             [composedOptions appendString:@","];
860
861         [composedOptions appendFormat:@"acodec=%@", [self.currentProfile objectAtIndex:10]];
862         if (![[self.currentProfile objectAtIndex:10] isEqualToString:@"none"]) {
863             [composedOptions appendFormat:@",ab=%@", [self.currentProfile objectAtIndex:11]]; // bitrate
864             [composedOptions appendFormat:@",channels=%@", [self.currentProfile objectAtIndex:12]]; // channel number
865             [composedOptions appendFormat:@",samplerate=%@", [self.currentProfile objectAtIndex:13]]; // sample rate
866         }
867     }
868     if ([self.currentProfile objectAtIndex:3]) {
869         // subtitles enabled
870         [composedOptions appendFormat:@",scodec=%@", [self.currentProfile objectAtIndex:14]];
871         if ([[self.currentProfile objectAtIndex:15] intValue])
872             [composedOptions appendFormat:@",soverlay"];
873     }
874
875     // add muxer
876     [composedOptions appendFormat:@"}:standard{mux=%@", [self.currentProfile objectAtIndex:0]];
877
878     // add output destination (file only at this point)
879     [composedOptions appendFormat:@",dst=%@,access=file}", _outputDestination];
880
881     NSString * returnString = [NSString stringWithString:composedOptions];
882     [composedOptions release];
883
884     return returnString;
885 }
886
887 - (void)updateCurrentProfile
888 {
889     [self.currentProfile removeAllObjects];
890
891     NSInteger i;
892     [self.currentProfile addObject: [self currentEncapsulationFormatAsFileExtension:NO]];
893     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_vid_ckb state]]];
894     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_aud_ckb state]]];
895     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_subs_ckb state]]];
896     i = [_customize_vid_codec_pop indexOfSelectedItem];
897     if (i >= 0)
898         [self.currentProfile addObject: [[_videoCodecs objectAtIndex:1] objectAtIndex:i]];
899     else
900         [self.currentProfile addObject: @"none"];
901     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_bitrate_fld intValue]]];
902     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [[[_customize_vid_scale_pop selectedItem] title] intValue]]];
903     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_framerate_fld intValue]]];
904     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_width_fld intValue]]];
905     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_height_fld intValue]]];
906     i = [_customize_aud_codec_pop indexOfSelectedItem];
907     if (i >= 0)
908         [self.currentProfile addObject: [[_audioCodecs objectAtIndex:1] objectAtIndex:i]];
909     else
910         [self.currentProfile addObject: @"none"];
911     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_aud_bitrate_fld intValue]]];
912     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_aud_channels_fld intValue]]];
913     [self.currentProfile addObject: [[_customize_aud_samplerate_pop selectedItem] title]];
914     i = [_customize_subs_pop indexOfSelectedItem];
915     if (i >= 0)
916         [self.currentProfile addObject: [[_subsCodecs objectAtIndex:1] objectAtIndex:i]];
917     else
918         [self.currentProfile addObject: @"none"];
919     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_subs_overlay_ckb state]]];
920 }
921
922 - (void)storeProfilesOnDisk
923 {
924     NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
925     [defaults setObject:_profileNames forKey:@"CASProfileNames"];
926     [defaults setObject:_profileValueList forKey:@"CASProfiles"];
927     [defaults synchronize];
928 }
929
930 - (void)recreateProfilePopup
931 {
932     [_profile_pop removeAllItems];
933     [_profile_pop addItemsWithTitles:self.profileNames];
934     [_profile_pop addItemWithTitle:_NS("Custom")];
935     [[_profile_pop menu] addItem:[NSMenuItem separatorItem]];
936     [_profile_pop addItemWithTitle:_NS("Organize Profiles...")];
937     [[_profile_pop lastItem] setTarget: self];
938     [[_profile_pop lastItem] setAction: @selector(deleteProfileAction:)];
939 }
940
941 @end
942
943 # pragma mark -
944 # pragma mark Drag and drop handling
945
946 @implementation VLCDropEnabledBox
947
948 - (void)awakeFromNib
949 {
950     [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
951 }
952
953 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
954 {
955     b_activeDragAndDrop = YES;
956     [self setNeedsDisplay:YES];
957
958     [[NSCursor dragCopyCursor] set];
959
960     if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
961         return NSDragOperationGeneric;
962
963     return NSDragOperationNone;
964 }
965
966 - (void)draggingEnded:(id < NSDraggingInfo >)sender
967 {
968     [[NSCursor arrowCursor] set];
969     b_activeDragAndDrop = NO;
970     [self setNeedsDisplay:YES];
971 }
972
973 - (void)draggingExited:(id < NSDraggingInfo >)sender
974 {
975     [[NSCursor arrowCursor] set];
976     b_activeDragAndDrop = NO;
977     [self setNeedsDisplay:YES];
978 }
979
980 - (void)drawRect:(NSRect)dirtyRect
981 {
982     if (b_activeDragAndDrop) {
983         [[NSColor colorWithCalibratedRed:(.154/.255) green:(.154/.255) blue:(.154/.255) alpha:1.] setFill];
984         NSRect frameRect = [[self contentView] bounds];
985         frameRect.origin.x += 10;
986         frameRect.origin.y += 10;
987         frameRect.size.width -= 17;
988         frameRect.size.height -= 17;
989         NSFrameRectWithWidthUsingOperation(frameRect, 4., NSCompositeHighlight);
990     }
991
992     [super drawRect:dirtyRect];
993 }
994
995 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
996 {
997     return YES;
998 }
999
1000 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
1001 {
1002     return [[VLCConvertAndSave sharedInstance] performDragOperation: sender];
1003 }
1004
1005 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
1006 {
1007     [self setNeedsDisplay:YES];
1008 }
1009
1010 @end
1011
1012 @implementation VLCDropEnabledImageView
1013
1014 - (void)awakeFromNib
1015 {
1016     [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
1017 }
1018
1019 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
1020 {
1021     return [[[self superview] superview] draggingEntered:sender];
1022 }
1023
1024 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
1025 {
1026     return YES;
1027 }
1028
1029 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
1030 {
1031     return [[VLCConvertAndSave sharedInstance] performDragOperation: sender];
1032 }
1033
1034 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
1035 {
1036     [self setNeedsDisplay:YES];
1037 }
1038
1039 @end
1040
1041 @implementation VLCDropEnabledButton
1042
1043 - (void)awakeFromNib
1044 {
1045     [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
1046 }
1047
1048 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
1049 {
1050     return [[[self superview] superview] draggingEntered:sender];
1051 }
1052
1053 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
1054 {
1055     return YES;
1056 }
1057
1058 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
1059 {
1060     return [[VLCConvertAndSave sharedInstance] performDragOperation: sender];
1061 }
1062
1063 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
1064 {
1065     [self setNeedsDisplay:YES];
1066 }
1067
1068 @end