diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-12-19 08:49:20 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-12-19 08:49:20 +0200 |
commit | 8528a8c26c66735d0a977aaafaa32f6c0dc52c42 (patch) | |
tree | 8a91f10948c5f801c02c0f85ad842e4c77632334 /src/ui/util.c | |
parent | 88a1c5b30d6ff07c9a3d0a9644ed02a4b8090d4b (diff) |
"Edit Feed..." opens Feed Settings
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 855f0fb3..9bd40e80 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -26,7 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
26 | #include "bookmarks.h" | 26 | #include "bookmarks.h" |
27 | #include "color.h" | 27 | #include "color.h" |
28 | #include "command.h" | 28 | #include "command.h" |
29 | #include "documentwidget.h" | ||
29 | #include "gmutil.h" | 30 | #include "gmutil.h" |
31 | #include "feeds.h" | ||
30 | #include "labelwidget.h" | 32 | #include "labelwidget.h" |
31 | #include "inputwidget.h" | 33 | #include "inputwidget.h" |
32 | #include "bindingswidget.h" | 34 | #include "bindingswidget.h" |
@@ -1249,6 +1251,55 @@ iWidget *makeBookmarkCreation_Widget(const iString *url, const iString *title, i | |||
1249 | return dlg; | 1251 | return dlg; |
1250 | } | 1252 | } |
1251 | 1253 | ||
1254 | |||
1255 | static iBool handleFeedSettingCommands_(iWidget *dlg, const char *cmd) { | ||
1256 | if (equal_Command(cmd, "cancel")) { | ||
1257 | destroy_Widget(dlg); | ||
1258 | /* Sidebars are disabled when a dialog is opened. */ | ||
1259 | setFlags_Widget(findWidget_App("sidebar"), disabled_WidgetFlag, iFalse); | ||
1260 | setFlags_Widget(findWidget_App("sidebar2"), disabled_WidgetFlag, iFalse); | ||
1261 | return iTrue; | ||
1262 | } | ||
1263 | if (equal_Command(cmd, "feedcfg.accept")) { | ||
1264 | iString *feedTitle = | ||
1265 | collect_String(copy_String(text_InputWidget(findChild_Widget(dlg, "feedcfg.title")))); | ||
1266 | trim_String(feedTitle); | ||
1267 | if (isEmpty_String(feedTitle)) { | ||
1268 | return iTrue; | ||
1269 | } | ||
1270 | int id = argLabel_Command(cmd, "bmid"); | ||
1271 | const iBool headings = isSelected_Widget(findChild_Widget(dlg, "feedcfg.type.headings")); | ||
1272 | const iString *tags = collectNewFormat_String("subscribed%s", headings ? " headings" : ""); | ||
1273 | if (!id) { | ||
1274 | const size_t numSubs = numSubscribed_Feeds(); | ||
1275 | const iString *url = url_DocumentWidget(document_App()); | ||
1276 | add_Bookmarks(bookmarks_App(), | ||
1277 | url, | ||
1278 | feedTitle, | ||
1279 | tags, | ||
1280 | siteIcon_GmDocument(document_DocumentWidget(document_App()))); | ||
1281 | if (numSubs == 0) { | ||
1282 | /* Auto-refresh after first addition. */ | ||
1283 | postCommand_App("feeds.refresh"); | ||
1284 | } | ||
1285 | } | ||
1286 | else { | ||
1287 | iBookmark *bm = get_Bookmarks(bookmarks_App(), id); | ||
1288 | if (bm) { | ||
1289 | set_String(&bm->title, feedTitle); | ||
1290 | set_String(&bm->tags, tags); | ||
1291 | } | ||
1292 | } | ||
1293 | postCommand_App("bookmarks.changed"); | ||
1294 | destroy_Widget(dlg); | ||
1295 | /* Sidebars are disabled when a dialog is opened. */ | ||
1296 | setFlags_Widget(findWidget_App("sidebar"), disabled_WidgetFlag, iFalse); | ||
1297 | setFlags_Widget(findWidget_App("sidebar2"), disabled_WidgetFlag, iFalse); | ||
1298 | return iTrue; | ||
1299 | } | ||
1300 | return iFalse; | ||
1301 | } | ||
1302 | |||
1252 | iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { | 1303 | iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { |
1253 | iWidget *dlg = makeSheet_Widget("feedcfg"); | 1304 | iWidget *dlg = makeSheet_Widget("feedcfg"); |
1254 | setId_Widget(addChildFlags_Widget( | 1305 | setId_Widget(addChildFlags_Widget( |
@@ -1291,6 +1342,17 @@ iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { | |||
1291 | as_Widget(input)->rect.size.x = 100 * gap_UI - headings->rect.size.x; | 1342 | as_Widget(input)->rect.size.x = 100 * gap_UI - headings->rect.size.x; |
1292 | addChild_Widget(get_Window()->root, iClob(dlg)); | 1343 | addChild_Widget(get_Window()->root, iClob(dlg)); |
1293 | centerSheet_Widget(dlg); | 1344 | centerSheet_Widget(dlg); |
1345 | /* Initialize. */ { | ||
1346 | const iBookmark *bm = bookmarkId ? get_Bookmarks(bookmarks_App(), bookmarkId) : NULL; | ||
1347 | setText_InputWidget(findChild_Widget(dlg, "feedcfg.title"), | ||
1348 | bm ? &bm->title : feedTitle_DocumentWidget(document_App())); | ||
1349 | setFlags_Widget(findChild_Widget(dlg, | ||
1350 | hasTag_Bookmark(bm, "headings") ? "feedcfg.type.headings" | ||
1351 | : "feedcfg.type.gemini"), | ||
1352 | selected_WidgetFlag, | ||
1353 | iTrue); | ||
1354 | setCommandHandler_Widget(dlg, handleFeedSettingCommands_); | ||
1355 | } | ||
1294 | return dlg; | 1356 | return dlg; |
1295 | } | 1357 | } |
1296 | 1358 | ||