blob: 2d86cc95f7d97d142d412dd28e71fa0cfb9b19c9 [file] [log] [blame]
Alexandre Lision0f66bd32016-01-18 11:30:45 -05001/*
Anthony Léonarde7d62ed2018-01-25 10:51:47 -05002 * Copyright (C) 2016-2018 Savoir-faire Linux Inc.
Alexandre Lision0f66bd32016-01-18 11:30:45 -05003 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Anthony Léonarde7d62ed2018-01-25 10:51:47 -05004 * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
Alexandre Lision0f66bd32016-01-18 11:30:45 -05005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#import "IMTableCellView.h"
Alexandre Lision0f66bd32016-01-18 11:30:45 -050022#import "NSColor+RingTheme.h"
23
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050024@implementation IMTableCellView {
25 uint64_t interaction;
26}
27
Alexandre Lision0f66bd32016-01-18 11:30:45 -050028@synthesize msgView;
29@synthesize photoView;
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050030@synthesize acceptButton;
31@synthesize declineButton;
32@synthesize progressIndicator;
33@synthesize statusLabel;
Alexandre Lision0f66bd32016-01-18 11:30:45 -050034
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050035- (void) setupDirection
Alexandre Lision0f66bd32016-01-18 11:30:45 -050036{
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050037 if ([self.identifier containsString:@"Right"]) {
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040038 self.msgBackground.pointerDirection = RIGHT;
Kateryna Kostiuk33089872017-07-14 16:43:59 -040039 self.msgBackground.bgColor = [NSColor ringLightBlue];
Alexandre Lision0f66bd32016-01-18 11:30:45 -050040 }
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040041 else {
42 self.msgBackground.pointerDirection = LEFT;
43 self.msgBackground.bgColor = [NSColor whiteColor];
44 }
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050045}
46
47- (void) setupForInteraction:(uint64_t)inter
48{
49 interaction = inter;
50 [self setupDirection];
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040051 [self.msgView setBackgroundColor:[NSColor clearColor]];
Alexandre Lision0f66bd32016-01-18 11:30:45 -050052 [self.msgView setString:@""];
53 [self.msgView setAutoresizingMask:NSViewWidthSizable];
Anthony Léonard3ad48112018-01-19 11:57:21 -050054 [self.msgView setAutoresizingMask:NSViewHeightSizable];
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040055 [self.msgBackground setAutoresizingMask:NSViewWidthSizable];
56 [self.msgBackground setAutoresizingMask:NSViewHeightSizable];
Alexandre Lision0f66bd32016-01-18 11:30:45 -050057 [self.msgView setEnabledTextCheckingTypes:NSTextCheckingTypeLink];
58 [self.msgView setAutomaticLinkDetectionEnabled:YES];
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050059 [self.msgView setEditable:NO];
60 if ([self.identifier containsString:@"Message"]) {
61 [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-5-[msgView]"
62 options:0
63 metrics:nil
64 views:NSDictionaryOfVariableBindings(msgView)]];
65 }
66}
Alexandre Lision0f66bd32016-01-18 11:30:45 -050067
68- (void) updateWidthConstraint:(CGFloat) newWidth
69{
70 [self.msgView removeConstraints:[self.msgView constraints]];
71 NSLayoutConstraint* constraint = [NSLayoutConstraint
72 constraintWithItem:self.msgView
73 attribute:NSLayoutAttributeWidth
74 relatedBy:NSLayoutRelationEqual
75 toItem: nil
76 attribute:NSLayoutAttributeWidth
77 multiplier:1.0f
78 constant:newWidth];
79
80 [self.msgView addConstraint:constraint];
81}
82
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050083- (uint64_t)interaction
84{
85 return interaction;
86}
87
Alexandre Lision0f66bd32016-01-18 11:30:45 -050088@end