create account: link to new lrc
Change-Id: I08b578cc29f0fc8f664763b3aeecb8406a6aa328
Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
diff --git a/src/AccountsVC.h b/src/AccountsVC.h
index ed64a79..7303aab 100644
--- a/src/AccountsVC.h
+++ b/src/AccountsVC.h
@@ -18,7 +18,8 @@
*/
#import <Cocoa/Cocoa.h>
+#import "LrcModelsProtocol.h"
-@interface AccountsVC : NSViewController <NSOutlineViewDelegate, NSMenuDelegate>
+@interface AccountsVC : NSViewController <NSOutlineViewDelegate, NSMenuDelegate, LrcModelsProtocol>
-@end
\ No newline at end of file
+@end
diff --git a/src/AccountsVC.mm b/src/AccountsVC.mm
index da7d67a..fa856cf 100644
--- a/src/AccountsVC.mm
+++ b/src/AccountsVC.mm
@@ -95,6 +95,8 @@
QMetaObject::Connection accountChangedConnection, selectedAccountChangedConnection, accountTypeChangedConnection;
+@synthesize accountModel;
+
- (void)loadView {
[super loadView];
@@ -182,6 +184,15 @@
[self.bannedListTabItem setView:self.bannedContactsVC.view];
}
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel
+{
+ if (self = [self initWithNibName: nibNameOrNil bundle:nibBundleOrNil])
+ {
+ self.accountModel= accountModel;
+ }
+ return self;
+}
+
- (void) setupSIPPanels
{
// Start by removing all tabs
@@ -404,17 +415,10 @@
- (IBAction)addAccountClicked:(NSButton *)sender
{
- NSMenu* menu = [[NSMenu alloc] init];
- [menu insertItemWithTitle:NSLocalizedString(@"Create RING Account", @"Contextual menu entry")
- action:@selector(createRingAccount:)
- keyEquivalent:@""
- atIndex:0];
- [menu insertItemWithTitle:NSLocalizedString(@"Create SIP Account", @"Contextual menu entry")
- action:@selector(createSIPAccount:)
- keyEquivalent:@""
- atIndex:0];
-
- [NSMenu popUpContextMenu:menu withEvent:[self forgedEventForButton:sender] forView:(NSButton *)sender];
+ wizard = [[RingWizardWC alloc] initWithNibName:@"RingWizard" bundle: nil accountmodel: self.accountModel];
+ [wizard showChooseWithCancelButton: YES andAdvanced: YES];
+ [self.view.window beginSheet:wizard.window completionHandler:nil];
+ [wizard showWindow:self];
}
- (void)createSIPAccount:(NSMenuItem*) sender
@@ -426,23 +430,6 @@
AccountModel::instance().save();
}
-- (void)createRingAccount:(NSMenuItem*) sender
-{
- wizard = [[RingWizardWC alloc] initWithWindowNibName:@"RingWizard"];
- [wizard showChooseWithCancelButton: YES];
- // [wizard.window makeKeyAndOrderFront:self];
-#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9
- [self.view.window beginSheet:wizard.window completionHandler:nil];
-#else
- [NSApp beginSheet: wizard.window
- modalForWindow: self.view.window
- modalDelegate: self
- didEndSelector: nil
- contextInfo: nil];
-#endif
- [wizard showWindow:self];
-}
-
#pragma mark - BackupAccountDelegate methods
-(void) didCompleteExportWithPath:(NSURL*) fileUrl
diff --git a/src/AddSIPAccountVC.h b/src/AddSIPAccountVC.h
new file mode 100644
index 0000000..3dbef87
--- /dev/null
+++ b/src/AddSIPAccountVC.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 22018 Savoir-faire Linux Inc.
+ * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import "LrcModelsProtocol.h"
+
+@protocol AddSIPAccountDelegate <NSObject>
+- (void)close;
+- (void)showView:(NSView*)view;
+@end
+
+@interface AddSIPAccountVC : NSViewController <LrcModelsProtocol>
+@property (nonatomic, weak) NSWindowController <AddSIPAccountDelegate>* delegate;
+- (void)show;
+
+@end
diff --git a/src/AddSIPAccountVC.mm b/src/AddSIPAccountVC.mm
new file mode 100644
index 0000000..2e3c4f2
--- /dev/null
+++ b/src/AddSIPAccountVC.mm
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 22018 Savoir-faire Linux Inc.
+ * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+//cocoa
+#import <Quartz/Quartz.h>
+
+//LRC
+#import <api/lrc.h>
+#import <api/newaccountmodel.h>
+#import <account.h>
+
+//ring
+#import "AddSIPAccountVC.h"
+
+@interface AddSIPAccountVC () {
+ __unsafe_unretained IBOutlet NSButton* photoView;
+ __unsafe_unretained IBOutlet NSImageView* addProfilePhotoImage;
+ __unsafe_unretained IBOutlet NSTextField* displayNameField;
+ __unsafe_unretained IBOutlet NSTextField* userNameField;
+ __unsafe_unretained IBOutlet NSSecureTextField* passwordField;
+ __unsafe_unretained IBOutlet NSTextField* serverField;
+}
+@end
+
+@implementation AddSIPAccountVC
+
+QMetaObject::Connection accountCreated;
+std::string accountToCreate;
+NSTimer* timeoutTimer;
+@synthesize accountModel;
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ [self.view setAutoresizingMask: NSViewHeightSizable];
+}
+
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel {
+ if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
+ {
+ self.accountModel = accountModel;
+ }
+ return self;
+}
+
+-(void) show {
+ [photoView setWantsLayer: YES];
+ photoView.layer.cornerRadius = photoView.frame.size.width / 2;
+ photoView.layer.masksToBounds = YES;
+ [photoView setBordered:YES];
+ [addProfilePhotoImage setWantsLayer: YES];
+}
+
+- (IBAction)cancel:(id)sender
+{
+ [self.delegate close];
+}
+
+- (IBAction)addAccount:(id)sender
+{
+ NSString* displayName = [displayNameField.stringValue isEqualToString:@""] ? @"SIP" : displayNameField.stringValue;
+
+ QObject::disconnect(accountCreated);
+ accountCreated = QObject::connect(self.accountModel,
+ &lrc::api::NewAccountModel::accountAdded,
+ [self] (const std::string& accountID) {
+ if(accountID.compare(accountToCreate) != 0) {
+ return;
+ }
+ if([photoView image]) {
+ NSImage *avatarImage = [photoView image];
+ auto imageToBytes = QByteArray::fromNSData([avatarImage TIFFRepresentation]).toBase64();
+ std::string imageToString = std::string(imageToBytes.constData(), imageToBytes.length());
+ self.accountModel->setAvatar(accountID, imageToString);
+ }
+ lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(accountID);
+ if(![serverField.stringValue isEqualToString:@""]) {
+ accountProperties.hostname = [serverField.stringValue UTF8String];
+ }
+ if(![passwordField.stringValue isEqualToString:@""]) {
+ accountProperties.password = [passwordField.stringValue UTF8String];
+ }
+ if(![userNameField.stringValue isEqualToString:@""]) {
+ accountProperties.username = [userNameField.stringValue UTF8String];
+ }
+ self.accountModel->setAccountConfig(accountID, accountProperties);
+ QObject::disconnect(accountCreated);
+ [self.delegate close];
+ });
+ accountToCreate = self.accountModel->createNewAccount(lrc::api::profile::Type::SIP, [displayName UTF8String]);
+
+ timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:5
+ target:self
+ selector:@selector(addingAccountTimeout) userInfo:nil
+ repeats:NO];
+}
+
+-(void) addingAccountTimeout {
+ QObject::disconnect(accountCreated);
+ [self.delegate close];
+}
+
+
+- (IBAction)editPhoto:(id)sender
+{
+ auto pictureTaker = [IKPictureTaker pictureTaker];
+
+ [pictureTaker beginPictureTakerSheetForWindow:[self.delegate window]
+ withDelegate:self
+ didEndSelector:@selector(pictureTakerDidEnd:returnCode:contextInfo:)
+ contextInfo:nil];
+
+}
+
+- (void)pictureTakerDidEnd:(IKPictureTaker *) picker
+ returnCode:(NSInteger) code
+ contextInfo:(void*) contextInfo
+{
+ if (auto outputImage = [picker outputImage]) {
+ [photoView setBordered:NO];
+ [photoView setImage:outputImage];
+ [addProfilePhotoImage setHidden:YES];
+ } else if(!photoView.image) {
+ [photoView setBordered:YES];
+ [addProfilePhotoImage setHidden:NO];
+ }
+}
+
+@end
diff --git a/src/AppDelegate.mm b/src/AppDelegate.mm
index 3d79537..38094f3 100644
--- a/src/AppDelegate.mm
+++ b/src/AppDelegate.mm
@@ -30,6 +30,7 @@
#import <QDebug>
#import <account.h>
#import <AvailableAccountModel.h>
+#import <api/lrc.h>
#if ENABLE_SPARKLE
@@ -54,9 +55,11 @@
@end
-@implementation AppDelegate
+@implementation AppDelegate {
NSTimer* preventSleepTimer;
+std::unique_ptr<lrc::api::Lrc> lrc;
+}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
@@ -76,6 +79,7 @@
NSAppleEventManager* appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleQuitEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
+ lrc = std::make_unique<lrc::api::Lrc>();
if([self checkForRingAccount]) {
[self showMainWindow];
@@ -239,7 +243,7 @@
- (void) showWizard
{
if(self.wizard == nil) {
- self.wizard = [[RingWizardWC alloc] initWithWindowNibName:@"RingWizard"];
+ self.wizard = [[RingWizardWC alloc] initWithNibName:@"RingWizard" bundle: nil accountmodel: &lrc->getAccountModel()];
}
[self.wizard.window makeKeyAndOrderFront:self];
}
@@ -247,7 +251,7 @@
- (void) showMainWindow
{
if(self.ringWindowController == nil) {
- self.ringWindowController = [[RingWindowController alloc] initWithWindowNibName:@"RingWindow"];
+ self.ringWindowController = [[RingWindowController alloc] initWithWindowNibName:@"RingWindow" bundle: nil accountModel:&lrc->getAccountModel() dataTransferModel:&lrc->getDataTransferModel() behaviourController:&lrc->getBehaviorController()];
}
[[NSApplication sharedApplication] removeWindowsItem:self.wizard.window];
[self.ringWindowController.window makeKeyAndOrderFront:self];
diff --git a/src/ChooseAccountVC.mm b/src/ChooseAccountVC.mm
index 252605b..040c8ae 100644
--- a/src/ChooseAccountVC.mm
+++ b/src/ChooseAccountVC.mm
@@ -180,7 +180,7 @@
QByteArray ba = QByteArray::fromStdString(account.profileInfo.avatar);
- QVariant photo = GlobalInstances::pixmapManipulator().personPhoto(ba);
+ QVariant photo = GlobalInstances::pixmapManipulator().personPhoto(ba, nil);
[profileImage setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
}
@catch (NSException *ex) {
@@ -234,6 +234,7 @@
}
[self updateMenu];
[self setPopUpButtonSelection];
+ [self updatePhoto];
}
-(void) setPopUpButtonSelection {
@@ -265,6 +266,7 @@
auto& account = accMdl_->getAccountInfo(accList[row]);
[accountSelectionManager_ setSavedAccount:account];
[delegate selectAccount:account];
+ [self updatePhoto];
}
#pragma mark - NSMenuDelegate
diff --git a/src/GeneralPrefsVC.h b/src/GeneralPrefsVC.h
index 7c7bf4c..615c246 100644
--- a/src/GeneralPrefsVC.h
+++ b/src/GeneralPrefsVC.h
@@ -19,8 +19,8 @@
#import <Cocoa/Cocoa.h>
-#import "LrcModelsSProtocol.h"
+#import "LrcModelsProtocol.h"
-@interface GeneralPrefsVC : NSViewController <LrcModelsSProtocol, NSOpenSavePanelDelegate>
+@interface GeneralPrefsVC : NSViewController <LrcModelsProtocol, NSOpenSavePanelDelegate>
@end
diff --git a/src/GeneralPrefsVC.mm b/src/GeneralPrefsVC.mm
index 550ec7c..e706569 100644
--- a/src/GeneralPrefsVC.mm
+++ b/src/GeneralPrefsVC.mm
@@ -65,7 +65,7 @@
@synthesize dataTransferModel;
--(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(lrc::api::DataTransferModel*) dataTransferModel
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dataTransferModel:(lrc::api::DataTransferModel*) dataTransferModel
{
if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
diff --git a/src/LrcModelsProtocol.h b/src/LrcModelsProtocol.h
new file mode 100644
index 0000000..f75848e
--- /dev/null
+++ b/src/LrcModelsProtocol.h
@@ -0,0 +1,38 @@
+/*
+* Copyright (C) 2018 Savoir-faire Linux Inc.
+* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+namespace lrc {
+ namespace api {
+ class DataTransferModel;
+ class NewAccountModel;
+ class BehaviorController;
+ }
+}
+
+@protocol LrcModelsProtocol
+
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dataTransferModel:(const lrc::api::DataTransferModel*) dataTransferModel;
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(const lrc::api::NewAccountModel*) accountModel;
+-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(const lrc::api::NewAccountModel*)accountModel dataTransferModel:(const lrc::api::DataTransferModel*)dataTransferModel behaviourController:(const lrc::api::BehaviorController*) behaviorController;
+
+@property lrc::api::DataTransferModel* dataTransferModel;
+@property lrc::api::NewAccountModel* accountModel;
+@property lrc::api::BehaviorController* behaviorController;
+
+@end
diff --git a/src/LrcModelsSProtocol.h b/src/LrcModelsSProtocol.h
deleted file mode 100644
index 30990d6..0000000
--- a/src/LrcModelsSProtocol.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-namespace lrc {
- namespace api {
- class DataTransferModel;
- }
-}
-
-@protocol LrcModelsSProtocol
-
--(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(lrc::api::DataTransferModel*) dataTransferModel;
-
-@property lrc::api::DataTransferModel* dataTransferModel;
-
-@end
diff --git a/src/PreferencesWC.h b/src/PreferencesWC.h
index 76fe691..d73b08e 100644
--- a/src/PreferencesWC.h
+++ b/src/PreferencesWC.h
@@ -17,9 +17,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import <Cocoa/Cocoa.h>
-#import "LrcModelsSProtocol.h"
+#import "LrcModelsProtocol.h"
-@interface PreferencesWC : NSWindowController <NSWindowDelegate, LrcModelsSProtocol>
+@interface PreferencesWC : NSWindowController <NSWindowDelegate, LrcModelsProtocol>
- (void)displayGeneral:(NSToolbarItem *)sender;
- (void)displayAudio:(NSToolbarItem *)sender;
diff --git a/src/PreferencesWC.mm b/src/PreferencesWC.mm
index 424745e..6a9b340 100644
--- a/src/PreferencesWC.mm
+++ b/src/PreferencesWC.mm
@@ -39,7 +39,7 @@
NSViewController *currentVC;
}
-@synthesize dataTransferModel;
+@synthesize dataTransferModel, accountModel, behaviorController;
// Identifiers used in PreferencesWindow.xib for tabs
static auto const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier";
@@ -55,11 +55,13 @@
[self displayGeneral:nil];
}
--(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(lrc::api::DataTransferModel*) dataTransferModel
+-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*)accountModel dataTransferModel:( lrc::api::DataTransferModel*)dataTransferModel behaviourController:( lrc::api::BehaviorController*) behaviorController
{
- if (self = [self initWithWindowNibName:nibNameOrNil])
+ if (self = [self initWithWindowNibName:nibNameOrNil])
{
+ self.accountModel = accountModel;
self.dataTransferModel = dataTransferModel;
+ self.behaviorController = behaviorController;
}
return self;
}
@@ -74,7 +76,7 @@
{
[[prefsContainer subviews]
makeObjectsPerformSelector:@selector(removeFromSuperview)];
- currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil model: self.dataTransferModel];
+ currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel];
[self resizeWindowWithFrame:currentVC.view.frame];
[prefsContainer addSubview:currentVC.view];
@@ -102,7 +104,7 @@
{
[[prefsContainer subviews]
makeObjectsPerformSelector:@selector(removeFromSuperview)];
- currentVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil];
+ currentVC = [[AccountsVC alloc] initWithNibName:@"Accounts" bundle:nil accountmodel:self.accountModel];
[self resizeWindowWithFrame:currentVC.view.frame];
[prefsContainer addSubview:currentVC.view];
}
diff --git a/src/RingWindowController.h b/src/RingWindowController.h
index bbf8b48..8949c89 100644
--- a/src/RingWindowController.h
+++ b/src/RingWindowController.h
@@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import <Cocoa/Cocoa.h>
+#import "LrcModelsProtocol.h"
namespace lrc {
namespace api {
@@ -26,7 +27,7 @@
}
}
-@interface RingWindowController : NSWindowController <NSSharingServicePickerDelegate> {
+@interface RingWindowController : NSWindowController <NSSharingServicePickerDelegate, LrcModelsProtocol> {
IBOutlet NSView *currentView;
}
diff --git a/src/RingWindowController.mm b/src/RingWindowController.mm
index 61c91a2..0527f2d 100644
--- a/src/RingWindowController.mm
+++ b/src/RingWindowController.mm
@@ -73,8 +73,6 @@
__unsafe_unretained IBOutlet NSButton* shareButton;
__unsafe_unretained IBOutlet NSImageView* qrcodeView;
- std::unique_ptr<lrc::api::Lrc> lrc_;
-
PreferencesWC* preferencesWC;
IBOutlet SmartViewVC* smartViewVC;
@@ -88,6 +86,19 @@
static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItemIdentifier";
+@synthesize dataTransferModel, accountModel, behaviorController;
+
+-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*)accountModel dataTransferModel:( lrc::api::DataTransferModel*)dataTransferModel behaviourController:( lrc::api::BehaviorController*) behaviorController
+{
+ if (self = [self initWithWindowNibName:nibNameOrNil])
+ {
+ self.accountModel = accountModel;
+ self.dataTransferModel = dataTransferModel;
+ self.behaviorController = behaviorController;
+ }
+ return self;
+}
+
- (void)windowDidLoad {
[super windowDidLoad];
[self.window setMovableByWindowBackground:YES];
@@ -95,12 +106,10 @@
[self.window setBackgroundColor:[NSColor colorWithRed:242.0/255 green:242.0/255 blue:242.0/255 alpha:1.0]];
self.window.titleVisibility = NSWindowTitleHidden;
- lrc_ = std::make_unique<lrc::api::Lrc>();
-
currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil];
conversationVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil delegate:self];
// toolbar items
- chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:&(lrc_->getAccountModel()) delegate:self];
+ chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:self.accountModel delegate:self];
[callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[conversationVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
@@ -132,7 +141,7 @@
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingString:@"/"];
}
- lrc_->getDataTransferModel().downloadDirectory = std::string([path UTF8String]);
+ self.dataTransferModel->downloadDirectory = std::string([path UTF8String]);
if(appSandboxed()) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
media::RecordingModel::instance().setRecordPath(QString::fromNSString([paths objectAtIndex:0]));
@@ -141,11 +150,11 @@
- (void) connect
{
- QObject::connect(&lrc_->getBehaviorController(),
+ QObject::connect(self.behaviorController,
&lrc::api::BehaviorController::showCallView,
[self](const std::string accountId,
const lrc::api::conversation::Info convInfo){
- auto* accInfo = &lrc_->getAccountModel().getAccountInfo(accountId);
+ auto* accInfo = &self.accountModel->getAccountInfo(accountId);
if (accInfo->contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING)
[smartViewVC selectPendingList];
else
@@ -159,11 +168,11 @@
[conversationVC hideWithAnimation:false];
});
- QObject::connect(&lrc_->getBehaviorController(),
+ QObject::connect(self.behaviorController,
&lrc::api::BehaviorController::showIncomingCallView,
[self](const std::string accountId,
const lrc::api::conversation::Info convInfo){
- auto* accInfo = &lrc_->getAccountModel().getAccountInfo(accountId);
+ auto* accInfo = &self.accountModel->getAccountInfo(accountId);
if (accInfo->contactModel->getContact(convInfo.participants[0]).profileInfo.type == lrc::api::profile::Type::PENDING)
[smartViewVC selectPendingList];
else
@@ -177,11 +186,11 @@
[conversationVC hideWithAnimation:false];
});
- QObject::connect(&lrc_->getBehaviorController(),
+ QObject::connect(self.behaviorController,
&lrc::api::BehaviorController::showChatView,
[self](const std::string& accountId,
const lrc::api::conversation::Info& convInfo){
- auto& accInfo = lrc_->getAccountModel().getAccountInfo(accountId);
+ auto& accInfo = self.accountModel->getAccountInfo(accountId);
[conversationVC setConversationUid:convInfo.uid model:accInfo.conversationModel.get()];
[smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()];
[conversationVC showWithAnimation:false];
@@ -328,7 +337,8 @@
[preferencesWC.window orderFront:preferencesWC.window];
return;
}
- preferencesWC = [[PreferencesWC alloc] initWithNibName:@"PreferencesWindow" bundle: nil model:&(lrc_->getDataTransferModel())];
+
+ preferencesWC = [[PreferencesWC alloc] initWithWindowNibName: @"PreferencesWindow" bundle: nil accountModel:self.accountModel dataTransferModel:self.dataTransferModel behaviourController:self.behaviorController];
[preferencesWC.window makeKeyAndOrderFront:preferencesWC.window];
}
diff --git a/src/RingWizardChooseVC.h b/src/RingWizardChooseVC.h
index acd19f0..4e66eb9 100644
--- a/src/RingWizardChooseVC.h
+++ b/src/RingWizardChooseVC.h
@@ -25,6 +25,8 @@
WIZARD_ACTION_INVALID = -1,
WIZARD_ACTION_NEW = 0,
WIZARD_ACTION_LINK = 1,
+ WIZARD_ACTION_ADVANCED = 2,
+ WIZARD_ACTION_SIP_ACCOUNT = 3
};
@protocol RingWizardChooseDelegate <NSObject>
@@ -38,8 +40,11 @@
@property (weak, nonatomic) id <RingWizardChooseDelegate> delegate;
@property BOOL isCancelable;
+@property BOOL withAdvancedOptions;
- (void)showCancelButton:(BOOL)showCancel;
+- (void)showAdvancedButton:(BOOL)showAdvanced;
+
@end
diff --git a/src/RingWizardChooseVC.mm b/src/RingWizardChooseVC.mm
index 1658d1b..47ceee3 100644
--- a/src/RingWizardChooseVC.mm
+++ b/src/RingWizardChooseVC.mm
@@ -23,12 +23,26 @@
@end
-@implementation RingWizardChooseVC
+@implementation RingWizardChooseVC {
+
+__unsafe_unretained IBOutlet NSButton* createSIPAccount;
+
+}
@synthesize delegate;
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ [self.view setAutoresizingMask: NSViewHeightSizable];
+}
+
- (void)showCancelButton:(BOOL)showCancel{
self.isCancelable = showCancel;
+ [createSIPAccount setHidden: YES];
+}
+
+- (void)showAdvancedButton:(BOOL)showAdvanced {
+ self.withAdvancedOptions = showAdvanced;
}
- (IBAction)createRingAccount:(id)sender
@@ -52,4 +66,19 @@
}
}
+- (IBAction)showCreateSIP:(id)sender
+{
+ if ([self.delegate respondsToSelector:@selector(didCompleteWithAction:)]){
+ [delegate didCompleteWithAction:WIZARD_ACTION_ADVANCED];
+ }
+ [createSIPAccount setHidden: NO];
+}
+
+- (IBAction)addSIPAccount:(id)sender
+{
+ if ([self.delegate respondsToSelector:@selector(didCompleteWithAction:)]){
+ [delegate didCompleteWithAction:WIZARD_ACTION_SIP_ACCOUNT];
+ }
+}
+
@end
diff --git a/src/RingWizardLinkAccountVC.h b/src/RingWizardLinkAccountVC.h
index bb8151c..866c1a0 100644
--- a/src/RingWizardLinkAccountVC.h
+++ b/src/RingWizardLinkAccountVC.h
@@ -18,12 +18,14 @@
*/
#import <Cocoa/Cocoa.h>
+#import "LrcModelsProtocol.h"
@protocol RingWizardLinkDelegate <NSObject>
- (void)didLinkAccountWithSuccess:(BOOL)success;
+- (void)showView:(NSView*)view;
@end
-@interface RingWizardLinkAccountVC : NSViewController
+@interface RingWizardLinkAccountVC : NSViewController <LrcModelsProtocol>
@property (nonatomic, weak) NSWindowController <RingWizardLinkDelegate>* delegate;
@property (nonatomic, weak) NSString* pinValue;
@property (nonatomic, weak) NSString* passwordValue;
diff --git a/src/RingWizardLinkAccountVC.mm b/src/RingWizardLinkAccountVC.mm
index 07cf824..99badd7 100644
--- a/src/RingWizardLinkAccountVC.mm
+++ b/src/RingWizardLinkAccountVC.mm
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015-2016 Savoir-faire Linux Inc.
* Author: Loïc Siret <loic.siret@savoirfairelinux.com>
+ * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,15 +27,8 @@
#import <QPixmap>
//LRC
-#import <accountmodel.h>
-#import <protocolmodel.h>
-#import <profilemodel.h>
-#import <QItemSelectionModel>
-#import <account.h>
-#import <certificate.h>
-#import <profilemodel.h>
-#import <profile.h>
-#import <person.h>
+#import <api/lrc.h>
+#import <api/newaccountmodel.h>
#import "Constants.h"
#import "views/NSImage+Extensions.h"
@@ -46,7 +40,6 @@
@implementation RingWizardLinkAccountVC {
__unsafe_unretained IBOutlet NSView* initialContainer;
- __unsafe_unretained IBOutlet NSView* firstStepContainer;
__unsafe_unretained IBOutlet NSView* loadingContainer;
__unsafe_unretained IBOutlet NSProgressIndicator* progressBar;
@@ -60,76 +53,76 @@
__unsafe_unretained IBOutlet NSButton* linkButton;
NSString *fileButtonTitleBackup;
- Account* accountToCreate;
NSURL* backupFile;
- NSTimer* errorTimer;
- QMetaObject::Connection stateChanged;
+ QMetaObject::Connection accountCreated;
+ QMetaObject::Connection accountRemoved;
+ std::string accountToCreate;
}
-- (IBAction)goToStepTwo:(id)sender
-{
- [self disconnectCallback];
- [firstStepContainer setHidden:YES];
- [initialContainer setHidden:NO];
- [loadingContainer setHidden:YES];
- [errorContainer setHidden:YES];
+@synthesize accountModel;
+
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel {
+ if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
+ {
+ self.accountModel = accountModel;
+ }
+ return self;
}
-- (IBAction)goToStepOne:(id)sender
-{
- [firstStepContainer setHidden:NO];
- [initialContainer setHidden:YES];
- [loadingContainer setHidden:YES];
- [errorContainer setHidden:YES];
- [fileButton setTitle:fileButtonTitleBackup];
- backupFile = nil;
- [pinTextField setStringValue:@""];
- [pinTextField setEnabled:YES];
- [linkButton setEnabled:NO];
- [passwordTextField setStringValue:@""];
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ [self.view setAutoresizingMask: NSViewHeightSizable];
}
- (void)show
{
- [firstStepContainer setHidden:NO];
- [initialContainer setHidden:YES];
- [loadingContainer setHidden:YES];
- [errorContainer setHidden:YES];
- fileButtonTitleBackup = [fileButton title];
+ [self.delegate showView:initialContainer];
+ [fileButton setTitle:fileButtonTitleBackup];
+ backupFile = nil;
+ [pinTextField setStringValue:@""];
+ [pinTextField setEnabled:YES];
+ [linkButton setEnabled:YES];
+ [passwordTextField setStringValue:@""];
}
- (void)showError
{
- [initialContainer setHidden:YES];
- [loadingContainer setHidden:YES];
- [errorContainer setHidden:NO];
+ [self.delegate showView:errorContainer];
+ QObject::disconnect(accountCreated);
+ QObject::disconnect(accountRemoved);
}
- (void)showLoading
{
- [initialContainer setHidden:YES];
- [loadingContainer setHidden:NO];
[progressBar startAnimation:nil];
- [errorContainer setHidden:YES];
+ [self.delegate showView:loadingContainer];
}
- (IBAction)importRingAccount:(id)sender
{
+ QObject::disconnect(accountCreated);
+ QObject::disconnect(accountRemoved);
+ accountCreated = QObject::connect(self.accountModel,
+ &lrc::api::NewAccountModel::accountAdded,
+ [self] (const std::string& accountID) {
+ [self.delegate didLinkAccountWithSuccess:YES];
+ [self registerDefaultPreferences];
+ QObject::disconnect(accountCreated);
+ QObject::disconnect(accountRemoved);
+ });
+ // account that is invalid will be removed, connect the signal to show error message
+ accountRemoved = QObject::connect(self.accountModel,
+ &lrc::api::NewAccountModel::accountRemoved,
+ [self] (const std::string& accountID) {
+ if(accountID.compare(accountToCreate) == 0) {
+ [self showError];
+ }
+ });
+
[self showLoading];
- if (auto profile = ProfileModel::instance().selectedProfile()) {
- profile->person()->setFormattedName([NSFullUserName() UTF8String]);
- profile->save();
- }
- accountToCreate = AccountModel::instance().add(QString::fromNSString(NSFullUserName()), Account::Protocol::RING);
- if (backupFile == nil)
- accountToCreate->setArchivePin(QString::fromNSString(self.pinValue));
- else
- accountToCreate->setArchivePath(QString::fromLocal8Bit([backupFile fileSystemRepresentation]));
- accountToCreate->setArchivePassword(QString::fromNSString(self.passwordValue));
-
- [self setCallback];
-
- [self performSelector:@selector(saveAccount) withObject:nil afterDelay:1];
- [self registerDefaultPreferences];
+ NSString *pin = backupFile ? @"" : (self.pinValue ? self.pinValue : @"");
+ NSString *archivePath = backupFile ? [backupFile path] : @"";
+ NSString *pathword = self.passwordValue ? self.passwordValue : @"";
+ accountToCreate = self.accountModel->createNewAccount(lrc::api::profile::Type::RING, "",[archivePath UTF8String], [pathword UTF8String], [pin UTF8String]);
}
- (IBAction)dismissViewWithError:(id)sender
@@ -137,12 +130,6 @@
[self.delegate didLinkAccountWithSuccess:NO];
}
-- (IBAction)back:(id)sender
-{
- [self deleteAccount];
- [self goToStepOne:sender];
-}
-
- (IBAction)pickBackupFile:(id)sender
{
NSOpenPanel* filePicker = [NSOpenPanel openPanel];
@@ -178,64 +165,4 @@
// enable Notifications
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:Preferences::Notifications];
}
-
-- (void)saveAccount
-{
- accountToCreate->setUpnpEnabled(YES); // Always active upnp
- accountToCreate << Account::EditAction::SAVE;
-}
-
-- (void)deleteAccount
-{
- if(auto account = AccountModel::instance().getById(accountToCreate->id())) {
- AccountModel::instance().remove(accountToCreate);
- AccountModel::instance().save();
- }
-}
-
-- (void)disconnectCallback
-{
- [errorTimer invalidate];
- QObject::disconnect(stateChanged);
-}
-
-- (void)setCallback
-{
- errorTimer = [NSTimer scheduledTimerWithTimeInterval:30
- target:self
- selector:@selector(didLinkFailed) userInfo:nil
- repeats:NO];
-
- stateChanged = QObject::connect(&AccountModel::instance(),
- &AccountModel::accountStateChanged,
- [=](Account *account, const Account::RegistrationState state) {
- switch(state){
- case Account::RegistrationState::READY:
- case Account::RegistrationState::TRYING:
- case Account::RegistrationState::UNREGISTERED:{
- accountToCreate<< Account::EditAction::RELOAD;
- QObject::disconnect(stateChanged);
- [errorTimer invalidate];
- [self.delegate didLinkAccountWithSuccess:YES];
- break;
- }
- case Account::RegistrationState::ERROR:
- QObject::disconnect(stateChanged);
- [errorTimer invalidate];
- [self showError];
- break;
- case Account::RegistrationState::INITIALIZING:
- case Account::RegistrationState::COUNT__:{
- //DO Nothing
- break;
- }
- }
- });
-}
-
-- (void)didLinkFailed
-{
- [self showError];
-}
-
@end
diff --git a/src/RingWizardNewAccountVC.h b/src/RingWizardNewAccountVC.h
index b593276..0819b42 100644
--- a/src/RingWizardNewAccountVC.h
+++ b/src/RingWizardNewAccountVC.h
@@ -18,13 +18,14 @@
*/
#import <Cocoa/Cocoa.h>
+#import "LrcModelsProtocol.h"
@protocol RingWizardNewDelegate <NSObject>
- (void)didCreateAccountWithSuccess:(BOOL)success;
- (void)showView:(NSView*)view;
@end
-@interface RingWizardNewAccountVC : NSViewController
+@interface RingWizardNewAccountVC : NSViewController <LrcModelsProtocol>
@property (nonatomic, weak)NSWindowController <RingWizardNewDelegate>* delegate;
diff --git a/src/RingWizardNewAccountVC.mm b/src/RingWizardNewAccountVC.mm
index 3db5045..0c61cd4 100644
--- a/src/RingWizardNewAccountVC.mm
+++ b/src/RingWizardNewAccountVC.mm
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015-2016 Savoir-faire Linux Inc.
* Author: Loïc Siret <loic.siret@savoirfairelinux.com>
+ * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,17 +27,14 @@
//Qt
#import <QUrl>
#import <QPixmap>
+#import <QSize>
+#import <QtMacExtras/qmacfunctions.h>
//LRC
-#import <accountmodel.h>
-#import <protocolmodel.h>
-#import <profilemodel.h>
-#import <QItemSelectionModel>
+#import <api/lrc.h>
+#import <api/newaccountmodel.h>
#import <account.h>
-#import <certificate.h>
-#import <profilemodel.h>
-#import <profile.h>
-#import <person.h>
+#import <interfaces/pixmapmanipulatori.h>
#import "AppDelegate.h"
#import "Constants.h"
@@ -69,14 +67,13 @@
__unsafe_unretained IBOutlet NSPopover* helpBlockchainContainer;
__unsafe_unretained IBOutlet NSPopover* helpPasswordContainer;
- Account* accountToCreate;
- NSTimer* errorTimer;
- QMetaObject::Connection stateChanged;
- QMetaObject::Connection registrationEnded;
QMetaObject::Connection registeredNameFound;
+ QMetaObject::Connection accountCreated;
+ QMetaObject::Connection accountRemoved;
BOOL lookupQueued;
NSString* usernameWaitingForLookupResult;
+ std::string accountToCreate;
}
NSInteger const DISPLAY_NAME_TAG = 1;
@@ -86,6 +83,20 @@
NSInteger const ERROR_PASSWORD_TOO_SHORT = -1;
NSInteger const ERROR_REPEAT_MISMATCH = -2;
+@synthesize accountModel;
+
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel {
+ if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
+ {
+ self.accountModel = accountModel;
+ }
+ return self;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ [self.view setAutoresizingMask: NSViewHeightSizable];
+}
- (BOOL)produceError:(NSError**)error withCode:(NSInteger)code andMessage:(NSString*)message
{
@@ -219,35 +230,48 @@
return;
}
+ QObject::disconnect(accountCreated);
+ QObject::disconnect(accountRemoved);
+ accountCreated = QObject::connect(self.accountModel,
+ &lrc::api::NewAccountModel::accountAdded,
+ [self] (const std::string& accountID) {
+ if(accountID.compare(accountToCreate) != 0) {
+ return;
+ }
+ QObject::disconnect(accountCreated);
+ QObject::disconnect(accountRemoved);
+ //set account avatar
+ if([photoView image]) {
+ NSImage *avatarImage = [photoView image];
+ auto imageToBytes = QByteArray::fromNSData([avatarImage TIFFRepresentation]).toBase64();
+ std::string imageToString = std::string(imageToBytes.constData(), imageToBytes.length());
+ self.accountModel->setAvatar(accountID, imageToString);
+ }
+ //register username
+ if (self.registeredName && ![self.registeredName isEqualToString:@""]) {
+ NSString *passwordString = self.password ? self.password: @"";
+ NSString *usernameString = self.registeredName;
+ self.accountModel->registerName(accountID, [passwordString UTF8String], [usernameString UTF8String]);
+ }
+
+ [self registerDefaultPreferences];
+ [self.delegate didCreateAccountWithSuccess:YES];
+ });
+ //if account creation failed remove loading view
+ accountRemoved = QObject::connect(self.accountModel,
+ &lrc::api::NewAccountModel::accountRemoved,
+ [self] (const std::string& accountID) {
+ if(accountID.compare(accountToCreate) != 0) {
+ return;
+ }
+ QObject::disconnect(accountCreated);
+ QObject::disconnect(accountRemoved);
+ [self.delegate didCreateAccountWithSuccess:NO];
+ });
[self display:loadingView];
[progressBar startAnimation:nil];
- NSString* displayName = displayNameField.stringValue;
- if ([displayName isEqualToString:@""]) {
- displayName = NSLocalizedString(@"Unknown", @"Name used when user leave field empty");
- }
-
- accountToCreate = AccountModel::instance().add(QString::fromNSString(displayName), Account::Protocol::RING);
- accountToCreate->setAlias([displayName UTF8String]);
- accountToCreate->setDisplayName([displayName UTF8String]);
-
- if (auto profile = ProfileModel::instance().selectedProfile()) {
- profile->person()->setFormattedName([displayName UTF8String]);
- QPixmap p;
- auto smallImg = [NSImage imageResize:[photoView image] newSize:{100,100}];
- if (p.loadFromData(QByteArray::fromNSData([smallImg TIFFRepresentation]))) {
- profile->person()->setPhoto(QVariant(p));
- }
- profile->save();
-
- }
-
- QModelIndex qIdx = AccountModel::instance().protocolModel()->selectionModel()->currentIndex();
-
- [self setCallback];
-
- [self performSelector:@selector(saveAccount) withObject:nil afterDelay:1];
- [self registerDefaultPreferences];
+ accountToCreate = self.accountModel->createNewAccount(lrc::api::profile::Type::RING, [displayNameField.stringValue UTF8String],"",[passwordField.stringValue UTF8String]);
}
/**
@@ -268,86 +292,6 @@
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:Preferences::Notifications];
}
-- (void)saveAccount
-{
- accountToCreate->setArchivePassword(QString::fromNSString(passwordField.stringValue));
- accountToCreate->setUpnpEnabled(YES); // Always active upnp
- accountToCreate << Account::EditAction::SAVE;
-}
-
-- (void)setCallback
-{
- stateChanged = QObject::connect(&AccountModel::instance(),
- &AccountModel::accountStateChanged,
- [=](Account *account, const Account::RegistrationState state) {
- switch(state){
- case Account::RegistrationState::READY:
- case Account::RegistrationState::TRYING:
- case Account::RegistrationState::UNREGISTERED:{
- accountToCreate << Account::EditAction::RELOAD;
- QObject::disconnect(stateChanged);
- //try to register username
- if (self.signUpBlockchainState == NSOnState){
- [self startNameRegistration:account];
- } else {
- [self.delegate didCreateAccountWithSuccess:YES];
- }
- break;
- }
- case Account::RegistrationState::ERROR:
- QObject::disconnect(stateChanged);
- [self.delegate didCreateAccountWithSuccess:NO];
- break;
- case Account::RegistrationState::INITIALIZING:
- case Account::RegistrationState::COUNT__:{
- //Do Nothing
- break;
- }
- }
- });
-}
-
-- (void) startNameRegistration:(Account*) account
-{
- // Dismiss this screen if after 30 seconds the name is still not registered
- errorTimer = [NSTimer scheduledTimerWithTimeInterval:30
- target:self
- selector:@selector(nameRegistrationTimeout) userInfo:nil
- repeats:NO];
- registrationEnded = QObject::connect(account,
- &Account::nameRegistrationEnded,
- [=] (NameDirectory::RegisterNameStatus status, const QString& name) {
- QObject::disconnect(registrationEnded);
- switch(status) {
- case NameDirectory::RegisterNameStatus::WRONG_PASSWORD:
- case NameDirectory::RegisterNameStatus::ALREADY_TAKEN:
- case NameDirectory::RegisterNameStatus::NETWORK_ERROR: {
- [self couldNotRegisterUsername];
- break;
- }
- case NameDirectory::RegisterNameStatus::SUCCESS: {
- break;
- }
- }
-
- [self.delegate didCreateAccountWithSuccess:YES];
- });
- self.isUserNameAvailable = account->registerName(QString::fromNSString(self.password),
- QString::fromNSString(self.registeredName));
- if (!self.isUserNameAvailable){
- NSLog(@"Could not initialize registerName operation");
- QObject::disconnect(registrationEnded);
- [self.delegate didCreateAccountWithSuccess:YES];
- }
-}
-
-- (void)nameRegistrationTimeout
-{
- // This callback is used when registration takes more than 30 seconds
- // It skips the wizard and brings the main window
- [self.delegate didCreateAccountWithSuccess:YES];
-}
-
- (IBAction)cancel:(id)sender
{
[self.delegate didCreateAccountWithSuccess:NO];
@@ -362,11 +306,6 @@
}
}
-- (void)couldNotRegisterUsername
-{
- // Do nothing
-}
-
- (BOOL)withBlockchain
{
return self.signUpBlockchainState == NSOnState;
diff --git a/src/RingWizardWC.h b/src/RingWizardWC.h
index 62a5ec5..e962630 100644
--- a/src/RingWizardWC.h
+++ b/src/RingWizardWC.h
@@ -21,11 +21,14 @@
#import "RingWizardChooseVC.h"
#import "RingWizardNewAccountVC.h"
#import "RingWizardLinkAccountVC.h"
+#import "LrcModelsProtocol.h"
+#import "AddSIPAccountVC.h"
+
@interface RingWizardWC : NSWindowController <NSWindowDelegate, NSPathControlDelegate,
NSOpenSavePanelDelegate, RingWizardChooseDelegate, RingWizardNewDelegate,
- RingWizardLinkDelegate>
-
-- (void)showChooseWithCancelButton:(BOOL)showCancel;
+ RingWizardLinkDelegate, AddSIPAccountDelegate, LrcModelsProtocol>
+- (void)showChooseWithCancelButton:(BOOL)showCancel andAdvanced:(BOOL)showAdvanced;
- (void)showNewAccountVC;
- (void)showLinkAccountVC;
+- (void)showSIPAccountVC;
@end
diff --git a/src/RingWizardWC.mm b/src/RingWizardWC.mm
index 82243f0..e7c2109 100644
--- a/src/RingWizardWC.mm
+++ b/src/RingWizardWC.mm
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015-2016 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,12 +17,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#import "RingWizardWC.h"
//Cocoa
#import <Quartz/Quartz.h>
-
+#import "RingWizardWC.h"
#import "AppDelegate.h"
#import "Constants.h"
#import "views/NSImage+Extensions.h"
@@ -30,7 +30,6 @@
#import "RingWizardLinkAccountVC.h"
#import "RingWizardChooseVC.h"
-
@interface RingWizardWC ()
@property (retain, nonatomic)IBOutlet NSView* container;
@@ -40,26 +39,37 @@
IBOutlet RingWizardNewAccountVC* newAccountWC;
IBOutlet RingWizardLinkAccountVC* linkAccountWC;
IBOutlet RingWizardChooseVC* chooseActiontWC;
+ IBOutlet AddSIPAccountVC* addSIPAccountVC;
BOOL isCancelable;
+ BOOL withAdvanced;
}
-- (instancetype)initWithWindowNibName:(NSString *)windowNibName{
- self = [super initWithWindowNibName:windowNibName];
+@synthesize accountModel;
- chooseActiontWC = [[RingWizardChooseVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
- linkAccountWC = [[RingWizardLinkAccountVC alloc] initWithNibName:@"RingWizardLinkAccount" bundle:nil];
- newAccountWC = [[RingWizardNewAccountVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(lrc::api::NewAccountModel*) accountModel;
+{
+ if (self = [self initWithWindowNibName:nibNameOrNil])
+ {
+ self.accountModel = accountModel;
+ }
return self;
}
- (void)windowDidLoad
{
[super windowDidLoad];
+ newAccountWC = [[RingWizardNewAccountVC alloc] initWithNibName:@"RingWizardNewAccount" bundle:nil accountmodel:self.accountModel];
+
+ chooseActiontWC = [[RingWizardChooseVC alloc] initWithNibName:@"RingWizardChoose" bundle:nil];
+ linkAccountWC = [[RingWizardLinkAccountVC alloc] initWithNibName:@"RingWizardLinkAccount" bundle:nil accountmodel:self.accountModel];
+ addSIPAccountVC = [[AddSIPAccountVC alloc] initWithNibName:@"AddSIPAccountVC" bundle:nil accountmodel:self.accountModel];
+ [addSIPAccountVC setDelegate:self];
[chooseActiontWC setDelegate:self];
[linkAccountWC setDelegate:self];
[newAccountWC setDelegate:self];
[self.window setBackgroundColor:[NSColor ringGreyHighlight]];
- [self showChooseWithCancelButton:isCancelable];
+ [self showChooseWithCancelButton:isCancelable andAdvanced: withAdvanced];
+ self.window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight];
}
- (void)removeSubviews
@@ -71,13 +81,15 @@
}
#define headerHeight 60
-#define minHeight 141
-#define defaultMargin 20
+#define minHeight 150
+#define defaultMargin 5
+#define heightWithSIP 160
- (void)showView:(NSView*)view
{
[self removeSubviews];
NSRect frame = [self.container frame];
- float sizeFrame = MAX(minHeight, view.bounds.size.height);
+ CGFloat height = withAdvanced ? minHeight : minHeight - 10;
+ float sizeFrame = MAX(height, view.frame.size.height);
frame.size.height = sizeFrame;
[view setFrame:frame];
@@ -90,6 +102,28 @@
[self.container addSubview:view];
}
+- (void) updateWindowHeight: (CGFloat) height {
+ NSRect frame = [self.container frame];
+ float sizeFrame = height;
+ frame.size.height = sizeFrame;
+ [self.container setFrame:frame];
+ float size = headerHeight + sizeFrame + defaultMargin;
+ NSRect frameWindows = self.window.frame;
+ frameWindows.size.height = size;
+ [self.window setFrame:frameWindows display:YES animate:YES];
+}
+
+- (void)showChooseWithCancelButton:(BOOL)showCancel andAdvanced:(BOOL)showAdvanced {
+ [chooseActiontWC showCancelButton:showCancel];
+ [chooseActiontWC showAdvancedButton:showAdvanced];
+ isCancelable = showCancel;
+ withAdvanced = showAdvanced;
+ NSRect frame = CGRectMake(0, 0, chooseActiontWC.view.frame.size.width, 0);
+ chooseActiontWC.view.frame = frame;
+ [self showView:chooseActiontWC.view];
+
+}
+
- (void)showChooseWithCancelButton:(BOOL)showCancel
{
[chooseActiontWC showCancelButton:showCancel];
@@ -109,6 +143,12 @@
[linkAccountWC show];
}
+- (void)showSIPAccountVC
+{
+ [self showView: addSIPAccountVC.view];
+ [addSIPAccountVC show];
+}
+
# pragma NSWindowDelegate methods
- (void)windowWillClose:(NSNotification *)notification
@@ -125,15 +165,18 @@
- (void)didCompleteWithAction:(WizardAction)action
{
- if (action == WIZARD_ACTION_LINK){
+ if (action == WIZARD_ACTION_LINK) {
[self showLinkAccountVC];
- } else if (action == WIZARD_ACTION_NEW){
+ } else if (action == WIZARD_ACTION_NEW) {
[self showNewAccountVC];
+ } else if (action == WIZARD_ACTION_ADVANCED) {
+ [self updateWindowHeight: heightWithSIP];
+ } else if (action == WIZARD_ACTION_SIP_ACCOUNT) {
+ [self showSIPAccountVC];
} else {
[self.window close];
[[NSApplication sharedApplication] removeWindowsItem:self.window];
}
-
}
#pragma - WizardCreateAccountDelegate methods
@@ -148,7 +191,7 @@
[appDelegate showMainWindow];
}
} else {
- [self showChooseWithCancelButton:isCancelable];
+ [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced];
}
}
@@ -164,8 +207,15 @@
[appDelegate showMainWindow];
}
} else {
- [self showChooseWithCancelButton:isCancelable];
+ [self showChooseWithCancelButton: isCancelable andAdvanced: withAdvanced];
}
}
+#pragma - AddSIPAccountDelegate methods
+
+- (void)close {
+ [self.window close];
+ [[NSApplication sharedApplication] removeWindowsItem:self.window];
+}
+
@end