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 | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 19 | #import "RingWindowController.h" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 20 | #import <QuartzCore/QuartzCore.h> |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 21 | #include <qrencode.h> |
Anthony Léonard | 7959760 | 2017-11-13 15:47:09 -0500 | [diff] [blame] | 22 | #include <memory> |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 23 | |
| 24 | //Qt |
| 25 | #import <QItemSelectionModel> |
| 26 | #import <QItemSelection> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 27 | |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 28 | //LRC |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 29 | #import <callmodel.h> |
| 30 | #import <account.h> |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 31 | #import <call.h> |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 32 | #import <recentmodel.h> |
Kateryna Kostiuk | 312f913 | 2017-04-18 12:09:06 -0400 | [diff] [blame] | 33 | #import <AvailableAccountModel.h> |
Anthony Léonard | 7959760 | 2017-11-13 15:47:09 -0500 | [diff] [blame] | 34 | #import <api/lrc.h> |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 35 | #import <api/account.h> |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 36 | #import <api/newaccountmodel.h> |
| 37 | #import <api/newcallmodel.h> |
| 38 | #import <api/behaviorcontroller.h> |
| 39 | #import <api/conversation.h> |
Anthony Léonard | d00cd18 | 2018-01-17 09:21:27 -0500 | [diff] [blame] | 40 | #import <api/contactmodel.h> |
| 41 | #import <api/contact.h> |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 42 | #import <api/datatransfermodel.h> |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 43 | #import <media/recordingmodel.h> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 44 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 45 | // Ring |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 46 | #import "AppDelegate.h" |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 47 | #import "Constants.h" |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 48 | #import "CurrentCallVC.h" |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 49 | #import "MigrateRingAccountsWC.h" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 50 | #import "ConversationVC.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 51 | #import "PreferencesWC.h" |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 52 | #import "SmartViewVC.h" |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 53 | #import "views/IconButton.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 54 | #import "views/NSColor+RingTheme.h" |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 55 | #import "views/HoverButton.h" |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 56 | #import "utils.h" |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 57 | #import "RingWizardWC.h" |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 58 | #import "AccountSettingsVC.h" |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 59 | #import "views/CallLayer.h" |
| 60 | |
| 61 | typedef NS_ENUM(NSInteger, ViewState) { |
| 62 | SHOW_WELCOME_SCREEN = 0, |
| 63 | SHOW_CONVERSATION_SCREEN, |
| 64 | SHOW_CALL_SCREEN, |
| 65 | SHOW_SETTINGS_SCREEN, |
| 66 | }; |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 67 | |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 68 | @interface RingWindowController () <MigrateRingAccountsDelegate, NSToolbarDelegate> |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 69 | |
| 70 | @property (retain) MigrateRingAccountsWC* migrateWC; |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 71 | @property RingWizardWC* wizard; |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 72 | |
| 73 | @end |
| 74 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 75 | @implementation RingWindowController { |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 76 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 77 | __unsafe_unretained IBOutlet NSLayoutConstraint* centerYQRCodeConstraint; |
| 78 | __unsafe_unretained IBOutlet NSLayoutConstraint* centerYWelcomeContainerConstraint; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 79 | IBOutlet NSLayoutConstraint* ringLabelTrailingConstraint; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 80 | __unsafe_unretained IBOutlet NSView* welcomeContainer; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 81 | __unsafe_unretained IBOutlet NSView* callView; |
| 82 | __unsafe_unretained IBOutlet NSTextField* ringIDLabel; |
| 83 | __unsafe_unretained IBOutlet NSButton* shareButton; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 84 | __unsafe_unretained IBOutlet NSImageView* qrcodeView; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 85 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 86 | PreferencesWC* preferencesWC; |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 87 | IBOutlet SmartViewVC* smartViewVC; |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 88 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 89 | CurrentCallVC* currentCallVC; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 90 | ConversationVC* conversationVC; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 91 | AccountSettingsVC* settingsVC; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 92 | |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 93 | // toolbar menu items |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 94 | ChooseAccountVC* chooseAccountVC; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 95 | } |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 96 | |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 97 | static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier"; |
| 98 | NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItemIdentifier"; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 99 | NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemIdentifier"; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 100 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 101 | @synthesize dataTransferModel, accountModel, behaviorController; |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 102 | @synthesize wizard; |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 103 | |
| 104 | -(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*)accountModel dataTransferModel:( lrc::api::DataTransferModel*)dataTransferModel behaviourController:( lrc::api::BehaviorController*) behaviorController |
| 105 | { |
| 106 | if (self = [self initWithWindowNibName:nibNameOrNil]) |
| 107 | { |
| 108 | self.accountModel = accountModel; |
| 109 | self.dataTransferModel = dataTransferModel; |
| 110 | self.behaviorController = behaviorController; |
| 111 | } |
| 112 | return self; |
| 113 | } |
| 114 | |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 115 | -(void)changeViewTo:(ViewState) state { |
| 116 | switch (state) { |
| 117 | case SHOW_WELCOME_SCREEN: |
| 118 | [self accountSettingsShouldOpen: NO]; |
| 119 | [conversationVC hideWithAnimation:false]; |
| 120 | [currentCallVC hideWithAnimation:false]; |
| 121 | [currentCallVC.view removeFromSuperview]; |
| 122 | [welcomeContainer setHidden: NO]; |
| 123 | [smartViewVC.view setHidden: NO]; |
| 124 | [settingsVC hide]; |
| 125 | break; |
| 126 | case SHOW_CONVERSATION_SCREEN: |
| 127 | [self accountSettingsShouldOpen: NO]; |
| 128 | [conversationVC showWithAnimation:false]; |
| 129 | [currentCallVC hideWithAnimation:false]; |
| 130 | [currentCallVC.view removeFromSuperview]; |
| 131 | [welcomeContainer setHidden: YES]; |
| 132 | [smartViewVC.view setHidden: NO]; |
| 133 | [settingsVC hide]; |
| 134 | break; |
| 135 | case SHOW_CALL_SCREEN: |
| 136 | [self accountSettingsShouldOpen: NO]; |
| 137 | if (![currentCallVC.view superview]) { |
| 138 | [callView addSubview:[currentCallVC view] positioned:NSWindowAbove relativeTo:nil]; |
| 139 | [currentCallVC initFrame]; |
| 140 | [currentCallVC showWithAnimation:false]; |
| 141 | [conversationVC hideWithAnimation:false]; |
| 142 | [welcomeContainer setHidden: YES]; |
| 143 | [smartViewVC.view setHidden: NO]; |
| 144 | [settingsVC hide]; |
| 145 | } |
| 146 | [currentCallVC showWithAnimation:false]; |
| 147 | break; |
| 148 | case SHOW_SETTINGS_SCREEN: |
| 149 | @try { |
| 150 | [self accountSettingsShouldOpen: YES]; |
| 151 | } |
| 152 | @catch (NSException *ex) { |
| 153 | return; |
| 154 | } |
| 155 | [welcomeContainer setHidden: YES]; |
| 156 | [currentCallVC hideWithAnimation:false]; |
| 157 | [currentCallVC.view removeFromSuperview]; |
| 158 | [conversationVC hideWithAnimation:false]; |
| 159 | [smartViewVC.view setHidden: YES]; |
| 160 | [settingsVC show]; |
| 161 | break; |
| 162 | default: |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 167 | - (void)windowDidLoad { |
| 168 | [super windowDidLoad]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 169 | [self.window setMovableByWindowBackground:YES]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 170 | |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 171 | self.window.titleVisibility = NSWindowTitleHidden; |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 172 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 173 | currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil]; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 174 | conversationVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil delegate:self]; |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 175 | // toolbar items |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 176 | chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:self.accountModel delegate:self]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 177 | settingsVC = [[AccountSettingsVC alloc] initWithNibName:@"AccountSettings" bundle:nil accountmodel:self.accountModel]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 178 | [callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 179 | [[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 180 | [[conversationVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 181 | [[settingsVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 182 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 183 | [callView addSubview:[conversationVC view] positioned:NSWindowAbove relativeTo:nil]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 184 | [self.window.contentView addSubview:[settingsVC view] positioned:NSWindowAbove relativeTo:nil]; |
Alexandre Lision | 16d9c0a | 2015-08-10 12:05:15 -0400 | [diff] [blame] | 185 | |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 186 | [conversationVC initFrame]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 187 | [settingsVC initFrame]; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 188 | @try { |
| 189 | [smartViewVC setConversationModel: [chooseAccountVC selectedAccount].conversationModel.get()]; |
| 190 | } |
| 191 | @catch (NSException *ex) { |
| 192 | NSLog(@"Caught exception %@: %@", [ex name], [ex reason]); |
| 193 | } |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 194 | |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 195 | // Fresh run, we need to make sure RingID appears |
| 196 | [shareButton sendActionOn:NSLeftMouseDownMask]; |
| 197 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 198 | [self connect]; |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 199 | [self updateRingID]; |
| 200 | // display accounts to select |
| 201 | NSToolbar *toolbar = self.window.toolbar; |
| 202 | toolbar.delegate = self; |
| 203 | [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 204 | [toolbar insertItemWithItemIdentifier:kOpenAccountToolBarItemIdentifier atIndex:1]; |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 205 | // set download folder (default - 'Documents') |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 206 | NSString* path = [[NSUserDefaults standardUserDefaults] stringForKey:Preferences::DownloadFolder]; |
| 207 | if (!path || path.length == 0) { |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 208 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
| 209 | path = [[paths objectAtIndex:0] stringByAppendingString:@"/"]; |
Kateryna Kostiuk | 6773523 | 2018-05-10 15:05:32 -0400 | [diff] [blame] | 210 | } |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 211 | self.dataTransferModel->downloadDirectory = std::string([path UTF8String]); |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 212 | if(appSandboxed()) { |
| 213 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
Kateryna Kostiuk | f9a72c0 | 2018-08-01 14:28:49 -0400 | [diff] [blame] | 214 | media::RecordingModel::instance().setRecordPath(QString::fromNSString([paths objectAtIndex:0])); |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 215 | } |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | - (void) connect |
| 219 | { |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 220 | QObject::connect(self.behaviorController, |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 221 | &lrc::api::BehaviorController::showCallView, |
| 222 | [self](const std::string accountId, |
| 223 | const lrc::api::conversation::Info convInfo){ |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 224 | auto* accInfo = &self.accountModel->getAccountInfo(accountId); |
Anthony Léonard | d00cd18 | 2018-01-17 09:21:27 -0500 | [diff] [blame] | 225 | if (accInfo->contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING) |
| 226 | [smartViewVC selectPendingList]; |
| 227 | else |
| 228 | [smartViewVC selectConversationList]; |
| 229 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 230 | [currentCallVC setCurrentCall:convInfo.callId |
| 231 | conversation:convInfo.uid |
| 232 | account:accInfo]; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 233 | [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 234 | [self changeViewTo:SHOW_CALL_SCREEN]; |
| 235 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 236 | }); |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 237 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 238 | QObject::connect(self.behaviorController, |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 239 | &lrc::api::BehaviorController::showIncomingCallView, |
| 240 | [self](const std::string accountId, |
| 241 | const lrc::api::conversation::Info convInfo){ |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 242 | auto* accInfo = &self.accountModel->getAccountInfo(accountId); |
Anthony Léonard | d00cd18 | 2018-01-17 09:21:27 -0500 | [diff] [blame] | 243 | if (accInfo->contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING) |
| 244 | [smartViewVC selectPendingList]; |
| 245 | else |
| 246 | [smartViewVC selectConversationList]; |
| 247 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 248 | [currentCallVC setCurrentCall:convInfo.callId |
| 249 | conversation:convInfo.uid |
| 250 | account:accInfo]; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 251 | [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 252 | [self changeViewTo:SHOW_CALL_SCREEN]; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 253 | }); |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 254 | |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 255 | QObject::connect(self.behaviorController, |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 256 | &lrc::api::BehaviorController::showChatView, |
| 257 | [self](const std::string& accountId, |
| 258 | const lrc::api::conversation::Info& convInfo){ |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 259 | auto& accInfo = self.accountModel->getAccountInfo(accountId); |
Andreas Traczyk | ecdc4fa | 2018-03-22 16:11:47 -0400 | [diff] [blame] | 260 | [conversationVC setConversationUid:convInfo.uid model:accInfo.conversationModel.get()]; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 261 | [smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 262 | [self changeViewTo:SHOW_CONVERSATION_SCREEN]; |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 263 | }); |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Implement the necessary logic to choose which Ring ID to display. |
| 268 | * This tries to choose the "best" ID to show |
| 269 | */ |
| 270 | - (void) updateRingID |
| 271 | { |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 272 | @try { |
| 273 | auto& account = [chooseAccountVC selectedAccount]; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 274 | |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 275 | [ringIDLabel setStringValue:@""]; |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 276 | |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 277 | if(account.profileInfo.type != lrc::api::profile::Type::RING) { |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 278 | self.notRingAccount = YES; |
| 279 | self.isSIPAccount = YES; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 280 | return; |
| 281 | } |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 282 | self.isSIPAccount = NO; |
| 283 | self.notRingAccount = NO; |
| 284 | [ringLabelTrailingConstraint setActive:YES]; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 285 | auto& registeredName = account.registeredName; |
| 286 | auto& ringID = account.profileInfo.uri; |
| 287 | NSString* uriToDisplay = nullptr; |
| 288 | if (!registeredName.empty()) { |
| 289 | uriToDisplay = @(registeredName.c_str()); |
| 290 | } else { |
| 291 | uriToDisplay = @(ringID.c_str()); |
| 292 | } |
| 293 | [ringIDLabel setStringValue:uriToDisplay]; |
| 294 | [self drawQRCode:@(ringID.c_str())]; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 295 | } |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 296 | @catch (NSException *ex) { |
| 297 | NSLog(@"Caught exception %@: %@", [ex name], [ex reason]); |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 298 | self.notRingAccount = YES; |
| 299 | self.isSIPAccount = NO; |
| 300 | [ringLabelTrailingConstraint setActive:NO]; |
Anthony Léonard | 70638f0 | 2018-02-05 11:10:19 -0500 | [diff] [blame] | 301 | [ringIDLabel setStringValue:NSLocalizedString(@"No account available", @"Displayed as RingID when no accounts are available for selection")]; |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 302 | } |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 303 | } |
| 304 | |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 305 | - (IBAction)shareRingID:(id)sender { |
| 306 | NSSharingServicePicker* sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:[NSArray arrayWithObject:[ringIDLabel stringValue]]]; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 307 | [sharingServicePicker setDelegate:self]; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 308 | [sharingServicePicker showRelativeToRect:[sender bounds] |
| 309 | ofView:sender |
| 310 | preferredEdge:NSMinYEdge]; |
| 311 | } |
| 312 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 313 | - (IBAction)toggleQRCode:(id)sender { |
| 314 | // Toggle pressed state of QRCode button |
| 315 | [sender setPressed:![sender isPressed]]; |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 316 | [self showQRCode:[sender isPressed]]; |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Draw the QRCode in the qrCodeView |
| 321 | */ |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 322 | - (void)drawQRCode:(NSString*) uriToDraw |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 323 | { |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 324 | auto qrCode = QRcode_encodeString(uriToDraw.UTF8String, |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 325 | 0, |
| 326 | QR_ECLEVEL_L, // Lowest level of error correction |
| 327 | QR_MODE_8, // 8-bit data mode |
| 328 | 1); |
| 329 | if (!qrCode) { |
| 330 | return; |
| 331 | } |
| 332 | |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 333 | unsigned char *data = 0; |
| 334 | int width; |
| 335 | data = qrCode->data; |
| 336 | width = qrCode->width; |
| 337 | int qr_margin = 3; |
| 338 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 339 | CGFloat size = qrcodeView.frame.size.width; |
| 340 | |
| 341 | // create context |
| 342 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
| 343 | CGContextRef ctx = CGBitmapContextCreate(0, size, size, 8, size * 4, colorSpace, kCGImageAlphaPremultipliedLast); |
| 344 | |
| 345 | CGAffineTransform translateTransform = CGAffineTransformMakeTranslation(0, -size); |
| 346 | CGAffineTransform scaleTransform = CGAffineTransformMakeScale(1, -1); |
| 347 | CGContextConcatCTM(ctx, CGAffineTransformConcat(translateTransform, scaleTransform)); |
| 348 | |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 349 | float zoom = ceil((double)size / (qrCode->width + 2.0 * qr_margin)); |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 350 | CGRect rectDraw = CGRectMake(0, 0, zoom, zoom); |
| 351 | |
| 352 | int ran; |
| 353 | for(int i = 0; i < width; ++i) { |
| 354 | for(int j = 0; j < width; ++j) { |
| 355 | if(*data & 1) { |
Kateryna Kostiuk | 394f74c | 2018-10-05 15:45:26 -0400 | [diff] [blame] | 356 | CGContextSetFillColorWithColor(ctx, [NSColor labelColor].CGColor); |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 357 | rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom); |
| 358 | CGContextAddRect(ctx, rectDraw); |
| 359 | CGContextFillPath(ctx); |
| 360 | } else { |
| 361 | CGContextSetFillColorWithColor(ctx, [NSColor windowBackgroundColor].CGColor); |
| 362 | rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom); |
| 363 | CGContextAddRect(ctx, rectDraw); |
| 364 | CGContextFillPath(ctx); |
| 365 | } |
| 366 | ++data; |
| 367 | } |
| 368 | } |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 369 | |
| 370 | // get image |
| 371 | auto qrCGImage = CGBitmapContextCreateImage(ctx); |
| 372 | auto qrImage = [[NSImage alloc] initWithCGImage:qrCGImage size:qrcodeView.frame.size]; |
| 373 | |
| 374 | // some releases |
| 375 | CGContextRelease(ctx); |
| 376 | CGImageRelease(qrCGImage); |
| 377 | CGColorSpaceRelease(colorSpace); |
| 378 | QRcode_free(qrCode); |
| 379 | |
| 380 | [qrcodeView setImage:qrImage]; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Start the in/out animation displaying the QRCode |
| 385 | * @param show should the QRCode be animated in or out |
| 386 | */ |
| 387 | - (void) showQRCode:(BOOL) show |
| 388 | { |
| 389 | static const NSInteger offset = 110; |
| 390 | [NSAnimationContext beginGrouping]; |
| 391 | NSAnimationContext.currentContext.duration = 0.5; |
| 392 | [[NSAnimationContext currentContext] setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; |
| 393 | qrcodeView.animator.alphaValue = show ? 1.0 : 0.0; |
| 394 | [centerYQRCodeConstraint.animator setConstant: show ? offset : 0]; |
| 395 | [centerYWelcomeContainerConstraint.animator setConstant:show ? -offset : 0]; |
| 396 | [NSAnimationContext endGrouping]; |
| 397 | } |
| 398 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 399 | - (IBAction)openPreferences:(id)sender |
| 400 | { |
Kateryna Kostiuk | bb68a1c | 2018-06-12 15:16:02 -0400 | [diff] [blame] | 401 | if (preferencesWC) { |
| 402 | [preferencesWC.window orderFront:preferencesWC.window]; |
| 403 | return; |
| 404 | } |
Kateryna Kostiuk | ecaa395 | 2018-07-13 16:00:34 -0400 | [diff] [blame] | 405 | |
| 406 | preferencesWC = [[PreferencesWC alloc] initWithWindowNibName: @"PreferencesWindow" bundle: nil accountModel:self.accountModel dataTransferModel:self.dataTransferModel behaviourController:self.behaviorController]; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 407 | [preferencesWC.window makeKeyAndOrderFront:preferencesWC.window]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 408 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 409 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 410 | - (IBAction)callClickedAtRow:(id)sender |
| 411 | { |
| 412 | NSTabViewItem *selectedTab = [smartViewVC.tabbar selectedTabViewItem]; |
| 413 | int index = [smartViewVC.tabbar indexOfTabViewItem:selectedTab]; |
| 414 | switch (index) { |
| 415 | case 0: |
| 416 | [smartViewVC startCallForRow:sender]; |
| 417 | break; |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 418 | default: |
| 419 | break; |
| 420 | } |
| 421 | } |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 422 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 423 | #pragma mark - Ring account migration |
| 424 | |
| 425 | - (void) migrateRingAccount:(Account*) acc |
| 426 | { |
| 427 | self.migrateWC = [[MigrateRingAccountsWC alloc] initWithDelegate:self actionCode:1]; |
| 428 | self.migrateWC.account = acc; |
| 429 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 |
| 430 | [self.window beginSheet:self.migrateWC.window completionHandler:nil]; |
| 431 | #else |
| 432 | [NSApp beginSheet: self.migrateWC.window |
| 433 | modalForWindow: self.window |
| 434 | modalDelegate: self |
| 435 | didEndSelector: nil |
| 436 | contextInfo: nil]; |
| 437 | #endif |
| 438 | } |
| 439 | |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 440 | // TODO: Reimplement as a blocking loop when new LRC models handle migration |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 441 | - (void)checkAccountsToMigrate |
| 442 | { |
| 443 | auto ringList = AccountModel::instance().accountsToMigrate(); |
| 444 | if (ringList.length() > 0){ |
| 445 | Account* acc = ringList.value(0); |
| 446 | [self migrateRingAccount:acc]; |
| 447 | } else { |
| 448 | // Fresh run, we need to make sure RingID appears |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 449 | [shareButton sendActionOn:NSLeftMouseDownMask]; |
| 450 | |
| 451 | [self connect]; |
Kateryna Kostiuk | a724846 | 2017-04-18 16:15:31 -0400 | [diff] [blame] | 452 | [self updateRingID]; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 453 | // display accounts to select |
| 454 | NSToolbar *toolbar = self.window.toolbar; |
| 455 | toolbar.delegate = self; |
| 456 | [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1]; |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | - (void)migrationDidComplete |
| 461 | { |
| 462 | [self checkAccountsToMigrate]; |
| 463 | } |
| 464 | |
| 465 | - (void)migrationDidCompleteWithError |
| 466 | { |
| 467 | [self checkAccountsToMigrate]; |
| 468 | } |
| 469 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 470 | - (void) selectAccount:(const lrc::api::account::Info&)accInfo currentRemoved:(BOOL) removed |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 471 | { |
| 472 | // If the selected account has been changed, we close any open panel |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 473 | [smartViewVC setConversationModel:accInfo.conversationModel.get()]; |
Anthony Léonard | 61e3dcf | 2017-12-27 12:19:52 -0500 | [diff] [blame] | 474 | // Welcome view informations are also updated |
| 475 | [self updateRingID]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 476 | [settingsVC setSelectedAccount:accInfo.id]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 477 | [self changeViewTo: ([settingsVC.view isHidden] || removed) ? SHOW_WELCOME_SCREEN : SHOW_SETTINGS_SCREEN]; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 478 | } |
| 479 | |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 480 | -(void)allAccountsDeleted |
| 481 | { |
| 482 | [smartViewVC clearConversationModel]; |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 483 | [self changeViewTo:SHOW_WELCOME_SCREEN]; |
Kateryna Kostiuk | ab499f4 | 2018-04-16 12:27:33 -0400 | [diff] [blame] | 484 | [self updateRingID]; |
| 485 | } |
| 486 | |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 487 | -(void)rightPanelClosed |
| 488 | { |
| 489 | [smartViewVC deselect]; |
Kateryna Kostiuk | 394f74c | 2018-10-05 15:45:26 -0400 | [diff] [blame] | 490 | [welcomeContainer setHidden:NO]; |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 491 | } |
| 492 | |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 493 | -(void)currentConversationTrusted |
| 494 | { |
| 495 | [smartViewVC selectConversationList]; |
| 496 | } |
| 497 | |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame] | 498 | -(void) listTypeChanged { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 499 | [self changeViewTo:SHOW_WELCOME_SCREEN]; |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame] | 500 | } |
| 501 | |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 502 | #pragma mark - NSToolbarDelegate |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 503 | - (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag |
| 504 | { |
| 505 | if(itemIdentifier == kChangeAccountToolBarItemIdentifier) { |
| 506 | NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kChangeAccountToolBarItemIdentifier]; |
Kateryna Kostiuk | d7e2e10 | 2018-10-01 13:33:38 -0400 | [diff] [blame] | 507 | toolbarItem.maxSize = NSMakeSize(187, 30); |
| 508 | toolbarItem.minSize = NSMakeSize(187, 30); |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 509 | toolbarItem.view = chooseAccountVC.view; |
| 510 | return toolbarItem; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 511 | } else if(itemIdentifier == kOpenAccountToolBarItemIdentifier) { |
| 512 | NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kOpenAccountToolBarItemIdentifier]; |
Kateryna Kostiuk | d7e2e10 | 2018-10-01 13:33:38 -0400 | [diff] [blame] | 513 | toolbarItem.maxSize = NSMakeSize(30, 30); |
| 514 | toolbarItem.minSize = NSMakeSize(30, 30); |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 515 | HoverButton *openSettingsButton = [[HoverButton alloc] initWithFrame:CGRectMake(0, 0, 28, 28)]; |
| 516 | openSettingsButton.bgColor = [NSColor clearColor]; |
| 517 | openSettingsButton.imageColor = [NSColor darkGrayColor]; |
| 518 | openSettingsButton.hoverColor = [NSColor controlHighlightColor]; |
| 519 | openSettingsButton.highlightColor = [NSColor lightGrayColor]; |
| 520 | openSettingsButton.imageInsets = 6; |
| 521 | openSettingsButton.title = @""; |
| 522 | [openSettingsButton setBordered: NO]; |
| 523 | [openSettingsButton setTransparent:YES]; |
| 524 | openSettingsButton.image = [NSImage imageNamed: NSImageNameSmartBadgeTemplate]; |
| 525 | [openSettingsButton setAction:@selector(openAccountSettings:)]; |
| 526 | [openSettingsButton setTarget:self]; |
| 527 | toolbarItem.view = openSettingsButton; |
| 528 | return toolbarItem; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 529 | } |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 530 | return nil; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 531 | } |
| 532 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 533 | - (IBAction)openAccountSettings:(NSButton *)sender |
| 534 | { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 535 | [self changeViewTo: [settingsVC.view isHidden] ? SHOW_SETTINGS_SCREEN : SHOW_WELCOME_SCREEN]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 536 | } |
| 537 | |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 538 | - (void) createNewAccount { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 539 | [self changeViewTo:SHOW_WELCOME_SCREEN]; |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 540 | wizard = [[RingWizardWC alloc] initWithNibName:@"RingWizard" bundle: nil accountmodel: self.accountModel]; |
| 541 | [wizard showChooseWithCancelButton: YES andAdvanced: YES]; |
| 542 | [self.window beginSheet:wizard.window completionHandler:nil]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | -(void) accountSettingsShouldOpen: (BOOL) open { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 546 | |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 547 | if (open) { |
Kateryna Kostiuk | c17db8d | 2018-10-23 09:48:03 -0400 | [diff] [blame] | 548 | [settingsVC setSelectedAccount: [chooseAccountVC selectedAccount].id]; |
Kateryna Kostiuk | 1f8c125 | 2018-07-30 18:18:57 -0400 | [diff] [blame] | 549 | } |
| 550 | NSToolbar *toolbar = self.window.toolbar; |
| 551 | NSArray *settings = [toolbar items]; |
| 552 | |
| 553 | for(NSToolbarItem *toolbarItem in settings) { |
| 554 | if (toolbarItem.itemIdentifier == kOpenAccountToolBarItemIdentifier) { |
| 555 | HoverButton *openSettingsButton = [[HoverButton alloc] initWithFrame:CGRectMake(0, 0, 28, 28)]; |
| 556 | openSettingsButton.bgColor = [NSColor clearColor]; |
| 557 | openSettingsButton.imageColor = [NSColor darkGrayColor]; |
| 558 | openSettingsButton.hoverColor = [NSColor controlHighlightColor]; |
| 559 | openSettingsButton.highlightColor = [NSColor lightGrayColor]; |
| 560 | openSettingsButton.imageInsets = 6; |
| 561 | openSettingsButton.title = @""; |
| 562 | [openSettingsButton setBordered: NO]; |
| 563 | [openSettingsButton setTransparent:YES]; |
| 564 | openSettingsButton.image = open ? [NSImage imageNamed: NSImageNameMenuOnStateTemplate] : [NSImage imageNamed: NSImageNameSmartBadgeTemplate]; |
| 565 | [openSettingsButton setAction:@selector(openAccountSettings:)]; |
| 566 | [openSettingsButton setTarget:self]; |
| 567 | toolbarItem.view = openSettingsButton; |
| 568 | } |
| 569 | } |
Kateryna Kostiuk | d73f960 | 2018-07-24 13:51:28 -0400 | [diff] [blame] | 570 | } |
| 571 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 572 | @end |