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> |
| 40 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 41 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 42 | // Ring |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 43 | #import "AppDelegate.h" |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 44 | #import "Constants.h" |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 45 | #import "CurrentCallVC.h" |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 46 | #import "MigrateRingAccountsWC.h" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 47 | #import "ConversationVC.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 48 | #import "PreferencesWC.h" |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 49 | #import "SmartViewVC.h" |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 50 | #import "views/IconButton.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 51 | #import "views/NSColor+RingTheme.h" |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 52 | #import "views/BackgroundView.h" |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 53 | #import "ChooseAccountVC.h" |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 54 | |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 55 | @interface RingWindowController () <MigrateRingAccountsDelegate, NSToolbarDelegate> |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 56 | |
| 57 | @property (retain) MigrateRingAccountsWC* migrateWC; |
| 58 | |
| 59 | @end |
| 60 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 61 | @implementation RingWindowController { |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 62 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 63 | __unsafe_unretained IBOutlet NSLayoutConstraint* centerYQRCodeConstraint; |
| 64 | __unsafe_unretained IBOutlet NSLayoutConstraint* centerYWelcomeContainerConstraint; |
| 65 | __unsafe_unretained IBOutlet NSView* welcomeContainer; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 66 | __unsafe_unretained IBOutlet NSView* callView; |
| 67 | __unsafe_unretained IBOutlet NSTextField* ringIDLabel; |
| 68 | __unsafe_unretained IBOutlet NSButton* shareButton; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 69 | __unsafe_unretained IBOutlet NSImageView* qrcodeView; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 70 | |
Anthony Léonard | 7959760 | 2017-11-13 15:47:09 -0500 | [diff] [blame] | 71 | std::unique_ptr<lrc::api::Lrc> lrc_; |
| 72 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 73 | PreferencesWC* preferencesWC; |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 74 | IBOutlet SmartViewVC* smartViewVC; |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 75 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 76 | CurrentCallVC* currentCallVC; |
| 77 | ConversationVC* offlineVC; |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 78 | // toolbar menu items |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 79 | ChooseAccountVC* chooseAccountVC; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 80 | } |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 81 | |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 82 | static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier"; |
| 83 | NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItemIdentifier"; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 84 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 85 | - (void)windowDidLoad { |
| 86 | [super windowDidLoad]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 87 | [self.window setMovableByWindowBackground:YES]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 88 | |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 89 | [self.window setBackgroundColor:[NSColor colorWithRed:242.0/255 green:242.0/255 blue:242.0/255 alpha:1.0]]; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 90 | self.window.titleVisibility = NSWindowTitleHidden; |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 91 | |
Anthony Léonard | 7959760 | 2017-11-13 15:47:09 -0500 | [diff] [blame] | 92 | lrc_ = std::make_unique<lrc::api::Lrc>(); |
| 93 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 94 | currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil]; |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 95 | offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil delegate:self]; |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 96 | // toolbar items |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 97 | chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:&(lrc_->getAccountModel()) delegate:self]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 98 | [callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 99 | [[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 100 | [[offlineVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 101 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 102 | [callView addSubview:[currentCallVC view] positioned:NSWindowAbove relativeTo:nil]; |
| 103 | [callView addSubview:[offlineVC view] positioned:NSWindowAbove relativeTo:nil]; |
Alexandre Lision | 16d9c0a | 2015-08-10 12:05:15 -0400 | [diff] [blame] | 104 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 105 | [currentCallVC initFrame]; |
| 106 | [offlineVC initFrame]; |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 107 | @try { |
| 108 | [smartViewVC setConversationModel: [chooseAccountVC selectedAccount].conversationModel.get()]; |
| 109 | } |
| 110 | @catch (NSException *ex) { |
| 111 | NSLog(@"Caught exception %@: %@", [ex name], [ex reason]); |
| 112 | } |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 113 | |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 114 | // Fresh run, we need to make sure RingID appears |
| 115 | [shareButton sendActionOn:NSLeftMouseDownMask]; |
| 116 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 117 | [self connect]; |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 118 | [self updateRingID]; |
| 119 | // display accounts to select |
| 120 | NSToolbar *toolbar = self.window.toolbar; |
| 121 | toolbar.delegate = self; |
| 122 | [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | - (void) connect |
| 126 | { |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 127 | 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éonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 135 | [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 136 | [currentCallVC animateIn]; |
| 137 | [offlineVC animateOut]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 138 | }); |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 139 | |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 140 | 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éonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 148 | [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()]; |
Olivier Soldano | 994971f | 2017-12-05 16:30:12 -0500 | [diff] [blame] | 149 | [currentCallVC animateIn]; |
Kateryna Kostiuk | abf4e27 | 2017-04-18 14:18:00 -0400 | [diff] [blame] | 150 | [offlineVC animateOut]; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 151 | }); |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 152 | |
| 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éonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 159 | [smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()]; |
Anthony Léonard | 2382b56 | 2017-12-13 15:51:28 -0500 | [diff] [blame] | 160 | [offlineVC animateIn]; |
| 161 | [currentCallVC animateOut]; |
| 162 | }); |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 163 | } |
| 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éonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 171 | @try { |
| 172 | auto& account = [chooseAccountVC selectedAccount]; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 173 | |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 174 | [ringIDLabel setStringValue:@""]; |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 175 | |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 176 | if(account.profileInfo.type != lrc::api::profile::Type::RING) { |
| 177 | self.hideRingID = YES; |
| 178 | return; |
| 179 | } |
| 180 | self.hideRingID = NO; |
| 181 | auto& registeredName = account.registeredName; |
| 182 | auto& ringID = account.profileInfo.uri; |
| 183 | NSString* uriToDisplay = nullptr; |
| 184 | if (!registeredName.empty()) { |
| 185 | uriToDisplay = @(registeredName.c_str()); |
| 186 | } else { |
| 187 | uriToDisplay = @(ringID.c_str()); |
| 188 | } |
| 189 | [ringIDLabel setStringValue:uriToDisplay]; |
| 190 | [self drawQRCode:@(ringID.c_str())]; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 191 | } |
Anthony Léonard | 72128c9 | 2017-12-26 16:48:39 -0500 | [diff] [blame] | 192 | @catch (NSException *ex) { |
| 193 | NSLog(@"Caught exception %@: %@", [ex name], [ex reason]); |
| 194 | self.hideRingID = NO; |
| 195 | [ringIDLabel setStringValue:@"No account available"]; |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 196 | } |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 199 | - (IBAction)shareRingID:(id)sender { |
| 200 | NSSharingServicePicker* sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:[NSArray arrayWithObject:[ringIDLabel stringValue]]]; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 201 | [sharingServicePicker setDelegate:self]; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 202 | [sharingServicePicker showRelativeToRect:[sender bounds] |
| 203 | ofView:sender |
| 204 | preferredEdge:NSMinYEdge]; |
| 205 | } |
| 206 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 207 | - (IBAction)toggleQRCode:(id)sender { |
| 208 | // Toggle pressed state of QRCode button |
| 209 | [sender setPressed:![sender isPressed]]; |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 210 | [self showQRCode:[sender isPressed]]; |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Draw the QRCode in the qrCodeView |
| 215 | */ |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 216 | - (void)drawQRCode:(NSString*) uriToDraw |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 217 | { |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 218 | auto qrCode = QRcode_encodeString(uriToDraw.UTF8String, |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 219 | 0, |
| 220 | QR_ECLEVEL_L, // Lowest level of error correction |
| 221 | QR_MODE_8, // 8-bit data mode |
| 222 | 1); |
| 223 | if (!qrCode) { |
| 224 | return; |
| 225 | } |
| 226 | |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 227 | unsigned char *data = 0; |
| 228 | int width; |
| 229 | data = qrCode->data; |
| 230 | width = qrCode->width; |
| 231 | int qr_margin = 3; |
| 232 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 233 | CGFloat size = qrcodeView.frame.size.width; |
| 234 | |
| 235 | // create context |
| 236 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
| 237 | CGContextRef ctx = CGBitmapContextCreate(0, size, size, 8, size * 4, colorSpace, kCGImageAlphaPremultipliedLast); |
| 238 | |
| 239 | CGAffineTransform translateTransform = CGAffineTransformMakeTranslation(0, -size); |
| 240 | CGAffineTransform scaleTransform = CGAffineTransformMakeScale(1, -1); |
| 241 | CGContextConcatCTM(ctx, CGAffineTransformConcat(translateTransform, scaleTransform)); |
| 242 | |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 243 | float zoom = ceil((double)size / (qrCode->width + 2.0 * qr_margin)); |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 244 | CGRect rectDraw = CGRectMake(0, 0, zoom, zoom); |
| 245 | |
| 246 | int ran; |
| 247 | for(int i = 0; i < width; ++i) { |
| 248 | for(int j = 0; j < width; ++j) { |
| 249 | if(*data & 1) { |
| 250 | CGContextSetFillColorWithColor(ctx, [NSColor ringDarkGrey].CGColor); |
| 251 | rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom); |
| 252 | CGContextAddRect(ctx, rectDraw); |
| 253 | CGContextFillPath(ctx); |
| 254 | } else { |
| 255 | CGContextSetFillColorWithColor(ctx, [NSColor windowBackgroundColor].CGColor); |
| 256 | rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom); |
| 257 | CGContextAddRect(ctx, rectDraw); |
| 258 | CGContextFillPath(ctx); |
| 259 | } |
| 260 | ++data; |
| 261 | } |
| 262 | } |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 263 | |
| 264 | // get image |
| 265 | auto qrCGImage = CGBitmapContextCreateImage(ctx); |
| 266 | auto qrImage = [[NSImage alloc] initWithCGImage:qrCGImage size:qrcodeView.frame.size]; |
| 267 | |
| 268 | // some releases |
| 269 | CGContextRelease(ctx); |
| 270 | CGImageRelease(qrCGImage); |
| 271 | CGColorSpaceRelease(colorSpace); |
| 272 | QRcode_free(qrCode); |
| 273 | |
| 274 | [qrcodeView setImage:qrImage]; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Start the in/out animation displaying the QRCode |
| 279 | * @param show should the QRCode be animated in or out |
| 280 | */ |
| 281 | - (void) showQRCode:(BOOL) show |
| 282 | { |
| 283 | static const NSInteger offset = 110; |
| 284 | [NSAnimationContext beginGrouping]; |
| 285 | NSAnimationContext.currentContext.duration = 0.5; |
| 286 | [[NSAnimationContext currentContext] setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; |
| 287 | qrcodeView.animator.alphaValue = show ? 1.0 : 0.0; |
| 288 | [centerYQRCodeConstraint.animator setConstant: show ? offset : 0]; |
| 289 | [centerYWelcomeContainerConstraint.animator setConstant:show ? -offset : 0]; |
| 290 | [NSAnimationContext endGrouping]; |
| 291 | } |
| 292 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 293 | - (IBAction)openPreferences:(id)sender |
| 294 | { |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 295 | preferencesWC = [[PreferencesWC alloc] initWithWindowNibName:@"PreferencesWindow"]; |
| 296 | [preferencesWC.window makeKeyAndOrderFront:preferencesWC.window]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 297 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 298 | |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 299 | - (IBAction)callClickedAtRow:(id)sender |
| 300 | { |
| 301 | NSTabViewItem *selectedTab = [smartViewVC.tabbar selectedTabViewItem]; |
| 302 | int index = [smartViewVC.tabbar indexOfTabViewItem:selectedTab]; |
| 303 | switch (index) { |
| 304 | case 0: |
| 305 | [smartViewVC startCallForRow:sender]; |
| 306 | break; |
Kateryna Kostiuk | 882cbac | 2017-07-05 17:29:00 -0400 | [diff] [blame] | 307 | default: |
| 308 | break; |
| 309 | } |
| 310 | } |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 311 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 312 | #pragma mark - Ring account migration |
| 313 | |
| 314 | - (void) migrateRingAccount:(Account*) acc |
| 315 | { |
| 316 | self.migrateWC = [[MigrateRingAccountsWC alloc] initWithDelegate:self actionCode:1]; |
| 317 | self.migrateWC.account = acc; |
| 318 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 |
| 319 | [self.window beginSheet:self.migrateWC.window completionHandler:nil]; |
| 320 | #else |
| 321 | [NSApp beginSheet: self.migrateWC.window |
| 322 | modalForWindow: self.window |
| 323 | modalDelegate: self |
| 324 | didEndSelector: nil |
| 325 | contextInfo: nil]; |
| 326 | #endif |
| 327 | } |
| 328 | |
Anthony Léonard | 49cb291 | 2017-11-13 16:15:39 -0500 | [diff] [blame] | 329 | // TODO: Reimplement as a blocking loop when new LRC models handle migration |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 330 | - (void)checkAccountsToMigrate |
| 331 | { |
| 332 | auto ringList = AccountModel::instance().accountsToMigrate(); |
| 333 | if (ringList.length() > 0){ |
| 334 | Account* acc = ringList.value(0); |
| 335 | [self migrateRingAccount:acc]; |
| 336 | } else { |
| 337 | // Fresh run, we need to make sure RingID appears |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 338 | [shareButton sendActionOn:NSLeftMouseDownMask]; |
| 339 | |
| 340 | [self connect]; |
Kateryna Kostiuk | a724846 | 2017-04-18 16:15:31 -0400 | [diff] [blame] | 341 | [self updateRingID]; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 342 | // display accounts to select |
| 343 | NSToolbar *toolbar = self.window.toolbar; |
| 344 | toolbar.delegate = self; |
| 345 | [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1]; |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | - (void)migrationDidComplete |
| 350 | { |
| 351 | [self checkAccountsToMigrate]; |
| 352 | } |
| 353 | |
| 354 | - (void)migrationDidCompleteWithError |
| 355 | { |
| 356 | [self checkAccountsToMigrate]; |
| 357 | } |
| 358 | |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 359 | -(void)selectAccount:(const lrc::api::account::Info&)accInfo |
| 360 | { |
| 361 | // If the selected account has been changed, we close any open panel |
| 362 | if ([smartViewVC setConversationModel:accInfo.conversationModel.get()]) { |
| 363 | [currentCallVC animateOut]; |
| 364 | [offlineVC animateOut]; |
| 365 | } |
Anthony Léonard | 61e3dcf | 2017-12-27 12:19:52 -0500 | [diff] [blame] | 366 | |
| 367 | // Welcome view informations are also updated |
| 368 | [self updateRingID]; |
Anthony Léonard | 9bebf1d | 2017-12-21 14:33:51 -0500 | [diff] [blame] | 369 | } |
| 370 | |
Anthony Léonard | 8585cc0 | 2017-12-28 14:03:45 -0500 | [diff] [blame] | 371 | -(void)rightPanelClosed |
| 372 | { |
| 373 | [smartViewVC deselect]; |
| 374 | } |
| 375 | |
Anthony Léonard | 0a9904c | 2018-01-11 16:43:47 -0500 | [diff] [blame] | 376 | -(void)currentConversationTrusted |
| 377 | { |
| 378 | [smartViewVC selectConversationList]; |
| 379 | } |
| 380 | |
Anthony Léonard | bee94cc | 2018-01-16 11:42:40 -0500 | [diff] [blame^] | 381 | -(void) listTypeChanged { |
| 382 | [offlineVC animateOut]; |
| 383 | [currentCallVC animateOut]; |
| 384 | } |
| 385 | |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 386 | #pragma mark - NSToolbarDelegate |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 387 | - (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag |
| 388 | { |
| 389 | if(itemIdentifier == kChangeAccountToolBarItemIdentifier) { |
| 390 | NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kChangeAccountToolBarItemIdentifier]; |
| 391 | toolbarItem.view = chooseAccountVC.view; |
| 392 | return toolbarItem; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 393 | } |
Kateryna Kostiuk | db1f3a1 | 2017-04-24 12:08:28 -0400 | [diff] [blame] | 394 | return nil; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 395 | } |
| 396 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 397 | @end |