blob: e657fd3ac8f573c2dd0abac727f6ea8836b3af3f [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];
98 offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil];
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];
Olivier Soldanod4311552017-11-20 15:09:53 -0500111 [smartViewVC setConversationModel: [chooseAccountVC selectedAccount].conversationModel.get()];
Alexandre Lisionbb5c2462015-07-30 12:55:37 -0400112
Anthony Léonard49cb2912017-11-13 16:15:39 -0500113 // Fresh run, we need to make sure RingID appears
114 [shareButton sendActionOn:NSLeftMouseDownMask];
115
Olivier Soldano994971f2017-12-05 16:30:12 -0500116 [self connect];
Anthony Léonard49cb2912017-11-13 16:15:39 -0500117 [self updateRingID];
118 // display accounts to select
119 NSToolbar *toolbar = self.window.toolbar;
120 toolbar.delegate = self;
121 [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1];
122 [toolbar insertItemWithItemIdentifier:kTrustRequestMenuItemIdentifier atIndex:2];
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500123}
124
125- (void) connect
126{
Olivier Soldano994971f2017-12-05 16:30:12 -0500127 QObject::connect(&lrc_->getBehaviorController(),
128 &lrc::api::BehaviorController::showCallView,
129 [self](const std::string accountId,
130 const lrc::api::conversation::Info convInfo){
131 auto* accInfo = &lrc_->getAccountModel().getAccountInfo(accountId);
132 [currentCallVC setCurrentCall:convInfo.callId
133 conversation:convInfo.uid
134 account:accInfo];
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500135 [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()];
Olivier Soldano994971f2017-12-05 16:30:12 -0500136 [currentCallVC animateIn];
137 [offlineVC animateOut];
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500138 });
Alexandre Lision210fe212016-01-27 11:15:13 -0500139
Olivier Soldano994971f2017-12-05 16:30:12 -0500140 QObject::connect(&lrc_->getBehaviorController(),
141 &lrc::api::BehaviorController::showIncomingCallView,
142 [self](const std::string accountId,
143 const lrc::api::conversation::Info convInfo){
144 auto* accInfo = &lrc_->getAccountModel().getAccountInfo(accountId);
145 [currentCallVC setCurrentCall:convInfo.callId
146 conversation:convInfo.uid
147 account:accInfo];
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500148 [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()];
Olivier Soldano994971f2017-12-05 16:30:12 -0500149 [currentCallVC animateIn];
Kateryna Kostiukabf4e272017-04-18 14:18:00 -0400150 [offlineVC animateOut];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400151 });
Anthony Léonard2382b562017-12-13 15:51:28 -0500152
153 QObject::connect(&lrc_->getBehaviorController(),
154 &lrc::api::BehaviorController::showChatView,
155 [self](const std::string& accountId,
156 const lrc::api::conversation::Info& convInfo){
157 auto& accInfo = lrc_->getAccountModel().getAccountInfo(accountId);
158 [offlineVC setConversationUid:convInfo.uid model:accInfo.conversationModel.get()];
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500159 [smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()];
Anthony Léonard2382b562017-12-13 15:51:28 -0500160 [offlineVC animateIn];
161 [currentCallVC animateOut];
162 });
Alexandre Lisionbb5c2462015-07-30 12:55:37 -0400163}
164
165/**
166 * Implement the necessary logic to choose which Ring ID to display.
167 * This tries to choose the "best" ID to show
168 */
169- (void) updateRingID
170{
Anthony Léonard49cb2912017-11-13 16:15:39 -0500171 auto& account = [chooseAccountVC selectedAccount];
Alexandre Lisionbb5c2462015-07-30 12:55:37 -0400172
173 [ringIDLabel setStringValue:@""];
Anthony Léonard49cb2912017-11-13 16:15:39 -0500174
175 if(account.profileInfo.type != lrc::api::profile::Type::RING) {
Kateryna Kostiuka7248462017-04-18 16:15:31 -0400176 self.hideRingID = YES;
Kateryna Kostiuk312f9132017-04-18 12:09:06 -0400177 return;
Alexandre Lisionbb5c2462015-07-30 12:55:37 -0400178 }
Kateryna Kostiuka7248462017-04-18 16:15:31 -0400179 self.hideRingID = NO;
Anthony Léonard49cb2912017-11-13 16:15:39 -0500180 auto& registeredName = account.registeredName;
181 auto& ringID = account.profileInfo.uri;
Kateryna Kostiuk65ba43e2017-03-30 15:10:04 -0400182 NSString* uriToDisplay = nullptr;
Anthony Léonard49cb2912017-11-13 16:15:39 -0500183 if (!registeredName.empty()) {
184 uriToDisplay = @(registeredName.c_str());
Alexandre Lision313427f2016-11-24 21:04:04 -0500185 } else {
Anthony Léonard49cb2912017-11-13 16:15:39 -0500186 uriToDisplay = @(ringID.c_str());
Alexandre Lision313427f2016-11-24 21:04:04 -0500187 }
Kateryna Kostiuk65ba43e2017-03-30 15:10:04 -0400188 [ringIDLabel setStringValue:uriToDisplay];
Anthony Léonard49cb2912017-11-13 16:15:39 -0500189 [self drawQRCode:@(ringID.c_str())];
Alexandre Lision5855b6a2015-02-03 11:31:05 -0500190}
191
Alexandre Lision1abdf582016-02-09 14:21:19 -0500192- (IBAction)shareRingID:(id)sender {
193 NSSharingServicePicker* sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:[NSArray arrayWithObject:[ringIDLabel stringValue]]];
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400194 [sharingServicePicker setDelegate:self];
Alexandre Lision1abdf582016-02-09 14:21:19 -0500195 [sharingServicePicker showRelativeToRect:[sender bounds]
196 ofView:sender
197 preferredEdge:NSMinYEdge];
198}
199
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400200- (IBAction)toggleQRCode:(id)sender {
201 // Toggle pressed state of QRCode button
202 [sender setPressed:![sender isPressed]];
Kateryna Kostiuk65ba43e2017-03-30 15:10:04 -0400203 [self showQRCode:[sender isPressed]];
Alexandre Lision313427f2016-11-24 21:04:04 -0500204}
205
206/**
207 * Draw the QRCode in the qrCodeView
208 */
Kateryna Kostiuk65ba43e2017-03-30 15:10:04 -0400209- (void)drawQRCode:(NSString*) uriToDraw
Alexandre Lision313427f2016-11-24 21:04:04 -0500210{
Kateryna Kostiuk65ba43e2017-03-30 15:10:04 -0400211 auto qrCode = QRcode_encodeString(uriToDraw.UTF8String,
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400212 0,
213 QR_ECLEVEL_L, // Lowest level of error correction
214 QR_MODE_8, // 8-bit data mode
215 1);
216 if (!qrCode) {
217 return;
218 }
219
Alexandre Lision313427f2016-11-24 21:04:04 -0500220 unsigned char *data = 0;
221 int width;
222 data = qrCode->data;
223 width = qrCode->width;
224 int qr_margin = 3;
225
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400226 CGFloat size = qrcodeView.frame.size.width;
227
228 // create context
229 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
230 CGContextRef ctx = CGBitmapContextCreate(0, size, size, 8, size * 4, colorSpace, kCGImageAlphaPremultipliedLast);
231
232 CGAffineTransform translateTransform = CGAffineTransformMakeTranslation(0, -size);
233 CGAffineTransform scaleTransform = CGAffineTransformMakeScale(1, -1);
234 CGContextConcatCTM(ctx, CGAffineTransformConcat(translateTransform, scaleTransform));
235
Alexandre Lision313427f2016-11-24 21:04:04 -0500236 float zoom = ceil((double)size / (qrCode->width + 2.0 * qr_margin));
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400237 CGRect rectDraw = CGRectMake(0, 0, zoom, zoom);
238
239 int ran;
240 for(int i = 0; i < width; ++i) {
241 for(int j = 0; j < width; ++j) {
242 if(*data & 1) {
243 CGContextSetFillColorWithColor(ctx, [NSColor ringDarkGrey].CGColor);
244 rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom);
245 CGContextAddRect(ctx, rectDraw);
246 CGContextFillPath(ctx);
247 } else {
248 CGContextSetFillColorWithColor(ctx, [NSColor windowBackgroundColor].CGColor);
249 rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom);
250 CGContextAddRect(ctx, rectDraw);
251 CGContextFillPath(ctx);
252 }
253 ++data;
254 }
255 }
Alexandre Lision313427f2016-11-24 21:04:04 -0500256
257 // get image
258 auto qrCGImage = CGBitmapContextCreateImage(ctx);
259 auto qrImage = [[NSImage alloc] initWithCGImage:qrCGImage size:qrcodeView.frame.size];
260
261 // some releases
262 CGContextRelease(ctx);
263 CGImageRelease(qrCGImage);
264 CGColorSpaceRelease(colorSpace);
265 QRcode_free(qrCode);
266
267 [qrcodeView setImage:qrImage];
Alexandre Lisionfd0d6c82016-03-29 17:06:54 -0400268}
269
270/**
271 * Start the in/out animation displaying the QRCode
272 * @param show should the QRCode be animated in or out
273 */
274- (void) showQRCode:(BOOL) show
275{
276 static const NSInteger offset = 110;
277 [NSAnimationContext beginGrouping];
278 NSAnimationContext.currentContext.duration = 0.5;
279 [[NSAnimationContext currentContext] setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
280 qrcodeView.animator.alphaValue = show ? 1.0 : 0.0;
281 [centerYQRCodeConstraint.animator setConstant: show ? offset : 0];
282 [centerYWelcomeContainerConstraint.animator setConstant:show ? -offset : 0];
283 [NSAnimationContext endGrouping];
284}
285
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500286- (IBAction)openPreferences:(id)sender
287{
Alexandre Lisionbfa68f62015-09-10 08:38:42 -0400288 preferencesWC = [[PreferencesWC alloc] initWithWindowNibName:@"PreferencesWindow"];
289 [preferencesWC.window makeKeyAndOrderFront:preferencesWC.window];
Alexandre Lision5855b6a2015-02-03 11:31:05 -0500290}
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500291
Kateryna Kostiuk882cbac2017-07-05 17:29:00 -0400292- (IBAction)callClickedAtRow:(id)sender
293{
294 NSTabViewItem *selectedTab = [smartViewVC.tabbar selectedTabViewItem];
295 int index = [smartViewVC.tabbar indexOfTabViewItem:selectedTab];
296 switch (index) {
297 case 0:
298 [smartViewVC startCallForRow:sender];
299 break;
Kateryna Kostiuk882cbac2017-07-05 17:29:00 -0400300 default:
301 break;
302 }
303}
Alexandre Lision624b1a82016-09-11 19:29:01 -0400304#pragma mark - Ring account migration
305
306- (void) migrateRingAccount:(Account*) acc
307{
308 self.migrateWC = [[MigrateRingAccountsWC alloc] initWithDelegate:self actionCode:1];
309 self.migrateWC.account = acc;
310#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9
311 [self.window beginSheet:self.migrateWC.window completionHandler:nil];
312#else
313 [NSApp beginSheet: self.migrateWC.window
314 modalForWindow: self.window
315 modalDelegate: self
316 didEndSelector: nil
317 contextInfo: nil];
318#endif
319}
320
Anthony Léonard49cb2912017-11-13 16:15:39 -0500321// TODO: Reimplement as a blocking loop when new LRC models handle migration
Alexandre Lision624b1a82016-09-11 19:29:01 -0400322- (void)checkAccountsToMigrate
323{
324 auto ringList = AccountModel::instance().accountsToMigrate();
325 if (ringList.length() > 0){
326 Account* acc = ringList.value(0);
327 [self migrateRingAccount:acc];
328 } else {
329 // Fresh run, we need to make sure RingID appears
Alexandre Lision624b1a82016-09-11 19:29:01 -0400330 [shareButton sendActionOn:NSLeftMouseDownMask];
331
332 [self connect];
Kateryna Kostiuka7248462017-04-18 16:15:31 -0400333 [self updateRingID];
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400334 // display accounts to select
335 NSToolbar *toolbar = self.window.toolbar;
336 toolbar.delegate = self;
337 [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1];
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -0400338 [toolbar insertItemWithItemIdentifier:kTrustRequestMenuItemIdentifier atIndex:2];
Alexandre Lision624b1a82016-09-11 19:29:01 -0400339 }
340}
341
342- (void)migrationDidComplete
343{
344 [self checkAccountsToMigrate];
345}
346
347- (void)migrationDidCompleteWithError
348{
349 [self checkAccountsToMigrate];
350}
351
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500352-(void)selectAccount:(const lrc::api::account::Info&)accInfo
353{
354 // If the selected account has been changed, we close any open panel
355 if ([smartViewVC setConversationModel:accInfo.conversationModel.get()]) {
356 [currentCallVC animateOut];
357 [offlineVC animateOut];
358 }
Anthony Léonard61e3dcf2017-12-27 12:19:52 -0500359
360 // Welcome view informations are also updated
361 [self updateRingID];
Anthony Léonard9bebf1d2017-12-21 14:33:51 -0500362}
363
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400364#pragma mark - NSToolbarDelegate
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -0400365- (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
366{
367 if(itemIdentifier == kChangeAccountToolBarItemIdentifier) {
368 NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kChangeAccountToolBarItemIdentifier];
369 toolbarItem.view = chooseAccountVC.view;
370 return toolbarItem;
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400371 }
Kateryna Kostiukdb1f3a12017-04-24 12:08:28 -0400372 if(itemIdentifier == kTrustRequestMenuItemIdentifier) {
373 NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kTrustRequestMenuItemIdentifier];
374 toolbarItem.view = contactRequestVC.view;
375 return toolbarItem;
376 }
377 return nil;
Kateryna Kostiuk13b76882017-03-30 09:18:44 -0400378}
379
Alexandre Lision5855b6a2015-02-03 11:31:05 -0500380@end