Commit 0f66bd33 authored by Alexandre Lision's avatar Alexandre Lision

chat: add conversation screen

- ability to chat off call
- system notification on incoming msg
- notification in smartlist

Tuleap: #202
Change-Id: Ide10f80f677f23022ad4296a82ae122e69a892cc
parent 57227777
......@@ -111,7 +111,9 @@ SET(ringclient_CONTROLLERS
src/SmartViewVC.mm
src/SmartViewVC.h
src/BrokerVC.mm
src/BrokerVC.h)
src/BrokerVC.h
src/ConversationVC.mm
src/ConversationVC.h)
SET(ringclient_BACKENDS
src/backends/AddressBookBackend.mm
......@@ -133,7 +135,9 @@ SET(ringclient_VIEWS
src/views/ContextualTableCellView.mm
src/views/ContextualTableCellView.h
src/views/IconButton.h
src/views/IconButton.mm)
src/views/IconButton.mm
src/views/IMTableCellView.h
src/views/IMTableCellView.mm)
SET(ringclient_OTHERS
src/main.mm
......@@ -162,7 +166,8 @@ SET(ringclient_XIBS
RingWizard
CertificateWindow
PersonLinker
Broker)
Broker
Conversation)
# Icons
# This part tells CMake where to find and install the file itself
......@@ -174,6 +179,7 @@ SET(ring_ICONS
${CMAKE_CURRENT_SOURCE_DIR}/data/symbol_name.png
${CMAKE_CURRENT_SOURCE_DIR}/data/background_tile.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_accept.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_arrow_back.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_call.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_cancel.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_hangup.png
......@@ -193,6 +199,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_add_participant.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_merge_calls.png
${CMAKE_CURRENT_SOURCE_DIR}/data/default_user_icon.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ancrage.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_send.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/audio.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_person_add.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_persons.png
......
data/dark/ic_action_video.png

321 Bytes | W: | H:

data/dark/ic_action_video.png

224 Bytes | W: | H:

data/dark/ic_action_video.png
data/dark/ic_action_video.png
data/dark/ic_action_video.png
data/dark/ic_action_video.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -22,6 +22,8 @@
#import <qapplication.h>
#import <accountmodel.h>
#import <protocolmodel.h>
#import <media/recordingmodel.h>
#import <media/textrecording.h>
#import <QItemSelectionModel>
#import <account.h>
......@@ -79,13 +81,42 @@
[self showIncomingNotification:call];
}
});
QObject::connect(&Media::RecordingModel::instance(),
&Media::RecordingModel::newTextMessage,
[=](Media::TextRecording* t, ContactMethod* cm) {
BOOL shouldNotify = [[NSUserDefaults standardUserDefaults] boolForKey:Preferences::Notifications];
auto qIdx = t->instantTextMessagingModel()->index(t->instantTextMessagingModel()->rowCount()-1, 0);
// Don't show a notification if we are sending the text OR window already has focus OR user disabled notifications
if(qvariant_cast<Media::Media::Direction>(qIdx.data((int)Media::TextRecording::Role::Direction)) == Media::Media::Direction::OUT
|| self.ringWindowController.window.keyWindow || !shouldNotify)
return;
NSUserNotification* notification = [[NSUserNotification alloc] init];
NSString* localizedTitle = NSLocalizedString(([NSString stringWithFormat:@"Message from %@",
qIdx.data((int)Media::TextRecording::Role::AuthorDisplayname).toString().toNSString()]),
@"Text message notification title");
[notification setTitle:localizedTitle];
[notification setSoundName:NSUserNotificationDefaultSoundName];
[notification setSubtitle:qIdx.data().toString().toNSString()];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
});
}
- (void) showIncomingNotification:(Call*) call{
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Incoming call", call->peerName();
//notification.informativeText = @"A notification";
notification.soundName = NSUserNotificationDefaultSoundName;
NSString* localizedTitle = NSLocalizedString(([NSString stringWithFormat:@"Incoming call from %@",
call->peerName().toNSString()]),
@"Call notification title");
[notification setTitle:localizedTitle];
[notification setSoundName:NSUserNotificationDefaultSoundName];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
......@@ -99,7 +130,6 @@
- (void) showWizard
{
NSLog(@"Showing wizard");
if(self.wizard == nil) {
self.wizard = [[RingWizardWC alloc] initWithWindowNibName:@"RingWizard"];
}
......
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.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 3 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 <Cocoa/Cocoa.h>
@interface ConversationVC : NSViewController
-(void) initFrame;
-(void) animateIn;
-(IBAction) animateOut:(id)sender;
/**
* Message contained in messageField TextField.
* This is a KVO method to bind the text with the send Button
* if message.length is > 0, button is enabled, otherwise disabled
*/
@property (retain) NSString* message;
@end
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.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 3 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 "ConversationVC.h"
#import <QItemSelectionModel>
#import <qstring.h>
#import <QPixmap>
#import <QtMacExtras/qmacfunctions.h>
#import <media/media.h>
#import <recentmodel.h>
#import <person.h>
#import <contactmethod.h>
#import <media/text.h>
#import <media/textrecording.h>
#import <callmodel.h>
#import <globalinstances.h>
#import "views/IconButton.h"
#import "views/IMTableCellView.h"
#import "views/NSColor+RingTheme.h"
#import "QNSTreeController.h"
#import "delegates/ImageManipulationDelegate.h"
#import <QuartzCore/QuartzCore.h>
@interface ConversationVC () <NSOutlineViewDelegate> {
__unsafe_unretained IBOutlet IconButton* backButton;
__unsafe_unretained IBOutlet NSTextField* messageField;
QVector<ContactMethod*> contactMethods;
NSMutableString* textSelection;
QNSTreeController* treeController;
__unsafe_unretained IBOutlet NSView* sendPanel;
__unsafe_unretained IBOutlet NSTextField* conversationTitle;
__unsafe_unretained IBOutlet NSTextField* emptyConversationPlaceHolder;
__unsafe_unretained IBOutlet IconButton* sendButton;
__unsafe_unretained IBOutlet NSOutlineView* conversationView;
__unsafe_unretained IBOutlet NSPopUpButton* contactMethodsPopupButton;
}
@end
@implementation ConversationVC
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
[self.view setWantsLayer:YES];
[self.view setLayer:[CALayer layer]];
[self.view.layer setBackgroundColor:[NSColor ringGreyHighlight].CGColor];
[self.view.layer setCornerRadius:5.0f];
[sendPanel setWantsLayer:YES];
[sendPanel setLayer:[CALayer layer]];
[self setupChat];
}
- (void) initFrame
{
[self.view setFrame:self.view.superview.bounds];
[self.view setHidden:YES];
self.view.layer.position = self.view.frame.origin;
}
- (void) setupChat
{
QObject::connect(RecentModel::instance().selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
contactMethods = RecentModel::instance().getContactMethods(current);
if (contactMethods.isEmpty()) {
return ;
}
[contactMethodsPopupButton removeAllItems];
for (auto cm : contactMethods) {
[contactMethodsPopupButton addItemWithTitle:cm->uri().toNSString()];
}
[contactMethodsPopupButton setEnabled:(contactMethods.length() > 1)];
[emptyConversationPlaceHolder setHidden:NO];
// Select first cm
[contactMethodsPopupButton selectItemAtIndex:0];
[self itemChanged:contactMethodsPopupButton];
NSString* localizedTitle = current.data((int)Ring::Role::Name).toString().toNSString();
[conversationTitle setStringValue:localizedTitle];
});
}
- (IBAction)sendMessage:(id)sender
{
/* make sure there is text to send */
NSString* text = self.message;
if (text && text.length > 0) {
QMap<QString, QString> messages;
messages["text/plain"] = QString::fromNSString(text);
contactMethods.at([contactMethodsPopupButton indexOfSelectedItem])->sendOfflineTextMessage(messages);
self.message = @"";
}
}
- (IBAction)placeCall:(id)sender
{
if(auto cm = contactMethods.at([contactMethodsPopupButton indexOfSelectedItem])) {
auto c = CallModel::instance().dialingCall();
c->setPeerContactMethod(cm);
c << Call::Action::ACCEPT;
CallModel::instance().selectCall(c);
}
}
# pragma mark private IN/OUT animations
-(void) animateIn
{
CGRect frame = CGRectOffset(self.view.superview.bounds, -self.view.superview.bounds.size.width, 0);
[self.view setHidden:NO];
[CATransaction begin];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setFromValue:[NSValue valueWithPoint:frame.origin]];
[animation setToValue:[NSValue valueWithPoint:self.view.superview.bounds.origin]];
[animation setDuration:0.2f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[self.view.layer addAnimation:animation forKey:animation.keyPath];
[CATransaction commit];
}
-(IBAction) animateOut:(id)sender
{
if(self.view.frame.origin.x < 0) {
return;
}
CGRect frame = CGRectOffset(self.view.frame, -self.view.frame.size.width, 0);
[CATransaction begin];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setFromValue:[NSValue valueWithPoint:self.view.frame.origin]];
[animation setToValue:[NSValue valueWithPoint:frame.origin]];
[animation setDuration:0.2f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[CATransaction setCompletionBlock:^{
[self.view setHidden:YES];
}];
[self.view.layer addAnimation:animation forKey:animation.keyPath];
[self.view.layer setPosition:frame.origin];
[CATransaction commit];
}
#pragma mark - NSOutlineViewDelegate methods
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;
{
return YES;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
return YES;
}
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)];
auto dir = qvariant_cast<Media::Media::Direction>(qIdx.data((int)Media::TextRecording::Role::Direction));
IMTableCellView* result;
if (dir == Media::Media::Direction::IN) {
result = [outlineView makeViewWithIdentifier:@"LeftMessageView" owner:self];
} else {
result = [outlineView makeViewWithIdentifier:@"RightMessageView" owner:self];
}
[result setup];
NSMutableAttributedString* msgAttString =
[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n",qIdx.data((int)Qt::DisplayRole).toString().toNSString()]
attributes:[self messageAttributesFor:qIdx]];
NSAttributedString* timestampAttrString =
[[NSAttributedString alloc] initWithString:qIdx.data((int)Media::TextRecording::Role::FormattedDate).toString().toNSString()
attributes:[self timestampAttributesFor:qIdx]];
CGFloat finalWidth = MAX(msgAttString.size.width, timestampAttrString.size.width);
finalWidth = MIN(finalWidth + 30, result.frame.size.width - result.photoView.frame.size.width - 30);
[msgAttString appendAttributedString:timestampAttrString];
[[result.msgView textStorage] appendAttributedString:msgAttString];
[result.msgView checkTextInDocument:nil];
[result.msgView setWantsLayer:YES];
result.msgView.layer.cornerRadius = 5.0f;
[result updateWidthConstraint:finalWidth];
Person* p = qvariant_cast<Person*>(qIdx.data((int)Person::Role::Object));
QVariant photo = GlobalInstances::pixmapManipulator().contactPhoto(p, QSize(50,50));
[result.photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
return result;
}
- (void)outlineView:(NSOutlineView *)outlineView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row
{
if (auto txtRecording = contactMethods.at([contactMethodsPopupButton indexOfSelectedItem])->textRecording()) {
[emptyConversationPlaceHolder setHidden:txtRecording->instantMessagingModel()->rowCount() > 0];
txtRecording->setAllRead();
}
}
- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
{
QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)];
double someWidth = outlineView.frame.size.width;
NSMutableAttributedString* msgAttString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n",qIdx.data((int)Qt::DisplayRole).toString().toNSString()]
attributes:[self messageAttributesFor:qIdx]];
NSAttributedString *timestampAttrString = [[NSAttributedString alloc] initWithString:
qIdx.data((int)Media::TextRecording::Role::FormattedDate).toString().toNSString()
attributes:[self timestampAttributesFor:qIdx]];
[msgAttString appendAttributedString:timestampAttrString];
NSRect frame = NSMakeRect(0, 0, someWidth, MAXFLOAT);
NSTextView *tv = [[NSTextView alloc] initWithFrame:frame];
[tv setEnabledTextCheckingTypes:NSTextCheckingTypeLink];
[tv setAutomaticLinkDetectionEnabled:YES];
[[tv textStorage] setAttributedString:msgAttString];
[tv sizeToFit];
double height = tv.frame.size.height + 20;
return MAX(height, 60.0f);
}
#pragma mark - Text formatting
- (NSMutableDictionary*) timestampAttributesFor:(QModelIndex) qIdx
{
auto dir = qvariant_cast<Media::Media::Direction>(qIdx.data((int)Media::TextRecording::Role::Direction));
NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
if (dir == Media::Media::Direction::IN) {
attrs[NSForegroundColorAttributeName] = [NSColor grayColor];
} else {
attrs[NSForegroundColorAttributeName] = [NSColor whiteColor];
}
NSFont* systemFont = [NSFont systemFontOfSize:12.0f];
attrs[NSFontAttributeName] = systemFont;
attrs[NSParagraphStyleAttributeName] = [self paragraphStyle];
return attrs;
}
- (NSMutableDictionary*) messageAttributesFor:(QModelIndex) qIdx
{
auto dir = qvariant_cast<Media::Media::Direction>(qIdx.data((int)Media::TextRecording::Role::Direction));
NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
if (dir == Media::Media::Direction::IN) {
attrs[NSForegroundColorAttributeName] = [NSColor blackColor];
} else {
attrs[NSForegroundColorAttributeName] = [NSColor whiteColor];
}
NSFont* systemFont = [NSFont systemFontOfSize:14.0f];
attrs[NSFontAttributeName] = systemFont;
attrs[NSParagraphStyleAttributeName] = [self paragraphStyle];
return attrs;
}
- (NSParagraphStyle*) paragraphStyle
{
/*
The only way to instantiate an NSMutableParagraphStyle is to mutably copy an
NSParagraphStyle. And since we don't have an existing NSParagraphStyle available
to copy, we use the default one.
The default values supplied by the default NSParagraphStyle are:
Alignment NSNaturalTextAlignment
Tab stops 12 left-aligned tabs, spaced by 28.0 points
Line break mode NSLineBreakByWordWrapping
All others 0.0
*/
NSMutableParagraphStyle* aMutableParagraphStyle =
[[NSParagraphStyle defaultParagraphStyle] mutableCopy];
// Now adjust our NSMutableParagraphStyle formatting to be whatever we want.
// The numeric values below are in points (72 points per inch)
[aMutableParagraphStyle setAlignment:NSLeftTextAlignment];
[aMutableParagraphStyle setLineSpacing:1.5];
[aMutableParagraphStyle setParagraphSpacing:5.0];
[aMutableParagraphStyle setHeadIndent:5.0];
[aMutableParagraphStyle setTailIndent:-5.0];
[aMutableParagraphStyle setFirstLineHeadIndent:5.0];
[aMutableParagraphStyle setLineBreakMode:NSLineBreakByWordWrapping];
return aMutableParagraphStyle;
}
#pragma mark - NSTextFieldDelegate
- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
{
if (commandSelector == @selector(insertNewline:) && self.message.length > 0) {
[self sendMessage:nil];
return YES;
}
return NO;
}
#pragma mark - NSPopUpButton item selection
- (IBAction)itemChanged:(id)sender {
NSInteger index = [(NSPopUpButton *)sender indexOfSelectedItem];
if (auto txtRecording = contactMethods.at(index)->textRecording()) {
treeController = [[QNSTreeController alloc] initWithQModel:txtRecording->instantMessagingModel()];
[treeController setAvoidsEmptySelection:NO];
[treeController setChildrenKeyPath:@"children"];
[conversationView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil];
[conversationView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil];
[conversationView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil];
}
[conversationView scrollToEndOfDocument:nil];
}
@end
......@@ -28,6 +28,8 @@ class Call;
}
- (void) initFrame;
-(void) initFrame;
-(void) animateIn;
-(void) animateOut;
@end
......@@ -124,7 +124,7 @@
NSButton* a = actionHash[(int) action];
if (a) {
[a setHidden:!(idx.flags() & Qt::ItemIsEnabled)];
[a setState:(idx.data(Qt::CheckStateRole) == Qt::Checked) ? NSOnState : NSOffState];
[a setHighlighted:(idx.data(Qt::CheckStateRole) == Qt::Checked) ? YES : NO];
}
}
......@@ -245,7 +245,6 @@
[=](const QModelIndex &current, const QModelIndex &previous) {
auto call = RecentModel::instance().getActiveCall(current);
if(!current.isValid() || !call) {
[self animateOut];
return;
}
......@@ -258,7 +257,6 @@
[self collapseRightView];
[self updateCall];
[self updateAllActions];
[self animateOut];
});
QObject::connect(CallModel::instance().userActionModel(),
......
......@@ -17,16 +17,24 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "RingWindowController.h"
#import <QuartzCore/QuartzCore.h>
//Qt
#import <QItemSelectionModel>
#import <QItemSelection>
//LRC
#import <accountmodel.h>
#import <callmodel.h>
#import <account.h>
#import <call.h>
#import <recentmodel.h>
#import "AppDelegate.h"
#import "Constants.h"
#import "CurrentCallVC.h"
#import "ConversationVC.h"
#import "PreferencesWC.h"
#import "views/NSColor+RingTheme.h"
......@@ -37,7 +45,8 @@
__unsafe_unretained IBOutlet NSTextField *ringIDLabel;
PreferencesWC *preferencesWC;
CurrentCallVC* currentVC;
CurrentCallVC* currentCallVC;
ConversationVC* offlineVC;
}
static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
......@@ -46,23 +55,52 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
[super windowDidLoad];
[self.window setMovableByWindowBackground:YES];
currentVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil];
currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil];
offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil];
[callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[currentVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[offlineVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[callView addSubview:[currentVC view] positioned:NSWindowAbove relativeTo:nil];
[callView addSubview:[currentCallVC view] positioned:NSWindowAbove relativeTo:nil];
[callView addSubview:[offlineVC view] positioned:NSWindowAbove relativeTo:nil];
[currentVC initFrame];
[currentCallVC initFrame];
[offlineVC initFrame];
// Fresh run, we need to make sure RingID appears
[self updateRingID];