source: murachi/esteidfirefoxplugin/common/PINPanel.m @ 28fc3c9

Last change on this file since 28fc3c9 was 7d3ae3e, checked in by antonioaraujob <aaraujo@…>, 9 years ago

Agregados archivos fuentes del complemento esteidfirefoxplugin de Estonia para firmar electrónicamente un hash.

  • Property mode set to 100644
File size: 4.2 KB
Line 
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#import "PINPanel.h"
23
24#include "esteid_log.h"
25#include "l10n.h"
26
27@implementation PINPanel
28@synthesize okButton, cancelButton, countdownTimer, progressBar;
29
30- (void)dealloc {
31        LOG_LOCATION;
32        [[NSNotificationCenter defaultCenter] removeObserver:self];
33        [super dealloc];
34}
35
36- (void) awakeFromNib {
37        LOG_LOCATION;
38        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pinFieldDidChange:) name:NSControlTextDidChangeNotification object:nil];
39}
40
41- (IBAction)okClicked:(id)pId
42{
43        cancelled = FALSE;
44        [NSApp stopModal];
45}
46
47- (IBAction)cancelClicked:(id)pId
48{
49        cancelled = TRUE;
50        [NSApp abortModal];
51}
52
53- (void)pinFieldDidChange:(NSNotification*)aNotification;
54{
55        [okButton setEnabled:([[[aNotification object] stringValue] length] >= minAcceptablePin2Length)];
56}
57
58- (void)doCountdown
59{
60        if (countdownTimer) {
61                return;
62        }
63        remainingTicks = 30;
64        [self updateProgressBar];
65        [progressBar startAnimation: self];
66        countdownTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(handleTimerTick) userInfo: nil repeats: YES];
67}
68
69- (void)handleTimerTick
70{
71        remainingTicks--;
72        [self updateProgressBar];       
73        if (remainingTicks <= 0) {
74                [countdownTimer invalidate];
75                [progressBar stopAnimation: self];
76                countdownTimer = nil;
77                EstEID_log("PIN pad countdown timer reached 0");
78        }
79}
80
81- (void)updateProgressBar
82{
83        [progressBar setDoubleValue:(double)remainingTicks];
84}
85
86- (NSString *)showForWindow:(NSWindow *)window withName:(const char *)name withMessage:(const char *)message withMinAcceptablePin2Length:(unsigned)minPin2Length usePinPad:(int)usePinPad
87{
88        EstEID_log("parameters: withName=%s, withMessage=%s, withMinAcceptablePin2Length=%u, usePinPad=%i", name, message, minPin2Length, usePinPad);           
89       
90        if(usePinPad) {
91                [NSBundle loadNibNamed: @"PINPadMessageBox" owner: self];
92                [pinFieldLabel setTitleWithMnemonic:[NSString stringWithUTF8String: l10n("For signing enter PIN2 from PIN pad")]];
93                [messageField setTitleWithMnemonic: (message && message[0]) ? [NSString stringWithUTF8String: message] : @""];
94               
95                [self doCountdown];
96                [[NSRunLoop currentRunLoop] addTimer:countdownTimer forMode:NSModalPanelRunLoopMode];
97               
98        }else{
99                minAcceptablePin2Length = minPin2Length;
100                EstEID_log("minAcceptablePin2Length set to %u", minAcceptablePin2Length);
101                if (message && message[0]) {
102                        [NSBundle loadNibNamed: @"PINDialogWithMessage" owner: self];
103                        [messageField setTitleWithMnemonic: [NSString stringWithUTF8String: message]];
104                }
105                else {
106                        [NSBundle loadNibNamed: @"PINDialog" owner: self];
107                }
108
109                [pinFieldLabel setTitleWithMnemonic:[NSString stringWithUTF8String: l10n("For signing enter PIN2:")]];
110                [okButton setTitle:[NSString stringWithUTF8String:l10n("Sign")]];
111                [cancelButton setTitle:[NSString stringWithUTF8String:l10n("Cancel")]];
112        }
113        [nameLabel setTitleWithMnemonic: [NSString stringWithUTF8String: name]];
114       
115        [NSApp beginSheet: pinPanel modalForWindow: window modalDelegate: nil didEndSelector: nil contextInfo: nil];
116        EstEID_log("starting modal sheet (%s)", usePinPad ? "pinpad": "card reader");
117        [pinPanel setTitle:[NSString stringWithUTF8String:l10n("Sign")]];
118        [NSApp runModalForWindow: pinPanel];
119        EstEID_log("modal sheet ended");
120        [NSApp endSheet: pinPanel];
121        [pinPanel orderOut: self];     
122
123        if (countdownTimer) {
124                [countdownTimer invalidate];
125                countdownTimer = nil;
126        }
127
128        if(usePinPad) {
129                LOG_LOCATION;
130                return @"";
131        }
132        LOG_LOCATION;
133        return cancelled ? @"" : [pinField stringValue];
134}
135
136@end
Note: See TracBrowser for help on using the repository browser.