summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/certimportwidget.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/ui/certimportwidget.c b/src/ui/certimportwidget.c
index 51743e89..c0f041b9 100644
--- a/src/ui/certimportwidget.c
+++ b/src/ui/certimportwidget.c
@@ -21,14 +21,19 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 21SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22 22
23#include "certimportwidget.h" 23#include "certimportwidget.h"
24#include "labelwidget.h" 24
25#include "inputwidget.h" 25#include "app.h"
26#include "color.h" 26#include "color.h"
27#include "command.h"
28#include "gmcerts.h"
29#include "inputwidget.h"
30#include "labelwidget.h"
27#include "text.h" 31#include "text.h"
28#include "ui/util.h" 32#include "ui/util.h"
29#include "app.h"
30 33
34#include <the_Foundation/file.h>
31#include <the_Foundation/tlsrequest.h> 35#include <the_Foundation/tlsrequest.h>
36#include <the_Foundation/path.h>
32#include <SDL_clipboard.h> 37#include <SDL_clipboard.h>
33 38
34iDefineObjectConstruction(CertImportWidget) 39iDefineObjectConstruction(CertImportWidget)
@@ -38,7 +43,6 @@ struct Impl_CertImportWidget {
38 iLabelWidget *info; 43 iLabelWidget *info;
39 iLabelWidget *crtLabel; 44 iLabelWidget *crtLabel;
40 iLabelWidget *keyLabel; 45 iLabelWidget *keyLabel;
41 iInputWidget *filename;
42 iInputWidget *notes; 46 iInputWidget *notes;
43 iTlsCertificate *cert; 47 iTlsCertificate *cert;
44}; 48};
@@ -137,13 +141,9 @@ void init_CertImportWidget(iCertImportWidget *d) {
137 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); 141 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
138 iWidget *values = addChildFlags_Widget( 142 iWidget *values = addChildFlags_Widget(
139 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); 143 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
140 addChild_Widget(headings, iClob(makeHeading_Widget("Save as:")));
141 addChild_Widget(values, iClob(d->filename = new_InputWidget(0)));
142 setHint_InputWidget(d->filename, "filename (no extension)");
143 addChild_Widget(headings, iClob(makeHeading_Widget("Notes:"))); 144 addChild_Widget(headings, iClob(makeHeading_Widget("Notes:")));
144 addChild_Widget(values, iClob(d->notes = new_InputWidget(0))); 145 addChild_Widget(values, iClob(d->notes = new_InputWidget(0)));
145 setHint_InputWidget(d->notes, "e.g., site name"); 146 setHint_InputWidget(d->notes, "description");
146 as_Widget(d->filename)->rect.size.x = gap_UI * 70;
147 as_Widget(d->notes)->rect.size.x = gap_UI * 70; 147 as_Widget(d->notes)->rect.size.x = gap_UI * 70;
148 } 148 }
149 addChild_Widget(w, iClob(page)); 149 addChild_Widget(w, iClob(page));
@@ -176,7 +176,7 @@ void setPageContent_CertImportWidget(iCertImportWidget *d, const iBlock *content
176 if (tryImport_CertImportWidget_(d, content)) { 176 if (tryImport_CertImportWidget_(d, content)) {
177 setTextCStr_LabelWidget(d->info, infoText_); 177 setTextCStr_LabelWidget(d->info, infoText_);
178 if (isComplete_CertImportWidget_(d)) { 178 if (isComplete_CertImportWidget_(d)) {
179 setFocus_Widget(as_Widget(d->filename)); 179 setFocus_Widget(as_Widget(d->notes));
180 } 180 }
181 } 181 }
182 else { 182 else {
@@ -206,9 +206,29 @@ static iBool processEvent_CertImportWidget_(iCertImportWidget *d, const SDL_Even
206 return iTrue; 206 return iTrue;
207 } 207 }
208 if (isCommand_Widget(w, ev, "certimport.accept")) { 208 if (isCommand_Widget(w, ev, "certimport.accept")) {
209 if (d->cert) { 209 if (d->cert && !isEmpty_TlsCertificate(d->cert) && hasPrivateKey_TlsCertificate(d->cert)) {
210 importIdentity_GmCerts(certs_App(), d->cert, text_InputWidget(d->notes));
211 d->cert = NULL; /* taken */
210 destroy_Widget(w); 212 destroy_Widget(w);
213 postCommand_App("idents.changed");
214 }
215 return iTrue;
216 }
217 if (ev->type == SDL_DROPFILE) {
218 const iString *name = collectNewCStr_String(ev->drop.file);
219 iFile *f = new_File(name);
220 if (open_File(f, readOnly_FileMode | text_FileMode)) {
221 if (tryImport_CertImportWidget_(d, collect_Block(readAll_File(f)))) {
222 if (isComplete_CertImportWidget_(d)) {
223 setFocus_Widget(as_Widget(d->notes));
224 }
225 }
226 else {
227 makeMessage_Widget(uiTextCaution_ColorEscape "DROPPED FILE",
228 "No certificate or private key was found.");
229 }
211 } 230 }
231 iRelease(f);
212 return iTrue; 232 return iTrue;
213 } 233 }
214 return processEvent_Widget(w, ev); 234 return processEvent_Widget(w, ev);