VLCPlaylistDataSource.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*****************************************************************************
  2. * VLCPlaylistDataSource.m: VLC.framework VLCPlaylistDataSource implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 VLC authors and VideoLAN
  6. * $Id$
  7. *
  8. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import <VLC/VLCPlaylistDataSource.h>
  25. #import "VLCEventManager.h"
  26. @implementation VLCPlaylistDataSource
  27. - (id)init
  28. {
  29. if (self = [super init])
  30. {
  31. playlist = nil;
  32. videoView = nil;
  33. }
  34. return self;
  35. }
  36. - (id)initWithPlaylist:(VLCPlaylist *)aPlaylist
  37. {
  38. if (self = [super init])
  39. {
  40. playlist = [aPlaylist retain];
  41. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(playlistDidChange:) name:VLCPlaylistItemAdded object:nil];
  42. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(itemDidAddSubitem:) name:VLCMediaSubItemAdded object:nil];
  43. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(itemDidChange:) name:VLCPlaylistItemChanged object:nil];
  44. videoView = nil;
  45. outlineView = nil;
  46. }
  47. return self;
  48. }
  49. - (id)initWithPlaylist:(VLCPlaylist *)aPlaylist videoView:(VLCVideoView *)aVideoView;
  50. {
  51. if (self = [super init])
  52. {
  53. playlist = [aPlaylist retain];
  54. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(playlistDidChange:) name:VLCPlaylistItemAdded object:nil];
  55. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(itemDidAddSubitem:) name:VLCMediaSubItemAdded object:nil];
  56. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(itemDidChange:) name:VLCPlaylistItemChanged object:nil];
  57. videoView = [aVideoView retain];
  58. /* Will be automatically set if an outline view ask us data,
  59. * be careful not to connect two outlineView to this object or this goes wrong. */
  60. outlineView = nil;
  61. }
  62. return self;
  63. }
  64. - (void)dealloc
  65. {
  66. [[NSNotificationCenter defaultCenter] removeObserver: self];
  67. if (playlist)
  68. [playlist release];
  69. if (videoView)
  70. [videoView release];
  71. [super dealloc];
  72. }
  73. - (VLCPlaylist *)playlist
  74. {
  75. return playlist;
  76. }
  77. - (VLCVideoView *)videoView
  78. {
  79. return videoView;
  80. }
  81. @end
  82. @implementation VLCPlaylistDataSource (OutlineViewDataSource)
  83. - (BOOL) outlineView: (NSOutlineView *)ov isItemExpandable: (id)item { return NO; }
  84. - (int) outlineView: (NSOutlineView *)ov numberOfChildrenOfItem:(id)item { return 0; }
  85. - (id) outlineView: (NSOutlineView *)ov child:(int)index ofItem:(id)item { return nil; }
  86. - (id) outlineView: (NSOutlineView *)ov objectValueForTableColumn:(NSTableColumn*)col byItem:(id)item { return nil; }
  87. @end
  88. @implementation VLCPlaylistDataSource (TableViewDropping)
  89. /* Dummy implementation cause we need them */
  90. - (int)numberOfRowsInTableView:(NSTableView *)aTableView { return 0; }
  91. - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {return nil;}
  92. - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
  93. {
  94. return NSDragOperationEvery; /* This is for now */
  95. }
  96. - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
  97. row:(int)row dropOperation:(NSTableViewDropOperation)operation
  98. {
  99. int i;
  100. NSArray * droppedItems = [[info draggingPasteboard] propertyListForType: NSFilenamesPboardType];
  101. for (i = 0; i < [droppedItems count]; i++)
  102. {
  103. NSString * filename = [droppedItems objectAtIndex:i];
  104. [[self playlist] insertMedia:[VLCMedia mediaWithURL:filename] atIndex:row+i];
  105. }
  106. }
  107. @end
  108. @interface NSObject (UnknownBindingsObject)
  109. /* OutlineViewDataSourceDropping and bindings hack */
  110. - (id)observedObject;
  111. @end
  112. @implementation VLCPlaylistDataSource (OutlineViewDataSourceDropping)
  113. - (BOOL)outlineView:(NSOutlineView *)aOutlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
  114. {
  115. NSArray * droppedItems = [[info draggingPasteboard] propertyListForType: NSFilenamesPboardType];
  116. VLCPlaylist * aPlaylist;
  117. int i;
  118. if (!item)
  119. item = [self playlist]; /* The root object is our playlist */
  120. else
  121. item = [item observedObject];
  122. if (![item isMemberOfClass:[VLCPlaylist class]])
  123. return NO;
  124. if (index < 0) /* No precise item given, put it as the first one */
  125. index = 0;
  126. aPlaylist = item;
  127. if (!droppedItems)
  128. {
  129. /* XXX: localization */
  130. NSRunCriticalAlertPanelRelativeToWindow(@"Error", @"Unable to drop the provided item.", @"OK", nil, nil, [outlineView window]);
  131. return NO;
  132. }
  133. for (i = 0; i < [droppedItems count]; i++)
  134. {
  135. NSString * filename = [droppedItems objectAtIndex:i];
  136. [aPlaylist insertMedia:[VLCMedia mediaWithURL:filename] atIndex:index+i];
  137. }
  138. return YES;
  139. }
  140. - (NSDragOperation)outlineView:(NSOutlineView *)aOutlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
  141. {
  142. return NSDragOperationEvery;
  143. }
  144. @end