Commit 313427fe authored by Alexandre Lision's avatar Alexandre Lision Committed by Alexandre Lision

welcome view: display username if available

Instead of displaying the ringID we display the registered name if
available

Change-Id: I070c9edd6bdf2f7aa97d6c7ad1042a9c962db711
Tuleap: #1342
parent 05ca83cd
......@@ -229,6 +229,8 @@ NSInteger const BLOCKCHAIN_NAME_TAG = 2;
break;
case NameDirectory::RegisterNameStatus::SUCCESS:
[self.delegate didRegisterNameWithSuccess];
// Artificial refresh of the model to update the welcome view
Q_EMIT AccountModel::instance().dataChanged(QModelIndex(), QModelIndex());
break;
}
});
......
......@@ -150,20 +150,30 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
[ringIDLabel setStringValue:@""];
auto ringList = AccountModel::instance().getAccountsByProtocol(Account::Protocol::RING);
for (int i = 0 ; i < ringList.size() && !registered ; ++i) {
Account* acc = ringList.value(i);
if (acc->isEnabled()) {
if(!enabled)
enabled = finalChoice = acc;
if (acc->registrationState() == Account::RegistrationState::READY) {
registered = enabled = finalChoice = acc;
auto account = ringList.value(i);
if (account->isEnabled()) {
if(!enabled) {
enabled = finalChoice = account;
}
if (account->registrationState() == Account::RegistrationState::READY) {
registered = enabled = finalChoice = account;
}
} else {
if (!finalChoice)
finalChoice = acc;
if (!finalChoice) {
finalChoice = account;
}
}
}
auto name = finalChoice->registeredName();
if (!name.isNull() && !name.isEmpty()) {
[ringIDLabel setStringValue:[[NSString alloc] initWithFormat:@"%@", name.toNSString()]];
} else {
[ringIDLabel setStringValue:[[NSString alloc] initWithFormat:@"%@", finalChoice->username().toNSString()]];
}
[ringIDLabel setStringValue:[[NSString alloc] initWithFormat:@"%@", finalChoice->username().toNSString()]];
if (qrcodeView.alphaValue == 1) {
[self drawQRCode];
}
}
- (IBAction)shareRingID:(id)sender {
......@@ -183,6 +193,16 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
return;
}
[self drawQRCode];
[self showQRCode:YES];
}
/**
* Draw the QRCode in the qrCodeView
*/
- (void)drawQRCode
{
auto qrCode = QRcode_encodeString(ringIDLabel.stringValue.UTF8String,
0,
QR_ECLEVEL_L, // Lowest level of error correction
......@@ -192,6 +212,12 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
return;
}
unsigned char *data = 0;
int width;
data = qrCode->data;
width = qrCode->width;
int qr_margin = 3;
CGFloat size = qrcodeView.frame.size.width;
// create context
......@@ -202,35 +228,7 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(1, -1);
CGContextConcatCTM(ctx, CGAffineTransformConcat(translateTransform, scaleTransform));
// draw QR on this context
[self drawQRCode:qrCode context:ctx size:size];
// get image
auto qrCGImage = CGBitmapContextCreateImage(ctx);
auto qrImage = [[NSImage alloc] initWithCGImage:qrCGImage size:qrcodeView.frame.size];
// some releases
CGContextRelease(ctx);
CGImageRelease(qrCGImage);
CGColorSpaceRelease(colorSpace);
QRcode_free(qrCode);
[qrcodeView setImage:qrImage];
[self showQRCode:YES];
}
/**
* @param code the previously generated QRCode
* @param ctx current drawing context
* @param size the output size in which to draw
*/
- (void)drawQRCode:(QRcode *)code context:(CGContextRef)ctx size:(CGFloat)size {
unsigned char *data = 0;
int width;
data = code->data;
width = code->width;
int qr_margin = 3;
float zoom = ceil((double)size / (code->width + 2.0 * qr_margin));
float zoom = ceil((double)size / (qrCode->width + 2.0 * qr_margin));
CGRect rectDraw = CGRectMake(0, 0, zoom, zoom);
int ran;
......@@ -250,6 +248,18 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
++data;
}
}
// get image
auto qrCGImage = CGBitmapContextCreateImage(ctx);
auto qrImage = [[NSImage alloc] initWithCGImage:qrCGImage size:qrcodeView.frame.size];
// some releases
CGContextRelease(ctx);
CGImageRelease(qrCGImage);
CGColorSpaceRelease(colorSpace);
QRcode_free(qrCode);
[qrcodeView setImage:qrImage];
}
/**
......
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16B2553a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<development version="7000" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
</dependencies>
<objects>
......@@ -599,6 +600,11 @@
<constraint firstAttribute="height" constant="200" id="tSn-OT-Zn8"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="mYG-HR-6oh"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="alphaValue">
<integer key="value" value="0"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</imageView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="D6e-KX-8gC">
<rect key="frame" x="103" y="194" width="520" height="270"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment