Alexandre Lision | 6200531 | 2016-01-28 15:55:16 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
| 20 | #import "DialpadWC.h" |
| 21 | |
| 22 | ///Qt |
| 23 | #import <QtCore/qitemselectionmodel.h> |
| 24 | |
| 25 | ///LRC |
| 26 | #import <callmodel.h> |
| 27 | |
| 28 | @interface DialpadWC () |
| 29 | |
| 30 | @property (unsafe_unretained) IBOutlet NSTextField* composerField; |
| 31 | |
| 32 | @end |
| 33 | |
| 34 | @implementation DialpadWC |
| 35 | @synthesize composerField; |
| 36 | |
| 37 | - (void)windowDidLoad { |
| 38 | [super windowDidLoad]; |
| 39 | |
| 40 | QObject::connect(CallModel::instance().selectionModel(), |
| 41 | &QItemSelectionModel::currentChanged, |
| 42 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 43 | [composerField setStringValue:@""]; |
| 44 | [composerField setNeedsDisplay:YES]; |
| 45 | if(!current.isValid()) { |
| 46 | [self.window close]; |
| 47 | } |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | - (IBAction)dtmfPressed:(id)sender |
| 52 | { |
| 53 | [self sendDTMF:[sender title]]; |
| 54 | } |
| 55 | |
| 56 | - (void) keyDown:(NSEvent *)theEvent |
| 57 | { |
| 58 | NSString* characters = [theEvent characters]; |
| 59 | if ([characters length] == 1) { |
| 60 | NSString* filter = @"0123456789*#"; |
| 61 | if ([filter containsString:characters]) { |
| 62 | [self sendDTMF:characters]; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | - (void) sendDTMF:(NSString*) dtmf |
| 68 | { |
| 69 | if (auto current = CallModel::instance().selectedCall()) { |
| 70 | current->playDTMF(QString::fromUtf8([dtmf UTF8String])); |
| 71 | } |
| 72 | [composerField setStringValue: |
| 73 | [NSString stringWithFormat: @"%@ %@", [composerField stringValue], dtmf]]; |
| 74 | } |
| 75 | |
| 76 | ///Accessibility |
| 77 | - (void)insertTab:(id)sender |
| 78 | { |
| 79 | if ([[self window] firstResponder] == self) { |
| 80 | [[self window] selectNextKeyView:self]; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | - (void)insertBacktab:(id)sender |
| 85 | { |
| 86 | if ([[self window] firstResponder] == self) { |
| 87 | [[self window] selectPreviousKeyView:self]; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | - (void) windowWillClose:(NSNotification *)notification |
| 92 | { |
| 93 | [composerField setStringValue:@""]; |
| 94 | [composerField setNeedsDisplay:YES]; |
| 95 | } |
| 96 | |
| 97 | @end |