Commit 9bebf1df authored by Anthony Léonard's avatar Anthony Léonard Committed by Kateryna Kostiuk

handle account selection change

Conversation list and right panels now react to account selection
change when triggered by the user selecting another account in top
right list.

Moreover, new method added in this patch make it possible to select
the relevant conversation in the right conversation model when a panel
display is triggered from LRC.

Change-Id: I29c1697f7d20963fe1ada1ed442706d9a5a2a801
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 2382b56e
......@@ -31,12 +31,14 @@ namespace lrc {
}
}
@class RingWindowController;
@interface ChooseAccountVC : NSViewController
@property (readonly) const lrc::api::account::Info& selectedAccount;
-(void) enable;
-(void) disable;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(const lrc::api::NewAccountModel*) accMdl;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(const lrc::api::NewAccountModel*) accMdl delegate:(RingWindowController *)mainWindow;
@end
......@@ -36,6 +36,7 @@
//RING
#import "views/AccountMenuItemView.h"
#import "AccountSelectionManager.h"
#import "RingWindowController.h"
@interface ChooseAccountVC () <NSMenuDelegate>
......@@ -47,6 +48,7 @@
__unsafe_unretained IBOutlet NSPopUpButton* accountSelectionButton;
const lrc::api::NewAccountModel* accMdl_;
AccountSelectionManager* accountSelectionManager_;
RingWindowController* delegate;
}
Boolean menuIsOpen;
......@@ -54,10 +56,11 @@ Boolean menuNeedsUpdate;
NSMenu* accountsMenu;
NSMenuItem* selectedMenuItem;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(const lrc::api::NewAccountModel*) accMdl
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil model:(const lrc::api::NewAccountModel*) accMdl delegate:(RingWindowController *)mainWindow
{
accMdl_ = accMdl;
accountSelectionManager_ = [[AccountSelectionManager alloc] initWithAccountModel:accMdl_];
delegate = mainWindow;
return [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
}
......@@ -223,6 +226,7 @@ NSMenuItem* selectedMenuItem;
auto& account = accMdl_->getAccountInfo(accList[row]);
[accountSelectionManager_ setSavedAccount:account];
[delegate selectAccount:account];
}
#pragma mark - NSMenuDelegate
......
......@@ -18,6 +18,14 @@
*/
#import <Cocoa/Cocoa.h>
namespace lrc {
namespace api {
namespace account {
struct Info;
}
}
}
@interface RingWindowController : NSWindowController <NSSharingServicePickerDelegate> {
IBOutlet NSView *currentView;
}
......@@ -33,4 +41,12 @@
- (IBAction)openPreferences:(id)sender;
/**
* This method is intended to be used by the ChooseAccountVC to signal the fact that
* the selected account has been changed by user. It will then forward this information
* to relevant controllers and views.
* @param accInfo reference to selected account
*/
- (void) selectAccount:(const lrc::api::account::Info&)accInfo;
@end
......@@ -97,7 +97,7 @@ NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIde
currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil];
offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil];
// toolbar items
chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:&(lrc_->getAccountModel())];
chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:&(lrc_->getAccountModel()) delegate:self];
contactRequestVC = [[ContactRequestVC alloc] initWithNibName:@"ContactRequest" bundle:nil];
[callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
......@@ -132,6 +132,7 @@ NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIde
[currentCallVC setCurrentCall:convInfo.callId
conversation:convInfo.uid
account:accInfo];
[smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()];
[currentCallVC animateIn];
[offlineVC animateOut];
});
......@@ -144,6 +145,7 @@ NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIde
[currentCallVC setCurrentCall:convInfo.callId
conversation:convInfo.uid
account:accInfo];
[smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()];
[currentCallVC animateIn];
[offlineVC animateOut];
});
......@@ -154,6 +156,7 @@ NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIde
const lrc::api::conversation::Info& convInfo){
auto& accInfo = lrc_->getAccountModel().getAccountInfo(accountId);
[offlineVC setConversationUid:convInfo.uid model:accInfo.conversationModel.get()];
[smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()];
[offlineVC animateIn];
[currentCallVC animateOut];
});
......@@ -346,6 +349,15 @@ NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIde
[self checkAccountsToMigrate];
}
-(void)selectAccount:(const lrc::api::account::Info&)accInfo
{
// If the selected account has been changed, we close any open panel
if ([smartViewVC setConversationModel:accInfo.conversationModel.get()]) {
[currentCallVC animateOut];
[offlineVC animateOut];
}
}
#pragma mark - NSToolbarDelegate
- (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
......
......@@ -22,6 +22,10 @@
namespace lrc {
namespace api {
class ConversationModel;
namespace conversation {
struct Info;
}
}
}
......@@ -29,8 +33,17 @@ namespace lrc {
@property (unsafe_unretained) IBOutlet NSTabView* tabbar;
@property lrc::api::ConversationModel* conversationModel;
- (BOOL)setConversationModel:(lrc::api::ConversationModel *)conversationModel;
- (void)startCallForRow:(id)sender;
/**
* This method is meant to be used by RingWindowController to set selected conversation in case
* a selection is triggered not by user but by LRC signal. If conversation is already selected, this method
* returns immediatly without changing any state.
* @param conv selected conversation
* @param model model responsible for conversation
*/
-(void)selectConversation:(const lrc::api::conversation::Info&)conv model:(lrc::api::ConversationModel*)model;
@end
......@@ -134,12 +134,14 @@ NSInteger const PRESENCE_TAG = 800;
[smartView scrollToBeginningOfDocument:nil];
}
- (void)setConversationModel:(lrc::api::ConversationModel *)conversationModel
- (BOOL)setConversationModel:(lrc::api::ConversationModel *)conversationModel
{
if (model_ != conversationModel) {
model_ = conversationModel;
selectedUid_.clear(); // Clear selected conversation as the selected account is being changed
[self reloadData];
QObject::disconnect(modelSortedConnection_);
QObject::disconnect(filterChangedConnection_);
if (model_ != nil) {
modelSortedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::modelSorted,
[self] (){
......@@ -149,6 +151,31 @@ NSInteger const PRESENCE_TAG = 800;
[self] (){
[self reloadData];
});
model_->setFilter(""); // Reset the filter
}
[searchField setStringValue:@""];
return YES;
}
return NO;
}
-(void)selectConversation:(const lrc::api::conversation::Info&)conv model:(lrc::api::ConversationModel*)model;
{
auto& uid = conv.uid;
if (selectedUid_ == uid)
return;
[self setConversationModel:model];
if (model_ != nil) {
auto it = std::find_if(model_->allFilteredConversations().begin(), model_->allFilteredConversations().end(),
[self] (const lrc::api::conversation::Info& conv) {
return selectedUid_ == conv.uid;
});
if (it != model_->allFilteredConversations().end()) {
NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())];
[smartView selectRowIndexes:indexSet byExtendingSelection:NO];
selectedUid_ = uid;
}
}
}
......
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