[vlc-commits] [Git][videolan/vlc][master] macosx: Make search field in toolbar functional for library

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Jul 23 08:02:16 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
f9057380 by Claudio Cambra at 2022-07-23T07:50:29+00:00
macosx: Make search field in toolbar functional for library

Signed-off-by: Claudio Cambra <claudio.cambra at gmail.com>

- - - - -


7 changed files:

- modules/gui/macosx/UI/VLCLibraryWindow.xib
- modules/gui/macosx/library/VLCLibraryController.h
- modules/gui/macosx/library/VLCLibraryController.m
- modules/gui/macosx/library/VLCLibraryModel.h
- modules/gui/macosx/library/VLCLibraryModel.m
- modules/gui/macosx/library/VLCLibraryWindow.h
- modules/gui/macosx/library/VLCLibraryWindow.m


Changes:

=====================================
modules/gui/macosx/UI/VLCLibraryWindow.xib
=====================================
@@ -2,6 +2,7 @@
 <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
+        <capability name="Search Toolbar Item" minToolsVersion="12.0" minSystemVersion="11.0"/>
         <capability name="System colors introduced in macOS 10.14" minToolsVersion="10.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -596,22 +597,6 @@
                             </segmentedCell>
                         </segmentedControl>
                     </toolbarItem>
-                    <toolbarItem implicitItemIdentifier="9B15C9C0-73AC-4190-803C-5AF14952E903" label="Custom View" paletteLabel="Search Field" sizingBehavior="auto" id="hnO-hn-Ad3">
-                        <nil key="toolTip"/>
-                        <searchField key="view" wantsLayer="YES" verticalHuggingPriority="751" allowsCharacterPickerTouchBarItem="YES" textCompletion="NO" id="Uje-gs-XyH">
-                            <rect key="frame" x="0.0" y="14" width="96" height="22"/>
-                            <autoresizingMask key="autoresizingMask"/>
-                            <constraints>
-                                <constraint firstAttribute="height" constant="22" id="bdi-0E-ZYl"/>
-                                <constraint firstAttribute="width" constant="96" id="pdg-70-JyS"/>
-                            </constraints>
-                            <searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" id="hOD-ST-dRA">
-                                <font key="font" metaFont="message"/>
-                                <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
-                                <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                            </searchFieldCell>
-                        </searchField>
-                    </toolbarItem>
                     <toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="89f-AL-zuU"/>
                     <toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="hs0-cc-34q"/>
                     <toolbarItem implicitItemIdentifier="FCCB897D-45D4-411A-91BF-302620882C8C" label="smallCone" paletteLabel="Toolbar Cone" tag="-1" image="VLC" navigational="YES" id="L28-Xw-ydE">
@@ -632,6 +617,21 @@
                             </segmentedCell>
                         </segmentedControl>
                     </toolbarItem>
+                    <searchToolbarItem implicitItemIdentifier="A132890F-6B3D-4523-A71B-B00F095057C4" label="Search" paletteLabel="Search" visibilityPriority="1001" id="dv4-Il-y8X">
+                        <nil key="toolTip"/>
+                        <searchField key="view" verticalHuggingPriority="750" textCompletion="NO" id="ab6-kR-8Io">
+                            <rect key="frame" x="0.0" y="0.0" width="100" height="21"/>
+                            <autoresizingMask key="autoresizingMask"/>
+                            <searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" refusesFirstResponder="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" sendsSearchStringImmediately="YES" id="MW6-rQ-Qtr">
+                                <font key="font" metaFont="system"/>
+                                <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                                <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                            </searchFieldCell>
+                            <connections>
+                                <action selector="filterLibrary:" target="QvC-M9-y7g" id="VoD-A4-uwu"/>
+                            </connections>
+                        </searchField>
+                    </searchToolbarItem>
                 </allowedToolbarItems>
                 <defaultToolbarItems>
                     <toolbarItem reference="L28-Xw-ydE"/>
