Commit db1f3a17 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

contact request: display requests list

In toolbar add button to display pending requests list
The list is updated depending on which account is currently selected

Tuleap: #1553
Change-Id: Ib0241dca8da2001f257bad79b96c3556a40b9d0f
Reviewed-by: default avatarAlexandre Lision <alexandre.lision@savorifairelinux.com>
parent 9d6657a2
......@@ -160,6 +160,10 @@ SET(ringclient_CONTROLLERS
src/RegisterNameWC.h
src/ChooseAccountVC.h
src/ChooseAccountVC.mm
src/ContactRequestsListVC.h
src/ContactRequestsListVC.mm
src/ContactRequestVC.h
src/ContactRequestVC.mm
)
SET(ringclient_BACKENDS
......@@ -234,6 +238,8 @@ SET(ringclient_XIBS
RegisterNameWindow
ChooseAccount
AccountMenuItemView
ContactRequestList
ContactRequest
)
# Icons
......@@ -279,7 +285,8 @@ ${CMAKE_CURRENT_SOURCE_DIR}/data/dark/general.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/video.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_delete.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/qrcode.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_video.png)
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_action_video.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/pending_contact_request.png)
SET_SOURCE_FILES_PROPERTIES(${ring_ICONS} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
......
/*
* Copyright (C) 2015-2017 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>
@interface ContactRequestVC : NSViewController
@end
/*
* Copyright (C) 2015-2017 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.
*/
// LRC
#import <availableaccountmodel.h>
#import "ContactRequestVC.h"
#import "ContactRequestsListVC.h"
@interface ContactRequestVC ()<NSPopoverDelegate> {
NSPopover* pendingContactRequestPopover;
}
@end
@implementation ContactRequestVC
- (void)awakeFromNib
{
[self.view setHidden:AvailableAccountModel::instance().rowCount() == 0];
QObject::connect(&AvailableAccountModel::instance(),
&QAbstractItemModel::rowsRemoved,
[self]{
[self.view setHidden:AvailableAccountModel::instance().rowCount() == 0];
});
QObject::connect(&AvailableAccountModel::instance(),
&QAbstractItemModel::dataChanged,
[self]{
[self.view setHidden:AvailableAccountModel::instance().rowCount() == 0];
});
}
- (IBAction)displayTrustRequests:(NSView*)sender
{
ContactRequestsListVC* contactRequestVC = [[ContactRequestsListVC alloc] initWithNibName:@"ContactRequestList" bundle:nil];
pendingContactRequestPopover = [[NSPopover alloc] init];
pendingContactRequestPopover.delegate = self;
[pendingContactRequestPopover setContentSize:contactRequestVC.view.frame.size];
[pendingContactRequestPopover setContentViewController:contactRequestVC];
[pendingContactRequestPopover setAnimates:YES];
[pendingContactRequestPopover setBehavior:NSPopoverBehaviorTransient];
[pendingContactRequestPopover setDelegate:self];
[pendingContactRequestPopover showRelativeToRect: sender.frame ofView:sender preferredEdge:NSMaxYEdge];
}
- (void)popoverDidClose:(NSNotification *)notification {
// when popover is closed remove ContactRequestsListVC to let it be allocated
[pendingContactRequestPopover setContentViewController:nil];
}
@end
/*
* Copyright (C) 2015-2017 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>
@interface ContactRequestsListVC : NSViewController
@end
/*
* Copyright (C) 2015-2017 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.
*/
//Qt
#import <QItemSelectionModel>
//LRC
#import <account.h>
#import <availableAccountModel.h>
#import <contactRequest.h>
#import <pendingContactRequestModel.h>
#import "ContactRequestsListVC.h"
#import "QNSTreeController.h"
@interface ContactRequestsListVC ()
@property QNSTreeController* requestsTreeController;
@property (unsafe_unretained) IBOutlet NSOutlineView* contactRequestView;
@property (unsafe_unretained) IBOutlet NSTextField* noRequestsLabel;
@end
@implementation ContactRequestsListVC
@synthesize requestsTreeController;
@synthesize contactRequestView;
@synthesize noRequestsLabel;
typedef NS_ENUM(NSInteger, ContactAction) {
ACCEPT = 0,
REFUSE,
BLOCK,
};
NSInteger const TAG_NAME = 100;
NSInteger const TAG_RINGID = 200;
- (void)awakeFromNib
{
Account* chosenAccount = [self chosenAccount];
requestsTreeController = [[QNSTreeController alloc] initWithQModel:chosenAccount->pendingContactRequestModel()];
[requestsTreeController setAvoidsEmptySelection:NO];
[requestsTreeController setAlwaysUsesMultipleValuesMarker:YES];
[requestsTreeController setChildrenKeyPath:@"children"];
[contactRequestView bind:@"content" toObject:requestsTreeController withKeyPath:@"arrangedObjects" options:nil];
[contactRequestView bind:@"sortDescriptors" toObject:requestsTreeController withKeyPath:@"sortDescriptors" options:nil];
[contactRequestView bind:@"selectionIndexPaths" toObject:requestsTreeController withKeyPath:@"selectionIndexPaths" options:nil];
[noRequestsLabel setHidden:[contactRequestView numberOfRows]>0];
}
- (IBAction)acceptContactRequest:(NSView*)sender
{
NSInteger row = [self.contactRequestView rowForView:sender];
[self performAction:ACCEPT forRequestAtRow:row];
}
- (IBAction)refuseContactRequest:(NSView*)sender
{
NSInteger row = [self.contactRequestView rowForView:sender];
[self performAction:REFUSE forRequestAtRow:row];
}
- (IBAction)blockContactRequest:(NSView*)sender
{
NSInteger row = [self.contactRequestView rowForView:sender];
[self performAction:BLOCK forRequestAtRow:row];
}
-(void) performAction:(ContactAction)action forRequestAtRow:(NSInteger)row {
id item = [self.contactRequestView itemAtRow:row];
QModelIndex qIdx = [self.requestsTreeController toQIdx:((NSTreeNode*)item)];
Account* chosenAccount = AccountModel::instance().userChosenAccount();
const auto& var = qIdx.data(static_cast<int>(Ring::Role::Object));
if (!var.isValid()) {
return;
}
auto contactRequest = qvariant_cast<ContactRequest*>(var);
switch (action) {
case ACCEPT:
contactRequest->accept();
break;
case REFUSE:
contactRequest->discard();
break;
case BLOCK:
contactRequest->block();
break;
default:
break;
}
[noRequestsLabel setHidden:[contactRequestView numberOfRows]>0];
}
#pragma mark - NSOutlineViewDelegate methods
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
return NO;
}
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
NSTableView* result = [outlineView makeViewWithIdentifier:@"ContactRequestView" owner:self];
QModelIndex qIdx = [self.requestsTreeController toQIdx:((NSTreeNode*)item)];
if(!qIdx.isValid()) {
return result;
}
Account* chosenAccount = [self chosenAccount];
NSTextField* nameLabel = [result viewWithTag:TAG_NAME];
NSTextField* ringIDLabel = [result viewWithTag:TAG_RINGID];
NSString* ringID = chosenAccount->pendingContactRequestModel()->data(qIdx,Qt::DisplayRole).toString().toNSString();
[nameLabel setStringValue:ringID];
[ringIDLabel setStringValue:ringID];
return result;
}
-(Account* ) chosenAccount
{
QModelIndex index = AvailableAccountModel::instance().selectionModel()->currentIndex();
return index.data(static_cast<int>(Account::Role::Object)).value<Account*>();
}
@end
......@@ -45,6 +45,7 @@
#import "views/NSColor+RingTheme.h"
#import "views/BackgroundView.h"
#import "ChooseAccountVC.h"
#import "ContactRequestVC.h"
@interface RingWindowController () <MigrateRingAccountsDelegate, NSToolbarDelegate>
......@@ -67,12 +68,14 @@
CurrentCallVC* currentCallVC;
ConversationVC* offlineVC;
// toolbar menu items
ChooseAccountVC* chooseAccountVC;
ContactRequestVC* contactRequestVC;
}
static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItemIdentifier";
static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItemIdentifier";
NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIdentifier";
- (void)windowDidLoad {
[super windowDidLoad];
......@@ -83,7 +86,9 @@ NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItem
currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil];
offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil];
// toolbar items
chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil];
contactRequestVC = [[ContactRequestVC alloc] initWithNibName:@"ContactRequest" bundle:nil];
[callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[currentCallVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[offlineVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
......@@ -322,6 +327,7 @@ NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItem
NSToolbar *toolbar = self.window.toolbar;
toolbar.delegate = self;
[toolbar insertItemWithItemIdentifier:kChangeAccountToolBarItemIdentifier atIndex:1];
[toolbar insertItemWithItemIdentifier:kTrustRequestMenuItemIdentifier atIndex:2];
}
}
......@@ -336,14 +342,19 @@ NSString* const kChangeAccountToolBarItemIdentifier = @"ChangeAccountToolBarItem
}
#pragma mark - NSToolbarDelegate
- (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag{
if(!(itemIdentifier == kChangeAccountToolBarItemIdentifier)) {
return nil;
- (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
if(itemIdentifier == kChangeAccountToolBarItemIdentifier) {
NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kChangeAccountToolBarItemIdentifier];
toolbarItem.view = chooseAccountVC.view;
return toolbarItem;
}
if(itemIdentifier == kTrustRequestMenuItemIdentifier) {
NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kTrustRequestMenuItemIdentifier];
toolbarItem.view = contactRequestVC.view;
return toolbarItem;
}
NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:kChangeAccountToolBarItemIdentifier];
CGRect frame = chooseAccountVC.view.frame;
toolbarItem.view = chooseAccountVC.view;
return toolbarItem;
return nil;
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D30a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<development version="7000" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<capability name="box content view" minToolsVersion="7.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ContactRequestVC">
<connections>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="30" height="30"/>
<subviews>
<box boxType="custom" borderType="none" translatesAutoresizingMaskIntoConstraints="NO" id="NHa-9l-NZV">
<rect key="frame" x="0.0" y="0.0" width="30" height="30"/>
<view key="contentView" id="OAa-jh-6SU">
<rect key="frame" x="0.0" y="0.0" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button toolTip="Contact Request" horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="WAQ-vX-IeC" customClass="IconButton">
<rect key="frame" x="0.0" y="0.0" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="MQQ-4M-yMd"/>
<constraint firstAttribute="height" constant="30" id="tDS-ze-T5K"/>
</constraints>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="pending_contact_request" imagePosition="overlaps" alignment="center" transparent="YES" imageScaling="proportionallyDown" id="A6C-kV-bIT">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="imageInsets">
<integer key="value" value="6"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="displayTrustRequests:" target="-2" id="1w7-RM-guW"/>
</connections>
</button>
</subviews>
</view>
<constraints>
<constraint firstAttribute="height" constant="30" id="EbY-83-hwO"/>
<constraint firstItem="WAQ-vX-IeC" firstAttribute="leading" secondItem="NHa-9l-NZV" secondAttribute="leading" id="jfo-1y-hcK"/>
<constraint firstAttribute="width" constant="30" id="n5A-s7-tQB"/>
<constraint firstItem="WAQ-vX-IeC" firstAttribute="top" secondItem="NHa-9l-NZV" secondAttribute="top" id="pOE-ry-D5Z"/>
</constraints>
</box>
</subviews>
<constraints>
<constraint firstItem="NHa-9l-NZV" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="1EN-Bz-FzB"/>
<constraint firstItem="NHa-9l-NZV" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="9qA-vg-9C7"/>
<constraint firstAttribute="trailing" secondItem="NHa-9l-NZV" secondAttribute="trailing" id="OqG-aX-O5u"/>
<constraint firstAttribute="bottom" secondItem="NHa-9l-NZV" secondAttribute="bottom" id="RKy-qQ-ZIg"/>
</constraints>
</customView>
<userDefaultsController representsSharedInstance="YES" id="7fN-pd-fr0"/>
</objects>
<resources>
<image name="pending_contact_request" width="48" height="48"/>
</resources>
</document>
This diff is collapsed.
......@@ -378,17 +378,17 @@
</tabViewItem>
<tabViewItem label="Contacts" identifier="" id="Zbi-X6-DLT" userLabel="Persons">
<view key="view" id="sag-tS-7Jw">
<rect key="frame" x="0.0" y="0.0" width="324" height="552"/>
<rect key="frame" x="0.0" y="0.0" width="324" height="612"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView focusRingType="none" borderType="none" autohidesScrollers="YES" horizontalLineScroll="72" horizontalPageScroll="10" verticalLineScroll="72" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" translatesAutoresizingMaskIntoConstraints="NO" id="rJv-ju-DFe">
<rect key="frame" x="0.0" y="0.0" width="324" height="552"/>
<rect key="frame" x="0.0" y="0.0" width="324" height="612"/>
<clipView key="contentView" focusRingType="none" drawsBackground="NO" copiesOnScroll="NO" id="S00-xr-jYM">
<rect key="frame" x="0.0" y="0.0" width="324" height="552"/>
<rect key="frame" x="0.0" y="0.0" width="324" height="612"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<outlineView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="70" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="10" outlineTableColumn="8Ve-L0-o7V" id="Hrg-Fe-uGq" customClass="RingOutlineView">
<rect key="frame" x="0.0" y="0.0" width="324" height="552"/>
<rect key="frame" x="0.0" y="0.0" width="324" height="612"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" white="1" alpha="0.0" colorSpace="deviceWhite"/>
......@@ -753,6 +753,8 @@
<toolbar key="toolbar" implicitIdentifier="DAC02128-D11F-490C-B61E-D9ECEB1294A5" autosavesConfiguration="NO" showsBaselineSeparator="NO" displayMode="iconOnly" sizeMode="regular" id="bUe-5b-kMc">
<allowedToolbarItems>
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="3XV-3Z-Voi"/>
<toolbarItem implicitItemIdentifier="9154E5A0-E0C8-40FF-8F66-3BB3741EA1D2" label="Toolbar Item" paletteLabel="Toolbar Item" tag="-1" image="symbol_blue" id="XSp-w5-Fes"/>
<toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="Wlp-6j-TKD"/>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="3XV-3Z-Voi"/>
......@@ -792,6 +794,7 @@
<image name="ic_action_cancel" width="72" height="72"/>
<image name="ic_action_video" width="72" height="72"/>
<image name="qrcode" width="72" height="72"/>
<image name="symbol_blue" width="161.6842041015625" height="161.6842041015625"/>
<image name="symbol_name" width="573" height="191"/>
</resources>
</document>
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