Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | */ |
| 19 | |
| 20 | #import "SmartViewVC.h" |
| 21 | |
| 22 | //Qt |
| 23 | #import <QtMacExtras/qmacfunctions.h> |
| 24 | #import <QPixmap> |
| 25 | #import <QIdentityProxyModel> |
| 26 | #import <QItemSelectionModel> |
| 27 | |
| 28 | //LRC |
| 29 | #import <recentmodel.h> |
| 30 | #import <callmodel.h> |
| 31 | #import <call.h> |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 32 | #import <uri.h> |
Alexandre Lision | d14bda3 | 2015-10-13 11:34:29 -0400 | [diff] [blame] | 33 | #import <itemdataroles.h> |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 34 | #import <namedirectory.h> |
| 35 | #import <accountmodel.h> |
| 36 | #import <account.h> |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 37 | #import <person.h> |
| 38 | #import <contactmethod.h> |
| 39 | #import <globalinstances.h> |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 40 | #import <phonedirectorymodel.h> |
Kateryna Kostiuk | 1f705ab | 2017-04-18 12:45:59 -0400 | [diff] [blame] | 41 | #import <AvailableAccountModel.h> |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 42 | |
| 43 | #import "QNSTreeController.h" |
| 44 | #import "delegates/ImageManipulationDelegate.h" |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 45 | #import "views/HoverTableRowView.h" |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 46 | #import "PersonLinkerVC.h" |
Alexandre Lision | 4baba4c | 2016-02-11 13:00:57 -0500 | [diff] [blame] | 47 | #import "views/IconButton.h" |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 48 | #import "views/RingOutlineView.h" |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 49 | #import "views/ContextualTableCellView.h" |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 50 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 51 | @interface SmartViewVC () <NSOutlineViewDelegate, NSPopoverDelegate, ContextMenuDelegate, ContactLinkedDelegate, KeyboardShortcutDelegate> { |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 52 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 53 | QNSTreeController *treeController; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 54 | NSPopover* addToContactPopover; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 55 | |
| 56 | //UI elements |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 57 | __unsafe_unretained IBOutlet RingOutlineView* smartView; |
| 58 | __unsafe_unretained IBOutlet NSSearchField* searchField; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 59 | |
| 60 | /* Pending ring usernames lookup for the search entry */ |
| 61 | QMetaObject::Connection usernameLookupConnection; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @end |
| 65 | |
| 66 | @implementation SmartViewVC |
| 67 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 68 | @synthesize tabbar; |
| 69 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 70 | // Tags for views |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 71 | NSInteger const IMAGE_TAG = 100; |
| 72 | NSInteger const DISPLAYNAME_TAG = 200; |
| 73 | NSInteger const DETAILS_TAG = 300; |
| 74 | NSInteger const CALL_BUTTON_TAG = 400; |
| 75 | NSInteger const TXT_BUTTON_TAG = 500; |
| 76 | NSInteger const CANCEL_BUTTON_TAG = 600; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 77 | NSInteger const RING_ID_LABEL = 700; |
Kateryna Kostiuk | d9039e9 | 2017-05-24 14:29:54 -0400 | [diff] [blame] | 78 | NSInteger const PRESENCE_TAG = 800; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 79 | |
| 80 | - (void)awakeFromNib |
| 81 | { |
| 82 | NSLog(@"INIT SmartView VC"); |
| 83 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 84 | treeController = [[QNSTreeController alloc] initWithQModel:RecentModel::instance().peopleProxy()]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 85 | [treeController setAvoidsEmptySelection:NO]; |
| 86 | [treeController setChildrenKeyPath:@"children"]; |
| 87 | |
| 88 | [smartView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 89 | [smartView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 90 | [smartView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 91 | [smartView setTarget:self]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 92 | [smartView setAction:@selector(selectRow:)]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 93 | [smartView setDoubleAction:@selector(placeCall:)]; |
| 94 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 95 | [smartView setContextMenuDelegate:self]; |
| 96 | [smartView setShortcutsDelegate:self]; |
| 97 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 98 | QObject::connect(RecentModel::instance().peopleProxy(), |
Alexandre Lision | ee09846 | 2015-10-22 17:22:50 -0400 | [diff] [blame] | 99 | &QAbstractItemModel::dataChanged, |
| 100 | [self](const QModelIndex &topLeft, const QModelIndex &bottomRight) { |
| 101 | for(int row = topLeft.row() ; row <= bottomRight.row() ; ++row) |
| 102 | { |
| 103 | [smartView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] |
| 104 | columnIndexes:[NSIndexSet indexSetWithIndex:0]]; |
| 105 | } |
| 106 | }); |
| 107 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 108 | QObject::connect(RecentModel::instance().selectionModel(), |
| 109 | &QItemSelectionModel::currentChanged, |
| 110 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
Alexandre Lision | 01cf5e3 | 2016-01-21 15:54:30 -0500 | [diff] [blame] | 111 | if(!current.isValid()) { |
| 112 | [smartView deselectAll:nil]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 113 | return; |
Alexandre Lision | 01cf5e3 | 2016-01-21 15:54:30 -0500 | [diff] [blame] | 114 | } |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 115 | |
| 116 | auto proxyIdx = RecentModel::instance().peopleProxy()->mapFromSource(current); |
| 117 | if (proxyIdx.isValid()) { |
| 118 | [treeController setSelectionQModelIndex:proxyIdx]; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 119 | [tabbar selectTabViewItemAtIndex:0]; |
| 120 | [smartView scrollRowToVisible:proxyIdx.row()]; |
| 121 | } |
| 122 | }); |
| 123 | |
Alexandre Lision | 25fc82a | 2016-05-08 17:30:40 -0400 | [diff] [blame] | 124 | QObject::connect(RecentModel::instance().peopleProxy(), |
| 125 | &QAbstractItemModel::rowsInserted, |
| 126 | [=](const QModelIndex &parent, int first, int last) { |
| 127 | Q_UNUSED(parent) |
| 128 | Q_UNUSED(first) |
| 129 | Q_UNUSED(last) |
| 130 | [smartView scrollRowToVisible:0]; |
| 131 | }); |
| 132 | |
Kateryna Kostiuk | 1f705ab | 2017-04-18 12:45:59 -0400 | [diff] [blame] | 133 | QObject::connect(AvailableAccountModel::instance().selectionModel(), |
| 134 | &QItemSelectionModel::currentChanged, |
| 135 | [self](const QModelIndex& idx){ |
| 136 | [self clearSearchField]; |
| 137 | }); |
| 138 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 139 | [self.view setWantsLayer:YES]; |
| 140 | [self.view setLayer:[CALayer layer]]; |
| 141 | [self.view.layer setBackgroundColor:[NSColor whiteColor].CGColor]; |
| 142 | |
| 143 | [searchField setWantsLayer:YES]; |
| 144 | [searchField setLayer:[CALayer layer]]; |
| 145 | [searchField.layer setBackgroundColor:[NSColor colorWithCalibratedRed:0.949 green:0.949 blue:0.949 alpha:0.9].CGColor]; |
| 146 | } |
| 147 | |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 148 | -(void) selectRow:(id)sender |
| 149 | { |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 150 | if ([treeController selectedNodes].count == 0) { |
| 151 | RecentModel::instance().selectionModel()->clearCurrentIndex(); |
| 152 | return; |
| 153 | } |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 154 | auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 155 | auto proxyIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx); |
| 156 | RecentModel::instance().selectionModel()->setCurrentIndex(proxyIdx, QItemSelectionModel::ClearAndSelect); |
| 157 | } |
| 158 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 159 | - (void)placeCall:(id)sender |
| 160 | { |
| 161 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 162 | ContactMethod* m = nil; |
| 163 | |
| 164 | // Double click on an ongoing call |
| 165 | if (qIdx.parent().isValid()) { |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | if([[treeController selectedNodes] count] > 0) { |
| 170 | QVariant var = qIdx.data((int)Call::Role::ContactMethod); |
| 171 | m = qvariant_cast<ContactMethod*>(var); |
| 172 | if (!m) { |
| 173 | // test if it is a person |
| 174 | QVariant var = qIdx.data((int)Person::Role::Object); |
| 175 | if (var.isValid()) { |
| 176 | Person *c = var.value<Person*>(); |
| 177 | if (c->phoneNumbers().size() > 0) { |
| 178 | m = c->phoneNumbers().first(); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // Before calling check if we properly extracted a contact method and that |
| 185 | // there is NOT already an ongoing call for this index (e.g: no children for this node) |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 186 | if(m && !RecentModel::instance().peopleProxy()->index(0, 0, qIdx).isValid()){ |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 187 | auto c = CallModel::instance().dialingCall(); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 188 | c->setPeerContactMethod(m); |
| 189 | c << Call::Action::ACCEPT; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 190 | CallModel::instance().selectCall(c); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 194 | - (void)showHistory |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 195 | { |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 196 | [tabbar selectTabViewItemAtIndex:1]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 197 | } |
| 198 | |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 199 | - (void)showContacts |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 200 | { |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 201 | [tabbar selectTabViewItemAtIndex:2]; |
| 202 | } |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 203 | |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 204 | - (void)showSmartlist |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 205 | { |
| 206 | [tabbar selectTabViewItemAtIndex:0]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | #pragma mark - NSOutlineViewDelegate methods |
| 210 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 211 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 212 | { |
| 213 | return YES; |
| 214 | } |
| 215 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 216 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 217 | { |
| 218 | return NO; |
| 219 | } |
| 220 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 221 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 222 | { |
| 223 | if ([treeController selectedNodes].count <= 0) { |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 224 | RecentModel::instance().selectionModel()->clearCurrentIndex(); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 225 | return; |
| 226 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 227 | } |
| 228 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 229 | - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 230 | { |
Alexandre Lision | a4bb051 | 2016-04-19 18:04:31 -0400 | [diff] [blame] | 231 | QModelIndex proxyIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 232 | QModelIndex qIdx = RecentModel::instance().peopleProxy()->mapToSource(proxyIdx); |
| 233 | |
| 234 | NSTableCellView* result; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 235 | if (!qIdx.parent().isValid()) { |
| 236 | result = [outlineView makeViewWithIdentifier:@"MainCell" owner:outlineView]; |
| 237 | NSTextField* details = [result viewWithTag:DETAILS_TAG]; |
| 238 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 239 | NSMutableArray* controls = [NSMutableArray arrayWithObject:[result viewWithTag:CALL_BUTTON_TAG]]; |
| 240 | [((ContextualTableCellView*) result) setContextualsControls:controls]; |
Kateryna Kostiuk | 3c960bf | 2017-06-01 12:11:54 -0400 | [diff] [blame] | 241 | [((ContextualTableCellView*) result) setShouldBlurParentView:YES]; |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 242 | |
Alexandre Lision | a4bb051 | 2016-04-19 18:04:31 -0400 | [diff] [blame] | 243 | if (auto call = RecentModel::instance().getActiveCall(qIdx)) { |
Alexandre Lision | d14bda3 | 2015-10-13 11:34:29 -0400 | [diff] [blame] | 244 | [details setStringValue:call->roleData((int)Ring::Role::FormattedState).toString().toNSString()]; |
Alexandre Lision | 21666f3 | 2015-09-22 17:04:36 -0400 | [diff] [blame] | 245 | [((ContextualTableCellView*) result) setActiveState:YES]; |
| 246 | } else { |
Alexandre Lision | d14bda3 | 2015-10-13 11:34:29 -0400 | [diff] [blame] | 247 | [details setStringValue:qIdx.data((int)Ring::Role::FormattedLastUsed).toString().toNSString()]; |
Alexandre Lision | 21666f3 | 2015-09-22 17:04:36 -0400 | [diff] [blame] | 248 | [((ContextualTableCellView*) result) setActiveState:NO]; |
| 249 | } |
| 250 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 251 | NSTextField* unreadCount = [result viewWithTag:TXT_BUTTON_TAG]; |
| 252 | int unread = qIdx.data((int)Ring::Role::UnreadTextMessageCount).toInt(); |
| 253 | [unreadCount setHidden:(unread == 0)]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 254 | [unreadCount setStringValue:qIdx.data((int)Ring::Role::UnreadTextMessageCount).toString().toNSString()]; |
| 255 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 256 | } else { |
| 257 | result = [outlineView makeViewWithIdentifier:@"CallCell" owner:outlineView]; |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 258 | NSMutableArray* controls = [NSMutableArray arrayWithObject:[result viewWithTag:CANCEL_BUTTON_TAG]]; |
| 259 | [((ContextualTableCellView*) result) setContextualsControls:controls]; |
Kateryna Kostiuk | 3c960bf | 2017-06-01 12:11:54 -0400 | [diff] [blame] | 260 | [((ContextualTableCellView*) result) setShouldBlurParentView:YES]; |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 261 | [((ContextualTableCellView*) result) setActiveState:NO]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 262 | NSTextField* details = [result viewWithTag:DETAILS_TAG]; |
| 263 | |
| 264 | [details setStringValue:qIdx.data((int)Call::Role::HumanStateName).toString().toNSString()]; |
| 265 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 266 | |
| 267 | NSTextField* displayName = [result viewWithTag:DISPLAYNAME_TAG]; |
Kateryna Kostiuk | 9d6657a | 2017-04-25 13:42:25 -0400 | [diff] [blame] | 268 | NSString* displayNameString = qIdx.data((int)Ring::Role::Name).toString().toNSString(); |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 269 | NSString* displayIDString = qIdx.data((int)Person::Role::IdOfLastCMUsed).toString().toNSString(); |
| 270 | if(displayNameString.length == 0 || [displayNameString isEqualToString:displayIDString]) { |
| 271 | [displayName setStringValue:displayIDString]; |
Kateryna Kostiuk | 9d6657a | 2017-04-25 13:42:25 -0400 | [diff] [blame] | 272 | } |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 273 | else { |
| 274 | NSTextField* displayRingID = [result viewWithTag:RING_ID_LABEL]; |
| 275 | [displayName setStringValue:displayNameString]; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 276 | [displayRingID setStringValue:displayIDString]; |
| 277 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 278 | NSImageView* photoView = [result viewWithTag:IMAGE_TAG]; |
Alexandre Lision | 43e91bc | 2016-04-19 18:04:52 -0400 | [diff] [blame] | 279 | |
| 280 | [photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(qIdx.data(Qt::DecorationRole)))]; |
Kateryna Kostiuk | d9039e9 | 2017-05-24 14:29:54 -0400 | [diff] [blame] | 281 | |
| 282 | NSView* presenceView = [result viewWithTag:PRESENCE_TAG]; |
| 283 | if (qIdx.data(static_cast<int>(Ring::Role::IsPresent)).value<bool>()) { |
| 284 | [presenceView setHidden:NO]; |
| 285 | } else { |
| 286 | [presenceView setHidden:YES]; |
| 287 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 288 | return result; |
| 289 | } |
| 290 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 291 | - (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item |
| 292 | { |
| 293 | return [outlineView makeViewWithIdentifier:@"HoverRowView" owner:nil]; |
| 294 | } |
| 295 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 296 | - (void)startCallForRow:(id)sender { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 297 | NSInteger row = [smartView rowForView:sender]; |
| 298 | [smartView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; |
| 299 | [self placeCall:nil]; |
| 300 | } |
| 301 | |
| 302 | - (IBAction)hangUpClickedAtRow:(id)sender { |
| 303 | NSInteger row = [smartView rowForView:sender]; |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 304 | id callNode = [smartView itemAtRow:row]; |
| 305 | auto callIdx = [treeController toQIdx:((NSTreeNode*)callNode)]; |
| 306 | |
| 307 | if (callIdx.isValid()) { |
| 308 | auto call = RecentModel::instance().getActiveCall(RecentModel::instance().peopleProxy()->mapToSource(callIdx)); |
| 309 | call << Call::Action::REFUSE; |
| 310 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 313 | - (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item |
| 314 | { |
| 315 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 316 | return (((NSTreeNode*)item).indexPath.length == 1) ? 60.0 : 50.0; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 317 | } |
| 318 | |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 319 | - (IBAction)placeCallFromSearchField:(id)sender |
| 320 | { |
| 321 | if ([searchField stringValue].length == 0) { |
| 322 | return; |
| 323 | } |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 324 | [self processSearchFieldInputAndStartCall:YES]; |
| 325 | } |
| 326 | |
| 327 | - (void) startCallFromURI:(const URI&) uri |
| 328 | { |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 329 | auto cm = PhoneDirectoryModel::instance().getNumber(uri, [self chosenAccount]); |
| 330 | if(!cm->account() && [self chosenAccount]) { |
| 331 | cm->setAccount([self chosenAccount]); |
| 332 | } |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 333 | auto c = CallModel::instance().dialingCall(); |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 334 | c->setPeerContactMethod(cm); |
| 335 | c << Call::Action::ACCEPT; |
| 336 | CallModel::instance().selectCall(c); |
| 337 | } |
| 338 | |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 339 | - (void) startConversationFromURI:(const URI&) uri |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 340 | { |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 341 | auto cm = PhoneDirectoryModel::instance().getNumber(uri, [self chosenAccount]); |
| 342 | if(!cm->account() && [self chosenAccount]) { |
| 343 | cm->setAccount([self chosenAccount]); |
| 344 | } |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 345 | time_t currentTime; |
| 346 | ::time(¤tTime); |
| 347 | cm->setLastUsed(currentTime); |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 348 | auto proxyIdx = RecentModel::instance().peopleProxy()->mapToSource(RecentModel::instance().peopleProxy()->index(0, 0)); |
| 349 | RecentModel::instance().selectionModel()->setCurrentIndex(proxyIdx, QItemSelectionModel::ClearAndSelect); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 352 | - (void) displayErrorModalWithTitle:(NSString*) title WithMessage:(NSString*) message |
| 353 | { |
| 354 | NSAlert* alert = [NSAlert alertWithMessageText:title |
| 355 | defaultButton:@"Ok" |
| 356 | alternateButton:nil |
| 357 | otherButton:nil |
| 358 | informativeTextWithFormat:message]; |
| 359 | |
| 360 | [alert beginSheetModalForWindow:self.view.window modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; |
| 361 | } |
| 362 | |
| 363 | - (void) processSearchFieldInputAndStartCall:(BOOL) shouldCall |
| 364 | { |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 365 | NSString* noValidAccountTitle = NSLocalizedString(@"No valid account available", |
| 366 | @"Alert dialog title"); |
| 367 | NSString* noValidAccountMessage = NSLocalizedString(@"Make sure you have at least one valid account", |
| 368 | @"Alert dialo message"); |
| 369 | |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 370 | const auto* numberEntered = [searchField stringValue]; |
| 371 | URI uri = URI(numberEntered.UTF8String); |
Alexandre Lision | f909fb1 | 2016-11-03 12:35:36 -0400 | [diff] [blame] | 372 | [self clearSearchField]; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 373 | |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 374 | if ([self chosenAccount] && [self chosenAccount]->protocol() == Account::Protocol::RING) { |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 375 | if (uri.protocolHint() == URI::ProtocolHint::RING) { |
| 376 | // If it is a RingID start the conversation or the call |
| 377 | if (shouldCall) { |
| 378 | [self startCallFromURI:uri]; |
| 379 | } else { |
| 380 | [self startConversationFromURI:uri]; |
| 381 | } |
| 382 | } else { |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 383 | // If it's not a ringID and the user choosen account is a Ring account do a search on the blockchain |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 384 | QString usernameToLookup = uri.userinfo(); |
| 385 | QObject::disconnect(usernameLookupConnection); |
| 386 | usernameLookupConnection = QObject::connect(&NameDirectory::instance(), |
| 387 | &NameDirectory::registeredNameFound, |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 388 | [self,usernameToLookup,shouldCall] (const Account* account, NameDirectory::LookupStatus status, const QString& address, const QString& name) { |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 389 | if (usernameToLookup.compare(name) != 0) { |
| 390 | //That is not our lookup. |
| 391 | return; |
| 392 | } |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 393 | switch(status) { |
| 394 | case NameDirectory::LookupStatus::SUCCESS: { |
| 395 | URI uri = URI("ring:" + address); |
| 396 | if (shouldCall) { |
| 397 | [self startCallFromURI:uri]; |
| 398 | } else { |
| 399 | [self startConversationFromURI:uri]; |
| 400 | } |
| 401 | break; |
| 402 | } |
| 403 | case NameDirectory::LookupStatus::INVALID_NAME: |
| 404 | case NameDirectory::LookupStatus::ERROR: |
| 405 | case NameDirectory::LookupStatus::NOT_FOUND: { |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 406 | [self displayErrorModalWithTitle:NSLocalizedString(@"Entered name not found", |
| 407 | @"Alert dialog title") |
| 408 | WithMessage:NSLocalizedString(@"The username you entered do not match a RingID on the network", |
| 409 | @"Alert dialog title")]; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 410 | } |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 411 | break; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 412 | } |
Alexandre Lision | f909fb1 | 2016-11-03 12:35:36 -0400 | [diff] [blame] | 413 | }); |
| 414 | |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 415 | NameDirectory::instance().lookupName([self chosenAccount], QString(), usernameToLookup); |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 416 | } |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 417 | } else if ([self chosenAccount] && [self chosenAccount]->protocol() == Account::Protocol::SIP) { |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 418 | if (uri.protocolHint() == URI::ProtocolHint::RING) { |
| 419 | // If it is a RingID and no valid account is available, present error |
| 420 | [self displayErrorModalWithTitle:noValidAccountTitle |
| 421 | WithMessage:noValidAccountMessage]; |
Alexandre Lision | f909fb1 | 2016-11-03 12:35:36 -0400 | [diff] [blame] | 422 | return; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 423 | } |
| 424 | if (shouldCall) { |
| 425 | [self startCallFromURI:uri]; |
| 426 | } else { |
| 427 | [self startConversationFromURI:uri]; |
| 428 | } |
| 429 | } else { |
| 430 | [self displayErrorModalWithTitle:noValidAccountTitle |
| 431 | WithMessage:noValidAccountMessage]; |
| 432 | } |
| 433 | } |
| 434 | |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 435 | -(Account* ) chosenAccount |
| 436 | { |
| 437 | auto idx = AvailableAccountModel::instance().selectionModel()->currentIndex(); |
| 438 | if (idx.isValid()) { |
| 439 | return idx.data(static_cast<int>(Ring::Role::Object)).value<Account*>(); |
| 440 | } |
| 441 | return nullptr; |
| 442 | } |
| 443 | |
Alexandre Lision | f909fb1 | 2016-11-03 12:35:36 -0400 | [diff] [blame] | 444 | - (void) clearSearchField |
| 445 | { |
| 446 | [searchField setStringValue:@""]; |
| 447 | RecentModel::instance().peopleProxy()->setFilterWildcard(QString::fromNSString([searchField stringValue])); |
| 448 | } |
| 449 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 450 | - (void) addToContact |
| 451 | { |
| 452 | if ([treeController selectedNodes].count == 0) |
| 453 | return; |
| 454 | |
| 455 | auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 456 | auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx); |
| 457 | auto contactmethod = RecentModel::instance().getContactMethods(originIdx); |
| 458 | if (contactmethod.isEmpty()) |
| 459 | return; |
| 460 | |
| 461 | if (addToContactPopover != nullptr) { |
| 462 | [addToContactPopover performClose:self]; |
| 463 | addToContactPopover = NULL; |
| 464 | } else if (contactmethod.first()) { |
| 465 | auto* editorVC = [[PersonLinkerVC alloc] initWithNibName:@"PersonLinker" bundle:nil]; |
| 466 | [editorVC setMethodToLink:contactmethod.first()]; |
| 467 | [editorVC setContactLinkedDelegate:self]; |
| 468 | addToContactPopover = [[NSPopover alloc] init]; |
| 469 | [addToContactPopover setContentSize:editorVC.view.frame.size]; |
| 470 | [addToContactPopover setContentViewController:editorVC]; |
| 471 | [addToContactPopover setAnimates:YES]; |
| 472 | [addToContactPopover setBehavior:NSPopoverBehaviorTransient]; |
| 473 | [addToContactPopover setDelegate:self]; |
| 474 | |
| 475 | [addToContactPopover showRelativeToRect:[smartView frameOfCellAtColumn:0 row:[smartView selectedRow]] |
| 476 | ofView:smartView preferredEdge:NSMaxXEdge]; |
| 477 | } |
| 478 | } |
| 479 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 480 | /** |
| 481 | Copy a NSString in the general Pasteboard |
| 482 | |
| 483 | @param sender the NSObject containing the represented object to copy |
| 484 | */ |
| 485 | - (void) copyStringToPasteboard:(id) sender |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 486 | { |
| 487 | NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard]; |
| 488 | [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
| 489 | [pasteBoard setString:[sender representedObject] forType:NSStringPboardType]; |
| 490 | } |
| 491 | |
| 492 | - (void) callNumber:(id) sender |
| 493 | { |
| 494 | Call* c = CallModel::instance().dialingCall(); |
| 495 | c->setDialNumber(QString::fromNSString([sender representedObject])); |
| 496 | c << Call::Action::ACCEPT; |
| 497 | } |
| 498 | |
Alexandre Lision | bf0385e | 2015-10-22 17:36:28 -0400 | [diff] [blame] | 499 | #pragma NSTextFieldDelegate |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 500 | |
| 501 | - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector |
| 502 | { |
| 503 | if (commandSelector == @selector(insertNewline:)) { |
| 504 | if([[searchField stringValue] isNotEqualTo:@""]) { |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 505 | [self processSearchFieldInputAndStartCall:NO]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 506 | return YES; |
| 507 | } |
| 508 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 509 | return NO; |
| 510 | } |
| 511 | |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 512 | - (void)controlTextDidChange:(NSNotification *) notification |
| 513 | { |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 514 | RecentModel::instance().peopleProxy()->setFilterWildcard(QString::fromNSString([searchField stringValue])); |
| 515 | } |
| 516 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 517 | #pragma mark - NSPopOverDelegate |
| 518 | |
| 519 | - (void)popoverDidClose:(NSNotification *)notification |
| 520 | { |
| 521 | if (addToContactPopover != nullptr) { |
| 522 | [addToContactPopover performClose:self]; |
| 523 | addToContactPopover = NULL; |
| 524 | } |
| 525 | } |
| 526 | |
Alexandre Lision | bf0385e | 2015-10-22 17:36:28 -0400 | [diff] [blame] | 527 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 528 | #pragma mark - ContactLinkedDelegate |
| 529 | |
| 530 | - (void)contactLinked |
| 531 | { |
| 532 | if (addToContactPopover != nullptr) { |
| 533 | [addToContactPopover performClose:self]; |
| 534 | addToContactPopover = NULL; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | #pragma mark - KeyboardShortcutDelegate |
| 539 | |
| 540 | - (void) onAddShortcut |
| 541 | { |
| 542 | auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 543 | auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx); |
| 544 | auto contactmethods = RecentModel::instance().getContactMethods(originIdx); |
| 545 | if (contactmethods.isEmpty()) |
| 546 | return; |
| 547 | |
| 548 | auto contactmethod = contactmethods.first(); |
| 549 | if (contactmethod && (!contactmethod->contact() || contactmethod->contact()->isPlaceHolder())) { |
| 550 | [self addToContact]; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | #pragma mark - ContextMenuDelegate |
| 555 | |
Alexandre Lision | 12946a7 | 2016-03-08 13:39:34 -0500 | [diff] [blame] | 556 | - (NSMenu*) contextualMenuForIndex:(NSTreeNode*) item |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 557 | { |
Alexandre Lision | 12946a7 | 2016-03-08 13:39:34 -0500 | [diff] [blame] | 558 | auto qIdx = [treeController toQIdx:item]; |
| 559 | |
| 560 | if (!qIdx.isValid()) { |
| 561 | return nil; |
| 562 | } |
| 563 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 564 | auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx); |
| 565 | auto contactmethods = RecentModel::instance().getContactMethods(originIdx); |
| 566 | if (contactmethods.isEmpty()) |
| 567 | return nil; |
| 568 | |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 569 | NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@""]; |
| 570 | |
| 571 | if (contactmethods.size() == 1 |
| 572 | && !contactmethods.first()->contact() |
| 573 | || contactmethods.first()->contact()->isPlaceHolder()) { |
| 574 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 575 | [theMenu insertItemWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action") |
| 576 | action:@selector(addToContact) |
| 577 | keyEquivalent:@"a" |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 578 | atIndex:theMenu.itemArray.count]; |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 579 | } else if (auto person = contactmethods.first()->contact()) { |
| 580 | NSMenuItem* copyNameItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Copy name", @"Contextual menu action") |
| 581 | action:@selector(copyStringToPasteboard:) |
| 582 | keyEquivalent:@""]; |
| 583 | |
| 584 | [copyNameItem setRepresentedObject:person->formattedName().toNSString()]; |
| 585 | [theMenu addItem:copyNameItem]; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 586 | } |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 587 | |
| 588 | NSMenu* copySubmenu = [[NSMenu alloc] init]; |
| 589 | NSMenu* callSubmenu = [[NSMenu alloc] init]; |
| 590 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 591 | for (auto cm : contactmethods) { |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 592 | NSMenuItem* tmpCopyItem = [[NSMenuItem alloc] initWithTitle:cm->uri().toNSString() |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 593 | action:@selector(copyStringToPasteboard:) |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 594 | keyEquivalent:@""]; |
| 595 | |
| 596 | [tmpCopyItem setRepresentedObject:cm->uri().toNSString()]; |
| 597 | [copySubmenu addItem:tmpCopyItem]; |
| 598 | |
| 599 | NSMenuItem* tmpCallItem = [[NSMenuItem alloc] initWithTitle:cm->uri().toNSString() |
| 600 | action:@selector(callNumber:) |
| 601 | keyEquivalent:@""]; |
| 602 | [tmpCallItem setRepresentedObject:cm->uri().toNSString()]; |
| 603 | [callSubmenu addItem:tmpCallItem]; |
| 604 | } |
| 605 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 606 | NSMenuItem* copyNumberItem = [[NSMenuItem alloc] init]; |
| 607 | [copyNumberItem setTitle:NSLocalizedString(@"Copy number", @"Contextual menu action")]; |
| 608 | [copyNumberItem setSubmenu:copySubmenu]; |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 609 | |
| 610 | NSMenuItem* callItems = [[NSMenuItem alloc] init]; |
| 611 | [callItems setTitle:NSLocalizedString(@"Call number", @"Contextual menu action")]; |
| 612 | [callItems setSubmenu:callSubmenu]; |
| 613 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 614 | [theMenu insertItem:copyNumberItem atIndex:theMenu.itemArray.count]; |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 615 | [theMenu insertItem:[NSMenuItem separatorItem] atIndex:theMenu.itemArray.count]; |
| 616 | [theMenu insertItem:callItems atIndex:theMenu.itemArray.count]; |
| 617 | |
| 618 | return theMenu; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 619 | } |
| 620 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 621 | @end |