summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-18 08:24:17 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-18 08:24:42 +0300
commit7cd0223948d31662e2a31dd80f26f95a11daa98c (patch)
tree0efc34c40517c10c099f3a555643cc7347bb4a5b
parentf529e9d67a8b5c6e47895ea30d0e00eb28768233 (diff)
UploadWidget: Identity selection
-rw-r--r--src/ui/uploadwidget.c26
-rw-r--r--src/ui/util.c24
-rw-r--r--src/ui/util.h2
3 files changed, 33 insertions, 19 deletions
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c
index 1b26922c..ab1afae9 100644
--- a/src/ui/uploadwidget.c
+++ b/src/ui/uploadwidget.c
@@ -107,9 +107,11 @@ static void updateInputMaxHeight_UploadWidget_(iUploadWidget *d) {
107static const iArray *makeIdentityItems_UploadWidget_(const iUploadWidget *d) { 107static const iArray *makeIdentityItems_UploadWidget_(const iUploadWidget *d) {
108 iArray *items = collectNew_Array(sizeof(iMenuItem)); 108 iArray *items = collectNew_Array(sizeof(iMenuItem));
109 const iGmIdentity *urlId = identityForUrl_GmCerts(certs_App(), &d->url); 109 const iGmIdentity *urlId = identityForUrl_GmCerts(certs_App(), &d->url);
110 pushBack_Array(items, &(iMenuItem){ format_CStr("${dlg.upload.id.default} (%s)", 110 pushBack_Array(items,
111 urlId ? cstr_String(name_GmIdentity(urlId)) : "${dlg.upload.id.none}"), 111 &(iMenuItem){ format_CStr("${dlg.upload.id.default} (%s)",
112 0, 0, "upload.setid arg:1" }); 112 urlId ? cstr_String(name_GmIdentity(urlId))
113 : "${dlg.upload.id.none}"),
114 0, 0, "upload.setid arg:1" });
113 pushBack_Array(items, &(iMenuItem){ "${dlg.upload.id.none}", 0, 0, "upload.setid arg:0" }); 115 pushBack_Array(items, &(iMenuItem){ "${dlg.upload.id.none}", 0, 0, "upload.setid arg:0" });
114 pushBack_Array(items, &(iMenuItem){ "---" }); 116 pushBack_Array(items, &(iMenuItem){ "---" });
115 iConstForEach(PtrArray, i, listIdentities_GmCerts(certs_App(), NULL, NULL)) { 117 iConstForEach(PtrArray, i, listIdentities_GmCerts(certs_App(), NULL, NULL)) {
@@ -219,21 +221,31 @@ void init_UploadWidget(iUploadWidget *d) {
219 setFixedSize_Widget(as_Widget(d->mime), init_I2(70 * gap_UI, -1)); 221 setFixedSize_Widget(as_Widget(d->mime), init_I2(70 * gap_UI, -1));
220 addTwoColumnDialogInputField_Widget(headings, values, "${upload.mime}", "upload.mime", iClob(d->mime)); 222 addTwoColumnDialogInputField_Widget(headings, values, "${upload.mime}", "upload.mime", iClob(d->mime));
221 } 223 }
222 /* Token. */ { 224 /* Identity and Token. */ {
223 addChild_Widget(w, iClob(makePadding_Widget(gap_UI))); 225 addChild_Widget(w, iClob(makePadding_Widget(gap_UI)));
224 iWidget *page = makeTwoColumns_Widget(&headings, &values); 226 iWidget *page = makeTwoColumns_Widget(&headings, &values);
227 /* Token. */
225 d->token = addTwoColumnDialogInputField_Widget( 228 d->token = addTwoColumnDialogInputField_Widget(
226 headings, values, "${upload.token}", "upload.token", iClob(new_InputWidget(0))); 229 headings, values, "${upload.token}", "upload.token", iClob(new_InputWidget(0)));
227 setHint_InputWidget(d->token, "${hint.upload.token}"); 230 setHint_InputWidget(d->token, "${hint.upload.token}");
228 setFixedSize_Widget(as_Widget(d->token), init_I2(50 * gap_UI, -1)); 231 setFixedSize_Widget(as_Widget(d->token), init_I2(50 * gap_UI, -1));
232 /* Identity. */
233 const iArray * identItems = makeIdentityItems_UploadWidget_(d);
234 const iMenuItem *items = constData_Array(identItems);
235 const size_t numItems = size_Array(identItems);
236 iLabelWidget * ident = makeMenuButton_LabelWidget("${upload.id}", items, numItems);
237 setTextCStr_LabelWidget(ident, items[findWidestLabel_MenuItem(items, numItems)].label);
238 addChild_Widget(headings, iClob(makeHeading_Widget("${upload.id}")));
239 setId_Widget(addChildFlags_Widget(values, iClob(ident), alignLeft_WidgetFlag), "upload.id");
229 addChild_Widget(w, iClob(page)); 240 addChild_Widget(w, iClob(page));
230 } 241 }
231 /* Buttons. */ { 242 /* Buttons. */ {
232 addChild_Widget(w, iClob(makePadding_Widget(gap_UI))); 243 addChild_Widget(w, iClob(makePadding_Widget(gap_UI)));
233 iWidget *buttons = makeDialogButtons_Widget(actions, iElemCount(actions)); 244 iWidget *buttons = makeDialogButtons_Widget(actions, iElemCount(actions));
234 setId_Widget(insertChildAfterFlags_Widget(buttons, 245 setId_Widget(insertChildAfterFlags_Widget(buttons,
235 iClob(d->counter = new_LabelWidget("", NULL)), 246 iClob(d->counter = new_LabelWidget("", NULL)),
236 0, frameless_WidgetFlag), 247 0,
248 frameless_WidgetFlag),
237 "upload.counter"); 249 "upload.counter");
238 addChild_Widget(w, iClob(buttons)); 250 addChild_Widget(w, iClob(buttons));
239 } 251 }
diff --git a/src/ui/util.c b/src/ui/util.c
index 5361250f..01939e66 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1490,7 +1490,7 @@ iWidget *makeQuestion_Widget(const char *title, const char *msg,
1490 addChild_Widget(dlg->root->widget, iClob(dlg)); 1490 addChild_Widget(dlg->root->widget, iClob(dlg));
1491 arrange_Widget(dlg); /* BUG: This extra arrange shouldn't be needed but the dialog won't 1491 arrange_Widget(dlg); /* BUG: This extra arrange shouldn't be needed but the dialog won't
1492 be arranged correctly unless it's here. */ 1492 be arranged correctly unless it's here. */
1493 finalizeSheet_Mobile(dlg); 1493 setupSheetTransition_Mobile(dlg, iTrue);
1494 return dlg; 1494 return dlg;
1495} 1495}
1496 1496
@@ -1726,7 +1726,7 @@ static void addDialogToggle_(iWidget *headings, iWidget *values,
1726 addChild_Widget(values, iClob(makeToggle_Widget(toggleId))); 1726 addChild_Widget(values, iClob(makeToggle_Widget(toggleId)));
1727} 1727}
1728 1728
1729static size_t findWidestItemLabel_(const iMenuItem *items, size_t num) { 1729size_t findWidestLabel_MenuItem(const iMenuItem *items, size_t num) {
1730 int widest = 0; 1730 int widest = 0;
1731 size_t widestPos = iInvalidPos; 1731 size_t widestPos = iInvalidPos;
1732 for (size_t i = 0; i < num && items[i].label; i++) { 1732 for (size_t i = 0; i < num && items[i].label; i++) {
@@ -1947,10 +1947,10 @@ iWidget *makePreferences_Widget(void) {
1947 }; 1947 };
1948 iString *aboutText = collectNew_String(); { 1948 iString *aboutText = collectNew_String(); {
1949 setCStr_String(aboutText, "Lagrange " LAGRANGE_APP_VERSION); 1949 setCStr_String(aboutText, "Lagrange " LAGRANGE_APP_VERSION);
1950 #if defined (iPlatformAppleMobile) 1950#if defined (iPlatformAppleMobile)
1951 appendFormat_String(aboutText, " (" LAGRANGE_IOS_VERSION ") %s" LAGRANGE_IOS_BUILD_DATE, 1951 appendFormat_String(aboutText, " (" LAGRANGE_IOS_VERSION ") %s" LAGRANGE_IOS_BUILD_DATE,
1952 escape_Color(uiTextDim_ColorId)); 1952 escape_Color(uiTextDim_ColorId));
1953 #endif 1953#endif
1954 } 1954 }
1955 const iMenuItem aboutPanelItems[] = { 1955 const iMenuItem aboutPanelItems[] = {
1956 { format_CStr("heading text:%s", cstr_String(aboutText)) }, 1956 { format_CStr("heading text:%s", cstr_String(aboutText)) },
@@ -2015,7 +2015,7 @@ iWidget *makePreferences_Widget(void) {
2015 iArray *uiLangs = collectNew_Array(sizeof(iMenuItem)); 2015 iArray *uiLangs = collectNew_Array(sizeof(iMenuItem));
2016 pushBackN_Array(uiLangs, langItems, iElemCount(langItems) - 1); 2016 pushBackN_Array(uiLangs, langItems, iElemCount(langItems) - 1);
2017 /* TODO: Add an arrange flag for resizing parent to widest child. */ 2017 /* TODO: Add an arrange flag for resizing parent to widest child. */
2018 size_t widestPos = findWidestItemLabel_(data_Array(uiLangs), size_Array(uiLangs)); 2018 size_t widestPos = findWidestLabel_MenuItem(data_Array(uiLangs), size_Array(uiLangs));
2019 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.uilang}"))); 2019 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.uilang}")));
2020 setId_Widget(addChildFlags_Widget(values, 2020 setId_Widget(addChildFlags_Widget(values,
2021 iClob(makeMenuButton_LabelWidget( 2021 iClob(makeMenuButton_LabelWidget(
@@ -2034,7 +2034,7 @@ iWidget *makePreferences_Widget(void) {
2034 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.returnkey}"))); 2034 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.returnkey}")));
2035 /* Return key behaviors. */ { 2035 /* Return key behaviors. */ {
2036 iLabelWidget *returnKey = makeMenuButton_LabelWidget( 2036 iLabelWidget *returnKey = makeMenuButton_LabelWidget(
2037 returnKeyBehaviors[findWidestItemLabel_(returnKeyBehaviors, 2037 returnKeyBehaviors[findWidestLabel_MenuItem(returnKeyBehaviors,
2038 iElemCount(returnKeyBehaviors) - 1)] 2038 iElemCount(returnKeyBehaviors) - 1)]
2039 .label, 2039 .label,
2040 returnKeyBehaviors, 2040 returnKeyBehaviors,
@@ -2104,7 +2104,7 @@ iWidget *makePreferences_Widget(void) {
2104 const char *mode = isDark ? "dark" : "light"; 2104 const char *mode = isDark ? "dark" : "light";
2105 addChild_Widget(headings, iClob(makeHeading_Widget(isDark ? "${prefs.doctheme.dark}" : "${prefs.doctheme.light}"))); 2105 addChild_Widget(headings, iClob(makeHeading_Widget(isDark ? "${prefs.doctheme.dark}" : "${prefs.doctheme.light}")));
2106 iLabelWidget *button = makeMenuButton_LabelWidget( 2106 iLabelWidget *button = makeMenuButton_LabelWidget(
2107 docThemes[i][findWidestItemLabel_(docThemes[i], max_GmDocumentTheme)].label, 2107 docThemes[i][findWidestLabel_MenuItem(docThemes[i], max_GmDocumentTheme)].label,
2108 docThemes[i], 2108 docThemes[i],
2109 max_GmDocumentTheme); 2109 max_GmDocumentTheme);
2110 // setFrameColor_Widget(findChild_Widget(as_Widget(button), "menu"), 2110 // setFrameColor_Widget(findChild_Widget(as_Widget(button), "menu"),
@@ -2125,7 +2125,7 @@ iWidget *makePreferences_Widget(void) {
2125 /* Colorize images. */ { 2125 /* Colorize images. */ {
2126 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.imagestyle}"))); 2126 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.imagestyle}")));
2127 iLabelWidget *button = makeMenuButton_LabelWidget( 2127 iLabelWidget *button = makeMenuButton_LabelWidget(
2128 imgStyles[findWidestItemLabel_(imgStyles, iElemCount(imgStyles) - 1)].label, 2128 imgStyles[findWidestLabel_MenuItem(imgStyles, iElemCount(imgStyles) - 1)].label,
2129 imgStyles, 2129 imgStyles,
2130 iElemCount(imgStyles) - 1); 2130 iElemCount(imgStyles) - 1);
2131 setBackgroundColor_Widget(findChild_Widget(as_Widget(button), "menu"), 2131 setBackgroundColor_Widget(findChild_Widget(as_Widget(button), "menu"),
@@ -2254,7 +2254,8 @@ iWidget *makePreferences_Widget(void) {
2254 iClob(makeDialogButtons_Widget( 2254 iClob(makeDialogButtons_Widget(
2255 (iMenuItem[]){ { "${close}", SDLK_ESCAPE, 0, "prefs.dismiss" } }, 1))); 2255 (iMenuItem[]){ { "${close}", SDLK_ESCAPE, 0, "prefs.dismiss" } }, 1)));
2256 addChild_Widget(dlg->root->widget, iClob(dlg)); 2256 addChild_Widget(dlg->root->widget, iClob(dlg));
2257 finalizeSheet_Mobile(dlg); 2257// finalizeSheet_Mobile(dlg);
2258// arrange_Widget(dlg);
2258 setupSheetTransition_Mobile(dlg, iTrue); 2259 setupSheetTransition_Mobile(dlg, iTrue);
2259// printTree_Widget(dlg); 2260// printTree_Widget(dlg);
2260 return dlg; 2261 return dlg;
@@ -2312,7 +2313,7 @@ iWidget *makeBookmarkEditor_Widget(void) {
2312 addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); 2313 addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI)));
2313 addChild_Widget(dlg, iClob(makeDialogButtons_Widget(actions, iElemCount(actions)))); 2314 addChild_Widget(dlg, iClob(makeDialogButtons_Widget(actions, iElemCount(actions))));
2314 addChild_Widget(get_Root()->widget, iClob(dlg)); 2315 addChild_Widget(get_Root()->widget, iClob(dlg));
2315 finalizeSheet_Mobile(dlg); 2316 setupSheetTransition_Mobile(dlg, iTrue);
2316 return dlg; 2317 return dlg;
2317} 2318}
2318 2319
@@ -2509,7 +2510,6 @@ iWidget *makeIdentityCreation_Widget(void) {
2509 { "input collapse:1 id:ident.country hint:hint.newident.optional text:${dlg.newident.country}" }, 2510 { "input collapse:1 id:ident.country hint:hint.newident.optional text:${dlg.newident.country}" },
2510 { NULL } 2511 { NULL }
2511 }, actions, iElemCount(actions)); 2512 }, actions, iElemCount(actions));
2512 setupSheetTransition_Mobile(dlg, iTrue);
2513 } 2513 }
2514 else { 2514 else {
2515 dlg = makeSheet_Widget("ident"); 2515 dlg = makeSheet_Widget("ident");
@@ -2578,8 +2578,8 @@ iWidget *makeIdentityCreation_Widget(void) {
2578 } 2578 }
2579 addChild_Widget(dlg, iClob(makeDialogButtons_Widget(actions, iElemCount(actions)))); 2579 addChild_Widget(dlg, iClob(makeDialogButtons_Widget(actions, iElemCount(actions))));
2580 addChild_Widget(get_Root()->widget, iClob(dlg)); 2580 addChild_Widget(get_Root()->widget, iClob(dlg));
2581 finalizeSheet_Mobile(dlg);
2582 } 2581 }
2582 setupSheetTransition_Mobile(dlg, iTrue);
2583 return dlg; 2583 return dlg;
2584} 2584}
2585 2585
diff --git a/src/ui/util.h b/src/ui/util.h
index 938a200d..3dd4e153 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -232,6 +232,8 @@ void openMenu_Widget (iWidget *, iInt2 windowCoord);
232void openMenuFlags_Widget(iWidget *, iInt2 windowCoord, iBool postCommands); 232void openMenuFlags_Widget(iWidget *, iInt2 windowCoord, iBool postCommands);
233void closeMenu_Widget (iWidget *); 233void closeMenu_Widget (iWidget *);
234 234
235size_t findWidestLabel_MenuItem (const iMenuItem *items, size_t num);
236
235iLabelWidget * findMenuItem_Widget (iWidget *menu, const char *command); 237iLabelWidget * findMenuItem_Widget (iWidget *menu, const char *command);
236void setMenuItemDisabled_Widget (iWidget *menu, const char *command, iBool disable); 238void setMenuItemDisabled_Widget (iWidget *menu, const char *command, iBool disable);
237 239