diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 94 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 8 | ||||
-rw-r--r-- | src/ui/util.c | 62 |
3 files changed, 64 insertions, 100 deletions
@@ -990,49 +990,6 @@ static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { | |||
990 | return iFalse; | 990 | return iFalse; |
991 | } | 991 | } |
992 | 992 | ||
993 | static iBool handleFeedSettingCommands_(iWidget *dlg, const char *cmd) { | ||
994 | iApp *d = &app_; | ||
995 | if (equal_Command(cmd, "cancel")) { | ||
996 | destroy_Widget(dlg); | ||
997 | return iTrue; | ||
998 | } | ||
999 | if (equal_Command(cmd, "feedcfg.accept")) { | ||
1000 | iString *feedTitle = | ||
1001 | collect_String(copy_String(text_InputWidget(findChild_Widget(dlg, "feedcfg.title")))); | ||
1002 | trim_String(feedTitle); | ||
1003 | if (isEmpty_String(feedTitle)) { | ||
1004 | return iTrue; | ||
1005 | } | ||
1006 | int id = argLabel_Command(cmd, "bmid"); | ||
1007 | const iBool headings = isSelected_Widget(findChild_Widget(dlg, "feedcfg.type.headings")); | ||
1008 | const iString *tags = collectNewFormat_String("subscribed%s", headings ? " headings" : ""); | ||
1009 | if (!id) { | ||
1010 | const size_t numSubs = numSubscribed_Feeds(); | ||
1011 | const iString *url = url_DocumentWidget(document_App()); | ||
1012 | add_Bookmarks(d->bookmarks, | ||
1013 | url, | ||
1014 | feedTitle, | ||
1015 | tags, | ||
1016 | siteIcon_GmDocument(document_DocumentWidget(document_App()))); | ||
1017 | if (numSubs == 0) { | ||
1018 | /* Auto-refresh after first addition. */ | ||
1019 | postCommand_App("feeds.refresh"); | ||
1020 | } | ||
1021 | } | ||
1022 | else { | ||
1023 | iBookmark *bm = get_Bookmarks(d->bookmarks, id); | ||
1024 | if (bm) { | ||
1025 | set_String(&bm->title, feedTitle); | ||
1026 | set_String(&bm->tags, tags); | ||
1027 | } | ||
1028 | } | ||
1029 | postCommand_App("bookmarks.changed"); | ||
1030 | destroy_Widget(dlg); | ||
1031 | return iTrue; | ||
1032 | } | ||
1033 | return iFalse; | ||
1034 | } | ||
1035 | |||
1036 | iBool willUseProxy_App(const iRangecc scheme) { | 993 | iBool willUseProxy_App(const iRangecc scheme) { |
1037 | return schemeProxy_App(scheme) != NULL; | 994 | return schemeProxy_App(scheme) != NULL; |
1038 | } | 995 | } |
@@ -1403,57 +1360,8 @@ iBool handleCommand_App(const char *cmd) { | |||
1403 | if (isEmpty_String(url)) { | 1360 | if (isEmpty_String(url)) { |
1404 | return iTrue; | 1361 | return iTrue; |
1405 | } | 1362 | } |
1406 | uint32_t id = findUrl_Bookmarks(d->bookmarks, url); | 1363 | makeFeedSettings_Widget(findUrl_Bookmarks(d->bookmarks, url)); |
1407 | const iBookmark *bm = id ? get_Bookmarks(d->bookmarks, id) : NULL; | ||
1408 | iWidget * dlg = makeFeedSettings_Widget(id); | ||
1409 | setText_InputWidget(findChild_Widget(dlg, "feedcfg.title"), | ||
1410 | bm ? &bm->title : feedTitle_DocumentWidget(document_App())); | ||
1411 | setFlags_Widget(findChild_Widget(dlg, | ||
1412 | hasTag_Bookmark(bm, "headings") ? "feedcfg.type.headings" | ||
1413 | : "feedcfg.type.gemini"), | ||
1414 | selected_WidgetFlag, | ||
1415 | iTrue); | ||
1416 | setCommandHandler_Widget(dlg, handleFeedSettingCommands_); | ||
1417 | return iTrue; | 1364 | return iTrue; |
1418 | #if 0 | ||
1419 | const size_t numSubs = numSubscribed_Feeds(); | ||
1420 | if (!isEmpty_String(url)) { | ||
1421 | iBool wasCreated = iFalse; | ||
1422 | uint32_t id = findUrl_Bookmarks(d->bookmarks, url); | ||
1423 | if (!id) { | ||
1424 | add_Bookmarks(d->bookmarks, | ||
1425 | url, | ||
1426 | bookmarkTitle_DocumentWidget(document_App()), | ||
1427 | collectNewCStr_String("subscribed"), | ||
1428 | siteIcon_GmDocument(document_DocumentWidget(document_App()))); | ||
1429 | wasCreated = iTrue; | ||
1430 | } | ||
1431 | |||
1432 | if (numSubs == 0 && !cmp_String(tag, "subscribed")) { | ||
1433 | postCommand_App("feeds.refresh"); | ||
1434 | } | ||
1435 | } | ||
1436 | #endif | ||
1437 | #if 0 | ||
1438 | const iString *tag = string_Command(cmd, "tag"); | ||
1439 | const iString *url = url_DocumentWidget(document_App()); | ||
1440 | const size_t numSubs = numSubscribed_Feeds(); | ||
1441 | if (!isEmpty_String(url)) { | ||
1442 | uint32_t id = findUrl_Bookmarks(d->bookmarks, url); | ||
1443 | if (id) { | ||
1444 | addTag_Bookmark(get_Bookmarks(d->bookmarks, id), cstr_String(tag)); | ||
1445 | } | ||
1446 | else { | ||
1447 | add_Bookmarks(d->bookmarks, url, bookmarkTitle_DocumentWidget(document_App()), | ||
1448 | tag, siteIcon_GmDocument(document_DocumentWidget(document_App()))); | ||
1449 | } | ||
1450 | postCommand_App("bookmarks.changed"); | ||
1451 | if (numSubs == 0 && !cmp_String(tag, "subscribed")) { | ||
1452 | postCommand_App("feeds.refresh"); | ||
1453 | } | ||
1454 | } | ||
1455 | return iTrue; | ||
1456 | #endif | ||
1457 | } | 1365 | } |
1458 | else if (equal_Command(cmd, "bookmarks.changed")) { | 1366 | else if (equal_Command(cmd, "bookmarks.changed")) { |
1459 | save_Bookmarks(d->bookmarks, dataDir_App_); | 1367 | save_Bookmarks(d->bookmarks, dataDir_App_); |
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index f08490a4..ff4be073 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -800,13 +800,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
800 | } | 800 | } |
801 | if (isCommand_Widget(w, ev, "feed.entry.edit")) { | 801 | if (isCommand_Widget(w, ev, "feed.entry.edit")) { |
802 | setFlags_Widget(w, disabled_WidgetFlag, iTrue); | 802 | setFlags_Widget(w, disabled_WidgetFlag, iTrue); |
803 | iWidget *dlg = makeBookmarkEditor_Widget(); | 803 | makeFeedSettings_Widget(id_Bookmark(feedBookmark)); |
804 | setId_Widget(dlg, format_CStr("bmed.%s", cstr_String(id_Widget(w)))); | ||
805 | setText_InputWidget(findChild_Widget(dlg, "bmed.title"), &feedBookmark->title); | ||
806 | setText_InputWidget(findChild_Widget(dlg, "bmed.url"), &feedBookmark->url); | ||
807 | setText_InputWidget(findChild_Widget(dlg, "bmed.tags"), &feedBookmark->tags); | ||
808 | setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_); | ||
809 | setFocus_Widget(findChild_Widget(dlg, "bmed.title")); | ||
810 | return iTrue; | 804 | return iTrue; |
811 | } | 805 | } |
812 | if (isCommand_Widget(w, ev, "feed.entry.unsubscribe")) { | 806 | if (isCommand_Widget(w, ev, "feed.entry.unsubscribe")) { |
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 | ||