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> |
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" |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 47 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 48 | @interface SmartViewVC () <NSTableViewDelegate, NSTableViewDataSource, NSPopoverDelegate, ContextMenuDelegate, ContactLinkedDelegate, KeyboardShortcutDelegate> { |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 49 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 50 | NSPopover* addToContactPopover; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 51 | |
| 52 | //UI elements |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 53 | __unsafe_unretained IBOutlet RingTableView* smartView; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 54 | __unsafe_unretained IBOutlet NSSearchField* searchField; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 55 | |
| 56 | /* Pending ring usernames lookup for the search entry */ |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 57 | QMetaObject::Connection usernameLookupConnection, modelSortedConnection_, filterChangedConnection_; |
| 58 | |
| 59 | lrc::api::ConversationModel* model_; |
| 60 | std::string selectedUid_; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @end |
| 64 | |
| 65 | @implementation SmartViewVC |
| 66 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 67 | @synthesize tabbar; |
| 68 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 69 | // Tags for views |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 70 | NSInteger const IMAGE_TAG = 100; |
| 71 | NSInteger const DISPLAYNAME_TAG = 200; |
| 72 | NSInteger const DETAILS_TAG = 300; |
| 73 | NSInteger const CALL_BUTTON_TAG = 400; |
| 74 | NSInteger const TXT_BUTTON_TAG = 500; |
| 75 | NSInteger const CANCEL_BUTTON_TAG = 600; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 76 | NSInteger const RING_ID_LABEL = 700; |
Kateryna Kostiuk | d9039e9 | 2017-05-24 14:29:54 -0400 | [diff] [blame] | 77 | NSInteger const PRESENCE_TAG = 800; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 78 | |
| 79 | - (void)awakeFromNib |
| 80 | { |
| 81 | NSLog(@"INIT SmartView VC"); |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 82 | //get selected account |
| 83 | //encapsulate conversationmodel in local version |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 84 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 85 | [smartView setTarget:self]; |
| 86 | [smartView setDoubleAction:@selector(placeCall:)]; |
| 87 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 88 | [smartView setContextMenuDelegate:self]; |
| 89 | [smartView setShortcutsDelegate:self]; |
| 90 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 91 | [smartView setDataSource: self]; |
Kateryna Kostiuk | 1f705ab | 2017-04-18 12:45:59 -0400 | [diff] [blame] | 92 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 93 | [self.view setWantsLayer:YES]; |
| 94 | [self.view setLayer:[CALayer layer]]; |
| 95 | [self.view.layer setBackgroundColor:[NSColor whiteColor].CGColor]; |
| 96 | |
| 97 | [searchField setWantsLayer:YES]; |
| 98 | [searchField setLayer:[CALayer layer]]; |
| 99 | [searchField.layer setBackgroundColor:[NSColor colorWithCalibratedRed:0.949 green:0.949 blue:0.949 alpha:0.9].CGColor]; |
| 100 | } |
| 101 | |
| 102 | - (void)placeCall:(id)sender |
| 103 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 104 | NSInteger row; |
| 105 | if (sender != nil && [sender clickedRow] != -1) |
| 106 | row = [sender clickedRow]; |
| 107 | else if ([smartView selectedRow] != -1) |
| 108 | row = [smartView selectedRow]; |
| 109 | else |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 110 | return; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 111 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 112 | auto conv = model_->filteredConversation(row); |
| 113 | model_->placeCall(conv.uid); |
| 114 | } |
| 115 | |
| 116 | -(void) reloadData |
| 117 | { |
| 118 | [smartView deselectAll:nil]; |
| 119 | [smartView reloadData]; |
| 120 | |
| 121 | if (!selectedUid_.empty() && model_ != nil) { |
| 122 | auto it = std::find_if(model_->allFilteredConversations().begin(), model_->allFilteredConversations().end(), |
| 123 | [self] (const lrc::api::conversation::Info& conv) { |
| 124 | return selectedUid_ == conv.uid; |
| 125 | }); |
| 126 | if (it != model_->allFilteredConversations().end()) { |
| 127 | NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())]; |
| 128 | [smartView selectRowIndexes:indexSet byExtendingSelection:NO]; |
| 129 | } else { |
| 130 | selectedUid_.clear(); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 134 | [smartView scrollToBeginningOfDocument:nil]; |
| 135 | } |
| 136 | |
| 137 | - (void)setConversationModel:(lrc::api::ConversationModel *)conversationModel |
| 138 | { |
| 139 | if (model_ != conversationModel) { |
| 140 | model_ = conversationModel; |
| 141 | [self reloadData]; |
| 142 | QObject::disconnect(modelSortedConnection_); |
| 143 | if (model_ != nil) { |
| 144 | modelSortedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::modelSorted, |
| 145 | [self] (){ |
| 146 | [self reloadData]; |
| 147 | }); |
| 148 | filterChangedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::filterChanged, |
| 149 | [self] (){ |
| 150 | [self reloadData]; |
| 151 | }); |
| 152 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 156 | #pragma mark - NSTableViewDelegate methods |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 157 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 158 | - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 159 | { |
| 160 | return YES; |
| 161 | } |
| 162 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 163 | - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 164 | { |
| 165 | return NO; |
| 166 | } |
| 167 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 168 | - (void)tableViewSelectionDidChange:(NSNotification *)notification |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 169 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 170 | NSInteger row = [notification.object selectedRow]; |
| 171 | |
| 172 | if (row == -1) |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 173 | return; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 174 | |
| 175 | auto uid = model_->filteredConversation(row).uid; |
| 176 | if (selectedUid_ != uid) { |
| 177 | selectedUid_ = uid; |
| 178 | model_->selectConversation(uid); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 179 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 182 | - (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 183 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 184 | return [tableView makeViewWithIdentifier:@"HoverRowView" owner:nil]; |
| 185 | } |
Alexandre Lision | a4bb051 | 2016-04-19 18:04:31 -0400 | [diff] [blame] | 186 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 187 | - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
| 188 | { |
| 189 | if (model_ == nil) |
| 190 | return nil; |
| 191 | |
| 192 | auto conversation = model_->filteredConversation(row); |
Alexandre Lision | a4bb051 | 2016-04-19 18:04:31 -0400 | [diff] [blame] | 193 | NSTableCellView* result; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 194 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 195 | result = [tableView makeViewWithIdentifier:@"MainCell" owner:tableView]; |
| 196 | // NSTextField* details = [result viewWithTag:DETAILS_TAG]; |
Alexandre Lision | 4e280d6 | 2015-09-09 15:56:30 -0400 | [diff] [blame] | 197 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 198 | NSMutableArray* controls = [NSMutableArray arrayWithObject:[result viewWithTag:CALL_BUTTON_TAG]]; |
| 199 | [((ContextualTableCellView*) result) setContextualsControls:controls]; |
| 200 | [((ContextualTableCellView*) result) setShouldBlurParentView:YES]; |
Alexandre Lision | 21666f3 | 2015-09-22 17:04:36 -0400 | [diff] [blame] | 201 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 202 | // if (auto call = RecentModel::instance().getActiveCall(qIdx)) { |
| 203 | // [details setStringValue:call->roleData((int)Ring::Role::FormattedState).toString().toNSString()]; |
| 204 | // [((ContextualTableCellView*) result) setActiveState:YES]; |
| 205 | // } else { |
| 206 | // [details setStringValue:qIdx.data((int)Ring::Role::FormattedLastUsed).toString().toNSString()]; |
| 207 | // [((ContextualTableCellView*) result) setActiveState:NO]; |
| 208 | // } |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 209 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 210 | NSTextField* unreadCount = [result viewWithTag:TXT_BUTTON_TAG]; |
| 211 | [unreadCount setHidden:(conversation.unreadMessages == 0)]; |
| 212 | [unreadCount setIntValue:conversation.unreadMessages]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 213 | |
| 214 | NSTextField* displayName = [result viewWithTag:DISPLAYNAME_TAG]; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 215 | NSString* displayNameString = bestNameForConversation(conversation, *model_); |
| 216 | NSString* displayIDString = bestIDForConversation(conversation, *model_); |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 217 | if(displayNameString.length == 0 || [displayNameString isEqualToString:displayIDString]) { |
Anthony LĂ©onard | 4adc3f0 | 2017-07-21 10:23:04 -0400 | [diff] [blame] | 218 | NSTextField* displayRingID = [result viewWithTag:RING_ID_LABEL]; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 219 | [displayName setStringValue:displayIDString]; |
Anthony LĂ©onard | 4adc3f0 | 2017-07-21 10:23:04 -0400 | [diff] [blame] | 220 | [displayRingID setHidden:YES]; |
Kateryna Kostiuk | 9d6657a | 2017-04-25 13:42:25 -0400 | [diff] [blame] | 221 | } |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 222 | else { |
| 223 | NSTextField* displayRingID = [result viewWithTag:RING_ID_LABEL]; |
| 224 | [displayName setStringValue:displayNameString]; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 225 | [displayRingID setStringValue:displayIDString]; |
Anthony LĂ©onard | 4adc3f0 | 2017-07-21 10:23:04 -0400 | [diff] [blame] | 226 | [displayRingID setHidden:NO]; |
Kateryna Kostiuk | 6a53636 | 2017-05-02 14:26:12 -0400 | [diff] [blame] | 227 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 228 | NSImageView* photoView = [result viewWithTag:IMAGE_TAG]; |
Alexandre Lision | 43e91bc | 2016-04-19 18:04:52 -0400 | [diff] [blame] | 229 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 230 | auto& imageManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator()); |
| 231 | [photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(imageManip.conversationPhoto(conversation, model_->owner)))]; |
Kateryna Kostiuk | d9039e9 | 2017-05-24 14:29:54 -0400 | [diff] [blame] | 232 | |
| 233 | NSView* presenceView = [result viewWithTag:PRESENCE_TAG]; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 234 | if (model_->owner.contactModel->getContact(conversation.participants[0]).isPresent) { |
Kateryna Kostiuk | d9039e9 | 2017-05-24 14:29:54 -0400 | [diff] [blame] | 235 | [presenceView setHidden:NO]; |
| 236 | } else { |
| 237 | [presenceView setHidden:YES]; |
| 238 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 239 | return result; |
| 240 | } |
| 241 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 242 | - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 243 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 244 | return 60.0; |
| 245 | } |
| 246 | |
| 247 | #pragma mark - NSTableDataSource methods |
| 248 | |
| 249 | - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView |
| 250 | { |
| 251 | if (tableView == smartView) { |
| 252 | if (model_ != nullptr) |
| 253 | return model_->allFilteredConversations().size(); |
| 254 | } |
| 255 | |
| 256 | return 0; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 257 | } |
| 258 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 259 | - (void)startCallForRow:(id)sender { |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 260 | NSInteger row = [smartView rowForView:sender]; |
| 261 | [smartView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; |
| 262 | [self placeCall:nil]; |
| 263 | } |
| 264 | |
| 265 | - (IBAction)hangUpClickedAtRow:(id)sender { |
| 266 | NSInteger row = [smartView rowForView:sender]; |
Alexandre Lision | 57914fa | 2016-02-10 14:52:24 -0500 | [diff] [blame] | 267 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 268 | if (row == -1) |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 269 | return; |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 270 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 271 | auto conv = model_->filteredConversation(row); |
| 272 | auto& callId = conv.callId; |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 273 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 274 | if (callId.empty()) |
| 275 | return; |
| 276 | |
| 277 | auto* callModel = model_->owner.callModel.get(); |
| 278 | callModel->hangUp(callId); |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 279 | } |
| 280 | |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 281 | - (void) displayErrorModalWithTitle:(NSString*) title WithMessage:(NSString*) message |
| 282 | { |
| 283 | NSAlert* alert = [NSAlert alertWithMessageText:title |
| 284 | defaultButton:@"Ok" |
| 285 | alternateButton:nil |
| 286 | otherButton:nil |
| 287 | informativeTextWithFormat:message]; |
| 288 | |
| 289 | [alert beginSheetModalForWindow:self.view.window modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; |
| 290 | } |
| 291 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 292 | - (void) processSearchFieldInput |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 293 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 294 | model_->setFilter(std::string([[searchField stringValue] UTF8String])); |
Alexandre Lision | 45c1867 | 2016-11-02 15:24:45 -0400 | [diff] [blame] | 295 | } |
| 296 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 297 | -(const lrc::api::account::Info&) chosenAccount |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 298 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 299 | return model_->owner; |
Kateryna Kostiuk | d2f7b5d | 2017-06-09 15:30:49 -0400 | [diff] [blame] | 300 | } |
| 301 | |
Alexandre Lision | f909fb1 | 2016-11-03 12:35:36 -0400 | [diff] [blame] | 302 | - (void) clearSearchField |
| 303 | { |
| 304 | [searchField setStringValue:@""]; |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 305 | [self processSearchFieldInput]; |
Kateryna Kostiuk | 9dd759c | 2017-07-11 12:06:55 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 308 | /** |
| 309 | Copy a NSString in the general Pasteboard |
| 310 | |
| 311 | @param sender the NSObject containing the represented object to copy |
| 312 | */ |
| 313 | - (void) copyStringToPasteboard:(id) sender |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 314 | { |
| 315 | NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard]; |
| 316 | [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
| 317 | [pasteBoard setString:[sender representedObject] forType:NSStringPboardType]; |
| 318 | } |
| 319 | |
Alexandre Lision | bf0385e | 2015-10-22 17:36:28 -0400 | [diff] [blame] | 320 | #pragma NSTextFieldDelegate |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 321 | |
| 322 | - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector |
| 323 | { |
| 324 | if (commandSelector == @selector(insertNewline:)) { |
| 325 | if([[searchField stringValue] isNotEqualTo:@""]) { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 326 | [self processSearchFieldInput]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 327 | return YES; |
| 328 | } |
| 329 | } |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 330 | return NO; |
| 331 | } |
| 332 | |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 333 | - (void)controlTextDidChange:(NSNotification *) notification |
| 334 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 335 | [self processSearchFieldInput]; |
Alexandre Lision | ac4f5b6 | 2016-02-17 13:53:12 -0500 | [diff] [blame] | 336 | } |
| 337 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 338 | #pragma mark - NSPopOverDelegate |
| 339 | |
| 340 | - (void)popoverDidClose:(NSNotification *)notification |
| 341 | { |
| 342 | if (addToContactPopover != nullptr) { |
| 343 | [addToContactPopover performClose:self]; |
| 344 | addToContactPopover = NULL; |
| 345 | } |
| 346 | } |
| 347 | |
Alexandre Lision | bf0385e | 2015-10-22 17:36:28 -0400 | [diff] [blame] | 348 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 349 | #pragma mark - ContactLinkedDelegate |
| 350 | |
| 351 | - (void)contactLinked |
| 352 | { |
| 353 | if (addToContactPopover != nullptr) { |
| 354 | [addToContactPopover performClose:self]; |
| 355 | addToContactPopover = NULL; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | #pragma mark - KeyboardShortcutDelegate |
| 360 | |
| 361 | - (void) onAddShortcut |
| 362 | { |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 363 | if ([smartView selectedRow] == -1) |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 364 | return; |
| 365 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 366 | auto uid = model_->filteredConversation([smartView selectedRow]).uid; |
| 367 | model_->makePermanent(uid); |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | #pragma mark - ContextMenuDelegate |
| 371 | |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 372 | #if 0 |
| 373 | // TODO: Reimplement contextual menu with new models and behaviors |
Alexandre Lision | 12946a7 | 2016-03-08 13:39:34 -0500 | [diff] [blame] | 374 | - (NSMenu*) contextualMenuForIndex:(NSTreeNode*) item |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 375 | { |
Alexandre Lision | 12946a7 | 2016-03-08 13:39:34 -0500 | [diff] [blame] | 376 | auto qIdx = [treeController toQIdx:item]; |
| 377 | |
| 378 | if (!qIdx.isValid()) { |
| 379 | return nil; |
| 380 | } |
| 381 | |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 382 | auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx); |
| 383 | auto contactmethods = RecentModel::instance().getContactMethods(originIdx); |
| 384 | if (contactmethods.isEmpty()) |
| 385 | return nil; |
| 386 | |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 387 | NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@""]; |
| 388 | |
| 389 | if (contactmethods.size() == 1 |
| 390 | && !contactmethods.first()->contact() |
| 391 | || contactmethods.first()->contact()->isPlaceHolder()) { |
| 392 | |
Kateryna Kostiuk | 9dd759c | 2017-07-11 12:06:55 -0400 | [diff] [blame] | 393 | NSMenuItem* addContactItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action") |
| 394 | action:@selector(addContactForRow:) |
| 395 | keyEquivalent:@""]; |
| 396 | [addContactItem setRepresentedObject:item]; |
| 397 | [theMenu addItem:addContactItem]; |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 398 | } else if (auto person = contactmethods.first()->contact()) { |
| 399 | NSMenuItem* copyNameItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Copy name", @"Contextual menu action") |
| 400 | action:@selector(copyStringToPasteboard:) |
| 401 | keyEquivalent:@""]; |
| 402 | |
| 403 | [copyNameItem setRepresentedObject:person->formattedName().toNSString()]; |
| 404 | [theMenu addItem:copyNameItem]; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 405 | } |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 406 | |
| 407 | NSMenu* copySubmenu = [[NSMenu alloc] init]; |
| 408 | NSMenu* callSubmenu = [[NSMenu alloc] init]; |
| 409 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 410 | for (auto cm : contactmethods) { |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 411 | NSMenuItem* tmpCopyItem = [[NSMenuItem alloc] initWithTitle:cm->uri().toNSString() |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 412 | action:@selector(copyStringToPasteboard:) |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 413 | keyEquivalent:@""]; |
| 414 | |
| 415 | [tmpCopyItem setRepresentedObject:cm->uri().toNSString()]; |
| 416 | [copySubmenu addItem:tmpCopyItem]; |
| 417 | |
| 418 | NSMenuItem* tmpCallItem = [[NSMenuItem alloc] initWithTitle:cm->uri().toNSString() |
| 419 | action:@selector(callNumber:) |
| 420 | keyEquivalent:@""]; |
| 421 | [tmpCallItem setRepresentedObject:cm->uri().toNSString()]; |
| 422 | [callSubmenu addItem:tmpCallItem]; |
| 423 | } |
| 424 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 425 | NSMenuItem* copyNumberItem = [[NSMenuItem alloc] init]; |
| 426 | [copyNumberItem setTitle:NSLocalizedString(@"Copy number", @"Contextual menu action")]; |
| 427 | [copyNumberItem setSubmenu:copySubmenu]; |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 428 | |
| 429 | NSMenuItem* callItems = [[NSMenuItem alloc] init]; |
| 430 | [callItems setTitle:NSLocalizedString(@"Call number", @"Contextual menu action")]; |
| 431 | [callItems setSubmenu:callSubmenu]; |
| 432 | |
Alexandre Lision | 72a669e | 2016-09-14 17:52:16 -0400 | [diff] [blame] | 433 | [theMenu insertItem:copyNumberItem atIndex:theMenu.itemArray.count]; |
Alexandre Lision | d7bf288 | 2015-10-22 22:54:32 -0400 | [diff] [blame] | 434 | [theMenu insertItem:[NSMenuItem separatorItem] atIndex:theMenu.itemArray.count]; |
| 435 | [theMenu insertItem:callItems atIndex:theMenu.itemArray.count]; |
| 436 | |
| 437 | return theMenu; |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 438 | } |
Olivier Soldano | d431155 | 2017-11-20 15:09:53 -0500 | [diff] [blame^] | 439 | #endif |
Alexandre Lision | 61db355 | 2015-10-22 19:12:52 -0400 | [diff] [blame] | 440 | |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 441 | @end |