PreferencesWC.mm 5.97 KB
Newer Older
Alexandre Lision's avatar
Alexandre Lision committed
1
/*
Alexandre Lision's avatar
Alexandre Lision committed
2
 *  Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lision's avatar
Alexandre Lision committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 *  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 "PreferencesWC.h"


22
#import <api/datatransfermodel.h>
Alexandre Lision's avatar
Alexandre Lision committed
23

24
//Ring
Alexandre Lision's avatar
Alexandre Lision committed
25
26
27
#import "GeneralPrefsVC.h"
#import "AudioPrefsVC.h"
#import "VideoPrefsVC.h"
28
#import "PluginPrefsVC.h"
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
29
#import "views/NSColor+RingTheme.h"
Alexandre Lision's avatar
Alexandre Lision committed
30
31
32
33
34
35
36

@implementation PreferencesWC {

    __unsafe_unretained IBOutlet NSView *prefsContainer;
    NSViewController *currentVC;
}

Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
37
@synthesize accountModel, behaviorController, avModel, pluginModel;
38

39
40
41
42
// Identifiers used in PreferencesWindow.xib for tabs
static auto const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier";
static auto const kAudioPrefsIdentifer    = @"AudioPrefsIdentifer";
static auto const kVideoPrefsIdentifer    = @"VideoPrefsIdentifer";
43
static auto const kPluginPrefsIdentifer    = @"PluginPrefsIdentifer";
Alexandre Lision's avatar
Alexandre Lision committed
44
45
46
47
48

- (void)windowDidLoad
{
    [super windowDidLoad];
    [self.window setMovableByWindowBackground:YES];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
49
50
    NSArray *items = [self.window.toolbar items];
    for(NSToolbarItem *toolbarItem in items) {
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
51
        NSImage * image =  [NSColor image: [toolbarItem image] tintedWithColor: [NSColor labelColor]];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
52
53
        toolbarItem.image = image;
    }
Alexandre Lision's avatar
Alexandre Lision committed
54
55
    [self.window.toolbar setSelectedItemIdentifier:kGeneralPrefsIdentifier];
    [self displayGeneral:nil];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
56
57
    NSToolbar *tb = [[self window] toolbar];
    [tb setAllowsUserCustomization:NO];
Alexandre Lision's avatar
Alexandre Lision committed
58
59
}

Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
60
-(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(lrc::api::NewAccountModel*)accountModel  behaviourController:(lrc::api::BehaviorController*)behaviorController avModel: (lrc::api::AVModel*)avModel pluginModel: (lrc::api::PluginModel*)pluginModel
61
{
62
    if (self =  [self initWithWindowNibName:nibNameOrNil])
63
    {
64
65
        self.accountModel = accountModel;
        self.behaviorController = behaviorController;
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
66
        self.avModel = avModel;
67
        self.pluginModel = pluginModel;
68
69
70
71
    }
    return self;
}

Alexandre Lision's avatar
Alexandre Lision committed
72
73
74
75
- (IBAction)displayGeneral:(NSToolbarItem *)sender
{
    [[prefsContainer subviews]
     makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
76
    currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil accountModel: self.accountModel avModel: self.avModel];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
77
    [self addCurrentVC];
Alexandre Lision's avatar
Alexandre Lision committed
78
79
80
81
82
83
}

- (IBAction)displayAudio:(NSToolbarItem *)sender
{
    [[prefsContainer subviews]
     makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
84
    currentVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil avModel: self.avModel];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
85
    [self addCurrentVC];
Alexandre Lision's avatar
Alexandre Lision committed
86
87
88
89
90
91
}

- (IBAction)displayVideo:(NSToolbarItem *)sender
{
    [[prefsContainer subviews]
     makeObjectsPerformSelector:@selector(removeFromSuperview)];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
92
    currentVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil avModel: self.avModel];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
93
94
95
    [self addCurrentVC];
}

96
97
98
99
100
101
102
103
- (IBAction)displayPlugins:(NSToolbarItem *)sender
{
    [[prefsContainer subviews]
     makeObjectsPerformSelector:@selector(removeFromSuperview)];
    currentVC = [[PluginPrefsVC alloc] initWithNibName:@"PluginPrefs" bundle:nil pluginModel: self.pluginModel];
    [self addCurrentVC];
}

Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
104
-(void) addCurrentVC {
Alexandre Lision's avatar
Alexandre Lision committed
105
106
    [self resizeWindowWithFrame:currentVC.view.frame];
    [prefsContainer addSubview:currentVC.view];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
107
108
109
110
111
112
113
114
115
116
117
118
119
    currentVC.view.translatesAutoresizingMaskIntoConstraints = false;
    [NSLayoutConstraint constraintWithItem:currentVC.view
                                 attribute:NSLayoutAttributeCenterX
                                 relatedBy:NSLayoutRelationEqual toItem: prefsContainer
                                 attribute:NSLayoutAttributeCenterX
                                multiplier:1 constant:0].active = YES;
    [NSLayoutConstraint constraintWithItem:currentVC.view
                                 attribute:NSLayoutAttributeTop
                                 relatedBy:NSLayoutRelationEqual
                                    toItem:prefsContainer
                                 attribute:NSLayoutAttributeTop
                                multiplier:1
                                  constant:0].active = YES;
Alexandre Lision's avatar
Alexandre Lision committed
120
121
122
123
124
125
}

- (void) resizeWindowWithFrame:(NSRect)fr
{
    auto frame = [self.window frame];
    frame.origin.y += frame.size.height;
126
127
    frame.origin.y -= NSHeight(fr) + [self toolBarHeight] + [self titleBarHeight];
    frame.size.height = NSHeight(fr) + [self toolBarHeight];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
128
129
130
    if (frame.size.width < NSWidth(fr)) {
        frame.size.width = NSWidth(fr);
    }
Alexandre Lision's avatar
Alexandre Lision committed
131
132
133
134
135
136
    frame = [NSWindow frameRectForContentRect:frame
                                         styleMask:[self.window styleMask]];

    [self.window setFrame:frame display:YES animate:YES];
}

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
- (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);
}

Alexandre Lision's avatar
Alexandre Lision committed
161
@end