blob: 8ba43c4d2e6a6bc3aa42687c71674414cbc6288a [file] [log] [blame]
Alexandre Lision8521baa2015-03-13 11:08:00 -04001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lision8521baa2015-03-13 11:08:00 -04003 * 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 Lision8521baa2015-03-13 11:08:00 -040018 */
Alexandre Lision5855b6a2015-02-03 11:31:05 -050019#import "RingWindowController.h"
Alexandre Lision0f66bd32016-01-18 11:30:45 -050020#import <QuartzCore/QuartzCore.h>
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -040021#include <qrencode.h>
Anthony Léonard79597602017-11-13 15:47:09 -050022#include <memory>
Alexandre Lision0f66bd32016-01-18 11:30:45 -050023
24//Qt
25#import <QItemSelectionModel>
26#import <QItemSelection>
Alexandre Lision5855b6a2015-02-03 11:31:05 -050027
Alexandre Lisionbb5c2462015-07-30 12:55:37 -040028//LRC
Alexandre Lision5855b6a2015-02-03 11:31:05 -050029#import <callmodel.h>
30#import <account.h>
Alexandre Lision91d11e52015-03-20 17:42:05 -040031#import <call.h>
Alexandre Lision0f66bd32016-01-18 11:30:45 -050032#import <recentmodel.h>
Kateryna Kostiuk312f9132017-04-18 12:09:06 -040033#import <AvailableAccountModel.h>
Anthony Léonard79597602017-11-13 15:47:09 -050034#import <api/lrc.h>
Anthony Léonard49cb2912017-11-13 16:15:39 -050035#import <api/account.h>
Olivier Soldano994971f2017-12-05 16:30:12 -050036#import <api/newaccountmodel.h>
37#import <api/newcallmodel.h>
38#import <api/behaviorcontroller.h>
39#import <api/conversation.h>
40
Alexandre Lision5855b6a2015-02-03 11:31:05 -050041
Alexandre Lision624b1a82016-09-11 19:29:01 -040042// Ring
Alexandre Lision745e4d62015-03-22 20:03:10 -040043#import "AppDelegate.h"
Alexandre Lisionc65310c2015-04-23 16:44:23 -040044#import "Constants.h"
Alexandre Lision58cab672015-06-09 15:25:40 -040045#import "CurrentCallVC.h"
Alexandre Lision624b1a82016-09-11 19:29:01 -040046#import "MigrateRingAccountsWC.h"
Alexandre Lision0f66bd32016-01-18 11:30:45 -050047#import "ConversationVC.h"
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040048#import "PreferencesWC.h"
Alexandre Lisiona3a43dc2017-03-30 16:21:30 -040049#import "SmartViewVC.h"
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -040050#import "views/IconButton.h"
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040051#import "views/NSColor+RingTheme.h"
Alexandre Lisione77f6f92016-04-17 23:39:39 -040052#import "views/BackgroundView.h"
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040053#import "ChooseAccountVC.h"
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -040054#import "ContactRequestVC.h"
Alexandre Lision2db8f472015-07-22 15:05:46 -040055
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040056@interface RingWindowController () <MigrateRingAccountsDelegate, NSToolbarDelegate>
Alexandre Lision624b1a82016-09-11 19:29:01 -040057
58@property (retain) MigrateRingAccountsWC* migrateWC;
59
60@end
61
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040062@implementation RingWindowController {
Alexandre Lision5855b6a2015-02-03 11:31:05 -050063
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -040064 __unsafe_unretained IBOutlet NSLayoutConstraint* centerYQRCodeConstraint;
65 __unsafe_unretained IBOutlet NSLayoutConstraint* centerYWelcomeContainerConstraint;
66 __unsafe_unretained IBOutlet NSView* welcomeContainer;
Alexandre Lision1abdf582016-02-09 14:21:19 -050067 __unsafe_unretained IBOutlet NSView* callView;
68 __unsafe_unretained IBOutlet NSTextField* ringIDLabel;
69 __unsafe_unretained IBOutlet NSButton* shareButton;
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -040070 __unsafe_unretained IBOutlet NSImageView* qrcodeView;
Alexandre Lision58cab672015-06-09 15:25:40 -040071
Anthony Léonard79597602017-11-13 15:47:09 -050072 std::unique_ptr<lrc::api::Lrc> lrc_;
73
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -040074 PreferencesWC* preferencesWC;
Alexandre Lisiona3a43dc2017-03-30 16:21:30 -040075 IBOutlet SmartViewVC* smartViewVC;
Alexandre Lisione77f6f92016-04-17 23:39:39 -040076
Alexandre Lision0f66bd32016-01-18 11:30:45 -050077 CurrentCallVC* currentCallVC;
78 ConversationVC* offlineVC;
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -040079 // toolbar menu items
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040080 ChooseAccountVC* chooseAccountVC;
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -040081 ContactRequestVC* contactRequestVC;
Alexandre Lisionbfa68f62015-09-10 08:38:42 -040082}
Alexandre Lision58cab672015-06-09 15:25:40 -040083
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -040084static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
85NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItemIdentifier";
86NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIdentifier";
Alexandre Lisionc5148052015-03-04 15:10:35 -050087
Alexandre Lision5855b6a2015-02-03 11:31:05 -050088- (void)windowDidLoad {
89 [super windowDidLoad];
Alexandre Lision4dfcafc2015-08-20 12:43:23 -040090 [self.window setMovableByWindowBackground:YES];
Alexandre Lision58cab672015-06-09 15:25:40 -040091
Alexandre Lisione77f6f92016-04-17 23:39:39 -040092 [self.window setBackgroundColor:[NSColor colorWithRed:242.0/255 green:242.0/255 blue:242.0/255 alpha:1.0]];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -040093 self.window.titleVisibility = NSWindowTitleHidden;
Alexandre Lisione77f6f92016-04-17 23:39:39 -040094
Anthony Léonard79597602017-11-13 15:47:09 -050095 lrc_ = std::make_unique<lrc::api::Lrc>();
96
Alexandre Lision0f66bd32016-01-18 11:30:45 -050097 currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil];
Anthony Léonard8585cc02017-12-28 14:03:45 -050098 offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil delegate:self];
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -040099 // toolbar items
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500100 chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:&(lrc_->getAccountModel()) delegate:self];
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -0400101 contactRequestVC = [[ContactRequestVC alloc] initWithNibName:@"ContactRequest" bundle:nil];
Alexandre Lision58cab672015-06-09 15:25:40 -0400102 [callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500103 [[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
104 [[offlineVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
Alexandre Lision58cab672015-06-09 15:25:40 -0400105
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500106 [callView addSubview:[currentCallVC view] positioned:NSWindowAbove relativeTo:nil];
107 [callView addSubview:[offlineVC view] positioned:NSWindowAbove relativeTo:nil];
Alexandre Lision16d9c0a2015-08-10 12:05:15 -0400108
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500109 [currentCallVC initFrame];
110 [offlineVC initFrame];
Anthony Léonard72128c92017-12-26 16:48:39 -0500111 @try {
112 [smartViewVC setConversationModel: [chooseAccountVC selectedAccount].conversationModel.get()];
113 }
114 @catch (NSException *ex) {
115 NSLog(@"Caught exception %@: %@", [ex name], [ex reason]);
116 }
Alexandre Lisionbb5c2462015-07-30 12:55:37 -0400117
Anthony Léonard49cb2912017-11-13 16:15:39 -0500118 // Fresh run, we need to make sure RingID appears
119 [shareButton sendActionOn:NSLeftMouseDownMask];
120
Olivier Soldano994971f2017-12-05 16:30:12 -0500121 [self connect];
Anthony Léonard49cb2912017-11-13 16:15:39 -0500122 [self updateRingID];
123 // display accounts to select
124 NSToolbar *toolbar = self.window.toolbar;
125 toolbar.delegate = self;
126 [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1];
127 [toolbar insertItemWithItemIdentifier:kTrustRequestMenuItemIdentifier atIndex:2];
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500128}
129
130- (void) connect
131{
Olivier Soldano994971f2017-12-05 16:30:12 -0500132 QObject::connect(&lrc_->getBehaviorController(),
133 &lrc::api::BehaviorController::showCallView,
134 [self](const std::string accountId,
135 const lrc::api::conversation::Info convInfo){
136 auto* accInfo = &lrc_->getAccountModel().getAccountInfo(accountId);
137 [currentCallVC setCurrentCall:convInfo.callId
138 conversation:convInfo.uid
139 account:accInfo];
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500140 [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()];
Olivier Soldano994971f2017-12-05 16:30:12 -0500141 [currentCallVC animateIn];
142 [offlineVC animateOut];
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500143 });
Alexandre Lision210fe212016-01-27 11:15:13 -0500144
Olivier Soldano994971f2017-12-05 16:30:12 -0500145 QObject::connect(&lrc_->getBehaviorController(),
146 &lrc::api::BehaviorController::showIncomingCallView,
147 [self](const std::string accountId,
148 const lrc::api::conversation::Info convInfo){
149 auto* accInfo = &lrc_->getAccountModel().getAccountInfo(accountId);
150 [currentCallVC setCurrentCall:convInfo.callId
151 conversation:convInfo.uid
152 account:accInfo];
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500153 [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()];
Olivier Soldano994971f2017-12-05 16:30:12 -0500154 [currentCallVC animateIn];
Kateryna Kostiukabf4e272017-04-18 14:18:00 -0400155 [offlineVC animateOut];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400156 });
Anthony Léonard2382b562017-12-13 15:51:28 -0500157
158 QObject::connect(&lrc_->getBehaviorController(),
159 &lrc::api::BehaviorController::showChatView,
160 [self](const std::string& accountId,
161 const lrc::api::conversation::Info& convInfo){
162 auto& accInfo = lrc_->getAccountModel().getAccountInfo(accountId);
163 [offlineVC setConversationUid:convInfo.uid model:accInfo.conversationModel.get()];
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500164 [smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()];
Anthony Léonard2382b562017-12-13 15:51:28 -0500165 [offlineVC animateIn];
166 [currentCallVC animateOut];
167 });
Alexandre Lisionbb5c2462015-07-30 12:55:37 -0400168}
169
170/**
171 * Implement the necessary logic to choose which Ring ID to display.
172 * This tries to choose the "best" ID to show
173 */
174- (void) updateRingID
175{
Anthony Léonard72128c92017-12-26 16:48:39 -0500176 @try {
177 auto& account = [chooseAccountVC selectedAccount];
Alexandre Lisionbb5c2462015-07-30 12:55:37 -0400178
Anthony Léonard72128c92017-12-26 16:48:39 -0500179 [ringIDLabel setStringValue:@""];
Anthony Léonard49cb2912017-11-13 16:15:39 -0500180
Anthony Léonard72128c92017-12-26 16:48:39 -0500181 if(account.profileInfo.type != lrc::api::profile::Type::RING) {
182 self.hideRingID = YES;
183 return;
184 }
185 self.hideRingID = NO;
186 auto& registeredName = account.registeredName;
187 auto& ringID = account.profileInfo.uri;
188 NSString* uriToDisplay = nullptr;
189 if (!registeredName.empty()) {
190 uriToDisplay = @(registeredName.c_str());
191 } else {
192 uriToDisplay = @(ringID.c_str());
193 }
194 [ringIDLabel setStringValue:uriToDisplay];
195 [self drawQRCode:@(ringID.c_str())];
Alexandre Lisionbb5c2462015-07-30 12:55:37 -0400196 }
Anthony Léonard72128c92017-12-26 16:48:39 -0500197 @catch (NSException *ex) {
198 NSLog(@"Caught exception %@: %@", [ex name], [ex reason]);
199 self.hideRingID = NO;
200 [ringIDLabel setStringValue:@"No account available"];
Alexandre Lision313427f2016-11-24 21:04:04 -0500201 }
Alexandre Lision5855b6a2015-02-03 11:31:05 -0500202}
203
Alexandre Lision1abdf582016-02-09 14:21:19 -0500204- (IBAction)shareRingID:(id)sender {
205 NSSharingServicePicker* sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:[NSArray arrayWithObject:[ringIDLabel stringValue]]];
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400206 [sharingServicePicker setDelegate:self];
Alexandre Lision1abdf582016-02-09 14:21:19 -0500207 [sharingServicePicker showRelativeToRect:[sender bounds]
208 ofView:sender
209 preferredEdge:NSMinYEdge];
210}
211
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400212- (IBAction)toggleQRCode:(id)sender {
213 // Toggle pressed state of QRCode button
214 [sender setPressed:![sender isPressed]];
Kateryna Kostiuk65ba43e2017-03-30 15:10:04 -0400215 [self showQRCode:[sender isPressed]];
Alexandre Lision313427f2016-11-24 21:04:04 -0500216}
217
218/**
219 * Draw the QRCode in the qrCodeView
220 */
Kateryna Kostiuk65ba43e2017-03-30 15:10:04 -0400221- (void)drawQRCode:(NSString*) uriToDraw
Alexandre Lision313427f2016-11-24 21:04:04 -0500222{
Kateryna Kostiuk65ba43e2017-03-30 15:10:04 -0400223 auto qrCode = QRcode_encodeString(uriToDraw.UTF8String,
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400224 0,
225 QR_ECLEVEL_L, // Lowest level of error correction
226 QR_MODE_8, // 8-bit data mode
227 1);
228 if (!qrCode) {
229 return;
230 }
231
Alexandre Lision313427f2016-11-24 21:04:04 -0500232 unsigned char *data = 0;
233 int width;
234 data = qrCode->data;
235 width = qrCode->width;
236 int qr_margin = 3;
237
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400238 CGFloat size = qrcodeView.frame.size.width;
239
240 // create context
241 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
242 CGContextRef ctx = CGBitmapContextCreate(0, size, size, 8, size * 4, colorSpace, kCGImageAlphaPremultipliedLast);
243
244 CGAffineTransform translateTransform = CGAffineTransformMakeTranslation(0, -size);
245 CGAffineTransform scaleTransform = CGAffineTransformMakeScale(1, -1);
246 CGContextConcatCTM(ctx, CGAffineTransformConcat(translateTransform, scaleTransform));
247
Alexandre Lision313427f2016-11-24 21:04:04 -0500248 float zoom = ceil((double)size / (qrCode->width + 2.0 * qr_margin));
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400249 CGRect rectDraw = CGRectMake(0, 0, zoom, zoom);
250
251 int ran;
252 for(int i = 0; i < width; ++i) {
253 for(int j = 0; j < width; ++j) {
254 if(*data & 1) {
255 CGContextSetFillColorWithColor(ctx, [NSColor ringDarkGrey].CGColor);
256 rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom);
257 CGContextAddRect(ctx, rectDraw);
258 CGContextFillPath(ctx);
259 } else {
260 CGContextSetFillColorWithColor(ctx, [NSColor windowBackgroundColor].CGColor);
261 rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom);
262 CGContextAddRect(ctx, rectDraw);
263 CGContextFillPath(ctx);
264 }
265 ++data;
266 }
267 }
Alexandre Lision313427f2016-11-24 21:04:04 -0500268
269 // get image
270 auto qrCGImage = CGBitmapContextCreateImage(ctx);
271 auto qrImage = [[NSImage alloc] initWithCGImage:qrCGImage size:qrcodeView.frame.size];
272
273 // some releases
274 CGContextRelease(ctx);
275 CGImageRelease(qrCGImage);
276 CGColorSpaceRelease(colorSpace);
277 QRcode_free(qrCode);
278
279 [qrcodeView setImage:qrImage];
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400280}
281
282/**
283 * Start the in/out animation displaying the QRCode
284 * @param show should the QRCode be animated in or out
285 */
286- (void) showQRCode:(BOOL) show
287{
288 static const NSInteger offset = 110;
289 [NSAnimationContext beginGrouping];
290 NSAnimationContext.currentContext.duration = 0.5;
291 [[NSAnimationContext currentContext] setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
292 qrcodeView.animator.alphaValue = show ? 1.0 : 0.0;
293 [centerYQRCodeConstraint.animator setConstant: show ? offset : 0];
294 [centerYWelcomeContainerConstraint.animator setConstant:show ? -offset : 0];
295 [NSAnimationContext endGrouping];
296}
297
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500298- (IBAction)openPreferences:(id)sender
299{
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400300 preferencesWC = [[PreferencesWC alloc] initWithWindowNibName:@"PreferencesWindow"];
301 [preferencesWC.window makeKeyAndOrderFront:preferencesWC.window];
Alexandre Lision5855b6a2015-02-03 11:31:05 -0500302}
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500303
Kateryna Kostiuk882cbac2017-07-05 17:29:00 -0400304- (IBAction)callClickedAtRow:(id)sender
305{
306 NSTabViewItem *selectedTab = [smartViewVC.tabbar selectedTabViewItem];
307 int index = [smartViewVC.tabbar indexOfTabViewItem:selectedTab];
308 switch (index) {
309 case 0:
310 [smartViewVC startCallForRow:sender];
311 break;
Kateryna Kostiuk882cbac2017-07-05 17:29:00 -0400312 default:
313 break;
314 }
315}
Alexandre Lision624b1a82016-09-11 19:29:01 -0400316#pragma mark - Ring account migration
317
318- (void) migrateRingAccount:(Account*) acc
319{
320 self.migrateWC = [[MigrateRingAccountsWC alloc] initWithDelegate:self actionCode:1];
321 self.migrateWC.account = acc;
322#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9
323 [self.window beginSheet:self.migrateWC.window completionHandler:nil];
324#else
325 [NSApp beginSheet: self.migrateWC.window
326 modalForWindow: self.window
327 modalDelegate: self
328 didEndSelector: nil
329 contextInfo: nil];
330#endif
331}
332
Anthony Léonard49cb2912017-11-13 16:15:39 -0500333// TODO: Reimplement as a blocking loop when new LRC models handle migration
Alexandre Lision624b1a82016-09-11 19:29:01 -0400334- (void)checkAccountsToMigrate
335{
336 auto ringList = AccountModel::instance().accountsToMigrate();
337 if (ringList.length() > 0){
338 Account* acc = ringList.value(0);
339 [self migrateRingAccount:acc];
340 } else {
341 // Fresh run, we need to make sure RingID appears
Alexandre Lision624b1a82016-09-11 19:29:01 -0400342 [shareButton sendActionOn:NSLeftMouseDownMask];
343
344 [self connect];
Kateryna Kostiuka7248462017-04-18 16:15:31 -0400345 [self updateRingID];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400346 // display accounts to select
347 NSToolbar *toolbar = self.window.toolbar;
348 toolbar.delegate = self;
349 [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1];
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -0400350 [toolbar insertItemWithItemIdentifier:kTrustRequestMenuItemIdentifier atIndex:2];
Alexandre Lision624b1a82016-09-11 19:29:01 -0400351 }
352}
353
354- (void)migrationDidComplete
355{
356 [self checkAccountsToMigrate];
357}
358
359- (void)migrationDidCompleteWithError
360{
361 [self checkAccountsToMigrate];
362}
363
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500364-(void)selectAccount:(const lrc::api::account::Info&)accInfo
365{
366 // If the selected account has been changed, we close any open panel
367 if ([smartViewVC setConversationModel:accInfo.conversationModel.get()]) {
368 [currentCallVC animateOut];
369 [offlineVC animateOut];
370 }
Anthony Léonard61e3dcf2017-12-27 12:19:52 -0500371
372 // Welcome view informations are also updated
373 [self updateRingID];
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500374}
375
Anthony Léonard8585cc02017-12-28 14:03:45 -0500376-(void)rightPanelClosed
377{
378 [smartViewVC deselect];
379}
380
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400381#pragma mark - NSToolbarDelegate
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -0400382- (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
383{
384 if(itemIdentifier == kChangeAccountToolBarItemIdentifier) {
385 NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kChangeAccountToolBarItemIdentifier];
386 toolbarItem.view = chooseAccountVC.view;
387 return toolbarItem;
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400388 }
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -0400389 if(itemIdentifier == kTrustRequestMenuItemIdentifier) {
390 NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kTrustRequestMenuItemIdentifier];
391 toolbarItem.view = contactRequestVC.view;
392 return toolbarItem;
393 }
394 return nil;
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400395}
396
Alexandre Lision5855b6a2015-02-03 11:31:05 -0500397@end