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> |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 22 | |
| 23 | //Qt |
| 24 | #import <QItemSelectionModel> |
| 25 | #import <QItemSelection> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 26 | |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 27 | //LRC |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 28 | #import <accountmodel.h> |
| 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> |
| 34 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 35 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 36 | // Ring |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 37 | #import "AppDelegate.h" |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 38 | #import "Constants.h" |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 39 | #import "CurrentCallVC.h" |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 40 | #import "MigrateRingAccountsWC.h" |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 41 | #import "ConversationVC.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 42 | #import "PreferencesWC.h" |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 43 | #import "SmartViewVC.h" |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 44 | #import "views/IconButton.h" |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 45 | #import "views/NSColor+RingTheme.h" |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 46 | #import "views/BackgroundView.h" |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 47 | #import "ChooseAccountVC.h" |
Alexandre Lision | 2db8f47 | 2015-07-22 15:05:46 -0400 | [diff] [blame] | 48 | |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 49 | @interface RingWindowController () <MigrateRingAccountsDelegate, NSToolbarDelegate> |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 50 | |
| 51 | @property (retain) MigrateRingAccountsWC* migrateWC; |
| 52 | |
| 53 | @end |
| 54 | |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 55 | @implementation RingWindowController { |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 56 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 57 | __unsafe_unretained IBOutlet NSLayoutConstraint* centerYQRCodeConstraint; |
| 58 | __unsafe_unretained IBOutlet NSLayoutConstraint* centerYWelcomeContainerConstraint; |
| 59 | __unsafe_unretained IBOutlet NSView* welcomeContainer; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 60 | __unsafe_unretained IBOutlet NSView* callView; |
| 61 | __unsafe_unretained IBOutlet NSTextField* ringIDLabel; |
| 62 | __unsafe_unretained IBOutlet NSButton* shareButton; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 63 | __unsafe_unretained IBOutlet NSImageView* qrcodeView; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 64 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 65 | PreferencesWC* preferencesWC; |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 66 | IBOutlet SmartViewVC* smartViewVC; |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 67 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 68 | CurrentCallVC* currentCallVC; |
| 69 | ConversationVC* offlineVC; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 70 | |
| 71 | ChooseAccountVC* chooseAccountVC; |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 72 | } |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 73 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 74 | static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier"; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 75 | NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItemIdentifier"; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 76 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 77 | - (void)windowDidLoad { |
| 78 | [super windowDidLoad]; |
Alexandre Lision | 4dfcafc | 2015-08-20 12:43:23 -0400 | [diff] [blame] | 79 | [self.window setMovableByWindowBackground:YES]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 80 | |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 81 | [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] | 82 | self.window.titleVisibility = NSWindowTitleHidden; |
Alexandre Lision | e77f6f9 | 2016-04-17 23:39:39 -0400 | [diff] [blame] | 83 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 84 | currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil]; |
| 85 | offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil]; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 86 | chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 87 | [callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 88 | [[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 89 | [[offlineVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame] | 90 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 91 | [callView addSubview:[currentCallVC view] positioned:NSWindowAbove relativeTo:nil]; |
| 92 | [callView addSubview:[offlineVC view] positioned:NSWindowAbove relativeTo:nil]; |
Alexandre Lision | 16d9c0a | 2015-08-10 12:05:15 -0400 | [diff] [blame] | 93 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 94 | [currentCallVC initFrame]; |
| 95 | [offlineVC initFrame]; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 96 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 97 | [self checkAccountsToMigrate]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | - (void) connect |
| 101 | { |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 102 | // Update Ring ID label based on account model changes |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 103 | QObject::connect(RecentModel::instance().selectionModel(), |
| 104 | &QItemSelectionModel::currentChanged, |
| 105 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 106 | auto call = RecentModel::instance().getActiveCall(current); |
Alexandre Lision | 261f1b9 | 2016-04-04 12:35:34 -0400 | [diff] [blame] | 107 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 108 | if(!current.isValid()) { |
Alexandre Lision | 01cf5e3 | 2016-01-21 15:54:30 -0500 | [diff] [blame] | 109 | [offlineVC animateOut]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 110 | [currentCallVC animateOut]; |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | if (!call) { |
| 115 | [currentCallVC animateOut]; |
| 116 | [offlineVC animateIn]; |
| 117 | } else { |
| 118 | [currentCallVC animateIn]; |
Alexandre Lision | 01cf5e3 | 2016-01-21 15:54:30 -0500 | [diff] [blame] | 119 | [offlineVC animateOut]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 120 | } |
| 121 | }); |
Alexandre Lision | 210fe21 | 2016-01-27 11:15:13 -0500 | [diff] [blame] | 122 | |
| 123 | QObject::connect(CallModel::instance().selectionModel(), |
| 124 | &QItemSelectionModel::currentChanged, |
| 125 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 126 | if(!current.isValid()) { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | if (previous.isValid()) { |
| 131 | // We were already on a call |
| 132 | [currentCallVC animateOut]; |
| 133 | } else { |
| 134 | // Make sure Conversation view hides when selecting a valid call |
| 135 | [currentCallVC animateIn]; |
| 136 | [offlineVC animateOut]; |
| 137 | } |
| 138 | }); |
Kateryna Kostiuk | 312f913 | 2017-04-18 12:09:06 -0400 | [diff] [blame^] | 139 | QObject::connect(AvailableAccountModel::instance().selectionModel(), |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 140 | &QItemSelectionModel::currentChanged, |
Kateryna Kostiuk | 312f913 | 2017-04-18 12:09:06 -0400 | [diff] [blame^] | 141 | [self](const QModelIndex& idx){ |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 142 | [self updateRingID]; |
| 143 | }); |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Implement the necessary logic to choose which Ring ID to display. |
| 148 | * This tries to choose the "best" ID to show |
| 149 | */ |
| 150 | - (void) updateRingID |
| 151 | { |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 152 | Account* finalChoice = nullptr; |
| 153 | |
| 154 | [ringIDLabel setStringValue:@""]; |
Kateryna Kostiuk | 312f913 | 2017-04-18 12:09:06 -0400 | [diff] [blame^] | 155 | QModelIndex index = AvailableAccountModel::instance().selectionModel()->currentIndex(); |
| 156 | finalChoice = index.data(static_cast<int>(Account::Role::Object)).value<Account*>(); |
| 157 | if(finalChoice == nil || (finalChoice->protocol() != Account::Protocol::RING)) { |
| 158 | return; |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 159 | } |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 160 | auto name = finalChoice->registeredName(); |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 161 | NSString* uriToDisplay = nullptr; |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 162 | if (!name.isNull() && !name.isEmpty()) { |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 163 | uriToDisplay = name.toNSString(); |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 164 | } else { |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 165 | uriToDisplay = finalChoice->username().toNSString(); |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 166 | } |
Alexandre Lision | bb5c246 | 2015-07-30 12:55:37 -0400 | [diff] [blame] | 167 | |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 168 | [ringIDLabel setStringValue:uriToDisplay]; |
| 169 | [self drawQRCode:finalChoice->username().toNSString()]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 170 | } |
| 171 | |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 172 | - (IBAction)shareRingID:(id)sender { |
| 173 | NSSharingServicePicker* sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:[NSArray arrayWithObject:[ringIDLabel stringValue]]]; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 174 | [sharingServicePicker setDelegate:self]; |
Alexandre Lision | 1abdf58 | 2016-02-09 14:21:19 -0500 | [diff] [blame] | 175 | [sharingServicePicker showRelativeToRect:[sender bounds] |
| 176 | ofView:sender |
| 177 | preferredEdge:NSMinYEdge]; |
| 178 | } |
| 179 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 180 | - (IBAction)toggleQRCode:(id)sender { |
| 181 | // Toggle pressed state of QRCode button |
| 182 | [sender setPressed:![sender isPressed]]; |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 183 | [self showQRCode:[sender isPressed]]; |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Draw the QRCode in the qrCodeView |
| 188 | */ |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 189 | - (void)drawQRCode:(NSString*) uriToDraw |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 190 | { |
Kateryna Kostiuk | 65ba43e | 2017-03-30 15:10:04 -0400 | [diff] [blame] | 191 | auto qrCode = QRcode_encodeString(uriToDraw.UTF8String, |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 192 | 0, |
| 193 | QR_ECLEVEL_L, // Lowest level of error correction |
| 194 | QR_MODE_8, // 8-bit data mode |
| 195 | 1); |
| 196 | if (!qrCode) { |
| 197 | return; |
| 198 | } |
| 199 | |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 200 | unsigned char *data = 0; |
| 201 | int width; |
| 202 | data = qrCode->data; |
| 203 | width = qrCode->width; |
| 204 | int qr_margin = 3; |
| 205 | |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 206 | CGFloat size = qrcodeView.frame.size.width; |
| 207 | |
| 208 | // create context |
| 209 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
| 210 | CGContextRef ctx = CGBitmapContextCreate(0, size, size, 8, size * 4, colorSpace, kCGImageAlphaPremultipliedLast); |
| 211 | |
| 212 | CGAffineTransform translateTransform = CGAffineTransformMakeTranslation(0, -size); |
| 213 | CGAffineTransform scaleTransform = CGAffineTransformMakeScale(1, -1); |
| 214 | CGContextConcatCTM(ctx, CGAffineTransformConcat(translateTransform, scaleTransform)); |
| 215 | |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 216 | float zoom = ceil((double)size / (qrCode->width + 2.0 * qr_margin)); |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 217 | CGRect rectDraw = CGRectMake(0, 0, zoom, zoom); |
| 218 | |
| 219 | int ran; |
| 220 | for(int i = 0; i < width; ++i) { |
| 221 | for(int j = 0; j < width; ++j) { |
| 222 | if(*data & 1) { |
| 223 | CGContextSetFillColorWithColor(ctx, [NSColor ringDarkGrey].CGColor); |
| 224 | rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom); |
| 225 | CGContextAddRect(ctx, rectDraw); |
| 226 | CGContextFillPath(ctx); |
| 227 | } else { |
| 228 | CGContextSetFillColorWithColor(ctx, [NSColor windowBackgroundColor].CGColor); |
| 229 | rectDraw.origin = CGPointMake((j + qr_margin) * zoom,(i + qr_margin) * zoom); |
| 230 | CGContextAddRect(ctx, rectDraw); |
| 231 | CGContextFillPath(ctx); |
| 232 | } |
| 233 | ++data; |
| 234 | } |
| 235 | } |
Alexandre Lision | 313427f | 2016-11-24 21:04:04 -0500 | [diff] [blame] | 236 | |
| 237 | // get image |
| 238 | auto qrCGImage = CGBitmapContextCreateImage(ctx); |
| 239 | auto qrImage = [[NSImage alloc] initWithCGImage:qrCGImage size:qrcodeView.frame.size]; |
| 240 | |
| 241 | // some releases |
| 242 | CGContextRelease(ctx); |
| 243 | CGImageRelease(qrCGImage); |
| 244 | CGColorSpaceRelease(colorSpace); |
| 245 | QRcode_free(qrCode); |
| 246 | |
| 247 | [qrcodeView setImage:qrImage]; |
Alexandre Lision | fd0d6c8 | 2016-03-29 17:06:54 -0400 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Start the in/out animation displaying the QRCode |
| 252 | * @param show should the QRCode be animated in or out |
| 253 | */ |
| 254 | - (void) showQRCode:(BOOL) show |
| 255 | { |
| 256 | static const NSInteger offset = 110; |
| 257 | [NSAnimationContext beginGrouping]; |
| 258 | NSAnimationContext.currentContext.duration = 0.5; |
| 259 | [[NSAnimationContext currentContext] setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; |
| 260 | qrcodeView.animator.alphaValue = show ? 1.0 : 0.0; |
| 261 | [centerYQRCodeConstraint.animator setConstant: show ? offset : 0]; |
| 262 | [centerYWelcomeContainerConstraint.animator setConstant:show ? -offset : 0]; |
| 263 | [NSAnimationContext endGrouping]; |
| 264 | } |
| 265 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 266 | - (IBAction)openPreferences:(id)sender |
| 267 | { |
Alexandre Lision | bfa68f6 | 2015-09-10 08:38:42 -0400 | [diff] [blame] | 268 | preferencesWC = [[PreferencesWC alloc] initWithWindowNibName:@"PreferencesWindow"]; |
| 269 | [preferencesWC.window makeKeyAndOrderFront:preferencesWC.window]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 270 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 271 | |
Alexandre Lision | a3a43dc | 2017-03-30 16:21:30 -0400 | [diff] [blame] | 272 | - (IBAction)showHistory:(NSButton*)sender |
| 273 | { |
| 274 | [smartViewVC showHistory]; |
| 275 | } |
| 276 | |
| 277 | - (IBAction)showContacts:(NSButton*)sender |
| 278 | { |
| 279 | [smartViewVC showContacts]; |
| 280 | } |
| 281 | |
| 282 | - (IBAction)showSmartlist:(NSButton*)sender |
| 283 | { |
| 284 | [smartViewVC showSmartlist]; |
| 285 | } |
| 286 | |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 287 | #pragma mark - Ring account migration |
| 288 | |
| 289 | - (void) migrateRingAccount:(Account*) acc |
| 290 | { |
| 291 | self.migrateWC = [[MigrateRingAccountsWC alloc] initWithDelegate:self actionCode:1]; |
| 292 | self.migrateWC.account = acc; |
| 293 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9 |
| 294 | [self.window beginSheet:self.migrateWC.window completionHandler:nil]; |
| 295 | #else |
| 296 | [NSApp beginSheet: self.migrateWC.window |
| 297 | modalForWindow: self.window |
| 298 | modalDelegate: self |
| 299 | didEndSelector: nil |
| 300 | contextInfo: nil]; |
| 301 | #endif |
| 302 | } |
| 303 | |
| 304 | - (void)checkAccountsToMigrate |
| 305 | { |
| 306 | auto ringList = AccountModel::instance().accountsToMigrate(); |
| 307 | if (ringList.length() > 0){ |
| 308 | Account* acc = ringList.value(0); |
| 309 | [self migrateRingAccount:acc]; |
| 310 | } else { |
| 311 | // Fresh run, we need to make sure RingID appears |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 312 | [shareButton sendActionOn:NSLeftMouseDownMask]; |
| 313 | |
| 314 | [self connect]; |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 315 | // display accounts to select |
| 316 | NSToolbar *toolbar = self.window.toolbar; |
| 317 | toolbar.delegate = self; |
| 318 | [toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1]; |
Alexandre Lision | 624b1a8 | 2016-09-11 19:29:01 -0400 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
| 322 | - (void)migrationDidComplete |
| 323 | { |
| 324 | [self checkAccountsToMigrate]; |
| 325 | } |
| 326 | |
| 327 | - (void)migrationDidCompleteWithError |
| 328 | { |
| 329 | [self checkAccountsToMigrate]; |
| 330 | } |
| 331 | |
Kateryna Kostiuk | 13b7688 | 2017-03-30 09:18:44 -0400 | [diff] [blame] | 332 | #pragma mark - NSToolbarDelegate |
| 333 | - (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag{ |
| 334 | if(!(itemIdentifier == kChangeAccountToolBarItemIdentifier)) { |
| 335 | return nil; |
| 336 | } |
| 337 | NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kChangeAccountToolBarItemIdentifier]; |
| 338 | CGRect frame = chooseAccountVC.view.frame; |
| 339 | toolbarItem.view = chooseAccountVC.view; |
| 340 | return toolbarItem; |
| 341 | } |
| 342 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 343 | @end |