[vlc-commits] macosx/library: expose preference API and history clearance

Felix Paul Kühne git at videolan.org
Thu May 2 22:56:22 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Thu May  2 22:23:53 2019 +0200| [21119ffe33af5532e9be4753157678f269166a06] | committer: Felix Paul Kühne

macosx/library: expose preference API and history clearance

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=21119ffe33af5532e9be4753157678f269166a06
---

 modules/gui/macosx/library/VLCLibraryController.h |   2 +
 modules/gui/macosx/library/VLCLibraryController.m |   5 +
 modules/gui/macosx/library/VLCLibraryDataTypes.h  |  22 ++
 modules/gui/macosx/library/VLCLibraryDataTypes.m  | 270 ++++++++++++++++++++++
 4 files changed, 299 insertions(+)

diff --git a/modules/gui/macosx/library/VLCLibraryController.h b/modules/gui/macosx/library/VLCLibraryController.h
index 06c0b2cf86..46635f84de 100644
--- a/modules/gui/macosx/library/VLCLibraryController.h
+++ b/modules/gui/macosx/library/VLCLibraryController.h
@@ -40,6 +40,8 @@ NS_ASSUME_NONNULL_BEGIN
 - (int)unbanFolderWithFileURL:(NSURL *)fileURL;
 - (int)removeFolderWithFileURL:(NSURL *)fileURL;
 
+- (int)clearHistory;
+
 @end
 
 NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/library/VLCLibraryController.m b/modules/gui/macosx/library/VLCLibraryController.m
index fb81ede9e8..225bd72d10 100644
--- a/modules/gui/macosx/library/VLCLibraryController.m
+++ b/modules/gui/macosx/library/VLCLibraryController.m
@@ -148,4 +148,9 @@
     return vlc_ml_remove_folder(_p_libraryInstance, [[fileURL absoluteString] UTF8String]);
 }
 
+- (int)clearHistory
+{
+    return vlc_ml_clear_history(_p_libraryInstance);
+}
+
 @end
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.h b/modules/gui/macosx/library/VLCLibraryDataTypes.h
index c5789b4767..67a8fac729 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.h
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.h
@@ -94,6 +94,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCMediaLibraryMediaItem : NSObject
 
++ (nullable instancetype)mediaItemForLibraryID:(int64_t)libraryID;
 - (instancetype)initWithMediaItem:(struct vlc_ml_media_t *)mediaItem;
 
 @property (readonly) int64_t libraryID;
@@ -119,6 +120,27 @@ NS_ASSUME_NONNULL_BEGIN
 @property (readonly, nullable) VLCMediaLibraryMovie *movie;
 @property (readonly, nullable) VLCMediaLibraryAlbumTrack *albumTrack;
 
+ at property (readwrite) int rating;
+ at property (readwrite) float lastPlaybackPosition;
+ at property (readwrite) float lastPlaybackRate;
+ at property (readwrite) int lastTitle;
+ at property (readwrite) int lastChapter;
+ at property (readwrite) int lastProgram;
+ at property (readwrite) BOOL seen;
+ at property (readwrite) int lastVideoTrack;
+ at property (readwrite) NSString *lastAspectRatio;
+ at property (readwrite) NSString *lastZoom;
+ at property (readwrite) NSString *lastCrop;
+ at property (readwrite) NSString *lastDeinterlaceFilter;
+ at property (readwrite) NSString *lastVideoFilters;
+ at property (readwrite) int lastAudioTrack;
+ at property (readwrite) float lastGain;
+ at property (readwrite) int lastAudioDelay;
+ at property (readwrite) int lastSubtitleTrack;
+ at property (readwrite) int lastSubtitleDelay;
+
+- (int)increasePlayCount;
+
 @end
 
 @interface VLCMediaLibraryEntryPoint : NSObject
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.m b/modules/gui/macosx/library/VLCLibraryDataTypes.m
index 9ea940b9b0..228b99076a 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.m
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.m
@@ -22,6 +22,7 @@
 
 #import "VLCLibraryDataTypes.h"
 
+#import "main/VLCMain.h"
 #import "extensions/NSString+Helpers.h"
 
 #import <vlc_url.h>
@@ -128,12 +129,38 @@
 
 @end
 
+ at interface VLCMediaLibraryMediaItem ()
+
+ at property (readwrite, assign) vlc_medialibrary_t *p_mediaLibrary;
+
+ at end
+
 @implementation VLCMediaLibraryMediaItem
 
