123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- // _____ _
- // |_ _| |_ _ _ ___ ___ _ __ __ _
- // | | | ' \| '_/ -_) -_) ' \/ _` |_
- // |_| |_||_|_| \___\___|_|_|_\__,_(_)
- //
- // Threema iOS Client
- // Copyright (c) 2012-2020 Threema GmbH
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License, version 3,
- // as published by the Free Software Foundation.
- //
- // 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 Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
- #import "VideoMessage.h"
- #import "ImageData.h"
- #import "VideoData.h"
- #import "NSString+Hex.h"
- #import "BundleUtil.h"
- #import "UTIConverter.h"
- #import "Utils.h"
- #import "ThreemaFramework/ThreemaFramework-swift.h"
- @implementation VideoMessage
- @dynamic progress;
- @dynamic videoSize;
- @dynamic videoBlobId;
- @dynamic encryptionKey;
- @dynamic video;
- @dynamic thumbnail;
- @dynamic duration;
- @synthesize thumbnailWithPlayOverlay = _thumbnailWithPlayOverlay;
- - (NSString*)logText {
- int seconds = self.duration.intValue;
- int minutes = seconds / 60;
- seconds -= minutes * 60;
- return [NSString stringWithFormat:@"%@ (%02d:%02d, %@)", NSLocalizedString(@"video", nil), minutes, seconds, [self blobGetFilename]];
- }
- - (NSString*)previewText {
- return NSLocalizedString(@"video", nil);
- }
- - (NSData *)blobGetData {
- if (self.video) {
- return self.video.data;
- }
-
- return nil;
- }
- - (NSData *)blobGetId {
- return self.videoBlobId;
- }
- - (NSData *)blobGetEncryptionKey {
- return self.encryptionKey;
- }
- - (NSNumber *)blobGetSize {
- return self.videoSize;
- }
- - (void)blobSetData:(NSData *)data {
- VideoData *dbData = [NSEntityDescription
- insertNewObjectForEntityForName:@"VideoData"
- inManagedObjectContext:self.managedObjectContext];
-
- dbData.data = data;
- self.video = dbData;
- }
- - (NSData *)blobGetThumbnail {
- if (self.thumbnail) {
- return self.thumbnail.data;
- }
-
- return nil;
- }
- - (NSString *)blobGetUTI {
- return UTTYPE_VIDEO;
- }
- - (UIImage *)thumbnailWithPlayOverlay {
- if (_thumbnailWithPlayOverlay == nil) {
- _thumbnailWithPlayOverlay = [Utils makeThumbWithOverlayFor:self.thumbnail.uiImage];
- }
-
- return _thumbnailWithPlayOverlay;
- }
- - (NSString *)blobGetFilename {
- return [NSString stringWithFormat: @"%@.%@", [NSString stringWithHexData:self.id], MEDIA_EXTENSION_VIDEO];
- }
- - (NSString *)blobGetWebFilename {
- return [NSString stringWithFormat: @"threema-%@-video.%@", [DateFormatter getDateForWeb:self.date], MEDIA_EXTENSION_VIDEO];
- }
- - (void)blobUpdateProgress:(NSNumber *)progress {
- self.progress = progress;
- }
- - (NSNumber *)blobGetProgress {
- return self.progress;
- }
- #ifdef DEBUG
- #else
- - (NSString *)debugDescription
- {
- return [NSString stringWithFormat:@"<%@: %p> %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@", [self class], self, @"progress = ", self.progress.description, @"videoBlobId = ", @"***", @"encryptionKey = ", @"***", @"videoSize = ", self.videoSize.description, @"video = ", self.video.description, @"thumbnail = ", self.thumbnail.description, @"duration = ", self.duration.description];
- }
- #endif
- #pragma mark ExternalStorageInfo
- - (NSString *)getFilename {
- return self.video != nil ? [self getFilename:self.video.data] : nil;
- }
- - (NSString *)getThumbnailname {
- return self.thumbnail != nil ? [self getFilename:self.thumbnail.data] : nil;
- }
- - (NSString *)getFilename:(NSData *)ofData {
- if (ofData != nil && [ofData respondsToSelector:NSSelectorFromString(@"filename")]) {
- return [ofData performSelector:NSSelectorFromString(@"filename")];
- }
- return nil;
- }
- @end
|