1 | /* |
---|
2 | * Estonian ID card plugin for web browsers |
---|
3 | * |
---|
4 | * Copyright (C) 2010-2011 Codeborne <info@codeborne.com> |
---|
5 | * |
---|
6 | * This is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the GNU Lesser General Public |
---|
8 | * License as published by the Free Software Foundation; either |
---|
9 | * version 2.1 of the License, or (at your option) any later version. |
---|
10 | * |
---|
11 | * This software 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 GNU |
---|
14 | * Lesser General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Lesser General Public |
---|
17 | * License along with this library; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | * |
---|
20 | */ |
---|
21 | |
---|
22 | #include "dialogs-cocoa.h" |
---|
23 | #include "dialogs.h" |
---|
24 | #include "PINPanel.h" |
---|
25 | #include "CertificateSelection.h" |
---|
26 | #include "esteid_log.h" |
---|
27 | |
---|
28 | char *cocoa_promptForPIN(NSWindow *window, const char *name, const char *message, unsigned minPin2Length, int usePinPad) { |
---|
29 | EstEID_log("parameters: window=%p, name=%s, message=%s, minPin2Length=%u, usePinPad=%i", window, name, message, minPin2Length, usePinPad); |
---|
30 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
---|
31 | PINPanel *pinPanel = [[PINPanel alloc] init]; |
---|
32 | char *pin = strdup([[pinPanel showForWindow: window withName: name withMessage: message withMinAcceptablePin2Length: minPin2Length usePinPad: usePinPad] UTF8String]); |
---|
33 | LOG_LOCATION; |
---|
34 | [pool release]; |
---|
35 | LOG_LOCATION; |
---|
36 | return pin; |
---|
37 | } |
---|
38 | |
---|
39 | void cocoa_showAlert(NSWindow *window, const char *message) { |
---|
40 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
---|
41 | NSAlert *alert = [[[NSAlert alloc] init] autorelease]; |
---|
42 | [alert addButtonWithTitle:@"OK"]; |
---|
43 | [alert setMessageText:[NSString stringWithUTF8String: message]]; |
---|
44 | [alert setAlertStyle:NSCriticalAlertStyle]; |
---|
45 | [alert beginSheetModalForWindow: window modalDelegate: nil didEndSelector: nil contextInfo: nil]; |
---|
46 | [pool release]; |
---|
47 | } |
---|
48 | |
---|
49 | int cocoa_promptForCertificate(void* nativeWindowHandle, char* certId) { |
---|
50 | LOG_LOCATION; |
---|
51 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
---|
52 | |
---|
53 | CertificateSelection *certificateSelection = [[CertificateSelection alloc] init]; |
---|
54 | NSString* selectedCertificateId = [certificateSelection showForWindow: nativeWindowHandle]; |
---|
55 | EstEID_log("selectedCertificate length = %u", [selectedCertificateId length]); |
---|
56 | strcpy(certId, [selectedCertificateId UTF8String]); |
---|
57 | int returnValue = IDOK; |
---|
58 | |
---|
59 | if (([selectedCertificateId length]) == 0) { |
---|
60 | returnValue = IDCANCEL; |
---|
61 | } |
---|
62 | [pool release]; |
---|
63 | return returnValue; |
---|
64 | } |
---|
65 | |
---|
66 | void closePinPadModalSheet() { |
---|
67 | LOG_LOCATION; |
---|
68 | [NSApp abortModal]; |
---|
69 | } |
---|