blob: 67c5f2b5e4360b74a9559985bf8dfece20e4be0b [file] [log] [blame]
Alexandre Lision8521baa2015-03-13 11:08:00 -04001/*
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 Lision4a7b95e2015-02-20 10:06:43 -050030#import "AudioPrefsVC.h"
31
Alexandre Lision611b8c12015-03-20 18:07:17 -040032#import <audio/settings.h>
Alexandre Lision66643432015-06-04 11:59:36 -040033#import <media/recordingmodel.h>
Alexandre Lision611b8c12015-03-20 18:07:17 -040034#import <QUrl>
35#import <audio/inputdevicemodel.h>
36#import <audio/outputdevicemodel.h>
37#import <qitemselectionmodel.h>
38
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050039@interface AudioPrefsVC ()
40
Alexandre Lision611b8c12015-03-20 18:07:17 -040041@property (assign) IBOutlet NSPathControl *recordingsPathControl;
42@property (assign) IBOutlet NSPopUpButton *outputDeviceList;
43@property (assign) IBOutlet NSPopUpButton *inputDeviceList;
44@property (assign) IBOutlet NSButton *alwaysRecordingButton;
45@property (assign) IBOutlet NSButton *muteDTMFButton;
46
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050047@end
48
49@implementation AudioPrefsVC
Alexandre Lision611b8c12015-03-20 18:07:17 -040050@synthesize recordingsPathControl;
51@synthesize outputDeviceList;
52@synthesize inputDeviceList;
53@synthesize alwaysRecordingButton;
54@synthesize muteDTMFButton;
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050055
Alexandre Lision611b8c12015-03-20 18:07:17 -040056- (void)loadView
57{
58 [super loadView];
59
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040060 QModelIndex qInputIdx = Audio::Settings::instance().inputDeviceModel()->selectionModel()->currentIndex();
61 QModelIndex qOutputIdx = Audio::Settings::instance().outputDeviceModel()->selectionModel()->currentIndex();
Alexandre Lision611b8c12015-03-20 18:07:17 -040062
63 [self.outputDeviceList addItemWithTitle:
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040064 Audio::Settings::instance().outputDeviceModel()->data(qOutputIdx, Qt::DisplayRole).toString().toNSString()];
Alexandre Lision611b8c12015-03-20 18:07:17 -040065
66 [self.inputDeviceList addItemWithTitle:
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040067 Audio::Settings::instance().inputDeviceModel()->data(qInputIdx, Qt::DisplayRole).toString().toNSString()];
Alexandre Lision611b8c12015-03-20 18:07:17 -040068 [self.alwaysRecordingButton setState:
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040069 Media::RecordingModel::instance().isAlwaysRecording() ? NSOnState:NSOffState];
Alexandre Lision611b8c12015-03-20 18:07:17 -040070
71 [self.muteDTMFButton setState:
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040072 Audio::Settings::instance().areDTMFMuted()?NSOnState:NSOffState];
Alexandre Lision611b8c12015-03-20 18:07:17 -040073
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040074 if([[Media::RecordingModel::instance().recordPath().toNSURL() absoluteString] isEqualToString:@""]) {
Alexandre Lision611b8c12015-03-20 18:07:17 -040075 NSArray * pathComponentArray = [self pathComponentArray];
76 [recordingsPathControl setPathComponentCells:pathComponentArray];
Alexandre Lision4de68ce2015-04-24 18:22:49 -040077 } else {
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040078 [recordingsPathControl setURL:Media::RecordingModel::instance().recordPath().toNSURL()];
Alexandre Lision611b8c12015-03-20 18:07:17 -040079 }
80}
81
82- (IBAction)toggleMuteDTMF:(NSButton *)sender
83{
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040084 Audio::Settings::instance().setDTMFMuted([sender state] == NSOnState);
Alexandre Lision611b8c12015-03-20 18:07:17 -040085}
86
87- (IBAction)toggleAlwaysRecording:(NSButton *)sender
88{
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040089 Media::RecordingModel::instance().setAlwaysRecording([sender state] == NSOnState);
Alexandre Lision611b8c12015-03-20 18:07:17 -040090}
91
92- (IBAction)pathControlSingleClick:(id)sender {
93 // Select that chosen component of the path.
94 [self.recordingsPathControl setURL:[[self.recordingsPathControl clickedPathComponentCell] URL]];
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -040095 Media::RecordingModel::instance().setRecordPath(QUrl::fromNSURL(self.recordingsPathControl.URL));
Alexandre Lision611b8c12015-03-20 18:07:17 -040096}
97
98- (IBAction)chooseOutput:(id)sender {
99 int index = [sender indexOfSelectedItem];
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400100 QModelIndex qIdx = Audio::Settings::instance().outputDeviceModel()->index(index, 0);
101 Audio::Settings::instance().outputDeviceModel()->selectionModel()->setCurrentIndex(
Alexandre Lision611b8c12015-03-20 18:07:17 -0400102 qIdx, QItemSelectionModel::ClearAndSelect);
103}
104
105- (IBAction)chooseInput:(id)sender {
106 int index = [sender indexOfSelectedItem];
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400107 QModelIndex qIdx = Audio::Settings::instance().inputDeviceModel()->index(index, 0);
108 Audio::Settings::instance().inputDeviceModel()->selectionModel()->setCurrentIndex(
Alexandre Lision611b8c12015-03-20 18:07:17 -0400109 qIdx, QItemSelectionModel::ClearAndSelect);
110}
111
112#pragma mark - NSPathControl delegate methods
113
114/*
115 Assemble a set of custom cells to display into an array to pass to the path control.
116 */
117- (NSArray *)pathComponentArray
118{
119 NSMutableArray *pathComponentArray = [[NSMutableArray alloc] init];
120
121 NSFileManager *fileManager = [[NSFileManager alloc] init];
122
123 NSURL* desktopURL = [fileManager URLForDirectory:NSDesktopDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
124 NSURL* documentsURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
125 NSURL* userURL = [fileManager URLForDirectory:NSUserDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
126
127 NSPathComponentCell *componentCell;
128
129 // Use utility method to obtain a NSPathComponentCell based on icon, title and URL.
130 componentCell = [self componentCellForType:kGenericFolderIcon withTitle:@"Desktop" URL:desktopURL];
131 [pathComponentArray addObject:componentCell];
132
133 componentCell = [self componentCellForType:kGenericFolderIcon withTitle:@"Documents" URL:documentsURL];
134 [pathComponentArray addObject:componentCell];
135
136 componentCell = [self componentCellForType:kUserFolderIcon withTitle:NSUserName() URL:userURL];
137 [pathComponentArray addObject:componentCell];
138
139 return pathComponentArray;
140}
141
142/*
143 This method is used by pathComponentArray to create a NSPathComponent cell based on icon, title and URL information.
144 Each path component needs an icon, URL and title.
145 */
146- (NSPathComponentCell *)componentCellForType:(OSType)withIconType withTitle:(NSString *)title URL:(NSURL *)url
147{
148 NSPathComponentCell *componentCell = [[NSPathComponentCell alloc] init];
149
150 NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(withIconType)];
151 [componentCell setImage:iconImage];
152 [componentCell setURL:url];
153 [componentCell setTitle:title];
154
155 return componentCell;
156}
157
158/*
159 Delegate method of NSPathControl to determine how the NSOpenPanel will look/behave.
160 */
161- (void)pathControl:(NSPathControl *)pathControl willDisplayOpenPanel:(NSOpenPanel *)openPanel
162{
163 NSLog(@"willDisplayOpenPanel");
164 [openPanel setAllowsMultipleSelection:NO];
165 [openPanel setCanChooseDirectories:YES];
166 [openPanel setCanChooseFiles:NO];
167 [openPanel setResolvesAliases:YES];
168 [openPanel setTitle:NSLocalizedString(@"Choose a file", @"Open panel title")];
Alexandre Lision922380d2015-09-15 10:25:17 -0400169 [openPanel setPrompt:NSLocalizedString(@"Choose file", @"Open panel prompt for 'Choose a directory'")];
Alexandre Lision611b8c12015-03-20 18:07:17 -0400170 [openPanel setDelegate:self];
171}
172
173- (void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu
174{
175
176}
177
178#pragma mark - NSOpenSavePanelDelegate delegate methods
179
180- (BOOL)panel:(id)sender validateURL:(NSURL *)url error:(NSError **)outError
181{
182 [recordingsPathControl setURL:url];
183 return YES;
184}
185
186#pragma mark - NSMenuDelegate methods
187
188- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel
189{
190 QModelIndex qIdx;
191
192 if([menu.title isEqualToString:@"inputlist"])
193 {
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400194 qIdx = Audio::Settings::instance().inputDeviceModel()->index(index);
195 [item setTitle:Audio::Settings::instance().inputDeviceModel()->data(qIdx, Qt::DisplayRole).toString().toNSString()];
Alexandre Lision611b8c12015-03-20 18:07:17 -0400196 } else
197 {
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400198 qIdx = Audio::Settings::instance().outputDeviceModel()->index(index);
199 [item setTitle:Audio::Settings::instance().outputDeviceModel()->data(qIdx, Qt::DisplayRole).toString().toNSString()];
Alexandre Lision611b8c12015-03-20 18:07:17 -0400200 }
201
202 return YES;
203}
204
205- (NSInteger)numberOfItemsInMenu:(NSMenu *)menu
206{
207 if([menu.title isEqualToString:@"inputlist"])
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400208 return Audio::Settings::instance().inputDeviceModel()->rowCount();
Alexandre Lision611b8c12015-03-20 18:07:17 -0400209 else
Alexandre Lisiond3aa3ad2015-10-23 14:28:41 -0400210 return Audio::Settings::instance().outputDeviceModel()->rowCount();
Alexandre Lision611b8c12015-03-20 18:07:17 -0400211}
Alexandre Lision4a7b95e2015-02-20 10:06:43 -0500212
213@end