[vlc-commits] [Git][videolan/vlc][master] 4 commits: macosx: Add starter VLCTimeFormatter
Steve Lhomme (@robUx4)
gitlab at videolan.org
Mon Nov 4 11:39:05 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
b6ffdf9b by Claudio Cambra at 2024-11-04T10:55:12+00:00
macosx: Add starter VLCTimeFormatter
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
67c34ff8 by Claudio Cambra at 2024-11-04T10:55:12+00:00
macosx: Implement getObjectValue to get HH:mm:ss time in VLCTimeFormatter
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
629af0ad by Claudio Cambra at 2024-11-04T10:55:12+00:00
macosx: Implement stringForObjectValue in time formatter
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
c3ed3184 by Claudio Cambra at 2024-11-04T10:55:12+00:00
macosx: Use VLCTimeFormatter in bookmarks table view data source
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
5 changed files:
- extras/package/macosx/VLC.xcodeproj/project.pbxproj
- modules/gui/macosx/Makefile.am
- modules/gui/macosx/panels/bookmarks/VLCBookmarksTableViewDataSource.m
- + modules/gui/macosx/views/VLCTimeFormatter.h
- + modules/gui/macosx/views/VLCTimeFormatter.m
Changes:
=====================================
extras/package/macosx/VLC.xcodeproj/project.pbxproj
=====================================
@@ -135,6 +135,7 @@
53A1F1172AB7168000686BAA /* VLCLibraryAllAudioGroupsMediaLibraryItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A1F1162AB7168000686BAA /* VLCLibraryAllAudioGroupsMediaLibraryItem.m */; };
53A8F9D12A7E1E6300BC11BF /* VLCLibraryPlaylistViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A8F9D02A7E1E6300BC11BF /* VLCLibraryPlaylistViewController.m */; };
53A8F9D42A7F815900BC11BF /* VLCLibraryPlaylistDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A8F9D32A7F815900BC11BF /* VLCLibraryPlaylistDataSource.m */; };
+ 53A9698A2CD5B9D400E6F66E /* VLCTimeFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A969892CD5B9D400E6F66E /* VLCTimeFormatter.m */; };
53B40FD72AA878E400C814E4 /* VLCLibraryHeroView.m in Sources */ = {isa = PBXBuildFile; fileRef = 53B40FD62AA878E400C814E4 /* VLCLibraryHeroView.m */; };
53B447CA2939823E00857588 /* VLCLibrarySongsTableViewSongPlayingTableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = 53B447C92939823E00857588 /* VLCLibrarySongsTableViewSongPlayingTableCellView.m */; };
53B447F9293BB47B00857588 /* VLCLibraryVideoDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 53B447F3293BB47A00857588 /* VLCLibraryVideoDataSource.m */; };
@@ -423,6 +424,8 @@
53A8F9D02A7E1E6300BC11BF /* VLCLibraryPlaylistViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryPlaylistViewController.m; sourceTree = "<group>"; };
53A8F9D22A7F815900BC11BF /* VLCLibraryPlaylistDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryPlaylistDataSource.h; sourceTree = "<group>"; };
53A8F9D32A7F815900BC11BF /* VLCLibraryPlaylistDataSource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryPlaylistDataSource.m; sourceTree = "<group>"; };
+ 53A969882CD5B9D400E6F66E /* VLCTimeFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCTimeFormatter.h; sourceTree = "<group>"; };
+ 53A969892CD5B9D400E6F66E /* VLCTimeFormatter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCTimeFormatter.m; sourceTree = "<group>"; };
53B40FD42AA7618000C814E4 /* VLCLibraryHeroView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = VLCLibraryHeroView.xib; sourceTree = "<group>"; };
53B40FD52AA878E400C814E4 /* VLCLibraryHeroView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryHeroView.h; sourceTree = "<group>"; };
53B40FD62AA878E400C814E4 /* VLCLibraryHeroView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryHeroView.m; sourceTree = "<group>"; };
@@ -1149,6 +1152,8 @@
53628400291147C500640C15 /* VLCSubScrollView.m */,
6BF093F71EE0182B0049D8B0 /* VLCTimeField.h */,
6BF093F81EE0182B0049D8B0 /* VLCTimeField.m */,
+ 53A969882CD5B9D400E6F66E /* VLCTimeFormatter.h */,
+ 53A969892CD5B9D400E6F66E /* VLCTimeFormatter.m */,
7D2008182289835C002679DF /* VLCTrackingView.h */,
7D2008192289835C002679DF /* VLCTrackingView.m */,
6B2EFC5E1F2819F700F3C0EA /* VLCVolumeSlider.h */,
@@ -2272,6 +2277,7 @@
7D404ABF2281892C00B28EF4 /* NSView+VLCAdditions.m in Sources */,
539F116D29F9785C00F13460 /* VLCMainVideoViewAudioMediaDecorativeView.m in Sources */,
7DE9C7DD220728420089108F /* VLCPlayerController.m in Sources */,
+ 53A9698A2CD5B9D400E6F66E /* VLCTimeFormatter.m in Sources */,
536283F4291146BC00640C15 /* VLCLibraryCollectionViewMediaItemSupplementaryDetailView.m in Sources */,
7D93D8FC2316C2DC001C0063 /* VLCCustomCropArWindowController.m in Sources */,
1C3113941E508C6900D4DD76 /* VLCAddonsWindowController.m in Sources */,
=====================================
modules/gui/macosx/Makefile.am
=====================================
@@ -398,6 +398,8 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/views/VLCSubScrollView.m \
gui/macosx/views/VLCTimeField.h \
gui/macosx/views/VLCTimeField.m \
+ gui/macosx/views/VLCTimeFormatter.h \
+ gui/macosx/views/VLCTimeFormatter.m \
gui/macosx/views/VLCTrackingView.h \
gui/macosx/views/VLCTrackingView.m \
gui/macosx/views/VLCVolumeSlider.h \
=====================================
modules/gui/macosx/panels/bookmarks/VLCBookmarksTableViewDataSource.m
=====================================
@@ -36,6 +36,8 @@
#import "playlist/VLCPlayerController.h"
#import "playlist/VLCPlaylistController.h"
+#import "views/VLCTimeFormatter.h"
+
#import <vlc_media_library.h>
NSString * const VLCBookmarksTableViewCellIdentifier = @"VLCBookmarksTableViewCellIdentifier";
@@ -223,18 +225,13 @@ static void bookmarksLibraryCallback(void *p_data, const vlc_ml_event_t *p_event
bookmark.bookmarkDescription = newDescription;
} else if ([columnIdentifier isEqualToString:VLCBookmarksTableViewTimeTableColumnIdentifier]) {
NSString * const timeString = (NSString *)object;
- NSArray * const components = [object componentsSeparatedByString:@":"];
- const NSUInteger componentCount = [components count];
-
- if (componentCount == 1) {
- bookmark.bookmarkTime = ([[components firstObject] longLongValue]) * 1000;
- } else if (componentCount == 2) {
- bookmark.bookmarkTime = ([[components firstObject] longLongValue] * 60 +
- [[components objectAtIndex:1] longLongValue]) * 1000;
- } else if (componentCount == 3) {
- bookmark.bookmarkTime = ([[components firstObject] longLongValue] * 3600 +
- [[components objectAtIndex:1] longLongValue] * 60 +
- [[components objectAtIndex:2] longLongValue]) * 1000;
+ VLCTimeFormatter * const formatter = [[VLCTimeFormatter alloc] init];
+ NSString *error = nil;
+ NSNumber *time = nil;
+ [formatter getObjectValue:&time forString:timeString errorDescription:&error];
+
+ if (error == nil) {
+ bookmark.bookmarkTime = time.longLongValue;
} else {
msg_Err(getIntf(), "Cannot set bookmark time as invalid string format for time was received");
}
=====================================
modules/gui/macosx/views/VLCTimeFormatter.h
=====================================
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * VLCTimeFormatter.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2024 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <developer at claudiocambra.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+ at interface VLCTimeFormatter : NSFormatter
+
+ at end
+
+NS_ASSUME_NONNULL_END
=====================================
modules/gui/macosx/views/VLCTimeFormatter.m
=====================================
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * VLCTimeFormatter.m: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2024 VLC authors and VideoLAN
+ *
+ * Authors: Claudio Cambra <developer at claudiocambra.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCTimeFormatter.h"
+
+#import "extensions/NSString+Helpers.h"
+
+ at implementation VLCTimeFormatter
+
+- (NSString *)stringForObjectValue:(id)obj
+{
+ NSParameterAssert([obj isKindOfClass:NSNumber.class]);
+ NSNumber * const time = obj;
+ return [NSString stringWithTime:time.longLongValue];
+}
+
+- (BOOL)getObjectValue:(out id _Nullable *)obj
+ forString:(NSString *)string
+ errorDescription:(out NSString * _Nullable *)error
+{
+ NSArray<NSString *> * const components = [string componentsSeparatedByString:@":"];
+ const NSUInteger componentCount = components.count;
+ if (componentCount <= 1 || componentCount > 3) {
+ *error = @"Cannot get bookmark time as invalid string format for time was received";
+ return NO;
+ }
+
+ size_t time = 0;
+
+ if (componentCount == 1) {
+ time = components.firstObject.longLongValue * 1000;
+ } else if (componentCount == 2) {
+ time = components.firstObject.longLongValue * 60 +
+ [components objectAtIndex:1].longLongValue * 1000;
+ } else if (componentCount == 3) {
+ time = components.firstObject.longLongValue * 3600 +
+ [components objectAtIndex:1].longLongValue * 60 +
+ [components objectAtIndex:2].longLongValue * 1000;
+ }
+
+ *obj = [NSNumber numberWithLongLong:time];
+ return YES;
+}
+
+ at end
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6de7998f920337492d3b73f17268ab192eab1ef4...c3ed31846ee2ae67e1260e6d1fbe025935cb81b5
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6de7998f920337492d3b73f17268ab192eab1ef4...c3ed31846ee2ae67e1260e6d1fbe025935cb81b5
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