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