summaryrefslogtreecommitdiff
path: root/src/ui/uploadwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/uploadwidget.c')
-rw-r--r--src/ui/uploadwidget.c45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c
index 90df1958..bad00071 100644
--- a/src/ui/uploadwidget.c
+++ b/src/ui/uploadwidget.c
@@ -45,7 +45,7 @@ iDefineObjectConstruction(UploadWidget)
45 45
46enum iUploadIdentity { 46enum iUploadIdentity {
47 none_UploadIdentity, 47 none_UploadIdentity,
48 defaultForUrl_UploadIdentity, 48 defaultForSite_UploadIdentity,
49 dropdown_UploadIdentity, 49 dropdown_UploadIdentity,
50}; 50};
51 51
@@ -104,9 +104,16 @@ static void updateInputMaxHeight_UploadWidget_(iUploadWidget *d) {
104 (avail - inputPos.y) / lineHeight_Text(font_InputWidget(d->input)))); 104 (avail - inputPos.y) / lineHeight_Text(font_InputWidget(d->input))));
105} 105}
106 106
107static const iGmIdentity *titanIdentityForUrl_(const iString *url) {
108 return findIdentity_GmCerts(
109 certs_App(),
110 collect_Block(hexDecode_Rangecc(range_String(valueString_SiteSpec(
111 collectNewRange_String(urlRoot_String(url)), titanIdentity_SiteSpecKey)))));
112}
113
107static const iArray *makeIdentityItems_UploadWidget_(const iUploadWidget *d) { 114static const iArray *makeIdentityItems_UploadWidget_(const iUploadWidget *d) {
108 iArray *items = collectNew_Array(sizeof(iMenuItem)); 115 iArray *items = collectNew_Array(sizeof(iMenuItem));
109 const iGmIdentity *urlId = identityForUrl_GmCerts(certs_App(), &d->url); 116 const iGmIdentity *urlId = titanIdentityForUrl_(&d->url);
110 pushBack_Array(items, 117 pushBack_Array(items,
111 &(iMenuItem){ format_CStr("${dlg.upload.id.default} (%s)", 118 &(iMenuItem){ format_CStr("${dlg.upload.id.default} (%s)",
112 urlId ? cstr_String(name_GmIdentity(urlId)) 119 urlId ? cstr_String(name_GmIdentity(urlId))
@@ -147,7 +154,7 @@ void init_UploadWidget(iUploadWidget *d) {
147 d->request = NULL; 154 d->request = NULL;
148 init_String(&d->filePath); 155 init_String(&d->filePath);
149 d->fileSize = 0; 156 d->fileSize = 0;
150 d->idMode = defaultForUrl_UploadIdentity; 157 d->idMode = defaultForSite_UploadIdentity;
151 init_Block(&d->idFingerprint, 0); 158 init_Block(&d->idFingerprint, 0);
152 const iMenuItem actions[] = { 159 const iMenuItem actions[] = {
153 { "${upload.port}", 0, 0, "upload.setport" }, 160 { "${upload.port}", 0, 0, "upload.setport" },
@@ -289,16 +296,22 @@ void deinit_UploadWidget(iUploadWidget *d) {
289 296
290static void remakeIdentityItems_UploadWidget_(iUploadWidget *d) { 297static void remakeIdentityItems_UploadWidget_(iUploadWidget *d) {
291 iWidget *dropMenu = findChild_Widget(findChild_Widget(as_Widget(d), "upload.id"), "menu"); 298 iWidget *dropMenu = findChild_Widget(findChild_Widget(as_Widget(d), "upload.id"), "menu");
292 releaseChildren_Widget(dropMenu);
293 const iArray *items = makeIdentityItems_UploadWidget_(d); 299 const iArray *items = makeIdentityItems_UploadWidget_(d);
294 makeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items)); 300 /* TODO: Make the following a utility method. */
301 if (flags_Widget(dropMenu) & nativeMenu_WidgetFlag) {
302 setNativeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items));
303 }
304 else {
305 releaseChildren_Widget(dropMenu);
306 makeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items));
307 }
295} 308}
296 309
297static void updateIdentityDropdown_UploadWidget_(iUploadWidget *d) { 310static void updateIdentityDropdown_UploadWidget_(iUploadWidget *d) {
298 updateDropdownSelection_LabelWidget( 311 updateDropdownSelection_LabelWidget(
299 findChild_Widget(as_Widget(d), "upload.id"), 312 findChild_Widget(as_Widget(d), "upload.id"),
300 d->idMode == none_UploadIdentity ? " arg:0" 313 d->idMode == none_UploadIdentity ? " arg:0"
301 : d->idMode == defaultForUrl_UploadIdentity 314 : d->idMode == defaultForSite_UploadIdentity
302 ? " arg:1" 315 ? " arg:1"
303 : format_CStr(" fp:%s", cstrCollect_String(hexEncode_Block(&d->idFingerprint)))); 316 : format_CStr(" fp:%s", cstrCollect_String(hexEncode_Block(&d->idFingerprint))));
304} 317}
@@ -422,7 +435,7 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
422 } 435 }
423 else if (arg_Command(cmd)) { 436 else if (arg_Command(cmd)) {
424 clear_Block(&d->idFingerprint); 437 clear_Block(&d->idFingerprint);
425 d->idMode = defaultForUrl_UploadIdentity; 438 d->idMode = defaultForSite_UploadIdentity;
426 } 439 }
427 else { 440 else {
428 clear_Block(&d->idFingerprint); 441 clear_Block(&d->idFingerprint);
@@ -452,19 +465,27 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
452 setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_); 465 setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_);
453 setUserData_Object(d->request, d); 466 setUserData_Object(d->request, d);
454 setUrl_GmRequest(d->request, &d->url); 467 setUrl_GmRequest(d->request, &d->url);
468 const iString *site = collectNewRange_String(urlRoot_String(&d->url));
455 switch (d->idMode) { 469 switch (d->idMode) {
456 case defaultForUrl_UploadIdentity:
457 break; /* GmRequest handles it */
458 case none_UploadIdentity: 470 case none_UploadIdentity:
459 setIdentity_GmRequest(d->request, NULL); 471 /* Ensure no identity will be used for this specific URL. */
460 signOut_GmCerts(certs_App(), url_GmRequest(d->request)); 472 signOut_GmCerts(certs_App(), url_GmRequest(d->request));
473 setValueString_SiteSpec(site, titanIdentity_SiteSpecKey, collectNew_String());
461 break; 474 break;
462 case dropdown_UploadIdentity: { 475 case dropdown_UploadIdentity: {
463 iGmIdentity *ident = findIdentity_GmCerts(certs_App(), &d->idFingerprint); 476 iGmIdentity *ident = findIdentity_GmCerts(certs_App(), &d->idFingerprint);
464 setIdentity_GmRequest(d->request, ident); 477 if (ident) {
465 signIn_GmCerts(certs_App(), ident, url_GmRequest(d->request)); 478 setValueString_SiteSpec(site,
479 titanIdentity_SiteSpecKey,
480 collect_String(hexEncode_Block(&ident->fingerprint)));
481 }
466 break; 482 break;
467 } 483 }
484 default:
485 break;
486 }
487 if (d->idMode != none_UploadIdentity) {
488 setIdentity_GmRequest(d->request, titanIdentityForUrl_(&d->url));
468 } 489 }
469 if (isText) { 490 if (isText) {
470 /* Uploading text. */ 491 /* Uploading text. */