summaryrefslogtreecommitdiff
path: root/src/ui/uploadwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-11 07:43:57 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-11 07:43:57 +0300
commit1410bbde7779efe3a20f603523547c8b8f55b6a1 (patch)
tree54e8ab43ea6d3dc35d7993b6909096c6c8429e50 /src/ui/uploadwidget.c
parent61c23be799956615ceeeda10aaeccc2bb11e9c94 (diff)
Mobile: Many UI improvements; Upload UI
Diffstat (limited to 'src/ui/uploadwidget.c')
-rw-r--r--src/ui/uploadwidget.c188
1 files changed, 110 insertions, 78 deletions
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c
index 4c72c60a..fb8aaf0a 100644
--- a/src/ui/uploadwidget.c
+++ b/src/ui/uploadwidget.c
@@ -81,91 +81,122 @@ void init_UploadWidget(iUploadWidget *d) {
81 iWidget *w = as_Widget(d); 81 iWidget *w = as_Widget(d);
82 init_Widget(w); 82 init_Widget(w);
83 setId_Widget(w, "upload"); 83 setId_Widget(w, "upload");
84 useSheetStyle_Widget(w);
85 init_String(&d->originalUrl); 84 init_String(&d->originalUrl);
86 init_String(&d->url); 85 init_String(&d->url);
87 d->viewer = NULL; 86 d->viewer = NULL;
88 d->request = NULL; 87 d->request = NULL;
89 init_String(&d->filePath); 88 init_String(&d->filePath);
90 d->fileSize = 0; 89 d->fileSize = 0;
91 addChildFlags_Widget(w, 90 const iMenuItem actions[] = {
92 iClob(new_LabelWidget(uiHeading_ColorEscape "${heading.upload}", NULL)), 91 { "${upload.port}", 0, 0, "upload.setport" },
93 frameless_WidgetFlag); 92 { "---" },
94 d->info = addChildFlags_Widget(w, iClob(new_LabelWidget("", NULL)), 93 { "${close}", SDLK_ESCAPE, 0, "upload.cancel" },
95 frameless_WidgetFlag | resizeToParentWidth_WidgetFlag | 94 { uiTextAction_ColorEscape "${dlg.upload.send}", SDLK_RETURN, KMOD_PRIMARY, "upload.accept" }
96 fixedHeight_WidgetFlag); 95 };
97 setWrap_LabelWidget(d->info, iTrue); 96 if (isUsingPanelLayout_Mobile()) {
98 /* Tabs for input data. */ 97 const iMenuItem textItems[] = {
99 iWidget *tabs = makeTabs_Widget(w); 98 { "title id:heading.upload.text" },
100 /* Make the tabs support vertical expansion based on content. */ { 99 { "input id:upload.text noheading:1" },
101 setFlags_Widget(tabs, resizeHeightOfChildren_WidgetFlag, iFalse); 100 { NULL }
102 setFlags_Widget(tabs, arrangeHeight_WidgetFlag, iTrue); 101 };
103 iWidget *tabPages = findChild_Widget(tabs, "tabs.pages"); 102 const iMenuItem fileItems[] = {
104 setFlags_Widget(tabPages, resizeHeightOfChildren_WidgetFlag, iFalse); 103 { "title id:heading.upload.file" },
105 setFlags_Widget(tabPages, arrangeHeight_WidgetFlag, iTrue); 104 { "button text:" uiTextAction_ColorEscape "${dlg.upload.pickfile}", 0, 0, "upload.pickfile" },
105 { "heading id:upload.file.name" },
106 { "label id:upload.filepathlabel" },
107 { "heading id:upload.file.size" },
108 { "label id:upload.filesizelabel" },
109 { "padding" },
110 { "input id:upload.mime" },
111 { "label id:upload.counter text:" },
112 { NULL }
113 };
114 initPanels_Mobile(w, NULL, (iMenuItem[]){
115 { "title id:heading.upload" },
116 { "label id:upload.info" },
117// { "padding" },
118 { "panel id:dlg.upload.text icon:0x1f5b9", 0, 0, (const void *) textItems },
119 { "panel id:dlg.upload.file icon:0x1f4c1", 0, 0, (const void *) fileItems },
120 { "padding" },
121 { "input id:upload.token hint:hint.upload.token" },
122 { NULL }
123 }, actions, iElemCount(actions));
124 d->info = findChild_Widget(w, "upload.info");
125 d->input = findChild_Widget(w, "upload.text");
126 d->filePathLabel = findChild_Widget(w, "upload.file.name");
127 d->fileSizeLabel = findChild_Widget(w, "upload.file.size");
128 d->mime = findChild_Widget(w, "upload.mime");
129 d->token = findChild_Widget(w, "upload.token");
130 d->counter = findChild_Widget(w, "upload.counter");
106 } 131 }
107 iWidget *headings, *values; 132 else {
108 setBackgroundColor_Widget(findChild_Widget(tabs, "tabs.buttons"), uiBackgroundSidebar_ColorId); 133 useSheetStyle_Widget(w);
109 setId_Widget(tabs, "upload.tabs"); 134 addChildFlags_Widget(w,
110// const int bigGap = lineHeight_Text(uiLabel_FontId) * 3 / 4; 135 iClob(new_LabelWidget(uiHeading_ColorEscape "${heading.upload}", NULL)),
111 /* Text input. */ { 136 frameless_WidgetFlag);
112 //appendTwoColumnTabPage_Widget(tabs, "${heading.upload.text}", '1', &headings, &values); 137 d->info = addChildFlags_Widget(w, iClob(new_LabelWidget("", NULL)),
113 iWidget *page = new_Widget(); 138 frameless_WidgetFlag | resizeToParentWidth_WidgetFlag |
114 setFlags_Widget(page, arrangeSize_WidgetFlag, iTrue); 139 fixedHeight_WidgetFlag);
115 d->input = new_InputWidget(0); 140 setWrap_LabelWidget(d->info, iTrue);
116 setId_Widget(as_Widget(d->input), "upload.text"); 141 /* Tabs for input data. */
117 setFont_InputWidget(d->input, monospace_FontId); 142 iWidget *tabs = makeTabs_Widget(w);
118 setLineLimits_InputWidget(d->input, 7, 20); 143 /* Make the tabs support vertical expansion based on content. */ {
119 setUseReturnKeyBehavior_InputWidget(d->input, iFalse); /* traditional text editor */ 144 setFlags_Widget(tabs, resizeHeightOfChildren_WidgetFlag, iFalse);
120 setHint_InputWidget(d->input, "${hint.upload.text}"); 145 setFlags_Widget(tabs, arrangeHeight_WidgetFlag, iTrue);
121 setFixedSize_Widget(as_Widget(d->input), init_I2(120 * gap_UI, -1)); 146 iWidget *tabPages = findChild_Widget(tabs, "tabs.pages");
122 addChild_Widget(page, iClob(d->input)); 147 setFlags_Widget(tabPages, resizeHeightOfChildren_WidgetFlag, iFalse);
123 appendFramelessTabPage_Widget(tabs, iClob(page), "${heading.upload.text}", '1', 0); 148 setFlags_Widget(tabPages, arrangeHeight_WidgetFlag, iTrue);
124 } 149 }
125 /* File content. */ { 150 iWidget *headings, *values;
126 appendTwoColumnTabPage_Widget(tabs, "${heading.upload.file}", '2', &headings, &values); 151 setBackgroundColor_Widget(findChild_Widget(tabs, "tabs.buttons"), uiBackgroundSidebar_ColorId);
127// iWidget *pad = addChild_Widget(headings, iClob(makePadding_Widget(0))); 152 setId_Widget(tabs, "upload.tabs");
128// iWidget *hint = addChild_Widget(values, iClob(new_LabelWidget("${upload.file.drophint}", NULL))); 153 /* Text input. */ {
129// pad->sizeRef = hint; 154 iWidget *page = new_Widget();
130 addChildFlags_Widget(headings, iClob(new_LabelWidget("${upload.file.name}", NULL)), frameless_WidgetFlag); 155 setFlags_Widget(page, arrangeSize_WidgetFlag, iTrue);
131 d->filePathLabel = addChildFlags_Widget(values, iClob(new_LabelWidget(uiTextAction_ColorEscape "${upload.file.drophere}", NULL)), frameless_WidgetFlag); 156 d->input = new_InputWidget(0);
132 addChildFlags_Widget(headings, iClob(new_LabelWidget("${upload.file.size}", NULL)), frameless_WidgetFlag); 157 setId_Widget(as_Widget(d->input), "upload.text");
133 d->fileSizeLabel = addChildFlags_Widget(values, iClob(new_LabelWidget("\u2014", NULL)), frameless_WidgetFlag); 158 setFixedSize_Widget(as_Widget(d->input), init_I2(120 * gap_UI, -1));
134 d->mime = new_InputWidget(0); 159 addChild_Widget(page, iClob(d->input));
135 setFixedSize_Widget(as_Widget(d->mime), init_I2(70 * gap_UI, -1)); 160 appendFramelessTabPage_Widget(tabs, iClob(page), "${heading.upload.text}", '1', 0);
136 addTwoColumnDialogInputField_Widget(headings, values, "${upload.mime}", "upload.mime", iClob(d->mime)); 161 }
137 } 162 /* File content. */ {
138 /* Token. */ { 163 appendTwoColumnTabPage_Widget(tabs, "${heading.upload.file}", '2', &headings, &values);
139 addChild_Widget(w, iClob(makePadding_Widget(gap_UI))); 164 addChildFlags_Widget(headings, iClob(new_LabelWidget("${upload.file.name}", NULL)), frameless_WidgetFlag);
140 iWidget *page = makeTwoColumns_Widget(&headings, &values); 165 d->filePathLabel = addChildFlags_Widget(values, iClob(new_LabelWidget(uiTextAction_ColorEscape "${upload.file.drophere}", NULL)), frameless_WidgetFlag);
141 d->token = addTwoColumnDialogInputField_Widget( 166 addChildFlags_Widget(headings, iClob(new_LabelWidget("${upload.file.size}", NULL)), frameless_WidgetFlag);
142 headings, values, "${upload.token}", "upload.token", iClob(new_InputWidget(0))); 167 d->fileSizeLabel = addChildFlags_Widget(values, iClob(new_LabelWidget("\u2014", NULL)), frameless_WidgetFlag);
143 setHint_InputWidget(d->token, "${hint.upload.token}"); 168 d->mime = new_InputWidget(0);
144 setFixedSize_Widget(as_Widget(d->token), init_I2(50 * gap_UI, -1)); 169 setFixedSize_Widget(as_Widget(d->mime), init_I2(70 * gap_UI, -1));
145 addChild_Widget(w, iClob(page)); 170 addTwoColumnDialogInputField_Widget(headings, values, "${upload.mime}", "upload.mime", iClob(d->mime));
146 } 171 }
147 /* Buttons. */ { 172 /* Token. */ {
148 addChild_Widget(w, iClob(makePadding_Widget(gap_UI))); 173 addChild_Widget(w, iClob(makePadding_Widget(gap_UI)));
149 iWidget *buttons = 174 iWidget *page = makeTwoColumns_Widget(&headings, &values);
150 makeDialogButtons_Widget((iMenuItem[]){ { "${upload.port}", 0, 0, "upload.setport" }, 175 d->token = addTwoColumnDialogInputField_Widget(
151 { "---" }, 176 headings, values, "${upload.token}", "upload.token", iClob(new_InputWidget(0)));
152 { "${close}", SDLK_ESCAPE, 0, "upload.cancel" }, 177 setHint_InputWidget(d->token, "${hint.upload.token}");
153 { uiTextAction_ColorEscape "${dlg.upload.send}", 178 setFixedSize_Widget(as_Widget(d->token), init_I2(50 * gap_UI, -1));
154 SDLK_RETURN, 179 addChild_Widget(w, iClob(page));
155 KMOD_PRIMARY, 180 }
156 "upload.accept" } }, 181 /* Buttons. */ {
157 4); 182 addChild_Widget(w, iClob(makePadding_Widget(gap_UI)));
158 setId_Widget(insertChildAfterFlags_Widget(buttons, 183 iWidget *buttons = makeDialogButtons_Widget(actions, iElemCount(actions));
159 iClob(d->counter = new_LabelWidget("", NULL)), 184 setId_Widget(insertChildAfterFlags_Widget(buttons,
160 0, frameless_WidgetFlag), 185 iClob(d->counter = new_LabelWidget("", NULL)),
161 "upload.counter"); 186 0, frameless_WidgetFlag),
162 addChild_Widget(w, iClob(buttons)); 187 "upload.counter");
188 addChild_Widget(w, iClob(buttons));
189 }
190 resizeToLargestPage_Widget(tabs);
191 arrange_Widget(w);
192 setFixedSize_Widget(as_Widget(d->token), init_I2(width_Widget(tabs) - left_Rect(parent_Widget(d->token)->rect), -1));
193 setFlags_Widget(as_Widget(d->token), expand_WidgetFlag, iTrue);
194 setFocus_Widget(as_Widget(d->input));
163 } 195 }
164 resizeToLargestPage_Widget(tabs); 196 setFont_InputWidget(d->input, monospace_FontId);
165 arrange_Widget(w); 197 setUseReturnKeyBehavior_InputWidget(d->input, iFalse); /* traditional text editor */
166 setFixedSize_Widget(as_Widget(d->token), init_I2(width_Widget(tabs) - left_Rect(parent_Widget(d->token)->rect), -1)); 198 setLineLimits_InputWidget(d->input, 7, 20);
167 setFlags_Widget(as_Widget(d->token), expand_WidgetFlag, iTrue); 199 setHint_InputWidget(d->input, "${hint.upload.text}");
168 setFocus_Widget(as_Widget(d->input));
169 setBackupFileName_InputWidget(d->input, "uploadbackup.txt"); 200 setBackupFileName_InputWidget(d->input, "uploadbackup.txt");
170 updateInputMaxHeight_UploadWidget_(d); 201 updateInputMaxHeight_UploadWidget_(d);
171} 202}
@@ -201,6 +232,7 @@ static void setUrlPort_UploadWidget_(iUploadWidget *d, const iString *url, uint1
201 appendFormat_String(&d->url, ":%u", overridePort ? overridePort : titanPortForUrl_(url)); 232 appendFormat_String(&d->url, ":%u", overridePort ? overridePort : titanPortForUrl_(url));
202 appendRange_String(&d->url, (iRangecc){ parts.path.start, constEnd_String(url) }); 233 appendRange_String(&d->url, (iRangecc){ parts.path.start, constEnd_String(url) });
203 setText_LabelWidget(d->info, &d->url); 234 setText_LabelWidget(d->info, &d->url);
235 arrange_Widget(as_Widget(d));
204} 236}
205 237
206void setUrl_UploadWidget(iUploadWidget *d, const iString *url) { 238void setUrl_UploadWidget(iUploadWidget *d, const iString *url) {
@@ -233,7 +265,7 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
233 if (isResize_UserEvent(ev)) { 265 if (isResize_UserEvent(ev)) {
234 updateInputMaxHeight_UploadWidget_(d); 266 updateInputMaxHeight_UploadWidget_(d);
235 } 267 }
236 if (isCommand_Widget(w, ev, "upload.cancel")) { 268 if (equal_Command(cmd, "upload.cancel")) {
237 setupSheetTransition_Mobile(w, iFalse); 269 setupSheetTransition_Mobile(w, iFalse);
238 destroy_Widget(w); 270 destroy_Widget(w);
239 return iTrue; 271 return iTrue;