summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks.c19
-rw-r--r--src/bookmarks.h3
-rw-r--r--src/ui/sidebarwidget.c25
3 files changed, 38 insertions, 9 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 7cf7f5a1..9c63710a 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -37,6 +37,7 @@ void init_Bookmark(iBookmark *d) {
37 init_String(&d->title); 37 init_String(&d->title);
38 init_String(&d->tags); 38 init_String(&d->tags);
39 iZap(d->when); 39 iZap(d->when);
40 d->sourceId = 0;
40} 41}
41 42
42void deinit_Bookmark(iBookmark *d) { 43void deinit_Bookmark(iBookmark *d) {
@@ -101,6 +102,7 @@ void init_Bookmarks(iBookmarks *d) {
101void deinit_Bookmarks(iBookmarks *d) { 102void deinit_Bookmarks(iBookmarks *d) {
102 iForEach(PtrArray, i, &d->remoteRequests) { 103 iForEach(PtrArray, i, &d->remoteRequests) {
103 cancel_GmRequest(i.ptr); 104 cancel_GmRequest(i.ptr);
105 free(userData_Object(i.ptr));
104 iRelease(i.ptr); 106 iRelease(i.ptr);
105 } 107 }
106 deinit_PtrArray(&d->remoteRequests); 108 deinit_PtrArray(&d->remoteRequests);
@@ -193,8 +195,8 @@ void save_Bookmarks(const iBookmarks *d, const char *dirPath) {
193 unlock_Mutex(d->mtx); 195 unlock_Mutex(d->mtx);
194} 196}
195 197
196void add_Bookmarks(iBookmarks *d, const iString *url, const iString *title, const iString *tags, 198uint32_t add_Bookmarks(iBookmarks *d, const iString *url, const iString *title,
197 iChar icon) { 199 const iString *tags, iChar icon) {
198 lock_Mutex(d->mtx); 200 lock_Mutex(d->mtx);
199 iBookmark *bm = new_Bookmark(); 201 iBookmark *bm = new_Bookmark();
200 set_String(&bm->url, url); 202 set_String(&bm->url, url);
@@ -204,6 +206,7 @@ void add_Bookmarks(iBookmarks *d, const iString *url, const iString *title, cons
204 initCurrent_Time(&bm->when); 206 initCurrent_Time(&bm->when);
205 insert_Bookmarks_(d, bm); 207 insert_Bookmarks_(d, bm);
206 unlock_Mutex(d->mtx); 208 unlock_Mutex(d->mtx);
209 return id_Bookmark(bm);
207} 210}
208 211
209iBool remove_Bookmarks(iBookmarks *d, uint32_t id) { 212iBool remove_Bookmarks(iBookmarks *d, uint32_t id) {
@@ -402,7 +405,9 @@ void requestFinished_Bookmarks(iBookmarks *d, iGmRequest *req) {
402 const iString *absUrl = absoluteUrl_String(url_GmRequest(req), urlStr); 405 const iString *absUrl = absoluteUrl_String(url_GmRequest(req), urlStr);
403 if (!findUrl_Bookmarks(d, absUrl)) { 406 if (!findUrl_Bookmarks(d, absUrl)) {
404 iString *titleStr = newRange_String(title); 407 iString *titleStr = newRange_String(title);
405 add_Bookmarks(d, absUrl, titleStr, remoteTag, 0x2913 /* arrow down */); 408 const uint32_t bmId = add_Bookmarks(d, absUrl, titleStr, remoteTag, 0x2913);
409 iBookmark *bm = get_Bookmarks(d, bmId);
410 bm->sourceId = *(uint32_t *) userData_Object(req);
406 delete_String(titleStr); 411 delete_String(titleStr);
407 } 412 }
408 delete_String(urlStr); 413 delete_String(urlStr);
@@ -414,6 +419,7 @@ void requestFinished_Bookmarks(iBookmarks *d, iGmRequest *req) {
414 else { 419 else {
415 /* TODO: Show error? */ 420 /* TODO: Show error? */
416 } 421 }
422 free(userData_Object(req));
417 iRelease(req); 423 iRelease(req);
418 if (isEmpty_PtrArray(&d->remoteRequests)) { 424 if (isEmpty_PtrArray(&d->remoteRequests)) {
419 postCommand_App("bookmarks.changed"); 425 postCommand_App("bookmarks.changed");
@@ -440,8 +446,11 @@ void fetchRemote_Bookmarks(iBookmarks *d) {
440 } 446 }
441 } 447 }
442 iConstForEach(PtrArray, i, list_Bookmarks(d, NULL, isRemoteSource_Bookmark_, NULL)) { 448 iConstForEach(PtrArray, i, list_Bookmarks(d, NULL, isRemoteSource_Bookmark_, NULL)) {
443 const iBookmark *bm = i.ptr; 449 const iBookmark *bm = i.ptr;
444 iGmRequest *req = new_GmRequest(certs_App()); 450 iGmRequest * req = new_GmRequest(certs_App());
451 uint32_t * bmId = malloc(4);
452 *bmId = id_Bookmark(bm);
453 setUserData_Object(req, bmId);
445 pushBack_PtrArray(&d->remoteRequests, req); 454 pushBack_PtrArray(&d->remoteRequests, req);
446 setUrl_GmRequest(req, &bm->url); 455 setUrl_GmRequest(req, &bm->url);
447 iConnect(GmRequest, req, finished, req, remoteRequestFinished_Bookmarks_); 456 iConnect(GmRequest, req, finished, req, remoteRequestFinished_Bookmarks_);
diff --git a/src/bookmarks.h b/src/bookmarks.h
index 26bd9a47..be2a4cfd 100644
--- a/src/bookmarks.h
+++ b/src/bookmarks.h
@@ -39,6 +39,7 @@ struct Impl_Bookmark {
39 iString tags; 39 iString tags;
40 iChar icon; 40 iChar icon;
41 iTime when; 41 iTime when;
42 uint32_t sourceId; /* remote */
42}; 43};
43 44
44iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; } 45iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; }
@@ -59,7 +60,7 @@ void save_Bookmarks (const iBookmarks *, const char *dirPath);
59void fetchRemote_Bookmarks (iBookmarks *); 60void fetchRemote_Bookmarks (iBookmarks *);
60void requestFinished_Bookmarks (iBookmarks *, iGmRequest *req); 61void requestFinished_Bookmarks (iBookmarks *, iGmRequest *req);
61 62
62void add_Bookmarks (iBookmarks *, const iString *url, const iString *title, 63uint32_t add_Bookmarks (iBookmarks *, const iString *url, const iString *title,
63 const iString *tags, iChar icon); 64 const iString *tags, iChar icon);
64iBool remove_Bookmarks (iBookmarks *, uint32_t id); 65iBool remove_Bookmarks (iBookmarks *, uint32_t id);
65iBool updateBookmarkIcon_Bookmarks (iBookmarks *, const iString *url, iChar icon); 66iBool updateBookmarkIcon_Bookmarks (iBookmarks *, const iString *url, iChar icon);
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 317e74bd..e28f86f9 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -52,6 +52,7 @@ struct Impl_SidebarItem {
52 uint32_t id; 52 uint32_t id;
53 int indent; 53 int indent;
54 iChar icon; 54 iChar icon;
55 iBool isBold;
55 iString label; 56 iString label;
56 iString meta; 57 iString meta;
57 iString url; 58 iString url;
@@ -62,6 +63,7 @@ void init_SidebarItem(iSidebarItem *d) {
62 d->id = 0; 63 d->id = 0;
63 d->indent = 0; 64 d->indent = 0;
64 d->icon = 0; 65 d->icon = 0;
66 d->isBold = iFalse;
65 init_String(&d->label); 67 init_String(&d->label);
66 init_String(&d->meta); 68 init_String(&d->meta);
67 init_String(&d->url); 69 init_String(&d->url);
@@ -106,7 +108,23 @@ static iBool isResizing_SidebarWidget_(const iSidebarWidget *d) {
106} 108}
107 109
108static int cmpTitle_Bookmark_(const iBookmark **a, const iBookmark **b) { 110static int cmpTitle_Bookmark_(const iBookmark **a, const iBookmark **b) {
109 return cmpStringCase_String(&(*a)->title, &(*b)->title); 111 const iBookmark *bm1 = *a, *bm2 = *b;
112 if (bm2->sourceId == id_Bookmark(bm1)) {
113 return -1;
114 }
115 if (bm1->sourceId == id_Bookmark(bm2)) {
116 return 1;
117 }
118 if (bm1->sourceId == bm2->sourceId) {
119 return cmpStringCase_String(&bm1->title, &bm2->title);
120 }
121 if (bm1->sourceId) {
122 bm1 = get_Bookmarks(bookmarks_App(), bm1->sourceId);
123 }
124 if (bm2->sourceId) {
125 bm2 = get_Bookmarks(bookmarks_App(), bm2->sourceId);
126 }
127 return cmpStringCase_String(&bm1->title, &bm2->title);
110} 128}
111 129
112static void updateItems_SidebarWidget_(iSidebarWidget *d) { 130static void updateItems_SidebarWidget_(iSidebarWidget *d) {
@@ -220,6 +238,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
220 init_RegExpMatch(&m); 238 init_RegExpMatch(&m);
221 if (matchString_RegExp(remoteSourceTag, &bm->tags, &m)) { 239 if (matchString_RegExp(remoteSourceTag, &bm->tags, &m)) {
222 appendChar_String(&item->meta, 0x2913); 240 appendChar_String(&item->meta, 0x2913);
241 item->isBold = iTrue;
223 } 242 }
224 } 243 }
225 addItem_ListWidget(d->list, item); 244 addItem_ListWidget(d->list, item);
@@ -1132,8 +1151,8 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect,
1132 const int itemHeight = height_Rect(itemRect); 1151 const int itemHeight = height_Rect(itemRect);
1133 const int iconColor = isHover ? (isPressing ? uiTextPressed_ColorId : uiIconHover_ColorId) 1152 const int iconColor = isHover ? (isPressing ? uiTextPressed_ColorId : uiIconHover_ColorId)
1134 : uiIcon_ColorId; 1153 : uiIcon_ColorId;
1135 const int font = uiContent_FontId; 1154 const int font = d->isBold ? uiContentBold_FontId : uiContent_FontId;
1136 int bg = uiBackground_ColorId; 1155 int bg = uiBackground_ColorId;
1137 if (isHover) { 1156 if (isHover) {
1138 bg = isPressing ? uiBackgroundPressed_ColorId 1157 bg = isPressing ? uiBackgroundPressed_ColorId
1139 : uiBackgroundFramelessHover_ColorId; 1158 : uiBackgroundFramelessHover_ColorId;