@@ -641,8 +641,8 @@
                     <toolbarItem reference="89f-AL-zuU"/>
                     <toolbarItem reference="KnW-Lr-R1d"/>
                     <toolbarItem reference="89f-AL-zuU"/>
+                    <searchToolbarItem reference="dv4-Il-y8X"/>
                     <toolbarItem reference="Lf2-ec-tHh"/>
-                    <toolbarItem reference="hnO-hn-Ad3"/>
                 </defaultToolbarItems>
             </toolbar>
             <connections>
@@ -659,6 +659,8 @@
                 <outlet property="dragDropImageBackgroundBox" destination="AXk-h7-dZ0" id="h3h-Wh-0op"/>
                 <outlet property="emptyLibraryView" destination="YJf-1r-vaC" id="AJB-eN-4u6"/>
                 <outlet property="gridVsListSegmentedControl" destination="lIg-5J-C5F" id="u6B-Zx-4mX"/>
+                <outlet property="librarySearchField" destination="ab6-kR-8Io" id="Qf7-UM-lol"/>
+                <outlet property="librarySearchToolbarItem" destination="dv4-Il-y8X" id="Um3-s4-Ax4"/>
                 <outlet property="librarySortButton" destination="Rja-6g-wNZ" id="FQ7-MU-hsk"/>
                 <outlet property="libraryTargetView" destination="iSp-bV-w6B" id="a94-ux-wUc"/>
                 <outlet property="mainSplitView" destination="u8g-jy-S4e" id="lI5-wR-kef"/>


=====================================
modules/gui/macosx/library/VLCLibraryController.h
=====================================
@@ -51,6 +51,12 @@ NS_ASSUME_NONNULL_BEGIN
  */
 - (void)sortByCriteria:(enum vlc_ml_sorting_criteria_t)sortCriteria andDescending:(bool)descending;
 