+#pragma mark - initialization
+
++ (nullable instancetype)mediaItemForLibraryID:(int64_t)libraryID
+{
+    vlc_medialibrary_t *p_mediaLibrary = vlc_ml_instance_get(getIntf());
+    vlc_ml_media_t *p_mediaItem = vlc_ml_get(p_mediaLibrary, VLC_ML_GET_MEDIA, libraryID);
+    VLCMediaLibraryMediaItem *returnValue = nil;
+    if (p_mediaItem) {
+        returnValue = [[VLCMediaLibraryMediaItem alloc] initWithMediaItem:p_mediaItem library:p_mediaLibrary];
+    }
+    return returnValue;
+}
+
 - (instancetype)initWithMediaItem:(struct vlc_ml_media_t *)p_mediaItem
 {
+    vlc_medialibrary_t *p_mediaLibrary = vlc_ml_instance_get(getIntf());
+    return [self initWithMediaItem:p_mediaItem library:p_mediaLibrary];
+}
+
+- (instancetype)initWithMediaItem:(struct vlc_ml_media_t *)p_mediaItem library:(vlc_medialibrary_t *)p_mediaLibrary
+{
     self = [super init];
     if (self) {
+        _p_mediaLibrary = p_mediaLibrary;
         _libraryID = p_mediaItem->i_id;
         _mediaType = p_mediaItem->i_type;
         _mediaSubType = p_mediaItem->i_subtype;
@@ -191,6 +218,249 @@
             NSStringFromClass([self class]), _title, _libraryID, _mediaType, _artworkMRL];
 }
 
