blob: 9c961db4ccde90d961e0fd1df9e8a717fb13e192 [file] [log] [blame]
Alexandre Lision8521baa2015-03-13 11:08:00 -04001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lision8521baa2015-03-13 11:08:00 -04003 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -04004 * Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Alexandre Lision8521baa2015-03-13 11:08:00 -04005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Alexandre Lision8521baa2015-03-13 11:08:00 -040019 */
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050020#import "AudioPrefsVC.h"
21
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040022//LRC
23#import <api/avmodel.h>
Alexandre Lision611b8c12015-03-20 18:07:17 -040024
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050025@interface AudioPrefsVC ()
26
Alexandre Lision611b8c12015-03-20 18:07:17 -040027@property (assign) IBOutlet NSPopUpButton *outputDeviceList;
28@property (assign) IBOutlet NSPopUpButton *inputDeviceList;
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050029@end
30
31@implementation AudioPrefsVC
Alexandre Lision611b8c12015-03-20 18:07:17 -040032@synthesize outputDeviceList;
33@synthesize inputDeviceList;
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040034@synthesize avModel;
35QMetaObject::Connection audioDeviceEvent;
36
37-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil avModel:(lrc::api::AVModel*) avModel
38{
39 if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
40 {
41 self.avModel = avModel;
42 }
43 return self;
44}
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050045
Alexandre Lision611b8c12015-03-20 18:07:17 -040046- (void)loadView
47{
48 [super loadView];
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040049 [self connectdDeviceEvent];
50 [self addDevices];
51}
Alexandre Lision611b8c12015-03-20 18:07:17 -040052
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040053-(void) addDevices {
54 [inputDeviceList removeAllItems];
55 [outputDeviceList removeAllItems];
56 auto inputDevices = avModel->getAudioInputDevices();
57 auto inputDevice = avModel->getInputDevice();
58 for (auto device : inputDevices) {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040059 [inputDeviceList addItemWithTitle: device.toNSString()];
Kateryna Kostiuk3cbc1662019-07-18 14:57:53 -040060 if(device == inputDevice) {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040061 [inputDeviceList selectItemWithTitle:inputDevice.toNSString()];
Kateryna Kostiuk3cbc1662019-07-18 14:57:53 -040062 }
Kateryna Kostiuk74fe20c2018-06-14 12:05:53 -040063 }
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040064 auto outputDevices = avModel->getAudioOutputDevices();
65 auto outputDevice = avModel->getOutputDevice();
66 for (auto device : outputDevices) {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040067 [outputDeviceList addItemWithTitle: device.toNSString()];
Kateryna Kostiuk3cbc1662019-07-18 14:57:53 -040068 if(device == outputDevice) {
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040069 [outputDeviceList selectItemWithTitle:outputDevice.toNSString()];
Kateryna Kostiuk3cbc1662019-07-18 14:57:53 -040070 }
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040071 }
Alexandre Lision611b8c12015-03-20 18:07:17 -040072}
73
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040074-(void)connectdDeviceEvent {
75 QObject::disconnect(audioDeviceEvent);
76 audioDeviceEvent = QObject::connect(avModel,
77 &lrc::api::AVModel::deviceEvent,
78 [=]() {
Kateryna Kostiuk3cbc1662019-07-18 14:57:53 -040079 dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
80 1 * NSEC_PER_SEC),
81 dispatch_get_main_queue(), ^{
82 [self addDevices];
83 });
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040084 });
Alexandre Lision611b8c12015-03-20 18:07:17 -040085}
86
87- (IBAction)chooseOutput:(id)sender {
88 int index = [sender indexOfSelectedItem];
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040089 auto output = [self.outputDeviceList itemTitleAtIndex:index];
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040090 avModel->setOutputDevice(QString::fromNSString(output));
Alexandre Lision611b8c12015-03-20 18:07:17 -040091}
92
93- (IBAction)chooseInput:(id)sender {
94 int index = [sender indexOfSelectedItem];
Kateryna Kostiuk5d90c3b2019-07-18 12:03:52 -040095 auto input = [self.inputDeviceList itemTitleAtIndex:index];
Kateryna Kostiukc867eb92020-03-08 13:15:17 -040096 avModel->setInputDevice(QString::fromNSString(input));
Alexandre Lision611b8c12015-03-20 18:07:17 -040097}
Alexandre Lision4a7b95e2015-02-20 10:06:43 -050098
99@end