summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-18 23:50:28 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-18 23:50:28 +0300
commit01b09cc3cf3cd25396c53e184563fbfdab74f8e7 (patch)
tree5da0135101930e2c992ce7616087b495d9e63434 /src
parent35a40515d7bfef700ed7680b07112ef5d5fa35b2 (diff)
Home button opens a random "homepage" bookmark
Diffstat (limited to 'src')
-rw-r--r--src/app.c25
-rw-r--r--src/bookmarks.c7
-rw-r--r--src/bookmarks.h2
3 files changed, 31 insertions, 3 deletions
diff --git a/src/app.c b/src/app.c
index 84e57ce2..2928522b 100644
--- a/src/app.c
+++ b/src/app.c
@@ -912,11 +912,30 @@ iBool handleCommand_App(const char *cmd) {
912 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.gopher"), 912 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.gopher"),
913 schemeProxy_App(range_CStr("gopher"))); 913 schemeProxy_App(range_CStr("gopher")));
914 setCommandHandler_Widget(dlg, handlePrefsCommands_); 914 setCommandHandler_Widget(dlg, handlePrefsCommands_);
915 postCommand_App("focus.set id:prefs.downloads");
916 } 915 }
917 else if (equal_Command(cmd, "navigate.home")) { 916 else if (equal_Command(cmd, "navigate.home")) {
918 /* TODO: Look for bookmarks tagged homepage, or use the URL set in Preferences. */ 917 /* Look for bookmarks tagged "homepage". */
919 postCommand_App("open url:about:lagrange"); 918 iRegExp *pattern = iClob(new_RegExp("\\bhomepage\\b", caseInsensitive_RegExpOption));
919 const iPtrArray *homepages =
920 list_Bookmarks(d->bookmarks, NULL, filterTagsRegExp_Bookmarks, pattern);
921 if (isEmpty_PtrArray(homepages)) {
922 postCommand_App("open url:about:lagrange");
923 }
924 else {
925 iStringSet *urls = iClob(new_StringSet());
926 iConstForEach(PtrArray, i, homepages) {
927 const iBookmark *bm = i.ptr;
928 /* Try to switch to a different bookmark. */
929 if (cmpStringCase_String(url_DocumentWidget(document_App()), &bm->url)) {
930 insert_StringSet(urls, &bm->url);
931 }
932 }
933 if (!isEmpty_StringSet(urls)) {
934 postCommandf_App(
935 "open url:%s",
936 cstr_String(constAt_StringSet(urls, iRandoms(0, size_StringSet(urls)))));
937 }
938 }
920 return iTrue; 939 return iTrue;
921 } 940 }
922 else if (equal_Command(cmd, "zoom.set")) { 941 else if (equal_Command(cmd, "zoom.set")) {
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 8fe7d109..7e98fb27 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
26#include <the_Foundation/hash.h> 26#include <the_Foundation/hash.h>
27#include <the_Foundation/mutex.h> 27#include <the_Foundation/mutex.h>
28#include <the_Foundation/path.h> 28#include <the_Foundation/path.h>
29#include <the_Foundation/regexp.h>
29 30
30void init_Bookmark(iBookmark *d) { 31void init_Bookmark(iBookmark *d) {
31 init_String(&d->url); 32 init_String(&d->url);
@@ -166,6 +167,12 @@ iBookmark *get_Bookmarks(iBookmarks *d, uint32_t id) {
166 return (iBookmark *) value_Hash(&d->bookmarks, id); 167 return (iBookmark *) value_Hash(&d->bookmarks, id);
167} 168}
168 169
170iBool filterTagsRegExp_Bookmarks(void *regExp, const iBookmark *bm) {
171 iRegExpMatch m;
172 init_RegExpMatch(&m);
173 return matchString_RegExp(regExp, &bm->tags, &m);
174}
175
169const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp, 176const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp,
170 iBookmarksFilterFunc filter, void *context) { 177 iBookmarksFilterFunc filter, void *context) {
171 lock_Mutex(d->mtx); 178 lock_Mutex(d->mtx);
diff --git a/src/bookmarks.h b/src/bookmarks.h
index aac83be1..4889e7b5 100644
--- a/src/bookmarks.h
+++ b/src/bookmarks.h
@@ -55,6 +55,8 @@ iBookmark *get_Bookmarks (iBookmarks *, uint32_t id);
55typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *); 55typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *);
56typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **); 56typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **);
57 57
58iBool filterTagsRegExp_Bookmarks (void *regExp, const iBookmark *);
59
58/** 60/**
59 * Lists all or a subset of the bookmarks in a sorted array of Bookmark pointers. 61 * Lists all or a subset of the bookmarks in a sorted array of Bookmark pointers.
60 * 62 *