Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -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 | 8521baa | 2015-03-13 11:08:00 -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. |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 18 | */ |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 19 | #import "HistoryVC.h" |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 20 | |
Alexandre Lision | 34e738e | 2015-09-24 14:13:23 -0400 | [diff] [blame] | 21 | //Qt |
Alexandre Lision | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 22 | #import <QSortFilterProxyModel> |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 23 | #import <QtMacExtras/qmacfunctions.h> |
| 24 | #import <QPixmap> |
Alexandre Lision | 34e738e | 2015-09-24 14:13:23 -0400 | [diff] [blame] | 25 | |
| 26 | //LRC |
| 27 | #import <categorizedhistorymodel.h> |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 28 | #import <callmodel.h> |
| 29 | #import <call.h> |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 30 | #import <person.h> |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 31 | #import <contactmethod.h> |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 32 | #import <globalinstances.h> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 33 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 34 | #import "QNSTreeController.h" |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 35 | #import "PersonLinkerVC.h" |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 36 | #import "views/HoverTableRowView.h" |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 37 | #import "delegates/ImageManipulationDelegate.h" |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 38 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 39 | @interface HistoryVC() <NSPopoverDelegate, KeyboardShortcutDelegate, ContactLinkedDelegate> { |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 40 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 41 | QNSTreeController *treeController; |
| 42 | IBOutlet RingOutlineView *historyView; |
| 43 | QSortFilterProxyModel *historyProxyModel; |
| 44 | NSPopover* addToContactPopover; |
| 45 | } |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 46 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 47 | @end |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 48 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 49 | @implementation HistoryVC |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 50 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 51 | // Tags for Views |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 52 | NSInteger const DIRECTION_TAG = 100; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 53 | NSInteger const DISPLAYNAME_TAG = 200; |
| 54 | NSInteger const DETAILS_TAG = 300; |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 55 | NSInteger const PHOTO_TAG = 400; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 56 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 57 | - (void)awakeFromNib |
| 58 | { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 59 | NSLog(@"INIT HVC"); |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 60 | historyProxyModel = new QSortFilterProxyModel(&CategorizedHistoryModel::instance()); |
| 61 | historyProxyModel->setSourceModel(&CategorizedHistoryModel::instance()); |
Alexandre Lision | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 62 | historyProxyModel->setSortRole(static_cast<int>(Call::Role::Date)); |
| 63 | historyProxyModel->sort(0,Qt::DescendingOrder); |
| 64 | treeController = [[QNSTreeController alloc] initWithQModel:historyProxyModel]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 65 | |
| 66 | [treeController setAvoidsEmptySelection:NO]; |
| 67 | [treeController setChildrenKeyPath:@"children"]; |
| 68 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 69 | [historyView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 70 | [historyView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 71 | [historyView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 72 | [historyView setTarget:self]; |
Alexandre Lision | 3b0bd33 | 2015-03-15 18:43:07 -0400 | [diff] [blame] | 73 | [historyView setDoubleAction:@selector(placeHistoryCall:)]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 74 | [historyView setContextMenuDelegate:self]; |
| 75 | [historyView setShortcutsDelegate:self]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 76 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 77 | QObject::connect(&CallModel::instance(), |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 78 | &CategorizedHistoryModel::dataChanged, |
| 79 | [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) { |
| 80 | [historyView reloadDataForRowIndexes: |
| 81 | [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(topLeft.row(), bottomRight.row() + 1)] |
| 82 | columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, historyView.tableColumns.count)]]; |
| 83 | }); |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 84 | } |
| 85 | |
Alexandre Lision | 54b0fae | 2015-08-04 15:19:01 -0400 | [diff] [blame] | 86 | - (void) dealloc |
| 87 | { |
| 88 | delete historyProxyModel; |
| 89 | } |
| 90 | |
Alexandre Lision | 3b0bd33 | 2015-03-15 18:43:07 -0400 | [diff] [blame] | 91 | - (void)placeHistoryCall:(id)sender |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 92 | { |
| 93 | if([[treeController selectedNodes] count] > 0) { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 94 | auto item = [treeController selectedNodes][0]; |
| 95 | QModelIndex qIdx = [treeController toQIdx:item]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 96 | if (!qIdx.parent().isValid()) { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 97 | if ([historyView isItemExpanded:item]) { |
| 98 | [[historyView animator] collapseItem:item]; |
| 99 | } else |
| 100 | [[historyView animator] expandItem:item]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 101 | return; |
| 102 | } |
Alexandre Lision | 7837e4f | 2015-03-23 09:58:12 -0400 | [diff] [blame] | 103 | QVariant var = historyProxyModel->data(qIdx, (int)Call::Role::ContactMethod); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 104 | ContactMethod* m = qvariant_cast<ContactMethod*>(var); |
| 105 | if(m){ |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 106 | auto c = CallModel::instance().dialingCall(); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 107 | c->setPeerContactMethod(m); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 108 | c << Call::Action::ACCEPT; |
Alexandre Lision | 89edc6a | 2015-11-09 11:30:47 -0500 | [diff] [blame] | 109 | CallModel::instance().selectCall(c); |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 114 | #pragma mark - NSOutlineViewDelegate methods |
| 115 | |
| 116 | // ------------------------------------------------------------------------------- |
| 117 | // shouldSelectItem:item |
| 118 | // ------------------------------------------------------------------------------- |
| 119 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 120 | { |
| 121 | return YES; |
| 122 | } |
| 123 | |
| 124 | // ------------------------------------------------------------------------------- |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 125 | // shouldEditTableColumn:tableColumn:item |
| 126 | // |
| 127 | // Decide to allow the edit of the given outline view "item". |
| 128 | // ------------------------------------------------------------------------------- |
| 129 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 130 | { |
| 131 | return NO; |
| 132 | } |
| 133 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 134 | - (NSImage*) image:(NSImage*) img withTintedWithColor:(NSColor *)tint |
| 135 | { |
| 136 | if (tint) { |
| 137 | [img lockFocus]; |
| 138 | [tint set]; |
| 139 | NSRect imageRect = {NSZeroPoint, [img size]}; |
| 140 | NSRectFillUsingOperation(imageRect, NSCompositeSourceAtop); |
| 141 | [img unlockFocus]; |
| 142 | } |
| 143 | return img; |
| 144 | } |
| 145 | |
| 146 | /* View Based OutlineView: See the delegate method -tableView:viewForTableColumn:row: in NSTableView. |
| 147 | */ |
| 148 | - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 149 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 150 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 151 | |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 152 | NSTableCellView* result; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 153 | if(!qIdx.parent().isValid()) { |
| 154 | result = [outlineView makeViewWithIdentifier:@"CategoryCell" owner:outlineView]; |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 155 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 156 | } else { |
| 157 | result = [outlineView makeViewWithIdentifier:@"HistoryCell" owner:outlineView]; |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 158 | NSImageView* directionView = [result viewWithTag:DIRECTION_TAG]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 159 | |
| 160 | if (qvariant_cast<Call::Direction>(qIdx.data((int)Call::Role::Direction)) == Call::Direction::INCOMING) { |
| 161 | if (qvariant_cast<Boolean>(qIdx.data((int) Call::Role::Missed))) { |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 162 | [directionView setImage:[self image:[NSImage imageNamed:@"ic_call_missed"] withTintedWithColor:[NSColor redColor]]]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 163 | } else { |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 164 | [directionView setImage:[self image:[NSImage imageNamed:@"ic_call_received"] |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 165 | withTintedWithColor:[NSColor colorWithCalibratedRed:116/255.0 green:179/255.0 blue:93/255.0 alpha:1.0]]]; |
| 166 | } |
| 167 | } else { |
| 168 | if (qvariant_cast<Boolean>(qIdx.data((int) Call::Role::Missed))) { |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 169 | [directionView setImage:[self image:[NSImage imageNamed:@"ic_call_missed"] withTintedWithColor:[NSColor redColor]]]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 170 | } else { |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 171 | [directionView setImage:[self image:[NSImage imageNamed:@"ic_call_made"] |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 172 | withTintedWithColor:[NSColor colorWithCalibratedRed:116/255.0 green:179/255.0 blue:93/255.0 alpha:1.0]]]; |
| 173 | } |
| 174 | } |
| 175 | |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 176 | auto call = qvariant_cast<Call*>(qIdx.data((int)Call::Role::Object)); |
| 177 | |
| 178 | NSImageView* photoView = [result viewWithTag:PHOTO_TAG]; |
Alexandre Lision | 43e91bc | 2016-04-19 18:04:52 -0400 | [diff] [blame^] | 179 | [photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(qIdx.data(Qt::DecorationRole)))]; |
Alexandre Lision | d5229f3 | 2015-11-16 11:17:41 -0500 | [diff] [blame] | 180 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 181 | NSTextField* details = [result viewWithTag:DETAILS_TAG]; |
| 182 | [details setStringValue:qIdx.data((int)Call::Role::FormattedDate).toString().toNSString()]; |
| 183 | } |
| 184 | |
| 185 | NSTextField* displayName = [result viewWithTag:DISPLAYNAME_TAG]; |
| 186 | [displayName setStringValue:qIdx.data(Qt::DisplayRole).toString().toNSString()]; |
| 187 | |
| 188 | return result; |
| 189 | } |
| 190 | |
| 191 | - (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item |
| 192 | { |
| 193 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 194 | if(!qIdx.parent().isValid()) { |
| 195 | return 35.0; |
| 196 | } else { |
| 197 | return 48.0; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 201 | /* View Based OutlineView: See the delegate method -tableView:rowViewForRow: in NSTableView. |
| 202 | */ |
| 203 | - (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 204 | { |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 205 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 206 | |
| 207 | HoverTableRowView* result = [outlineView makeViewWithIdentifier:@"HoverRowView" owner:nil]; |
| 208 | if(!qIdx.parent().isValid()) { |
| 209 | [result setHighlightable:NO]; |
| 210 | } else |
| 211 | [result setHighlightable:YES]; |
| 212 | |
| 213 | return result; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 214 | } |
| 215 | |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 216 | #pragma mark - ContextMenuDelegate |
| 217 | |
Alexandre Lision | 12946a7 | 2016-03-08 13:39:34 -0500 | [diff] [blame] | 218 | - (NSMenu*) contextualMenuForIndex:(NSTreeNode*) item |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 219 | { |
Alexandre Lision | 12946a7 | 2016-03-08 13:39:34 -0500 | [diff] [blame] | 220 | |
| 221 | QModelIndex qIdx = [treeController toQIdx:item]; |
| 222 | if (!qIdx.isValid()) { |
| 223 | return nil; |
| 224 | } |
| 225 | |
| 226 | const auto& var = qIdx.data(static_cast<int>(Call::Role::Object)); |
| 227 | if (qIdx.parent().isValid() && var.isValid()) { |
| 228 | if (auto call = var.value<Call *>()) { |
| 229 | auto contactmethod = call->peerContactMethod(); |
| 230 | if (!contactmethod->contact() || contactmethod->contact()->isPlaceHolder()) { |
| 231 | NSMenu *theMenu = [[NSMenu alloc] |
| 232 | initWithTitle:@""]; |
| 233 | [theMenu insertItemWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action") |
| 234 | action:@selector(addToContact) |
| 235 | keyEquivalent:@"a" |
| 236 | atIndex:0]; |
| 237 | return theMenu; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | } |
| 241 | return nil; |
| 242 | } |
| 243 | |
| 244 | - (void) addToContact |
| 245 | { |
| 246 | ContactMethod* contactmethod = nullptr; |
| 247 | if([[treeController selectedNodes] count] > 0) { |
| 248 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 249 | const auto& var = qIdx.data(static_cast<int>(Call::Role::Object)); |
| 250 | if (qIdx.parent().isValid() && var.isValid()) { |
| 251 | if (auto call = var.value<Call *>()) { |
| 252 | contactmethod = call->peerContactMethod(); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 257 | if (addToContactPopover != nullptr) { |
| 258 | [addToContactPopover performClose:self]; |
| 259 | addToContactPopover = NULL; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 260 | } else if (contactmethod) { |
Alexandre Lision | ae840f2 | 2015-08-04 15:02:16 -0400 | [diff] [blame] | 261 | auto* editorVC = [[PersonLinkerVC alloc] initWithNibName:@"PersonLinker" bundle:nil]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 262 | [editorVC setMethodToLink:contactmethod]; |
| 263 | [editorVC setContactLinkedDelegate:self]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 264 | addToContactPopover = [[NSPopover alloc] init]; |
| 265 | [addToContactPopover setContentSize:editorVC.view.frame.size]; |
| 266 | [addToContactPopover setContentViewController:editorVC]; |
| 267 | [addToContactPopover setAnimates:YES]; |
| 268 | [addToContactPopover setBehavior:NSPopoverBehaviorTransient]; |
| 269 | [addToContactPopover setDelegate:self]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 270 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 271 | [addToContactPopover showRelativeToRect:[historyView frameOfOutlineCellAtRow:[historyView selectedRow]] ofView:historyView preferredEdge:NSMaxXEdge]; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
| 275 | #pragma mark - NSPopOverDelegate |
| 276 | |
| 277 | - (void)popoverDidClose:(NSNotification *)notification |
| 278 | { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 279 | if (addToContactPopover != nullptr) { |
| 280 | [addToContactPopover performClose:self]; |
| 281 | addToContactPopover = NULL; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | #pragma mark - ContactLinkedDelegate |
| 286 | |
| 287 | - (void)contactLinked |
| 288 | { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 289 | if (addToContactPopover != nullptr) { |
| 290 | [addToContactPopover performClose:self]; |
| 291 | addToContactPopover = NULL; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
| 295 | #pragma mark - KeyboardShortcutDelegate |
| 296 | |
| 297 | - (void) onAddShortcut |
| 298 | { |
| 299 | if([[treeController selectedNodes] count] > 0) { |
| 300 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 301 | const auto& var = qIdx.data(static_cast<int>(Call::Role::Object)); |
| 302 | if (qIdx.parent().isValid() && var.isValid()) { |
| 303 | if (auto call = var.value<Call *>()) { |
| 304 | auto contactmethod = call->peerContactMethod(); |
| 305 | if (!contactmethod->contact() || contactmethod->contact()->isPlaceHolder()) { |
| 306 | [self addToContact]; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 313 | @end |