Debian Codegraph @

src/af/xap/cocoa/xap_CocoaDlg_Password.cpp

raw
1 /* AbiWord
2 * Copyright (C) 2000 AbiSource, Inc.
3 * Copyright (C) 2003 Hubert Figuiere
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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
18 * 02110-1301 USA.
19 */
20
21 #include <stdlib.h>
22 #include <time.h>
23
24 #include "ut_string.h"
25 #include "ut_assert.h"
26 #include "ut_debugmsg.h"
27
28 #include "xap_CocoaDialog_Utilities.h"
29
30 #include "xap_App.h"
31 #include "xap_CocoaApp.h"
32 #include "xap_CocoaFrame.h"
33
34 #include "xap_Strings.h"
35 #include "xap_Dialog_Id.h"
36 #include "xap_CocoaDlg_Password.h"
37
38 /*****************************************************************/
39 void XAP_CocoaDialog_Password::event_Ok ()
40 {
41 UT_UTF8String pass ([[m_dlg password] UTF8String]);
42
43 UT_DEBUGMSG(("ok: %s\n", pass.utf8_str()));
44
45 setPassword (pass);
46 setAnswer(XAP_Dialog_Password::a_OK);
47 [NSApp stopModal];
48 }
49
50 void XAP_CocoaDialog_Password::event_Cancel ()
51 {
52 UT_DEBUGMSG(("cancel\n"));
53 setAnswer(XAP_Dialog_Password::a_Cancel);
54 [NSApp stopModal];
55 }
56
57 XAP_Dialog * XAP_CocoaDialog_Password::static_constructor(XAP_DialogFactory * pFactory,
58 XAP_Dialog_Id dlgid)
59 {
60 XAP_CocoaDialog_Password * p = new XAP_CocoaDialog_Password(pFactory, dlgid);
61 return p;
62 }
63
64 XAP_CocoaDialog_Password::XAP_CocoaDialog_Password(XAP_DialogFactory * pDlgFactory,
65 XAP_Dialog_Id dlgid)
66 : XAP_Dialog_Password(pDlgFactory, dlgid)
67 {
68 }
69
70 XAP_CocoaDialog_Password::~XAP_CocoaDialog_Password(void)
71 {
72 }
73
74 void XAP_CocoaDialog_Password::runModal(XAP_Frame * /*pFrame*/)
75 {
76 m_dlg = [[XAP_CocoaDlg_PasswordController alloc] initFromNib];
77
78 // used similarly to convert between text and numeric arguments
79 [m_dlg setXAPOwner:this];
80
81 // build the dialog
82 NSWindow * window = [m_dlg window];
83 UT_ASSERT(window);
84
85 [NSApp runModalForWindow:window];
86
87 [m_dlg discardXAP];
88 [m_dlg close];
89 [m_dlg release];
90 m_dlg = nil;
91 }
92
93
94
95
96
97 @implementation XAP_CocoaDlg_PasswordController
98 - (id)initFromNib
99 {
100 if(![super initWithWindowNibName:@"xap_CocoaDlg_Password"]) {
101 return nil;
102 }
103 return self;
104 }
105
106 -(void)discardXAP
107 {
108 _xap = NULL;
109 }
110
111 -(void)dealloc
112 {
113 [super dealloc];
114 }
115
116 - (void)setXAPOwner:(XAP_Dialog *)owner
117 {
118 _xap = dynamic_cast<XAP_CocoaDialog_Password*>(owner);
119 }
120
121 -(void)windowDidLoad
122 {
123 if (_xap) {
124 const XAP_StringSet *pSS = XAP_App::getApp()->getStringSet();
125 LocalizeControl([self window], pSS, XAP_STRING_ID_DLG_Password_Title);
126 LocalizeControl(_okBtn, pSS, XAP_STRING_ID_DLG_OK);
127 LocalizeControl(_cancelBtn, pSS, XAP_STRING_ID_DLG_Cancel);
128 LocalizeControl(_passwordLabel, pSS, XAP_STRING_ID_DLG_Password_Password);
129 }
130 }
131
132 - (NSString*)password
133 {
134 return [_passwordData stringValue];
135 }
136
137 - (IBAction)cancelAction:(id)sender
138 {
139 UT_UNUSED(sender);
140 _xap->event_Cancel ();
141 }
142
143 - (IBAction)okAction:(id)sender
144 {
145 UT_UNUSED(sender);
146 _xap->event_Ok ();
147 }
148
149 @end