blob: 6174038fe108a95e34a58a03608bcfbc26c27fe9 [file] [log] [blame]
Alexandre Lision4dfcafc2015-08-20 12:43:23 -04001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lision4dfcafc2015-08-20 12:43:23 -04003 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Olivier Soldanod4311552017-11-20 15:09:53 -05004 * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
5 * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
Alexandre Lision4dfcafc2015-08-20 12:43:23 -04006 *
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 Lision4dfcafc2015-08-20 12:43:23 -040031#import <globalinstances.h>
Olivier Soldanod4311552017-11-20 15:09:53 -050032#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 Lision4dfcafc2015-08-20 12:43:23 -040038
39#import "QNSTreeController.h"
40#import "delegates/ImageManipulationDelegate.h"
Alexandre Lision4e280d62015-09-09 15:56:30 -040041#import "views/HoverTableRowView.h"
Alexandre Lision61db3552015-10-22 19:12:52 -040042#import "PersonLinkerVC.h"
Alexandre Lision4baba4c2016-02-11 13:00:57 -050043#import "views/IconButton.h"
Olivier Soldanod4311552017-11-20 15:09:53 -050044#import "views/RingTableView.h"
Alexandre Lision4e280d62015-09-09 15:56:30 -040045#import "views/ContextualTableCellView.h"
Olivier Soldanod4311552017-11-20 15:09:53 -050046#import "utils.h"
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040047
Olivier Soldanod4311552017-11-20 15:09:53 -050048@interface SmartViewVC () <NSTableViewDelegate, NSTableViewDataSource, NSPopoverDelegate, ContextMenuDelegate, ContactLinkedDelegate, KeyboardShortcutDelegate> {
Alexandre Lision0f66bd32016-01-18 11:30:45 -050049
Alexandre Lision61db3552015-10-22 19:12:52 -040050 NSPopover* addToContactPopover;
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040051
52 //UI elements
Olivier Soldanod4311552017-11-20 15:09:53 -050053 __unsafe_unretained IBOutlet RingTableView* smartView;
Alexandre Lision61db3552015-10-22 19:12:52 -040054 __unsafe_unretained IBOutlet NSSearchField* searchField;
Alexandre Lision45c18672016-11-02 15:24:45 -040055
Anthony Léonard01634102017-12-27 16:37:16 -050056 QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_;
Olivier Soldanod4311552017-11-20 15:09:53 -050057
58 lrc::api::ConversationModel* model_;
59 std::string selectedUid_;
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040060}
61
62@end
63
64@implementation SmartViewVC
65
Kateryna Kostiuk882cbac2017-07-05 17:29:00 -040066@synthesize tabbar;
67
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040068// Tags for views
Alexandre Lision57914fa2016-02-10 14:52:24 -050069NSInteger const IMAGE_TAG = 100;
70NSInteger const DISPLAYNAME_TAG = 200;
71NSInteger const DETAILS_TAG = 300;
72NSInteger const CALL_BUTTON_TAG = 400;
73NSInteger const TXT_BUTTON_TAG = 500;
74NSInteger const CANCEL_BUTTON_TAG = 600;
Kateryna Kostiuk6a536362017-05-02 14:26:12 -040075NSInteger const RING_ID_LABEL = 700;
Kateryna Kostiukd9039e92017-05-24 14:29:54 -040076NSInteger const PRESENCE_TAG = 800;
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040077
78- (void)awakeFromNib
79{
80 NSLog(@"INIT SmartView VC");
Olivier Soldanod4311552017-11-20 15:09:53 -050081 //get selected account
82 //encapsulate conversationmodel in local version
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040083
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040084 [smartView setTarget:self];
85 [smartView setDoubleAction:@selector(placeCall:)];
86
Alexandre Lision61db3552015-10-22 19:12:52 -040087 [smartView setContextMenuDelegate:self];
88 [smartView setShortcutsDelegate:self];
89
Olivier Soldanod4311552017-11-20 15:09:53 -050090 [smartView setDataSource: self];
Kateryna Kostiuk1f705ab2017-04-18 12:45:59 -040091
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040092 [self.view setWantsLayer:YES];
93 [self.view setLayer:[CALayer layer]];
94 [self.view.layer setBackgroundColor:[NSColor whiteColor].CGColor];
95
96 [searchField setWantsLayer:YES];
97 [searchField setLayer:[CALayer layer]];
98 [searchField.layer setBackgroundColor:[NSColor colorWithCalibratedRed:0.949 green:0.949 blue:0.949 alpha:0.9].CGColor];
99}
100
101- (void)placeCall:(id)sender
102{
Olivier Soldanod4311552017-11-20 15:09:53 -0500103 NSInteger row;
104 if (sender != nil && [sender clickedRow] != -1)
105 row = [sender clickedRow];
106 else if ([smartView selectedRow] != -1)
107 row = [smartView selectedRow];
108 else
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400109 return;
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400110
Olivier Soldanod4311552017-11-20 15:09:53 -0500111 auto conv = model_->filteredConversation(row);
112 model_->placeCall(conv.uid);
113}
114
115-(void) reloadData
116{
117 [smartView deselectAll:nil];
118 [smartView reloadData];
119
120 if (!selectedUid_.empty() && model_ != nil) {
121 auto it = std::find_if(model_->allFilteredConversations().begin(), model_->allFilteredConversations().end(),
122 [self] (const lrc::api::conversation::Info& conv) {
123 return selectedUid_ == conv.uid;
124 });
125 if (it != model_->allFilteredConversations().end()) {
126 NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())];
127 [smartView selectRowIndexes:indexSet byExtendingSelection:NO];
128 } else {
129 selectedUid_.clear();
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400130 }
131 }
132
Olivier Soldanod4311552017-11-20 15:09:53 -0500133 [smartView scrollToBeginningOfDocument:nil];
134}
135
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500136- (BOOL)setConversationModel:(lrc::api::ConversationModel *)conversationModel
Olivier Soldanod4311552017-11-20 15:09:53 -0500137{
138 if (model_ != conversationModel) {
139 model_ = conversationModel;
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500140 selectedUid_.clear(); // Clear selected conversation as the selected account is being changed
Olivier Soldanod4311552017-11-20 15:09:53 -0500141 [self reloadData];
142 QObject::disconnect(modelSortedConnection_);
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500143 QObject::disconnect(filterChangedConnection_);
Anthony Léonard01634102017-12-27 16:37:16 -0500144 QObject::disconnect(newConversationConnection_);
145 QObject::disconnect(conversationRemovedConnection_);
Olivier Soldanod4311552017-11-20 15:09:53 -0500146 if (model_ != nil) {
147 modelSortedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::modelSorted,
148 [self] (){
149 [self reloadData];
150 });
151 filterChangedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::filterChanged,
152 [self] (){
153 [self reloadData];
154 });
Anthony Léonard01634102017-12-27 16:37:16 -0500155 newConversationConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::newConversation,
156 [self] (){
157 [self reloadData];
158 });
159 conversationRemovedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::conversationRemoved,
160 [self] (){
161 [self reloadData];
162 });
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500163 model_->setFilter(""); // Reset the filter
164 }
165 [searchField setStringValue:@""];
166 return YES;
167 }
168 return NO;
169}
170
171-(void)selectConversation:(const lrc::api::conversation::Info&)conv model:(lrc::api::ConversationModel*)model;
172{
173 auto& uid = conv.uid;
174 if (selectedUid_ == uid)
175 return;
176
177 [self setConversationModel:model];
178
179 if (model_ != nil) {
180 auto it = std::find_if(model_->allFilteredConversations().begin(), model_->allFilteredConversations().end(),
181 [self] (const lrc::api::conversation::Info& conv) {
182 return selectedUid_ == conv.uid;
183 });
184 if (it != model_->allFilteredConversations().end()) {
185 NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())];
186 [smartView selectRowIndexes:indexSet byExtendingSelection:NO];
187 selectedUid_ = uid;
Olivier Soldanod4311552017-11-20 15:09:53 -0500188 }
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400189 }
190}
191
Anthony Léonard8585cc02017-12-28 14:03:45 -0500192-(void)deselect
193{
194 selectedUid_.clear();
195 [smartView deselectAll:nil];
196}
197
Olivier Soldanod4311552017-11-20 15:09:53 -0500198#pragma mark - NSTableViewDelegate methods
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400199
Olivier Soldanod4311552017-11-20 15:09:53 -0500200- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400201{
202 return YES;
203}
204
Olivier Soldanod4311552017-11-20 15:09:53 -0500205- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400206{
207 return NO;
208}
209
Olivier Soldanod4311552017-11-20 15:09:53 -0500210- (void)tableViewSelectionDidChange:(NSNotification *)notification
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400211{
Olivier Soldanod4311552017-11-20 15:09:53 -0500212 NSInteger row = [notification.object selectedRow];
213
214 if (row == -1)
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400215 return;
Olivier Soldanod4311552017-11-20 15:09:53 -0500216
217 auto uid = model_->filteredConversation(row).uid;
218 if (selectedUid_ != uid) {
219 selectedUid_ = uid;
220 model_->selectConversation(uid);
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400221 }
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400222}
223
Olivier Soldanod4311552017-11-20 15:09:53 -0500224- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400225{
Olivier Soldanod4311552017-11-20 15:09:53 -0500226 return [tableView makeViewWithIdentifier:@"HoverRowView" owner:nil];
227}
Alexandre Lisiona4bb0512016-04-19 18:04:31 -0400228
Olivier Soldanod4311552017-11-20 15:09:53 -0500229- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
230{
231 if (model_ == nil)
232 return nil;
233
234 auto conversation = model_->filteredConversation(row);
Alexandre Lisiona4bb0512016-04-19 18:04:31 -0400235 NSTableCellView* result;
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400236
Olivier Soldanod4311552017-11-20 15:09:53 -0500237 result = [tableView makeViewWithIdentifier:@"MainCell" owner:tableView];
238// NSTextField* details = [result viewWithTag:DETAILS_TAG];
Alexandre Lision4e280d62015-09-09 15:56:30 -0400239
Olivier Soldanod4311552017-11-20 15:09:53 -0500240 NSMutableArray* controls = [NSMutableArray arrayWithObject:[result viewWithTag:CALL_BUTTON_TAG]];
241 [((ContextualTableCellView*) result) setContextualsControls:controls];
242 [((ContextualTableCellView*) result) setShouldBlurParentView:YES];
Alexandre Lision21666f32015-09-22 17:04:36 -0400243
Olivier Soldanod4311552017-11-20 15:09:53 -0500244// if (auto call = RecentModel::instance().getActiveCall(qIdx)) {
245// [details setStringValue:call->roleData((int)Ring::Role::FormattedState).toString().toNSString()];
246// [((ContextualTableCellView*) result) setActiveState:YES];
247// } else {
248// [details setStringValue:qIdx.data((int)Ring::Role::FormattedLastUsed).toString().toNSString()];
249// [((ContextualTableCellView*) result) setActiveState:NO];
250// }
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500251
Olivier Soldanod4311552017-11-20 15:09:53 -0500252 NSTextField* unreadCount = [result viewWithTag:TXT_BUTTON_TAG];
253 [unreadCount setHidden:(conversation.unreadMessages == 0)];
254 [unreadCount setIntValue:conversation.unreadMessages];
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400255
256 NSTextField* displayName = [result viewWithTag:DISPLAYNAME_TAG];
Olivier Soldanod4311552017-11-20 15:09:53 -0500257 NSString* displayNameString = bestNameForConversation(conversation, *model_);
258 NSString* displayIDString = bestIDForConversation(conversation, *model_);
Kateryna Kostiuk6a536362017-05-02 14:26:12 -0400259 if(displayNameString.length == 0 || [displayNameString isEqualToString:displayIDString]) {
Anthony Léonard4adc3f02017-07-21 10:23:04 -0400260 NSTextField* displayRingID = [result viewWithTag:RING_ID_LABEL];
Kateryna Kostiuk6a536362017-05-02 14:26:12 -0400261 [displayName setStringValue:displayIDString];
Anthony Léonard4adc3f02017-07-21 10:23:04 -0400262 [displayRingID setHidden:YES];
Kateryna Kostiuk9d6657a2017-04-25 13:42:25 -0400263 }
Kateryna Kostiuk6a536362017-05-02 14:26:12 -0400264 else {
265 NSTextField* displayRingID = [result viewWithTag:RING_ID_LABEL];
266 [displayName setStringValue:displayNameString];
Kateryna Kostiuk6a536362017-05-02 14:26:12 -0400267 [displayRingID setStringValue:displayIDString];
Anthony Léonard4adc3f02017-07-21 10:23:04 -0400268 [displayRingID setHidden:NO];
Kateryna Kostiuk6a536362017-05-02 14:26:12 -0400269 }
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400270 NSImageView* photoView = [result viewWithTag:IMAGE_TAG];
Alexandre Lision43e91bc2016-04-19 18:04:52 -0400271
Olivier Soldanod4311552017-11-20 15:09:53 -0500272 auto& imageManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator());
273 [photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(imageManip.conversationPhoto(conversation, model_->owner)))];
Kateryna Kostiukd9039e92017-05-24 14:29:54 -0400274
275 NSView* presenceView = [result viewWithTag:PRESENCE_TAG];
Olivier Soldanod4311552017-11-20 15:09:53 -0500276 if (model_->owner.contactModel->getContact(conversation.participants[0]).isPresent) {
Kateryna Kostiukd9039e92017-05-24 14:29:54 -0400277 [presenceView setHidden:NO];
278 } else {
279 [presenceView setHidden:YES];
280 }
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400281 return result;
282}
283
Olivier Soldanod4311552017-11-20 15:09:53 -0500284- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500285{
Olivier Soldanod4311552017-11-20 15:09:53 -0500286 return 60.0;
287}
288
289#pragma mark - NSTableDataSource methods
290
291- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
292{
293 if (tableView == smartView) {
294 if (model_ != nullptr)
295 return model_->allFilteredConversations().size();
296 }
297
298 return 0;
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500299}
300
Kateryna Kostiuk882cbac2017-07-05 17:29:00 -0400301- (void)startCallForRow:(id)sender {
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400302 NSInteger row = [smartView rowForView:sender];
303 [smartView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
304 [self placeCall:nil];
305}
306
307- (IBAction)hangUpClickedAtRow:(id)sender {
308 NSInteger row = [smartView rowForView:sender];
Alexandre Lision57914fa2016-02-10 14:52:24 -0500309
Olivier Soldanod4311552017-11-20 15:09:53 -0500310 if (row == -1)
Alexandre Lisionac4f5b62016-02-17 13:53:12 -0500311 return;
Alexandre Lision45c18672016-11-02 15:24:45 -0400312
Olivier Soldanod4311552017-11-20 15:09:53 -0500313 auto conv = model_->filteredConversation(row);
314 auto& callId = conv.callId;
Alexandre Lisionac4f5b62016-02-17 13:53:12 -0500315
Olivier Soldanod4311552017-11-20 15:09:53 -0500316 if (callId.empty())
317 return;
318
319 auto* callModel = model_->owner.callModel.get();
320 callModel->hangUp(callId);
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400321}
322
Alexandre Lision45c18672016-11-02 15:24:45 -0400323- (void) displayErrorModalWithTitle:(NSString*) title WithMessage:(NSString*) message
324{
325 NSAlert* alert = [NSAlert alertWithMessageText:title
326 defaultButton:@"Ok"
327 alternateButton:nil
328 otherButton:nil
329 informativeTextWithFormat:message];
330
331 [alert beginSheetModalForWindow:self.view.window modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
332}
333
Olivier Soldanod4311552017-11-20 15:09:53 -0500334- (void) processSearchFieldInput
Alexandre Lision45c18672016-11-02 15:24:45 -0400335{
Olivier Soldanod4311552017-11-20 15:09:53 -0500336 model_->setFilter(std::string([[searchField stringValue] UTF8String]));
Alexandre Lision45c18672016-11-02 15:24:45 -0400337}
338
Olivier Soldanod4311552017-11-20 15:09:53 -0500339-(const lrc::api::account::Info&) chosenAccount
Kateryna Kostiukd2f7b5d2017-06-09 15:30:49 -0400340{
Olivier Soldanod4311552017-11-20 15:09:53 -0500341 return model_->owner;
Kateryna Kostiukd2f7b5d2017-06-09 15:30:49 -0400342}
343
Alexandre Lisionf909fb12016-11-03 12:35:36 -0400344- (void) clearSearchField
345{
346 [searchField setStringValue:@""];
Olivier Soldanod4311552017-11-20 15:09:53 -0500347 [self processSearchFieldInput];
Kateryna Kostiuk9dd759c2017-07-11 12:06:55 -0400348}
349
Alexandre Lision72a669e2016-09-14 17:52:16 -0400350/**
351 Copy a NSString in the general Pasteboard
352
353 @param sender the NSObject containing the represented object to copy
354 */
355- (void) copyStringToPasteboard:(id) sender
Alexandre Lisiond7bf2882015-10-22 22:54:32 -0400356{
357 NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
358 [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
359 [pasteBoard setString:[sender representedObject] forType:NSStringPboardType];
360}
361
Alexandre Lisionbf0385e2015-10-22 17:36:28 -0400362#pragma NSTextFieldDelegate
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400363
364- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
365{
366 if (commandSelector == @selector(insertNewline:)) {
367 if([[searchField stringValue] isNotEqualTo:@""]) {
Olivier Soldanod4311552017-11-20 15:09:53 -0500368 [self processSearchFieldInput];
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400369 return YES;
370 }
371 }
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400372 return NO;
373}
374
Alexandre Lisionac4f5b62016-02-17 13:53:12 -0500375- (void)controlTextDidChange:(NSNotification *) notification
376{
Olivier Soldanod4311552017-11-20 15:09:53 -0500377 [self processSearchFieldInput];
Alexandre Lisionac4f5b62016-02-17 13:53:12 -0500378}
379
Alexandre Lision61db3552015-10-22 19:12:52 -0400380#pragma mark - NSPopOverDelegate
381
382- (void)popoverDidClose:(NSNotification *)notification
383{
384 if (addToContactPopover != nullptr) {
385 [addToContactPopover performClose:self];
386 addToContactPopover = NULL;
387 }
388}
389
Alexandre Lisionbf0385e2015-10-22 17:36:28 -0400390
Alexandre Lision61db3552015-10-22 19:12:52 -0400391#pragma mark - ContactLinkedDelegate
392
393- (void)contactLinked
394{
395 if (addToContactPopover != nullptr) {
396 [addToContactPopover performClose:self];
397 addToContactPopover = NULL;
398 }
399}
400
401#pragma mark - KeyboardShortcutDelegate
402
403- (void) onAddShortcut
404{
Olivier Soldanod4311552017-11-20 15:09:53 -0500405 if ([smartView selectedRow] == -1)
Alexandre Lision61db3552015-10-22 19:12:52 -0400406 return;
407
Olivier Soldanod4311552017-11-20 15:09:53 -0500408 auto uid = model_->filteredConversation([smartView selectedRow]).uid;
409 model_->makePermanent(uid);
Alexandre Lision61db3552015-10-22 19:12:52 -0400410}
411
412#pragma mark - ContextMenuDelegate
413
Olivier Soldanod4311552017-11-20 15:09:53 -0500414#if 0
415// TODO: Reimplement contextual menu with new models and behaviors
Alexandre Lision12946a72016-03-08 13:39:34 -0500416- (NSMenu*) contextualMenuForIndex:(NSTreeNode*) item
Alexandre Lision61db3552015-10-22 19:12:52 -0400417{
Alexandre Lision12946a72016-03-08 13:39:34 -0500418 auto qIdx = [treeController toQIdx:item];
419
420 if (!qIdx.isValid()) {
421 return nil;
422 }
423
Alexandre Lision61db3552015-10-22 19:12:52 -0400424 auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx);
425 auto contactmethods = RecentModel::instance().getContactMethods(originIdx);
426 if (contactmethods.isEmpty())
427 return nil;
428
Alexandre Lisiond7bf2882015-10-22 22:54:32 -0400429 NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@""];
430
431 if (contactmethods.size() == 1
432 && !contactmethods.first()->contact()
433 || contactmethods.first()->contact()->isPlaceHolder()) {
434
Kateryna Kostiuk9dd759c2017-07-11 12:06:55 -0400435 NSMenuItem* addContactItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action")
436 action:@selector(addContactForRow:)
437 keyEquivalent:@""];
438 [addContactItem setRepresentedObject:item];
439 [theMenu addItem:addContactItem];
Alexandre Lision72a669e2016-09-14 17:52:16 -0400440 } else if (auto person = contactmethods.first()->contact()) {
441 NSMenuItem* copyNameItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Copy name", @"Contextual menu action")
442 action:@selector(copyStringToPasteboard:)
443 keyEquivalent:@""];
444
445 [copyNameItem setRepresentedObject:person->formattedName().toNSString()];
446 [theMenu addItem:copyNameItem];
Alexandre Lision61db3552015-10-22 19:12:52 -0400447 }
Alexandre Lisiond7bf2882015-10-22 22:54:32 -0400448
449 NSMenu* copySubmenu = [[NSMenu alloc] init];
450 NSMenu* callSubmenu = [[NSMenu alloc] init];
451
Alexandre Lision72a669e2016-09-14 17:52:16 -0400452 for (auto cm : contactmethods) {
Alexandre Lisiond7bf2882015-10-22 22:54:32 -0400453 NSMenuItem* tmpCopyItem = [[NSMenuItem alloc] initWithTitle:cm->uri().toNSString()
Alexandre Lision72a669e2016-09-14 17:52:16 -0400454 action:@selector(copyStringToPasteboard:)
Alexandre Lisiond7bf2882015-10-22 22:54:32 -0400455 keyEquivalent:@""];
456
457 [tmpCopyItem setRepresentedObject:cm->uri().toNSString()];
458 [copySubmenu addItem:tmpCopyItem];
459
460 NSMenuItem* tmpCallItem = [[NSMenuItem alloc] initWithTitle:cm->uri().toNSString()
461 action:@selector(callNumber:)
462 keyEquivalent:@""];
463 [tmpCallItem setRepresentedObject:cm->uri().toNSString()];
464 [callSubmenu addItem:tmpCallItem];
465 }
466
Alexandre Lision72a669e2016-09-14 17:52:16 -0400467 NSMenuItem* copyNumberItem = [[NSMenuItem alloc] init];
468 [copyNumberItem setTitle:NSLocalizedString(@"Copy number", @"Contextual menu action")];
469 [copyNumberItem setSubmenu:copySubmenu];
Alexandre Lisiond7bf2882015-10-22 22:54:32 -0400470
471 NSMenuItem* callItems = [[NSMenuItem alloc] init];
472 [callItems setTitle:NSLocalizedString(@"Call number", @"Contextual menu action")];
473 [callItems setSubmenu:callSubmenu];
474
Alexandre Lision72a669e2016-09-14 17:52:16 -0400475 [theMenu insertItem:copyNumberItem atIndex:theMenu.itemArray.count];
Alexandre Lisiond7bf2882015-10-22 22:54:32 -0400476 [theMenu insertItem:[NSMenuItem separatorItem] atIndex:theMenu.itemArray.count];
477 [theMenu insertItem:callItems atIndex:theMenu.itemArray.count];
478
479 return theMenu;
Alexandre Lision61db3552015-10-22 19:12:52 -0400480}
Olivier Soldanod4311552017-11-20 15:09:53 -0500481#endif
Alexandre Lision61db3552015-10-22 19:12:52 -0400482
Alexandre Lision4dfcafc2015-08-20 12:43:23 -0400483@end