Commit bb5c2466 authored by Alexandre Lision's avatar Alexandre Lision Committed by gerrit2

ui: display ring ID on main interface

This reproduce the behavior of Gnome and Windows clients

Issue: #78363
Change-Id: I1f6e9fc216e81907c41caff61d7e8fe1b2d8e277
parent e0c7e33d
/*
* Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
* Copyright (C) 2015 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -29,6 +29,7 @@
*/
#import "RingWindowController.h"
//LRC
#import <accountmodel.h>
#import <callmodel.h>
#import <account.h>
......@@ -43,6 +44,7 @@
@property NSSearchField* callField;
@property CurrentCallVC* currentVC;
@property (unsafe_unretained) IBOutlet NSView *callView;
@property (unsafe_unretained) IBOutlet NSTextField *ringIDLabel;
@end
......@@ -50,7 +52,7 @@
@implementation RingWindowController
@synthesize callField;
@synthesize currentVC;
@synthesize callView;
@synthesize callView, ringIDLabel;
static NSString* const kSearchViewIdentifier = @"SearchViewIdentifier";
static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
......@@ -67,6 +69,42 @@ static NSString* const kCallButtonIdentifer = @"CallButtonIdentifier";
[callView addSubview:[self.currentVC view]];
[currentVC initFrame];
// Update Ring ID label based on account model changes
QObject::connect(AccountModel::instance(),
&AccountModel::dataChanged,
[=] {
[self updateRingID];
});
}
/**
* Implement the necessary logic to choose which Ring ID to display.
* This tries to choose the "best" ID to show
*/
- (void) updateRingID
{
Account* registered = nullptr;
Account* enabled = nullptr;
Account* finalChoice = nullptr;
[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;
}
} else {
if (!finalChoice)
finalChoice = acc;
}
}
[ringIDLabel setStringValue:[[NSString alloc] initWithFormat:@"Your Ring ID : %@", finalChoice->username().toNSString()]];
}
- (IBAction)openPreferences:(id)sender
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14D2134" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
</dependencies>
......@@ -8,6 +8,7 @@
<connections>
<outlet property="callView" destination="tSW-YT-asL" id="NRy-rM-XW4"/>
<outlet property="currentView" destination="se5-gp-TjO" id="Sae-7F-MB3"/>
<outlet property="ringIDLabel" destination="JN3-vO-zcd" id="dXy-NP-91h"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
......@@ -237,11 +238,25 @@
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="725" id="ccX-uq-zuj"/>
</constraints>
</customView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="JN3-vO-zcd">
<rect key="frame" x="321" y="20" width="714" height="26"/>
<constraints>
<constraint firstAttribute="height" constant="26" id="935-yR-f9b"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" sendsActionOnEndEditing="YES" alignment="center" id="qCF-Zf-vZg">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="JN3-vO-zcd" firstAttribute="leading" secondItem="tSW-YT-asL" secondAttribute="leading" id="4Vu-Lf-w9F"/>
<constraint firstItem="xXW-iq-GcP" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="20" id="6mJ-d2-JIf"/>
<constraint firstItem="bqQ-DB-Z0g" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" constant="20" id="FeC-4y-ScK"/>
<constraint firstItem="xXW-iq-GcP" firstAttribute="top" secondItem="bqQ-DB-Z0g" secondAttribute="bottom" constant="8" id="KXj-CP-Fmh"/>
<constraint firstAttribute="trailing" secondItem="JN3-vO-zcd" secondAttribute="trailing" constant="20" symbolic="YES" id="O3N-2P-8iN"/>
<constraint firstItem="JN3-vO-zcd" firstAttribute="bottom" secondItem="xXW-iq-GcP" secondAttribute="bottom" id="OoQ-1f-3Nr"/>
<constraint firstAttribute="bottom" secondItem="tSW-YT-asL" secondAttribute="bottom" id="Xa4-hd-K1t"/>
<constraint firstItem="tSW-YT-asL" firstAttribute="leading" secondItem="bqQ-DB-Z0g" secondAttribute="trailing" constant="8" id="cW1-si-AGR"/>
<constraint firstAttribute="trailing" secondItem="tSW-YT-asL" secondAttribute="trailing" id="g0F-Wt-YT6"/>
......
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