+#pragma mark - preference setters / getters
+
+- (int)setIntegerPreference:(int)value forKey:(enum vlc_ml_playback_pref)key
+{
+    return vlc_ml_media_set_playback_pref(_p_mediaLibrary, _libraryID, key, [[[NSNumber numberWithInt:value] stringValue] UTF8String]);
+}
+
+- (int)integerPreferenceForKey:(enum vlc_ml_playback_pref)key
+{
+    int ret = 0;
+    char *psz_value;
+
+    if (vlc_ml_media_get_playback_pref(_p_mediaLibrary, _libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
+        ret = atoi(psz_value);
+        free(psz_value);
+    }
+
+    return ret;
+}
+
+- (int)setFloatPreference:(float)value forKey:(enum vlc_ml_playback_pref)key
+{
+    return vlc_ml_media_set_playback_pref(_p_mediaLibrary, _libraryID, key, [[[NSNumber numberWithFloat:value] stringValue] UTF8String]);
+}
+
+- (float)floatPreferenceForKey:(enum vlc_ml_playback_pref)key
+{
+    float ret = .0;
+    char *psz_value;
+
+    if (vlc_ml_media_get_playback_pref(_p_mediaLibrary, _libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
+        ret = atof(psz_value);
+        free(psz_value);
+    }
+
+    return ret;
+}
+
+- (int)setStringPreference:(NSString *)value forKey:(enum vlc_ml_playback_pref)key
+{
+    return vlc_ml_media_set_playback_pref(_p_mediaLibrary, _libraryID, key, [value UTF8String]);
+}
+
+- (NSString *)stringPreferenceForKey:(enum vlc_ml_playback_pref)key
+{
+    NSString *ret = @"";
+    char *psz_value;
+
+    if (vlc_ml_media_get_playback_pref(_p_mediaLibrary, _libraryID, key, &psz_value) == VLC_SUCCESS && psz_value != NULL) {
+        ret = toNSStr(psz_value);
+        free(psz_value);
+    }
+
+    return ret;
+}
+
+#pragma mark - preference properties
+
+- (int)rating
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_RATING];
+}
+
+- (void)setRating:(int)rating
+{
+    [self setIntegerPreference:rating forKey:VLC_ML_PLAYBACK_PREF_RATING];
+}
+
+- (float)lastPlaybackPosition
+{
+    return [self floatPreferenceForKey:VLC_ML_PLAYBACK_PREF_PROGRESS];
+}
+
+- (void)setLastPlaybackPosition:(float)lastPlaybackPosition
+{
+    [self setFloatPreference:lastPlaybackPosition forKey:VLC_ML_PLAYBACK_PREF_PROGRESS];
+}
+
+- (float)lastPlaybackRate
+{
+    return [self floatPreferenceForKey:VLC_ML_PLAYBACK_PREF_SPEED];
+}
+
+- (void)setLastPlaybackRate:(float)lastPlaybackRate
+{
+    [self setFloatPreference:lastPlaybackRate forKey:VLC_ML_PLAYBACK_PREF_SPEED];
+}
+
+- (int)lastTitle
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_TITLE];
+}
+
+- (void)setLastTitle:(int)lastTitle
+{
+    [self setIntegerPreference:lastTitle forKey:VLC_ML_PLAYBACK_PREF_TITLE];
+}
+
+- (int)lastChapter
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_CHAPTER];
+}
+
+- (void)setLastChapter:(int)lastChapter
+{
+    [self setIntegerPreference:lastChapter forKey:VLC_ML_PLAYBACK_PREF_CHAPTER];
+}
+
+- (int)lastProgram
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_PROGRAM];
+}
+
+- (void)setLastProgram:(int)lastProgram
+{
+    [self setIntegerPreference:lastProgram forKey:VLC_ML_PLAYBACK_PREF_PROGRAM];
+}
+
+- (BOOL)seen
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_SEEN] > 0 ? YES : NO;
+}
+
+- (void)setSeen:(BOOL)seen
+{
+    [self setIntegerPreference:seen forKey:VLC_ML_PLAYBACK_PREF_SEEN];
+}
+
+- (int)lastVideoTrack
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_VIDEO_TRACK];
+}
+
+- (void)setLastVideoTrack:(int)lastVideoTrack
+{
+    [self setIntegerPreference:lastVideoTrack forKey:VLC_ML_PLAYBACK_PREF_VIDEO_TRACK];
+}
+
+- (NSString *)lastAspectRatio
+{
+    return [self stringPreferenceForKey:VLC_ML_PLAYBACK_PREF_ASPECT_RATIO];
+}
+
+- (void)setLastAspectRatio:(NSString *)lastAspectRatio
+{
+    [self setStringPreference:lastAspectRatio forKey:VLC_ML_PLAYBACK_PREF_ASPECT_RATIO];
+}
+
+- (NSString *)lastZoom
+{
+    return [self stringPreferenceForKey:VLC_ML_PLAYBACK_PREF_ZOOM];
+}
+
+- (void)setLastZoom:(NSString *)lastZoom
+{
+    [self setStringPreference:lastZoom forKey:VLC_ML_PLAYBACK_PREF_ZOOM];
+}
+
+- (NSString *)lastCrop
+{
+    return [self stringPreferenceForKey:VLC_ML_PLAYBACK_PREF_CROP];
+}
+
+- (void)setLastCrop:(NSString *)lastCrop
+{
+    [self setStringPreference:lastCrop forKey:VLC_ML_PLAYBACK_PREF_CROP];
+}
+
+- (NSString *)lastDeinterlaceFilter
+{
+    return [self stringPreferenceForKey:VLC_ML_PLAYBACK_PREF_DEINTERLACE];
+}
+
+- (void)setLastDeinterlaceFilter:(NSString *)lastDeinterlaceFilter
+{
+    [self setStringPreference:lastDeinterlaceFilter forKey:VLC_ML_PLAYBACK_PREF_DEINTERLACE];
+}
+
+- (NSString *)lastVideoFilters
+{
+    return [self stringPreferenceForKey:VLC_ML_PLAYBACK_PREF_VIDEO_FILTER];
+}
+
+- (void)setLastVideoFilters:(NSString *)lastVideoFilters
+{
+    [self setStringPreference:lastVideoFilters forKey:VLC_ML_PLAYBACK_PREF_VIDEO_FILTER];
+}
+
+- (int)lastAudioTrack
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_AUDIO_TRACK];
+}
+
+- (void)setLastAudioTrack:(int)lastAudioTrack
+{
+    [self setIntegerPreference:lastAudioTrack forKey:VLC_ML_PLAYBACK_PREF_AUDIO_TRACK];
+}
+
+- (float)lastGain
+{
+    return [self floatPreferenceForKey:VLC_ML_PLAYBACK_PREF_GAIN];
+}
+
+- (void)setLastGain:(float)lastGain
+{
+    [self setFloatPreference:lastGain forKey:VLC_ML_PLAYBACK_PREF_GAIN];
+}
+
+- (int)lastAudioDelay
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_AUDIO_DELAY];
+}
+
+- (void)setLastAudioDelay:(int)lastAudioDelay
+{
+    [self setIntegerPreference:lastAudioDelay forKey:VLC_ML_PLAYBACK_PREF_AUDIO_DELAY];
+}
+
+- (int)lastSubtitleTrack
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_SUBTITLE_TRACK];
+}
+
+- (void)setLastSubtitleTrack:(int)lastSubtitleTrack
+{
+    [self setIntegerPreference:lastSubtitleTrack forKey:VLC_ML_PLAYBACK_PREF_SUBTITLE_TRACK];
+}
+
+- (int)lastSubtitleDelay
+{
+    return [self integerPreferenceForKey:VLC_ML_PLAYBACK_PREF_SUBTITLE_DELAY];
+}
+
+- (void)setLastSubtitleDelay:(int)lastSubtitleDelay
+{
+    [self setIntegerPreference:lastSubtitleDelay forKey:VLC_ML_PLAYBACK_PREF_SUBTITLE_DELAY];
+}
+
+- (int)increasePlayCount
+{
+    return vlc_ml_media_increase_playcount(_p_mediaLibrary, _libraryID);
+}
+
 @end
 
 @implementation VLCMediaLibraryEntryPoint



More information about the vlc-commits mailing list