summaryrefslogtreecommitdiff
path: root/src/ui/certimportwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/certimportwidget.c')
-rw-r--r--src/ui/certimportwidget.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/ui/certimportwidget.c b/src/ui/certimportwidget.c
index c0f041b9..0c1cf674 100644
--- a/src/ui/certimportwidget.c
+++ b/src/ui/certimportwidget.c
@@ -151,17 +151,18 @@ void init_CertImportWidget(iCertImportWidget *d) {
151 setSize_Widget(as_Widget(d->crtLabel), init_I2(width_Widget(w) - 6.5 * gap_UI, gap_UI * 12)); 151 setSize_Widget(as_Widget(d->crtLabel), init_I2(width_Widget(w) - 6.5 * gap_UI, gap_UI * 12));
152 setSize_Widget(as_Widget(d->keyLabel), init_I2(width_Widget(w) - 6.5 * gap_UI, gap_UI * 12)); 152 setSize_Widget(as_Widget(d->keyLabel), init_I2(width_Widget(w) - 6.5 * gap_UI, gap_UI * 12));
153 /* Buttons. */ 153 /* Buttons. */
154 iWidget *div = new_Widget(); { 154 addChild_Widget(w, iClob(makePadding_Widget(gap_UI)));
155 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); 155 iWidget *buttons = makeDialogButtons_Widget(
156 addChild_Widget(div, iClob(newKeyMods_LabelWidget("Cancel", SDLK_ESCAPE, 0, "cancel"))); 156 (iMenuItem[]){
157 iLabelWidget *accept = addChild_Widget( 157 { "Cancel", 0, 0, NULL },
158 div, 158 { uiTextAction_ColorEscape "Import", SDLK_RETURN, KMOD_PRIMARY, "certimport.accept" } },
159 iClob(newKeyMods_LabelWidget( 159 2);
160 uiTextAction_ColorEscape "Import", SDLK_RETURN, KMOD_PRIMARY, "certimport.accept"))); 160 addChild_Widget(w, iClob(buttons));
161 setFont_LabelWidget(accept, uiLabelBold_FontId);
162 }
163 addChild_Widget(w, iClob(div));
164 arrange_Widget(w); 161 arrange_Widget(w);
162 if (deviceType_App() != desktop_AppDeviceType) {
163 /* Try auto-pasting. */
164 postCommand_App("certimport.paste");
165 }
165} 166}
166 167
167void deinit_CertImportWidget(iCertImportWidget *d) { 168void deinit_CertImportWidget(iCertImportWidget *d) {
@@ -186,14 +187,17 @@ void setPageContent_CertImportWidget(iCertImportWidget *d, const iBlock *content
186 arrange_Widget(as_Widget(d)); 187 arrange_Widget(as_Widget(d));
187} 188}
188 189
190static iBool tryImportFromClipboard_CertImportWidget_(iCertImportWidget *d) {
191 return tryImport_CertImportWidget_(d, collect_Block(newCStr_Block(SDL_GetClipboardText())));
192}
193
189static iBool processEvent_CertImportWidget_(iCertImportWidget *d, const SDL_Event *ev) { 194static iBool processEvent_CertImportWidget_(iCertImportWidget *d, const SDL_Event *ev) {
190 iWidget *w = as_Widget(d); 195 iWidget *w = as_Widget(d);
191 if (ev->type == SDL_KEYDOWN) { 196 if (ev->type == SDL_KEYDOWN) {
192 const int key = ev->key.keysym.sym; 197 const int key = ev->key.keysym.sym;
193 const int mods = keyMods_Sym(ev->key.keysym.mod); 198 const int mods = keyMods_Sym(ev->key.keysym.mod);
194 if (key == SDLK_v && mods == KMOD_PRIMARY) { 199 if (key == SDLK_v && mods == KMOD_PRIMARY) {
195 if (!tryImport_CertImportWidget_( 200 if (!tryImportFromClipboard_CertImportWidget_(d)) {
196 d, collect_Block(newCStr_Block(SDL_GetClipboardText())))) {
197 makeMessage_Widget(uiTextCaution_ColorEscape "PASTED FROM CLIPBOARD", 201 makeMessage_Widget(uiTextCaution_ColorEscape "PASTED FROM CLIPBOARD",
198 "No certificate or private key was found."); 202 "No certificate or private key was found.");
199 } 203 }
@@ -201,6 +205,10 @@ static iBool processEvent_CertImportWidget_(iCertImportWidget *d, const SDL_Even
201 return iTrue; 205 return iTrue;
202 } 206 }
203 } 207 }
208 if (isCommand_UserEvent(ev, "certimport.paste")) {
209 tryImportFromClipboard_CertImportWidget_(d);
210 return iTrue;
211 }
204 if (isCommand_Widget(w, ev, "cancel")) { 212 if (isCommand_Widget(w, ev, "cancel")) {
205 destroy_Widget(w); 213 destroy_Widget(w);
206 return iTrue; 214 return iTrue;