Commit 0f0ba991 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

conversation: preview transferred files.

Change-Id: Idbb78e5fa438a877855d7fd98edd4c9cf67611da
parent bb68a1c9
......@@ -126,7 +126,7 @@
-(void) setConversationUid:(const std::string)convUid model:(lrc::api::ConversationModel *)model {
if (convUid_ == convUid && convModel_ == model)
return;
[self clearData];
cachedConv_ = nil;
convUid_ = convUid;
convModel_ = model;
......
......@@ -35,11 +35,15 @@
#import "delegates/ImageManipulationDelegate.h"
#import "utils.h"
#import "views/NSColor+RingTheme.h"
#import "views/IconButton.h"
#import <QuickLook/QuickLook.h>
#import <Quartz/Quartz.h>
@interface MessagesVC () <NSTableViewDelegate, NSTableViewDataSource> {
@interface MessagesVC () <NSTableViewDelegate, NSTableViewDataSource, QLPreviewPanelDataSource> {
__unsafe_unretained IBOutlet NSTableView* conversationView;
__unsafe_unretained IBOutlet NSView* containerView;
std::string convUid_;
lrc::api::ConversationModel* convModel_;
......@@ -52,6 +56,7 @@
QMetaObject::Connection modelSortedSignal_;
QMetaObject::Connection filterChangedSignal_;
QMetaObject::Connection interactionStatusUpdatedSignal_;
NSString* previewImage;
}
@property (nonatomic, strong, readonly) INDSequentialTextSelectionManager* selectionManager;
......@@ -71,6 +76,7 @@ CGFloat const BUBBLE_HEIGHT_FOR_TRANSFERED_FILE = 87;
@implementation MessagesVC
//MessageBuble type
typedef NS_ENUM(NSInteger, MessageSequencing) {
SINGLE_WITH_TIME = 0,
......@@ -266,6 +272,11 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
[result.declineButton setTarget:self];
break;}
case lrc::api::interaction::Status::TRANSFER_FINISHED:
result = [tableView makeViewWithIdentifier:@"LeftFinishedFileView" owner:conversationView];
[result.transferedFileName setAction:@selector(imagePreview:)];
[result.transferedFileName setTarget:self];
[result.transferedFileName.cell setHighlightsBy:NSContentsCellMask];
break;
case lrc::api::interaction::Status::TRANSFER_CANCELED:
case lrc::api::interaction::Status::TRANSFER_ERROR:
result = [tableView makeViewWithIdentifier:@"LeftFinishedFileView" owner:conversationView];
......@@ -284,6 +295,11 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
[result.declineButton setTarget:self];
break;
case lrc::api::interaction::Status::TRANSFER_FINISHED:
result = [tableView makeViewWithIdentifier:@"RightFinishedFileView" owner:conversationView];
[result.transferedFileName setAction:@selector(imagePreview:)];
[result.transferedFileName setTarget:self];
[result.transferedFileName.cell setHighlightsBy:NSContentsCellMask];
break;
case lrc::api::interaction::Status::TRANSFER_CANCELED:
case lrc::api::interaction::Status::TRANSFER_ERROR:
case lrc::api::interaction::Status::TRANSFER_UNJOINABLE_PEER:
......@@ -318,15 +334,32 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
if (name.length > 0) {
fileName = [name lastPathComponent];
}
result.transferedFileName.stringValue = fileName;
NSFont *nameFont = [NSFont userFontOfSize:14.0];
NSColor *nameColor = [NSColor textColor];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
paragraphStyle.alignment = NSTextAlignmentLeft;
NSDictionary *nameAttr = [NSDictionary dictionaryWithObjectsAndKeys:nameFont,NSFontAttributeName,
nameColor,NSForegroundColorAttributeName,
paragraphStyle,NSParagraphStyleAttributeName, nil];
NSAttributedString* nameAttributedString = [[NSAttributedString alloc] initWithString:fileName attributes:nameAttr];
result.transferedFileName.attributedTitle = nameAttributedString;
if (status == lrc::api::interaction::Status::TRANSFER_FINISHED) {
NSImage* image = [self getImageForFilePath:name];
NSColor *higlightColor = [NSColor grayColor];
NSDictionary *alternativeNametAttr = [NSDictionary dictionaryWithObjectsAndKeys:nameFont,NSFontAttributeName,
higlightColor,NSForegroundColorAttributeName,
paragraphStyle,NSParagraphStyleAttributeName, nil];
NSAttributedString* alternativeString = [[NSAttributedString alloc] initWithString:fileName attributes:alternativeNametAttr];
result.transferedFileName.attributedAlternateTitle = alternativeString;
NSImage* image = [self getImageForFilePath:name size:MAX_TRANSFERED_IMAGE_SIZE];
if (([name rangeOfString:@"/"].location == NSNotFound)) {
image = [self getImageForFilePath:[self getDataTransferPath:interactionID]];
image = [self getImageForFilePath:[self getDataTransferPath:interactionID] size:MAX_TRANSFERED_IMAGE_SIZE];
}
if(image != nil) {
result.transferedImage.image = [image roundCorners:14];
[result updateImageConstraint:image.size.width andHeight:image.size.height];
[result.transferedImage setAction:@selector(imagePreview:)];
[result.transferedImage setTarget:self];
}
}
[result setupForInteraction:interactionID];
......@@ -492,9 +525,9 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
if( interaction.status == lrc::api::interaction::Status::TRANSFER_FINISHED) {
NSString* name = @(interaction.body.c_str());
NSImage* image = [self getImageForFilePath:name];
NSImage* image = [self getImageForFilePath:name size:MAX_TRANSFERED_IMAGE_SIZE];
if (([name rangeOfString:@"/"].location == NSNotFound)) {
image = [self getImageForFilePath:[self getDataTransferPath:it->first]];
image = [self getImageForFilePath:[self getDataTransferPath:it->first] size:MAX_TRANSFERED_IMAGE_SIZE];
}
if (image != nil) {
return image.size.height + TIME_BOX_HEIGHT;
......@@ -540,12 +573,12 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
return @(info.path.c_str());
}
-(NSImage*) getImageForFilePath: (NSString *) path {
-(NSImage*) getImageForFilePath: (NSString *) path size:(CGFloat)size {
if (path.length <= 0) {return nil;}
if (![[NSFileManager defaultManager] fileExistsAtPath: path]) {return nil;}
NSImage* transferedImage = [[NSImage alloc] initWithContentsOfFile: path];
if(transferedImage != nil) {
return [transferedImage imageResizeInsideMax: MAX_TRANSFERED_IMAGE_SIZE];
return [transferedImage imageResizeInsideMax: size];
}
return nil;
}
......@@ -754,4 +787,41 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
}
}
- (void)imagePreview:(id)sender {
uint64_t interId;
if ([[sender superview] isKindOfClass:[IMTableCellView class]]) {
interId = [(IMTableCellView*)[sender superview] interaction];
} else if ([[[sender superview] superview] isKindOfClass:[IMTableCellView class]]) {
interId = [(IMTableCellView*)[[sender superview] superview] interaction];
} else {
return;
}
auto it = [self getCurrentConversation]->interactions.find(interId);
if (it == [self getCurrentConversation]->interactions.end()) {
return;
}
auto& interaction = it->second;
NSString* name = @(interaction.body.c_str());
if (([name rangeOfString:@"/"].location == NSNotFound)) {
name = [self getDataTransferPath:interId];
}
previewImage = name;
if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
[[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
} else {
[[QLPreviewPanel sharedPreviewPanel] updateController];
[QLPreviewPanel sharedPreviewPanel].dataSource = self;
[[QLPreviewPanel sharedPreviewPanel] setAnimationBehavior:NSWindowAnimationBehaviorDocumentWindow];
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
}
}
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel {
return 1;
}
- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index {
return [NSURL fileURLWithPath:previewImage];
}
@end
......@@ -32,8 +32,8 @@
@property (nonatomic, strong) IBOutlet NSTextField* statusLabel;
@property (nonatomic, strong) IBOutlet NSBox* timeBox;
@property (nonatomic, strong) IBOutlet NSTextField* timeLabel;
@property (nonatomic, strong) IBOutlet NSTextField* transferedFileName;
@property (nonatomic, strong) IBOutlet NSImageView* transferedImage;
@property (nonatomic, strong) IBOutlet NSButton* transferedFileName;
@property (nonatomic, strong) IBOutlet NSButton* transferedImage;
@property (nonatomic, strong) IBOutlet NSProgressIndicator* sendingMessageIndicator;
@property (nonatomic, strong) IBOutlet NSImageView* messageFailed;
@property (nonatomic, strong) IBOutlet NSView* messageStatus;
......
......@@ -57,6 +57,8 @@ NSString* const TIME_BOX_HEIGHT = @"34";
[self.msgView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.msgBackground setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.msgView setEditable:NO];
[(NSButtonCell*)transferedImage.cell setShowsStateBy:NSNoCellMask];
[(NSButtonCell*)transferedImage.cell setHighlightsBy:NSNoCellMask];
acceptButton.image = [NSColor image: [NSImage imageNamed:@"ic_file_upload.png"] tintedWithColor:[NSColor greenSuccessColor]];
declineButton.image = [NSColor image: [NSImage imageNamed:@"ic_action_cancel.png"] tintedWithColor:[NSColor redColor]];
}
......
......@@ -114,14 +114,15 @@ return [NSColor colorWithCalibratedRed:59/255.0 green:193/255.0 blue:211/255.0 a
+ (NSImage*) image:(NSImage*) img tintedWithColor:(NSColor *)tint
{
NSImage* image = img;
if (tint) {
[img lockFocus];
[image lockFocus];
[tint set];
NSRect imageRect = {NSZeroPoint, [img size]};
NSRect imageRect = {NSZeroPoint, [image size]};
NSRectFillUsingOperation(imageRect, NSCompositeSourceAtop);
[img unlockFocus];
[image unlockFocus];
}
return img;
return image;
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
<capability name="box content view" minToolsVersion="7.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
<capability name="system font weights other than Regular or Bold" minToolsVersion="7.0"/>
......@@ -29,16 +29,16 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="EJD-f8-Xqd">
<rect key="frame" x="0.0" y="60" width="798" height="708"/>
<rect key="frame" x="0.0" y="60" width="798" height="713"/>
<subviews>
<scrollView verticalCompressionResistancePriority="250" borderType="none" autohidesScrollers="YES" horizontalLineScroll="62" horizontalPageScroll="10" verticalLineScroll="62" verticalPageScroll="10" hasHorizontalScroller="NO" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" scrollerKnobStyle="dark" translatesAutoresizingMaskIntoConstraints="NO" id="Ez2-Rf-DZN">
<rect key="frame" x="49" y="0.0" width="700" height="708"/>
<rect key="frame" x="49" y="0.0" width="700" height="713"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="ofC-Bs-tHR">
<rect key="frame" x="0.0" y="0.0" width="700" height="708"/>
<rect key="frame" x="0.0" y="0.0" width="700" height="713"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" autosaveColumns="NO" rowHeight="60" rowSizeStyle="automatic" viewBased="YES" id="bOO-CW-S21">
<rect key="frame" x="0.0" y="0.0" width="700" height="693"/>
<rect key="frame" x="0.0" y="0.0" width="700" height="698"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" white="1" alpha="0.0" colorSpace="deviceWhite"/>
......@@ -165,7 +165,7 @@
</subviews>
</customView>
<customView ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="R85-0p-W1u">
<rect key="frame" x="323" y="0.0" width="40" height="30"/>
<rect key="frame" x="323" y="0.0" width="30" height="30"/>
<subviews>
<progressIndicator wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="0wQ-xJ-dyK">
<rect key="frame" x="7" y="7" width="16" height="16"/>
......@@ -513,7 +513,7 @@
<constraint firstItem="EJD-f8-Xqd" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="L79-xO-12P"/>
<constraint firstItem="RuH-fO-poy" firstAttribute="centerY" secondItem="ooq-vs-Xt1" secondAttribute="centerY" id="MS8-kk-8g8"/>
<constraint firstItem="cFH-d7-Erh" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="10" id="Tok-wc-chb"/>
<constraint firstItem="EJD-f8-Xqd" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="60" id="XkO-FA-l3J"/>
<constraint firstItem="EJD-f8-Xqd" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="55" id="XkO-FA-l3J"/>
<constraint firstItem="Sn1-dJ-QCw" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="55" id="aZT-2B-gv9"/>
<constraint firstItem="Rth-di-Tls" firstAttribute="trailing" secondItem="Ez2-Rf-DZN" secondAttribute="trailing" id="b6d-Ue-Zl5"/>
<constraint firstAttribute="trailing" secondItem="cFH-d7-Erh" secondAttribute="trailing" constant="10" id="bWY-wj-6dr"/>
......@@ -533,6 +533,7 @@
<userDefaultsController representsSharedInstance="YES" id="Zjc-KB-CJZ"/>
<viewController id="iH6-17-JsM" customClass="MessagesVC">
<connections>
<outlet property="containerView" destination="EJD-f8-Xqd" id="hoF-D3-hw1"/>
<outlet property="conversationView" destination="bOO-CW-S21" id="Vzg-3J-K2b"/>
</connections>
</viewController>
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14109"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
......@@ -422,23 +422,23 @@
</constraints>
</customView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Fzg-MB-mlx" userLabel="HomeView">
<rect key="frame" x="326" y="0.0" width="727" height="658"/>
<rect key="frame" x="325" y="0.0" width="728" height="658"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="6bh-ow-nJO" customClass="BackgroundView">
<rect key="frame" x="0.0" y="0.0" width="727" height="172"/>
<rect key="frame" x="0.0" y="0.0" width="728" height="172"/>
<constraints>
<constraint firstAttribute="height" constant="172" id="hCN-uz-Nmc"/>
</constraints>
</customView>
<customView focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="tSW-YT-asL">
<rect key="frame" x="0.0" y="0.0" width="727" height="658"/>
<rect key="frame" x="0.0" y="0.0" width="728" height="658"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="340" id="5yo-rb-X1O"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="725" id="ccX-uq-zuj"/>
</constraints>
</customView>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="dZR-JL-MY4">
<rect key="frame" x="263" y="229" width="200" height="200"/>
<rect key="frame" x="264" y="229" width="200" height="200"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="RCZ-Wt-iKD"/>
<constraint firstAttribute="height" constant="200" id="tSn-OT-Zn8"/>
......@@ -451,7 +451,7 @@
</userDefinedRuntimeAttributes>
</imageView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="D6e-KX-8gC">
<rect key="frame" x="103" y="194" width="520" height="270"/>
<rect key="frame" x="104" y="194" width="520" height="270"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kFj-Sh-o5u">
<rect key="frame" x="95" y="98" width="330" height="19"/>
......@@ -576,7 +576,7 @@
<constraint firstItem="Pav-Bw-GgK" firstAttribute="leading" secondItem="YgH-CN-tkB" secondAttribute="trailing" id="RdH-bx-3aI"/>
<constraint firstAttribute="trailing" secondItem="Fzg-MB-mlx" secondAttribute="trailing" id="T3I-2c-Eto"/>
<constraint firstItem="Fzg-MB-mlx" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" id="VUS-o0-RNY"/>
<constraint firstItem="Fzg-MB-mlx" firstAttribute="leading" secondItem="YgH-CN-tkB" secondAttribute="trailing" constant="2" id="Xgw-Na-kgh"/>
<constraint firstItem="Fzg-MB-mlx" firstAttribute="leading" secondItem="YgH-CN-tkB" secondAttribute="trailing" constant="1" id="Xgw-Na-kgh"/>
<constraint firstItem="Pav-Bw-GgK" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" id="hcV-ir-ZEc"/>
<constraint firstAttribute="bottom" secondItem="YgH-CN-tkB" secondAttribute="bottom" id="hkC-sf-sNA"/>
<constraint firstAttribute="bottom" secondItem="Fzg-MB-mlx" secondAttribute="bottom" id="tQc-0j-ggO"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment