Commit 32956532 authored by Aline Gondim Santos's avatar Aline Gondim Santos Committed by Kateryna Kostiuk

plugins: add settings view

GitLab: #280
Change-Id: I767b89a2a30090ba78fa2eb08ede5440835a3509
parent 91aa17b0
......@@ -137,6 +137,8 @@ SET(ringclient_CONTROLLERS
src/AudioPrefsVC.h
src/VideoPrefsVC.mm
src/VideoPrefsVC.h
src/PluginPrefsVC.mm
src/PluginPrefsVC.h
src/GeneralPrefsVC.h
src/ChatVC.mm
src/ChatVC.h
......@@ -280,6 +282,7 @@ SET(ringclient_XIBS
AccAdvancedRing
AudioPrefs
VideoPrefs
PluginPrefs
PreferencesWindow
RingWizard
CertificateWindow
......@@ -363,6 +366,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_record_stop.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_camera.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_audio_msg.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_group.png
${CMAKE_CURRENT_SOURCE_DIR}/data/dark/ic_plugin.png
${CMAKE_CURRENT_SOURCE_DIR}/data/light/ic_picture.png
${CMAKE_CURRENT_SOURCE_DIR}/data/light/ic_moderator.png
${CMAKE_CURRENT_SOURCE_DIR}/data/light/ic_moderator_audio_muted.png
......
......@@ -359,7 +359,7 @@ static void ReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNet
- (void) showMainWindow
{
if(self.ringWindowController == nil) {
self.ringWindowController = [[RingWindowController alloc] initWithWindowNibName:@"RingWindow" bundle: nil accountModel:&lrc->getAccountModel() dataTransferModel:&lrc->getDataTransferModel() behaviourController:&lrc->getBehaviorController() avModel: &lrc->getAVModel()];
self.ringWindowController = [[RingWindowController alloc] initWithWindowNibName:@"RingWindow" bundle: nil accountModel:&lrc->getAccountModel() dataTransferModel:&lrc->getDataTransferModel() behaviourController:&lrc->getBehaviorController() avModel: &lrc->getAVModel() pluginModel: &lrc->getPluginModel()];
}
[[NSApplication sharedApplication] removeWindowsItem:self.wizard.window];
self.wizard = nil;
......
......@@ -23,6 +23,7 @@ namespace lrc {
class NewAccountModel;
class BehaviorController;
class AVModel;
class PluginModel;
}
}
......@@ -30,14 +31,17 @@ namespace lrc {
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dataTransferModel:(const lrc::api::DataTransferModel*) dataTransferModel;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dataTransferModel:(const lrc::api::DataTransferModel*) dataTransferModel avModel:(const lrc::api::AVModel*) avModel;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil pluginModel:(const lrc::api::PluginModel*) pluginModel;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil avModel:(const lrc::api::AVModel*) avModel;
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(const lrc::api::NewAccountModel*) accountModel;
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(const lrc::api::NewAccountModel*)accountModel dataTransferModel:(const lrc::api::DataTransferModel*)dataTransferModel behaviourController:(const lrc::api::BehaviorController*) behaviorController;
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(const lrc::api::NewAccountModel*)accountModel dataTransferModel:(const lrc::api::DataTransferModel*)dataTransferModel behaviourController:(const lrc::api::BehaviorController*) behaviorController avModel: (const lrc::api::AVModel*)avModel;
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(const lrc::api::NewAccountModel*)accountModel dataTransferModel:(const lrc::api::DataTransferModel*)dataTransferModel behaviourController:(const lrc::api::BehaviorController*) behaviorController avModel: (const lrc::api::AVModel*)avModel pluginModel: (const lrc::api::PluginModel*)pluginModel;
@property lrc::api::DataTransferModel* dataTransferModel;
@property lrc::api::NewAccountModel* accountModel;
@property lrc::api::BehaviorController* behaviorController;
@property lrc::api::AVModel* avModel;
@property lrc::api::PluginModel* pluginModel;
@end
/*
* Copyright (C) 2021 Savoir-faire Linux Inc.
* Author: Aline Gondim Santos <aline.gondimsantos@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>
#import "LrcModelsProtocol.h"
@interface PluginPrefsVC : NSViewController <LrcModelsProtocol, NSTableViewDataSource, NSTableViewDelegate> {
}
@end
/*
* Copyright (C) 2021 Savoir-faire Linux Inc.
* Author: Aline Gondim Santos <aline.gondimsantos@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 "PluginPrefsVC.h"
#import "AppDelegate.h"
#import <api/pluginmodel.h>
@interface PluginPrefsVC ()
@property (assign) IBOutlet NSButton *enablePluginsButton;
@property (unsafe_unretained) IBOutlet NSTableView *installedPluginsView;
@end
@implementation PluginPrefsVC
@synthesize pluginModel;
@synthesize installedPluginsView;
NS_ENUM(NSInteger, tablesViews1) {
PLUGIN_NAME_TAG = 1,
PLUGIN_LOADED_TAG,
PLUGIN_UNINSTALL_TAG,
PLUGIN_ICON_TAG
};
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil pluginModel:(lrc::api::PluginModel*) pluginModel
{
if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.pluginModel = pluginModel;
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
self.installedPluginsView.delegate = self;
self.installedPluginsView.dataSource = self;
}
- (void)update {
[self.enablePluginsButton setState: self.pluginModel->getPluginsEnabled()];
[self.installedPluginsView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self update];
}
#pragma mark - actions
- (IBAction)toggleEnablePluginsButton:(NSButton *)sender {
bool enabled = [sender state]==NSOnState;
self.pluginModel->setPluginsEnabled(enabled);
[self update];
}
- (IBAction)installPlugin:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:NO];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
if ([panel runModal] != NSFileHandlingPanelOKButton) return;
if ([[panel URLs] lastObject] == nil) return;
NSString * path = [[[panel URLs] lastObject] path];
bool status = self.pluginModel->installPlugin(QString::fromNSString(path), true);
[self update];
}
- (IBAction)loadPlugin:(id)sender
{
NSInteger row = [installedPluginsView rowForView:sender];
if(row < 0) {
return;
}
auto installedPlugins = self.pluginModel->getInstalledPlugins();
if ((installedPlugins.size()-1) < row) {
return;
}
auto plugin = installedPlugins[row];
auto details = self.pluginModel->getPluginDetails(plugin);
if (details.loaded) {
self.pluginModel->unloadPlugin(plugin);
} else
self.pluginModel->loadPlugin(plugin);
[self update];
}
- (IBAction)uninstallPlugin:(id)sender
{
NSInteger row = [installedPluginsView rowForView:sender];
if(row < 0) {
return;
}
auto installedPlugins = self.pluginModel->getInstalledPlugins();
if ((installedPlugins.size()-1) < row) {
return;
}
auto plugin = installedPlugins[row];
self.pluginModel->uninstallPlugin(plugin);
[self update];
}
#pragma mark - signals
#pragma mark - dispaly
#pragma mark - NSOpenSavePanelDelegate delegate methods
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSTableCellView* installedPluginCell = [tableView makeViewWithIdentifier:@"TableCellInstalledPluginItem" owner:self];
NSTextField* pluginNameLabel = [installedPluginCell viewWithTag: PLUGIN_NAME_TAG];
NSButton* pluginLoadButton = [installedPluginCell viewWithTag: PLUGIN_LOADED_TAG];
NSButton* pluginUninstallButton = [installedPluginCell viewWithTag: PLUGIN_UNINSTALL_TAG];
NSImageView* pluginIcon = [installedPluginCell viewWithTag: PLUGIN_ICON_TAG];
auto installedPlugins = self.pluginModel->getInstalledPlugins();
if ((installedPlugins.size() - 1) < row) {
return nil;
}
auto plugin = installedPlugins[row];
auto details = self.pluginModel->getPluginDetails(plugin);
if (details.iconPath.endsWith(".svg")) {
details.iconPath.replace(".svg", ".png");
}
NSString* pathIcon = details.iconPath.toNSString();
NSImage *image = [[NSImage alloc] initWithContentsOfFile:pathIcon];
[pluginIcon setImage: image];
[pluginNameLabel setStringValue: details.name.toNSString()];
[pluginLoadButton setState: details.loaded];
[pluginLoadButton setAction:@selector(loadPlugin:)];
[pluginLoadButton setTarget:self];
[pluginUninstallButton setAction:@selector(uninstallPlugin:)];
[pluginUninstallButton setTarget:self];
return installedPluginCell;
}
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
{
if(![tableView isEnabled]) {
return nil;
}
return [tableView makeViewWithIdentifier:@"HoverRowView" owner:nil];
}
#pragma mark - NSTableViewDataSource methods
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return self.pluginModel->getInstalledPlugins().size();
}
@end
......@@ -25,5 +25,6 @@
- (void)displayAudio:(NSToolbarItem *)sender;
- (void)displayVideo:(NSToolbarItem *)sender;
- (void)displayAccounts:(NSToolbarItem *)sender;
- (void)displayPlugins:(NSToolbarItem *)sender;
@end
......@@ -25,6 +25,7 @@
#import "GeneralPrefsVC.h"
#import "AudioPrefsVC.h"
#import "VideoPrefsVC.h"
#import "PluginPrefsVC.h"
#import "views/NSColor+RingTheme.h"
@implementation PreferencesWC {
......@@ -33,12 +34,13 @@
NSViewController *currentVC;
}
@synthesize dataTransferModel, accountModel, behaviorController, avModel;
@synthesize dataTransferModel, accountModel, behaviorController, avModel, pluginModel;
// Identifiers used in PreferencesWindow.xib for tabs
static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
static auto const kPluginPrefsIdentifer = @"PluginPrefsIdentifer";
- (void)windowDidLoad
{
......@@ -55,7 +57,7 @@ static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
[tb setAllowsUserCustomization:NO];
}
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(lrc::api::NewAccountModel*)accountModel dataTransferModel:(lrc::api::DataTransferModel*)dataTransferModel behaviourController:(lrc::api::BehaviorController*) behaviorController avModel: (lrc::api::AVModel*)avModel
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(lrc::api::NewAccountModel*)accountModel dataTransferModel:(lrc::api::DataTransferModel*)dataTransferModel behaviourController:(lrc::api::BehaviorController*)behaviorController avModel: (lrc::api::AVModel*)avModel pluginModel: (lrc::api::PluginModel*)pluginModel
{
if (self = [self initWithWindowNibName:nibNameOrNil])
{
......@@ -63,6 +65,7 @@ static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
self.dataTransferModel = dataTransferModel;
self.behaviorController = behaviorController;
self.avModel = avModel;
self.pluginModel = pluginModel;
}
return self;
}
......@@ -91,6 +94,14 @@ static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
[self addCurrentVC];
}
- (IBAction)displayPlugins:(NSToolbarItem *)sender
{
[[prefsContainer subviews]
makeObjectsPerformSelector:@selector(removeFromSuperview)];
currentVC = [[PluginPrefsVC alloc] initWithNibName:@"PluginPrefs" bundle:nil pluginModel: self.pluginModel];
[self addCurrentVC];
}
-(void) addCurrentVC {
[self resizeWindowWithFrame:currentVC.view.frame];
[prefsContainer addSubview:currentVC.view];
......
......@@ -31,6 +31,7 @@
#import <api/contact.h>
#import <api/datatransfermodel.h>
#import <api/avmodel.h>
#import <api/pluginmodel.h>
// Ring
#import "AppDelegate.h"
......@@ -86,10 +87,10 @@ typedef NS_ENUM(NSInteger, ViewState) {
IBOutlet ChooseAccountVC* chooseAccountVC;
}
@synthesize dataTransferModel, accountModel, behaviorController, avModel;
@synthesize dataTransferModel, accountModel, behaviorController, avModel, pluginModel;
@synthesize wizard;
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*)accountModel dataTransferModel:( lrc::api::DataTransferModel*)dataTransferModel behaviourController:( lrc::api::BehaviorController*) behaviorController avModel: (lrc::api::AVModel*)avModel
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:( lrc::api::NewAccountModel*)accountModel dataTransferModel:( lrc::api::DataTransferModel*)dataTransferModel behaviourController:( lrc::api::BehaviorController*) behaviorController avModel: (lrc::api::AVModel*)avModel pluginModel: (lrc::api::PluginModel*)pluginModel
{
if (self = [self initWithWindowNibName:nibNameOrNil])
{
......@@ -97,6 +98,7 @@ typedef NS_ENUM(NSInteger, ViewState) {
self.dataTransferModel = dataTransferModel;
self.behaviorController = behaviorController;
self.avModel = avModel;
self.pluginModel = pluginModel;
self.avModel->useAVFrame(YES);
[NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
}
......@@ -564,7 +566,7 @@ typedef NS_ENUM(NSInteger, ViewState) {
return;
}
preferencesWC = [[PreferencesWC alloc] initWithWindowNibName: @"PreferencesWindow" bundle: nil accountModel:self.accountModel dataTransferModel:self.dataTransferModel behaviourController:self.behaviorController avModel: self.avModel];
preferencesWC = [[PreferencesWC alloc] initWithWindowNibName: @"PreferencesWindow" bundle: nil accountModel:self.accountModel dataTransferModel:self.dataTransferModel behaviourController:self.behaviorController avModel: self.avModel pluginModel: self.pluginModel];
[preferencesWC.window makeKeyAndOrderFront:preferencesWC.window];
}
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
......@@ -16,7 +16,7 @@
<window title="Jami Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" animationBehavior="default" id="C1T-wE-wxb">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<rect key="contentRect" x="469" y="334" width="653" height="383"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
<view key="contentView" id="33Y-I6-Ofh">
<rect key="frame" x="0.0" y="0.0" width="653" height="383"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
......@@ -39,27 +39,44 @@
<toolbarItem implicitItemIdentifier="NSToolbarPrintItem" id="KmD-NW-2Sc"/>
<toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="6aq-4y-T31"/>
<toolbarItem implicitItemIdentifier="A53BED01-97D4-496F-9806-EB216CF9D2D9" explicitItemIdentifier="VideoPrefsIdentifer" label="Video" paletteLabel="Video" tag="-1" image="video" selectable="YES" id="jLi-an-TR2">
<size key="minSize" width="22" height="22"/>
<size key="maxSize" width="22" height="22"/>
<connections>
<action selector="displayVideo:" target="-2" id="UAi-6C-AQw"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="E53EE3E8-C5D3-49F8-A231-B8FC691E37CE" explicitItemIdentifier="AudioPrefsIdentifer" label="Audio" paletteLabel="Audio" tag="-1" image="audio" selectable="YES" id="iuJ-eu-b7f">
<size key="minSize" width="22" height="22"/>
<size key="maxSize" width="22" height="22"/>
<connections>
<action selector="displayAudio:" target="-2" id="bbf-3M-NFB"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="EE8B14A6-94EE-47DC-8E40-437D3207D41B" explicitItemIdentifier="GeneralPrefsIdentifier" label="General" paletteLabel="General" tag="-1" image="general" selectable="YES" id="GQi-nL-0Ey">
<size key="minSize" width="22" height="22"/>
<size key="maxSize" width="22" height="22"/>
<connections>
<action selector="displayGeneral:" target="-2" id="mCA-4c-06H"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="627205FE-1164-4992-8C29-54EB6409DF24" label="Advanced" paletteLabel="Advanced" tag="-1" image="NSAdvanced" id="Qza-fj-d45"/>
<toolbarItem implicitItemIdentifier="627205FE-1164-4992-8C29-54EB6409DF24" label="Advanced" paletteLabel="Advanced" tag="-1" image="NSAdvanced" id="Qza-fj-d45">
<size key="minSize" width="22" height="22"/>
<size key="maxSize" width="22" height="22"/>
</toolbarItem>
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="aIF-RX-dpX"/>
<toolbarItem implicitItemIdentifier="8FE54A8C-2FC0-42B8-B234-011662AD0A28" explicitItemIdentifier="PluginPrefsIdentifier" label="Plugins" paletteLabel="Plugins" tag="-1" image="ic_plugin" selectable="YES" id="zzE-XA-cFn">
<size key="minSize" width="22" height="22"/>
<size key="maxSize" width="22" height="22"/>
<connections>
<action selector="displayPlugins:" target="-2" id="pluginprefaction"/>
</connections>
</toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="GQi-nL-0Ey"/>
<toolbarItem reference="iuJ-eu-b7f"/>
<toolbarItem reference="jLi-an-TR2"/>
<toolbarItem reference="zzE-XA-cFn"/>
<toolbarItem reference="aIF-RX-dpX"/>
</defaultToolbarItems>
</toolbar>
......@@ -68,11 +85,13 @@
</connections>
<point key="canvasLocation" x="449.5" y="181.5"/>
</window>
<userDefaultsController representsSharedInstance="YES" id="4wX-Ep-Yxj"/>
</objects>
<resources>
<image name="NSAdvanced" width="128" height="128"/>
<image name="NSAdvanced" width="32" height="32"/>
<image name="audio" width="36" height="36"/>
<image name="general" width="36" height="36"/>
<image name="ic_plugin" width="32" height="32"/>
<image name="video" width="36" height="36"/>
</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