Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2015 Savoir-Faire Linux Inc. |
| 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 30 | #import "RingWindowController.h" |
| 31 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 32 | #import <accountmodel.h> |
| 33 | #import <callmodel.h> |
| 34 | #import <account.h> |
Alexandre Lision | 91d11e5 | 2015-03-20 17:42:05 -0400 | [diff] [blame] | 35 | #import <call.h> |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 36 | |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 37 | #import "AppDelegate.h" |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 38 | #import "Constants.h" |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame^] | 39 | #import "CurrentCallVC.h" |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 40 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 41 | @interface RingWindowController () |
| 42 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 43 | @property NSSearchField* callField; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame^] | 44 | @property CurrentCallVC* currentVC; |
| 45 | @property (unsafe_unretained) IBOutlet NSView *callView; |
| 46 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 47 | |
| 48 | @end |
| 49 | |
| 50 | @implementation RingWindowController |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 51 | @synthesize callField; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame^] | 52 | @synthesize currentVC; |
| 53 | @synthesize callView; |
| 54 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 55 | static NSString* const kSearchViewIdentifier = @"SearchViewIdentifier"; |
| 56 | static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier"; |
| 57 | static NSString* const kCallButtonIdentifer = @"CallButtonIdentifier"; |
| 58 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 59 | - (void)windowDidLoad { |
| 60 | [super windowDidLoad]; |
Alexandre Lision | 745e4d6 | 2015-03-22 20:03:10 -0400 | [diff] [blame] | 61 | [self.window setReleasedWhenClosed:FALSE]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 62 | [self displayMainToolBar]; |
Alexandre Lision | 58cab67 | 2015-06-09 15:25:40 -0400 | [diff] [blame^] | 63 | |
| 64 | currentVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil]; |
| 65 | [callView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 66 | [[currentVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 67 | |
| 68 | [callView addSubview:[self.currentVC view]]; |
| 69 | [currentVC initFrame]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 72 | - (IBAction)openPreferences:(id)sender |
| 73 | { |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 74 | if(self.preferencesViewController != nil) { |
| 75 | [self closePreferences:nil]; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 76 | return; |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 77 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 78 | NSToolbar* tb = [[NSToolbar alloc] initWithIdentifier: @"PreferencesToolbar"]; |
| 79 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 80 | self.preferencesViewController = [[PreferencesVC alloc] initWithNibName:@"PreferencesScreen" bundle:nil]; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 81 | self.myCurrentViewController = self.preferencesViewController; |
| 82 | |
| 83 | NSLayoutConstraint* test = [NSLayoutConstraint constraintWithItem:self.preferencesViewController.view |
| 84 | attribute:NSLayoutAttributeWidth |
| 85 | relatedBy:NSLayoutRelationEqual |
| 86 | toItem:currentView |
| 87 | attribute:NSLayoutAttributeWidth |
| 88 | multiplier:1.0f |
| 89 | constant:0.0f]; |
| 90 | |
| 91 | NSLayoutConstraint* test2 = [NSLayoutConstraint constraintWithItem:self.preferencesViewController.view |
| 92 | attribute:NSLayoutAttributeHeight |
| 93 | relatedBy:NSLayoutRelationEqual |
| 94 | toItem:currentView |
| 95 | attribute:NSLayoutAttributeHeight |
| 96 | multiplier:1.0f |
| 97 | constant:0.0f]; |
| 98 | |
| 99 | NSLayoutConstraint* test3 = [NSLayoutConstraint constraintWithItem:self.preferencesViewController.view |
| 100 | attribute:NSLayoutAttributeCenterX |
| 101 | relatedBy:NSLayoutRelationEqual |
| 102 | toItem:currentView |
| 103 | attribute:NSLayoutAttributeCenterX |
| 104 | multiplier:1.0f |
| 105 | constant:0.0f]; |
| 106 | |
| 107 | |
| 108 | [currentView addSubview:[self.preferencesViewController view]]; |
| 109 | |
| 110 | [tb setDelegate: self.preferencesViewController]; |
| 111 | [self.window setToolbar: tb]; |
| 112 | |
| 113 | [self.window.toolbar setSelectedItemIdentifier:@"GeneralPrefsIdentifier"]; |
| 114 | |
| 115 | [currentView addConstraint:test]; |
| 116 | [currentView addConstraint:test2]; |
| 117 | [currentView addConstraint:test3]; |
| 118 | // make sure we automatically resize the controller's view to the current window size |
| 119 | [[self.myCurrentViewController view] setFrame:[currentView bounds]]; |
| 120 | |
| 121 | // set the view controller's represented object to the number of subviews in that controller |
| 122 | // (our NSTextField's value binding will reflect this value) |
| 123 | [self.myCurrentViewController setRepresentedObject:[NSNumber numberWithUnsignedInteger:[[[self.myCurrentViewController view] subviews] count]]]; |
| 124 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 125 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 126 | |
| 127 | - (IBAction) closePreferences:(NSToolbarItem *)sender { |
| 128 | if(self.myCurrentViewController != nil) |
| 129 | { |
| 130 | [self.preferencesViewController close]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 131 | [self displayMainToolBar]; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 132 | self.preferencesViewController = nil; |
| 133 | } |
| 134 | } |
| 135 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 136 | -(void) displayMainToolBar |
| 137 | { |
| 138 | NSToolbar* tb = [[NSToolbar alloc] initWithIdentifier: @"MainToolbar"]; |
| 139 | [tb setDisplayMode:NSToolbarDisplayModeIconAndLabel]; |
| 140 | [tb setDelegate: self]; |
| 141 | [self.window setToolbar: tb]; |
| 142 | } |
| 143 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 144 | // FIXME: This is sick, NSWindowController is catching my selectors |
| 145 | - (void)displayGeneral:(NSToolbarItem *)sender { |
| 146 | [self.preferencesViewController displayGeneral:sender]; |
| 147 | } |
| 148 | |
| 149 | - (void)displayAudio:(NSToolbarItem *)sender { |
| 150 | [self.preferencesViewController displayAudio:sender]; |
| 151 | } |
| 152 | |
| 153 | - (void)displayAncrage:(NSToolbarItem *)sender { |
| 154 | [self.preferencesViewController displayAncrage:sender]; |
| 155 | } |
| 156 | |
| 157 | - (void)displayVideo:(NSToolbarItem *)sender { |
| 158 | [self.preferencesViewController displayVideo:sender]; |
| 159 | } |
| 160 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 161 | - (void)displayAccounts:(NSToolbarItem *)sender { |
| 162 | [self.preferencesViewController displayAccounts:sender]; |
| 163 | } |
| 164 | |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 165 | - (void)togglePowerSettings:(id)sender |
| 166 | { |
Alexandre Lision | c65310c | 2015-04-23 16:44:23 -0400 | [diff] [blame] | 167 | BOOL advanced = [[NSUserDefaults standardUserDefaults] boolForKey:Preferences::ShowAdvanced]; |
| 168 | [[NSUserDefaults standardUserDefaults] setBool:!advanced forKey:Preferences::ShowAdvanced]; |
Alexandre Lision | 1154eb3 | 2015-03-20 18:31:48 -0400 | [diff] [blame] | 169 | [[NSUserDefaults standardUserDefaults] synchronize]; |
| 170 | |
| 171 | NSToolbar* tb = [[NSToolbar alloc] initWithIdentifier: @"PreferencesToolbar"]; |
| 172 | [tb setDelegate: self.preferencesViewController]; |
| 173 | [self.preferencesViewController displayGeneral:nil]; |
| 174 | [self.window setToolbar:tb]; |
| 175 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 176 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 177 | #pragma NSToolbar Delegate |
| 178 | |
| 179 | -(NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag |
| 180 | { |
| 181 | NSToolbarItem* item = nil; |
| 182 | |
| 183 | if ([itemIdentifier isEqualToString: kSearchViewIdentifier]) { |
| 184 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kSearchViewIdentifier]; |
| 185 | callField = [[NSSearchField alloc] initWithFrame:NSMakeRect(0,0,400,21)]; |
| 186 | [[callField cell] setSearchButtonCell:nil]; |
| 187 | [callField setToolTip:@"Call"]; |
Alexandre Lision | 25bcd48 | 2015-03-22 22:49:12 -0400 | [diff] [blame] | 188 | [callField setAlignment:NSCenterTextAlignment]; |
| 189 | [callField setDelegate:self]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 190 | [item setView:callField]; |
| 191 | } |
| 192 | |
| 193 | if ([itemIdentifier isEqualToString: kCallButtonIdentifer]) { |
| 194 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kCallButtonIdentifer]; |
| 195 | |
| 196 | NSButton *callButton = [[NSButton alloc] initWithFrame:NSMakeRect(0,0,80,30)]; |
| 197 | |
| 198 | [callButton setButtonType:NSMomentaryLightButton]; //Set what type button You want |
| 199 | [callButton setBezelStyle:NSRoundedBezelStyle]; //Set what style You want] |
| 200 | [callButton setBordered:YES]; |
| 201 | [callButton setTitle:@"Call"]; |
| 202 | [item setView:callButton]; |
| 203 | [item setAction:@selector(placeCall:)]; |
| 204 | } |
| 205 | |
| 206 | if ([itemIdentifier isEqualToString: kPreferencesIdentifier]) { |
| 207 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kPreferencesIdentifier]; |
| 208 | [item setImage: [NSImage imageNamed: @"NSAdvanced"]]; |
| 209 | [item setLabel: @"Settings"]; |
| 210 | [item setAction:@selector(openPreferences:)]; |
| 211 | } |
| 212 | |
| 213 | return item; |
Alexandre Lision | 25bcd48 | 2015-03-22 22:49:12 -0400 | [diff] [blame] | 214 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 215 | |
Alexandre Lision | 25bcd48 | 2015-03-22 22:49:12 -0400 | [diff] [blame] | 216 | - (IBAction)placeCall:(id)sender |
| 217 | { |
| 218 | Call* c = CallModel::instance()->dialingCall(); |
Alexandre Lision | 0a22c8f | 2015-03-29 21:40:06 -0400 | [diff] [blame] | 219 | // check for a valid ring hash |
| 220 | NSCharacterSet *hexSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789abcdefABCDEF"]; |
| 221 | BOOL valid = [[[callField stringValue] stringByTrimmingCharactersInSet:hexSet] isEqualToString:@""]; |
| 222 | |
| 223 | if(valid && callField.stringValue.length == 40) { |
| 224 | c->setDialNumber(QString::fromNSString([NSString stringWithFormat:@"ring:%@",[callField stringValue]])); |
| 225 | } else { |
| 226 | c->setDialNumber(QString::fromNSString([callField stringValue])); |
| 227 | } |
| 228 | |
Alexandre Lision | 25bcd48 | 2015-03-22 22:49:12 -0400 | [diff] [blame] | 229 | c << Call::Action::ACCEPT; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 230 | } |
| 231 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 232 | -(NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar |
| 233 | { |
| 234 | return [NSArray arrayWithObjects: |
| 235 | NSToolbarSpaceItemIdentifier, |
| 236 | NSToolbarFlexibleSpaceItemIdentifier, |
| 237 | NSToolbarSpaceItemIdentifier, |
| 238 | NSToolbarSpaceItemIdentifier, |
| 239 | kSearchViewIdentifier, |
| 240 | kCallButtonIdentifer, |
| 241 | NSToolbarFlexibleSpaceItemIdentifier, |
| 242 | kPreferencesIdentifier, |
| 243 | nil]; |
| 244 | } |
| 245 | |
| 246 | -(NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar |
| 247 | { |
| 248 | return [NSArray arrayWithObjects: |
| 249 | kSearchViewIdentifier, |
| 250 | kCallButtonIdentifer, |
| 251 | kPreferencesIdentifier, |
| 252 | nil]; |
| 253 | } |
| 254 | |
| 255 | -(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar |
| 256 | { |
| 257 | return nil; |
| 258 | } |
| 259 | |
Alexandre Lision | 25bcd48 | 2015-03-22 22:49:12 -0400 | [diff] [blame] | 260 | #pragma NSTextField Delegate |
| 261 | |
| 262 | - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector |
| 263 | { |
Alexandre Lision | 25bcd48 | 2015-03-22 22:49:12 -0400 | [diff] [blame] | 264 | if (commandSelector == @selector(insertNewline:)) { |
| 265 | if([[callField stringValue] isNotEqualTo:@""]) { |
| 266 | [self placeCall:nil]; |
| 267 | return YES; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | return NO; |
| 272 | } |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 273 | |
| 274 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 275 | @end |