Commit 261f1b91 authored by Alexandre Lision's avatar Alexandre Lision

profile: add edition in settings

- fix a small offset of the preference window when
switching between tabs
- increase sizes of photos to avoid pixelisation

Change-Id: Idfb9149a8de08c034dff3e42b41f5888bba893f7
Tuleap: #530
parent 54187a23
......@@ -137,6 +137,8 @@ SET(ringclient_VIEWS
src/views/HoverTableRowView.h
src/views/NSColor+RingTheme.mm
src/views/NSColor+RingTheme.h
src/views/NSImage+Extensions.mm
src/views/NSImage+Extensions.h
src/views/ContextualTableCellView.mm
src/views/ContextualTableCellView.h
src/views/IconButton.h
......
......@@ -156,7 +156,7 @@
[stateLabel setStringValue:callIdx.data((int)Call::Role::HumanStateName).toString().toNSString()];
if (firstRun) {
QVariant photo = GlobalInstances::pixmapManipulator().callPhoto(current, QSize(50,50));
QVariant photo = GlobalInstances::pixmapManipulator().callPhoto(current, QSize(100,100));
[personPhoto setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
}
......
......@@ -18,35 +18,43 @@
*/
#import "GeneralPrefsVC.h"
#import <Quartz/Quartz.h>
//Qt
#import <QSize>
#import <QtMacExtras/qmacfunctions.h>
#import <QPixmap>
//LRC
#import <categorizedhistorymodel.h>
#import <profilemodel.h>
#import <profile.h>
#import <person.h>
#import <globalinstances.h>
#if ENABLE_SPARKLE
#import <Sparkle/Sparkle.h>
#endif
#import "Constants.h"
@interface GeneralPrefsVC ()
@property (unsafe_unretained) IBOutlet NSTextField* historyChangedLabel;
@property (unsafe_unretained) IBOutlet NSButton* startUpButton;
@property (unsafe_unretained) IBOutlet NSButton* toggleAutomaticUpdateCheck;
@property (unsafe_unretained) IBOutlet NSPopUpButton* checkIntervalPopUp;
@property (unsafe_unretained) IBOutlet NSView* sparkleContainer;
@property (unsafe_unretained) IBOutlet NSTextField* historyTextField;
@property (unsafe_unretained) IBOutlet NSStepper* historyStepper;
@property (unsafe_unretained) IBOutlet NSButton* historySwitch;
#import "views/NSImage+Extensions.h"
#import "delegates/ImageManipulationDelegate.h"
@interface GeneralPrefsVC () {
__unsafe_unretained IBOutlet NSTextField* historyChangedLabel;
__unsafe_unretained IBOutlet NSButton* startUpButton;
__unsafe_unretained IBOutlet NSButton* toggleAutomaticUpdateCheck;
__unsafe_unretained IBOutlet NSPopUpButton* checkIntervalPopUp;
__unsafe_unretained IBOutlet NSView* sparkleContainer;
__unsafe_unretained IBOutlet NSTextField* historyTextField;
__unsafe_unretained IBOutlet NSStepper* historyStepper;
__unsafe_unretained IBOutlet NSButton* historySwitch;
__unsafe_unretained IBOutlet NSButton* photoView;
__unsafe_unretained IBOutlet NSTextField* profileNameField;
}
@end
@implementation GeneralPrefsVC
@synthesize historyChangedLabel;
@synthesize startUpButton;
@synthesize toggleAutomaticUpdateCheck;
@synthesize checkIntervalPopUp;
@synthesize sparkleContainer;
@synthesize historyTextField;
@synthesize historyStepper;
@synthesize historySwitch;
- (void)loadView
{
......@@ -74,6 +82,16 @@
[sparkleContainer setHidden:YES];
#endif
[photoView setWantsLayer: YES];
photoView.layer.cornerRadius = photoView.frame.size.width / 2;
photoView.layer.masksToBounds = YES;
if (auto pro = ProfileModel::instance().selectedProfile()) {
auto photo = GlobalInstances::pixmapManipulator().contactPhoto(pro->person(), {140,140});
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
[profileNameField setStringValue:pro->person()->formattedName().toNSString()];
}
}
- (void) dealloc
......@@ -86,7 +104,7 @@
[historyChangedLabel setHidden:NO];
}
- (IBAction)toggleHistory:(id)sender {
- (IBAction)toggleHistory:(NSButton*)sender {
CategorizedHistoryModel::instance().setHistoryLimited([sender state]);
int historyLimit = CategorizedHistoryModel::instance().historyLimit();
[historyTextField setStringValue:[NSString stringWithFormat:@"%d", historyLimit]];
......@@ -171,4 +189,42 @@
return itemRef;
}
#pragma mark - Profile Photo edition
- (IBAction) editPhoto:(id)sender {
auto pictureTaker = [IKPictureTaker pictureTaker];
[pictureTaker beginPictureTakerSheetForWindow:self.view.window
withDelegate:self
didEndSelector:@selector(pictureTakerDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void) pictureTakerDidEnd:(IKPictureTaker *) picker
returnCode:(NSInteger) code
contextInfo:(void*) contextInfo
{
if (auto outputImage = [picker outputImage]) {
[photoView setImage:outputImage];
} else
[photoView setImage:[NSImage imageNamed:@"default_user_icon"]];
if (auto pro = ProfileModel::instance().selectedProfile()) {
QPixmap p;
auto smallImg = [NSImage imageResize:[photoView image] newSize:{100,100}];
if (p.loadFromData(QByteArray::fromNSData([smallImg TIFFRepresentation]))) {
pro->person()->setPhoto(QVariant(p));
}
pro->save();
}
}
#pragma mark - NSTextFieldDelegate methods
-(void)controlTextDidChange:(NSNotification *)notif
{
if (auto pro = ProfileModel::instance().selectedProfile()) {
pro->person()->setFormattedName(profileNameField.stringValue.UTF8String);
pro->save();
}
}
@end
......@@ -20,14 +20,17 @@
#import <QuartzCore/QuartzCore.h>
//LRC
#import <accountmodel.h>
#import <codecmodel.h>
#import <profilemodel.h>
#import <profile.h>
//Ring
#import "AccountsVC.h"
#import "GeneralPrefsVC.h"
#import "AudioPrefsVC.h"
#import "VideoPrefsVC.h"
#import "Constants.h"
@implementation PreferencesWC {
......@@ -36,10 +39,11 @@
}
static NSString* const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier";
static NSString* const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
static NSString* const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
static NSString* const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
// Identifiers used in PreferencesWindow.xib for tabs
static auto const kProfilePrefsIdentifier = @"AccountsPrefsIdentifier";
static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
static auto const kAudioPrefsIdentifer = @"AudioPrefsIdentifer";
static auto const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
- (void)windowDidLoad
{
......@@ -52,6 +56,7 @@ static NSString* const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
- (void)windowWillClose:(NSNotification *)notification
{
AccountModel::instance().save();
ProfileModel::instance().selectedProfile()->save();
}
- (IBAction)displayGeneral:(NSToolbarItem *)sender
......@@ -93,26 +98,39 @@ static NSString* const kVideoPrefsIdentifer = @"VideoPrefsIdentifer";
- (void) resizeWindowWithFrame:(NSRect)fr
{
NSToolbar *toolbar = [self.window toolbar];
CGFloat toolbarHeight = 0.0;
NSRect windowFrame;
if (toolbar && [toolbar isVisible]) {
windowFrame = [NSWindow contentRectForFrameRect:[self.window frame]
styleMask:[self.window styleMask]];
toolbarHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]);
}
auto frame = [self.window frame];
frame.origin.y += frame.size.height;
frame.origin.y -= NSHeight(fr) + toolbarHeight;
frame.size.height = NSHeight(fr) + toolbarHeight;
frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight];
frame.size.height = NSHeight(fr) + [self toolBarHeight];
frame.size.width = NSWidth(fr);
frame = [NSWindow frameRectForContentRect:frame
styleMask:[self.window styleMask]];
[self.window setFrame:frame display:YES animate:YES];
}
- (CGFloat) toolBarHeight
{
NSRect windowFrame;
NSToolbar *toolbar = [self.window toolbar];
CGFloat tHeight = 0.0;
if (toolbar && [toolbar isVisible]) {
windowFrame = [NSWindow contentRectForFrameRect:[self.window frame]
styleMask:[self.window styleMask]];
tHeight = NSHeight(windowFrame) - NSHeight([[self.window contentView] frame]);
}
return tHeight;
}
- (float) titleBarHeight
{
NSRect frame = NSMakeRect (0, 0, 100, 100);
NSRect contentRect;
contentRect = [NSWindow contentRectForFrameRect: frame
styleMask: NSTitledWindowMask];
return (frame.size.height - contentRect.size.height);
}
@end
......@@ -89,6 +89,7 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
auto call = RecentModel::instance().getActiveCall(current);
if(!current.isValid()) {
[offlineVC animateOut];
[currentCallVC animateOut];
......
......@@ -39,6 +39,7 @@
#import "AppDelegate.h"
#import "Constants.h"
#import "views/NSImage+Extensions.h"
#import "views/NSColor+RingTheme.h"
@implementation RingWizardWC {
......@@ -156,7 +157,8 @@ NSInteger const NICKNAME_TAG = 1;
if (auto profile = ProfileModel::instance().selectedProfile()) {
profile->person()->setFormattedName([[nicknameField stringValue] UTF8String]);
QPixmap p;
if (p.loadFromData(QByteArray::fromNSData([[photoView image] TIFFRepresentation]))) {
auto smallImg = [NSImage imageResize:[photoView image] newSize:{100,100}];
if (p.loadFromData(QByteArray::fromNSData([smallImg TIFFRepresentation]))) {
profile->person()->setPhoto(QVariant(p));
}
profile->save();
......
......@@ -33,6 +33,7 @@
#import <categorizedhistorymodel.h>
#import <localhistorycollection.h>
#import <localprofilecollection.h>
#import <peerprofilecollection.h>
#import <numbercategorymodel.h>
#import <callmodel.h>
#import <profilemodel.h>
......@@ -80,6 +81,7 @@ int main(int argc, const char *argv[]) {
RecentModel::instance(); // Make sure RecentModel is initialized before showing UI
ProfileModel::instance().addCollection<LocalProfileCollection>(LoadOptions::FORCE_ENABLED);
PersonModel::instance().addCollection<PeerProfileCollection>(LoadOptions::FORCE_ENABLED);
return NSApplicationMain(argc, argv);
}
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@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 NSImage (Extensions)
/**
* @param anImage is the original NSImage
* @param newSize is the desired output size
* @return a resized NSImage
*/
+ (NSImage *)imageResize:(NSImage*)anImage
newSize:(NSSize)newSize;
@end
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@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 "NSImage+Extensions.h"
@implementation NSImage (Extensions)
+ (NSImage *)imageResize:(NSImage*)anImage
newSize:(NSSize)newSize
{
auto sourceImage = anImage;
// Report an error if the source isn't a valid image
if (![sourceImage isValid]) {
NSLog(@"Invalid Image");
} else {
auto smallImage = [[NSImage alloc] initWithSize: newSize];
[smallImage lockFocus];
[sourceImage setSize: newSize];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
[sourceImage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.];
[smallImage unlockFocus];
return smallImage;
}
return nil;
}
@end
This diff is collapsed.
......@@ -20,7 +20,7 @@
<windowCollectionBehavior key="collectionBehavior" fullScreenPrimary="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="1053" height="658"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1050"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<view key="contentView" autoresizesSubviews="NO" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="1053" height="658"/>
<autoresizingMask key="autoresizingMask"/>
......
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