summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app.c78
-rw-r--r--src/bookmarks.c1
-rw-r--r--src/ui/labelwidget.c4
-rw-r--r--src/ui/labelwidget.h1
-rw-r--r--src/ui/util.c40
-rw-r--r--src/ui/util.h1
-rw-r--r--src/ui/window.c4
7 files changed, 126 insertions, 3 deletions
diff --git a/src/app.c b/src/app.c
index eb8eb16a..3daf7c03 100644
--- a/src/app.c
+++ b/src/app.c
@@ -905,6 +905,42 @@ static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) {
905 return iFalse; 905 return iFalse;
906} 906}
907 907
908static iBool handleFeedSettingCommands_(iWidget *dlg, const char *cmd) {
909 iApp *d = &app_;
910 if (equal_Command(cmd, "cancel")) {
911 destroy_Widget(dlg);
912 return iTrue;
913 }
914 if (equal_Command(cmd, "feedcfg.accept")) {
915 int id = argLabel_Command(cmd, "bmid");
916 const iBool headings = isSelected_Widget(findChild_Widget(dlg, "feedcfg.type.headings"));
917 const iString *tags = collectNewFormat_String("subscribed%s", headings ? " headings" : "");
918 if (!id) {
919 const size_t numSubs = numSubscribed_Feeds();
920 const iString *url = url_DocumentWidget(document_App());
921 add_Bookmarks(d->bookmarks,
922 url,
923 bookmarkTitle_DocumentWidget(document_App()),
924 tags,
925 siteIcon_GmDocument(document_DocumentWidget(document_App())));
926 if (numSubs == 0) {
927 /* Auto-refresh after first addition. */
928 postCommand_App("feeds.refresh");
929 }
930 }
931 else {
932 iBookmark *bm = get_Bookmarks(d->bookmarks, id);
933 if (bm) {
934 set_String(&bm->tags, tags);
935 }
936 }
937 postCommand_App("bookmarks.changed");
938 destroy_Widget(dlg);
939 return iTrue;
940 }
941 return iFalse;
942}
943
908iBool willUseProxy_App(const iRangecc scheme) { 944iBool willUseProxy_App(const iRangecc scheme) {
909 return schemeProxy_App(scheme) != NULL; 945 return schemeProxy_App(scheme) != NULL;
910} 946}
@@ -1244,7 +1280,46 @@ iBool handleCommand_App(const char *cmd) {
1244 postCommand_App("focus.set id:bmed.title"); 1280 postCommand_App("focus.set id:bmed.title");
1245 return iTrue; 1281 return iTrue;
1246 } 1282 }
1247 else if (equal_Command(cmd, "bookmark.addtag")) { 1283 else if (equal_Command(cmd, "feeds.subscribe")) {
1284 const iString *url = url_DocumentWidget(document_App());
1285 if (isEmpty_String(url)) {
1286 return iTrue;
1287 }
1288 uint32_t id = findUrl_Bookmarks(d->bookmarks, url);
1289 const iBookmark *bm = id ? get_Bookmarks(d->bookmarks, id) : NULL;
1290 iWidget * dlg = makeFeedSettings_Widget(id);
1291 setText_LabelWidget(findChild_Widget(dlg, "feedcfg.title"),
1292 collectNewFormat_String(
1293 uiHeading_ColorEscape "%s",
1294 bm ? cstr_String(&bm->title)
1295 : cstr_String(bookmarkTitle_DocumentWidget(document_App()))));
1296 setFlags_Widget(findChild_Widget(dlg,
1297 hasTag_Bookmark(bm, "headings") ? "feedcfg.type.headings"
1298 : "feedcfg.type.gemini"),
1299 selected_WidgetFlag,
1300 iTrue);
1301 setCommandHandler_Widget(dlg, handleFeedSettingCommands_);
1302 return iTrue;
1303#if 0
1304 const size_t numSubs = numSubscribed_Feeds();
1305 if (!isEmpty_String(url)) {
1306 iBool wasCreated = iFalse;
1307 uint32_t id = findUrl_Bookmarks(d->bookmarks, url);
1308 if (!id) {
1309 add_Bookmarks(d->bookmarks,
1310 url,
1311 bookmarkTitle_DocumentWidget(document_App()),
1312 collectNewCStr_String("subscribed"),
1313 siteIcon_GmDocument(document_DocumentWidget(document_App())));
1314 wasCreated = iTrue;
1315 }
1316
1317 if (numSubs == 0 && !cmp_String(tag, "subscribed")) {
1318 postCommand_App("feeds.refresh");
1319 }
1320 }
1321#endif
1322#if 0
1248 const iString *tag = string_Command(cmd, "tag"); 1323 const iString *tag = string_Command(cmd, "tag");
1249 const iString *url = url_DocumentWidget(document_App()); 1324 const iString *url = url_DocumentWidget(document_App());
1250 const size_t numSubs = numSubscribed_Feeds(); 1325 const size_t numSubs = numSubscribed_Feeds();
@@ -1263,6 +1338,7 @@ iBool handleCommand_App(const char *cmd) {
1263 } 1338 }
1264 } 1339 }
1265 return iTrue; 1340 return iTrue;
1341#endif
1266 } 1342 }
1267 else if (equal_Command(cmd, "bookmarks.changed")) { 1343 else if (equal_Command(cmd, "bookmarks.changed")) {
1268 save_Bookmarks(d->bookmarks, dataDir_App_); 1344 save_Bookmarks(d->bookmarks, dataDir_App_);
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 8bde5b8b..54b0407f 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -42,6 +42,7 @@ void deinit_Bookmark(iBookmark *d) {
42} 42}
43 43
44iBool hasTag_Bookmark(const iBookmark *d, const char *tag) { 44iBool hasTag_Bookmark(const iBookmark *d, const char *tag) {
45 if (!d) return iFalse;
45 iRegExp *pattern = new_RegExp(format_CStr("\\b%s\\b", tag), caseSensitive_RegExpOption); 46 iRegExp *pattern = new_RegExp(format_CStr("\\b%s\\b", tag), caseSensitive_RegExpOption);
46 iRegExpMatch m; 47 iRegExpMatch m;
47 init_RegExpMatch(&m); 48 init_RegExpMatch(&m);
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c
index 1f0e7b4d..bd8b71da 100644
--- a/src/ui/labelwidget.c
+++ b/src/ui/labelwidget.c
@@ -330,6 +330,10 @@ void setTextCStr_LabelWidget(iLabelWidget *d, const char *text) {
330 updateSize_LabelWidget(d); 330 updateSize_LabelWidget(d);
331} 331}
332 332
333void setCommand_LabelWidget(iLabelWidget *d, const iString *command) {
334 set_String(&d->command, command);
335}
336
333const iString *text_LabelWidget(const iLabelWidget *d) { 337const iString *text_LabelWidget(const iLabelWidget *d) {
334 return &d->label; 338 return &d->label;
335} 339}
diff --git a/src/ui/labelwidget.h b/src/ui/labelwidget.h
index 5b2efc42..c91793e5 100644
--- a/src/ui/labelwidget.h
+++ b/src/ui/labelwidget.h
@@ -33,6 +33,7 @@ void setAlignVisually_LabelWidget(iLabelWidget *, iBool alignVisual);
33void setFont_LabelWidget (iLabelWidget *, int fontId); 33void setFont_LabelWidget (iLabelWidget *, int fontId);
34void setText_LabelWidget (iLabelWidget *, const iString *text); /* resizes widget */ 34void setText_LabelWidget (iLabelWidget *, const iString *text); /* resizes widget */
35void setTextCStr_LabelWidget (iLabelWidget *, const char *text); 35void setTextCStr_LabelWidget (iLabelWidget *, const char *text);
36void setCommand_LabelWidget (iLabelWidget *, const iString *command);
36 37
37void updateSize_LabelWidget (iLabelWidget *); 38void updateSize_LabelWidget (iLabelWidget *);
38void updateText_LabelWidget (iLabelWidget *, const iString *text); /* not resized */ 39void updateText_LabelWidget (iLabelWidget *, const iString *text); /* not resized */
diff --git a/src/ui/util.c b/src/ui/util.c
index 428f9e9d..d5bddda9 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1245,6 +1245,46 @@ iWidget *makeBookmarkCreation_Widget(const iString *url, const iString *title, i
1245 return dlg; 1245 return dlg;
1246} 1246}
1247 1247
1248iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) {
1249 iWidget *dlg = makeSheet_Widget("feedcfg");
1250 setId_Widget(addChildFlags_Widget(
1251 dlg,
1252 iClob(new_LabelWidget(uiHeading_ColorEscape "FEED SETTINGS", NULL)),
1253 frameless_WidgetFlag),
1254 "feedcfg.heading");
1255 iWidget *page = new_Widget();
1256 addChild_Widget(dlg, iClob(page));
1257 setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
1258 iWidget *headings = addChildFlags_Widget(
1259 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
1260 iWidget *values = addChildFlags_Widget(
1261 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
1262 addChild_Widget(headings, iClob(makeHeading_Widget("Feed title:")));
1263 setId_Widget(
1264 addChildFlags_Widget(values, iClob(new_LabelWidget("", NULL)), frameless_WidgetFlag),
1265 "feedcfg.title");
1266 addChild_Widget(headings, iClob(makeHeading_Widget("Entry type:")));
1267 iWidget *types = new_Widget(); {
1268 addRadioButton_(types, "feedcfg.type.gemini", "YYYY-MM-DD", "feedcfg.type arg:0");
1269 addRadioButton_(types, "feedcfg.type.headings", "New Headings", "feedcfg.type arg:1");
1270 }
1271 addChildFlags_Widget(values, iClob(types), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag);
1272 iWidget *div = new_Widget(); {
1273 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
1274 addChild_Widget(div, iClob(newKeyMods_LabelWidget("Cancel", SDLK_ESCAPE, 0, "cancel")));
1275 setId_Widget(addChild_Widget(
1276 div,
1277 iClob(newKeyMods_LabelWidget(
1278 uiTextCaution_ColorEscape "Save Settings", SDLK_RETURN, KMOD_PRIMARY,
1279 format_CStr("feedcfg.accept bmid:%d", bookmarkId)))),
1280 "feedcfg.save");
1281 }
1282 addChild_Widget(dlg, iClob(div));
1283 addChild_Widget(get_Window()->root, iClob(dlg));
1284 centerSheet_Widget(dlg);
1285 return dlg;
1286}
1287
1248iWidget *makeIdentityCreation_Widget(void) { 1288iWidget *makeIdentityCreation_Widget(void) {
1249 iWidget *dlg = makeSheet_Widget("ident"); 1289 iWidget *dlg = makeSheet_Widget("ident");
1250 setId_Widget(addChildFlags_Widget( 1290 setId_Widget(addChildFlags_Widget(
diff --git a/src/ui/util.h b/src/ui/util.h
index 062ae56a..c9f464ad 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -203,3 +203,4 @@ iWidget * makePreferences_Widget (void);
203iWidget * makeBookmarkEditor_Widget (void); 203iWidget * makeBookmarkEditor_Widget (void);
204iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon); 204iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon);
205iWidget * makeIdentityCreation_Widget (void); 205iWidget * makeIdentityCreation_Widget (void);
206iWidget * makeFeedSettings_Widget (uint32_t bookmarkId);
diff --git a/src/ui/window.c b/src/ui/window.c
index b3843a76..199e35a7 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -105,7 +105,7 @@ static const iMenuItem navMenuItems_[] = {
105 { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, 105 { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" },
106 { "---", 0, 0, NULL }, 106 { "---", 0, 0, NULL },
107 { "Bookmark Page", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, 107 { "Bookmark Page", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
108 { "Subscribe to Page", subscribeToPage_KeyModifier, "bookmark.addtag tag:subscribed" }, 108 { "Subscribe to Page", subscribeToPage_KeyModifier, "feeds.subscribe" },
109 { "---", 0, 0, NULL }, 109 { "---", 0, 0, NULL },
110 { "Show Feed Entries", 0, 0, "!open url:about:feeds" }, 110 { "Show Feed Entries", 0, 0, "!open url:about:feeds" },
111 { "---", 0, 0, NULL }, 111 { "---", 0, 0, NULL },
@@ -160,7 +160,7 @@ static const iMenuItem viewMenuItems_[] = {
160static iMenuItem bookmarksMenuItems_[] = { 160static iMenuItem bookmarksMenuItems_[] = {
161 { "Bookmark This Page...", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, 161 { "Bookmark This Page...", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
162 { "---", 0, 0, NULL }, 162 { "---", 0, 0, NULL },
163 { "Subscribe to This Page", subscribeToPage_KeyModifier, "bookmark.addtag tag:subscribed" }, 163 { "Subscribe to This Page", subscribeToPage_KeyModifier, "feeds.subscribe" },
164 { "---", 0, 0, NULL }, 164 { "---", 0, 0, NULL },
165 { "Show Feed Entries", 0, 0, "open url:about:feeds" }, 165 { "Show Feed Entries", 0, 0, "open url:about:feeds" },
166 { "Refresh Feeds", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" }, 166 { "Refresh Feeds", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" },