Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 1 | /* |
Anthony Léonard | cb73a2c | 2018-01-18 11:45:56 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2018 Savoir-faire Linux Inc. |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 4 | * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> |
| 5 | * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
| 22 | #import "SmartViewVC.h" |
| 23 | |
| 24 | //Qt |
| 25 | #import <QtMacExtras/qmacfunctions.h> |
| 26 | #import <QPixmap> |
| 27 | #import <QIdentityProxyModel> |
| 28 | #import <QItemSelectionModel> |
| 29 | |
| 30 | //LRC |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 31 | #import <globalinstances.h> |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 32 | #import <api/newaccountmodel.h> |
| 33 | #import <api/conversationmodel.h> |
| 34 | #import <api/account.h> |
| 35 | #import <api/contact.h> |
| 36 | #import <api/contactmodel.h> |
| 37 | #import <api/newcallmodel.h> |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 38 | |
| 39 | #import "QNSTreeController.h" |
| 40 | #import "delegates/ImageManipulationDelegate.h" |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 41 | #import "views/HoverTableRowView.h" |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 42 | #import "PersonLinkerVC.h" |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 43 | #import "views/IconButton.h" |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 44 | #import "views/RingTableView.h" |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 45 | #import "views/ContextualTableCellView.h" |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 46 | #import "utils.h" |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame] | 47 | #import "RingWindowController.h" |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 48 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 49 | @interface SmartViewVC () <NSTableViewDelegate, NSTableViewDataSource, NSPopoverDelegate, ContextMenuDelegate, ContactLinkedDelegate, KeyboardShortcutDelegate> { |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 50 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 51 | NSPopover* addToContactPopover; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 52 | |
| 53 | //UI elements |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 54 | __unsafe_unretained IBOutlet RingTableView* smartView; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 55 | __unsafe_unretained IBOutlet NSSearchField* searchField; |
Anthony Léonard | cb73a2c | 2018-01-18 11:45:56 -0500 | [diff] [blame] | 56 | __strong IBOutlet NSSegmentedControl *listTypeSelector; |
| 57 | bool selectorIsPresent; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 58 | |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 59 | QMetaObject::Connection modelSortedConnection_, modelUpdatedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_, interactionStatusUpdatedConnection_, conversationClearedConnection; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 60 | |
| 61 | lrc::api::ConversationModel* model_; |
| 62 | std::string selectedUid_; |
Anthony Léonard | 4bfd68b | 2018-01-15 16:23:50 -0500 | [diff] [blame] | 63 | lrc::api::profile::Type currentFilterType; |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame] | 64 | |
| 65 | __unsafe_unretained IBOutlet RingWindowController *delegate; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @end |
| 69 | |
| 70 | @implementation SmartViewVC |
| 71 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 72 | @synthesize tabbar; |
| 73 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 74 | // Tags for views |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 75 | NSInteger const IMAGE_TAG = 100; |
| 76 | NSInteger const DISPLAYNAME_TAG = 200; |
| 77 | NSInteger const DETAILS_TAG = 300; |
| 78 | NSInteger const CALL_BUTTON_TAG = 400; |
| 79 | NSInteger const TXT_BUTTON_TAG = 500; |
| 80 | NSInteger const CANCEL_BUTTON_TAG = 600; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 81 | NSInteger const RING_ID_LABEL = 700; |
Kateryna Kostiuk | d9039e9 | 2017-05-24 14:29:54 -0400 | [diff] [blame] | 82 | NSInteger const PRESENCE_TAG = 800; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 83 | |
Anthony Léonard | e6a01fa | 2018-01-12 10:29:58 -0500 | [diff] [blame] | 84 | // Segment indices for smartlist selector |
| 85 | NSInteger const CONVERSATION_SEG = 0; |
| 86 | NSInteger const REQUEST_SEG = 1; |
| 87 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 88 | - (void)awakeFromNib |
| 89 | { |
| 90 | NSLog(@"INIT SmartView VC"); |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 91 | //get selected account |
| 92 | //encapsulate conversationmodel in local version |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 93 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 94 | [smartView setTarget:self]; |
| 95 | [smartView setDoubleAction:@selector(placeCall:)]; |
| 96 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 97 | [smartView setContextMenuDelegate:self]; |
| 98 | [smartView setShortcutsDelegate:self]; |
| 99 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 100 | [smartView setDataSource: self]; |
Kateryna Kostiuk | 1f705ab | 2017-04-18 12:45:59 -0400 | [diff] [blame] | 101 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 102 | [self.view setWantsLayer:YES]; |
| 103 | [self.view setLayer:[CALayer layer]]; |
| 104 | [self.view.layer setBackgroundColor:[NSColor whiteColor].CGColor]; |
| 105 | |
| 106 | [searchField setWantsLayer:YES]; |
| 107 | [searchField setLayer:[CALayer layer]]; |
| 108 | [searchField.layer setBackgroundColor:[NSColor colorWithCalibratedRed:0.949 green:0.949 blue:0.949 alpha:0.9].CGColor]; |
Anthony Léonard | 4bfd68b | 2018-01-15 16:23:50 -0500 | [diff] [blame] | 109 | |
| 110 | currentFilterType = lrc::api::profile::Type::RING; |
Anthony Léonard | cb73a2c | 2018-01-18 11:45:56 -0500 | [diff] [blame] | 111 | selectorIsPresent = true; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | - (void)placeCall:(id)sender |
| 115 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 116 | NSInteger row; |
| 117 | if (sender != nil && [sender clickedRow] != -1) |
| 118 | row = [sender clickedRow]; |
| 119 | else if ([smartView selectedRow] != -1) |
| 120 | row = [smartView selectedRow]; |
| 121 | else |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 122 | return; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame^] | 123 | if (model_ == nil) |
| 124 | return; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 125 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 126 | auto conv = model_->filteredConversation(row); |
| 127 | model_->placeCall(conv.uid); |
| 128 | } |
| 129 | |
| 130 | -(void) reloadData |
| 131 | { |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 132 | NSLog(@"reload"); |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 133 | [smartView deselectAll:nil]; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame^] | 134 | if (model_ == nil) |
| 135 | return; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 136 | |
Anthony Léonard | 4bfd68b | 2018-01-15 16:23:50 -0500 | [diff] [blame] | 137 | if (!model_->owner.contactModel->hasPendingRequests()) { |
| 138 | if (currentFilterType == lrc::api::profile::Type::PENDING) { |
| 139 | [self selectConversationList]; |
| 140 | } |
Anthony Léonard | cb73a2c | 2018-01-18 11:45:56 -0500 | [diff] [blame] | 141 | if (selectorIsPresent) { |
| 142 | [listTypeSelector removeFromSuperview]; |
| 143 | selectorIsPresent = false; |
| 144 | } |
Anthony Léonard | 4bfd68b | 2018-01-15 16:23:50 -0500 | [diff] [blame] | 145 | } else { |
Anthony Léonard | cb73a2c | 2018-01-18 11:45:56 -0500 | [diff] [blame] | 146 | if (!selectorIsPresent) { |
| 147 | // First we restore the selector with selection on "Conversations" |
| 148 | [self.view addSubview:listTypeSelector]; |
| 149 | [listTypeSelector setSelected:YES forSegment:CONVERSATION_SEG]; |
| 150 | |
| 151 | // Then constraints are recreated (as these are lost when calling removeFromSuperview) |
| 152 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[searchField]-8-[listTypeSelector]" |
| 153 | options:0 |
| 154 | metrics:nil |
| 155 | views:NSDictionaryOfVariableBindings(searchField, listTypeSelector)]]; |
| 156 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[listTypeSelector]-8-[tabbar]" |
| 157 | options:0 |
| 158 | metrics:nil |
| 159 | views:NSDictionaryOfVariableBindings(listTypeSelector, tabbar)]]; |
| 160 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[listTypeSelector]-20-|" |
| 161 | options:0 |
| 162 | metrics:nil |
| 163 | views:NSDictionaryOfVariableBindings(listTypeSelector)]]; |
| 164 | selectorIsPresent = true; |
| 165 | } |
Anthony Léonard | 4bfd68b | 2018-01-15 16:23:50 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Anthony Léonard | cb73a2c | 2018-01-18 11:45:56 -0500 | [diff] [blame] | 168 | [smartView reloadData]; |
| 169 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 170 | if (!selectedUid_.empty() && model_ != nil) { |
Anthony Léonard | 6f81975 | 2018-01-05 09:53:40 -0500 | [diff] [blame] | 171 | auto it = getConversationFromUid(selectedUid_, *model_); |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 172 | if (it != model_->allFilteredConversations().end()) { |
| 173 | NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())]; |
| 174 | [smartView selectRowIndexes:indexSet byExtendingSelection:NO]; |
| 175 | } else { |
| 176 | selectedUid_.clear(); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 180 | [smartView scrollToBeginningOfDocument:nil]; |
| 181 | } |
| 182 | |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 183 | -(void) reloadConversationWithUid:(NSString *)uid |
| 184 | { |
| 185 | if (model_ != nil) { |
| 186 | auto it = getConversationFromUid(std::string([uid UTF8String]), *model_); |
| 187 | if (it != model_->allFilteredConversations().end()) { |
| 188 | NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())]; |
| 189 | NSLog(@"reloadConversationWithUid: %@", uid); |
| 190 | [smartView reloadDataForRowIndexes:indexSet |
| 191 | columnIndexes:[NSIndexSet indexSetWithIndex:0]]; |
| 192 | } |
| 193 | } |
| 194 | } |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 195 | |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 196 | - (BOOL)setConversationModel:(lrc::api::ConversationModel *)conversationModel |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 197 | { |
| 198 | if (model_ != conversationModel) { |
| 199 | model_ = conversationModel; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 200 | selectedUid_.clear(); // Clear selected conversation as the selected account is being changed |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 201 | QObject::disconnect(modelSortedConnection_); |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 202 | QObject::disconnect(modelUpdatedConnection_); |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 203 | QObject::disconnect(filterChangedConnection_); |
Anthony Léonard | 0163410 | 2017-12-27 16:37:16 -0500 | [diff] [blame] | 204 | QObject::disconnect(newConversationConnection_); |
| 205 | QObject::disconnect(conversationRemovedConnection_); |
Anthony Léonard | dd85dee | 2018-02-19 14:34:35 -0500 | [diff] [blame] | 206 | QObject::disconnect(interactionStatusUpdatedConnection_); |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 207 | QObject::disconnect(conversationClearedConnection); |
Anthony Léonard | cb73a2c | 2018-01-18 11:45:56 -0500 | [diff] [blame] | 208 | [self reloadData]; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 209 | if (model_ != nil) { |
| 210 | modelSortedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::modelSorted, |
| 211 | [self] (){ |
| 212 | [self reloadData]; |
| 213 | }); |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 214 | modelUpdatedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::conversationUpdated, |
| 215 | [self] (const std::string& uid){ |
| 216 | [self reloadConversationWithUid: [NSString stringWithUTF8String:uid.c_str()]]; |
| 217 | }); |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 218 | filterChangedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::filterChanged, |
| 219 | [self] (){ |
| 220 | [self reloadData]; |
| 221 | }); |
Anthony Léonard | 0163410 | 2017-12-27 16:37:16 -0500 | [diff] [blame] | 222 | newConversationConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::newConversation, |
| 223 | [self] (){ |
| 224 | [self reloadData]; |
| 225 | }); |
| 226 | conversationRemovedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::conversationRemoved, |
| 227 | [self] (){ |
| 228 | [self reloadData]; |
| 229 | }); |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 230 | conversationClearedConnection = QObject::connect(model_, &lrc::api::ConversationModel::conversationCleared, |
| 231 | [self] (const std::string& id){ |
| 232 | [self deselect]; |
| 233 | [delegate listTypeChanged]; |
| 234 | }); |
Anthony Léonard | dd85dee | 2018-02-19 14:34:35 -0500 | [diff] [blame] | 235 | interactionStatusUpdatedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::interactionStatusUpdated, |
| 236 | [self] (const std::string& convUid) { |
| 237 | if (convUid != selectedUid_) |
| 238 | return; |
Andreas Traczyk | 46d53af | 2018-04-13 16:00:17 -0400 | [diff] [blame] | 239 | [self reloadConversationWithUid: [NSString stringWithUTF8String:convUid.c_str()]]; |
Anthony Léonard | dd85dee | 2018-02-19 14:34:35 -0500 | [diff] [blame] | 240 | }); |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 241 | model_->setFilter(""); // Reset the filter |
| 242 | } |
| 243 | [searchField setStringValue:@""]; |
| 244 | return YES; |
| 245 | } |
| 246 | return NO; |
| 247 | } |
| 248 | |
| 249 | -(void)selectConversation:(const lrc::api::conversation::Info&)conv model:(lrc::api::ConversationModel*)model; |
| 250 | { |
| 251 | auto& uid = conv.uid; |
| 252 | if (selectedUid_ == uid) |
| 253 | return; |
| 254 | |
| 255 | [self setConversationModel:model]; |
| 256 | |
| 257 | if (model_ != nil) { |
Anthony Léonard | 6f81975 | 2018-01-05 09:53:40 -0500 | [diff] [blame] | 258 | auto it = getConversationFromUid(selectedUid_, *model_); |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 259 | if (it != model_->allFilteredConversations().end()) { |
| 260 | NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())]; |
| 261 | [smartView selectRowIndexes:indexSet byExtendingSelection:NO]; |
| 262 | selectedUid_ = uid; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 263 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 267 | -(void)deselect |
| 268 | { |
| 269 | selectedUid_.clear(); |
| 270 | [smartView deselectAll:nil]; |
| 271 | } |
| 272 | |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame^] | 273 | -(void) clearConversationModel { |
| 274 | model_ = nil; |
| 275 | [self deselect]; |
| 276 | [smartView reloadData]; |
| 277 | } |
| 278 | |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 279 | - (IBAction) listTypeChanged:(id)sender |
| 280 | { |
| 281 | NSInteger selectedItem = [sender selectedSegment]; |
Anthony Léonard | e6a01fa | 2018-01-12 10:29:58 -0500 | [diff] [blame] | 282 | switch (selectedItem) { |
| 283 | case CONVERSATION_SEG: |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame] | 284 | if (currentFilterType != lrc::api::profile::Type::RING) { |
| 285 | model_->setFilter(lrc::api::profile::Type::RING); |
| 286 | [delegate listTypeChanged]; |
| 287 | currentFilterType = lrc::api::profile::Type::RING; |
| 288 | } |
Anthony Léonard | e6a01fa | 2018-01-12 10:29:58 -0500 | [diff] [blame] | 289 | break; |
| 290 | case REQUEST_SEG: |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame] | 291 | if (currentFilterType != lrc::api::profile::Type::PENDING) { |
| 292 | model_->setFilter(lrc::api::profile::Type::PENDING); |
| 293 | [delegate listTypeChanged]; |
| 294 | currentFilterType = lrc::api::profile::Type::PENDING; |
| 295 | } |
Anthony Léonard | e6a01fa | 2018-01-12 10:29:58 -0500 | [diff] [blame] | 296 | break; |
| 297 | default: |
| 298 | NSLog(@"Invalid item selected in list selector: %d", selectedItem); |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | -(void) selectConversationList |
| 303 | { |
Anthony Léonard | d00cd18 | 2018-01-17 09:21:27 -0500 | [diff] [blame] | 304 | if (currentFilterType == lrc::api::profile::Type::RING) |
| 305 | return; |
Anthony Léonard | e6a01fa | 2018-01-12 10:29:58 -0500 | [diff] [blame] | 306 | [listTypeSelector setSelectedSegment:CONVERSATION_SEG]; |
Anthony Léonard | 4bfd68b | 2018-01-15 16:23:50 -0500 | [diff] [blame] | 307 | |
| 308 | // Do not invert order of the next two lines or stack overflow |
| 309 | // may happen on -(void) reloadData call if filter is currently set to PENDING |
| 310 | currentFilterType = lrc::api::profile::Type::RING; |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 311 | model_->setFilter(lrc::api::profile::Type::RING); |
Anthony Léonard | 4bfd68b | 2018-01-15 16:23:50 -0500 | [diff] [blame] | 312 | model_->setFilter(""); |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 313 | } |
| 314 | |
Anthony Léonard | d00cd18 | 2018-01-17 09:21:27 -0500 | [diff] [blame] | 315 | -(void) selectPendingList |
| 316 | { |
| 317 | if (currentFilterType == lrc::api::profile::Type::PENDING) |
| 318 | return; |
| 319 | [listTypeSelector setSelectedSegment:REQUEST_SEG]; |
| 320 | |
| 321 | currentFilterType = lrc::api::profile::Type::PENDING; |
| 322 | model_->setFilter(lrc::api::profile::Type::PENDING); |
| 323 | model_->setFilter(""); |
| 324 | } |
| 325 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 326 | #pragma mark - NSTableViewDelegate methods |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 327 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 328 | - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 329 | { |
| 330 | return YES; |
| 331 | } |
| 332 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 333 | - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 334 | { |
| 335 | return NO; |
| 336 | } |
| 337 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 338 | - (void)tableViewSelectionDidChange:(NSNotification *)notification |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 339 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 340 | NSInteger row = [notification.object selectedRow]; |
| 341 | |
| 342 | if (row == -1) |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 343 | return; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame^] | 344 | if (model_ == nil) |
| 345 | return; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 346 | |
| 347 | auto uid = model_->filteredConversation(row).uid; |
| 348 | if (selectedUid_ != uid) { |
| 349 | selectedUid_ = uid; |
| 350 | model_->selectConversation(uid); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 351 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 352 | } |
| 353 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 354 | - (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 355 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 356 | return [tableView makeViewWithIdentifier:@"HoverRowView" owner:nil]; |
| 357 | } |
Alexandre Lision | a4bb051 | 2016-04-19 18:04:31 -0400 | [diff] [blame] | 358 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 359 | - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
| 360 | { |
| 361 | if (model_ == nil) |
| 362 | return nil; |
| 363 | |
| 364 | auto conversation = model_->filteredConversation(row); |
Alexandre Lision | a4bb051 | 2016-04-19 18:04:31 -0400 | [diff] [blame] | 365 | NSTableCellView* result; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 366 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 367 | result = [tableView makeViewWithIdentifier:@"MainCell" owner:tableView]; |
| 368 | // NSTextField* details = [result viewWithTag:DETAILS_TAG]; |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 369 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 370 | NSMutableArray* controls = [NSMutableArray arrayWithObject:[result viewWithTag:CALL_BUTTON_TAG]]; |
| 371 | [((ContextualTableCellView*) result) setContextualsControls:controls]; |
| 372 | [((ContextualTableCellView*) result) setShouldBlurParentView:YES]; |
Alexandre Lision | 21666f3 | 2015-09-22 17:04:36 -0400 | [diff] [blame] | 373 | |
Andreas Traczyk | 3b98eb8 | 2018-03-29 17:54:42 -0400 | [diff] [blame] | 374 | // if (auto call = RecentModel::instance().getActiveCall(qIdx)) { |
| 375 | // [details setStringValue:call->roleData((int)Ring::Role::FormattedState).toString().toNSString()]; |
| 376 | // [((ContextualTableCellView*) result) setActiveState:YES]; |
| 377 | // } else { |
| 378 | // [details setStringValue:qIdx.data((int)Ring::Role::FormattedLastUsed).toString().toNSString()]; |
| 379 | // [((ContextualTableCellView*) result) setActiveState:NO]; |
| 380 | // } |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 381 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 382 | NSTextField* unreadCount = [result viewWithTag:TXT_BUTTON_TAG]; |
| 383 | [unreadCount setHidden:(conversation.unreadMessages == 0)]; |
| 384 | [unreadCount setIntValue:conversation.unreadMessages]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 385 | |
| 386 | NSTextField* displayName = [result viewWithTag:DISPLAYNAME_TAG]; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 387 | NSString* displayNameString = bestNameForConversation(conversation, *model_); |
| 388 | NSString* displayIDString = bestIDForConversation(conversation, *model_); |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 389 | if(displayNameString.length == 0 || [displayNameString isEqualToString:displayIDString]) { |
Anthony Léonard | 4adc3f0 | 2017-07-21 10:23:04 -0400 | [diff] [blame] | 390 | NSTextField* displayRingID = [result viewWithTag:RING_ID_LABEL]; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 391 | [displayName setStringValue:displayIDString]; |
Anthony Léonard | 4adc3f0 | 2017-07-21 10:23:04 -0400 | [diff] [blame] | 392 | [displayRingID setHidden:YES]; |
Kateryna Kostiuk | 9d6657a | 2017-04-25 13:42:25 -0400 | [diff] [blame] | 393 | } |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 394 | else { |
| 395 | NSTextField* displayRingID = [result viewWithTag:RING_ID_LABEL]; |
| 396 | [displayName setStringValue:displayNameString]; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 397 | [displayRingID setStringValue:displayIDString]; |
Anthony Léonard | 4adc3f0 | 2017-07-21 10:23:04 -0400 | [diff] [blame] | 398 | [displayRingID setHidden:NO]; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 399 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 400 | NSImageView* photoView = [result viewWithTag:IMAGE_TAG]; |
Alexandre Lision | 43e91bc | 2016-04-19 18:04:52 -0400 | [diff] [blame] | 401 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 402 | auto& imageManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator()); |
| 403 | [photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(imageManip.conversationPhoto(conversation, model_->owner)))]; |
Kateryna Kostiuk | d9039e9 | 2017-05-24 14:29:54 -0400 | [diff] [blame] | 404 | |
| 405 | NSView* presenceView = [result viewWithTag:PRESENCE_TAG]; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 406 | if (model_->owner.contactModel->getContact(conversation.participants[0]).isPresent) { |
Kateryna Kostiuk | d9039e9 | 2017-05-24 14:29:54 -0400 | [diff] [blame] | 407 | [presenceView setHidden:NO]; |
| 408 | } else { |
| 409 | [presenceView setHidden:YES]; |
| 410 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 411 | return result; |
| 412 | } |
| 413 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 414 | - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 415 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 416 | return 60.0; |
| 417 | } |
| 418 | |
| 419 | #pragma mark - NSTableDataSource methods |
| 420 | |
| 421 | - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView |
| 422 | { |
| 423 | if (tableView == smartView) { |
| 424 | if (model_ != nullptr) |
| 425 | return model_->allFilteredConversations().size(); |
| 426 | } |
| 427 | |
| 428 | return 0; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 429 | } |
| 430 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 431 | - (void)startCallForRow:(id)sender { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 432 | NSInteger row = [smartView rowForView:sender]; |
| 433 | [smartView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; |
| 434 | [self placeCall:nil]; |
| 435 | } |
| 436 | |
| 437 | - (IBAction)hangUpClickedAtRow:(id)sender { |
| 438 | NSInteger row = [smartView rowForView:sender]; |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 439 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 440 | if (row == -1) |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 441 | return; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame^] | 442 | if (model_ == nil) |
| 443 | return; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 444 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 445 | auto conv = model_->filteredConversation(row); |
| 446 | auto& callId = conv.callId; |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 447 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 448 | if (callId.empty()) |
| 449 | return; |
| 450 | |
| 451 | auto* callModel = model_->owner.callModel.get(); |
| 452 | callModel->hangUp(callId); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 453 | } |
| 454 | |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 455 | - (void) displayErrorModalWithTitle:(NSString*) title WithMessage:(NSString*) message |
| 456 | { |
| 457 | NSAlert* alert = [NSAlert alertWithMessageText:title |
| 458 | defaultButton:@"Ok" |
| 459 | alternateButton:nil |
| 460 | otherButton:nil |
| 461 | informativeTextWithFormat:message]; |
| 462 | |
| 463 | [alert beginSheetModalForWindow:self.view.window modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; |
| 464 | } |
| 465 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 466 | - (void) processSearchFieldInput |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 467 | { |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame^] | 468 | if (model_ == nil) |
| 469 | return; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 470 | model_->setFilter(std::string([[searchField stringValue] UTF8String])); |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 471 | } |
| 472 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 473 | -(const lrc::api::account::Info&) chosenAccount |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 474 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 475 | return model_->owner; |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 476 | } |
| 477 | |
Alexandre Lision | f909fb1 | 2016-11-03 12:35:36 -0400 | [diff] [blame] | 478 | - (void) clearSearchField |
| 479 | { |
| 480 | [searchField setStringValue:@""]; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 481 | [self processSearchFieldInput]; |
Kateryna Kostiuk | 9dd759c | 2017-07-11 12:06:55 -0400 | [diff] [blame] | 482 | } |
| 483 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 484 | /** |
| 485 | Copy a NSString in the general Pasteboard |
| 486 | |
| 487 | @param sender the NSObject containing the represented object to copy |
| 488 | */ |
| 489 | - (void) copyStringToPasteboard:(id) sender |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 490 | { |
| 491 | NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard]; |
| 492 | [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
| 493 | [pasteBoard setString:[sender representedObject] forType:NSStringPboardType]; |
| 494 | } |
| 495 | |
Alexandre Lision | bf0385e | 2015-10-22 17:36:28 -0400 | [diff] [blame] | 496 | #pragma NSTextFieldDelegate |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 497 | |
| 498 | - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector |
| 499 | { |
Kateryna Kostiuk | 0febcfa | 2018-04-04 11:14:51 -0400 | [diff] [blame] | 500 | if (commandSelector != @selector(insertNewline:) || [[searchField stringValue] isEqual:@""]) { |
| 501 | return NO; |
| 502 | } |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame^] | 503 | if (model_ == nil) { |
| 504 | [self displayErrorModalWithTitle:NSLocalizedString(@"No account available", @"Displayed as RingID when no accounts are available for selection") WithMessage:NSLocalizedString(@"Navigate to preferences to create a new account", @"Allert message when no accounts are available")]; |
| 505 | return NO; |
| 506 | } |
Kateryna Kostiuk | 0febcfa | 2018-04-04 11:14:51 -0400 | [diff] [blame] | 507 | if (model_->allFilteredConversations().size() <= 0) { |
| 508 | return YES; |
| 509 | } |
| 510 | auto model = model_->filteredConversation(0); |
| 511 | auto uid = model.uid; |
| 512 | if (selectedUid_ == uid) { |
| 513 | return YES; |
| 514 | } |
| 515 | @try { |
| 516 | auto contact = model_->owner.contactModel->getContact(model.participants[0]); |
| 517 | if ((contact.profileInfo.uri.empty() && contact.profileInfo.type != lrc::api::profile::Type::SIP) || contact.profileInfo.type == lrc::api::profile::Type::INVALID) { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 518 | return YES; |
| 519 | } |
Kateryna Kostiuk | 0febcfa | 2018-04-04 11:14:51 -0400 | [diff] [blame] | 520 | selectedUid_ = uid; |
| 521 | model_->selectConversation(uid); |
| 522 | [self.view.window makeFirstResponder: smartView]; |
| 523 | searchField.stringValue = @""; |
| 524 | return YES; |
| 525 | } @catch (NSException *exception) { |
| 526 | return YES; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 527 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 528 | } |
| 529 | |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 530 | - (void)controlTextDidChange:(NSNotification *) notification |
| 531 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 532 | [self processSearchFieldInput]; |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 533 | } |
| 534 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 535 | #pragma mark - NSPopOverDelegate |
| 536 | |
| 537 | - (void)popoverDidClose:(NSNotification *)notification |
| 538 | { |
| 539 | if (addToContactPopover != nullptr) { |
| 540 | [addToContactPopover performClose:self]; |
| 541 | addToContactPopover = NULL; |
| 542 | } |
| 543 | } |
| 544 | |
Alexandre Lision | bf0385e | 2015-10-22 17:36:28 -0400 | [diff] [blame] | 545 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 546 | #pragma mark - ContactLinkedDelegate |
| 547 | |
| 548 | - (void)contactLinked |
| 549 | { |
| 550 | if (addToContactPopover != nullptr) { |
| 551 | [addToContactPopover performClose:self]; |
| 552 | addToContactPopover = NULL; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | #pragma mark - KeyboardShortcutDelegate |
| 557 | |
| 558 | - (void) onAddShortcut |
| 559 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 560 | if ([smartView selectedRow] == -1) |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 561 | return; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame^] | 562 | if (model_ == nil) |
| 563 | return ; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 564 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame] | 565 | auto uid = model_->filteredConversation([smartView selectedRow]).uid; |
| 566 | model_->makePermanent(uid); |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | #pragma mark - ContextMenuDelegate |
| 570 | |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 571 | - (NSMenu*) contextualMenuForRow:(int) index |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 572 | { |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 573 | if (model_ == nil) |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 574 | return nil; |
| 575 | |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 576 | auto conversation = model_->filteredConversation(NSInteger(index)); |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 577 | |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 578 | @try { |
| 579 | auto contact = model_->owner.contactModel->getContact(conversation.participants[0]); |
| 580 | if (contact.profileInfo.type == lrc::api::profile::Type::INVALID) { |
| 581 | return nil; |
| 582 | } |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 583 | |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 584 | BOOL isSIP = false; |
| 585 | BOOL isRingContact = false; |
| 586 | /* for SIP contact show only call menu options |
| 587 | * if contact does not have uri that is not RING contact |
| 588 | * for trusted Ring contact show option block contact |
| 589 | * for untrasted contact show option add contact |
| 590 | */ |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 591 | |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 592 | if (contact.profileInfo.type == lrc::api::profile::Type::SIP) { |
| 593 | isSIP = true; |
| 594 | } else if (contact.profileInfo.uri.empty()) { |
| 595 | return nil; |
| 596 | } |
| 597 | |
| 598 | else if (contact.profileInfo.type == lrc::api::profile::Type::RING && contact.isTrusted == true) { |
| 599 | isRingContact = true; |
| 600 | } |
| 601 | auto conversationUD = conversation.uid; |
| 602 | NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@""]; |
| 603 | NSString* conversationUID = @(conversationUD.c_str()); |
| 604 | NSMenuItem* separator = [NSMenuItem separatorItem]; |
| 605 | NSMenuItem* videoCallItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Place video call", |
| 606 | @"Contextual menu action") |
| 607 | action:@selector(videoCall:) |
| 608 | keyEquivalent:@""]; |
| 609 | NSMenuItem* audioCallItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Place audio call", |
| 610 | @"Contextual menu action") |
| 611 | action:@selector(audioCall:) |
| 612 | keyEquivalent:@""]; |
| 613 | [videoCallItem setRepresentedObject: conversationUID]; |
| 614 | [audioCallItem setRepresentedObject: conversationUID]; |
| 615 | [theMenu addItem:videoCallItem]; |
| 616 | [theMenu addItem:audioCallItem]; |
| 617 | if (isSIP == false) { |
| 618 | [theMenu addItem:separator]; |
| 619 | NSMenuItem* clearConversationItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Clear conversation", @"Contextual menu action") |
| 620 | action:@selector(clearConversation:) |
| 621 | keyEquivalent:@""]; |
| 622 | [clearConversationItem setRepresentedObject: conversationUID]; |
| 623 | [theMenu addItem:clearConversationItem]; |
| 624 | if(isRingContact) { |
| 625 | NSMenuItem* blockContactItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Block contact", @"Contextual menu action") |
| 626 | action:@selector(blockContact:) |
| 627 | keyEquivalent:@""]; |
| 628 | [blockContactItem setRepresentedObject: conversationUID]; |
| 629 | [theMenu addItem:blockContactItem]; |
| 630 | } else { |
| 631 | NSMenuItem* addContactItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action") |
| 632 | action:@selector(addContact:) |
| 633 | keyEquivalent:@"A"]; |
| 634 | [addContactItem setRepresentedObject: conversationUID]; |
| 635 | [theMenu addItem:addContactItem]; |
| 636 | } |
| 637 | } |
| 638 | return theMenu; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 639 | } |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 640 | @catch (NSException *exception) { |
| 641 | return nil; |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 642 | } |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 643 | } |
Kateryna Kostiuk | d51a325 | 2018-04-04 09:20:37 -0400 | [diff] [blame] | 644 | |
| 645 | - (void) addContact: (NSMenuItem* ) item { |
| 646 | auto menuObject = item.representedObject; |
| 647 | if(menuObject == nil) { |
| 648 | return; |
| 649 | } |
| 650 | NSString * convUId = (NSString*)menuObject; |
| 651 | std::string conversationID = std::string([convUId UTF8String]); |
| 652 | model_->makePermanent(conversationID); |
| 653 | } |
| 654 | |
| 655 | - (void) blockContact: (NSMenuItem* ) item { |
| 656 | auto menuObject = item.representedObject; |
| 657 | if(menuObject == nil) { |
| 658 | return; |
| 659 | } |
| 660 | NSString * convUId = (NSString*)menuObject; |
| 661 | std::string conversationID = std::string([convUId UTF8String]); |
| 662 | model_->clearHistory(conversationID); |
| 663 | model_->removeConversation(conversationID, true); |
| 664 | } |
| 665 | |
| 666 | - (void) audioCall: (NSMenuItem* ) item { |
| 667 | auto menuObject = item.representedObject; |
| 668 | if(menuObject == nil) { |
| 669 | return; |
| 670 | } |
| 671 | NSString * convUId = (NSString*)menuObject; |
| 672 | std::string conversationID = std::string([convUId UTF8String]); |
| 673 | model_->placeAudioOnlyCall(conversationID); |
| 674 | |
| 675 | } |
| 676 | |
| 677 | - (void) videoCall: (NSMenuItem* ) item { |
| 678 | auto menuObject = item.representedObject; |
| 679 | if(menuObject == nil) { |
| 680 | return; |
| 681 | } |
| 682 | NSString * convUId = (NSString*)menuObject; |
| 683 | std::string conversationID = std::string([convUId UTF8String]); |
| 684 | model_->placeCall(conversationID); |
| 685 | } |
| 686 | |
| 687 | - (void) clearConversation:(NSMenuItem* ) item { |
| 688 | auto menuObject = item.representedObject; |
| 689 | if(menuObject == nil) { |
| 690 | return; |
| 691 | } |
| 692 | NSString * convUId = (NSString*)menuObject; |
| 693 | std::string conversationID = std::string([convUId UTF8String]); |
| 694 | model_->clearHistory(conversationID); |
| 695 | } |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 696 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 697 | @end |