selected account: change UI when select SIP
Hide controls on MainWindow related to RING ID when user select
SIP account
Tuleap: #1532
Change-Id: I472c647545dfc7ba4a68461f2357b91cce1cadda
Reviewed-by: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
diff --git a/src/ChooseAccountVC.mm b/src/ChooseAccountVC.mm
index 422a33d..7ca77c7 100644
--- a/src/ChooseAccountVC.mm
+++ b/src/ChooseAccountVC.mm
@@ -103,7 +103,16 @@
[itemView.accountLabel setStringValue:account->alias().toNSString()];
NSString* userNameString = [self nameForAccount: account];
[itemView.userNameLabel setStringValue:userNameString];
- [itemView.accountTypeLabel setStringValue:@"Ring"];
+ switch (account->protocol()) {
+ case Account::Protocol::SIP:
+ [itemView.accountTypeLabel setStringValue:@"SIP"];
+ break;
+ case Account::Protocol::RING:
+ [itemView.accountTypeLabel setStringValue:@"RING"];
+ break;
+ default:
+ break;
+ }
auto humanState = account->toHumanStateName();
[itemView.accountStatus setStringValue:humanState.toNSString()];
[menuBarItem setView:itemView];
@@ -125,15 +134,19 @@
-(NSString*) itemTitleForAccount:(Account*) account {
NSString* alias = account->alias().toNSString();
- alias = [NSString stringWithFormat: @"%@\n", alias];
NSString* userNameString = [self nameForAccount: account];
+ if([userNameString length] > 0) {
+ alias = [NSString stringWithFormat: @"%@\n", alias];
+ }
return [alias stringByAppendingString:userNameString];
}
- (NSAttributedString*) attributedItemTitleForAccount:(Account*) account {
NSString* alias = account->alias().toNSString();
- alias = [NSString stringWithFormat: @"%@\n", alias];
NSString* userNameString = [self nameForAccount: account];
+ if([userNameString length] > 0){
+ alias = [NSString stringWithFormat: @"%@\n", alias];
+ }
NSFont *fontAlias = [NSFont userFontOfSize:14.0];
NSFont *fontUserName = [NSFont userFontOfSize:11.0];
NSColor *colorAlias = [NSColor labelColor];
diff --git a/src/RingWindowController.h b/src/RingWindowController.h
index a40129e..6e5151d 100644
--- a/src/RingWindowController.h
+++ b/src/RingWindowController.h
@@ -23,6 +23,15 @@
IBOutlet NSView *currentView;
}
+/**
+ * KVO to show or hide some UI elements in RingWindow:
+ * - Share button
+ * - QRCode
+ * - RingID field
+ * - Explanatory label
+ */
+@property (nonatomic) BOOL hideRingID;
+
- (IBAction)openPreferences:(id)sender;
@end
diff --git a/src/RingWindowController.mm b/src/RingWindowController.mm
index d2e0ec9..8ef5f40 100644
--- a/src/RingWindowController.mm
+++ b/src/RingWindowController.mm
@@ -166,8 +166,10 @@
QModelIndex index = AvailableAccountModel::instance().selectionModel()->currentIndex();
finalChoice = index.data(static_cast<int>(Account::Role::Object)).value<Account*>();
if(finalChoice == nil || (finalChoice->protocol() != Account::Protocol::RING)) {
+ self.hideRingID = YES;
return;
}
+ self.hideRingID = NO;
auto name = finalChoice->registeredName();
NSString* uriToDisplay = nullptr;
if (!name.isNull() && !name.isEmpty()) {
@@ -175,7 +177,6 @@
} else {
uriToDisplay = finalChoice->username().toNSString();
}
-
[ringIDLabel setStringValue:uriToDisplay];
[self drawQRCode:finalChoice->username().toNSString()];
}
@@ -323,6 +324,7 @@
[shareButton sendActionOn:NSLeftMouseDownMask];
[self connect];
+ [self updateRingID];
// display accounts to select
NSToolbar *toolbar = self.window.toolbar;
toolbar.delegate = self;
diff --git a/ui/Base.lproj/RingWindow.xib b/ui/Base.lproj/RingWindow.xib
index 942ee65..2850ea8 100644
--- a/ui/Base.lproj/RingWindow.xib
+++ b/ui/Base.lproj/RingWindow.xib
@@ -250,7 +250,7 @@
<rect key="frame" x="0.0" y="0.0" width="324" height="612"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="eME-fQ-3QX">
<rect key="frame" x="0.0" y="0.0" width="324" height="612"/>
- <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <autoresizingMask key="autoresizingMask"/>
<subviews>
<outlineView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="70" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="3" outlineTableColumn="pTT-gU-NVa" id="rr8-UC-gGF" customClass="RingOutlineView">
<rect key="frame" x="0.0" y="0.0" width="324" height="612"/>
@@ -641,6 +641,9 @@
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
+ <connections>
+ <binding destination="-2" name="hidden" keyPath="self.hideRingID" id="EPK-C2-VsC"/>
+ </connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="JN3-vO-zcd" userLabel="Ring ID" customClass="RingIDField">
<rect key="frame" x="20" y="64" width="400" height="26"/>
@@ -653,6 +656,9 @@
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
+ <connections>
+ <binding destination="-2" name="hidden" keyPath="self.hideRingID" id="nmu-Lf-o2m"/>
+ </connections>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="f62-JV-dgr">
<rect key="frame" x="147" y="175" width="225" height="75"/>
@@ -674,6 +680,7 @@
</buttonCell>
<connections>
<action selector="shareRingID:" target="-2" id="8bY-RW-cQS"/>
+ <binding destination="-2" name="hidden" keyPath="self.hideRingID" id="WnF-cs-9yr"/>
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="eXV-BT-B6J" customClass="IconButton">
@@ -689,6 +696,7 @@
</userDefinedRuntimeAttributes>
<connections>
<action selector="toggleQRCode:" target="-2" id="jZa-65-o5C"/>
+ <binding destination="-2" name="hidden" keyPath="self.hideRingID" id="4zb-wx-Nna"/>
</connections>
</button>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VJ1-xk-v5e">