blob: 5a3a9ed715ee41c3c7d5b471995fbfb9cda4da36 [file] [log] [blame]
Alexandre Lision58cab672015-06-09 15:25:40 -04001/*
Anthony Léonard2382b562017-12-13 15:51:28 -05002 * Copyright (C) 2015-2017 Savoir-faire Linux Inc.
Alexandre Lision58cab672015-06-09 15:25:40 -04003 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Anthony Léonard2382b562017-12-13 15:51:28 -05004 * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
Alexandre Lision58cab672015-06-09 15:25:40 -04005 *
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.
Alexandre Lision58cab672015-06-09 15:25:40 -040019 */
20
21#import "ChatVC.h"
22
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040023#import "MessagesVC.h"
24
Anthony Léonard2382b562017-12-13 15:51:28 -050025@interface ChatVC ()
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040026{
Anthony Léonard2382b562017-12-13 15:51:28 -050027 IBOutlet MessagesVC* messagesViewVC;
28
29 std::string convUid_;
30 lrc::api::ConversationModel* convModel_;
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040031}
Alexandre Lision58cab672015-06-09 15:25:40 -040032
Alexandre Lision58cab672015-06-09 15:25:40 -040033@property (unsafe_unretained) IBOutlet NSTextField *messageField;
34@property (unsafe_unretained) IBOutlet NSButton *sendButton;
35
Alexandre Lision58cab672015-06-09 15:25:40 -040036@end
37
38@implementation ChatVC
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040039
40
Anthony Léonard2382b562017-12-13 15:51:28 -050041@synthesize messageField,sendButton;
Alexandre Lision58cab672015-06-09 15:25:40 -040042
43- (void)awakeFromNib
44{
45 NSLog(@"Init ChatVC");
46
47 [self.view setWantsLayer:YES];
48 [self.view setLayer:[CALayer layer]];
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040049 [self.view.layer setBackgroundColor:[NSColor controlColor].CGColor];
Alexandre Lision58cab672015-06-09 15:25:40 -040050}
51
Anthony Léonard2382b562017-12-13 15:51:28 -050052-(void)setConversationUid:(const std::string)convUid model:(lrc::api::ConversationModel *)model
Alexandre Lision58cab672015-06-09 15:25:40 -040053{
Anthony Léonard2382b562017-12-13 15:51:28 -050054 convUid_ = convUid;
55 convModel_ = model;
Alexandre Lision58cab672015-06-09 15:25:40 -040056
Anthony Léonard2382b562017-12-13 15:51:28 -050057 [messagesViewVC setConversationUid:convUid_ model:convModel_];
Alexandre Lision58cab672015-06-09 15:25:40 -040058}
59
Alexandre Lision16d9c0a2015-08-10 12:05:15 -040060- (void) takeFocus
61{
62 [self.view.window makeFirstResponder:self.messageField];
63}
64
Alexandre Lision58cab672015-06-09 15:25:40 -040065- (IBAction)sendMessage:(id)sender {
Alexandre Lision58cab672015-06-09 15:25:40 -040066 /* make sure there is text to send */
67 NSString* text = self.message;
68 if (text && text.length > 0) {
Anthony Léonard2382b562017-12-13 15:51:28 -050069 convModel_->sendMessage(convUid_, std::string([text UTF8String]));
Alexandre Lision58cab672015-06-09 15:25:40 -040070 self.message = @"";
Anthony Léonard2382b562017-12-13 15:51:28 -050071 [messageField setStringValue:@""];
72 [messagesViewVC newMessageSent];
Alexandre Lision58cab672015-06-09 15:25:40 -040073 }
74}
75
76#pragma mark - NSTextFieldDelegate
77
78- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
79{
80 if (commandSelector == @selector(insertNewline:) && self.message.length > 0) {
81 [self sendMessage:nil];
82 return YES;
83 }
84 return NO;
85}
86
87@end