+/**
+ * @brief Filter the entire library representation based on:
+ * @param filterString the string that will be used to filter items
+ */
+- (void)filterByString:(NSString*)filterString;
+
 /**
  * Initially, the library is unsorted until the user decides to do so
  * Until then, the unsorted state is retained.


=====================================
modules/gui/macosx/library/VLCLibraryController.m
=====================================
@@ -195,4 +195,9 @@
     [_libraryModel sortByCriteria:sortCriteria andDescending:descending];
 }
 
+- (void)filterByString:(NSString*)filterString
+{
+    [_libraryModel filterByString:filterString];
+}
+
 @end


=====================================
modules/gui/macosx/library/VLCLibraryModel.h
=====================================
@@ -69,6 +69,7 @@ extern NSString *VLCLibraryModelMediaItemUpdated;
 - (nullable NSArray <VLCMediaLibraryAlbum *>*)listAlbumsOfParentType:(enum vlc_ml_parent_type)parentType forID:(int64_t)ID;
 
 - (void)sortByCriteria:(enum vlc_ml_sorting_criteria_t)sortCriteria andDescending:(bool)descending;
+- (void)filterByString:(NSString*)filterString;
 
 @end
 


=====================================
modules/gui/macosx/library/VLCLibraryModel.m
=====================================
@@ -49,6 +49,7 @@ NSString *VLCLibraryModelMediaItemUpdated = @"VLCLibraryModelMediaItemUpdated";
 
     enum vlc_ml_sorting_criteria_t _sortCriteria;
     bool _sortDescending;
+    NSString *_filterString;
     
     size_t _initialVideoCount;
     size_t _initialAudioCount;
@@ -133,6 +134,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     if (self) {
         _sortCriteria = VLC_ML_SORTING_DEFAULT;
         _sortDescending = NO;
+        _filterString = @"";
         _p_mediaLibrary = library;
         _p_eventCallback = vlc_ml_event_register_callback(_p_mediaLibrary, libraryCallback, (__bridge void *)self);
         _defaultNotificationCenter = [NSNotificationCenter defaultCenter];
@@ -187,10 +189,18 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     return _cachedAudioMedia.count;
 }
 
+- (vlc_ml_query_params_t)queryParams
+{
+    const vlc_ml_query_params_t queryParams = { .psz_pattern = self->_filterString.length > 0 ? [self->_filterString UTF8String] : NULL, 
+                                                .i_sort = self->_sortCriteria, 
+                                                .b_desc = self->_sortDescending };
+    return queryParams;
+}
+
 - (void)updateCachedListOfAudioMedia
 {
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
-        const vlc_ml_query_params_t queryParams = { .i_sort = self->_sortCriteria, .b_desc = self->_sortDescending };
+        const vlc_ml_query_params_t queryParams = [self queryParams];
         vlc_ml_media_list_t *p_media_list = vlc_ml_list_audio_media(self->_p_mediaLibrary, &queryParams);
         if (!p_media_list) {
             return;
@@ -230,7 +240,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 - (void)updateCachedListOfArtists
 {
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
-        const vlc_ml_query_params_t queryParams = { .i_sort = self->_sortCriteria, .b_desc = self->_sortDescending };
+        const vlc_ml_query_params_t queryParams = { .psz_pattern = [self->_filterString UTF8String], .i_sort = self->_sortCriteria, .b_desc = self->_sortDescending };
         vlc_ml_artist_list_t *p_artist_list = vlc_ml_list_artists(self->_p_mediaLibrary, &queryParams, NO);
         NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:p_artist_list->i_nb_items];
         for (size_t x = 0; x < p_artist_list->i_nb_items; x++) {
@@ -266,7 +276,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 - (void)updateCachedListOfAlbums
 {
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
-        const vlc_ml_query_params_t queryParams = { .i_sort = self->_sortCriteria, .b_desc = self->_sortDescending };
+        const vlc_ml_query_params_t queryParams = [self queryParams];
         vlc_ml_album_list_t *p_album_list = vlc_ml_list_albums(self->_p_mediaLibrary, &queryParams);
         NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:p_album_list->i_nb_items];
         for (size_t x = 0; x < p_album_list->i_nb_items; x++) {
@@ -300,7 +310,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 - (void)updateCachedListOfGenres
 {
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
-        const vlc_ml_query_params_t queryParams = { .i_sort = self->_sortCriteria, .b_desc = self->_sortDescending };
+        const vlc_ml_query_params_t queryParams = [self queryParams];
         vlc_ml_genre_list_t *p_genre_list = vlc_ml_list_genres(self->_p_mediaLibrary, &queryParams);
         NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:p_genre_list->i_nb_items];
         for (size_t x = 0; x < p_genre_list->i_nb_items; x++) {
@@ -339,11 +349,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 - (void)updateCachedListOfVideoMedia
 {
     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
-        const vlc_ml_query_params_t queryParameters = {
-            .i_nbResults = 0,
-            .i_sort = self->_sortCriteria,
-            .b_desc = self->_sortDescending
-        };
+        const vlc_ml_query_params_t queryParameters = [self queryParams];
         vlc_ml_media_list_t *p_media_list = vlc_ml_list_video_media(self->_p_mediaLibrary, &queryParameters);
         if (p_media_list == NULL) {
             return;
@@ -440,7 +446,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 
 - (nullable NSArray <VLCMediaLibraryAlbum *>*)listAlbumsOfParentType:(enum vlc_ml_parent_type)parentType forID:(int64_t)ID;
 {
-    const vlc_ml_query_params_t queryParams = { .i_sort = self->_sortCriteria, .b_desc = self->_sortDescending };
+    const vlc_ml_query_params_t queryParams = [self queryParams];
     vlc_ml_album_list_t *p_albumList = vlc_ml_list_albums_of(_p_mediaLibrary, &queryParams, parentType, ID);
     if (p_albumList == NULL) {
         return nil;
@@ -461,6 +467,16 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     [self dropCaches];
 }
 
+- (void)filterByString:(NSString*)filterString
+{
+    if([filterString isEqualToString:_filterString]) {
+        return;
+    }
+
+    _filterString = filterString;
+    [self dropCaches];
+}
+
 - (void)dropCaches
 {
     _cachedVideoMedia = nil;


=====================================
modules/gui/macosx/library/VLCLibraryWindow.h
=====================================
@@ -72,6 +72,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (readwrite, weak) IBOutlet NSButton *shufflePlaylistButton;
 @property (readwrite, weak) IBOutlet VLCRoundedCornerTextField *playlistCounterTextField;
 @property (readwrite, weak) IBOutlet NSButton *librarySortButton;
+ at property (readwrite, weak) IBOutlet NSSearchField *librarySearchField;
+ at property (readwrite, weak) IBOutlet NSToolbarItem *librarySearchToolbarItem;
 @property (readwrite, weak) IBOutlet NSButton *playQueueToggle;
 
 @property (readonly) BOOL nativeFullscreenMode;
@@ -87,6 +89,7 @@ NS_ASSUME_NONNULL_BEGIN
 - (IBAction)clearPlaylist:(id)sender;
 - (IBAction)sortPlaylist:(id)sender;
 - (IBAction)sortLibrary:(id)sender;
+- (IBAction)filterLibrary:(id)sender;
 - (IBAction)openMedia:(id)sender;
 - (IBAction)showAndHidePlaylist:(id)sender;
 


=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -190,6 +190,8 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
 
     [self.gridVsListSegmentedControl setHidden:NO];
     [self.librarySortButton setHidden:NO];
+    [self.librarySearchField setEnabled:YES];
+
     self.videoView.translatesAutoresizingMaskIntoConstraints = NO;
     [self.contentView addSubview:self.videoView];
     [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.videoView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.mainSplitView attribute:NSLayoutAttributeWidth multiplier:1. constant:1.]];
@@ -559,6 +561,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     }
     
     _librarySortButton.hidden = NO;
+    _librarySearchField.enabled = YES;
     _optionBarView.hidden = YES;
     _audioSegmentedControl.hidden = YES;
 
@@ -610,6 +613,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     }
     
     _librarySortButton.hidden = NO;
+    _librarySearchField.enabled = YES;
     _optionBarView.hidden = NO;
     _audioSegmentedControl.hidden = NO;
     
@@ -637,6 +641,8 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     }
     _mediaSourceDataSource.mediaSourceMode = _segmentedTitleControl.selectedSegment == 2 ? VLCMediaSourceModeLAN : VLCMediaSourceModeInternet;
     _librarySortButton.hidden = YES;
+    _librarySearchField.enabled = NO;
+    [self clearLibraryFilterString];
     _optionBarView.hidden = YES;
     _audioSegmentedControl.hidden = YES;
     [_mediaSourceDataSource reloadViews];
@@ -672,6 +678,17 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     [NSMenu popUpContextMenu:_librarySortingMenuController.librarySortingMenu withEvent:[NSApp currentEvent] forView:sender];
 }
 
+- (IBAction)filterLibrary:(id)sender
+{
+    [[[VLCMain sharedInstance] libraryController] filterByString:_librarySearchField.stringValue];
+}
+
+- (void)clearLibraryFilterString
+{
+    _librarySearchField.stringValue = @"";
+    [self filterLibrary:self];
+}
+
 - (IBAction)openMedia:(id)sender
 {
     [[[VLCMain sharedInstance] open] openFileGeneric];
@@ -794,6 +811,9 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     [self.videoView setHidden:NO];
     [self.gridVsListSegmentedControl setHidden:YES];
     [self.librarySortButton setHidden:YES];
+    [self.librarySearchField setEnabled:NO];
+    [self clearLibraryFilterString];
+
     if (self.nativeFullscreenMode) {
         if ([self hasActiveVideo] && [self fullscreen]) {
             [self hideControlsBar];
@@ -830,6 +850,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     [self.videoView setHidden:YES];
     [self.gridVsListSegmentedControl setHidden:NO];
     [self.librarySortButton setHidden:NO];
+    [self.librarySearchField setEnabled:YES];
 
     [self segmentedControlAction:nil];
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/f9057380231f39d362c59d4cb3c82063014e3182

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/f9057380231f39d362c59d4cb3c82063014e3182
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list