blob: f1dbdbddd3d9787246455746f99f18e934e73637 [file] [log] [blame]
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -04001/*
2 * Copyright (C) 2015-2018 Savoir-faire Linux Inc.
3 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
4 * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20#import "AccRingGeneralVC.h"
21
22//cocoa
23#import <Quartz/Quartz.h>
Kateryna Kostiuk91b44e32018-09-28 17:08:02 -040024#import <AVFoundation/AVFoundation.h>
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -040025
26
27//Qt
28#import <QSize>
29#import <QtMacExtras/qmacfunctions.h>
30#import <QPixmap>
31
32//LRC
33#import <api/lrc.h>
34#import <api/newaccountmodel.h>
35#import <api/newdevicemodel.h>
36#import <interfaces/pixmapmanipulatori.h>
37#import <globalinstances.h>
38
39#import "RegisterNameWC.h"
40#import "RestoreAccountWC.h"
41#import "BackupAccountWC.h"
42#import "views/NSColor+RingTheme.h"
43#import "views/NSImage+Extensions.h"
44#import "views/HoverTableRowView.h"
45#import "ExportPasswordWC.h"
46#import "utils.h"
47
48@interface AccRingGeneralVC ()
49
50@property (unsafe_unretained) IBOutlet NSTextField *displayNameField;
51@property (unsafe_unretained) IBOutlet NSTextField *ringIDField;
52@property (unsafe_unretained) IBOutlet NSTextField *registeredNameField;
53@property (unsafe_unretained) IBOutlet NSButton *registerNameButton;
54@property (unsafe_unretained) IBOutlet NSButton* photoView;
55@property (unsafe_unretained) IBOutlet NSButton* passwordButton;
56@property (unsafe_unretained) IBOutlet NSButton* removeAccountButton;
57@property (unsafe_unretained) IBOutlet NSImageView* addProfilePhotoImage;
58@property (unsafe_unretained) IBOutlet NSTableView* devicesTableView;
59@property (unsafe_unretained) IBOutlet NSTableView* blockedContactsTableView;
60@property (assign) IBOutlet NSLayoutConstraint* buttonRegisterWidthConstraint;
61@property (assign) IBOutlet NSLayoutConstraint* bannedContactHeightConstraint;
62@property (assign) IBOutlet NSLayoutConstraint* advancedButtonMarginConstraint;
63
64
65@property AbstractLoadingWC* accountModal;
66@property PasswordChangeWC* passwordModal;
67@property std::string selectedAccountID;
68
69@end
70
71@implementation AccRingGeneralVC
72
73QMetaObject::Connection deviceAddedSignal;
74QMetaObject::Connection deviceRevokedSignal;
75QMetaObject::Connection deviceUpdatedSignal;
76QMetaObject::Connection contactBlockedSignal;
77QMetaObject::Connection bannedContactsChangedSignal;
78
79
80@synthesize displayNameField;
81@synthesize ringIDField;
82@synthesize registeredNameField;
83@synthesize photoView;
84@synthesize addProfilePhotoImage;
85@synthesize accountModel;
86@synthesize registerNameButton, passwordButton, removeAccountButton;
87@synthesize buttonRegisterWidthConstraint;
88@synthesize accountModal;
89@synthesize delegate;
90@synthesize devicesTableView;
91@synthesize blockedContactsTableView;
92
93
94typedef NS_ENUM(NSInteger, TagViews) {
95 DISPLAYNAME = 100,
96 DEVICE_NAME_TAG = 200,
97 DEVICE_ID_TAG = 300,
98 DEVICE_EDIT_TAG = 400,
99 DEVICE_REVOKE_TAG = 500,
100 BANNED_CONTACT_NAME_TAG = 600,
101 BANNED_CONTACT_ID_TAG = 700,
102 UNBLOCK_CONTACT_TAG = 800
103};
104
105-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel
106{
107 if (self = [self initWithNibName: nibNameOrNil bundle:nibBundleOrNil])
108 {
109 self.accountModel= accountModel;
110 }
111 return self;
112}
113
114- (void)awakeFromNib
115{
116 [super awakeFromNib];
Kateryna Kostiuk39ce23d2018-10-02 14:33:37 -0400117 [photoView setBordered:YES];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400118 [addProfilePhotoImage setWantsLayer: YES];
119 devicesTableView.delegate = self;
120 devicesTableView.dataSource = self;
121 blockedContactsTableView.delegate = self;
122 blockedContactsTableView.dataSource= self;
Kateryna Kostiuk3164fb02018-08-28 17:51:43 -0400123 [[self view] setAutoresizingMask: NSViewMinXMargin | NSViewMaxXMargin | NSViewHeightSizable];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400124}
125
126- (void)viewDidLoad {
127 [super viewDidLoad];
128 [self updateView];
129}
130
131- (void) setSelectedAccount:(std::string) account {
132 self.selectedAccountID = account;
133 [self connectSignals];
134 [self updateView];
135 [self hideBannedContacts];
136}
137
138-(void) updateView {
139 const auto& account = accountModel->getAccountInfo(self.selectedAccountID);
140 QByteArray ba = QByteArray::fromStdString(account.profileInfo.avatar);
141
142 QVariant photo = GlobalInstances::pixmapManipulator().personPhoto(ba, nil);
143 if(QtMac::toNSImage(qvariant_cast<QPixmap>(photo))) {
Kateryna Kostiuk39ce23d2018-10-02 14:33:37 -0400144 [photoView setBordered:NO];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400145 NSImage *image = QtMac::toNSImage(qvariant_cast<QPixmap>(photo));
146 CGFloat newSize = MIN(image.size.height, image.size.width);
147 image = [image cropImageToSize:CGSizeMake(newSize, newSize)];
148 [photoView setImage: [image roundCorners: image.size.height * 0.5]];
149 [addProfilePhotoImage setHidden:YES];
150 } else {
151 [photoView setImage:nil];
Kateryna Kostiuk39ce23d2018-10-02 14:33:37 -0400152 [photoView setBordered:YES];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400153 [addProfilePhotoImage setHidden:NO];
154 }
155 NSString* displayName = @(account.profileInfo.alias.c_str());
156 [displayNameField setStringValue:displayName];
157 [ringIDField setStringValue:@(account.profileInfo.uri.c_str())];
158 if(account.registeredName.empty()) {
159 [registerNameButton setHidden:NO];
160 buttonRegisterWidthConstraint.constant = 260.0;
161 } else {
162 buttonRegisterWidthConstraint.constant = 0.0;
163 [registerNameButton setHidden:YES];
164 }
165
166 [registeredNameField setStringValue:@(account.registeredName.c_str())];
167
168 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
169 [passwordButton setTitle:accountProperties.archiveHasPassword ? @"Change password" : @"Create password"];
170 self.accountEnabled = account.enabled;
171
172 NSMutableAttributedString *colorTitle = [[NSMutableAttributedString alloc] initWithAttributedString:[removeAccountButton attributedTitle]];
173 NSRange titleRange = NSMakeRange(0, [colorTitle length]);
174 [colorTitle addAttribute:NSForegroundColorAttributeName value:[NSColor errorColor] range:titleRange];
175 [removeAccountButton setAttributedTitle:colorTitle];
176 [devicesTableView reloadData];
177 [blockedContactsTableView reloadData];
178}
179
180-(void) connectSignals {
181 QObject::disconnect(deviceAddedSignal);
182 QObject::disconnect(deviceRevokedSignal);
183 QObject::disconnect(deviceUpdatedSignal);
184 QObject::disconnect(bannedContactsChangedSignal);
185 deviceAddedSignal = QObject::connect(&*(self.accountModel->getAccountInfo(self.selectedAccountID)).deviceModel,
186 &lrc::api::NewDeviceModel::deviceAdded,
187 [self] (const std::string &id) {
188 [devicesTableView reloadData];
189 });
190 deviceRevokedSignal = QObject::connect(&*(self.accountModel->getAccountInfo(self.selectedAccountID)).deviceModel,
191 &lrc::api::NewDeviceModel::deviceRevoked,
192 [self] (const std::string &id, const lrc::api::NewDeviceModel::Status status) {
193 switch (status) {
194 case lrc::api::NewDeviceModel::Status::SUCCESS:
195 [devicesTableView reloadData];
196 break;
197 case lrc::api::NewDeviceModel::Status::WRONG_PASSWORD:
198 [self showAlertWithTitle: @"" andText: @"Device revocation failed with error: Wrong password"];
199 break;
200 case lrc::api::NewDeviceModel::Status::UNKNOWN_DEVICE:
201 [self showAlertWithTitle: @"" andText: @"Device revocation failed with error: Unknown device"];
202 break;
203 }
204 });
205 deviceUpdatedSignal = QObject::connect(&*(self.accountModel->getAccountInfo(self.selectedAccountID)).deviceModel,
206 &lrc::api::NewDeviceModel::deviceUpdated,
207 [self] (const std::string &id) {
208 [devicesTableView reloadData];
209 });
210 bannedContactsChangedSignal = QObject::connect(&*(self.accountModel->getAccountInfo(self.selectedAccountID)).contactModel,
211 &lrc::api::ContactModel::bannedStatusChanged,
212 [self] (const std::string &contactUri, bool banned) {
213 [blockedContactsTableView reloadData];
214 });
215}
216
217-(void) showAlertWithTitle: (NSString *) title andText: (NSString *)text {
218 NSAlert *alert = [[NSAlert alloc] init];
219 [alert addButtonWithTitle:@"OK"];
220 [alert setMessageText:title];
221 [alert setInformativeText:text];
222 [alert runModal];
223}
224
225- (void)pictureTakerDidEnd:(IKPictureTaker *) picker
226 returnCode:(NSInteger) code
227 contextInfo:(void*) contextInfo
228{
Kateryna Kostiuk256814e2018-09-04 14:47:33 -0400229 //do nothing when editing canceled
230 if (code == 0) {
231 return;
232 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400233 if (auto outputImage = [picker outputImage]) {
234 auto image = [picker inputImage];
235 CGFloat newSize = MIN(image.size.height, image.size.width);
236 outputImage = [outputImage cropImageToSize:CGSizeMake(newSize, newSize)];
237 [photoView setImage: [outputImage roundCorners: outputImage.size.height * 0.5]];
Kateryna Kostiuk39ce23d2018-10-02 14:33:37 -0400238 [photoView setBordered:NO];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400239 [addProfilePhotoImage setHidden:YES];
240 auto imageToBytes = QByteArray::fromNSData([outputImage TIFFRepresentation]).toBase64();
241 std::string imageToString = std::string(imageToBytes.constData(), imageToBytes.length());
242 self.accountModel->setAvatar(self.selectedAccountID, imageToString);
243 } else if(!photoView.image) {
Kateryna Kostiuk39ce23d2018-10-02 14:33:37 -0400244 [photoView setBordered:YES];
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400245 [addProfilePhotoImage setHidden:NO];
246 }
247}
248
249#pragma mark - RegisterNameDelegate methods
250
251- (void) didRegisterName:(NSString *) name withSuccess:(BOOL) success
252{
253 [self.accountModal close];
254 if(!success) {
255 return;
256 }
257
258 if(name.length == 0) {
259 return;
260 }
261 buttonRegisterWidthConstraint.constant = 0.0;
262 [registerNameButton setHidden:YES];
263 [registeredNameField setStringValue:name];
264}
265
266#pragma mark - NSTextFieldDelegate delegate methods
267
268- (void)controlTextDidChange:(NSNotification *)notif
269{
270 NSTextField* textField = [notif object];
271 if (textField.tag != DISPLAYNAME) {
272 return;
273 }
274 NSString* displayName = textField.stringValue;
275
276 [NSObject cancelPreviousPerformRequestsWithTarget:self];
277 self.accountModel->setAlias(self.selectedAccountID, [displayName UTF8String]);
278 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
279 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
280}
281
282#pragma mark - NSTableViewDataSource methods
283
284- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
285 if(tableView == devicesTableView) {
286 return self.accountModel->getAccountInfo(self.selectedAccountID).deviceModel->getAllDevices().size();
287 } else if (tableView == blockedContactsTableView){
288 return self.accountModel->getAccountInfo(self.selectedAccountID).contactModel->getBannedContacts().size();
289 }
290 return 0;
291}
292
293#pragma mark - NSTableViewDelegate methods
294- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
295{
296 if(tableView == devicesTableView) {
297 NSTableCellView* deviceView = [tableView makeViewWithIdentifier:@"TableCellDeviceItem" owner:self];
298 NSTextField* nameLabel = [deviceView viewWithTag: DEVICE_NAME_TAG];
299 NSTextField* idLabel = [deviceView viewWithTag: DEVICE_ID_TAG];
300 NSButton* revokeButton = [deviceView viewWithTag: DEVICE_REVOKE_TAG];
301 NSButton* editButton = [deviceView viewWithTag: DEVICE_EDIT_TAG];
302 [editButton setAction:@selector(editDevice:)];
303 [editButton setTarget:self];
304 [revokeButton setAction:@selector(startDeviceRevocation:)];
305 [revokeButton setTarget:self];
306 auto devices = self.accountModel->getAccountInfo(self.selectedAccountID).deviceModel->getAllDevices();
307 auto device = devices.begin();
308
309 std::advance(device, row);
310
311 auto name = device->name;
312 auto deviceID = device->id;
313
314 [nameLabel setStringValue: @(name.c_str())];
315 [idLabel setStringValue: @(deviceID.c_str())];
316 [revokeButton setHidden: device->isCurrent];
317 [editButton setHidden: !device->isCurrent];
318 return deviceView;
319 } else if (tableView == blockedContactsTableView) {
320 NSTableCellView* contactView = [tableView makeViewWithIdentifier:@"TableCellBannedContactItem" owner:self];
321 NSTextField* nameLabel = [contactView viewWithTag: BANNED_CONTACT_NAME_TAG];
322 NSTextField* idLabel = [contactView viewWithTag: BANNED_CONTACT_ID_TAG];
323 NSButton* revokeButton = [contactView viewWithTag: UNBLOCK_CONTACT_TAG];
324 auto contacts = self.accountModel->getAccountInfo(self.selectedAccountID).contactModel->getBannedContacts();
325 auto contactID = contacts.begin();
326 std::advance(contactID, row);
327 [idLabel setStringValue: @(contactID->c_str())];
328 auto contact = self.accountModel->getAccountInfo(self.selectedAccountID).contactModel->getContact([@(contactID->c_str()) UTF8String]);
329 [nameLabel setStringValue: bestNameForContact(contact)];
330 [revokeButton setAction:@selector(unblockContact:)];
331 [revokeButton setTarget:self];
332 return contactView;
333 }
334}
335
336- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
337{
338 if(tableView == devicesTableView) {
339 return tableView.rowHeight;
340 } else if (tableView == blockedContactsTableView) {
341 CGFloat height = self.bannedContactHeightConstraint.constant;
342 if(height == 150) {
343 return 52;
344 } else {
345 return 1;
346 }
347 }
348}
349
350- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
351{
352 return [tableView makeViewWithIdentifier:@"HoverRowView" owner:nil];
353}
354
355#pragma mark - Actions
356
357- (IBAction)editPhoto:(id)sender
358{
359 auto pictureTaker = [IKPictureTaker pictureTaker];
Kateryna Kostiuk91b44e32018-09-28 17:08:02 -0400360 if (@available(macOS 10.14, *)) {
361 AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
362 if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied)
363 {
364 [pictureTaker setValue:0 forKey:IKPictureTakerAllowsVideoCaptureKey];
365 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400366
Kateryna Kostiuk91b44e32018-09-28 17:08:02 -0400367 if(authStatus == AVAuthorizationStatusNotDetermined)
368 {
369 [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
370 if(!granted){
371 [pictureTaker setValue:0 forKey:IKPictureTakerAllowsVideoCaptureKey];
372 }
373 }];
374 }
375 }
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400376 [pictureTaker beginPictureTakerSheetForWindow:[self.view window]
377 withDelegate:self
378 didEndSelector:@selector(pictureTakerDidEnd:returnCode:contextInfo:)
379 contextInfo:nil];
380
381}
382
383- (IBAction)startExportOnRing:(id)sender
384{
385 ExportPasswordWC *passwordWC = [[ExportPasswordWC alloc] initWithNibName:@"ExportPasswordWindow" bundle: nil accountmodel: self.accountModel];
386 passwordWC.selectedAccountID = self.selectedAccountID;
387 accountModal = passwordWC;
388 [self.view.window beginSheet: passwordWC.window completionHandler:nil];
389}
390- (IBAction)triggerAdwancedSettings: (NSButton *)sender {
391 [self.delegate triggerAdvancedOptions];
392}
393
394- (IBAction)enableAccount: (NSButton *)sender {
395 const auto& account = accountModel->getAccountInfo(self.selectedAccountID);
396 self.accountModel->enableAccount(self.selectedAccountID, !account.enabled);
397 self.accountEnabled = account.enabled;
398 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
399 self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
400}
401
402- (IBAction)removeAccount:(id)sender
403{
404 NSAlert *alert = [[NSAlert alloc] init];
405 [alert addButtonWithTitle:@"OK"];
406 [alert addButtonWithTitle:@"Cancel"];
407 [alert setMessageText: NSLocalizedString(@"Remove account",
408 @"Remove account alert title")];
409 [alert setInformativeText:NSLocalizedString(@"By clicking \"OK\" you will remove this account on this device! This action can not be undone. Also, your registered name can be lost.",
410 @"Remove account alert message")];
411
412 if ([alert runModal] == NSAlertFirstButtonReturn) {
413 self.accountModel->removeAccount(self.selectedAccountID);
414 }
415}
416
417- (IBAction)exportAccount:(id)sender
418{
419 BackupAccountWC* passwordWC = [[BackupAccountWC alloc] initWithNibName:@"BackupAccountWindow" bundle: nil accountmodel: self.accountModel];
420 passwordWC.delegate = self;
421 [passwordWC setAllowFileSelection:NO];
Kateryna Kostiuk14366812018-08-24 16:30:20 -0400422 passwordWC.selectedAccountID = self.selectedAccountID;
Kateryna Kostiuk1f8c1252018-07-30 18:18:57 -0400423 accountModal = passwordWC;
424 [self.view.window beginSheet:passwordWC.window completionHandler:nil];
425}
426
427- (IBAction)startNameRegistration:(id)sender
428{
429 RegisterNameWC* registerWC = [[RegisterNameWC alloc] initWithNibName:@"RegisterNameWindow" bundle: nil accountmodel: self.accountModel];
430 registerWC.delegate = self;
431 registerWC.selectedAccountID = self.selectedAccountID;
432 self.accountModal = registerWC;
433 [self.view.window beginSheet:registerWC.window completionHandler:nil];
434}
435- (IBAction)changePassword:(id)sender
436{
437 PasswordChangeWC* passwordWC = [[PasswordChangeWC alloc] initWithNibName:@"PasswordChange" bundle: nil accountmodel: self.accountModel];
438 passwordWC.selectedAccountID = self.selectedAccountID;
439 passwordWC.delegate = self;
440 [self.view.window beginSheet:passwordWC.window completionHandler:nil];
441 self.passwordModal = passwordWC;
442}
443
444- (IBAction)showBanned: (NSButton *)sender {
445 CGFloat height = self.bannedContactHeightConstraint.constant;
446 NSRect frame = self.view.frame;
447 if(height == 150) {
448 frame.size.height = frame.size.height - 150 - 10;
449 } else {
450 frame.size.height = frame.size.height + 150 + 10;
451 }
452 self.view.frame = frame;
453 [self.delegate updateFrame];
454 CGFloat advancedHeight = self.advancedButtonMarginConstraint.constant;
455 self.advancedButtonMarginConstraint.constant = (height== 2) ? 40 : 30;
456 self.bannedContactHeightConstraint.constant = (height== 2) ? 150 : 2;
457 [[[self.blockedContactsTableView superview] superview] setHidden:![[[self.blockedContactsTableView superview] superview] isHidden]];
458 [blockedContactsTableView reloadData];
459}
460
461-(void) hideBannedContacts {
462 CGFloat height = self.bannedContactHeightConstraint.constant;
463 NSRect frame = self.view.frame;
464 if(height == 150) {
465 [self showBanned:nil];
466 }
467}
468
469- (IBAction)startDeviceRevocation:(NSView*)sender
470{
471 NSInteger row = [devicesTableView rowForView:sender];
472 if(row < 0) {
473 return;
474 }
475 auto devices = self.accountModel->getAccountInfo(self.selectedAccountID).deviceModel->getAllDevices();
476 auto device = devices.begin();
477 std::advance(device, row);
478 if(device == devices.end()) {
479 return;
480 }
481 [self proceedDeviceRevokationAlert:device->id];
482}
483
484- (IBAction)unblockContact:(NSView*)sender
485{
486 NSInteger row = [blockedContactsTableView rowForView:sender];
487 if(row < 0) {
488 return;
489 }
490 auto contacts = self.accountModel->getAccountInfo(self.selectedAccountID).contactModel->getBannedContacts();
491 auto contactID = contacts.begin();
492 std::advance(contactID, row);
493 if(contactID == contacts.end()) {
494 return;
495 }
496 auto contact = self.accountModel->getAccountInfo(self.selectedAccountID).contactModel->getContact([@(contactID->c_str()) UTF8String]);
497 if(!contact.isBanned) {
498 return;
499 }
500 self.accountModel->getAccountInfo(self.selectedAccountID).contactModel->addContact(contact);
501}
502
503- (IBAction)editDevice:(NSView*)sender
504{
505 NSInteger row = [devicesTableView rowForView:sender];
506 if(row < 0) {
507 return;
508 }
509
510 NSTableCellView* deviceView = [devicesTableView viewAtColumn:0 row:row makeIfNecessary:NO];
511 if(!deviceView || ![deviceView isKindOfClass:[NSTableCellView class]]) {
512 return;
513 }
514
515 NSTextField* nameLabel = [deviceView viewWithTag: DEVICE_NAME_TAG];
516 NSButton* editButton = [deviceView viewWithTag: DEVICE_EDIT_TAG];
517 if ([nameLabel isEditable]) {
518 self.accountModel->getAccountInfo(self.selectedAccountID).deviceModel->setCurrentDeviceName([nameLabel.stringValue UTF8String]);
519 [nameLabel setEditable:NO];
520 [self.view.window makeFirstResponder:nil];
521 editButton.image = [NSImage imageNamed:NSImageNameTouchBarComposeTemplate];
522 return;
523 }
524 [nameLabel setEditable:YES];
525 [nameLabel becomeFirstResponder];
526 editButton.image = [NSImage imageNamed:NSImageNameTouchBarDownloadTemplate];
527}
528
529-(void) revokeDeviceWithID: (std::string) deviceID password:(NSString *) password {
530 self.accountModel->getAccountInfo(self.selectedAccountID).deviceModel->revokeDevice(deviceID, [password UTF8String]);
531}
532
533-(void) proceedDeviceRevokationAlert: (std::string) deviceID {
534 NSAlert *alert = [[NSAlert alloc] init];
535 [alert addButtonWithTitle:@"OK"];
536 [alert addButtonWithTitle:@"Cancel"];
537 [alert setMessageText:@"Revoke Device"];
538 [alert setInformativeText:@"Attention! This action could not be undone!"];
539 lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
540 if(accountProperties.archiveHasPassword) {
541 NSSecureTextField *passwordText = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)];
542 [passwordText setPlaceholderString:@"Enter password"];
543 [alert setAccessoryView:passwordText];
544 if ([alert runModal] == NSAlertFirstButtonReturn) {
545 [self revokeDeviceWithID:deviceID password:[passwordText stringValue]];
546 }
547 } else {
548 if ([alert runModal] == NSAlertFirstButtonReturn) {
549 [self revokeDeviceWithID:deviceID password:@""];
550 }
551 }
552}
553
554#pragma mark - BackupAccountDelegate methods
555
556-(void) didCompleteExportWithPath:(NSURL*) fileUrl
557{
558 [[NSWorkspace sharedWorkspace] selectFile:fileUrl.path inFileViewerRootedAtPath:@""];
559}
560
561#pragma mark - PasswordChangeDelegate
562
563-(void) paswordCreatedWithSuccess:(BOOL) success
564{
565 [passwordButton setTitle: success ? @"Change password" : @"Create password"];
566}
567
568@end